-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathHTTPScan.py
119 lines (98 loc) · 4.83 KB
/
HTTPScan.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
# -*- encoding: utf-8 -*-
#class for HttpScan connection
import socket
import urllib2
import httplib
import socket
import HTMLParser
import socket
import base64
import sys
class HTTPScan:
def basic_auth(self, host, username, passwd, code=0):
try:
request = urllib2.Request(host)
authTokenBase64 = base64.encodestring('%s:%s' % (username, passwd)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % authTokenBase64)
request.add_header("Host", host)
result = urllib2.urlopen(request)
if result is not None:
print 'Found %s:%s\n' %(username, passwd)
except (urllib2.HTTPError,socket.gaierror, socket.error, IOError) as e:
print e
code = 2
return code
def basic_auth2(self, host, username, passwd, code=0):
try:
request = httplib.HTTP(host)
authTokenBase64 = base64.encodestring('%s:%s' % (username, passwd)).replace('\n', '')
request.putheader("Authorization", "Basic %s" % authTokenBase64)
request.putheader("Host", host)
request.endheaders()
request.send("")
statusCode,statusMsg,headers = request.reply()
if statusCode is not None:
print 'Found %s:%s\n' %(username, passwd)
except (urllib2.HTTPError,socket.gaierror, socket.error, IOError) as e:
print e
code = 2
return code
def basic_auth_proxy(self, host, username, passwd, proxy_address, code=0):
try:
proxy = urllib2.ProxyHandler({'http': proxy_address})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
request = urllib2.Request(host)
authTokenBase64 = base64.encodestring('%s:%s' % (username, passwd))[:-1]
request.add_header("Authorization", "Basic %s" % authTokenBase64)
request.add_header("Host", host)
result = urllib2.urlopen(request)
if result is not None:
print 'Found %s:%s\n' %(username, passwd)
except (urllib2.HTTPError,socket.gaierror, socket.error, IOError) as e:
print e
code = 2
return code
def startHTTPScanBruteForce(self,host,ip,proxy):
try:
#check port 80 is open
sock= socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex((ip,80))
if host.startswith("http") == False:
host = "http://"+host
if result == 0:
print "Port 80 open"
print '\n[*] Started scanning \'%s\' \n' % (host)
#open files dictionary
users_file = open("users.txt")
passwords_file = open("passwords.txt")
for user in users_file.readlines():
for password in passwords_file.readlines():
user_text = user.strip("\n")
password_text = password.strip("\n")
try:
#check connection with user and password
if proxy is not None:
response = self.basic_auth_proxy(host,user_text,password_text,proxy)
else:
response = self.basic_auth(host,user_text,password_text)
if response == 0:
print("[*] User: %s [*] Pass Found:%s" %(user_text,password_text))
elif response == 1:
print("[*] User: %s [*] Pass %s => Login incorrect !!!" %(user,password))
elif response == 2:
print("[*] Connection could not be established to %s" %(host))
return 2
except Exception,e:
print e
print "Error http scan"
pass
#close files
users_file.close()
passwords_file.close()
else:
print "Port HTTP 80 closed"
except Exception,e:
print "users.txt /passwords.txt Not found"
pass