-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDatabase.py
461 lines (407 loc) · 25.1 KB
/
Database.py
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
import csv
import sqlite3
#from peewee import*
from datetime import*
def create_database():
sqlite_db = 'SeeSec.sqlite.sqlite'
print('Creating database: {0}. Version: {1}'.format(sqlite_db, sqlite3.version))
print('Connecting to {0}'.format(sqlite_db))
conn = sqlite3.connect('SeeSec.sqlite')
print('Database connection successful')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS Vulnerability(ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name TEXT,
Status TEXT,
Description TEXT,
CVEReferences TEXT,
Phases TEXT,
Votes TEXT,
Comments TEXT,
FixAvailable INTEGER,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER)
''')
reader = csv.reader(open('IoTVulnerabilities.csv', 'rb'))
int_value = 1
for row in reader:
insert_value = [unicode(row[0], 'utf8'), unicode(row[1], 'utf8'), unicode(row[2], 'utf8'),
unicode(row[3], 'utf8'), unicode(row[4], 'utf8'), unicode(row[5], 'utf8'),
unicode(row[6], 'utf8'), int_value, datetime.now(), datetime.now(), int_value]
cursor.execute('INSERT INTO Vulnerability (Name, Status, Description, CVEReferences, Phases, Votes, Comments, '
'FixAvailable, DateAdded, LastModifiedDate, UseStatus) VALUES(?, ?, ?, ?, ? ,? ,? ,? ,?, ?, ?);',
insert_value)
conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS DeviceBios(ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name TEXT,
Description TEXT,
MacAddress TEXT,
IPAddress TEXT,
Manufacturer TEXT,
Brand TEXT,
Model TEXT,
Type TEXT,
Version TEXT,
OperatingSystem TEXT,
Memory INTEGER,
Capacity INTEGER ,
Accuracy TEXT,
NumberOfServices TEXT,
ManufactureDate TEXT,
LastSoftwareUpdated TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER)
''')
conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS DeviceOSInformation(ID INTEGER PRIMARY KEY AUTOINCREMENT,
DeviceID INTEGER,
OsmatchName TEXT,
OsmatchAccuracy TEXT,
OsmatchLine TEXT,
OsclassType TEXT,
OsclassVendor TEXT,
OsclassOsfamily TEXT,
OsclassOsgen TEXT,
OsclassAccuracy TEXT,
OsclassCPE TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS DeviceHops(ID INTEGER PRIMARY KEY AUTOINCREMENT,
DeviceID INTEGER,
HopTtl TEXT,
HopIpAddress TEXT,
HopRtt TEXT,
HopHost TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS DeviceAddress(ID INTEGER PRIMARY KEY AUTOINCREMENT,
DeviceID INTEGER,
AddressType TEXT,
Address TEXT,
Vendor TEXT,
HopHost TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS DeviceOSPortUsed(ID INTEGER PRIMARY KEY AUTOINCREMENT,
DeviceID INTEGER,
State TEXT,
Proto TEXT,
PortID TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER)
''')
# cursor.execute('''
# CREATE TABLE IF NOT EXISTS DevicePorts(ID INTEGER PRIMARY KEY AUTOINCREMENT,
# DeviceID INTEGER,
# State TEXT,
# Proto TEXT,
# PortID TEXT,
# DateAdded TEXT,
# LastModifiedDate TEXT,
# UseStatus INTEGER)
# ''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS DevicePorts(ID INTEGER PRIMARY KEY AUTOINCREMENT,
DeviceID INTEGER,
Protocol TEXT,
PortID TEXT,
State TEXT,
Reason TEXT,
ReasonTtl TEXT,
ServiceName TEXT,
Products TEXT,
Version TEXT,
ExtraInfo TEXT,
OsType TEXT,
Method TEXT,
Conf TEXT,
Cpe TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS AvailableFixes(ID INTEGER PRIMARY KEY AUTOINCREMENT,
VulnerabilityID INTEGER,
ScannerID INTEGER,
Description TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER)
''')
# fixed_reader = csv.reader(open('AvailableFixes.csv', 'rb'))
# for row in fixed_reader:
# insert_fixes = [unicode(row[0], 'utf8'), unicode(row[1], 'utf8'), unicode(row[2], 'utf8'), datetime.now(),
# datetime.now(), int_value]
#
# cursor.execute('INSERT INTO AvailableFixes (VulnerabilityID, ScannerID, Description, DateAdded,'
# ' LastModifiedDate, UseStatus) VALUES(?, ?, ?, ?, ? , ? ,? ,? ,?);',
# insert_fixes)
# conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS Suggestions(ID INTEGER PRIMARY KEY AUTOINCREMENT,
VulnerabilityID INTEGER,
ScannerID INTEGER,
Description TEXT,
Suggestion TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER)
''')
# suggestions_reader = csv.reader(open('Suggestions.csv', 'rb'))
# for row in suggestions_reader:
# insert_suggestions = [unicode(row[0], 'utf8'), unicode(row[1], 'utf8'), unicode(row[2], 'utf8'),
# unicode(row[3], 'utf8'), datetime.now(), datetime.now(), int_value]
#
# cursor.execute('INSERT INTO Suggestions (VulnerabilityID, ScannerID, Description, Suggestion, DateAdded,'
# ' LastModifiedDate, UseStatus) VALUES(?, ?, ?, ?, ? , ? ,? ,? ,?);',
# insert_suggestions)
# conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS ScanResults(ID INTEGER PRIMARY KEY AUTOINCREMENT,
ScannerID INTEGER,
VulnerabilityID INTEGER,
DeviceID INTEGER,
Description TEXT,
NewPassword TEXT,
Resolved INTEGER,
FixAvailable INTEGER,
Type TEXT,
Version TEXT,
ScanDate TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER
)
''')
conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS Scanners(ID INTEGER PRIMARY KEY,
Name TEXT,
Description TEXT,
Author TEXT,
Function TEXT,
Company TEXT,
Type TEXT,
Version TEXT,
Source TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER
)
''')
scanners_reader = csv.reader(open('Scanners.csv', 'rb'))
int_value2 = 1
for row in scanners_reader:
insert_value_scanners = [unicode(row[0], 'utf8'), unicode(row[1], 'utf8'), unicode(row[2], 'utf8'),
unicode(row[3], 'utf8'), unicode(row[4], 'utf8'), unicode(row[5], 'utf8'),
unicode(row[6], 'utf8'), unicode(row[7], 'utf8'), datetime.now(), datetime.now(),
int_value2]
cursor.execute('INSERT INTO Scanners (Name, Description, Author, Function, Company, Type, '
'Version, Source, DateAdded, LastModifiedDate, UseStatus) VALUES(?, ?, ?, ?, ? ,'
'? ,? ,? ,?, ?, ?);',
insert_value_scanners)
conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS NmapReport(ID INTEGER PRIMARY KEY AUTOINCREMENT,
DeviceID INTEGER,
Services TEXT,
Type TEXT,
Protocol TEXT,
NumberofServices TEXT,
StartTime TEXT,
EndTime TEXT,
State TEXT,
Reason TEXT,
ReasonTtl TEXT,
HostName TEXT,
HostType TEXT,
Seconds TEXT,
LastBoot TEXT,
DistanceValue INTEGER,
TCPIndex TEXT,
TCPDifficulty TEXT,
TCPValues TEXT,
IPIDClass TEXT,
IPIDValues TEXT,
TCPTSClass TEXT,
TCPTSValues TEXT,
TimesSrtt TEXT,
TimesRttvar TEXT,
TimesTo TEXT,
FinishedTime TEXT,
FinishedTimeStr TEXT,
FinishedElapsed TEXT,
FinishedSummary TEXT,
FinishedExit TEXT,
HostsUp TEXT,
HostsDown TEXT,
HostsTotal TEXT,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS MiraiReport(ID INTEGER PRIMARY KEY AUTOINCREMENT,
VulnerabilityID INTEGER,
DeviceID INTEGER,
IPAddress TEXT,
Description TEXT,
ScanTime TEXT,
Response TEXT,
VulnerabilityStatus TEXT,
ScanDate TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER
)
''')
conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS SshScannerReport(ID INTEGER PRIMARY KEY AUTOINCREMENT,
VulnerabilityID INTEGER,
DeviceID INTEGER,
IPAddress TEXT,
Description TEXT,
ScanTime TEXT,
UpTime Text,
PortStatus Text,
Response TEXT,
DefaultPassword TEXT,
Combinations INTEGER,
VulnerabilityStatus TEXT,
ScanDate TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER
)
''')
conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS EncryptionAlgorithms(ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name INTEGER,
EncryptionType TEXT,
Description TEXT,
Vulnerable INTEGER,
RiskLevel TEXT,
VulnerableTo Text,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER
)
''')
encryp_algo_reader = csv.reader(open('EncryptionAlgorithms.csv', 'rb'))
for row in encryp_algo_reader:
insert_encryp_algo = [unicode(row[0], 'utf8'), unicode(row[1], 'utf8'), unicode(row[2], 'utf8'),
unicode(row[3], 'utf8'), unicode(row[4], 'utf8'), unicode(row[5], 'utf8'), datetime.now(),
datetime.now(),
int_value]
cursor.execute('INSERT INTO EncryptionAlgorithms (Name, EncryptionType, Description, Vulnerable, RiskLevel,'
' VulnerableTo, DateAdded, LastModifiedDate, UseStatus) VALUES(?, ?, ?, ?, ? , ? ,? ,? ,?);',
insert_encryp_algo)
conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS OperatingSystems(ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name TEXT,
Description TEXT,
Vulnerable INTEGER,
RiskLevel TEXT,
Version Text,
SafeVersion Text,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER
)
''')
os_reader = csv.reader(open('OperatingSystems.csv', 'rb'))
for row in os_reader:
insert_os = [unicode(row[0], 'utf8'), unicode(row[1], 'utf8'), unicode(row[2], 'utf8'), unicode(row[3], 'utf8'),
unicode(row[4], 'utf8'), unicode(row[5], 'utf8'), datetime.now(), datetime.now(), int_value]
cursor.execute('INSERT INTO OperatingSystems (Name, Description, Vulnerable, RiskLevel, Version, SafeVersion,'
' DateAdded, LastModifiedDate, UseStatus) VALUES(?, ?, ?, ?, ? , ? ,? ,? ,?);',
insert_os)
conn.commit()
cursor.execute('''
CREATE TABLE IF NOT EXISTS DeviceNmapVulnScripts(ID INTEGER PRIMARY KEY AUTOINCREMENT,
DeviceID INTEGER,
ScriptID TEXT,
Output TEXT,
State TEXT,
Title INTEGER,
Key TEXT,
Description TEXT,
Disclosure TEXT,
ExploitsResults Text,
Refs Text,
DateAdded TEXT,
LastModifiedDate TEXT,
UseStatus INTEGER
)
''')
conn.commit()
conn.close()
def is_fix_available(vulnerability_id):
print ('Fix is available for %s', vulnerability_id)
def get_suggestions(vulnerability_id):
print('Suggestions for fixing vulnerability: %s', vulnerability_id)
def insert_scan_results(vulnerability_id, scanner_id, device_id, description, new_password, resolved, fix_available,
scan_type, version):
conn = sqlite3.connect('SeeSec.sqlite')
print('Database connection successful')
cursor = conn.cursor()
insert_value = [vulnerability_id, scanner_id, device_id, description, new_password, resolved, fix_available,
scan_type, version, datetime.now(), datetime.now()]
cursor.execute('INSERT INTO ScanResults (VulnerabilityID, ScannerID, DeviceID, Description, NewPassword, Resolved,'
'FixAvailable, Type, Version, ScanDate, LastModifiedDate) '
'VALUES(?, ?, ?, ?, ? ,? ,? ,? ,?, ?, ?);',
insert_value)
conn.commit()
def upload_new_scanners():
conn = sqlite3.connect('SeeSec.sqlite')
print('Database connection successful')
cursor = conn.cursor()
scanners_reader = csv.reader(open('Scanners.csv', 'rb'))
int_value2 = 1
for row in scanners_reader:
insert_value_scanners = [unicode(row[0], 'utf8'), unicode(row[1], 'utf8'), unicode(row[2], 'utf8'),
unicode(row[3], 'utf8'), unicode(row[4], 'utf8'), unicode(row[5], 'utf8'),
unicode(row[6], 'utf8'), unicode(row[7], 'utf8'), datetime.now(), datetime.now(),
int_value2]
cursor.execute('INSERT INTO Scanners (Name, Description, Author, Function, Company, Type, '
'Version, Source, DateAdded, LastModifiedDate, UseStatus) VALUES(?, ?, ?, ?, ? ,'
'? ,? ,? ,?, ?, ?);',
insert_value_scanners)
conn.commit()
print('New scanner added successfully')
def upload_new_operating_systems():
conn = sqlite3.connect('SeeSec.sqlite')
print('Database connection successful')
cursor = conn.cursor()
int_value = 1
os_reader = csv.reader(open('OperatingSystems.csv', 'rb'))
for row in os_reader:
insert_os = [unicode(row[0], 'utf8'), unicode(row[1], 'utf8'), "N/A", "N/A", "N/A","N/A", datetime.now(),
datetime.now(), int_value]
# insert_os = [unicode(row[0], 'utf8'), unicode(row[1], 'utf8'), unicode(row[2], 'utf8'), unicode(row[3], 'utf8'),
# unicode(row[4], 'utf8'), unicode(row[5], 'utf8'), datetime.now(), datetime.now(), int_value]
cursor.execute('INSERT INTO OperatingSystems (Name, Description, Vulnerable, RiskLevel, Version, SafeVersion,'
' DateAdded, LastModifiedDate, UseStatus) VALUES(?, ?, ?, ?, ? , ? ,? ,? ,?);',
insert_os)
conn.commit()
if __name__ == "__main__":
# insert_scan_results(1, 2, 3, 'description', 'xyz', 1, 1, 'Badlock', 'version')
# create_database()
# upload_new_operating_systems()
print('Database creation completed successfully')