Friday, August 14, 2009

Kismet-Newcore OpenWRT Cross-Compile

So, after much headbanging, I believe I have been able to cross-compile Kismet-newcore (just Kismet now) for the WRT54GL on OpenWRT Kamikaze trunk.

This guide will hopefully help people build Kismet for use on OpenWRT flashed devices. I can't say that it is 100% perfect, or complete, but I can say that with some tweaking, Kismet will build and will at least install on a WRT54GL. Since the Broadcom drives do not allow monitor mode, there is limited use for Kismet, but hopefully this will work on other devices. I just tried this and it seems to work in monitor mode (WooHoo!). I'd love to try it out, but I only own the WRT54GL, so that is all I can comment on. If anyone can try it out on other devices, please let me know how/if it works. Also, if there are any errors in the guide, please feel free to point them out and I will correct as necessary.

(Thx DJ Flux for the make/Makefile-fu)

#Download OpenWRT SVN trunk
svn checkout svn://svn.openwrt.org/openwrt/trunk/ ~/trunk/

#Download Kismet SVN trunk
svn co https://www.kismetwireless.net/code/svn/trunk ~/kismet-devel

#Change to trunk directory
cd ~/trunk/

#Update packages
./scripts/feeds update

#Install necessary packages for Kismet
./scripts/feeds install -d m uclibcxx
./scripts/feeds install -d m libpcre


-You should see output similar to this:
mike@openwrt:~/openwrt/trunk$ ./scripts/feeds install -d m uclibcxx
++ mkdir -p /home/mike/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1
++ cd /home/mike/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1
++ mkdir -p stamp lib usr/include usr/lib
Installing package 'uclibc++'

mike@openwrt:~/openwrt/trunk$ ./scripts/feeds install -d m libpcre
++ mkdir -p /home/mike/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1
++ cd /home/mike/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-3.4.6_uClibc-0.9.30.1
++ mkdir -p stamp lib usr/include usr/lib
Installing package 'pcre'


#Create Kismet package directory

cd package
mkdir kismet-newcore
mkdir kismet-newcore/files
mkdir kismet-newcore/patches


#Create kismet-devel tarball

cd ~/
tar czvf kismet-devel.tar.gz kismet-devel/


#Now copy or move the kismet-devel.tar.gz to a webserver
-I ended up creating a code directory in /var/www/ (/var/www/code) and placed the file there

#Create or copy Kismet package Makefile
kismet-newcore files
***UPDATE(The included Makefile points to 127.0.0.1/code)***

