-
-
Notifications
You must be signed in to change notification settings - Fork 239
Toolchain identification
This page contains the documentation of how we succeeded building certain buildchains. Over time, new ones will be added. If you made one yourself. Please let us know with opening an issue, so we can add it here!
With the module F02 EMBA gives the tester further details on a possible toolchain. This includes the used kernel, version, release date and the same kind of information for an identified GCC:
These details give the tester a good overview which components (with versions) are relevant and how old the original build chain probably is. The next step could be to check a Linux distribution of choice of this age and start compiling.
The following scripts give some impression of how such a build script could look like. A big shoutout to Tom and his great work which is the base for the F02 EMBA module and the following documentation.
#Tested on Ubuntu 8.04 installed in a VM from install DVD
#export WHEREVER=/home/csa/Desktop/dlback <- Put source packages here
#Creating directory structure
cd /home/csa/Desktop/
mkdir myself
cd myself
mkdir -p deviceroot/lib
mkdir -p deviceroot/usr/include
mkdir -p deviceroot/usr/lib
mkdir buildroot
# Copying sources
cp $WHEREVER/gmp-4.2.4.tar.bz2 .
cp $WHEREVER/mpfr-2.4.1.tar.bz2 .
cp $WHEREVER/gcc-3.4.3.tar.gz .
cp $WHEREVER/binutils-2.19.tar.bz2 .
cp $WHEREVER/uClibc-0.9.28.tar.bz2 .
cp $WHEREVER/Linux_Kernel_3.4.84.tar.bz2 .
# Building gmp (gcc dependency)
tar -xjf gmp-4.2.4.tar.bz2
cd gmp-4.2.4
./configure --prefix=/home/csa/Desktop/myself/buildroot
make
make install
cd ..
#Build mpfr (gcc dependency)
tar -xjf mpfr-2.4.1.tar.bz2
cd mpfr-2.4.1
./configure --prefix=/home/csa/Desktop/myself/buildroot --with-gmp=/home/csa/Desktop/myself/buildroot
make
make install
cd ..
#Build binutils
tar -xjf binutils-2.19.tar.bz2
cd binutils-2.19
./configure --prefix=/home/csa/Desktop/myself/buildroot --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=mipsisa32r2-linux-uclibc --with-gmp=/home/csa/Desktop/myself/buildroot --with-mpfr=/home/csa/Desktop/myself/buildroot --with-sysroot=/home/csa/Desktop/myself/deviceroot
make
make install
cd ..
#Update environment variables
export LD_LIBRARY_PATH=/home/csa/Desktop/myself/buildroot/lib:$LD_LIBRARY_PATH
export PATH=/home/csa/Desktop/myself/buildroot/bin:$PATH
#Unpack linux sources
mkdir Linux_Kernel_3.4.84
tar -xjf Linux_Kernel_3.4.84.tar.bz2 -C Linux_Kernel_3.4.84
#Build uClibc header files
tar -xjf uClibc-0.9.28.tar.bz2
cd uClibc-0.9.28
############################# ! INTERACTIVE ! ######################################################
#configure
# Target Architecture (mips)
# Target Processor Architecture (MIPS32)
# Target Processor Endianness (Big Endian)
# Linux kernel header location -> /home/csa/Desktop/myself/Linux_Kernel_3.4.84
# Large File Support -> no
# Wide Character Support -> yes
# uClibc runtime library directory -> /home/csa/Desktop/myself/deviceroot/
# uClibc development environment directory -> /home/csa/Desktop/myself/deviceroot/usr/
make menuconfig
############################# ! INTERACTIVE END ! ######################################################
make headers
cp -rL include/ /home/csa/Desktop/myself/deviceroot/usr
cd ..
#Build gcc (host part and crti.o)
tar -xzf gcc-3.4.3.tar.gz
cd gcc-3.4.3
mkdir build
cd build
../configure --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=mipsisa32r2-linux-uclibc --enable-languages=c,c++ --with-sysroot=/home/csa/Desktop/myself/deviceroot --with-gmp=/home/csa/Desktop/myself/buildroot --with-mpfr=/home/csa/Desktop/myself/buildroot --prefix=/home/csa/Desktop/myself/buildroot --disable-multilib --with-tune=mips32r2
make all-gcc # Will fail when it cannot find crti.o, but it has created libgcc.a on the way
make install-gcc
cp ./gcc/xgcc /home/csa/Desktop/myself/buildroot/bin/mipsisa32r2-linux-uclibc-gcc
cp ./gcc/libgcc.a /home/csa/Desktop/myself/deviceroot/lib/
cd ../../
#Build crti.o
cd uClibc-0.9.28
make CROSS="mipsisa32r2-linux-uclibc-" #Will fail when it cannot find crtbeginS.o, but it has created crti.o on the way
cp ./lib/* ../deviceroot/lib
cd ..
#Finish gcc host part
cd gcc-3.4.3/build
make all-gcc
make install-gcc
cd ../../
#Finish uClibc
cd uClibc-0.9.28
make CROSS="mipsisa32r2-linux-uclibc-"
make install
cd ..
#Build gcc target part
cd gcc-3.4.3/build
make all-target
sed -i 's/r = __ctype/r = (const int*)__ctype/g' ./mipsisa32r2-linux-uclibc/libstdc++-v3/include/mipsisa32r2-linux-uclibc/bits/ctype_noninline.h
sed -i 's@#define _GLIBCXX_USE_LFS 1@//#define _GLIBCXX_USE_LFS 1@g' ./mipsisa32r2-linux-uclibc/libstdc++-v3/include/mipsisa32r2-linux-uclibc/bits/c++config.h
make all-target
make install-target
cp ../../buildroot/mipsisa32r2-linux-uclibc/lib/* ../../deviceroot/lib/
rm ../../buildroot/mipsisa32r2-linux-uclibc/lib/libgcc_s.so*
cd ../../
# Copy original files from device
cp -r $WHEREVER/deviceroot .
#rm ./deviceroot/lib/libgcc.a
#cp ./deviceroot/lib/libgcc_s.so ./deviceroot/lib/libgcc.so
#---------------------- DONE BUILD ENVIRONMENT ---------------------------------------------
#Build netcat
cp $WHEREVER/netcat-0.7.1.tar.gz .
tar -xzf netcat-0.7.1.tar.gz
cd netcat-0.7.1
./configure CC="mipsisa32r2-linux-uclibc-gcc" LDFLAGS="-Wl,--dynamic-linker -Wl,/lib/ld-uClibc.so.0" --host=x86_64-pc-linux-gnu
make
readelf -l src/netcat
readelf -d src/netcat
readelf -h src/netcat
cd ..
#Building nmap
cp $WHEREVER/nmap-6.00.tgz .
tar -xzf nmap-6.00.tgz
cd nmap-6.00
./configure CC="mipsisa32r2-linux-uclibc-gcc" CXX="mipsisa32r2-linux-uclibc-c++" LDFLAGS="-Wl,--dynamic-linker -Wl,/lib/ld-uClibc.so.0" --host=x86_64-pc-linux-gnu --with-pcap=linux --with-liblua=included --with-libpcap=included --prefix=/home/csa/Desktop/myself/deviceroot/usr
make lua_build
make liblinear_build
make pcre_build
make dnet_build
make nbase_build
make nsock_build
make pcap_build
make ncat_build
readelf -l ncat/ncat
readelf -d ncat/ncat
readelf -h ncat/ncat
make netutil_build
make build-nping
readelf -l nping/nping
readelf -d nping/nping
readelf -h nping/nping
make nmap
readelf -l nmap
readelf -d nmap
readelf -h nmap
cd ..
#Build helloworld
mkdir test
vim hello.c
mipsisa32r2-linux-uclibc-gcc -Wl,--dynamic-linker -Wl,/lib/ld-uClibc.so.0 -o hello hello.c
readelf -l hello
readelf -h hello
readelf -d hello
cd ..
#Tested on Ubuntu 8.04 installed in a VM from install DVD
#export WHEREVER=/home/csa/Desktop/dlback <- Put source packages here
#Creating directory structure
cd /home/csa/Desktop/
mkdir myself
cd myself
mkdir -p deviceroot/lib
mkdir -p deviceroot/usr/include
mkdir -p deviceroot/usr/lib
mkdir buildroot
# Copying sources
cp $WHEREVER/gmp-4.2.4.tar.bz2 .
cp $WHEREVER/mpfr-2.4.1.tar.bz2 .
cp $WHEREVER/gcc-4.3.2.tar.gz .
cp $WHEREVER/binutils-2.19.tar.bz2 .
cp $WHEREVER/uClibc-0.9.28.tar.bz2 .
cp $WHEREVER/Linux_Kernel_3.4.84.tar.bz2 .
# Building gmp (gcc dependency)
tar -xjf gmp-4.2.4.tar.bz2
cd gmp-4.2.4
./configure --prefix=/home/csa/Desktop/myself/buildroot
make
make install
cd ..
#Build mpfr (gcc dependency)
tar -xjf mpfr-2.4.1.tar.bz2
cd mpfr-2.4.1
./configure --prefix=/home/csa/Desktop/myself/buildroot --with-gmp=/home/csa/Desktop/myself/buildroot
make
make install
cd ..
#Build binutils
tar -xjf binutils-2.19.tar.bz2
cd binutils-2.19
./configure --prefix=/home/csa/Desktop/myself/buildroot --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=mipsisa32r2-linux-uclibc --with-gmp=/home/csa/Desktop/myself/buildroot --with-mpfr=/home/csa/Desktop/myself/buildroot --with-sysroot=/home/csa/Desktop/myself/deviceroot
make
make install
cd ..
#Update environment variables
export LD_LIBRARY_PATH=/home/csa/Desktop/myself/buildroot/lib:$LD_LIBRARY_PATH
export PATH=/home/csa/Desktop/myself/buildroot/bin:$PATH
#Build gcc (host part)
tar -xzf gcc-4.3.2.tar.gz
cd gcc-4.3.2
mkdir build
cd build
../configure --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=mipsisa32r2-linux-uclibc --enable-languages=c,c++ --with-sysroot=/home/csa/Desktop/myself/deviceroot --with-gmp=/home/csa/Desktop/myself/buildroot --with-mpfr=/home/csa/Desktop/myself/buildroot --prefix=/home/csa/Desktop/myself/buildroot --disable-multilib --with-tune=mips32r2
make all-gcc
make install-gcc
cd ../../
#Unpack linux sources
mkdir Linux_Kernel_3.4.84
tar -xjf Linux_Kernel_3.4.84.tar.bz2 -C Linux_Kernel_3.4.84
#Build uClibc header files
tar -xjf uClibc-0.9.28.tar.bz2
cd uClibc-0.9.28
############################# ! INTERACTIVE ! ######################################################
#configure
# Target Architecture (mips)
# Target Processor Architecture (MIPS32)
# Target Processor Endianness (Big Endian)
# Linux kernel header location -> /home/csa/Desktop/myself/Linux_Kernel_3.4.84
# Large File Support -> no
# Wide Character Support -> yes
# uClibc runtime library directory -> /home/csa/Desktop/myself/deviceroot/
# uClibc development environment directory -> /home/csa/Desktop/myself/deviceroot/usr/
make menuconfig
############################# ! INTERACTIVE END ! ######################################################
make CROSS="mipsisa32r2-linux-uclibc-" #Will fail when it cannot find libgcc.a
cp -rL include/ /home/csa/Desktop/myself/deviceroot/usr
cd ..
#Build libgcc.a
cd gcc-4.3.2/build
make all-target-libgcc # Will fail when it cannot find crti.o, but it has created libgcc.a on the way
cp ./mipsisa32r2-linux-uclibc/libgcc/libgcc.a /home/csa/Desktop/myself/deviceroot/lib/
cd ../../
#Build crti.o
cp ./buildroot/lib/gcc/mipsisa32r2-linux-uclibc/4.3.2/install-tools/include/limits.h ./buildroot/lib/gcc/mipsisa32r2-linux-uclibc/4.3.2/include
cd uClibc-0.9.28
make CROSS="mipsisa32r2-linux-uclibc-" #Will fail when it cannot find crtbeginS.o, but it has created crti.o on the way
cp ./lib/* ../deviceroot/lib
cd ..
#Finish libgcc
cd gcc-4.3.2/build
make all-target-libgcc
make install-target-libgcc
rm ../../buildroot/mipsisa32r2-linux-uclibc/lib/libgcc_s*.so #This is a bug! This should not be necessary! The files are in the wrong position and malfunctioning
cd ../../
#Finish uClibc
cd uClibc-0.9.28
make CROSS="mipsisa32r2-linux-uclibc-"
make install
cd ..
# Copy original files from device
cp -r $WHEREVER/deviceroot .
#rm ./deviceroot/lib/libgcc.a
#cp ./deviceroot/lib/libgcc_s.so ./deviceroot/lib/libgcc.so
#---------------------- DONE BUILD ENVIRONMENT ---------------------------------------------
#Build netcat
cp $WHEREVER/netcat-0.7.1.tar.gz .
tar -xzf netcat-0.7.1.tar.gz
cd netcat-0.7.1
./configure CC="mipsisa32r2-linux-uclibc-gcc" --host=x86_64-pc-linux-gnu
make
readelf -d src/netcat
readelf -h src/netcat
cd ..
#Build libpcap
cp $WHEREVER/libpcap-1.3.0.tar.gz .
tar -xzf libpcap-1.3.0.tar.gz
cd libpcap-1.3.0
./configure CC="mipsisa32r2-linux-uclibc-gcc" --host=x86_64-pc-linux-gnu --with-pcap=linux --prefix=/home/csa/Desktop/myself/deviceroot/usr
make
make install
readelf -d libpcap.so.1.3.0
readelf -h libpcap.so.1.3.0
cd ..
#Build readline
cp $WHEREVER/readline-6.0.tar.gz .
tar -xzf readline-6.0.tar.gz
cd readline-6.0
./configure CC="mipsisa32r2-linux-uclibc-gcc" --host=x86_64-pc-linux-gnu --prefix=/home/csa/Desktop/myself/deviceroot/usr
make
make install
readelf -d shlib/libreadline.so.6.0
readelf -h shlib/libreadline.so.6.0
cd ..
#Build ncurses
cp $WHEREVER/ncurses-5.9.tar.gz .
tar -xzf ncurses-5.9.tar.gz
cd ncurses-5.9
./configure CC="mipsisa32r2-linux-uclibc-gcc" --host=x86_64-pc-linux-gnu --prefix=/home/csa/Desktop/myself/deviceroot/usr --without-cxx --without-cxx-bindin --without-ada --without-manpages --without-progs --without-tests --without-curses-h --disable-largefile
make
############################# ! INTERACTIVE ! ######################################################
make install #Ctrl+C Required as tic -x will hang
############################# ! INTERACTIVE END ! ######################################################
cd ..
#Build lua
cp $WHEREVER/lua-5.2.0.tar.gz .
tar -xzf lua-5.2.0.tar.gz
cd lua-5.2.0
sed -i 's@/usr/local@/home/csa/Desktop/myself/deviceroot/usr@g' Makefile
make CC="mipsisa32r2-linux-uclibc-gcc" CFLAGS=" -D_FILE_OFFSET_BITS=32" linux
make install
cd ..
#Building nmap
cp $WHEREVER/nmap-6.00.tgz .
tar -xzf nmap-6.00.tgz
cd nmap-6.00
./configure CC="mipsisa32r2-linux-uclibc-gcc" --host=x86_64-pc-linux-gnu --with-pcap=linux
make
cd ..
EMBA - firmware security scanning at its best
Sponsor EMBA and EMBArk:
The EMBA environment is free and open source!
We put a lot of time and energy into these tools and related research to make this happen. It's now possible for you to contribute as a sponsor!
If you like EMBA you have the chance to support future development by becoming a Sponsor
Thank You ❤️ Get a Sponsor
You can also buy us some beer here ❤️ Buy me a coffee
To show your love for EMBA with nice shirts or other merch you can check our Spreadshop
EMBA - firmware security scanning at its best