
Sammlung von Skripten für die Arbeit mit Cisco-ASA-Firmware [Packen/Entpacken usw.]
Vorbemerkung: wir empfehlen, dies als Teil von asatools zu verwenden, aber es kann auch eigenständig verwendet werden.
asafw ist eine Sammlung von Skripten zur Arbeit mit Cisco-ASA-Firmware. Sie ermöglicht das Entpacken von Firmware, die beim Debuggen mit gdb benötigt wird, sowie das Entpacken/Neuverpacken, um bestimmte Funktionen zu aktivieren, wie zum Beispiel:
Die nützlichsten Werkzeuge sind unpack_repack_bin.sh und unpack_repack_qcow2.sh.
Sie ermöglichen es, die Image-Formate asa*.bin bzw. asav*.qcow2 zu
manipulieren. Beide müssen als root ausgeführt werden, wenn das Rootfs tatsächlich neu verpackt wird, um
die richtigen Berechtigungen beizubehalten.
Sie müssen zunächst asafw/env.sh an Ihre Umgebung anpassen. Es
ermöglicht Ihnen, Pfade zu den von allen Skripten verwendeten Werkzeugen sowie einige
Variablen zu definieren, die Ihrer ASA-Umgebung entsprechen. Beachten Sie, dass es ein ähnliches
asadbg/env.sh gibt, aber nur eines für beide Projekte verwendet werden muss. Wir
empfehlen, es zu Ihrer ~/.bashrc hinzuzufügen:```
source /path/to/asafw/env.sh
# unpack_repack_bin.sh
`unpack_repack_bin.sh` wird verwendet, um `asa*.bin`-Images zu entpacken/neu zu packen, die für
echte Cisco-ASA-Hardware (wie die Serien ASA 5500 und 5500-X) verwendet werden. Die vollständige
Verwendung ist:```
$ 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
Nehmen wir an, wir haben diese beiden Firmware:``` ~/fw$ ls asa924-k8.bin asa981-smp-k8.bin
Wenn du nur Firmware extrahieren möchtest, z. B. um sie mit
[asadbg](https://github.com/nccgroup/asadbg) zu debuggen, kannst du `-u` verwenden, um nur zu entpacken,
und `-k`, um nur das Rootfs zu behalten und andere von binwalk extrahierte Dateien zu löschen,
die du nicht benötigst. Beachte, dass der Ausgabeordner derselbe wie der Eingabeordner ist,
da wir uns dabei auf binwalk verlassen:```
~/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"
Beachten Sie, dass Fehler wie die untenstehenden, die Sie möglicherweise erhalten, in diesem Fall keine Rolle spielen, da Sie die Firmware nicht neu verpacken werden:``` 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 beim Booten aktivieren / Debug-Shell