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
shadow — Framework di sfruttamento dell'heap jemalloc | Kitploit
Strumenti/GitHubGitHub/census/shadow
Memory ForensicsExploitReverse EngineeringDebuggerBinary Exploitation
GitHubcensus/shadow

shadow

Framework di sfruttamento dell'heap jemalloc

Vedi Repository
469714 anni faRevisionato da Kitploit

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

shadow :: De Mysteriis Dom jemalloc

shadow è un framework per lo sfruttamento dell'heap jemalloc. È stato progettato per essere agnostico rispetto all'applicazione target che utilizza jemalloc come allocatore di heap (sia esso Android's libc, Firefox, FreeBSD's libc, jemalloc standalone, o altro). La versione attuale (2.0) è stata testata estesamente con i seguenti target:

  • Android 6-9 libc (ARM32 e ARM64)
  • Firefox (x86 e x86-64) su Windows e Linux

Oltre al codice sorgente dello strumento, questo repository include anche documentazione su come configurare un ambiente di debug userland Android per utilizzare shadow, una panoramica rapida delle strutture jemalloc di Android utilizzando shadow, e alcune note su come i bug di free() doppia, non allineata e arbitraria si comportano su jemalloc di Android.

Usage

Quando si emette un comando specifico di jemalloc per la prima volta, shadow analizza tutti i metadati jemalloc che conosce e li salva in un file pickle Python. I comandi successivi usano questo file pickle invece di analizzare nuovamente i metadati dalla memoria per essere più veloci.

Quando si sa che lo stato dei metadati jemalloc è cambiato (ad esempio quando sono state fatte alcune allocazioni o è stata attivata una garbage collection), usare il comando jeparse per ri-analizzare i metadati e ricreare il file pickle.

Android Installation

Il primo passo è installare pyrsistence sulla propria macchina host.

Su un dispositivo rootato fare quanto segue:

root@kitploit:~
host$ adb shell
phone$ su root
phone# ps -e

Dall'output di ps selezionare un processo, ad esempio com.google.process.gapps:

root@kitploit:~
...
u0_a19    4679  3214  1668980 69216 SyS_epoll_ 7fa5f41430 S com.google.process.gapps
...
phone$ cd /data/local/tmp
phone$ ./gdbserver64 :5039 --attach 4679

Si possono trovare i binari di GDB server per ARM32 e ARM64 nella directory "bin". Oppure, se non ci si fida, fare:

root@kitploit:~
host$ git clone http://android.googlesource.com/toolchain/gdb
host$ cd ./gdb/gdb-7.11
host$ mkdir build64; cd build64
host$ ../configure --program-prefix=aarch64-eabi-linux- --target=aarch64-eabi-linux --disable-werror
host$ make
host$ sudo make install

Poi sulla macchina host fare:

root@kitploit:~
host$ adb forward tcp:5039 tcp:5039
host$ aarch64-eabi-linux-gdb
(gdb) target remote :5039
(gdb) source /dir/with/shadow/gdb_driver.py
(gdb) jeparse -c /dir/with/shadow/cfg/android7_64.cfg
(gdb) jeruns -c

A volte GDB server smette di ascoltare se si impiega troppo tempo ad emettere il comando target remote :5039. Quindi se si vedono errori strani quando si emette il comando jeparse, basta ricominciare dall'inizio.

Windows/Firefox Installation

shadow per Windows/Firefox è stato testato con quanto segue:

  • Windows 8.1 e 10 x86-64
  • Windows 7 SP1 x86 e x86-64
  • Varie versioni di WinDBG
  • pykd version 0.3.2.8
  • Molte diverse versioni di Firefox (sia x86-64 che x86), inclusa l'ultima stabile (55.0)

Nota: Se si lavora con una versione di Firefox precedente alla 36.0 usare il ramo mozjs!

All'inizio è necessario configurare WinDBG con Mozilla's symbol server. È anche necessario installare pykd. Poi copiare la directory shadow che hai clonato da GitHub in qualche percorso (ad esempio C:\tmp\).

Si può anche trovare uno script di inizializzazione esempio di WinDBG nel file "windbg-init.cmd". Posizionarlo in C:\tmp\ e avviare WinDBG con windbg.exe -c "$$>< C:\tmp\windbg-init.cmd".

Infine, da WinDBG eseguire i seguenti comandi:

root@kitploit:~
!load pykd.pyd
!py c:\\tmp\\shadow\\pykd_driver help

[shadow] De Mysteriis Dom jemalloc
[shadow] shadow v2.0
[shadow] Firefox v56.0a1 (x86-64)

