Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a86d230

Browse files
remove ALL trailing newlines/CRs as soon as possible from parsed file. Also use 'with' to open files, to ensure file is automatically closed
1 parent de427ca commit a86d230

File tree

1 file changed

+49
-47
lines changed

1 file changed

+49
-47
lines changed

‎nosqlmap.py

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -400,46 +400,51 @@ def options():
400400

401401
elif select == "0":
402402
loadPath = raw_input("Enter file name to load: ")
403+
cvsOpt = []
403404
try:
404-
fo = open(loadPath,"r" )
405-
csvOpt = fo.readlines()
406-
fo.close()
407-
optList = csvOpt[0].split(",")
408-
victim = optList[0]
409-
webPort = optList[1]
410-
uri = optList[2]
411-
httpMethod = optList[3]
412-
myIP = optList[4]
413-
myPort = optList[5]
414-
verb = optList[6]
415-
https = optList[7]
405+
with open(loadPath,"r") as fo:
406+
for line in fo:
407+
cvsOpt.append(line.rstrip())
408+
except IOError as e:
409+
print "I/O error({0}): {1}".format(e.errno, e.strerror)
410+
raw_input("error reading file. Press enter to continue...")
411+
return
412+
413+
optList = csvOpt[0].split(",")
414+
victim = optList[0]
415+
webPort = optList[1]
416+
uri = optList[2]
417+
httpMethod = optList[3]
418+
myIP = optList[4]
419+
myPort = optList[5]
420+
verb = optList[6]
421+
https = optList[7]
422+
423+
# saved headers position will depend of the request verb
424+
headersPos= 1
425+
426+
if httpMethod == "POST":
427+
postData = ast.literal_eval(csvOpt[1])
428+
headersPos = 2
416429

417-
# saved headers position will depend of the request verb
418-
headersPos= 1
419-
420-
if httpMethod == "POST":
421-
postData = ast.literal_eval(csvOpt[1])
422-
headersPos = 2
423-
424-
requestHeaders = ast.literal_eval(csvOpt[headersPos])
425-
426-
# Set option checking array based on what was loaded
427-
x = 0
428-
for item in optList:
429-
if item != "Not Set":
430-
optionSet[x] = True
431-
x += 1
432-
except:
433-
print "Couldn't load options file!"
430+
requestHeaders = ast.literal_eval(csvOpt[headersPos])
431+
432+
# Set option checking array based on what was loaded
433+
x = 0
434+
for item in optList:
435+
if item != "Not Set":
436+
optionSet[x] = True
437+
x += 1
434438

435439
elif select == "a":
436440
loadPath = raw_input("Enter path to Burp request file: ")
437-
441+
reqData= []
438442
try:
439-
fo = open(loadPath,"r")
440-
reqData = fo.readlines()
441-
442-
except:
443+
with open(loadPath,"r") as fo:
444+
for line in fo:
445+
reqData.append(line.rstrip())
446+
except IOError as e:
447+
print "I/O error({0}): {1}".format(e.errno, e.strerror)
443448
raw_input("error reading file. Press enter to continue...")
444449
return
445450

@@ -473,25 +478,22 @@ def options():
473478
header = line.split(": ");
474479
requestHeaders[header[0]] = header[1].strip()
475480

476-
victim = reqData[1].split( " ")[1].replace("\r","")
477-
victim = victim.replace("\n","")
481+
victim = reqData[1].split( " ")[1]
478482
optionSet[0] = True
479-
uri = methodPath[1].replace("\r","")
480-
uri = uri.replace("\n","")
483+
uri = methodPath[1]
481484
optionSet[2] = True
482485

483486
elif select == "b":
484487
savePath = raw_input("Enter file name to save: ")
485488
try:
486-
fo = open(savePath, "wb")
487-
fo.write(str(victim) + "," + str(webPort) + "," + str(uri) + "," + str(httpMethod) + "," + str(myIP) + "," + str(myPort) + "," + verb + "," + https)
488-
489-
if httpMethod == "POST":
490-
fo.write(",\n"+ str(postData))
491-
fo.write(",\n" + str(requestHeaders) )
492-
fo.close()
493-
print "Options file saved!"
494-
except:
489+
with open(savePath, "wb") as fo:
490+
fo.write(str(victim) + "," + str(webPort) + "," + str(uri) + "," + str(httpMethod) + "," + str(myIP) + "," + str(myPort) + "," + verb + "," + https)
491+
492+
if httpMethod == "POST":
493+
fo.write(",\n"+ str(postData))
494+
fo.write(",\n" + str(requestHeaders) )
495+
print "Options file saved!"
496+
except IOError:
495497
print "Couldn't save options file."
496498

497499
elif select == "h":

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /