-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
194 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from ghunt.objects.base import GHuntCreds | ||
from ghunt.errors import * | ||
import ghunt.globals as gb | ||
from ghunt.objects.apis import GAPI | ||
from ghunt.parsers.geolocate import GeolocationResponse | ||
|
||
import httpx | ||
|
||
from typing import * | ||
import inspect | ||
import json | ||
|
||
|
||
class GeolocationHttp(GAPI): | ||
def __init__(self, creds: GHuntCreds, headers: Dict[str, str] = {}): | ||
super().__init__() | ||
|
||
if not headers: | ||
headers = gb.config.headers | ||
|
||
base_headers = {} | ||
|
||
headers = {**headers, **base_headers} | ||
|
||
self.hostname = "www.googleapis.com" | ||
self.scheme = "https" | ||
|
||
self.authentication_mode = None # sapisidhash, cookies_only, oauth or None | ||
self.require_key = "geolocation" # key name, or None | ||
|
||
self._load_api(creds, headers) | ||
|
||
async def geolocate(self, as_client: httpx.AsyncClient, bssid: str, body: dict) -> Tuple[bool, GeolocationResponse]: | ||
endpoint_name = inspect.currentframe().f_code.co_name | ||
|
||
verb = "POST" | ||
base_url = f"/geolocation/v1/geolocate" | ||
data_type = "json" # json, data or None | ||
|
||
if bssid: | ||
payload = { | ||
"considerIp": False, | ||
"wifiAccessPoints": [ | ||
{ | ||
"macAddress": "00:25:9c:cf:1c:ad" | ||
}, | ||
{ | ||
"macAddress": bssid | ||
}, | ||
] | ||
} | ||
else: | ||
payload = body | ||
|
||
self._load_endpoint(endpoint_name) | ||
req = await self._query(as_client, verb, endpoint_name, base_url, None, payload, data_type) | ||
|
||
# Parsing | ||
data = json.loads(req.text) | ||
|
||
resp = GeolocationResponse() | ||
if "error" in data: | ||
return False, resp | ||
|
||
resp._scrape(data) | ||
|
||
return True, resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from ghunt import globals as gb | ||
from ghunt.helpers.utils import get_httpx_client | ||
from ghunt.apis.geolocation import GeolocationHttp | ||
from ghunt.helpers import auth | ||
|
||
import httpx | ||
from geopy.geocoders import Nominatim | ||
|
||
from typing import * | ||
from pathlib import Path | ||
import json | ||
|
||
|
||
async def main(as_client: httpx.AsyncClient, bssid: str, input_file: Path, json_file: Path=None): | ||
# Verifying args | ||
body = None | ||
if input_file: | ||
if not input_file.exists(): | ||
exit(f"[-] The input file \"{input_file}\" doesn't exist.") | ||
with open(input_file, "r", encoding="utf-8") as f: | ||
try: | ||
body = json.load(f) | ||
except json.JSONDecodeError: | ||
exit("[-] The input file is not a valid JSON file.") | ||
|
||
if not as_client: | ||
as_client = get_httpx_client() | ||
|
||
ghunt_creds = await auth.load_and_auth(as_client) | ||
|
||
geo_api = GeolocationHttp(ghunt_creds) | ||
found, resp = await geo_api.geolocate(as_client, bssid=bssid, body=body) | ||
if not found: | ||
exit("[-] The location wasn't found.") | ||
|
||
geolocator = Nominatim(user_agent="nominatim") | ||
location = geolocator.reverse(f"{resp.location.latitude}, {resp.location.longitude}", timeout=10) | ||
raw_address = location.raw['address'] | ||
address = location.address | ||
|
||
gb.rc.print("📍 Location found !\n", style="plum2") | ||
gb.rc.print(f"🛣️ [italic]Accuracy : {resp.accuracy} meters[/italic]\n") | ||
gb.rc.print(f"Latitude : {resp.location.latitude}", style="bold") | ||
gb.rc.print(f"Longitude : {resp.location.longitude}\n", style="bold") | ||
gb.rc.print(f"🏠 Estimated address : {address}\n") | ||
gb.rc.print(f"🗺️ [italic][link=https://www.google.com/maps/search/?q={resp.location.latitude},{resp.location.longitude}]Open in Google Maps[/link][/italic]\n", style=f"cornflower_blue") | ||
|
||
if json_file: | ||
from ghunt.objects.encoders import GHuntEncoder; | ||
with open(json_file, "w", encoding="utf-8") as f: | ||
f.write(json.dumps({ | ||
"accuracy": resp.accuracy, | ||
"latitude": resp.location.latitude, | ||
"longitude": resp.location.longitude, | ||
"address": raw_address, | ||
"pretty_address": address | ||
}, cls=GHuntEncoder, indent=4)) | ||
gb.rc.print(f"[+] JSON output wrote to {json_file} !", style="italic") | ||
|
||
await as_client.aclose() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from ghunt.objects.apis import Parser | ||
from ghunt.objects.base import Position | ||
|
||
from typing import * | ||
|
||
|
||
class GeolocationResponse(Parser): | ||
def __init__(self): | ||
self.accuracy: int = 0 | ||
self.location: Position = Position() | ||
|
||
def _scrape(self, base_model_data: dict[str, any]): | ||
self.accuracy = base_model_data.get("accuracy") | ||
|
||
location = base_model_data.get("location") | ||
self.location.longitude = location.get("lng") | ||
self.location.latitude = location.get("lat") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
metadata = { | ||
"version": "2.1.6", | ||
"name": "BlackHat Edition" | ||
"version": "2.2.0", | ||
"name": "Wardriving Edition" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "ghunt" | ||
version = "2.1.6" | ||
version = "2.2.0" | ||
authors = [ | ||
{name = "mxrch", email = "[email protected]"}, | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters