
asadbg는 Cisco ASA 장치의 실시간 디버깅 자동화를 지원하는 도구 프레임워크입니다.
예비 참고: 이 도구는 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: libdlmalloc,
libptmalloc 및
libmempool을 사용하는 gdb Python 스크립트.asa_sync.py: ret-sync을 사용하는 gdb Python 스크립트comm.py: 시리얼, SSH, 텔넷을 통해 통신하는 함수 집합.find_lina_pid.py: SSH 명령을 사용하여 lina PID를 찾는 스크립트template_gdbinit: 디버깅하는 모든 대상에 대해 asadbg.py가 패치하는 gdbinit 템플릿처음에는 환경에 맞게 asadbg/env.sh를 수정해야 합니다. 이 파일을 통해 모든 스크립트에서 사용하는 도구의 경로와 ASA 환경에 맞는 일부 변수를 정의할 수 있습니다. 유사한 asafw/env.sh도 있지만 두 프로젝트 모두에서 하나만 사용하면 됩니다. ~/.bashrc에 추가하는 것을 권장합니다:```
source /path/to/asadbg/env.sh
# 자동 디버깅
asadbg를 사용하는 주요 이점 중 하나는 에뮬레이션된(GNS3) 및 실제 Cisco ASA
장치 모두에서의 사용을 자동화할 수 있다는 것입니다. 여기에는 일반적으로 다양한
펌웨어와 구성을 부팅하고 실행하는 자동화나, gdb를 사용하여 `lina`의
디버깅 프로세스를 자동화하는 것도 포함될 수 있습니다. 이는 대부분 `asadbg.py`
스크립트를 통해 수행됩니다. 기본 개념은 장치에서 사용하려는 펌웨어와 구성 파일을
ASA 장치의 플래시에 미리 로드하는 것입니다. 디버깅하려는 각 펌웨어에 대해
`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
It also points to the ASA database `asadb.json` file containing the addresses required. What
is important here is that the `version=941200` and `arch=gns3` specified in
`asadbg.cfg` allow to match the firmware in `asadb.json` below. Also we indicate
we want to attach 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
또한 펌웨어가 수정되지 않았는지, 루팅되었는지, 시리얼 셸이 활성화되었는지, 부팅 시 gdb가 활성화되었는지를 나타내는 firmware_type을 지정해야 한다는 점에 유의하십시오. 이는
부팅 시 형식에 따라 서로 다른 작업을 수행하기 때문입니다. 여기서
우리는 부팅 시 gdbserver가 활성화되고 디버그 셸이 포함된 수정된 펌웨어 asa924-k8-debugshell-gdbserver.bin을 사용하는 것을 볼 수 있습니다.
아래에서 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`를 임의의 명령과 함께 사용하면 해당 명령의 결과가 무엇인지 확인할 수 있습니다.