初步说明:我们建议你将其作为 asatools 的一部分使用,但也可以单独使用。
asafw 是一组用于处理 Cisco ASA 固件的脚本。它可以让你解包使用 gdb 调试时所需的固件,也可以解包/重新打包固件以启用某些功能,例如:
更有用的工具是 unpack_repack_bin.sh 和 unpack_repack_qcow2.sh。它们分别用于操作 asa*.bin 和 asav*.qcow2 镜像格式。在实际重新打包 rootfs 时,两者都需要以 root 身份执行,以保留正确的权限。
你首先需要修改 asafw/env.sh 以匹配你的环境。它可以让你定义所有脚本使用的工具路径,以及一些与你的 ASA 环境匹配的变量。请注意,还有一个类似的 asadbg/env.sh,但两个项目只需使用其中一个即可。我们建议你将其添加到你的 ~/.bashrc 中:```
source /path/to/asafw/env.sh
# unpack_repack_bin.sh
`unpack_repack_bin.sh` 用于解包/重新打包 `asa*.bin` 镜像,这些镜像用于真实 Cisco ASA 硬件(如 ASA 5500 和 5500-X 系列)。完整用法如下:```
$ unpack_repack_bin.sh -h
Usage:
./unpack_repack_bin.sh -i <firmware_file> -o <out_dir> [-f -g -G -a -A -m -b -r -u -l <linabin_dir> -d -e -k]
-h, --help This help menu
-i, --input <firmware_file> What firmware bin to operate on
-o, --output <out_dir> Where to write new firmware
-f, --free-space Remove space from .bin to ensure injections fit
-g, --enable-gdb Set gdb to start on boot
-G, --disable-gdb Stop gdb from starting on boot
-a, --enable-aslr Turn on ASLR
-A, --disable-aslr Turn off ASLR
-m, --inject-gdb Inject gdbserver to run
-b, --debug-shell Inject ssh-triggered debug shell
-H, --lina-hook Inject hooks for monitor lina heap (requires -b)
-r, --root root the bin to get a rootshell on boot
-c, --custom custom?
-n, --n-custom custom?
-q, --gns3-fixup gns?
-u, --unpack-only unpack the firmware and nothing else
-l, --linabins <linabin_dir> destination folder to save lina binaries
-d, --delete-extracted delete files extracted during modification
-e, --delete-original-bin delete the original firmware being modified
-k, --keep-rootfs keep the extracted rootfs on disk
-s, --simple-name use a simple name for the output .bin with just appended '-repacked'
Examples:
./unpack_repack_bin.sh -i /home/user/firmware -o /home/user/firmware_repacked --free-space --enable-gdb --inject-gdb
./unpack_repack_bin.sh -i /home/user/firmware/asa961-smp-k8.bin -f -g -m
./unpack_repack_bin.sh -u -i /home/user/firmware -l /home/user/linabins
./unpack_repack_bin.sh -u -i /home/user/firmware/asa924-k8.bin -k
假设我们有以下两个固件:``` ~/fw$ ls asa924-k8.bin asa981-smp-k8.bin
如果你只想提取固件,例如用 [asadbg](https://github.com/nccgroup/asadbg) 调试它们,你可以使用 `-u` 仅解包,使用 `-k` 仅保留 rootfs 并删除 binwalk 提取的其他不需要的文件。注意,输出文件夹与输入文件夹相同,因为我们在这方面依赖 binwalk:```
~/fw$ unpack_repack_bin.sh -i . -k -u
[unpack_repack_bin] Directory of firmware detected: .
[unpack_repack_bin] extract_one: asa924-k8.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
75000 0x124F8 SHA256 hash constants, little endian
144510 0x2347E gzip compressed data, maximum compression, from Unix, last modified: 2015-07-15 04:53:23
1501296 0x16E870 gzip compressed data, has original file name: "rootfs.img", from Unix, last modified: 2015-07-15 05:19:52
27168620 0x19E8F6C MySQL ISAM index file Version 4
28192154 0x1AE2D9A Zip archive data, at least v2.0 to extract, name: com/cisco/webvpn/csvrjavaloader64.dll
28773362 0x1B70BF2 Zip archive data, at least v2.0 to extract, name: AliasHandlerWrapper-win64.dll
[unpack_repack_bin] Extracted firmware to /home/user/fw/_asa924-k8.bin.extracted
[unpack_repack_bin] Firmware uses regular rootfs/ dir
[unpack_repack_bin] Extracting /home/user/fw/_asa924-k8.bin.extracted/rootfs/rootfs.img into /home/user/fw/_asa924-k8.bin.extracted/rootfs
[unpack_repack_bin] Keeping rootfs
[unpack_repack_bin] Deleting "/home/user/fw/_asa924-k8.bin.extracted/rootfs.img"
[unpack_repack_bin] Deleting "/home/user/fw/_asa924-k8.bin.extracted/2347E"
[unpack_repack_bin] Deleting "/home/user/fw/_asa924-k8.bin.extracted/1AE2D9A.zip"
[unpack_repack_bin] extract_one: asa981-smp-k8.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
75264 0x12600 SHA256 hash constants, little endian
133120 0x20800 Microsoft executable, portable (PE)
149183 0x246BF gzip compressed data, maximum compression, from Unix, last modified: 2017-01-30 19:33:09
3678112 0x381FA0 gzip compressed data, has original file name: "rootfs.img", from Unix, last modified: 2017-05-10 22:42:05
14838307 0xE26A23 MySQL MISAM compressed data file Version 4
87985870 0x53E8ECE MySQL MISAM compressed data file Version 7
96261881 0x5BCD6F9 Zip archive data, at least v2.0 to extract, name: com/cisco/webvpn/csvrjavaloader64.dll
96890193 0x5C66D51 MySQL ISAM compressed data file Version 5
[unpack_repack_bin] Extracted firmware to /home/user/fw/_asa981-smp-k8.bin.extracted
[unpack_repack_bin] Firmware uses regular rootfs/ dir
[unpack_repack_bin] Extracting /home/user/fw/_asa981-smp-k8.bin.extracted/rootfs/rootfs.img into /home/user/fw/_asa981-smp-k8.bin.extracted/rootfs
[unpack_repack_bin] Keeping rootfs
[unpack_repack_bin] Deleting "/home/user/fw/_asa981-smp-k8.bin.extracted/rootfs.img"
[unpack_repack_bin] Deleting "/home/user/fw/_asa981-smp-k8.bin.extracted/5BCD6F9.zip"
[unpack_repack_bin] Deleting "/home/user/fw/_asa981-smp-k8.bin.extracted/246BF"
请注意,你可能会收到如下所示的错误,但在这种情况下这并不重要,因为你 不会重新打包固件:``` cpio: lib/udev/devices/kmem: Function mknod failed: Operation not permitted cpio: lib/udev/devices/net/tun: Function mknod failed: Operation not permitted cpio: lib/udev/devices/loop01: Function mknod failed: Operation not permitted cpio: lib/udev/devices/null: Function mknod failed: Operation not permitted cpio: lib/udev/devices/console: Function mknod failed: Operation not permitted cpio: lib/udev/devices/loop00: Function mknod failed: Operation not permitted 134992 blocks
## 在启动时启用 gdb / 调试 shell