MIPS32 아키텍쳐 펌웨어를 에뮬레이팅할 예정
아래 url을 통해 커널 이미지 다운
https://people.debian.org/~aurel32/qemu/mips/
mips와 mipsel이 있는데 빅엔디안, 리틀엔디안 차이임
» qemu-system-mips -M malta -kernel vmlinux-2.6.32-5-4kc-malta -hda debian_squeeze_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0"
또는
» qemu-system-mips -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0"
» qemu-system-mips64 -M malta -kernel vmlinux-2.6.32-5-5kc-malta -hda debian_squeeze_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0"
또는
» qemu-system-mips64 -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0"
» qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0" -netdev user,id=mynet,hostfwd=tcp::2022-:22,hostfwd=tcp::2080-:80 -device e1000,netdev=mynet
ssh root@localhost -p 2022 로 접속» binwalk -e AX1500_1.0.2.bin
WARNING: Extractor.execute failed to run external extractor 'sasquatch -p 1 -le -d 'squashfs-root-0' '%e'': [Errno 2] No such file or directory: 'sasquatch', 'sasquatch -p 1 -le -d 'squashfs-root-0' '%e'' might not be installed correctly 과 같은 오류가 발생» binwalk AX1500_1.0.2.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
10264 0x2818 LZMA compressed data, properties: 0x5D, dictionary size: 8388608 bytes, uncompressed size: 5194424 bytes
1745954 0x1AA422 Squashfs filesystem, little endian, version 4.0, compression:xz, size: 6065580 bytes, 790 inodes, blocksize: 131072 bytes, created: 2038-05-06 08:36:16
» dd if=AX1500_1.0.2.bin bs=1 skip=1745954 of=squashfs.img
if : 추출할 펌웨어
bs : block size. 한 번에 읽고 쓰는 데이터 블록의 크기
skip : 해당 주소부터 추출(10진수)
of : 추출 후 이름
추출된 img 파일을 unsquashfs 를 이용해 파일시스템 추출
» sudo unsquashfs -d squashfs-root squashfs.img
» ls
AX1500_1.0.2.bin squashfs.img squashfs-root
root@debian-mipsel:~# uname -a
Linux debian-mipsel 2.6.32-5-4kc-malta #1 Tue Sep 24 01:20:35 UTC 2013 mips GNU/Linux
root@debian-mipsel:~/squashfs-root# ls
bin dev etc home init jffs2 lib mnt proc qemu-mipsel-static root sys tmp usr var web
root@debian-mipsel:~/squashfs-root# chroot . busybox
BusyBox v1.24.1 (2023-09-26 16:15:21 KST) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.
Usage: busybox [function [arguments]...]
or: busybox --list
or: function [arguments]...
BusyBox is a multi-call binary that combines many common Unix
utilities into a single executable. Most people will create a
link to busybox for each function they wish to use and BusyBox
will act like whatever it was invoked as.
Currently defined functions:
ash, awk, bunzip2, bzcat, cat, chmod, cp, cut, date, depmod,
dnsdomainname, echo, expr, false, free, grep, halt, head, hostname,
ifconfig, init, insmod, ip, kill, killall, klogd, ln, login, ls, lsmod,
lzop, lzopcat, mkdir, modprobe, mount, ping, poweroff, ps, readahead,
reboot, renice, rm, rmmod, route, sed, sh, sleep, syslogd, tail,
telnetd, tftp, tftpd, top, true, umount, unlzop, unxz, uptime, vconfig,
vi, wc, xz, xzcat
root@debian-mipsel:~/squashfs-root# chroot . ./bin/sh
# ls
bin init proc tmp
dev jffs2 qemu-mipsel-static usr
etc lib root var
home mnt sys web
» sudo mount --bind /proc ./proc
» sudo mount --bind /dev ./dev
» sudo mount --bind /sys ./sys
» sudo cp /usr/bin/qemu-mipsel-static ./
» sudo chroot . ./qemu-mipsel-static ./bin/busybox
BusyBox v1.24.1 (2023-09-26 16:15:21 KST) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.
Usage: busybox [function [arguments]...]
or: busybox --list
or: function [arguments]...
BusyBox is a multi-call binary that combines many common Unix
utilities into a single executable. Most people will create a
link to busybox for each function they wish to use and BusyBox
will act like whatever it was invoked as.
Currently defined functions:
ash, awk, bunzip2, bzcat, cat, chmod, cp, cut, date, depmod,
dnsdomainname, echo, expr, false, free, grep, halt, head, hostname,
ifconfig, init, insmod, ip, kill, killall, klogd, ln, login, ls, lsmod,
lzop, lzopcat, mkdir, modprobe, mount, ping, poweroff, ps, readahead,
reboot, renice, rm, rmmod, route, sed, sh, sleep, syslogd, tail,
telnetd, tftp, tftpd, top, true, umount, unlzop, unxz, uptime, vconfig,
vi, wc, xz, xzcat
» sudo chroot . ./qemu-mipsel-static ./bin/sh
# ls
bin init proc tmp
dev jffs2 qemu-mipsel-static usr
etc lib root var
home mnt sys web
#
# ./bin/boa
Read hw setting header failed!
Invalid hw setting signature [sig=]!
Initialize AP MIB failed!asp_init:1008
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault (core dumped)
해당 오류를 해결하기 위해 boa 바이너리 분석

apmib_init 이라는 함수의 return 값이 1이어야 함
apmib_init 함수에 들어가면
int apmib_init(void){
return off_45A068();
}
이렇게만 나와있기 때문에 해당하는 라이브러리에서 apmib_init 내용을 찾아줘야 함
파일시스템의 lib 폴더의 라이브러리에서 apmib_init 검색
» grep -r "apmib_init" ./lib/
grep: ./lib/libapmib.so: binary file matches
apmib_init 함수 안의 apmib_hwconf 함수에서 나머지 오류 메시지 확인
int apmib_init()
{
int v0; // $v0
int v2; // $v0
int v3; // $a0
int v4; // $a1
int v5; // $v0
int v6; // $v0
apmib_sem_lock();
if ( !pMib )
{
v0 = apmib_hwconf();
if ( !v0 )
{
LABEL_3:
apmib_sem_unlock();
return 0;
}
fbss = v0;
v2 = apmib_dsconf();
if ( !v2 )
{
v3 = fbss;
v4 = 0;
LABEL_6:
apmib_shm_free(v3, v4);
goto LABEL_3;
}
pMibDef = v2;
v5 = apmib_csconf();
if ( !v5 )
{
apmib_shm_free(fbss, 0);
v4 = 1;
v3 = pMibDef;
goto LABEL_6;
}
pMib = v5;
v6 = apmib_customerHwconf();
if ( !v6 )
{
apmib_shm_free(fbss, 0);
apmib_shm_free(pMibDef, 1);
v4 = 2;
v3 = pMib;
goto LABEL_6;
}
pCustomerHwSetting = v6;
}
apmib_sem_unlock();
return 1;
}
int apmib_hwconf()
{
.
.
.
if ( read_mtdblock0((int)v20, 0x20000, 6) )
compress_hw_setting = memcmp(v20, &off_A9AC, 2) && memcmp(v20, &off_A9B0, 2) && memcmp(v20, &off_A9B4, 2);
else
puts("Read hw setting header failed!");
if ( !compress_hw_setting )
{
if ( !read_mtdblock0((int)&hsHeader, 0x20000, 6) )
return 0;
.
.
.
}