-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
113 lines (104 loc) · 5.35 KB
/
main.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
import requests
import json
import base64
import time
# Variables
shouldStop = False
# Reading the settings.json file
try:
_settings = json.load(open('settings.json', 'r'))
except Exception as e:
print("[ERR] Cannot read the 'settings.json' file.")
pass
# Template Generators
def getHTTPMessageFromTemplate(cResponse):
templateString = ""
with open('./templates/http.txt', 'r') as wF:
templateString = templateString = wF.read()
templateString = templateString.replace("{{type}}", "HTTP")
templateString = templateString.replace("{{protocol}}", cResponse['protocol'])
templateString = templateString.replace("{{from}}", cResponse['client'])
templateString = templateString.replace("{{time}}", cResponse['time'])
templateString = templateString.replace("{{request}}", base64.b64decode(cResponse['data']['request']).decode('utf-8'))
templateString = templateString.replace("{{response}}", base64.b64decode(cResponse['data']['response']).decode('utf-8'))
return templateString
def getDNSMessageFromTemplate(cResponse):
templateString = ""
with open('./templates/dns.txt', 'r') as wF:
templateString = wF.read()
templateString = templateString.replace("{{type}}", "DNS")
templateString = templateString.replace("{{from}}", cResponse['client'])
templateString = templateString.replace("{{domain}}", cResponse['data']['subDomain'])
templateString = templateString.replace("{{time}}", cResponse['time'])
try:
templateString = templateString.replace("{{request}}", base64.b64decode(cResponse['data']['rawRequest']).decode('utf-8'))
except Exception as e:
templateString = templateString.replace("{{request}}", cResponse['data']['rawRequest'])
return templateString
def getSMTPMessageFromTemplate(cResponse):
templateString = ""
with open('./templates/smtp.txt', 'r') as wF:
templateString = wF.read()
templateString = templateString.replace("{{type}}", "SMTP")
templateString = templateString.replace("{{sender}}", cResponse['data']['sender'])
templateString = templateString.replace("{{time}}", cResponse['time'])
templateString = templateString.replace("{{recipients}}", base64.b64decode(cResponse['data']['recipients']).decode('utf-8'))
templateString = templateString.replace("{{message}}", base64.b64decode(cResponse['data']['message']).decode('utf-8'))
templateString = templateString.replace("{{conversation}}", base64.b64decode(cResponse['data']['conversation']).decode('utf-8'))
return templateString
# Discord Message Sender
def sendToDiscord(message):
data = {
"content" : message,
"username" : "bcollabtodiscord"
}
requests.post(_settings['dWebhook'], json=data)
# Checking if the given information is correct
print("[LOG] Sending a test HTTP request to the collaborator domain.")
res = requests.post(f"https://{_settings['cdomain']}/bcollabtodiscord/test", json={"time":time.localtime()})
if (res.status_code == 200):
resContent = res.content.decode()
res = requests.get(f"{_settings['polling-endpoint']}?biid={_settings['biid']}")
if (res.content.decode() == r"{}"):
print("[LOG] Cannot detect the test HTTP request, Burp Polling endpoint haven't detected the HTTP request. Please recheck your configuration.")
if (res.status_code == 200):
cResults = json.loads(res.content.decode())
for cResponse in cResults['responses']:
if (cResponse['protocol'] == 'https' or cResponse['protocol'] == 'http'):
message = getHTTPMessageFromTemplate(cResponse)
elif (cResponse['protocol'] == 'dns'):
message = getDNSMessageFromTemplate(cResponse)
elif (cResponse['protocol'] == 'smtp'):
message = getSMTPMessageFromTemplate(cResponse)
else:
message = json.dumps(cResponse)
sendToDiscord(message=message)
print("[LOG] Sent the test Discord Messages.")
# Main polling loop
print(f"[LOG] Started listening")
while (not shouldStop):
try:
res = requests.get(f"{_settings['polling-endpoint']}?biid={_settings['biid']}")
if (res.content.decode() == r"{}"):
time.sleep(_settings['poll-interval'])
continue
print(f"[LOG] Found {len(cResults['responses'])} Interactions.")
if (res.status_code == 200):
cResults = json.loads(res.content.decode())
for cResponse in cResults['responses']:
if (cResponse['protocol'] == 'https' or cResponse['protocol'] == 'http'):
message = getHTTPMessageFromTemplate(cResponse)
elif (cResponse['protocol'] == 'dns'):
message = getDNSMessageFromTemplate(cResponse)
elif (cResponse['protocol'] == 'smtp'):
message = getSMTPMessageFromTemplate(cResponse)
else:
message = json.dumps(cResponse)
sendToDiscord(message=message)
time.sleep(_settings['poll-interval'])
except Exception as e:
if ('KeyboardInterrupt' in str(e)):
print("[LOG] Script Ended.")
else:
print("[ERR] Something went wrong.")
print(e)