Skip to content
KitploitKITPLOIT
StrumentiBlog
Invia
StrumentiBlog
Invia

Strumenti di Hacking, PenTest e Cybersecurity per il tuo Arsenale di Sicurezza!

Kitploit è una directory di strumenti di hacking, cybersecurity e pentesting. Scopri gli ultimi aggiornamenti dei progetti per trovare vulnerabilità, analizzare sistemi, automatizzare i test e rafforzare la tua sicurezza.

··Feed·Contatto·Privacy·© 2026 Kitploit

Directory degli strumenti

Categorie

Vedi tutte le categorie
Loading categories
MIPS-CVE-2014-9222 — Divertiamoci scavando nel firmware di un router Zyxel e nell'architettura MIPS. | Kitploit
Strumenti/GitHubGitHub/mercul1ninna/mips-cve-2014-9222
Sicurezza Sistemi EmbeddedAnalisi delle VulnerabilitàExploitReverse EngineeringHacking HardwareAnalisi di BinariApprendimento e FormazioneAnalisi del Firmware
GitHubmercul1ninna/mips-cve-2014-9222

MIPS-CVE-2014-9222

Divertiamoci scavando nel firmware di un router Zyxel e nell'architettura MIPS.

Vedi Repository
7 anni faNon ancora revisionato

Più Popolari

Vedi tutti →

Scopri gli strumenti più utilizzati dalla nostra community.

Esplora tutti gli strumenti

Sfoglia la nostra collezione di strumenti

Vedi tutti gli strumenti →
Condividi

Disclaimer

I tutorial sono solo a scopo informativo ed educativo. Credo che l'hacking etico, la sicurezza delle informazioni e la cyber security dovrebbero essere argomenti familiari a chiunque utilizzi informazioni digitali e computer. Credo che sia impossibile difendersi dagli hacker senza sapere come viene effettuato l'hacking.

Requisiti

root@kitploit:~
$ IDA Pro +7.0 (you can use Radar2 since IDA is quite expensive)
$ Router running Rompager 4.07 : there're immense number of them such as TP-Link TD-W8951*, ZyXEL P-660R, Billion BiPAC 51**/52**
$ UART to USB

La vulnerabilità Misfortune Cookie esiste da un po' di tempo, ma manca ancora un'analisi pubblica che illustri i dettagli tecnici della vulnerabilità. Secondo Check Point, il software interessato è il server web integrato RomPager di AllegroSoft. Scansioni su scala Internet suggeriscono che RomPager sia probabilmente il software server web più diffuso al mondo in termini di numero di endpoint disponibili. RomPager è tipicamente integrato nel firmware distribuito con il dispositivo. Questa specifica vulnerabilità è stata introdotta nella base di codice nel 2002. Inoltre, i dispositivi esposti sono quelli che utilizzano i servizi RomPager con versioni precedenti alla 4.34 (e in particolare la 4.07).

Per questo tutorial userò un ZXHN H108L che utilizza RomPager 4.07

root@kitploit:~
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="ZXHN H108L"
Content-Type: text/html
Transfer-Encoding: chunked
Server: RomPager/4.07 UPnP/1.0
EXT:

Ora usiamo la porta seriale; prima dobbiamo determinare il baud rate

root@kitploit:~
$ sudo stty -F /dev/ttyUSB0

OUT :

root@kitploit:~
speed 115200 baud; line = 0;
-brkint -imaxbel

device

Io uso minicom, puoi usare qualsiasi cosa, da screen a HyperTerminal, ma preferisco questo per la sua stabilità ;)

Devi prima disattivare il controllo di flusso hardware

root@kitploit:~
$ sudo minicom -s
root@kitploit:~
    +-----------------------------------------------------------------------+
    | A -    Serial Device      : /dev/modem                                |
    | B - Lockfile Location     : /var/lock                                 |
    | C -   Callin Program      :                                           |
    | D -  Callout Program      :                                           |
    | E -    Bps/Par/Bits       : 115200 8N1                                |
    | F - Hardware Flow Control : No                                        |
    | G - Software Flow Control : No                                        |
    |                                                                       |
    |    Change which setting?                                              |
    +-----------------------------------------------------------------------+
            | Screen and keyboard      |
            | Save setup as dfl        |
            | Save setup as..          |
            | Exit                     |
            | Exit from Minicom        |
            +--------------------------+

