US 22 Iooss Ghost in The Wireless Iwlwifi Edition
US 22 Iooss Ghost in The Wireless Iwlwifi Edition
iwlwifi Edition
Nicolas Iooss, Gabriel Campana
#BHUSA @BlackHatEvents
Context
- Up-to-date Ubuntu 18.04 LTS
- HTTP server
- Android smartphone
- The chip has DMA (Direct Memory Access) by design, because network
- DMA attacks: FireWire attacks, PCIe screamer, Thunderspy, Thunderclap…
7
Information Classification: General 7 #BHUSA @BlackHatEvents
Intel WireLess (IWL) Wi-Fi on Linux
FW
# ls /lib/firmware/iwlwifi-9000-pu-b0-jf-b0-*
/lib/firmware/iwlwifi-9000-pu-b0-jf-b0-33.ucode
/lib/firmware/iwlwifi-9000-pu-b0-jf-b0-34.ucode
/lib/firmware/iwlwifi-9000-pu-b0-jf-b0-38.ucode
/lib/firmware/iwlwifi-9000-pu-b0-jf-b0-41.ucode
/lib/firmware/iwlwifi-9000-pu-b0-jf-b0-43.ucode
/lib/firmware/iwlwifi-9000-pu-b0-jf-b0-46.ucode
00000000: 0000 0000 4957 4c0a 7265 6c65 6173 652f ....IWL.release/
Header: 00000010: 636f 7265 3433 3a3a 3666 3966 3231 3563 core43::6f9f215c
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
- API version 0x2e = 46
00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
- build number 6f9f215c 00000040: 0000 0000 0000 0000 2e00 0000 5c21 9f6f ............\!.o
00000050: 0000 0000 0000 0000 1600 0000 0c00 0000 ................
Entries: 00000060: 0000 0000 db15 060f 8b95 020f 2400 0000 ............$...
Type, 00000070: 0c00 0000 2e00 0000 5c21 9f6f 0000 0000 ........\!.o....
Length, 00000080: 3700 0000 2000 0000 143c 8100 7c74 4600 7... ....<..|tF.
…
Value
000002e0: 0700 0000 0000 0000 1b00 0000 0400 0000 ................
000002f0: 0200 0000 1300 0000 bc02 0000 0040 4000 .............@@.
00000300: 0600 0000 a100 0000 0000 0100 0000 0000 ................
00000310: 8680 0000 2801 2120 cb1e 0200 4000 0000 ....(.! ....@...
No encryption
Information Classification: General 10 #BHUSA @BlackHatEvents
Firmware file format
Linux: drivers/net/wireless/intel/iwlwifi/fw/file.h
00000000: 0000 0000 4957 4c0a 7265 6c65 6173 652f ....IWL.release/
00000010: 636f 7265 3433 3a3a 3666 3966 3231 3563 core43::6f9f215c
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 0000 2e00 0000 5c21 9f6f ............\!.o
00000050: 0000 0000 0000 0000 1600 0000 0c00 0000 ................
00000060: 0000 0000 db15 060f 8b95 020f 2400 0000 ............$...
00000070: 0c00 0000 2e00 0000 5c21 9f6f 0000 0000 ........\!.o....
00000080: 3700 0000 2000 0000 143c 8100 7c74 4600 7... ....<..|tF.
…
000002e0: 0700 0000 0000 0000 1b00 0000 0400 0000 ................
000002f0: 0200 0000 1300 0000 bc02 0000 0040 4000 .............@@.
00000300: 0600 0000 a100 0000 0000 0100 0000 0000 ................
00000310: 8680 0000 2801 2120 cb1e 0200 4000 0000 ....(.! ....@...
No encryption
Information Classification: General 11 #BHUSA @BlackHatEvents
$
-
Firmware decoder
parse_intel_wifi_fw.py iwlwifi-9000-pu-b0-jf-b0-46.ucode
DEF_CALIB (12 bytes): ucode_type=REGULAR flow_trigger=0x0F0615DB event_trigger=0x0F02958B
- FW_VERSION (12 bytes): 46.6f9f215c.0
- LMAC_DEBUG_ADDRS (32 bytes):
error_event_table_ptr = 0x00813C14
00000000: 0000 0000 4957 4c0a 7265 6c65 6173 652f ....IWL.release/
log_event_table_ptr = 0x0046747C
00000010: 636f 7265 3433 3a3a 3666 3966 3231 3563 core43::6f9f215c
…
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
- NUM_OF_CPU (4 bytes): 2
00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
- SEC_RT (700 bytes): runtime microcode at 00404000..004042b8 (ACM Header)
00000040: 0000 0000 0000 0000 2e00 0000 5c21 9f6f ............\!.o
00000050: 0000 0000 0000 0000 1600 0000 0c00 0000 ................
00000060: 0000 0000 db15 060f 8b95 020f 2400 0000 ............$...
00000070: 0c00 0000 2e00 0000 5c21 9f6f 0000 0000 ........\!.o....
00000080: 3700 0000 2000 0000 143c 8100 7c74 4600 7... ....<..|tF.
…
000002e0: 0700 0000 0000 0000 1b00 0000 0400 0000 ................
000002f0: 0200 0000 1300 0000 bc02 0000 0040 4000 .............@@.
00000300: 0600 0000 a100 0000 0000 0100 0000 0000 ................
00000310: 8680 0000 2801 2120 cb1e 0200 4000 0000 ....(.! ....@...
No encryption
Information Classification: General 12 #BHUSA @BlackHatEvents
2 Processors?!?
PCIe Main System
Firmware loading
UMAC CPU
Upper Medium Access Controller
On-Chip Memory
Unknown bus
(SRAM, DCCM…)
LMAC CPU
Lower Medium Access Controller
Unknown bus
- DEF_CALIB
Memory
- FW_VERSION
00000000..00037fff (229376 bytes)
- LMAC_DEBUG_ADDRS
cpu_rec: ARCompact
… c0080000..c008ffff (65536 bytes)
- NUM_OF_CPU 2
- SEC_RT 00404000 00404000..004042b7 (696 bytes) Authenticated Module
LMAC
#BHUSA @BlackHatEvents
Information Classification: General
14
Reverse all the things!
Tools: objdump, IDA Pro, Ghidra (Pull Req #3006) and custom Python scripts
FAIL
17
Information Classification: General 17 #BHUSA @BlackHatEvents
Linux Debug Filesystem
Maaaaaany files in the debugfs!
# ls /sys/kernel/debug/iwlwifi/0000:00:14.3/iwlmvm
bt_cmd fw_restart nvm_sw
bt_force_ant fw_rx_stats prph_reg
bt_notif fw_ver ps_disabled
bt_tx_prio he_sniffer_params rfi_freq_table
ctdp_budget indirection_tbl sar_geo_profile
d3_test inject_beacon_ie scan_ant_rxchain
d3_wake_sysassert inject_beacon_ie_restore send_echo_cmd
disable_power_off inject_packet send_hcmd
drop_bcn_ap_mode last_netdetect_scans set_nic_temperature
drv_rx_stats mem sram
enabled_severities netdev:p2p-dev-wlp0s20@ sta_drain
enable_scan_iteration_notif netdev:wlp0s20f3@ stations
force_ctkill nic_temp stop_ctdp
fw_dbg_collect nvm_calib timestamp_marker
fw_dbg_conf nvm_hw tx_flush
fw_dbg_domain nvm_phy_sku uapsd_noagg_bssids
fw_info nvm_prod
fw_nmi nvm_reg
# DBGFS=/sys/kernel/debug/iwlwifi/0000:00:14.3
# dd if=$DBGFS/iwlmvm/mem bs=1 count=128 | xxd
00000000: 2020 800f 0000 4000 2020 800f 0300 e474 ....@. .....t
00000010: 2020 800f 0300 3837 2020 800f 0000 c819 ....87 ......
00000020: 6920 0000 6920 4000 6920 0000 6920 4000 i ..i @.i ..i @.
00000030: 2020 800f 4700 14b6 6920 0000 6920 4000 ..G...i ..i @.
00000040: 6920 0000 4a20 0000 4a21 0000 4a22 0000 i ..J ..J!..J"..
00000050: 4a23 0000 4a24 0000 4a25 0000 4a26 0000 J#..J$..J%..J&..
00000060: 4a27 0000 4a20 0010 4a21 0010 4a22 0010 J'..J ..J!..J"..
00000070: 4a23 0010 4a24 0010 4a25 0010 4a26 0010 J#..J$..J%..J&..
23
Information Classification: General 23 #BHUSA @BlackHatEvents
Vulnerability
$ sudo ./exploit_enable_debug.py
[*] loading module pwn
[*] putting shellcode in memory (24 bytes)
[*] ensuring shellcode is there
[*] triggering overflow
[*] ensuring debug flag is set
SUCCESS (read at 0xc0a03088: 0x400)!
[*] unloading module pwn
30
Information Classification: General 30 #BHUSA @BlackHatEvents
Discovering the Loader
Registers
Get pc value LMAC pc = 0x0006107e
Registers
Get pc value LMAC pc = 0x0006107e
Registers
Get pc value LMAC pc = 0x0006107e
3. Wait
3. Wait
36
Information Classification: General 36 #BHUSA @BlackHatEvents
Tracing
- Tell which functions are executed
- Replace the first instruction (push_s blink) of every functions with:
- LMAC: trap_s 0
- UMAC: invalid instruction
- Hook the exception vector in the exception handler
- Log the address to a unused buffer (0xc004ad00 - 0xc0050000)
- Emulate push_s blink and return after the patched instruction
- Write hooks thanks to debug mode
- Read the shared buffer from the host in a loop
42
Information Classification: General 42 #BHUSA @BlackHatEvents
The Additional Code in the File
Wi-Fi chip
Firmware File
- NUM_OF_CPU 2
Memory
- SEC_RT 00404000
00000000..00037fff (229376 bytes)
LMAC
- SEC_RT 00800000
- SEC_RT 00000000 c0080000..c008ffff (65536 bytes)
- SEC_RT 00456000
… 00404000..004042b7 (696 bytes)
- SEC_RT 00405000
- SEC_RT c0080000 00405000..004052b7 (696 bytes)
UMAC
- SEC_RT c0880000
- SEC_RT 80448000 80448000..80455ad3 (56020 bytes)
… 00456000..0048d873 (227444 bytes)
- NUM_OF_CPU 2
Memory
- SEC_RT 00404000
00000000..00037fff (229376 bytes)
LMAC
- SEC_RT 00800000
- SEC_RT 00000000 c0080000..c008ffff (65536 bytes)
- SEC_RT 00456000
… 00404000..004042b7 (696 bytes)
- SEC_RT 00405000
- SEC_RT c0080000 00405000..004052b7 (696 bytes)
UMAC
- SEC_RT c0880000
- SEC_RT 80448000 80448000..80455ad3 (56020 bytes)
… 00456000..0048d873 (227444 bytes)
aaaabbbb: separator (4 bytes)
- SEC_RT aaaabbbb
- SEC_RT 00000000 00800000..00817fff (98304 bytes)
00000000..00000297 (664 bytes)
- SEC_RT 01000000
c0880000..c0887fff (32768 bytes)
01000000..0103afff (241664 bytes)
DMA Attack
Other memory
51
Information Classification: General 51 #BHUSA @BlackHatEvents
Context
- Up-to-date Ubuntu 18.04 LTS
- HTTP server
- Android smartphone
https://github.com/Ledger-Donjon/intel-wifi-research-tools
@IooNag
-X
55
Information Classification: General 55 #BHUSA @BlackHatEvents