-
Notifications
You must be signed in to change notification settings - Fork 0
/
Network_Scanner.html
204 lines (184 loc) · 13.6 KB
/
Network_Scanner.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module Network_Scanner</title>
<meta charset="utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>Network_Scanner</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/isaidnocookies/Documents/Development/NetworkScanner/Network_Scanner.py">/home/isaidnocookies/Documents/Development/NetworkScanner/Network_Scanner.py</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="xml.etree.ElementTree.html">xml.etree.ElementTree</a><br>
<a href="argparse.html">argparse</a><br>
<a href="datetime.html">datetime</a><br>
<a href="json.html">json</a><br>
</td><td width="25%" valign=top><a href="logging.html">logging</a><br>
<a href="os.html">os</a><br>
<a href="pickle.html">pickle</a><br>
<a href="signal.html">signal</a><br>
</td><td width="25%" valign=top><a href="sqlite3.html">sqlite3</a><br>
<a href="subprocess.html">subprocess</a><br>
<a href="sys.html">sys</a><br>
<a href="time.html">time</a><br>
</td><td width="25%" valign=top><a href="xmltodict.html">xmltodict</a><br>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="Network_Scanner.html#Network_Scanner">Network_Scanner</a>
</font></dt></dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Network_Scanner">class <strong>Network_Scanner</strong></a></font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Network_Scanner-__del__"><strong>__del__</strong></a>(self)</dt><dd><tt>Destructor:<br>
Attempts to close database connection when instance is destroyed.</tt></dd></dl>
<dl><dt><a name="Network_Scanner-__init__"><strong>__init__</strong></a>(self)</dt><dd><tt>Constructor:<br>
Establishes timestamp for instance, logging, and initializing some instance variables.</tt></dd></dl>
<dl><dt><a name="Network_Scanner-getConfig"><strong>getConfig</strong></a>(self)</dt><dd><tt>Returns the configuration object. REQUIRES loadConfig to be called<br>
on the object for initialization.<br>
<br>
Returns:<br>
Object - {}<br>
Return the configuration object from the class instance.</tt></dd></dl>
<dl><dt><a name="Network_Scanner-getTargetFiles"><strong>getTargetFiles</strong></a>(self)</dt><dd><tt>Returns the target filenames. REQUIRES loadTargetFiles to be called<br>
on the object for initialization.<br>
<br>
Returns:<br>
Array of strings - [strings]<br>
Returns an array of strings representing all of the target lists</tt></dd></dl>
<dl><dt><a name="Network_Scanner-initializeSqlite"><strong>initializeSqlite</strong></a>(self, filename<font color="#909090">=''</font>)</dt><dd><tt>Initializes the SQLite database. This function connects to / creates the sqlite database file and creates<br>
the status table that holds the associated scans<br>
<br>
Parameters:<br>
Filname : string<br>
Filename associated with the sqlite database. If this does not exist, the db will be created.<br>
<br>
Returns:<br>
Boolean<br>
Returns if the function was success in pulling the files from the target_directory</tt></dd></dl>
<dl><dt><a name="Network_Scanner-initializeSqliteScanData"><strong>initializeSqliteScanData</strong></a>(self)</dt><dd><tt>Initializes the database and populates the scans table with data from the target_directory.<br>
NOTE - This will drop the data from the existing scans table<br>
This function generates the scans table - (target_file, status, start_timestamp, end_timestamp)<br>
<br>
Parameters:<br>
N/A<br>
<br>
Returns:<br>
N/A</tt></dd></dl>
<dl><dt><a name="Network_Scanner-loadConfig"><strong>loadConfig</strong></a>(self, filename<font color="#909090">='./config.json'</font>)</dt><dd><tt>Sets the configuration within the class instance.<br>
<br>
Parameters:<br>
filename : string<br>
Filename of the configuration (json) file.<br>
Defaults to config.json in the scripts root directory<br>
<br>
Returns:<br>
N/A</tt></dd></dl>
<dl><dt><a name="Network_Scanner-loadTargetFiles"><strong>loadTargetFiles</strong></a>(self)</dt><dd><tt>Loads files from the target directory specified in the configuration file. This will set the input files<br>
to the targetFiles variable (array of strings) within the instance.<br>
<br>
Parameters:<br>
N/A<br>
<br>
Returns:<br>
Boolean<br>
Returns if the function was success in pulling the files from the target_directory</tt></dd></dl>
<dl><dt><a name="Network_Scanner-nmapScan"><strong>nmapScan</strong></a>(self, target_file)</dt><dd><tt>Runs an nmap scan with the -sT, -Pn flags on the ip addresses included in the specified target file.<br>
The results are parsed from xml to a json object for later manipulation and storage.<br>
Nmap scans on the ports specified in the configuration file.<br>
<br>
Parameters:<br>
target_file : string<br>
Filename of the target file. Ip addresses / networks are pulled from this file. Any format<br>
compatible with nmap input lists can be used<br>
<br>
Returns:<br>
Object - json<br>
Nmap data that has been converted from the XML dat</tt></dd></dl>
<dl><dt><a name="Network_Scanner-saveDataInDatabase"><strong>saveDataInDatabase</strong></a>(self, targetFilename, scanData)</dt><dd><tt>Saves data to the database in the appropiate table. Each table corresponds to an individual scan.<br>
DB Schema - (ip_address TEXT, hostname TEXT, port TEXT, protocol TEXT, service TEXT, state TEXT)<br>
<br>
Parameters:<br>
targetFilename : string<br>
target filename associated with the completed scan. This will become the scan's table name<br>
scanData : Object<br>
The data associated with the completed nmap scan. This will be in JSON / Object format from the XML parsing<br>
<br>
Returns:<br>
N/A</tt></dd></dl>
<dl><dt><a name="Network_Scanner-scanFromDB"><strong>scanFromDB</strong></a>(self)</dt><dd><tt>Runs nmap scans from pending entries in the database. This function will loop through the database scan entries<br>
and run scans associated with pending target lists. If there is an In Progress scan, it will not resume it -- yet<br>
<br>
This function will also dump scan data into a temp directory. Each scan will be associated with an output dump (in<br>
the Object format) in the specified folder.<br>
<br>
This function calls the saveDataInDatabase function and will initialize the Sqlite database if the dbInit variable<br>
has not been set.<br>
<br>
Parameters:<br>
N/A<br>
<br>
Returns:<br>
N/A</tt></dd></dl>
<hr>
Static methods defined here:<br>
<dl><dt><a name="Network_Scanner-checkIfFileExists"><strong>checkIfFileExists</strong></a>(filename)</dt><dd><tt>Simple function to check if a file exists<br>
<br>
Parameters:<br>
filename : string<br>
filename to be checked<br>
<br>
Returns:<br>
Boolean<br>
Whether or not the file exists</tt></dd></dl>
<dl><dt><a name="Network_Scanner-getTimeStamp"><strong>getTimeStamp</strong></a>(iIncludeTime<font color="#909090">=True</font>)</dt><dd><tt>Simple function to generate a timestamp<br>
<br>
Parameters:<br>
iIncludeTime : Boolean<br>
Whether or not the time is included with the date timestamp<br>
<br>
Returns:<br>
String<br>
Formatted timestamp</tt></dd></dl>
<dl><dt><a name="Network_Scanner-parseNmapXml"><strong>parseNmapXml</strong></a>(xmlData)</dt><dd><tt>Parses the XML data exported from the nmap scan. This function converts the xml document to<br>
an object to be parsed and saved to the database<br>
<br>
Parameters:<br>
xmlData : String<br>
String dump of the xml output from nmap<br>
<br>
Returns:<br>
Object - JSON<br>
Object from the xml document</tt></dd></dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-exitApplication"><strong>exitApplication</strong></a>(sig_num, frame)</dt><dd><tt>Catches SIGINT in order to provide a place for graceful terminations during scans.<br>
<br>
Parameters:<br>
sign_num : int<br>
Signal integer<br>
frame : Object<br>
Current stack frame<br>
<br>
Returns:<br>
N/A</tt></dd></dl>
</td></tr></table>
</body></html>