Ora siamo pronti per partire:

root@kitploit:~
$ sudo minicom -D /dev/ttyUSB0 -b 115200
root@kitploit:~
Bootbase Version: VTC_SPI1.26 |  2012/12/26 16:00:00    
RAM: Size = 8192 Kbytes
Found SPI Flash 2MiB GD25Q16 at 0xbfc00000
SPI Flash Quad Enable
Turn off Quad Mode

RAS Version: ZXHN H108LV4.0.0a_ZRQ_MA                                          
System   ID: $2.12.162.0(G94.BY.2)3.20.19.0| 2014/03/21   20140321_v006  | 2014 

Press any key to enter debug mode within 3 seconds.
..........

Per mostrare i possibili comandi:

$ ATHE

root@kitploit:~
======= Debug Command Listing =======
AT          just answer OK
ATHE          print help
ATBAx         change baudrate. 1:38.4k, 2:19.2k, 3:9.6k 4:57.6k 5:115.2k
ATENx,(y)     set BootExtension Debug Flag (y=password)
ATSE          show the seed of password generator
ATTI(h,m,s)   change system time to hour:min:sec or show current time
ATDA(y,m,d)   change system date to year/month/day or show current date
ATDS          dump RAS stack
ATDT          dump Boot Module Common Area
ATDUx,y       dump memory contents from address x for length y
ATRBx         display the  8-bit value of address x
ATRWx         display the 16-bit value of address x
ATRLx         display the 32-bit value of address x
ATGO(x)       run program at addr x or boot router
ATGR          boot router
ATGT          run Hardware Test Program
ATRTw,x,y(,z) RAM test level w, from address x to y (z iterations)
ATSH          dump manufacturer related data in ROM
ATDOx,y       download from address x for length y to PC via XMODEM
ATTD          download router configuration to PC via XMODEM
ATUR          upload router firmware to flash ROM

< press any key to continue >

Questo firmware ha un insieme di comandi nascosti molto utili per la nostra analisi dinamica; il problema è che non possiamo vedere i registri né impostare breakpoint, ma fortunatamente con questi comandi nascosti avremo queste funzionalità. Per vederli e usarli dobbiamo usare ATEN. Tuttavia, questo comando richiede una password, quindi cosa possiamo fare ora? Facciamo reverse engineering del firmware per trovare l'algoritmo del generatore di password.

(Analisi statica) Vediamo prima il file del firmware:

root@kitploit:~
$ binwalk ras

binwalk1

root@kitploit:~
$ dd if=ras of=rom1.lzma bs=1 skip=85043 count=66696
$ dd if=ras of=rom2.lzma bs=1 skip=350259 count=3350556
$ lzma -d <rom1.lzma> rom1
$ lzma -d <rom2.lzma> rom2

Vediamo ora la firma nei file estratti:

root@kitploit:~
$ binwalk -Y rom1
root@kitploit:~
DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             MIPS executable code, 32/64-bit, big endian, at least 1250 valid instructions

string è un grande strumento per farsi un'idea di cosa sia un file binario o di cosa contenga; vediamo se riusciamo a trovare l'algoritmo della password:

root@kitploit:~
$ strings rom1 | grep -i aten
$ strings rom2 | grep -i aten

A quanto pare, non possiamo vederlo perché il firmware è ancora compresso, il che significa che dobbiamo estrarlo dal router usando la modalità di debug:

root@kitploit:~
$ ATDO bfc00000, 1f0000

xmodem

La prima cosa che viene in mente è iniziare a cercare una dispatch table. Perché? Solo intuizione; l'unica alternativa è una serie di if-elif, ma sarebbe molto lunga, per verificare la validità della password fornita dall'utente. Ed ecco cosa ho trovato:

