-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
daemon_endpoints.py
executable file
·129 lines (93 loc) · 2.72 KB
/
daemon_endpoints.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
#!/usr/bin/python
import os
import sys
import time
import subprocess
from colored import fg, bg, attr
#
# print banner
#
def banner():
print("""
_
__| | _ __ ___ _ __ _ _ _ __ _ _
/ _` | | '_ \ / __| | '_ \ | | | | | '_ \ | | | |
| (_| | | | | | \__ \ | |_) | | |_| | _ | |_) | | |_| |
\__,_| |_| |_| |___/ | .__/ \__, | (_) | .__/ \__, |
|_| |___/ |_| |___/
by @gwendallecoguic
""")
pass
#
# usage
#
def usage( error="" ):
sys.stdout.write( "Usage: %s\n" % sys.argv[0] )
if len(error):
sys.stdout.write( "Error: %s\n" % error )
sys.exit(-1)
#
# remove the n first lines of the input file
#
def truncateFile( file, n_lines ):
sys.stdout.write( "[+] removing %d lines from %s\n" % (n_lines,file) )
cmd = "sed -i -e '1," + str(n_lines) + "d' " + file
print( cmd )
try:
output = subprocess.check_output( cmd, shell=True ).decode('utf-8')
except Exception as e:
sys.stdout.write( "%s[-] error occurred: %s%s\n" % (fg('red'),e,attr(0)) )
return
#
# run the subdomain grabber
#
def runGrabber( domain ):
cmd = dnspy_dir + '/grabber_endpoints.sh ' + domain
print( cmd )
try:
output = subprocess.check_output( cmd, shell=True ).decode('utf-8')
except Exception as e:
sys.stdout.write( "%s[-] %s error occurred: %s%s\n" % (fg('red'),domain,e,attr(0)) )
return False
return True
#
# run the whole shit for a single domain
#
def runDomain( domain ):
print( "handling "+domain )
if not runGrabber( domain ):
return
return
#
# MAIN
#
loop_sleep = 5
read_lines = 1
dnspy_dir = os.path.dirname( os.path.abspath(__file__) )
domains_dir = dnspy_dir + '/domains'
queue_file = dnspy_dir + '/queue_endpoints'
if not os.path.isfile(queue_file):
fp = open( queue_file, 'w' )
fp.close()
n_loop = 1
while( n_loop ):
time.sleep( loop_sleep )
sys.stdout.write( "[*] running loop %d\n" % n_loop )
n_loop += 1
cmd = 'head -n ' + str(read_lines) + ' ' + queue_file
print( cmd )
try:
output = subprocess.check_output( cmd, shell=True ).decode('utf-8')
except Exception as e:
sys.stdout.write( "%s[-] error occurred: %s%s\n" % (fg('red'),e,attr(0)) )
continue
output = output.strip()
if not len(output):
sys.stdout.write( "[-] %s input file is empty\n" % queue_file )
# time.sleep( 3 )
continue
t_output = output.split("\n")
sys.stdout.write( "[+] %d domains to test\n" % len(t_output) )
for domain in t_output:
runDomain( domain )
truncateFile( queue_file, read_lines )