-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrimson_recon.py
221 lines (183 loc) · 6.14 KB
/
crimson_recon.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import sys
import argparse
import subprocess
import pathlib
import requests
import re
import os
import time
import datetime
from bs4 import BeautifulSoup
ts = time.time()
sttime = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d_%H:%M:%S')
print("Started crimson recon @ "+ sttime)
resultsDir = str(os.getcwd())+"/results"
wordlistFolder = str(os.getcwd())+"/wordlists"
if not os.path.exists(resultsDir):
os.makedirs(resultsDir)
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--domain", help="Domain to perform recon on",
required=True)
parser.add_argument("-i", "--inscope", help="In-scope regex file")
parser.add_argument("-o", "--outscope", help="Out-scope regex file")
parser.add_argument("-na", "--noasn", action='store_true', help="Skip ASN parsing")
args = parser.parse_args()
print ("Parsing: " + args.domain)
name = (args.domain.split("."))[0]
inscopeList = list()
if args.inscope:
with open(args.inscope) as fp:
inscopeList += fp.read().splitlines()
outscopeList = list()
if args.outscope:
with open(args.outscope) as fp:
outscopeList += fp.read().splitlines()
companyDir = resultsDir+"/"+name
if not os.path.exists(companyDir):
os.makedirs(companyDir)
amassDir = str(pathlib.Path.home())+"/tools/amass"
if not args.noasn:
print ("Retrieving asn list")
process = subprocess.run([amassDir+"/amass intel -org "+name],
cwd=amassDir,
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True)
asnList = process.stdout.split("\n")
asnResults = companyDir+"/"+name+"_asns.txt"
with open(asnResults, 'w') as f:
for asn in asnList:
f.write("%s\n" % asn)
print("asn found: ==> " + str(asnList))
cidrList = list()
domainList = list()
print ("Retrieving cidr for each asn found")
for asn in asnList:
print ("Processing asn: ==> "+asn)
asnNumber = (asn.split(","))[0]
regEx = "([0-9.]+){4}/[0-9]+"
whoisCommand = "whois -h whois.radb.net -- '-i origin "+asnNumber+" ' | grep -Eo \""+regEx+"\" | sort -u"
whoProcess = subprocess.run([whoisCommand],
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True)
cidrArray = whoProcess.stdout.split("\n")
cidrList += cidrArray
amassProcess = subprocess.run([amassDir+"/amass intel -asn "+asnNumber],
cwd=amassDir,
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True)
asnDomainList = amassProcess.stdout.split("\n")
domainList+=asnDomainList
print("asnDomainList: "+asn+"==> "+str(asnDomainList))
#break
cidrSet = set(list(filter(None, cidrList)))
cidrResults = companyDir+"/"+name+"_cidrs.txt"
with open(cidrResults, 'w') as f:
for cidr in cidrSet:
f.write("%s\n" % cidr)
print("cidr: ==> "+str(cidrSet))
print ("Retrieving subdomains for each cidr")
for cidr in cidrSet:
amassProcess = subprocess.run([amassDir+"/amass intel -cidr "+cidr],
cwd=amassDir,
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True)
cidrDomainList = amassProcess.stdout.split("\n")
domainList+=cidrDomainList
print("cidrDomainList: "+cidr+"==> "+str(cidrDomainList))
#break
domainSet = set(list(filter(None, domainList)))
print ("Found domains ==> "+str(domainSet))
if inscopeList or outscopeList:
print ("Filtering out of scope domains")
removalCandidates = list()
for domain in domainSet:
if outscopeList and not inscopeList:
inScope = True
else:
inScope = False
if inscopeList:
for scope in inscopeList:
m = re.search(scope, domain)
if m:
inScope = True
break
if outscopeList:
for scope in outscopeList:
m = re.search(scope, domain)
if m:
inScope = False
break
if not inScope:
removalCandidates.append(domain)
for removalDomain in removalCandidates:
domainSet.remove(removalDomain)
print(domainSet)
else:
print ("Skipping asn asset discovery")
subdomainList = list()
print ("passively scraping subdomains using amass enum")
amassProcess = subprocess.run([amassDir+"/amass enum -passive -d "+args.domain],
cwd=amassDir,
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True)
amassSubdomainList = amassProcess.stdout.split("\n")
subdomainList+=amassSubdomainList
print ("Brute forcing domain names using gobuster")
process = subprocess.run(["gobuster dns -d "+args.domain+" -z -q -w "+wordlistFolder+"/subdomains-top1million-5000.txt"],
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True)
gobustedSubdomains = process.stdout.split("\n")
print (gobustedSubdomains)
for goDomain in gobustedSubdomains:
m = re.search('Found: (.*)', goDomain)
if m:
subdomainList.append(m.group(1))
subdomainSet = set(list(filter(None, subdomainList)))
print ("Found subdomains")
if inscopeList or outscopeList:
print ("Filtering out of scope subdomains")
removalCandidates = list()
for domain in subdomainSet:
if outscopeList and not inscopeList:
inScope = True
else:
inScope = False
if inscopeList:
for scope in inscopeList:
m = re.search(scope, domain)
if m:
inScope = True
break
if outscopeList:
for scope in outscopeList:
m = re.search(scope, domain)
if m:
inScope = False
break
if not inScope:
removalCandidates.append(domain)
for removalDomain in removalCandidates:
subdomainSet.remove(removalDomain)
print("Filtered subdomain list")
print(subdomainSet)
companyDir = resultsDir+"/"+name
if not os.path.exists(companyDir):
os.makedirs(companyDir)
domainResults = companyDir+"/"+name+"_domains.txt"
with open(domainResults, 'w') as f:
for domain in domainSet:
f.write("%s\n" % domain)
subDomainResults = companyDir+"/"+name+"_subdomains.txt"
with open(subDomainResults, 'w') as f:
for subdomain in subdomainSet:
f.write("%s\n" % subdomain)
ts = time.time()
sttime = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d_%H:%M:%S - ')
with open(companyDir+"/"+name+"_lastrun.txt", 'w') as f:
f.write(sttime+"\n")