root@kitploit:~
ROM:800158A0 CmdTable:       .word unk_80015C20       # DATA XREF: sub_8000E3D8+4Co
ROM:800158A0                                          # sub_8000E3D8+90o ...
ROM:800158A4                 .word sub_8000E6D0
ROM:800158A8                 .byte    0
ROM:800158A9                 .byte    0
ROM:800158AA                 .byte    0
ROM:800158AB                 .byte    0
ROM:800158AC                 .word aJustAnswerOk      # "          just answer OK"
ROM:800158B0                 .word aAthe              # "ATHE"
ROM:800158B4                 .word CMD_SHOW_HELP_ATHE
ROM:800158B8                 .byte    0
ROM:800158B9                 .byte    0
ROM:800158BA                 .byte    0
ROM:800158BB                 .byte    0
ROM:800158BC                 .word aPrintHelp         # "          print help"
ROM:800158C0                 .word aAtba              # "ATBA"
ROM:800158C4                 .word CMD_ATBA
...
ROM:800158D0                 .word aAten              # "ATEN"
ROM:800158D4                 .word CMD_ATEN

Tieni presente che una parola MIPS è di 4 byte; ora vediamo CMD_ATEN:

root@kitploit:~
ROM:8000FF84                 lw      $a0, 8($s0)
ROM:8000FF88                 jal     sub_80013654
ROM:8000FF8C                 li      $a1, 0
ROM:8000FF90                 jal     passwd_generator

e ora: passwd_generator

root@kitploit:~
ROM:80010A2C passwd_generator:                         # CODE XREF: CMD_ATEN+50p
ROM:80010A2C                 lui     $t9, 0xA11F
ROM:80010A30                 lw      $v1, ptrDO_GTABLE
ROM:80010A34                 lw      $t8, dword_80017050
ROM:80010A38                 lw      $v1, 0x18($v1)   # take the seed part, generated by the ATSE command
ROM:80010A3C                 lbu     $t8, 0x6D($t8)   # take the last byte of the MAC Address
ROM:80010A40                 sll     $v1, 8     # $v1 = v1 << 8
ROM:80010A44                 andi    $t7, $t8, 7    # $t7 = t8 & 0x7
ROM:80010A48                 li      $t8, 0     # $t8 = 0
ROM:80010A4C                 srl     $v1, 8     # $v1 = v1 >> 8 
ROM:80010A50                 li      $t9, 0xA11F5AC6    # $t9 = MAGIC
ROM:80010A54                 j       loc_80010A68
ROM:80010A58                 addu    $t9, $v1, $t9    # $t9 = $v1 + $t9
ROM:80010A5C  # ---------------------------------------------------------------------------
ROM:80010A5C
ROM:80010A5C loc_80010A5C:                              # CODE XREF: passwd_generator+40j
ROM:80010A5C                 sll     $t9, 31      # $t9 = $t9 << 31
ROM:80010A60                 or      $t9, $t6, $t9    # $t9 = $t6 | $t9
ROM:80010A64                 addiu   $t8, 1       # $t8 = $t8 + 1
ROM:80010A68
ROM:80010A68 loc_80010A68:                # CODE XREF: passwd_generator+28j
ROM:80010A68                 sltu    $t6, $t8, $t7    # $t6 = (t8 < t7? 1:0)
ROM:80010A6C                 bnez    $t6, loc_80010A5C    # take jump if $t6 != 0
ROM:80010A70                 srl     $t6, $t9, 1    # $t6 = $t9 >> 1
ROM:80010A74                 jr      $ra      # all done, exit
ROM:80010A78                 xor     $v0, $t9, $v1    # $v0 = $t9 ^ $v1

Cosa possiamo concludere:

  • $v1 è il valore del seed (generato dal comando ATSE, zero se ATSE non viene usato)
  • $t8 contiene inizialmente l'ultimo byte dell'indirizzo MAC (ultimo ottetto)
  • 0xA11F5AC6 è il valore magico che stavamo cercando!
  • Quelle due istruzioni: "$v1 = v1 << 8" e "$v1 = v1 >> 8" equivalgono a "seed = seed & 0x00FFFFFF"
  • Il ciclo con (sll-or-srl) non è altro che un'istruzione ROR (l'istruzione ROR su MIPS è una pseudo-istruzione, solitamente emulata usando una sequenza sll-or-srl)
  • $v0 è il risultato

Ora scriviamo un programma in C che faccia la stessa cosa e compiliamolo:

