-
Notifications
You must be signed in to change notification settings - Fork 9
/
chaosprogram.py
101 lines (84 loc) · 3.26 KB
/
chaosprogram.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
#!/usr/bin/env python3
import requests, socket, random, string, os, subprocess, sys
twhite = '\033[40m'
tgood = '\033[32m'
tnormal = '\033[33m'
tbad = '\033[31m'
talert = '\033[31m'
tend = '\033[m'
def get_random_string(length):
letters = string.ascii_lowercase
result_str = ''.join(random.choice(letters) for i in range(length))
#print("Random string of length", length, "is:", result_str)
return result_str
url = 'https://raw.githubusercontent.com/projectdiscovery/public-bugbounty-programs/master/chaos-bugbounty-list.json'
r = requests.get(url)
data = r.json()
programs_to_add_count = 0
domains_to_add_count = 0
pr = open ('./programs.txt', 'r')
plist = pr.readlines()
pr.close()
programadd = str(sys.argv[1]).lower()
for (k,v) in data.items():
for program in v:
found = False
program_name = program['name'].replace(" ","_").replace("(","").replace(")","").replace("&","and").replace("'","").replace("!","").replace(",","").lower()
if program_name == programadd:
print(tgood,'\n---- Program: '+program_name,tend)
for line in plist:
line = line.rstrip('\n')
if line == program_name:
print(tnormal,'--- Program %s already in autofd'%(line),tend)
found = True
print('found: '+str(found))
if not found:
print(tgood,'--- Adding %s to autofd'%(program_name),tend)
try:
FNULL = open(os.devnull, 'w')
proc = subprocess.call(['./autofd.py', 'add', program_name],stdout=FNULL, stderr=subprocess.STDOUT)
except OSError as e:
print (e.output)
found = False
valid_domains=0
domains_to_add=[]
domains = program['domains']
for domain in domains:
domain.replace(" ","_").replace("(","").replace(")","").replace("&","and").replace("'","").replace("!","").replace(",","").lower()
print('Domain: '+domain)
testdomain = get_random_string(12)+'.'+domain
print(tnormal,'Testing for wildcard domain using: %s'%(testdomain),tend)
try:
ip = socket.gethostbyname(testdomain)
except Exception as e:
print(tgood,'No IP resolution for %s, %s will be added to autofd'%(testdomain, domain),tend)
domains_to_add.append(domain)
valid_domains += 1
else:
print(tbad,'Received IP resolution for %s pointing to %s. %s will not be added to autofd'%(testdomain,ip,domain),tend)
if valid_domains > 0:
dr = open('./programs/'+program_name+'/domains.txt')
dlist = dr.readlines()
dr.close()
for domain in domains_to_add:
for line in dlist:
line = line.rstrip('\n')
if line == domain:
print(tnormal,'--- Domain %s already in program %s'%(domain,program_name),tend)
found = True
if not found:
print(tgood,'--- Adding %s to program %s'%(domain,program_name),tend)
try:
FNULL = open(os.devnull, 'w')
proc = subprocess.call(['./autofd.py', 'add-domain', program_name, domain],stdout=FNULL, stderr=subprocess.STDOUT)
except OSError as e:
print (e.output)
found = False
else:
print(tbad,'Will not add this program to autofd',tend)
domains_to_add_count += valid_domains
print(tgood,'Adding %s new programs to autofd with a total of %s domain'%(str(programs_to_add_count),str(domains_to_add_count)),tend)
#print(program['domains'])
#program = v[key]['name']
#print(type(program))
#print(program)