-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
165 lines (139 loc) · 5.6 KB
/
utils.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
'''
Load Balancer Finder - Try to detect load balancers / domain using multiple hosts
Copyright (C) 2011 Alejandro Nolla Blanco - [email protected]
Nick: z0mbiehunt3r - @z0mbiehunt3r
Blog: navegandoentrecolisiones.blogspot.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
'''
import sys
import httplib
import re
class cParams():
'''
Class used to set some parameters
'''
def __init__(self):
'''
Constructor
'''
self.USE_COLOURS = False
self.NORMAL_OUTPUT = None # writer for output, normaly the screen
self.ERROR_OUTPUT = None # writer for outpu, normaly the screen
self.args = []
def get_use_colours(self):
return self.USE_COLOURS
def get_normal_output(self):
return self.NORMAL_OUTPUT
def get_error_output(self):
return self.ERROR_OUTPUT
def set_use_colours(self, value):
self.USE_COLOURS = value
def set_normal_output(self, value):
self.NORMAL_OUTPUT = value
def set_error_output(self, value):
self.ERROR_OUTPUT = value
def del_use_colours(self):
del self.USE_COLOURS
def del_normal_output(self):
del self.NORMAL_OUTPUT
def del_error_output(self):
del self.ERROR_OUTPUT
USE_COLOURS = property(get_use_colours, set_use_colours, del_use_colours, "USE_COLOURS's docstring")
NORMAL_OUTPUT = property(get_normal_output, set_normal_output, del_normal_output, "NORMAL_OUTPUT's docstring")
ERROR_OUTPUT = property(get_error_output, set_error_output, del_error_output, "ERROR_OUTPUT's docstring")
'''
Function used to print some message to file descriptor
@param message: Message to show, format like "[+] Message" or "<-> Message"
@param type: Type of error - info/less/plus/error/verbose
'''
def printMessage(message, type, options):
# Split "prompt" from message like "[!] Some weird error" or like "<-> Some info"
srematch = re.search("(\s*[\[\<].{1}[\]|>])(.+)", message)
message_original = message
prompt = srematch.group(1)
message = srematch.group(2)
if type == "info":
if options.USE_COLOURS:
options.NORMAL_OUTPUT.write(chr(27)+"[0;93m"+prompt+chr(27)+"[0m")
options.NORMAL_OUTPUT.write(message+"\n")
else:
options.NORMAL_OUTPUT.write(message_original+"\n")
elif type == "less":
if options.USE_COLOURS:
options.NORMAL_OUTPUT.write(chr(27)+"[0;34m"+prompt+chr(27)+"[0m")
options.NORMAL_OUTPUT.write(message+"\n")
else:
options.NORMAL_OUTPUT.write(message_original+"\n")
elif type == "plus":
if options.USE_COLOURS:
options.NORMAL_OUTPUT.write(chr(27)+"[0;32m"+prompt+chr(27)+"[0m")
options.NORMAL_OUTPUT.write(message+"\n")
else:
options.NORMAL_OUTPUT.write(message_original+"\n")
elif type == "error":
if options.USE_COLOURS:
options.ERROR_OUTPUT.write(chr(27)+"[0;31m"+prompt+chr(27)+"[0m")
options.ERROR_OUTPUT.write(message+"\n")
else:
options.NORMAL_OUTPUT.write(message_original+"\n")
elif type == "verbose":
if options.USE_COLOURS:
options.NORMAL_OUTPUT.write(chr(27)+"[0;35m"+prompt+chr(27)+"[0m")
options.NORMAL_OUTPUT.write(message+"\n")
else:
options.NORMAL_OUTPUT.write(message+"\n")
'''
Function used to get just one HTTP header
'''
def getHTTPHeader(host, port, ssl, header, useragent, http_timeout, progOptions, url=""):
try:
headers = {'User-agent': useragent,
'Host': host,
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'gzip,deflate',
'Proxy-Connection': 'keep-alive'
}
if not ssl:
conn = httplib.HTTPConnection(host, port, timeout=http_timeout)
conn.request("GET", "http://%s%s" %(host, url), headers=headers)
else:
conn = httplib.HTTPSConnection(host, port, timeout=http_timeout)
conn.request("GET", "https://%s%s" %(host, url), headers=headers)
response = conn.getresponse()
return response.getheader(header)
except KeyboardInterrupt:
printMessage("[!] Aborted by user...", "error", progOptions)
sys.exit()
except Exception, e:
print str(e)
sys.exit()
'''
Function used to read DNS servers from a file
'''
def readDNSServers(dnsserversfile, progOptions):
'''
Google - 8.8.8.8
Advantage - 156.154.70.1
Telefonica - 80.58.61.250
OpenDNS - 208.67.222.222
DNS Advantage - 156.154.70.1
http://www.tech-faq.com/public-dns-servers.html
'''
try:
fd = open(dnsserversfile, "r")
dnsservers = fd.readlines()
fd.close()
return map(str.rstrip,dnsservers)
except IOError:
printMessage("[!] Error al abrir el fichero", "error", progOptions)
sys.exit(0)