root@kitploit:~
U32 passwd_generator(U32 seed, U8 last_mac_octet)
{
      U32 b = seed & 0x00FFFFFF;
      U32 r = ROR(b + 0xA11F5AC6, last_mac_octet & 7);
      return r^b;
}

Ora eseguiamo ATSE per ottenere il seed e usiamolo (per esempio: ho ottenuto 088521A78838):

root@kitploit:~
$ ./gen_pass 088521A78838

Eseguiamo il comando magico che abbiamo appena hackerato :p

root@kitploit:~
$ ATEN1, A12F5AC6
root@kitploit:~
ATEN1, A12F5AC6
OK
ATHE
======= Debug Command Listing =======
AT          just answer OK
ATHE          print help
ATBAx         change baudrate. 1:38.4k, 2:19.2k, 3:9.6k 4:57.6k 5:115.2k
ATENx,(y)     set BootExtension Debug Flag (y=password)
ATSE          show the seed of password generator
ATTI(h,m,s)   change system time to hour:min:sec or show current time
ATDA(y,m,d)   change system date to year/month/day or show current date
ATDS          dump RAS stack
ATDT          dump Boot Module Common Area
ATDUx,y       dump memory contents from address x for length y
ATWBx,y       write address x with  8-bit value y
ATWWx,y       write address x with 16-bit value y
ATWLx,y       write address x with 32-bit value y
ATRBx         display the  8-bit value of address x
ATRWx         display the 16-bit value of address x
ATRLx         display the 32-bit value of address x
ATGO(x)       run program at addr x or boot router
ATGR          boot router
ATGT          run Hardware Test Program
AT%Tx         Enable Hardware Test Program at boot up
ATBTx         block0 write enable (1=enable, other=disable)

< press any key to continue >
ATRTw,x,y(,z) RAM test level w, from address x to y (z iterations)
ATWEa(,b,c,d) write MAC addr, Country code, EngDbgFlag, FeatureBit to flash ROM
ATCUx         write Country code to flash ROM
ATCB          copy from FLASH ROM to working buffer
ATCL          clear working buffer
ATSB          save working buffer to FLASH ROM
ATBU          dump manufacturer related data in working buffer
ATSH          dump manufacturer related data in ROM
ATWMx         set low 6 digits MAC address in working buffer
ATMHx         set hight 6 digits MAC address in working buffer
ATBS          show the bootbase seed of password generator
ATLBx         xmodem upload bootbase,x is password
ATSMx         set 6 digits MAC address in working buffer
ATCOx         set country code in working buffer
ATFLx         set EngDebugFlag in working buffer
ATSTx         set ROMRAS address in working buffer
ATSYx         set system type in working buffer
ATVDx         set vendor name in working buffer
ATPNx         set product name in working buffer
ATFEx,y,...   set feature bits in working buffer
ATMP          check & dump memMapTab
ATDOx,y       download from address x for length y to PC via XMODEM

< press any key to continue >
ATTD          download router configuration to PC via XMODEM
ATUPx,y       upload to RAM address x for length y from PC via XMODEM
ATUR          upload router firmware to flash ROM
ATDC          hardware version check disable during uploading firmware
ATLC          upload router configuration file to flash ROM
ATUXx(,y)     xmodem upload from flash block x to y
ATERx,y       erase flash rom from block x to y
ATWFx,y,z     copy data from addr x to flash addr y, length z
ATXSx         xmodem select: x=0: CRC mode(default); x=1: checksum mode
ATLD          Upload Configuration File and Default ROM File to Flash
ATBR              Reset to default Romfile
ATCD          Convert Running ROM File to Default ROM File into Flash

OK

Finalmente otteniamo un intero nuovo set di comandi che ci consente di fare il dump della memoria

root@kitploit:~
$ ATMP
root@kitploit:~
ROMIO image start at bfc30000
code version: 
code start: 80008000
code length: 1A5D4E
memMapTab: 18 entries, start = bfc44000, checksum = 9770
$RAM Section:
  0: BootExt(RAMBOOT), start=80030000, len=18000
  1: HTPCode(RAMCODE), start=80048000, len=E0000
  2: RasCode(RAMCODE), start=80048000, len=420000
