Hack a Machine
Tags: security, sql, ctf
Published: 2023-02-19 09:20:41

## **Penetration Testing Report of Windows Desktop and CentOS Server**

[Link to machines](https://download1351.mediafire.com/ig2opor8abng/sb1ldskt9083ypu/Assignment-3+VED+Machines.zip)

**<u>Setting up the Environment</u>**
The two machines were opened in VMWare. The Desktop machine appears to be a Windows-7 based system while the Server machine is a CentOS system as shown in the image below.
![Machines Look Like](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/648xxkpwdxa8jmt9c07o.png)


**<u>Scanning Phase</u>**
**Tool Used:** Angry IP Scanner
Scanning is a phase where we look for open ports in a system or a network. For this exercise, we scanned the entire network and found the CentOS server on IP address 192.168.10.10 along with its open ports. It is clearly evident that port 80 (for HTTP), port 22 (for SSH) and port 445 (for SMB) are open in the CentOS server. This means that a web application might be running on the server.

![Angry Ip Scanner result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z233d70qzd2bnugsxza3.png)

<u>**Checking the Server Web Application on Port 80**</u>
Since port 80 was open on the CentOS server as highlighted in the scanning phase, we therefore accessed the web application running there as shown in the image below. We made use of Firefox browser as it allows modifying the HTTP Requests which will be helpful in later stages.


![Coping Post Data](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9bij4jg27qeuldj59655.png)

Moreover, we inspected the page source in order to capture the POST request by supplying dummy data to the website. As depicted in the image below, we entered mbrown in the username field and sdsda in the password field. Although the password is wrong but capturing the POST request is important for launching further attacks. 



**<u>Running SQLMap on Captured Post Requests</u>**
After capturing the POST Request, we launched SQLMap tool on that in order to harvest details about database, its tables, columns and fields as shown in the image below. SQL Map basically finds SQL injection vulnerabilities in web pages whereby a malicious SQL query when inserted on any user input field is passed on to the database and it fetches further information for the attacker. The web service running on CentOS server was found to be vulnerable for SQL injection attacks. 



![Sql injection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xkzlalc60qzt2ruvnvp8.png)





 After getting the table details, SQLMap then shows the credentials as shown below.

![Credentials](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bri7sn208ovca2vhub67.png)

Here, we can see that passwords for two accounts (Lora Brown and Matt Brown) are stored in an unencrypted form in the back-end database. Storing passwords in plaintext is not a recommended approach. They should be stored in the form of hashes. Moreover, the credentials for the Windows system are also stored here. Both machines got logged in using these credentials as shown below. This shows that the web application running on CentOS server is wide open for SQL injection attacks


![Server](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbb50e1phun3kn6fpseb.png)


![Desktop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dyzly6m3tk5or0zhnjze.png)





Another utility of SQL injection attack is that that they do not generate persistence related issues in the victim system. Even in this case, the attack is persistent and stealthy because we are way above the Network layer of the TCP/IP protocol and no antivirus and firewall (if present) can guard against attacks on the Application layer of the TCP/IP protocol. That is the reason we chose such a persistent attack in order to get into the system, in the first place. This also speaks about the vulnerability in the implemented web application which should be patched to curtail injection attacks. Moreover, since the web application is running on port 80 and not 443, the entire session is insecure making the entire correspondence with the web application open for sniffers and eavesdroppers. 



**<u>Issue with the Windows Operating System</u>**
While logging into the Windows machine, we found out that it is not running a genuine copy of the Operating System. 



![Not genuine copy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ofu8l7slnr5w2d7oto9w.png)



This means that the machine will not receive any official update, security patch or service pack update/upgrade, making it vulnerable to a wide variety of attacks. Moreover, using a counterfeit copy of a commercially licensed Operating System is not an acceptable act in many parts of the world. 

**<u>HTTP TRACE Request on CentOS Web Server</u>**
Since attackers make use of TRACE Request method in HTTP requests in order to enumerate the website(s), therefore they should not be allowed. But that is not the case with the web service running on CentOS as it accepts the TRACE HTTP Request type. While using the Mozilla Firefox operating system, we first modified our HTTP request to the web service and replaced the GET Request Type with TRACE Request Type in order to see the website’s response, as shown in the figure below.  


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9w8ooqa6khag28u4c9pv.png)



We noticed that the website gave some response to our TRACE request which was in ASCII as shown below.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ks3ejudao4a8vq5dkp1.png)



When we converted this ASCII back into a readable form, we got the actual response website generated as a result of our TRACE request. Ideally, the website should block TRACE but it does not and that’s a vulnerability which would help any attacker fingerprint and/or enumerate the website.
 

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2g725cyc8dq7oq7z6nyq.png)



**<u>HTTP TRACK Request on CentOS Web Server</u>**
Similarly, the website also responds to the TRACK HTTP Request method which is used by the attackers to debug the webserver connections. Ideally, it should be blocked but the web application does not block it and rather responds to such requests. The image below shows the HTTP 200 OK response to the TRACK Request. We again made use of Mozilla Firefox browser to modify the GET HTTP Request Type with TRACK HTTP Request Type.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3aiyu0a0oxleq8hf2hz.png)



**<u>Anonymous READ/WRITE in CentOS (SMB Vulnerability)</u>**
The SMB (Service Message Block) service on the CentOS server requires no authentication and anyone, even anonymous users can get Read and/or Write access on the remote machine as shown in the image below. The administrator has not set any security whatsoever in this regard. This vulnerability can lead to man in the middle attacks on the CentOS machine. 


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3j71g4b2q0ed5hkiuxul.png)



**<u>SMB Vulnerability in Windows Desktop Machine</u>**
Like the CentOS machine, the Windows machine was also vulnerable to the SMB vulnerability. The Windows machine is on the IP Address 192.168.10.20 and after scanning it was found out that the machine also has a remote code execution vulnerability in the SMB service as it is using the older version of SMB which has not been updated or patched and is hence vulnerable.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v8nguc3zuiqp3y8xnj80.png)



**<u>Eternal Blue Vulnerability in Windows Desktop</u>**
Due to the SMB vulnerability, the Windows system was exploited using the Eternal Blue exploit. Metasploit Framework was used on a Kali Linux machine for exploitation purpose as shown in the figures below. Metasploit is framework built-in the Kali Linux Operating System which contains all the payloads and exploit codes which are known and published. It can be used for learning and educational purposes. In the image below, we have set the target IP to that of the Windows machine (192.168.10.25) and the remote port to 445 on which the vulnerable SMB service is listening. This would build a persistent connection and presence on the victim system because it has the vulnerable version of SMB installed which would be unable to detect the payload as vulnerable.



![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pz6okggq7wsa9a38no56.png)



The meterpreter session has opened which shows that the exploit has successfully executed on the remote Windows machine without getting detected, as shown below. Now since the session has been established, the remote system can be probed or fingerprinting in whatever way by providing commands from the Meterpreter terminal in Kali Linux.


![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/scsgcalnmu8d1j0v6sq7.png)




Moreover, the following security policies need to be implemented on both systems.

- Password Security and Management Policy to ensure that the passwords meet the minimum complexity criteria and are properly managed and secured and are not stored anywhere in plaintext.

- Security Patching and Update Policy to ensure that the version of Operating System and other applications running on the system are updated and patched against known security vulnerabilities. This would evade all possibilities of attacks with known CVE numbers that are launched on vulnerable applications and services.

- Web Security Policy to ensure that the web applications running on the system are secure, sanitize and validate incoming requests and do not make the backend database and host system vulnerable to malicious attackers who try compromising the website through crafted HTTP requests and injections

- Software Procurement and Licensing Policy to ensure that the system is not running a counterfeit operating system but a genuine and licensed version of Windows.
 

- Access Control and Authentication Policy to ensure that anonymous and un-privileged users do not get the admin or root privileges in the system and access levels are properly well defined and thoroughly implemented.