Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9be844c

Browse files
committed
Adapted the code to support a list of targets from a text file (Burp log file) or from a directory (WebScarab conversations folder) with command line option -l.
1 parent 80425c9 commit 9be844c

10 files changed

Lines changed: 94 additions & 37 deletions

File tree

lib/controller/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def checkConnection():
308308
try:
309309
kb.defaultResult = Request.queryPage()
310310
except sqlmapConnectionException, exceptionMsg:
311-
if conf.googleDork:
311+
if conf.multipleTargets:
312312
exceptionMsg += ", skipping to next url"
313313
logger.warn(exceptionMsg)
314314
return False

lib/controller/controller.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ def start():
9292
"""
9393

9494
if conf.url:
95-
kb.targetUrls.add(conf.url)
95+
kb.targetUrls[conf.url] = None
9696

9797
if conf.configFile and not kb.targetUrls:
9898
errMsg = "you did not edit the configuration file properly, set "
99-
errMsg += "the target url"
99+
errMsg += "the target url, list of targets or google dork"
100100
logger.error(errMsg)
101101

102102
hostCount = 0
@@ -105,15 +105,17 @@ def start():
105105
cookieStr = ""
106106
setCookieAsInjectable = True
107107

108-
for targetUrl in kb.targetUrls:
109-
if conf.googleDork:
108+
for targetUrl, _ in kb.targetUrls.items():
109+
if conf.multipleTargets:
110110
hostCount += 1
111111

112112
message = "url %d: %s, " % (hostCount, targetUrl)
113113
message += "do you want to test this url? [Y/n/q] "
114114
test = readInput(message, default="Y")
115115

116-
if test[0] in ("n", "N"):
116+
if not test:
117+
pass
118+
elif test[0] in ("n", "N"):
117119
continue
118120
elif test[0] in ("q", "Q"):
119121
break
@@ -166,7 +168,7 @@ def start():
166168
errMsg += "to the user's manual paragraph 'String match' "
167169
errMsg += "for details"
168170

169-
if conf.googleDork:
171+
if conf.multipleTargets:
170172
errMsg += ", skipping to next url"
171173
logger.warn(errMsg)
172174

@@ -219,12 +221,12 @@ def start():
219221
kb.injPlace, kb.injParameter, kb.injType = injDataSelected
220222
setInjection()
221223

222-
if not conf.googleDork and ( not kb.injPlace or not kb.injParameter or not kb.injType ):
224+
if not conf.multipleTargets and ( not kb.injPlace or not kb.injParameter or not kb.injType ):
223225
raise sqlmapNotVulnerableException, "all parameters are not injectable"
224226
elif kb.injPlace and kb.injParameter and kb.injType:
225227
condition = False
226228

227-
if conf.googleDork:
229+
if conf.multipleTargets:
228230
message = "do you want to exploit this SQL injection? [Y/n] "
229231
exploit = readInput(message, default="Y")
230232

lib/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def paramToDict(place, parameters=None):
9797
warnMsg = "the testable parameter '%s' " % paramStr
9898
warnMsg += "you provided is not into the %s" % place
9999

100-
if conf.googleDork:
100+
if conf.multipleTargets:
101101
warnMsg += ", skipping to next url"
102102

103103
logger.warn(warnMsg)

lib/core/dump.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def dbTableValues(self, tableValues):
219219
db = "All"
220220
table = tableValues["__infos__"]["table"]
221221

222-
if not conf.googleDork:
222+
if not conf.multipleTargets:
223223
dumpDbPath = "%s%s%s" % (conf.dumpPath, os.sep, db)
224224

225225
if not os.path.isdir(dumpDbPath):
@@ -259,15 +259,15 @@ def dbTableValues(self, tableValues):
259259
blank = " " * (maxlength - len(column))
260260
self.__write("| %s%s" % (column, blank), n=False)
261261

262-
if not conf.googleDork and field == fields:
262+
if not conf.multipleTargets and field == fields:
263263
dataToDumpFile(dumpFP, "\"%s\"" % column)
264264
else:
265265
dataToDumpFile(dumpFP, "\"%s\"," % column)
266266

267267
field += 1
268268

269269
self.__write("|\n%s" % separator)
270-
if not conf.googleDork:
270+
if not conf.multipleTargets:
271271
dataToDumpFile(dumpFP, "\n")
272272

273273
for i in range(count):
@@ -293,12 +293,12 @@ def dbTableValues(self, tableValues):
293293
field += 1
294294

295295
self.__write("|")
296-
if not conf.googleDork:
296+
if not conf.multipleTargets:
297297
dataToDumpFile(dumpFP, "\n")
298298

299299
self.__write("%s\n" % separator)
300300

301-
if not conf.googleDork:
301+
if not conf.multipleTargets:
302302
dataToDumpFile(dumpFP, "\n")
303303
dumpFP.close()
304304

lib/core/option.py

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,48 @@ def __setGoogleDorking():
129129
raise sqlmapGenericException, errMsg
130130

131131

132+
def __feedTargetsDict(reqFile):
133+
pass
134+
#kb.targetUrls = googleObj.getTargetUrls()
135+
#conf.data
136+
#conf.cookie
137+
138+
139+
def __setMultipleTargets():
140+
"""
141+
Define a configuration parameter if we are running in multiple target
142+
mode.
143+
"""
144+
145+
listType = None
146+
147+
if conf.googleDork or conf.list:
148+
conf.multipleTargets = True
149+
150+
if not conf.list:
151+
return
152+
153+
if not os.path.exists(conf.list):
154+
errMsg = "the specified list of target urls does not exist"
155+
raise sqlmapFilePathException, errMsg
156+
157+
if os.path.isfile(conf.list):
158+
__feedTargetsDict(conf.list)
159+
elif os.path.isdir(conf.list):
160+
files = os.listdir(conf.list)
161+
files.sort()
162+
163+
for reqFile in files:
164+
if not re.search("([\d]+)\-request", reqFile):
165+
continue
166+
167+
__feedTargetsDict(reqFile)
168+
else:
169+
errMsg = "the specified list of target urls is not a file "
170+
errMsg += "nor a directory"
171+
raise sqlmapFilePathException, errMsg
172+
173+
132174
def __setRemoteDBMS():
133175
"""
134176
Checks and set the back-end DBMS option.
@@ -422,20 +464,21 @@ def __setConfAttributes():
422464
debugMsg = "initializing the configuration"
423465
logger.debug(debugMsg)
424466

