examples/shellcode_run.py crashes: unhandled CPU exceptions (ARM64/ARM/MIPS) and missing-DLL handling (Windows)

Offen
#1,629 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
python

Rechercherichtung

Start with examples/shellcode_run.py and reproduce the ARM64 case with ql.run(), then inspect the Linux OS layer’s syscall and unhandled-interrupt handling for the ARM, ARM64, and MIPS exception cases described. Check examples/scripts/dllscollector.bat and the Windows stages for missing-DLL behavior; done means illegal-instruction stages end cleanly and stages lacking required DLLs are skipped with a helpful message.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Describe the bug

Running examples/shellcode_run.py does not complete. It crashes on the very first stage and never reaches the later ones. There are two distinct problems.

1. Unhandled CPU exception on ARM64 / ARM / MIPS (QlErrorCoreHook)

Since execve was patched to return -1 for paths outside the rootfs (commit "Patch POSIX execve"), the rootfs-less shellcodes in this example no longer stop at execve. Execution falls through into the trailing data (the sockaddr struct and the /bin/sh string), which decodes as an illegal instruction:

  • ARM64 / ARM: undefined instruction → exception 1 (EXCP_UDEF)
  • MIPS: reserved instruction → exception 20 (EXCP_RI)

The Linux OS layer only hooks the syscall trap (exception 2 for ARM/ARM64, 17 for MIPS), so these exceptions reach the unhandled-interrupt dispatcher and abort the whole run:

qiling.exception.QlErrorCoreHook: _hook_intr_cb : not handled

A real kernel would deliver SIGILL and terminate the process, rather than crashing the framework.

2. Windows stages crash with UC_ERR_READ_UNMAPPED when system DLLs are absent

The two Windows stages need genuine Windows system DLLs (collected via examples/scripts/dllscollector.bat), which are not shipped. On a stock checkout the loader logs Could not find DLL file: .../Windows/System32/ntdll.dll but then continues and dies with an unhandled unicorn.UcError: Invalid memory read (UC_ERR_READ_UNMAPPED) instead of failing with a clear, actionable message.

Sample Code

# examples/shellcode_run.py, first stage
from qiling import Qiling
from qiling.const import QL_ARCH, QL_OS, QL_VERBOSE

ARM64_LIN = bytes.fromhex(
    '420002ca210080d2400080d2c81880d2010000d4e60300aa01020010020280d2'
    '681980d2010000d4410080d2420002cae00306aa080380d2010000d4210400f1'
    '65ffff54e0000010420002ca210001caa81b80d2010000d4020004d27f000001'
    '2f62696e2f736800')

ql = Qiling(code=ARM64_LIN, archtype=QL_ARCH.ARM64, ostype=QL_OS.LINUX, verbose=QL_VERBOSE.DEBUG)
ql.run()   # -> QlErrorCoreHook: _hook_intr_cb : not handled

Expected behavior

examples/shellcode_run.py should run to completion. Illegal-instruction exceptions on the Linux archs should be treated as a fatal signal that ends the emulated process cleanly (as a real kernel would), and the Windows stages should be skipped with a helpful message when the required DLLs are not present.

Additional context

  • Qiling: 1.4.10 (reproduced on current master, da210f07)
  • Unicorn: 2.1.3
  • Python: 3.12.3
  • Host: Linux

I have fixes for all of the above and will open a PR shortly:

  • hook the undefined/reserved-instruction exceptions on ARM/ARM64/MIPS Linux and end emulation cleanly (SIGILL semantics);
  • detect missing Windows DLLs in the example and skip those stages gracefully;
  • plus a MIPS32 big-endian shellcode test.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Vorherrschende Sprache
Python
Sterne
6.2k
Forks
806
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

  • Enthält ein Dockerfile oder eine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus qilingframework/qiling

Alle Issues in qilingframework/qiling

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.