본문 바로가기

Security/Reverse Engineering

[Reversing] Cross-Compiler & Remote Debugging with gdb on Linux

Cross-Compiler & Remote Debugging with gdb on Linux

1. Installing Cross-Compiler for MIPS, ARM, PPC, etc...

1
2
3
4
5
6
7
8
9
10
sudo apt-get install -y  gcc-multilib-arm-linux-gnueabi
sudo apt-get install -y  gcc-multilib-arm-linux-gnueabihf
sudo apt-get install -y  gcc-multilib-mips-linux-gnu
sudo apt-get install -y  gcc-multilib-mips64-linux-gnuabi64
sudo apt-get install -y  gcc-multilib-mips64el-linux-gnuabi64
sudo apt-get install -y  gcc-multilib-mipsel-linux-gnu
sudo apt-get install -y  gcc-multilib-powerpc-linux-gnu
sudo apt-get install -y  gcc-multilib-powerpc64-linux-gnu
sudo apt-get install -y  gcc-multilib-s390x-linux-gnu
sudo apt-get install -y  gcc-multilib-sparc64-linux-gnu
cs

- Installing echo architectures' gcc

After installing all of them, u can compile like below.

ARM  : arm-linux-gnueabi-gcc

MIPS  : mips-linux-gnu-gcc


2. Setup remote debugging for debugging other architecture binary.

1
2
sudo apt-get install gdb-multiarch
sudo apt-get install qemu-user-static
cs

- Installing gdb for multi-arch and qemu emulator for running other arch binary



1
2
3
4
5
6
7
8
9
10
11
- Terminal 1
zero@ubuntu:~/Desktop/pwn/ARM$ qemu-arm-static -/usr/arm-linux-gnueabi -7777 ./a
 
- Terminal 2
zero@ubuntu:~/Desktop/pwn/ARM$ gdb-multiarch -q
gdb-peda$ target remote localhost:7777
Remote debugging using localhost:7777
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
Warning: not running or target is remote
0x00008054 in ?? ()
cs

MIPS is also similar. qemu-mips-static -L /usr/mips-linux-gnu -g 7777 ./a