$ROM Section:
  3: BootBas(ROMIMG), start=bfc28000, len=4000
  4: DbgArea(ROMIMG), start=bfc2c000, len=2000
  5: RomDir2(ROMDIR), start=bfc2e000, len=2000
  6: BootExt(ROMIMG), start=bfc30030, len=13FD0
  7: MemMapT(ROMMAP), start=bfc44000, len=C00
  8: HTPCode(ROMBIN), start=bfc44c00, len=8000
     (Compressed)
     Version: HTP_TC V 0.05, start: bfc44c30
     Length: 10488, Checksum: CB32
     Compressed Length: 41CF, Checksum: D5A5
  9: termcap(ROMIMG), start=bfc4cc00, len=400
 10: RomDefa(ROMIMG), start=bfc4d000, len=2000
 11: LedDefi(ROMIMG), start=bfc4f000, len=400
 12: LogoImg(ROMIMG), start=bfc4f400, len=2000
 13: LogoImg2(ROMIMG), start=bfc51400, len=2000
 14: StrImag(ROMIMG), start=bfc53400, len=32000
 15: StrImag2(ROMIMG), start=bfc85400, len=32000
 16: Rt11nE2p(ROMIMG), start=bfcb7400, len=400
 17: RasCode(ROMBIN), start=bfcb7800, len=246C00
     (Compressed)
     Version: ADSL ATU-R, start: bfcb7830
     Length: 321D2C, Checksum: 582D
     Compressed Length: 11E54B, Checksum: B30B
$USER Section:
Msecs   128
Heap0   16   300 16
Heap1   32   64  4
Heap2   64   64  4
Heap3   128  160 4
Heap4   192  256 4
Heap5   256  80  4
Heap6   320  20   4
Heap7   384  4   2
Heap8   448  20  2
Heap9   512  34  2
Heap10  1024 52  4
Heap11  2048 20  2
Heap12  3172 4   2
Heap13  4096 2   2
Heap14  0 0
...

Quello che abbiamo appena imparato ci aiuterà ad analizzare i file rom estratti in precedenza

root@kitploit:~
code start: 80008000
code length: 1A5D4E

Ora possiamo impostare l'indirizzo di inizio ROM e l'indirizzo di caricamento a 0x80008000 dopo aver scaricato un nuovo file rom usando:

root@kitploit:~
$ ATDO 80008000, 1A5D4E

Sappiamo che ATGR avvia il router, quindi quello che possiamo fare è tracciarlo per trovare le istruzioni che passano l'esecuzione alla seconda parte del firmware.

atgr1

root@kitploit:~
ROM:80011E8C loc_80011E8C:            # CODE XREF: LoadAndRunImage+D8j
ROM:80011E8C                 jal     sub_80009B24
ROM:80011E90                 li      $a0, 0x1F4
ROM:80011E94
ROM:80011E94 execute_image:           # execute image
ROM:80011E94                 jalr    $s0        # jump and link to address in $s0
ROM:80011E98                 nop

Ora dobbiamo chiederci: qual è l'indirizzo memorizzato in $s0? Ovviamente non possiamo ancora impostare un breakpoint e non possiamo visualizzare i registri, quindi dobbiamo farlo uscire con qualche trucco. Fortunatamente possiamo leggere e scrivere la memoria; dai un'occhiata al seguente comando:

root@kitploit:~
ATWL 80011E94, ae30001c
ATGR

Da come sembra, questo comando applica una patch all'istruzione a 0x80011E94 con ae30001c (la rappresentazione in byte dell'istruzione MIPS sw $s0, 0x1C($s1)). Sovrascrivendo l'originale jalr $s0 con sw $s0, 0x1C($s1), abbiamo costretto il programma a memorizzare il contenuto del registro $s0 all'indirizzo di memoria 0x8001FF1C. Quindi ora il firmware del secondo stadio non verrà eseguito; al suo posto verrà mostrato il messaggio "ERROR" e avremo ancora accesso alla console del primo stadio. Evviva! Quindi diamo un'occhiata a cosa è stato memorizzato a 0x8001FF1C.

root@kitploit:~
ATRL 8001FF1C
8001FF1C: 80020000

Preso! ... usando 0x80020000 possiamo fare il dump e analizzare correttamente la seconda parte del firmware

Continua ...

Scarica lo strumento