text stringlengths 0 1.99k |
|---|
--[ 7 - Give this a try yourself! |
* Turn off the WR940Nv6 |
* Connect a serial adapter to the UART pins |
* Note: There are two jumpers that need to be soldered to complete the |
circuit for RX/TX |
* Run the script below to drop the WR940Nv6 into the Das U-Boot shell |
* Turn on the Router via the button on the back of the router |
* Note: If the script doesn't detect a shell within a few seconds then |
reboot the router and it should work |
* Connect to port TCP port 1337 once the script detects a Das U-boot shell |
* Send the string `w0x18040008 0x00080000` to turn the front LED blue |
* Send the string `w0x18040008 0x00004000` to turn off the front LED |
* Send `shutdown` to close the server socket and exit |
* MMIO MITM Python Code: |
``` |
import serial |
import time |
import socket |
import logging |
### CONSTS ### |
GPIO_OUT = 0x18040008 |
logger = logging.getLogger(__name__) |
logging.basicConfig(filename='bootup.log', |
format='"%(asctime)s;%(message)s', |
datefmt="%H:%M:%S", filemode='w', |
encoding='utf-8', level=logging.DEBUG) |
def get_response(ser): |
time.sleep(0.02) |
out = b"" |
while ser.inWaiting() > 0: |
out += ser.read(1) |
return out |
def read_from_phy_memory(ser, address): |
print(f'[*] Reading from Address: 0x{address:08X}...') |
ser.write(bytes(f"md 0x{address:08X} 1\n","UTF-8")) |
out = get_response(ser) |
offset = out.rfind(bytes(f'{address:08x}: ',"UTF-8")) |
value = int(b'0x' + out[offset + len(bytes(f'{address:08x}: ', |
"UTF-8")):offset + len(bytes(f'{address:08x}: ',"UTF-8")) + 8], 16) |
logging.debug(f"READ: 0x{address:08X}: 0x{value:08X}") |
return value |
def write_to_phy_memory(ser, address, value): |
print(f'[*] Writing to Address: 0x{address:08X} with value \ |
0x{value:08X}...') |
logging.debug(f"WRITE: 0x{address:08X}: 0x{value:08X}") |
ser.write(bytes(f"mw 0x{address:04X} 0x{value:04X}\n","UTF-8")) |
time.sleep(0.01) |
def test_uboot_cmd_line(ser, test_string): |
ser.write(bytes(f"{test_string}\n","UTF-8")) |
out = get_response(ser) |
if bytes(f'Unknown command \'{test_string}\'', "UTF-8") in out: |
return True |
def spam_tpl_for_uboot(ser, max_attempts): |
while True: |
ser.write(b'tpl') |
out = get_response(ser) |
if b"ap151>" in out: |
print(f"[+] Router is now in [REDACTED] state with \ |
{max_attempts} attempts remaining.") |
return True |
max_attempts -= 1 |
if max_attempts == 0: |
print("[-] Unable to get the router into the [REDACTED] state. \ |
Try Rebooting...") |
return False |
def listen_and_respond(ser, port): |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
try: |
s.bind(("0.0.0.0", port)) |
except socket.error as msg: |
print('[-] Bind failed. Error Code : ' + str(msg[0]) + \ |
' Message ' + msg[1]) |
return False |
s.listen(1) |
print (f'[*] Socket now listening on port {port}') |
while True: |
conn, addr = s.accept() |
msg = conn.recv(1024) |
while len(msg) > 0: |
if msg == b'exit\n': |
conn.send(bytes('[*] Byeeeeee\n', "UTF-8")) |
conn.close() |
break |
if msg == b'shutdown\n': |
conn.send(bytes('[*] The server is going down down\n', |
"UTF-8")) |
conn.close() |
s.shutdown(socket.SHUT_WR) |
s.close() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.