This repository was archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeoForensic.py
More file actions
228 lines (167 loc) · 6.12 KB
/
GeoForensic.py
File metadata and controls
228 lines (167 loc) · 6.12 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
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
import argparse
import os
import requests
import sqlite3
#Constant
URL = "https://www.googleapis.com/geolocation/v1/geolocate?key="
WIGLE_WIFI_QUERY = "select lastlat, lastlon, bssid from network group by bssid"
HERREAVAD_WIFI_QUERY = "select bssid from local_reports group by bssid"
HERREAVAD_CELL_QUERY = "select rowkey from lru_table group by rowkey"
ASTRO_WIFI_QUERY = "select bssid from wifi_network group by bssid"
def SQLite(Path, Query):
'''
This fuction return de result of the query of SQLite
:param Path: The path of db
:param Query: Query to extract information
:return: Result of query
'''
result = []
conn = sqlite3.connect(Path)
cur = conn.cursor()
rows = cur.execute(Query).fetchall()
for row in rows:
result.append(list(row))
return result
def GoogleGeolocationAPI(Data, Name):
'''
This fuction interacts with Google API, get precision and acurrency of data
:param Data: json for request to Google API
:param Name: Mac for represent in Google Maps
:return: Array with latitude, longitude and name
'''
response = requests.post(URL+YOUR_API_KEY, json=Data)
if response.status_code == 200:
lat = response.json()['location']['lat']
long = response.json()['location']['lng']
return [lat, long, Name]
def DireccionIP():
'''
First method for get position of any device. Get lat, long and acurrency of IP
:return:Array with latitude, longitude and name
'''
datos = {
"considerIp": "true"
}
return datos
def AccesPointWifi(Bssid):
'''
Second method for get position of any device. Get lat, long and acurrency with
Wardriving thecnique.
:param Bssid: Unique name to identificate a Wifi
:return:Array with latitude, longitude and name
'''
geolocation = []
geolocation.append(['Lat', 'Long', 'Name'])
for mac in Bssid:
mac = mac[0]
if mac is not None:
datos = {
"wifiAccessPoints": [
{
"macAddress": "%s" % mac,
}
]
}
result = GoogleGeolocationAPI(datos, mac)
if result is not None:
geolocation.append(result)
return geolocation
def AccesPointWifiTriangulation(Bssid):
'''
Second method for get position of any device. Is better because use technical triangulation.
:param Bssid: Unique name to identificate a Wifi
:return:Array with latitude, longitude and name
'''
"""
geolocation = []
geolocation.append(['Lat', 'Long', 'Name'])
for mac in Bssid:
datos = {
"considerIp": "false",
"wifiAccessPoints": [
{
"macAddress": "%s" % Bssid[1],
"signalStrength": -48,
"signalToNoiseRatio": 0
},
{
"macAddress": "%s" % Bssid[2],
"signalStrength": -49,
"signalToNoiseRatio": 0
}
]
}
geolocation.append(GoogleGeolocationAPI(datos, mac))
return geolocation
"""
def TowerCell(CellTower):
'''
Third method for get position of any device. Get lat, long and acurrency with GSM. LTE or CDMA log's.
:param CellTower: Recive CellID, Location area, Mobile Country Code and mobile Network
:return:Array with latitude, longitude and name
The log's recived "gsm:214:03:9150:2401"
type = gsm
mobileCountryCode (MCC) = 214
mobileNetworkCode (MNC) = 03
locationAreaCode (LAC) = 9150
cellId (CID) = 2401
https://es.wikipedia.org/wiki/MCC/MNC
'''
geolocation = []
geolocation.append(['Lat', 'Long', 'Name'])
for gsm in CellTower:
gsm = gsm[0]
if gsm.startswith('gsm') or gsm.startswith('lte') or gsm.startswith('cdma'):
gsm = gsm.split(":")
datos = {
"considerIp": "false",
"cellTowers": [
{
"cellId": gsm[4],
"locationAreaCode": gsm[3],
"mobileCountryCode": gsm[1],
"mobileNetworkCode": gsm[2]
}
]
}
result = GoogleGeolocationAPI(datos, gsm[4])
if result is not None:
geolocation.append(result)
return geolocation
def outputHtml(Name, ArrayData):
'''
Print the GeoData in html geo chart like a map.
:param Name: Name of output file
:param ArrayData: Array with latitude, longitude and name
:return: the output is a html
'''
file = open('templates/index.html', 'r')
text = file.read()
geoWifi = text.replace('{{ array }}', ArrayData)
file.close()
file = open("templates/%s.html"%Name, "w")
file.write(geoWifi)
file.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='GeoForensic', description='Example with long option names', usage='python3 GeoForensic.py [options]')
parser.add_argument('--db_path','-db', help="Path of sqlite")
parser.add_argument('--type','-t', help="herrevad or wigle")
args = parser.parse_args()
dbPath = args.db_path
if os.path.exists(dbPath):
if args.type == "herrevad":
LocationBssid = AccesPointWifi(SQLite(dbPath, HERREAVAD_WIFI_QUERY))
outputHtml("HERREAVAD_WIFI",str(LocationBssid))
CellTower = TowerCell(SQLite(dbPath, HERREAVAD_CELL_QUERY))
outputHtml("HERREAVAD_CELL",str(CellTower))
elif args.type == "wigle":
LocationBssid = SQLite(dbPath, WIGLE_WIFI_QUERY)
LocationBssid.insert(0, ['Lat', 'Long', 'Name'])
outputHtml("WIGLE_WIFI", str(LocationBssid))
elif args.type == "astro":
LocationBssid = AccesPointWifi(SQLite(dbPath, ASTRO_WIFI_QUERY))
outputHtml("ASTRO_WIFI",str(LocationBssid))
else:
print("Please, use a correct type")
else:
print("Doesn't exit path")