Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use distinct exit codes for intentional exits #521

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/email_registered.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import httpx
import asyncio

Expand All @@ -8,7 +10,8 @@

async def main():
if not sys.argv[1:]:
exit("Please give an email address.")
print("Please give an email address.")
exit(os.EX_IOERR)

as_client = httpx.AsyncClient() # Async Client

Expand Down
3 changes: 2 additions & 1 deletion ghunt/ghunt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys


Expand All @@ -6,7 +7,7 @@ def main():
if (version < (3, 10)):
print('[-] GHunt only works with Python 3.10+.')
print(f'Your current Python version : {version.major}.{version.minor}.{version.micro}')
sys.exit(1)
sys.exit(os.EX_SOFTWARE)

from ghunt.cli import parse_and_run
from ghunt.helpers.banner import show_banner
Expand Down
4 changes: 3 additions & 1 deletion ghunt/helpers/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import json
import base64
import os
from typing import *

import httpx
Expand Down Expand Up @@ -195,7 +196,8 @@ def auth_dialog() -> Tuple[Dict[str, str], str] :
master_token = input(f"Master token => ").strip('" ')

else:
exit("Please choose a valid choice. Exiting...")
print("Please choose a valid choice. Exiting...")
exit(os.EX_IOERR)

return oauth_token, master_token

Expand Down
5 changes: 4 additions & 1 deletion ghunt/helpers/ia.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from ghunt import globals as gb
from ghunt.apis.vision import VisionHttp

Expand All @@ -20,7 +22,8 @@ async def detect_face(vision_api: VisionHttp, as_client: httpx.AsyncClient, imag
break
await asyncio.sleep(0.5)
else:
exit("\n[-] Vision API keeps rate-limiting.")
print("\n[-] Vision API keeps rate-limiting.")
exit(os.EX_UNAVAILABLE)

if are_faces_found:
if len(faces_results.face_annotations) > 1:
Expand Down
4 changes: 3 additions & 1 deletion ghunt/helpers/listener.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from http.server import BaseHTTPRequestHandler, HTTPServer
from typing import *

Expand Down Expand Up @@ -45,7 +46,8 @@ def run(server_class=HTTPServer, handler_class=Server, port=60067):
break

except KeyboardInterrupt:
exit("[-] Exiting...")
print("[-] Exiting...")
exit(os.CLD_KILLED)
else:
if handler_class.data_bridge.data:
print("[+] Received cookies !")
Expand Down
5 changes: 4 additions & 1 deletion ghunt/modules/drive.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from ghunt.helpers.utils import *
from ghunt.objects.base import DriveExtractedUser, GHuntCreds
from ghunt.apis.drive import DriveHttp
Expand Down Expand Up @@ -38,7 +40,8 @@ async def hunt(as_client: httpx.AsyncClient, file_id: str, json_file: bool=Path)
drive = DriveHttp(ghunt_creds)
file_found, file = await drive.get_file(as_client, file_id)
if not file_found:
exit("[-] The file wasn't found.")
print("[-] The file wasn't found.")
exit(os.EX_IOERR)

is_folder = file.mime_type == "application/vnd.google-apps.folder"
file_type = drive_knownledge.mime_types.get(file.mime_type)
Expand Down
8 changes: 6 additions & 2 deletions ghunt/modules/email.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from ghunt import globals as gb
from ghunt.helpers.utils import get_httpx_client
from ghunt.objects.base import GHuntCreds
Expand All @@ -24,7 +26,8 @@ async def hunt(as_client: httpx.AsyncClient, email_address: str, json_file: Path
# vision_api = VisionHttp(ghunt_creds)
is_found, target = await people_pa.people_lookup(as_client, email_address, params_template="max_details")
if not is_found:
exit("[-] The target wasn't found.")
print("[-] The target wasn't found.")
exit(os.EX_DATAERR)

if json_file:
json_results = {}
Expand All @@ -37,7 +40,8 @@ async def hunt(as_client: httpx.AsyncClient, email_address: str, json_file: Path
print(f"- {container.title()}")

if not "PROFILE" in containers:
exit("[-] Given information does not match a public Google Account.")
print("[-] Given information does not match a public Google Account.")
exit(os.EX_DATAERR)

container = "PROFILE"

Expand Down
8 changes: 6 additions & 2 deletions ghunt/modules/gaia.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from ghunt import globals as gb
from ghunt.objects.base import GHuntCreds
from ghunt.apis.peoplepa import PeoplePaHttp
Expand All @@ -24,7 +26,8 @@ async def hunt(as_client: httpx.AsyncClient, gaia_id: str, json_file: Path=None)
# vision_api = VisionHttp(ghunt_creds)
is_found, target = await people_pa.people(as_client, gaia_id, params_template="max_details")
if not is_found:
exit("[-] The target wasn't found.")
print("[-] The target wasn't found.")
exit(os.EX_DATAERR)

if json_file:
json_results = {}
Expand All @@ -37,7 +40,8 @@ async def hunt(as_client: httpx.AsyncClient, gaia_id: str, json_file: Path=None)
print(f"- {container.title()}")

if not "PROFILE" in containers:
exit("[-] Given information does not match a public Google Account.")
print("[-] Given information does not match a public Google Account.")
exit(os.EX_DATAERR)

container = "PROFILE"

Expand Down
11 changes: 8 additions & 3 deletions ghunt/modules/geolocate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from ghunt import globals as gb
from ghunt.helpers.utils import get_httpx_client
from ghunt.apis.geolocation import GeolocationHttp
Expand All @@ -16,12 +18,14 @@ async def main(as_client: httpx.AsyncClient, bssid: str, input_file: Path, json_
body = None
if input_file:
if not input_file.exists():
exit(f"[-] The input file \"{input_file}\" doesn't exist.")
print(f"[-] The input file \"{input_file}\" doesn't exist.")
exit(os.EX_IOERR)
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.")
print(f"[-] The input file \"{input_file}\" is not a valid JSON file.")
exit(os.EX_IOERR)

if not as_client:
as_client = get_httpx_client()
Expand All @@ -31,7 +35,8 @@ async def main(as_client: httpx.AsyncClient, bssid: str, input_file: Path, json_
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.")
print("[-] The location wasn't found.")
exit(os.EX_DATAERR)

geolocator = Nominatim(user_agent="nominatim")
location = geolocator.reverse(f"{resp.location.latitude}, {resp.location.longitude}", timeout=10)
Expand Down
5 changes: 3 additions & 2 deletions ghunt/modules/login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import *

import httpx
Expand All @@ -22,7 +23,7 @@ async def check_and_login(as_client: httpx.AsyncClient, clean: bool=False) -> No
print(f"[+] Credentials file at {creds_path} deleted !")
else:
print(f"Credentials file at {creds_path} doesn't exists, no need to delete.")
exit()
exit(os.EX_OK)

if not as_client:
as_client = get_httpx_client()
Expand Down Expand Up @@ -59,7 +60,7 @@ async def check_and_login(as_client: httpx.AsyncClient, clean: bool=False) -> No
if new_gen_inp == "y":
oauth_token, master_token = auth.auth_dialog()
else:
exit()
exit(os.EX_OK)

ghunt_creds.android.authorization_tokens = {} # Reset the authorization tokens

Expand Down