
asadbg is a framework of tools to aid in automating live debugging of Cisco ASA devices
初步说明:我们建议你将其作为 asatools 的一部分使用,但它也可以 独立使用。
asadbg 是一个工具框架,用于帮助自动执行 Cisco ASA 设备的实时调试, 以及通过串口/SSH 自动与 Cisco CLI 交互, 以快速执行重复性任务。

asadbg.cfg 配置文件,以方便调试不同的
版本主工具是 asadbg.py,它将执行大多数其他辅助脚本。
请注意,你可能需要先使用
asafw 解包固件,以获得最佳
的 asadbg 使用体验。
asadbg.py:用于调试 ASA 的主工具asdbg_hunt.py/asadbg_rename.py:与 idahunt 一起使用的 IDA Python 脚本,用于为新目标导入符号以下内容由 asadbg.py 自动导入,但我们提供一些
关于它们用途的信息:
asa_lib*.py:gdb Python 脚本,用于使用
libdlmalloc、
libptmalloc 和
libmempool。asa_sync.py:gdb Python 脚本,用于使用
ret-synccomm.py:一组用于通过串口、SSH、telnet 通信的函数。find_lina_pid.py:使用 SSH 命令查找 lina PIDtemplate_gdbinit:gdbinit 模板,由 asadbg.py 针对我们调试的每个目标
打补丁你首先需要修改 asadbg/env.sh 以匹配你的环境。它将
允许你定义所有脚本使用的工具路径,以及一些
与你的 ASA 环境匹配的变量。请注意,还有一个类似的
asafw/env.sh,但两个项目只需使用其中一个。我们
建议你将它添加到你的 ~/.bashrc 中:```
source /path/to/asadbg/env.sh
# 自动化调试
使用 asadbg 的主要好处之一是,你可以自动化使用模拟(GNS3)和真实 Cisco ASA 设备的操作。这可以包括一般性地自动化启动和运行各种固件与配置,也可以专门使用 gdb 自动化 `lina` 的调试过程。这主要通过 `asadbg.py` 脚本完成。其核心思路是预先在 ASA 设备的 flash 上装载你想要使用的固件和配置文件。对于每个你想要调试的固件,你可以使用类似 `asafw` 的工具来挖掘不同的符号,然后利用这些符号自动生成 gdbinit 文件。默认情况下,`asadbg.py` 会使用一个名为 `template_gdbinit` 的文件,在运行时根据数据库中存在的符号自动构建特定于版本的 gdbinit 文件。
## 快速启动真实设备(不进行调试)
你可以通过指定固件和配置文件来快速启动某个特定版本,这些文件必须已经存在于 CF 卡上。```
asadbg$ ./asadbg.py --firmware-type normal --serial-port /dev/ttyUSB0 --firmware asa802-k8.bin --config config-802
以下示例展示了如何设置配置文件来调试
GNS3 设备。首先我们定义一个类似下方的 asadbg.cfg 配置文件。它包含从 GNS3 自身获取的、已配置防火墙的 GNS3 IP/端口。```ini
[GLOBAL]
gns3_host=192.168.5.1
asadb_file=asadb.json
[asav941200] version=941200 arch=gns3 rootfs_path= /home/user/_asav941-200.qcow2.extracted/rootfs gns3_port=12005 attach_gdb=yes
它还指向ASA数据库文件`asadb.json`,其中包含所需的地址。这里重要的是,`asadbg.cfg`中指定的`version=941200`和`arch=gns3`能够匹配下面`asadb.json`中的固件。同时我们指明要附加gdb。```json
{
"ASLR": false,
"addresses": {
"clock_interval": 59514112,
"socks_proxy_server_start": 22139744,
"aaa_admin_authenticate": 418288
},
"fw": "asav941-200.qcow2",
"lina_imagebase": 4194304,
"version": "9.4.1.200",
"arch": 64
}
现在我们开始调试,clock_interval 将被自动修补:```
asadbg$ ./asadbg.py --name asav941200 --asadbg-config asadbg.cfg
[asadbg] Using config file: asadbg.cfg
[asadbg] Found section: 'asav941200' in config
[asadbg] Using gdb: '/usr/bin/gdb'
[asadbg] Using architecture: gns3
[asadbg] Trying lina: /home/user/_asav941-200.qcow2.extracted/rootfs/asa/bin/lina
[asadbg] Going to debug...
[asadbg] Using GNS3 emulator 192.168.5.1:12005
[asadbg] Starting gdb now...
[gdbinit_941200] Configuring paths...
[gdbinit_941200] Disabling pagination...
[gdbinit_941200] Connecting over TCP/IP...
0x0000003655201190 in ?? () from /home/user/_asav941-200.qcow2.extracted/rootfs/lib64/ld-linux-x86-64.so.2
[gdbinit_941200] Connected.
[gdbinit_941200] Watchdog disabled
[gdbinit_941200] heap debugging plugins loaded
[gdbinit_941200] Additional gdb scripts loaded
[gdbinit_941200] Done.
(gdb) c
Continuing.
## 使用配置文件调试真实设备
以下示例展示了如何设置配置文件,以通过串行控制台调试
真实的 Cisco ASA 设备。```ini
[GLOBAL]
serial_port=/dev/ttyUSB0
asadb_file=asadb.json
[asa924-gdb]
version=924
arch=32
rootfs_path=/home/user/_asa924-k8.bin.extracted/rootfs
firmware=asa924-k8-debugshell-gdbserver.bin
config=config-924
firmware_type=gdb
attach_gdb=yes
另请注意,我们需要指定一个 firmware_type,它指示固件是否
未修改、已 root、启用了串行 shell,还是已在启动时
启用了 gdb。这是因为我们将根据格式在启动时执行不同的操作。
这里我们可以看到,我们使用了一个修改过的固件
asa924-k8-debugshell-gdbserver.bin,它已在启动时启用了 gdbserver
并包含一个调试 shell。
我们在下面可以看到,当 bootrom 启动时,asadbg 会自动
中断该序列,以便加载固件和配置文件,这些文件
已在 CF 卡上。```
asadbg$ ./asadbg.py --name asa924-gdb --asadbg-config asadbg.cfg
[asadbg] Using config file: asadbg.cfg
[asadbg] Found section: 'asa924-gdb' in config
[asadbg] Using gdb: '/usr/bin/gdb'
[asadbg] Using architecture: 32
[asadbg] Trying lina: /home/user/_asa924-k8.bin.extracted/rootfs/asa/bin/lina
[asadbg] Going to debug...
[asadbg] Using serial port: /dev/ttyUSB0
[asadbg] Loading 'asa924-k8-debugshell-gdbserver.bin' with 'config-924'...
[comm] Waiting boot...
[SNIP]
Platform ASA5505
Use BREAK or ESC to interrupt boot. Use SPACE to begin boot immediately. Boot interrupted.
[SNIP] rommon #0> boot asa924-k8-debugshell-gdbserver.bin cfg=config-924 Launching BootLoader... Boot configuration file contains 1 entry.
Loading asa924-k8-debugshell-gdbserver.bin........ Booting... Platform ASA5505 [SNIP] SMFW PID: 514, Starting /asa/bin/lina under gdbserver /dev/ttyS0 SMFW PID: 512, started gdbserver on member: 514//asa/bin/lina SMFW PID: 512, created member ASA BLOB, PID=514 Process /asa/bin/lina created; pid = 517 Remote debugging using /dev/ttyS0 [comm] gdb detected - boot finished. [comm] Boot should be finished now? [asadbg] Starting gdb now... [gdbinit_924] Configuring paths... [gdbinit_924] Disabling pagination... [gdbinit_924] Connecting over USB... 0xdc7e2820 in ?? () from /home/user/_asa924-k8.bin.extracted/rootfs/lib/ld-linux.so.2 [gdbinit_924] Connected. [gdbinit_924] Watchdog disabled [gdbinit_924] heap debugging plugins loaded [gdbinit_924] Additional gdb scripts loaded [gdbinit_924] Done. (gdb) c Continuing.
# 导入附加符号
asadbg 的许多部分依赖于一个数据库 `asadbg/asadb.json`,其中包含各种固件版本的符号。我们提供了一小部分现有符号,但您可以手动添加其他符号,或使用
[idahunt](https://github.com/nccgroup/idahunt)
自动添加新目标。本节将介绍具体操作方法。
## 要求
asadbg 中的 IDA Python 脚本假定 `filelock.py/ida_helper.py` 可用。由于它们直接从 IDA Python 执行,我们目前的做法是在 `asadbg/` 中创建符号链接。我们无法在仓库中真正创建它们,因为 Windows 上的符号链接与 Linux 上的不同。因此需要手动完成。
在 Linux 上:```
asadbg$ ln -s ../idahunt/ida_helper.py ida_helper.py
asadbg$ ln -s ../idahunt/filelock.py filelock.py
在 Windows 上,使用管理员权限:``` C:\asadbg> mklink filelock.py ..\idahunt\filelock.py C:\asadbg> mklink ida_helper.py ..\idahunt\ida_helper.py
我们还需要设置数据库的路径(由 `env.sh` 自动完成):```
C:\idahunt>set ASADBG_DB=C:\asadbg\asadb.json
我们假设您已经使用例如 asafw 将所有固件提取到一个目录中,或者您只提取了 lina 文件并将它们放入一个能表明其来自哪个固件的目录结构中:```
C:\temp>tree /F
Folder PATH listing
Volume serial number is XXXX-XXX
C:.
├───asa924-k8.bin
│ lina
│
├───asa924-smp-k8.bin
│ lina
│
└───asav941-200.qcow2
lina
首先,你需要在 IDA 中进行初始分析。我们可以将 `--list-only` 与
任何命令一起使用,以检查该命令会得到什么结果。
注意,我们筛选了特定的 ASA 版本(9.2.4)和架构(32 位):```
C:\idahunt>idahunt.py --verbose --inputdir "C:\temp" --analyse --scripts C:\asadbg\asadbg_rename.py --filter "filters\ciscoasa.py -m 924 -M 924 -v -a 32"
[idahunt] IDA32 = C:\Program Files (x86)\IDA 6.95\idaq.exe
[idahunt] IDA64 = C:\Program Files (x86)\IDA 6.95\idaq64.exe
[idahunt] ANALYSING FILES
[idahunt] Analysing C:\temp\asa924-k8.bin\lina
[idahunt] C:\Program Files (x86)\IDA 6.95\idaq.exe -B -LC:\temp\asa924-k8.bin\lina.log C:\temp\asa924-k8.bin\lina
[ciscoasa] Skipping non 32-bit: C:\temp\asa924-smp-k8.bin\lina
[ciscoasa] Skipping version too high: C:\temp\asav941-200.qcow2\lina
[idahunt] Waiting on remaining 1 IDA instances
[idahunt] EXECUTE SCRIPTS
[idahunt] Executing script C:\asadbg\asadbg_rename.py for C:\temp\asa924-k8.bin\lina
[idahunt] C:\Program Files (x86)\IDA 6.95\idaq.exe -A -SC:\asadbg\asadbg_rename.py -LC:\temp\asa924-k8.bin\lina.log C:\temp\asa924-k8.bin\lina.idb
[ciscoasa] Skipping non 32-bit: C:\temp\asa924-smp-k8.bin\lina
[ciscoasa] Skipping version too high: C:\temp\asav941-200.qcow2\lina
[idahunt] Waiting on remaining 0 IDA instances
分析完成后,你应该在对应文件夹中的 lina 附近看到 lina.i64 或 lina.idb。
我们使用 idahunt 向数据库添加符号:``` C:\idahunt>idahunt.py --verbose --inputdir "C:\temp" --scripts C:\asadbg\asadbg_hunt.py --filter "filters\ciscoasa.py -v" [idahunt] IDA32 = C:\Program Files (x86)\IDA 6.95\idaq.exe [idahunt] IDA64 = C:\Program Files (x86)\IDA 6.95\idaq64.exe [idahunt] EXECUTE SCRIPTS [idahunt] Executing script C:\asadbg\asadbg_hunt.py for C:\temp\asa924-k8.bin\lina [idahunt] C:\Program Files (x86)\IDA 6.95\idaq.exe -A -SC:\asadbg\asadbg_hunt.py -LC:\temp\asa924-k8.bin\lina.log C:\temp\asa924-k8.bin\lina.idb [idahunt] Executing script C:\asadbg\asadbg_hunt.py for C:\temp\asa924-smp-k8.bin\lina [idahunt] C:\Program Files (x86)\IDA 6.95\idaq64.exe -A -SC:\asadbg\asadbg_hunt.py -LC:\temp\asa924-smp-k8.bin\lina.log C:\temp\asa924-smp-k8.bin\lina.i64 [idahunt] Executing script C:\asadbg\asadbg_hunt.py for C:\temp\asav941-200.qcow2\lina [idahunt] C:\Program Files (x86)\IDA 6.95\idaq64.exe -A -SC:\asadbg\asadbg_hunt.py -LC:\temp\asav941-200.qcow2\lina.log C:\temp\asav941-200.qcow2\lina.i64 [idahunt] Executing script C:\asadbg\asadbg_hunt.py for C:\temp\asav962-7.qcow2\lina [idahunt] C:\Program Files (x86)\IDA 6.95\idaq64.exe -A -SC:\asadbg\asadbg_hunt.py -LC:\temp\asav962-7.qcow2\lina.log C:\temp\asav962-7.qcow2\lina.i64 [idahunt] Waiting on remaining 0 IDA instances
# 在CLI上自动执行命令
我们支持通过SSH或串口自动执行一些有用的命令,
理论上也支持telnet,但尚未经过充分测试。```
$ comm.py -h
usage: comm.py [-h] [--comm COMM_TYPE] [--port TARGET_PORT] [--ip TARGET_IP]
[--user USER] [--pass PASSWORD] [--reboot] [--version]
[--disable-checkheaps] [--upload] [--force] [--download]
[--delete-ike-sa] [--delete-webvpn-sessions] [--md5]
[--input [INPUT [INPUT ...]]] [--oldssh] [--cmd CMD]
[-C CFG_FILE]
optional arguments:
-h, --help show this help message and exit
--comm COMM_TYPE Communication type {serial(default), telnet, ssh}
--port TARGET_PORT Specify a custom serial (e.g. "/dev/ttyUSB0")/telnet
(e.g. 5000) port)
--ip TARGET_IP Cisco ASA/GNS3 IP address
--user USER User for SSH
--pass PASSWORD Password for SSH
--reboot Reboot router (serial, SSH)
--version Get the version (serial, SSH)
--disable-checkheaps Disable checkheaps default timeout (60 sec)
--upload Upload over SSH
--force Overwrite existing files
--download Download over SSH
--delete-ike-sa Delete IKE SAs (serial, SSH)
--delete-webvpn-sessions
Delete WebVPN sessions (serial, SSH)
--md5 Compute MD5 for files (serial, SSH)
--input [INPUT [INPUT ...]]
List of input files for other commands (eg: file1
file2 file3) (e.g.: --upload, --download, --md5)
--oldssh Specify an old version of SSH (do not know specific
command lines options and do not need them because
unsecure :))
--cmd CMD Command to run on the CLI (debugging)
-C CFG_FILE File containing commands to use (e.g.
config/setup_ssh.cfg)
我们使用 --version,可以通过串口或 SSH 执行:```
$ comm.py --comm serial --port /dev/ttyUSB0 --version
[comm] Retrieving version now...
[comm] Serial: /dev/ttyUSB0
[comm] Detected version: 9.2(4)
$ comm.py --comm ssh --ip 192.168.210.77 --port 22 --user user --pass user --version
[comm] Retrieving version now...
[comm] SSH: 192.168.210.77:22
[comm] Detected version: 9.2(4)
## 重启 ASA
我们使用 `--reboot`:```
$ comm.py --comm ssh --reboot
[comm] Rebooting router now...
[comm] SSH: 192.168.210.77:22
如果你有一个正在运行的 CLI,你应该会看到它自动重启:``` ciscoasa#
*** --- START GRACEFUL SHUTDOWN --- Shutting down isakmp Shutting down License Controller Shutting down File system
*** --- SHUTDOWN NOW --- Process shutdown finished
## 上传文件到闪存
我们可以通过 SSH 一次上传多个文件:```
$ comm.py --upload --comm ssh --oldssh --pass user --input fw/*
[comm] Warning: using forced SSH
[comm] Uploading file...
[comm] SSH: 192.168.210.77:22
[comm] Uploading: asa924-5-k8.bin...
[comm] Executing 'sshpass -p user scp fw/asa924-5-k8.bin [email protected]:asa924-5-k8.bin'...
Connection to 192.168.210.77 closed by remote host.
[comm] Uploading file...
[comm] SSH: 192.168.210.77:22
[comm] Uploading: asa924-k8.bin...
[comm] Executing 'sshpass -p user scp fw/asa924-k8.bin [email protected]:asa924-k8.bin'...
Connection to 192.168.210.77 closed by remote host.
[comm] Finished all tasks.
请注意,如果你使用的是旧版 ssh 客户端,--oldssh 会很有用。
有时,检查 flash 上文件的 MD5 是很有用的, 可以确保文件已正确上传。``` $ comm.py --md5 --input asa924-k8.bin asa924-5-k8.bin --comm ssh --oldssh --ip 192.168.210.77 Calculating MD5. Will take 20 seconds... asa924-k8.bin = 4558b27d0dd7ba1751e43b0ba33593a3 Calculating MD5. Will take 20 seconds... asa924-5-k8.bin = 74765d62abb2c4a5e677ed9ca49ebf87
# 在 gdb 中确定 lina PID/内存映射```
(gdb) info proc mappings
Can't determine the current process's PID: you must name one.
我们使用 find_lina_pid.py 来查找 lina 的 PID。
然后我们使用 info proc mappings <pid> 来获取映射。```
(gdb) source find_lina_pid.py
Finding lina PID:
516
You can use the following to see the lina mapping: info proc mappings
(gdb) info proc mappings 516
process 516
Mapped address spaces:
Start Addr End Addr Size Offset objfile
0x8048000 0xa388000 0x2340000 0x0 /asa/bin/lina
0xa388000 0xa38a000 0x2000 0x233f000 /asa/bin/lina
0xa38a000 0xa9aa000 0x620000 0x2341000 /asa/bin/lina
0xa9aa000 0xb74b000 0xda1000 0xa9aa000 [heap]
0xa5ad9000 0xa5bda000 0x101000 0xa5ad9000
0xa5bda000 0xa5bde000 0x4000 0x0 /dev/zero (deleted)
0xa5bde000 0xa5de1000 0x203000 0xa5bde000
0xa5de1000 0xa5de5000 0x4000 0x50004000 /dev/mem
0xa5de5000 0xa5fe7000 0x202000 0xa5de5000
0xa5fe7000 0xa5fe8000 0x1000 0xffb00000 /dev/mem
0xa5fe8000 0xa5ff8000 0x10000 0xfff00000 /dev/mem
0xa5ff8000 0xa6000000 0x8000 0xd8000 /dev/mem
0xa6000000 0xa8724000 0x2724000 0x0 /dev/udma0
0xa8800000 0xab400000 0x2c00000 0x0 /SYSV00000002 (deleted)
0xab400000 0xab800000 0x400000 0x2c00000 /SYSV00000002 (deleted)
0xab800000 0xabc00000 0x400000 0x3000000 /SYSV00000002 (deleted)
0xabc00000 0xac000000 0x400000 0x3400000 /SYSV00000002 (deleted)
0xac000000 0xac400000 0x400000 0x3800000 /SYSV00000002 (deleted)
0xac400000 0xdbc00000 0x2f800000 0x3c00000 /SYSV00000002 (deleted)
0xdbf55000 0xdbf58000 0x3000 0xdbf55000
0xdbf58000 0xdc091000 0x139000 0x0 /lib/libc-2.9.so
0xdc091000 0xdc092000 0x1000 0x139000 /lib/libc-2.9.so
0xdc092000 0xdc094000 0x2000 0x139000 /lib/libc-2.9.so
0xdc094000 0xdc095000 0x1000 0x13b000 /lib/libc-2.9.so
0xdc095000 0xdc098000 0x3000 0xdc095000
0xdc098000 0xdc0a2000 0xa000 0x0 /lib/libgcc_s.so.1
0xdc0a2000 0xdc0a3000 0x1000 0x9000 /lib/libgcc_s.so.1
0xdc0a3000 0xdc0a4000 0x1000 0xa000 /lib/libgcc_s.so.1
0xdc0a4000 0xdc0c8000 0x24000 0x0 /lib/libm-2.9.so
0xdc0c8000 0xdc0c9000 0x1000 0x23000 /lib/libm-2.9.so
0xdc0c9000 0xdc0ca000 0x1000 0x24000 /lib/libm-2.9.so
0xdc0ca000 0xdc0d3000 0x9000 0x0 /lib/libudev.so.0.5.0
0xdc0d3000 0xdc0d4000 0x1000 0x8000 /lib/libudev.so.0.5.0
0xdcfeb000 0xdd000000 0x15000 0xdcfeb000 [stack]
0xffffe000 0xfffff000 0x1000 0x0 [vdso]
0xdc0e0000 0xdc0e1000 0x1000 0xa000 /usr/lib/libcgroup.so.1.0.34
0xdc0e1000 0xdc0e2000 0x1000 0xb000 /usr/lib/libcgroup.so.1.0.34
0xdc0e2000 0xdc6dc000 0x5fa000 0xdc0e2000
0xdc6dc000 0xdc6e3000 0x7000 0x0 /lib/librt-2.9.so
0xdc6e3000 0xdc6e4000 0x1000 0x6000 /lib/librt-2.9.so
0xdc6e4000 0xdc6e5000 0x1000 0x7000 /lib/librt-2.9.so
0xdc6e5000 0xdc6e7000 0x2000 0x0 /lib/libdl-2.9.so
0xdc6e7000 0xdc6e8000 0x1000 0x1000 /lib/libdl-2.9.so
0xdc6e8000 0xdc6e9000 0x1000 0x2000 /lib/libdl-2.9.so
0xdc6e9000 0xdc6fd000 0x14000 0x0 /lib/libpthread-2.9.so
0xdc6fd000 0xdc6fe000 0x1000 0x13000 /lib/libpthread-2.9.so
0xdc6fe000 0xdc6ff000 0x1000 0x14000 /lib/libpthread-2.9.so
0xdc6ff000 0xdc701000 0x2000 0xdc6ff000
0xdc701000 0xdc71c000 0x1b000 0x0 /usr/lib/libexpat.so.1.6.0
0xdc71c000 0xdc71e000 0x2000 0x1a000 /usr/lib/libexpat.so.1.6.0
0xdc71e000 0xdc71f000 0x1000 0x1c000 /usr/lib/libexpat.so.1.6.0
0xdc71f000 0xdc7cd000 0xae000 0x0 /lib/libstdc++.so.6.0.10
0xdc7cd000 0xdc7d1000 0x4000 0xad000 /lib/libstdc++.so.6.0.10
0xdc7d1000 0xdc7d2000 0x1000 0xb1000 /lib/libstdc++.so.6.0.10
0xdc7d2000 0xdc7d8000 0x6000 0xdc7d2000
0xdc7d8000 0xdc7dd000 0x5000 0x0 /usr/lib/libnuma.so.1
0xdc7dd000 0xdc7de000 0x1000 0x4000 /usr/lib/libnuma.so.1
0xdc7de000 0xdc7df000 0x1000 0x5000 /usr/lib/libnuma.so.1
0xdc7df000 0xdc7e0000 0x1000 0xdc7df000
0xdc7e1000 0xdc7e2000 0x1000 0xdc7e1000
0xdc7e2000 0xdc7fe000 0x1c000 0x0 /lib/ld-2.9.so
0xdc7fe000 0xdc7ff000 0x1000 0x1b000 /lib/ld-2.9.so
0xdc7ff000 0xdc800000 0x1000 0x1c000 /lib/ld-2.9.so
0xdcfeb000 0xdd000000 0x15000 0xdcfeb000 [stack]
0xffffe000 0xfffff000 0x1000 0x0 [vdso]