#Copy kismet_drone.conf to kismet-newcore/files directory
**This file is included in the above tarball**
-This is just the default file with gps server turned off (I don't have GPS available)

#Configure the image environment
make menuconfig

#Choose your Target System/Subtarget/Target Profile and select packages/features
-There are two ways to add the extra items:
-Add as a built-in package (creates larger images, but less hassle with installing packages)
-Only use if you have enough RAM for the larger images
-Add as a package (smaller images, but requires package be copied to device and installed manually)

-select libraries-> libncurses, libnl, libpcre, libpcap

#Build images
make world
-This step can be done before or after kismet is selected. If it's done before, you won't get the errors, and it will at least build clean the first time through. After kismet is added to the packages and selected, there will be errors that need to be resolved before the make will finish.
-This could take some time, so be patient. Also, note any errors.

-Example output:

mike@openwrt:~/openwrt/trunk$ make world
make[1] world
make[2] tools/install
make[3] -C tools/m4 compile
make[3] -C tools/m4 install
make[3] -C tools/autoconf compile
make[3] -C tools/autoconf install
make[3] -C tools/automake compile
make[3] -C tools/automake install
make[3] -C tools/bison compile
make[3] -C tools/bison install
make[3] -C tools/sed compile
make[3] -C tools/sed install
make[3] -C tools/pkg-config compile
make[3] -C tools/pkg-config install
make[3] -C tools/mklibs compile
make[3] -C tools/mklibs install
make[3] -C tools/sstrip compile
make[3] -C tools/sstrip install
make[3] -C tools/ipkg-utils compile
make[3] -C tools/ipkg-utils install
make[3] -C tools/genext2fs compile
make[3] -C tools/genext2fs install
make[3] -C tools/lzma-old compile
make[3] -C tools/lzma-old install
make[3] -C tools/squashfs compile
make[3] -C tools/squashfs install
make[3] -C tools/lzma compile
make[3] -C tools/lzma install
make[3] -C tools/squashfs4 compile
make[3] -C tools/squashfs4 install
make[3] -C tools/mtd-utils compile
make[3] -C tools/mtd-utils install
make[3] -C tools/mkimage compile
make[3] -C tools/mkimage install
make[3] -C tools/firmware-utils compile
make[3] -C tools/firmware-utils install
make[3] -C tools/patch-cmdline compile
make[3] -C tools/patch-cmdline install
make[3] -C tools/quilt compile
make[3] -C tools/quilt install
make[3] -C tools/yaffs2 compile
make[3] -C tools/yaffs2 install
make[2] toolchain/install
make[3] -C toolchain/binutils prepare
make[3] -C toolchain/binutils compile
make[3] -C toolchain/binutils install
make[3] -C toolchain/gcc prepare
make[3] -C toolchain/kernel-headers prepare
make[3] -C toolchain/kernel-headers compile
make[3] -C toolchain/kernel-headers install
make[3] -C toolchain/uClibc prepare
make[3] -C toolchain/gcc compile
make[3] -C toolchain/uClibc compile
make[3] -C toolchain/gcc install
make[3] -C toolchain/uClibc install
make[2] target/compile
make[3] -C target/linux compile
make[2] package/cleanup
make[2] package/compile
make[3] -C package/base-files compile
make[3] -C package/broadcom-diag compile
make[3] -C package/wireless-tools compile
make[3] -C package/broadcom-wl compile
make[3] -C package/busybox compile
make[3] -C package/dnsmasq compile
make[3] -C package/dropbear compile
make[3] -C feeds/packages/libs/pcre compile
make[3] -C feeds/packages/libs/uclibc++ compile
make[3] -C package/libtool host-compile
make[3] -C package/libtool compile
make[3] -C package/iptables compile
make[3] -C package/firewall compile
make[3] -C package/kernel compile
make[3] -C package/libnl compile
make[3] -C package/libpcap compile
make[3] -C package/lua compile
make[3] -C package/mtd compile
make[3] -C package/ncurses compile
make[3] -C package/nvram compile
make[3] -C package/opkg compile
make[3] -C package/linux-atm compile
make[3] -C package/ppp compile
make[3] -C package/switch compile
make[3] -C package/uci compile
make[2] package/install
make[3] -C package/base-files install
make[3] -C package/broadcom-diag install
make[3] -C package/broadcom-wl install
make[3] -C package/busybox install
make[3] -C package/dnsmasq install
make[3] -C package/dropbear install
make[3] -C package/firewall install
make[3] -C package/iptables install
make[3] -C package/kernel install
make[3] -C package/libnl install
make[3] -C package/lua install
make[3] -C package/mtd install
make[3] -C package/ncurses install
make[3] -C package/nvram install
make[3] -C package/opkg install
make[3] -C package/ppp install
make[3] -C package/switch install
make[3] -C package/uci install
make[3] -C package/wireless-tools install
make[2] package/rootfs-prepare
make[3] package/preconfig
make[2] target/install
make[3] -C target/linux install
make[6] -C target/linux/brcm-2.4/image/lzma-loader clean install
make[2] package/index


#After initial build
make menuconfig

#Select Network->Wireless->kismet-drone

#Build image again
make
-This will error out because the Kismet Makefile needs to be tweaked
Kismet Makefile Example

**See updated post**
#Edit Kismet Makefile

cd ~/trunk/build_dir/target-mipsel_uClibc-0.9.30.1/kismet-2009-06-R1
vi Makefile



-Change the following flags:

CFLAGS = -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/usr/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include/uClibc++ -I/include -I/usr/include/ncurses

CXXFLAGS = -Wall -Os -pipe -mips32 -mtune=mips32 -funit-at-a-time -fhonour-copts -msoft-float -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include/uClibc++ -fno-builtin -fno-rtti -nostdinc++

CPPFLAGS = -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/usr/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include/uClibc++ -I/include -I/usr/include/ncurses



-To: (You are adding the "+" before the "=")

CFLAGS += -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/usr/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include/uClibc++ -I/include -I/usr/include/ncurses

CXXFLAGS += -Wall -Os -pipe -mips32 -mtune=mips32 -funit-at-a-time -fhonour-copts -msoft-float -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include/uClibc++ -fno-builtin -fno-rtti -nostdinc++

CPPFLAGS += -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/usr/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/target-mipsel_uClibc-0.9.30.1/usr/include/uClibc++ -I/include -I/usr/include/ncurses



-Change the following line:
all: Makefile $(DEPEND) $(PS) $(CS) $(DRONE) $(NC)

-To:
all: Makefile $(DEPEND) $(PS) $(CS) $(DRONE)


#New make command line:
-This is all one line, remove the "\"

CCFLAGS="$CCFLAGS -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/usr/include/uClibc++" \ CXXFLAGS="$CXXFLAGS -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/usr/include/uClibc++" \ CPPFLAGS="$CPPFLAGS -I/home/mike/openwrt/trunk/staging_dir/target-mipsel_uClibc-0.9.30.1/usr/include/uClibc++" make V=99


-There may be some errors at this point, or at least warnings.

#Once the make completes successfully, you can flash your router with whatever method you choose.
#I won't go into the flashing details in this tutorial.

#Once the router is flashed, you will need to copy over packages if you created them as modules, and not built-in

-Packages to copy to wrt54gl:
kismet-drone_2009-06-R1-1_mipsel.ipk
libpcap_1.0.0-1_mipsel.ipk
libpcre_7.9-1_mipsel.ipk
uclibcxx_0.2.2-2_mipsel.ipk

-The easiest way is to SCP them over to the /tmp directory on the router.

#SSH into router and install the packages

ssh 192.168.1.1
cd /tmp
opkg install uclibcxx_0.2.2-2_mipsel.ipk
opkg install libpcre_7.9-1_mipsel.ipk
opkg install libpcap_1.0.0-1_mipsel.ipk
opkg install kismet-drone_2009-06-R1-1_mipsel.ipk