You’ll find this vm here : https://www.vulnhub.com/entry/pylington-1,684/
Port Scan
1 |
|
1 |
|
As we see nmap found the robots.txt
with 3 disallowed entries
- /register
- /login
- /zbir7mn240soxhicso2z
Let’s investigate them
So the /zbir7mn240soxhicso2z
gave us these Credentials :
1 |
|
Login
Login requires to solve a math problem, using python eval()
you can solve it
Playing with code
I tried to spawn a reverse shell using :
1 |
|
But the website detected my malicious code
And gave me this message : H4CK3R AL3R7!!! Malicious program detected by the sandbox
We are lucky because the developer provide us the code of the sandbox
Let’s read it
1 |
|
1 |
|
1 |
|
we are not allowed to use import
, os
and open
in our code
Bypass Python sandbox
After a google Searching if found this nice article : python-sandbox-escape I use the below code :
1 |
|
Reverse order | Explanation of the exploit
The noimportos_sandbox.py
checks the input string if contains these 3 strings : import
, os
and open
We can simple execute these disallowed values using the reverse order, For example the
1 |
|
Our stealth code is :
1 |
|
equals to :
1 |
|
Reverse Shell
First i need to change my malicious code to reverse order
1 |
|
Malicious code
1 |
|
Listener
1 |
|
It works | we are in
Privileges Escalation | User py
Find SUID permissions
1 |
|
Let’s check the /home/py/typing
1 |
|
SSH login as user py
Credentials : py
: 54ezhCGaJV
1 |
|
Root
Find SUID permissions
1 |
|
We focus to /home/py/secret_stuff/backup
First we will read the c++ source code of the backup to understand /home/py/secret_stuff/backup.cc
1 |
|
Explanation
First of all,
We can run The script /home/py/secret_stuff/backup
with root permissions
The snippet :
1 |
|
Allow us to insert what even string we want
The line if(!path.starts_with("/srv/backups/")){
checks only if the path that we inserted starts with /srv/backups/
What about with the rest ???
Writing a user to /etc/passwd
Create a password
1 |
|
The whole string
1 |
|
Final Step
Because the script checks only the starting string we can file inclusion the /srv/backups/../../etc/passwd
So, i typed :
1 |
|
1 |
|
1 |
|
The /etc/passwd
looks like this :
1 |
|