425-
conf.cj = None
426-
conf.dbmsHandler = None
427-
conf.dumpPath = None
428-
conf.httpHeaders = []
429-
conf.hostname = None
430-
conf.loggedToOut = None
431-
conf.outputPath = None
432-
conf.paramDict = {}
433-
conf.parameters = {}
434-
conf.path = None
435-
conf.port = None
436-
conf.scheme = None
437-
conf.sessionFP = None
438-
conf.start = True
467+
conf.cj = None
468+
conf.dbmsHandler = None
469+
conf.dumpPath = None
470+
conf.httpHeaders = []
471+
conf.hostname = None
472+
conf.loggedToOut = None
473+
conf.multipleTargets = False
474+
conf.outputPath = None
475+
conf.paramDict = {}
476+
conf.parameters = {}
477+
conf.path = None
478+
conf.port = None
479+
conf.scheme = None
480+
conf.sessionFP = None
481+
conf.start = True
439482

440483

441484
def __setKnowledgeBaseAttributes():
@@ -462,7 +505,7 @@ def __setKnowledgeBaseAttributes():
462505
kb.injType = None
463506
kb.parenthesis = None
464507
kb.resumedQueries = {}
465-
kb.targetUrls = set()
508+
kb.targetUrls = {}
466509
kb.timeTest = None
467510
kb.unionComment = ""
468511
kb.unionCount = None
@@ -582,6 +625,7 @@ def init(inputOptions=advancedDict()):
582625
__setHTTPProxy()
583626
__setThreads()
584627
__setRemoteDBMS()
628+
__setMultipleTargets()
585629
__setGoogleDorking()
586630
__urllib2Opener()
587631

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# Family: { "parameter_name": "parameter_datatype",
2929
"Request": {
3030
"url": "string",
31+
"list": "string",
3132
"googleDork": "string",
3233
"testParameter": "string",
3334
"method": "string",

lib/parse/cmdline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def cmdLineParser():
4949

5050
request.add_option("-u", "--url", dest="url", help="Target url")
5151

52+
request.add_option("-l", dest="list", help="List of target urls")
53+
5254
request.add_option("-g", dest="googleDork",
5355
help="Process Google dork results as target urls")
5456

@@ -271,7 +273,7 @@ def cmdLineParser():
271273

272274
(args, _) = parser.parse_args()
273275

274-
if not args.url and not args.googleDork and not args.configFile and not args.updateAll:
276+
if not args.url and not args.list and not args.googleDork and not args.configFile and not args.updateAll:
275277
errMsg = "missing a mandatory parameter ('-u', '-g', '-c' or '--update'), "
276278
errMsg += "-h for help"
277279
parser.error(errMsg)

lib/request/connect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def getPage(**kwargs):
162162
except (urllib2.URLError, socket.error), _:
163163
warnMsg = "unable to connect to the target url"
164164

165-
if conf.googleDork:
165+
if conf.multipleTargets:
166166
warnMsg += ", skipping to next url"
167167
logger.warn(warnMsg)
168168

@@ -174,7 +174,7 @@ def getPage(**kwargs):
174174
except socket.timeout, _:
175175
warnMsg = "connection timed out to the target url"
176176

177-
if conf.googleDork:
177+
if conf.multipleTargets:
178178
warnMsg += ", skipping to next url"
179179
logger.warn(warnMsg)
180180

@@ -188,7 +188,7 @@ def getPage(**kwargs):
188188
warnMsg += "status code, try to force the HTTP User-Agent "
189189
warnMsg += "header with option --user-agent or -a"
190190

191-
if conf.googleDork:
191+
if conf.multipleTargets:
192192
warnMsg += ", skipping to next url"
193193
logger.warn(warnMsg)
194194

lib/utils/google.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,15 @@ def getTargetUrls(self):
6868
your Google dork search results
6969
"""
7070

71-
targetUrls = set()
71+
targetUrls = {}
72+
targetUrlsSet = set()
7273

7374
for match in self.__matches:
7475
if re.search("(.*?)\?(.+)", match, re.I):
75-
targetUrls.add(match)
76+
targetUrlsSet.add(match)
77+
78+
for targetUrl in targetUrlsSet:
79+
targetUrls[targetUrl] = None
7680

7781
return targetUrls
7882

sqlmap.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Target URL.
44
# Example: http://192.168.1.121/sqlmap/mysql/get_int.php?id=1&cat=2
55
# PHP and MySQL (local)
6-
#url = http://127.0.0.1/sqlmap/mysql/get_int.php?id=1
6+
url = http://127.0.0.1/sqlmap/mysql/get_int.php?id=1
77
# PHP and Oracle (local)
88
#url = http://127.0.0.1/sqlmap/oracle/get_int.php?id=1
99
# PHP and PostgreSQL (local)
@@ -18,6 +18,10 @@
1818
#url = http://192.168.192.10/sqlmap/get_int.asp?id=1
1919
# ASP.NET and MySQL (local)
2020
#url = http://192.168.192.10/sqlmap/get_int.aspx?id=1
21+
#url =
22+
23+
# List of targets
24+
list =
2125

2226
# Rather than providing a target url, let Google return target
2327
# hosts as result of your Google dork expression. For a list of Google

0 commit comments

Comments
 (0)