From 8bcfb063582c898d4e16627ef5625442d7f092f4 Mon Sep 17 00:00:00 2001 From: giacomogiallombardo Date: Tue, 2 Jan 2024 00:29:55 +0100 Subject: [PATCH] Added login module + saving access file in a specific path. --- README.md | 2 +- setup.py | 6 +-- src/atop/atop.py | 16 ++++++-- src/atop/modules/telegramhelper.py | 30 ++++++++++---- src/atop/modules/util.py | 63 ++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 src/atop/modules/util.py diff --git a/README.md b/README.md index b28c53b..f3f7163 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# A TON of privacy v0.1.8 +# A TON of privacy v0.1.9 ## ATOP - A tool for investigating TON network and its NFT. "A TON of Privacy" formally called ATOP ... is a tool for conducting OSINT investigations on TON (Telegram 🙃) NFTs. diff --git a/setup.py b/setup.py index fd80b38..ce34245 100644 --- a/setup.py +++ b/setup.py @@ -5,11 +5,11 @@ setup( name="atop", - version="0.1.8-1", + version="0.1.9", author="Aaarghhh", author_email="giacomo@udontneed.it", packages=["atop", "atop.modules"], - package_dir={'':'src'}, + package_dir={"": "src"}, include_package_data=True, entry_points={"console_scripts": ["a-ton-of-privacy = atop.atop:run"]}, url="https://github.com/aaarghhh/a_TON_of_privacy", @@ -30,7 +30,7 @@ "rsa>=4.9", "soupsieve>=2.5", "Telethon==1.30.3", - "urllib3>=2.0.5" + "urllib3>=2.0.5", ], zip_safe=False, ) diff --git a/src/atop/atop.py b/src/atop/atop.py index 544efb7..b9f5a9b 100644 --- a/src/atop/atop.py +++ b/src/atop/atop.py @@ -46,7 +46,7 @@ def print_banner(): ░░ ░░ ░ ▒ ░ ░░ ░ ▒ ░ ▒ ▒ ░░ ░ ░ ░ ░ ░░ ░ ░ ░ ░ ░ ░ ░ -v 0.1.8 """ +v 0.1.9 """ + Style.RESET_ALL ) @@ -538,8 +538,8 @@ def start_searching(self): self.pivot_ens() @staticmethod - def telegram_generate_session(): - TelegramHelper.generate_string_session() + def telegram_generate_session(session_path=None): + TelegramHelper.generate_string_session(session_path) def run(): @@ -602,6 +602,11 @@ def run(): required=False, help="[?] where to store profile pics ...", ) + parser.add_argument( + "--sessionpath", + required=False, + help="[?] where to store or dump the sesssion string, this an optional parameter, it will printed in stdout without it ...", + ) try: print_banner() args = parser.parse_args() @@ -611,7 +616,10 @@ def run(): exit(0) if args.login: - Ton_retriever.telegram_generate_session() + session_path = None + if args.sessionpath: + session_path = args.sessionpath + Ton_retriever.telegram_generate_session(session_path=session_path) exit(0) else: ton_ret = Ton_retriever( diff --git a/src/atop/modules/telegramhelper.py b/src/atop/modules/telegramhelper.py index 59f3687..8a95a71 100644 --- a/src/atop/modules/telegramhelper.py +++ b/src/atop/modules/telegramhelper.py @@ -10,6 +10,7 @@ from telethon.sessions import StringSession from atop.modules.const import user_agent +from atop.modules.util import Util import requests import random @@ -27,7 +28,7 @@ class TelegramHelper: _sessionstring = None @staticmethod - def generate_string_session(): + def generate_string_session(path): api_id = input(" [!] Please enter your API ID:\n") api_hash = input(" [!] Please enter your API Hash:\n") phone_number = input(" [!] Please enter your phone number:\n") @@ -44,7 +45,22 @@ def generate_string_session(): else: _api_id = int(api_id) with TelegramClient(StringSession(), _api_id, api_hash) as client: - print(client.session.save()) + saved = False + if path and path != "": + if Util.is_pathname_valid(path): + sessionstring = client.session.save() + with open(path, "w+") as f: + f.write("API_ID=" + api_id + "\n") + f.write("API_HASH=" + api_hash + "\n") + f.write("PHONE_NUMBER=" + phone_number + "\n") + f.write("SESSION_STRING=" + sessionstring + "\n") + print(f" [!] Sessionstring saved to {path}") + saved = True + else: + print(" [-] Path is not valid.") + return -1 + if not saved: + print(client.session.save()) return 0 @staticmethod @@ -134,7 +150,9 @@ def create_client(self): ) self._client.connect() if not self._client.is_user_authorized(): - print(f"[-] TELEGRAM ISN'T AUTHENTICATE PLS RECREATE A SESSIONSTRING...") + print( + f"[-] TELEGRAM ISN'T AUTHENTICATE PLS RECREATE A SESSIONSTRING..." + ) exit(1) else: self._client = TelegramClient( @@ -304,9 +322,7 @@ def check_telegram_number(self, _number_to_check): if not username: username = "N/A" if username != "N/A": - telegram_details = self.check_telegram_nickname( - "@" + username - ) + telegram_details = self.check_telegram_nickname("@" + username) try: try: self._client( @@ -333,7 +349,7 @@ def check_telegram_number(self, _number_to_check): except TypeError as e: print( - f" | TypeError: {e}. --> The error might have occured due to the inability to delete the {_number_to_check} from the contact list." + f" | TypeError: {e}. --> The error might have occurred due to the inability to delete the {_number_to_check} from the contact list." ) except: raise diff --git a/src/atop/modules/util.py b/src/atop/modules/util.py new file mode 100644 index 0000000..86d57e2 --- /dev/null +++ b/src/atop/modules/util.py @@ -0,0 +1,63 @@ +import os +import sys +import errno +import math + +ERROR_INVALID_NAME = 123 + + +class Util: + def __init__(self): + pass + + @staticmethod + def is_pathname_valid(pathname: str) -> bool: + """ + `True` if the passed pathname is a valid pathname for the current OS; + `False` otherwise. + """ + try: + if not isinstance(pathname, str) or not pathname: + return False + + _, pathname = os.path.splitdrive(pathname) + root_dirname = ( + os.environ.get("HOMEDRIVE", "C:") + if sys.platform == "win32" + else os.path.sep + ) + assert os.path.isdir(root_dirname) + root_dirname = root_dirname.rstrip(os.path.sep) + os.path.sep + + for pathname_part in pathname.split(os.path.sep): + try: + os.lstat(root_dirname + pathname_part) + except OSError as exc: + if hasattr(exc, "winerror"): + if exc.winerror == ERROR_INVALID_NAME: + return False + elif exc.errno in {errno.ENAMETOOLONG, errno.ERANGE}: + return False + except TypeError as exc: + return False + else: + return True + + @staticmethod + def get_file_size(self, path): + return os.path.getsize(path) + + @staticmethod + def get_file_size_human(self, path): + size = self.get_file_size(path) + return self.convert_size(size) + + @staticmethod + def convert_size(self, size_bytes): + if size_bytes == 0: + return "0B" + size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") + i = int(math.floor(math.log(size_bytes, 1024))) + p = math.pow(1024, i) + s = round(size_bytes / p, 2) + return "%s %s" % (s, size_name[i])