forked from codingo/NoSQLMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnsmscan.py
More file actions
163 lines (126 loc) · 4.97 KB
/
nsmscan.py
File metadata and controls
163 lines (126 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python
#NoSQLMap Copyright 2016 Russell Butturini
#This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
import ipcalc
import nsmmongo
import nsmcouch
def massScan(platform):
yes_tag = ['y', 'Y']
no_tag = ['n', 'N']
optCheck = True
loadCheck = False
ping = False
success = []
versions = []
creds = []
commError = []
ipList = []
resultSet = []
print "\n"
print platform + " Default Access Scanner"
print "=============================="
print "1-Scan a subnet for default " + platform + " access"
print "2-Loads IPs to scan from a file"
print "3-Enable/disable host pings before attempting connection"
print "x-Return to main menu"
while optCheck:
loadOpt = raw_input("Select an option: ")
if loadOpt == "1":
subnet = raw_input("Enter subnet to scan: ")
try:
for ip in ipcalc.Network(subnet):
ipList.append(str(ip))
optCheck = False
except:
raw_input("Not a valid subnet. Press enter to return to main menu.")
return
if loadOpt == "2":
while loadCheck == False:
loadPath = raw_input("Enter file name with IP list to scan: ")
try:
with open (loadPath) as f:
ipList = f.readlines()
loadCheck = True
optCheck = False
except:
print "Couldn't open file."
if loadOpt == "3":
if ping == False:
ping = True
print "Scan will ping host before connection attempt."
elif ping == True:
ping = False
print "Scan will not ping host before connection attempt."
if loadOpt == "x":
return
print "\n"
for target in ipList:
if platform == "MongoDB":
result = nsmmongo.mongoScan(target.rstrip(),27017,ping)
elif platform == "CouchDB":
result = nsmcouch.couchScan(target.rstrip(),5984,ping)
if result[0] == 0:
print "Successful default access on " + target.rstrip() + "(" + platform + " Version: " + result[1] + ")."
success.append(target.rstrip())
versions.append(result[1])
elif result[0] == 1:
print platform + " running but credentials required on " + target.rstrip() + "."
creds.append(target.rstrip()) #Future use
elif result[0] == 2:
print "Successful " + platform + " connection to " + target.rstrip() + " but error executing command."
commError.append(target.rstrip()) #Future use
elif result[0] == 3:
print "Couldn't connect to " + target.rstrip() + "."
elif result[0] == 4:
print target.rstrip() + " didn't respond to ping."
print "\n\n"
select = True
while select:
saveEm = raw_input("Save scan results to CSV? (y/n):")
if saveEm in yes_tag:
savePath = raw_input("Enter file name to save: ")
outCounter = 0
try:
fo = open(savePath, "wb")
fo.write("IP Address," + platform + " Version\n")
for server in success:
fo.write(server + "," + versions[outCounter] + "\n" )
outCounter += 1
fo.close()
print "Scan results saved!"
select = False
except:
print "Couldn't save scan results."
elif saveEm in no_tag:
select = False
else:
select = True
print "Discovered " + platform + " Servers with No Auth:"
print "IP" + " " + "Version"
outCounter= 1
for server in success:
print str(outCounter) + "-" + server + " " + versions[outCounter - 1]
outCounter += 1
select = True
print "\n"
while select:
select = raw_input("Select a NoSQLMap target or press x to exit: ")
if select == "x" or select == "X":
return None
elif select.isdigit() == True and int(select) <= outCounter:
victim = success[int(select) - 1]
resultSet[0] = True
resultSet[1] = victim
raw_input("New target set! Press enter to return to the main menu.")
return resultSet
else:
raw_input("Invalid selection.")