Skip to content

Commit 0628784

Browse files
author
Cotonne
committed
Add parameters for Web Attack
1 parent 71dcd79 commit 0628784

File tree

5 files changed

+90
-49
lines changed

5 files changed

+90
-49
lines changed

nosqlmap.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ def attack(args):
152152

153153
if args.attack == 1:
154154
if platform == "MongoDB":
155-
nsmmongo.netAttacks(victim, dbPort, myIP, myPort)
155+
nsmmongo.netAttacks(victim, dbPort, myIP, myPort, args)
156156
elif platform == "CouchDB":
157-
nsmcouch.netAttacks(victim, dbPort, myIP)
157+
nsmcouch.netAttacks(victim, dbPort, myIP, args)
158158
elif args.attack == 2:
159159
if httpMethod == "GET":
160-
nsmweb.getApps(webPort,victim,uri,https,verb,requestHeaders)
160+
nsmweb.getApps(webPort,victim,uri,https,verb,requestHeaders, args)
161161
elif httpMethod == "POST":
162-
nsmweb.postApps(victim,webPort,uri,https,verb,postData,requestHeaders)
162+
nsmweb.postApps(victim,webPort,uri,https,verb,postData,requestHeaders, args)
163163
elif args.attack == 3:
164164
scanResult = nsmscan.massScan(platform)
165165
if scanResult != None:
@@ -514,6 +514,12 @@ def build_parser():
514514
parser.add_argument("--verb", help="Toggle Verbose Mode", choices=["ON", "OFF"], default="OFF")
515515
parser.add_argument("--postData", help="Enter POST data in a comma separated list (i.e. param name 1,value1,param name 2,value2)", default="")
516516
parser.add_argument("--requestHeaders", help="Request headers in a comma separated list (i.e. param name 1,value1,param name 2,value2)", default="")
517+
518+
modules = [nsmcouch, nsmmongo, nsmscan, nsmweb]
519+
for module in modules:
520+
for arg in module.args():
521+
parser.add_argument(arg[0], help=arg[1])
522+
517523
return parser
518524

519525
def signal_handler(signal, frame):

nsmcouch.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
yes_tag = ['y', 'Y']
2222
no_tag = ['n', 'N']
2323

24+
def args():
25+
return []
2426

2527
def couchScan(target,port,pingIt):
2628
if pingIt == True:
@@ -63,8 +65,7 @@ def couchScan(target,port,pingIt):
6365
except:
6466
return [3,None]
6567

66-
67-
def netAttacks(target,port, myIP):
68+
def netAttacks(target,port, myIP, args = None):
6869
print "DB Access attacks (CouchDB)"
6970
print "======================"
7071
mgtOpen = False

nsmmongo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
yes_tag = ['y', 'Y']
1919
no_tag = ['n', 'N']
2020

21+
def args():
22+
return []
2123

22-
def netAttacks(target, dbPort, myIP, myPort):
24+
def netAttacks(target, dbPort, myIP, myPort, args = None):
2325
print "DB Access attacks (MongoDB)"
2426
print "================="
2527
mgtOpen = False

nsmscan.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import nsmmongo
88
import nsmcouch
99

10+
def args():
11+
return []
1012

11-
def massScan(platform):
13+
def massScan(platform, args = None):
1214
yes_tag = ['y', 'Y']
1315
no_tag = ['n', 'N']
1416
optCheck = True

nsmweb.py

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
ssl._create_default_https_context = ssl._create_unverified_context
2020

2121

22-
def getApps(webPort,victim,uri,https,verb,requestHeaders):
22+
def args():
23+
return [
24+
["--injectSize", "Size of payload"],
25+
["--injectFormat", "1-Alphanumeric, 2-Letters only, 3-Numbers only, 4-Email address"],
26+
["--params", "Enter parameters to inject in a comma separated list"],
27+
["--doTimeAttack", "Start timing based tests (y/n)"]]
28+
29+
def getApps(webPort,victim,uri,https,verb,requestHeaders, args = None):
2330
print "Web App Attacks (GET)"
2431
print "==============="
2532
paramName = []
@@ -81,25 +88,32 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
8188

8289
if appUp == True:
8390

84-
sizeSelect = True
91+
if args == None:
92+
sizeSelect = not injectSize.isdigit()
8593

86-
while sizeSelect:
87-
injectSize = raw_input("Baseline test-Enter random string size: ")
88-
if injectSize.isdigit():
89-
sizeSelect = False
90-
else:
91-
print "Invalid! The size should be an integer."
94+
while sizeSelect:
95+
injectSize = raw_input("Baseline test-Enter random string size: ")
96+
sizeSelect = not injectSize.isdigit()
97+
if sizeSelect:
98+
print "Invalid! The size should be an integer."
99+
100+
format = randInjString(int(injectSize))
101+
else:
102+
injectSize = int(args.injectSize)
103+
format = args.injectFormat
104+
105+
injectString = build_random_string(format, injectSize)
92106

93-
injectString = randInjString(int(injectSize))
94107
print "Using " + injectString + " for injection testing.\n"
95108

96109
# Build a random string and insert; if the app handles input correctly, a random string and injected code should be treated the same.
97110
if "?" not in appURL:
98111
print "No URI parameters provided for GET request...Check your options.\n"
99-
raw_input("Press enter to continue...")
112+
if args == None:
113+
raw_input("Press enter to continue...")
100114
return()
101115

