3434import re
3535from hashlib import md5
3636from threading import Thread
37- import Queue
3837
3938#Set a list so we can track whether options are set or not to avoid resetting them in subsequent cals to the options menu.
4039global optionSet
@@ -1499,10 +1498,6 @@ def stealDBs(myDB,mongoConn):
14991498 return
15001499
15011500def accessCheck (ip ,port ,pingIt ):
1502- global success
1503- global versions
1504- global creds
1505- global commError
15061501
15071502 if pingIt == True :
15081503 test = os .system ("ping -c 1 -n -W 1 " + ip + ">/dev/null" )
@@ -1515,32 +1510,22 @@ def accessCheck(ip,port,pingIt):
15151510 dbList = conn .database_names ()
15161511 dbVer = conn .server_info ()['version' ]
15171512 conn .disconnect ()
1518- print "Successful default access on " + ip .rstrip () + "(Mongo Version: " + dbVer + ")."
1519- success .append (ip .rstrip ())
1520- versions .append (dbVer )
1521- return
1513+ return [0 ,dbVer ]
15221514
15231515 except :
15241516 if str (sys .exc_info ()).find ('need to login' ) != - 1 :
15251517 conn .disconnect ()
1526- print "MongoDB running but credentials required on " + ip .rstrip () + "."
1527- creds .append (ip .rstrip ()) #Future use
1528- return
1518+ return [1 ,None ]
15291519
15301520 else :
15311521 conn .disconnect ()
1532- print "Successful MongoDB connection to " + ip .rstrip () + " but error executing command."
1533- commError .append (ip .rstrip ())
1534- return
1522+ return [2 ,None ]
15351523
15361524 except :
1537- print "Couldn't connect to " + ip .rstrip () + "."
1538- return
1539-
1525+ return [3 ,None ]
15401526
15411527 else :
1542- print target .rstrip () + " didn't respond to ping."
1543- return
1528+ return [4 ,None ]
15441529 else :
15451530 try :
15461531 conn = pymongo .MongoClient (ip ,port ,connectTimeoutMS = 4000 ,socketTimeoutMS = 4000 )
@@ -1549,38 +1534,26 @@ def accessCheck(ip,port,pingIt):
15491534 dbList = conn .database_names ()
15501535 dbVer = conn .server_info ()['version' ]
15511536 conn .disconnect ()
1552- print "Successful default access on " + ip .rstrip () + "(Mongo Version: " + dbVer + ")."
1553- success .append (ip .rstrip ())
1554- versions .append (dbVer )
1555- return
1537+ return [0 ,dbVer ]
15561538
15571539 except :
15581540 if str (sys .exc_info ()).find ('need to login' ) != - 1 :
15591541 conn .disconnect ()
1560- print "MongoDB running but credentials required on " + ip .rstrip () + "."
1561- creds .append (ip .rstrip ()) #Future use
1562- return
1542+ return [1 ,None ]
15631543
15641544 else :
15651545 conn .disconnect ()
1566- print "Successful MongoDB connection to " + ip .rstrip () + " but error executing command."
1567- commError .append (ip .rstrip ())
1568- return
1546+ return [2 ,None ]
15691547
15701548 except :
1571- print "Couldn't connect to " + ip .rstrip () + "."
1572- return
1549+ return [3 ,None ]
15731550
15741551
15751552def massMongo ():
15761553 global victim
15771554 optCheck = True
15781555 loadCheck = False
15791556 ping = False
1580- global success
1581- global versions
1582- global creds
1583- global commError
15841557 success = []
15851558 versions = []
15861559 creds = []
@@ -1635,10 +1608,27 @@ def massMongo():
16351608
16361609 print "\n "
16371610 for target in ipList :
1638- #result = accessCheck(target.rstrip(),27017,ping)
1611+ result = accessCheck (target .rstrip (),27017 ,ping )
1612+
1613+ if result [0 ] == 0 :
1614+ print "Successful default access on " + target .rstrip () + "(Mongo Version: " + result [1 ] + ")."
1615+ success .append (target .rstrip ())
1616+ versions .append (result [1 ])
1617+
1618+ elif result [0 ] == 1 :
1619+ print "MongoDB running but credentials required on " + target .rstrip () + "."
1620+ creds .append (target .rstrip ()) #Future use
1621+
1622+ elif result [0 ] == 2 :
1623+ print "Successful MongoDB connection to " + target .rstrip () + " but error executing command."
1624+ commError .append (target .rstrip ()) #Future use
16391625
1640- t = Thread (target = accessCheck , args = (target .rstrip (), 27017 , ping ))
1641- t .start ()
1626+ elif result [0 ] == 3 :
1627+ print "Couldn't connect to " + target .rstrip () + "."
1628+
1629+ elif result [0 ] == 4 :
1630+ print target .rstrip () + " didn't respond to ping."
1631+
16421632
16431633 print "\n \n "
16441634 select = True
0 commit comments