[shadow] jemalloc-specific commands:
[shadow]   jechunks                : dump info on all available chunks
[shadow]   jearenas                : dump info on jemalloc arenas
[shadow]   jerun [-m] <address>    : dump info on a single run
[shadow]                                 -m : map content preview to metadata
[shadow]   jeruns [-cs]            : dump info on jemalloc runs
[shadow]                                 -c : current runs only
[shadow]                    -s <size class> : runs for the given size class only
[shadow]   jebins                  : dump info on jemalloc bins
[shadow]   jebininfo               : dump info on bin sizes 
[shadow]   jesize2bin              : convert size to bin index
[shadow]   jeregions <size class>  : dump all runs that host the regions of
[shadow]                             the given size class
[shadow]   jesearch [-cs] <hex>    : search the heap for the given hex dword
[shadow]                                 -c : current runs only
[shadow]                    -s <size class> : regions of the given size only
[shadow]   jeinfo <address>        : display all available details for an address
[shadow]   jedump [path]           : store the heap snapshot to the current
[shadow]                             working directory or to the specified path
[shadow]   jestore [path]          : jedump alias
[shadow]   jetcaches               : dump info on all tcaches
[shadow]   jetcache [-bs] <tid>    : dump info on single tcache
[shadow]                    -b <bin index>  : info for the given bin index only
[shadow]                    -s <size class> : info for the given size class only
[shadow]   jeparse [-crv]           : parse jemalloc structures from memory
[shadow]                   -c <config file> : jemalloc target config file
[shadow]                                 -r : read content preview
[shadow]                                 -v : produce debug.log
[shadow] Firefox-specific (pykd only) commands:
[shadow]   nursery                 : display info on the SpiderMonkey GC nursery
[shadow]   symbol [-vjdx] <size>   : display all Firefox symbols of the given size
[shadow]                                 -v : only class symbols with vtable
[shadow]                                 -j : only symbols from SpiderMonkey
[shadow]                                 -d : only DOM symbols
[shadow]                                 -x : only non-SpiderMonkey symbols
[shadow]   pa <address> [<length>] : modify the ArrayObject's length (default new length 0x666)
[shadow] Android-specific commands:
[shadow]   jefreecheck [-bm]                : display addresses that can be passed to free()
[shadow]                     -b <bin index> : display addresses that will be freed to
[shadow]                                      the tcache bin of <bin index>
[shadow]                          -m <name> : only search this specific module
[shadow] Generic commands:
[shadow]   jeversion               : output version number
[shadow]   jehelp                  : this help message

Se non si vede il messaggio di aiuto sopra, hai fatto qualcosa di sbagliato ;)

Support for symbols

Nota: Questa funzionalità è attualmente solo per Firefox/Windows!

Il comando symbol permette di cercare classi (e strutture) SpiderMonkey e DOM di dimensioni specifiche. Questo è utile quando si cercano di sfruttare bug use-after-free, o quando si vogliono posizionare oggetti vittima interessanti da sovrascrivere/corruttare.

Nella directory principale di shadow si possono trovare due piccole utility per il parsing di PDB, symhex.py e pdbdy.py (più veloce). Eseguirle su "xul.pdb" per generare il file pickle Python che shadow si aspetta nella directory "pdb" (come "pdb/xul-VERSION.pdb.pkl"). Prima di eseguirle assicurarsi di aver registrato "msdia90.dll"; ad esempio su Windows 8.1 x86-64 si può fare con:

regsvr32 "c:\Program Files (x86)\Common Files\Microsoft Shared\VC\msdia90.dll"

da un prompt di Amministratore. È anche necessario il modulo Python "comtypes"; installare pip e poi fare pip install comtypes.

Per ottenere "xul.pdb" è necessario configurare WinDBG con Mozilla's symbol server.

Design

unmask_jemalloc è stato inizialmente riprogettato con un design modulare per supportare tutti e tre i principali debugger e piattaforme (WinDBG, GDB e LLDB). Lo strumento è stato rinominato shadow quando sono state aggiunte funzionalità specifiche per Firefox/Windows/WinDBG.

Quello che segue è una panoramica del nuovo design (leggere le frecce come "import"). L'obiettivo è, ovviamente, avere tutto il codice dipendente dal debugger nei moduli *_driver e *_engine.

root@kitploit:~
---------------------------------------------------------------------------------------

                                                    debugger-required frontend (glue)


+------------+     +-------------+     +-------------+
| gdb_driver |     | lldb_driver |     | pykd_driver |
+------------+     +-------------+     +-------------+
      ^                   ^                   ^
      |                   |                   |
------+-------------------+-------------------+----------------------------------------
      |                   |                   |   
      |                   +--------+          |
      +------------------------    |    +-----+        core logic (debugger-agnostic)
                              |    |    |
                              |    |    |
                           +-----------------+
  +------+                 |                 |
  |      |---------------> |      shadow     |<-----+
  | util |        +------> |                 |      |
  |      |        |        +-----------------+      |
  +------+        |          ^  ^     ^    ^        |
    | | |         |          |  |     |    |        |   +--------+
    | | |   +-----+----------+  |     +----+--------+---| symbol |
    | | |   |     |             |          |        |   +--------+
  +-+ | |   |  +----------+     |          |        |   +---------+
  |   | |   |  | jemalloc |     |          +--------+---| nursery |
  |   | |   |  +----------+     |                   |   +---------+
  |   | |   |   ^    ^   ^      |                   |
  |   | |   |   |    |   |      |                   |
  |   | |   |   |    |   +------+--------+          |
  |   | |   |   |    |          |        |          |
  |   | +---+---+----+----------+--------+-----+    |
  |   |     |   |    |          |        |     |    |
  |   +-----+---+----+----+     |        |     |    |
  |         |   |    |    |     |        |     |    |
--+---------+---+----+----+-----+--------+-----+----+----------------------------------
  |         |   |    |    |     |        |     |    |
  |         |   |    |    |     |        |     |    |       debugger-dependent APIs
  |         |   |    |    |     |        |     |    |
  |         |   |    |    |     |        |     |    |
  |         |   |    |    v     |        |     v    |
  |  +------------+  |  +-------------+  |  +-------------+
  +->| gdb_engine |  +--| lldb_engine |  +--| pykd_engine |
     +------------+     +-------------+     +-------------+
           ^                   ^                   ^
           |                   |                   |
       +---+         +---------+   +---------------+
       |             |             |
       |             |             |
-------+-------------+-------------+---------------------------------------------------
       |             |             |
       |             |             |                        debugger-provided backend
       |             |             |
       |             |             |
    +-----+      +------+      +------+
    | gdb |      | lldb |      | pykd |
    +-----+      +------+      +------+

---------------------------------------------------------------------------------------
Scarica lo strumento