102-
randomUri = buildUri(appURL,injectString)
116+
randomUri = buildUri(appURL,injectString, args)
103117
print "URI : " + randomUri
104118
req = urllib2.Request(randomUri, None, requestHeaders)
105119

@@ -260,8 +274,10 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
260274
checkResult(randLength,injLen,testNum,verb,None)
261275
testNum += 1
262276

263-
264-
doTimeAttack = raw_input("Start timing based tests (y/n)? ")
277+
if args == None:
278+
doTimeAttack = raw_input("Start timing based tests (y/n)? ")
279+
else:
280+
doTimeAttack = args.doTimeAttack
265281

266282
if doTimeAttack.lower() == "y":
267283
print "Starting Javascript string escape time based injection..."
@@ -323,7 +339,10 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
323339
else:
324340
print "Integer attack-Unsuccessful"
325341

326-
fileOut = raw_input("Save results to file (y/n)? ")
342+
if args == None:
343+
fileOut = raw_input("Save results to file (y/n)? ")
344+
else:
345+
fileOut = "n"
327346

328347
if fileOut.lower() == "y":
329348
savePath = raw_input("Enter output file name: ")
@@ -349,7 +368,8 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders):
349368
fo.write("\n")
350369
fo.close()
351370

352-
raw_input("Press enter to continue...")
371+
if args == None:
372+
raw_input("Press enter to continue...")
353373
return()
354374

355375

@@ -430,20 +450,25 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
430450
menuItem += 1
431451

432452
try:
433-
injIndex = raw_input("Which parameter should we inject? ")
453+
injIndex = 1
454+
if args == None:
455+
injIndex = raw_input("Which parameter should we inject? ")
456+
434457
injOpt = str(postData.keys()[int(injIndex)-1])
435458
print "Injecting the " + injOpt + " parameter..."
436459
except:
437-
raw_input("Something went wrong. Press enter to return to the main menu...")
460+
if args == None:
461+
raw_input("Something went wrong. Press enter to return to the main menu...")
438462
return
439463

440-
sizeSelect = True
464+
465+
sizeSelect = (args == None)
466+
injectSize = 1000
441467

442468
while sizeSelect:
443469
injectSize = raw_input("Baseline test-Enter random string size: ")
444-
if injectSize.isdigit():
445-
sizeSelect = False
446-
else:
470+
sizeSelect = not injectSize.isdigit()
471+
if sizeSelect:
447472
print "Invalid! The size should be an integer."
448473

449474
injectString = randInjString(int(injectSize))
@@ -454,7 +479,6 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
454479
postData.update({injOpt:injectString})
455480
if verb == "ON":
456481
print "Checking random injected parameter HTTP response size sending " + str(postData) +"...\n"
457-
458482
else:
459483
print "Sending random parameter value..."
460484

@@ -641,7 +665,9 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders):
641665
testNum += 1
642666
print "\n"
643667

644-
doTimeAttack = raw_input("Start timing based tests (y/n)? ")
668+
doTimeAttack = "N"
669+
if args == None:
670+
doTimeAttack = raw_input("Start timing based tests (y/n)? ")
645671

646672
if doTimeAttack == "y" or doTimeAttack == "Y":
647673
print "Starting Javascript string escape time based injection..."
@@ -849,28 +875,29 @@ def randInjString(size):
849875

850876
while format:
851877
format = raw_input("Select an option: ")
878+
if format not in ["1", "2", "3", "4"]:
879+
format = True
880+
print "Invalid selection."
881+
return format
852882

853-
if format == "1":
854-
chars = string.ascii_letters + string.digits
855-
return ''.join(random.choice(chars) for x in range(size))
856-
857-
elif format == "2":
858-
chars = string.ascii_letters
859-
return ''.join(random.choice(chars) for x in range(size))
883+
def build_random_string(format, size):
884+
if format == "1":
885+
chars = string.ascii_letters + string.digits
886+
return ''.join(random.choice(chars) for x in range(size))
860887

861-
elif format == "3":
862-
chars = string.digits
863-
return ''.join(random.choice(chars) for x in range(size))
888+
elif format == "2":
889+
chars = string.ascii_letters
890+
return ''.join(random.choice(chars) for x in range(size))
864891

865-
elif format == "4":
866-
chars = string.ascii_letters + string.digits
867-
return ''.join(random.choice(chars) for x in range(size)) + '@' + ''.join(random.choice(chars) for x in range(size)) + '.com'
868-
else:
869-
format = True
870-
print "Invalid selection."
892+
elif format == "3":
893+
chars = string.digits
894+
return ''.join(random.choice(chars) for x in range(size))
871895

896+
else: # format == "4":
897+
chars = string.ascii_letters + string.digits
898+
return ''.join(random.choice(chars) for x in range(size)) + '@' + ''.join(random.choice(chars) for x in range(size)) + '.com'
872899

873-
def buildUri(origUri, randValue):
900+
def buildUri(origUri, randValue, args=None):
874901
paramName = []
875902
paramValue = []
876903
global uriArray
@@ -898,7 +925,10 @@ def buildUri(origUri, randValue):
898925
menuItem += 1
899926

900927
try:
901-
injIndex = raw_input("Enter parameters to inject in a comma separated list: ")
928+
if args == None:
929+
injIndex = raw_input("Enter parameters to inject in a comma separated list: ")
930+
else:
931+
injIndex = args.params
902932

903933
for params in injIndex.split(","):
904934
injOpt.append(paramName[int(params)-1])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy