Sitemap
dj4m

dj4m

SshControl

6 min readNov 8, 2025

--

Summary

This machine is all about REGEX from foothold to root, it starts by identifying a SQL injection that is exploited to get access to web application, from there a regex vulnerability will lead to password exfiltration. with the last mentioned password I was able to add my publis ssh key to the user’s authorized_keys getting ssh access to the target. then to get root I identified a vulnerable cronjob that does not properly validate input leading to command injection into the cron script resulting in reverse shell as root.

Nmap Scan

Press enter or click to view image in full size

Foothold

Port 3000 shows a web application for managing SSH keys

Press enter or click to view image in full size

Trying to login with a single quote in the username triggers an error different from the error when submitting a random username so there is potential SQL injection

Press enter or click to view image in full size

I will try to identify which database is running, since this is blind error based injection, all I can tell is if the command runs or triggers an error so if i run a bad command I get the error and I can use that to identify the databases. This should work because different databases have different function/methods to return version, I just need to establish a baseline to run my commands

The payload above confirmed my baseline, since it did not return an error it means the command run successfully and from that I understand I can run valid SQL commands in this format

';<my sql command>--

then I can use the payloads from portswigger to identify the database

Press enter or click to view image in full size
Press enter or click to view image in full size

Here the last screenshot did not show an error which means the database is postgresql.

Next I will identify table name and columns using the following payloads using the same method, querying a table name or column that does not exists returns an error

# To identify table name 
';select * from users--

# To identify column username
';select username from users--

# To identify column password
';select password from users--
# or
';select username,password from users--

So now I know there is table users with columns username and password I move to user enumeration, for this I will use time based + conditional payload for the username

';select pg_sleep(5) where exists (select * from users where username='FUZZ')--

I pass this to ffuf and since I working username will trigger a 5 second sleep I grep with ‘duration: 5’ because ffuf show request duration in milliseconds so it will probably be in the 5050ds, I also use burp proxy this way even if my grep does not work because the request was a little longer and get processed in let’s say 6 sec I can still filter with burp and find the request that took longer

Press enter or click to view image in full size
Press enter or click to view image in full size

Username identified to ‘antwon’ all is left is the password, I can either use the same method, bruteforcing with wordlist, instead I will be using a smaller list here and build the password progressively using ‘like’ operation

';select pg_sleep(5) where exists (select * from users where username='antwon' and password like 'FUZZ%')--

Here I found the fist char of the password

Press enter or click to view image in full size

I change my payload as following to get the second char and keep going

';select pg_sleep(5) where exists (select * from users where username='antwon' and password like 'fFUZZ%')--
Press enter or click to view image in full size

I can repeat this until I get the Full password, When I stop getting delays that means the password is complete. The password I was able to esfiltrate was hashed and is showing bellow.

f46daca7eb795765f476243ee233a9c3fa03bd49e71121bb5aebad24a0b5d015

I identified it as SHA-256 and used hashcat to crack it

Press enter or click to view image in full size
Press enter or click to view image in full size

The whole process for SQL injection can just be automate with SQLmap as showing bellow which will handle everything to drop all database and even crack the password for us

sqlmap -r .login_req --threads 10  -dbms postgresql --batch -p username -D public -T users --dump
Press enter or click to view image in full size

So now with username and password exfiltrated from database I can login to the web application

Press enter or click to view image in full size

It seems I can use the check password function to identify the master password fuzzing with a wordlist, I make a request with burp the use it to run ffuf

Press enter or click to view image in full size

Funny thing the password seems to validate when empty (the second valid ffuf submission is just creating a new parameter with & and leaving the password empty this returning HTTP 200 also). Double check with burp confirms that

I thought the master password was empty at first but trying the create ssh login function with an empty password was not taking it so the password is not empty but validating with an empty string ! why ?!

Get dj4m’s stories in your inbox

Join Medium for free to get updates from this writer.

It’s a comparison that validate for empty string, think of it this way, any string starts with an empty string so is it a regex comparison somehow?

I try fuzzing with a char list

Press enter or click to view image in full size

this returned a valid char! so yes, I have to build the password the same way I did with the password hash from database. Fuzzing one character at a time I validated the following password

C000ntr0lM4st3rK3yyy

Initial Access

I have the master password identified so I can submit a public ssh key, I generate a new one and submit the public key then used the private key to connect on SSH with user antwon. This lead to access to local.txt flag

The public key I submitted was just appended to user antwon authorized_keys

Privilege Escalation

checking cronjobs I found an interesting one

Press enter or click to view image in full size

and checking the json file being processed I can tell antwon have write permission over it as part of the group metausers

The problem with this script is that is_valid_code function only validates the first 4 characters of the code, so whatever comes after is not checked thus I could inject a command there ! just need to make sure not to break the eval command and use port 3000 (simple curl test with other port confirms they are blocked)

I setup my listener and edit the json file with the following payload

And my listener was able to catch the reverse shell as root and give me access to proof.txt flag

--

--