{"id":457,"date":"2012-02-29T07:34:36","date_gmt":"2012-02-29T13:34:36","guid":{"rendered":"http:\/\/www.jedge.com\/wordpress\/?p=457"},"modified":"2012-07-05T22:31:45","modified_gmt":"2012-07-06T04:31:45","slug":"compiling-nmap-for-android","status":"publish","type":"post","link":"https:\/\/www.jedge.com\/wordpress\/2012\/02\/compiling-nmap-for-android\/","title":{"rendered":"Compiling Nmap for Android"},"content":{"rendered":"<p><strong>Compile Nmap for Android<\/strong><\/p>\n<p>This tutorial will show you how to compile the latest version of Nmap for your Android device starting with a standard Ubuntu install. I will offer instructions on how to obtain two versions of compiler that I\u2019ve had success compiling software for Android. I will show the Android NDK and the free Lite ARM compiler from Mentor (formally Code Sorcery). Hopefully you can take this instruction to try and compile other tools for Android.<\/p>\n<p>The build environment and instructions come from an auditor with strong technical skills but somebody who is not a programmer or developer so hopefully my view point can help other individuals who are also not developers. I\u2019ve built cross-compile environments for Openwrt, Nokia Maemo, Familiar Linux (iPaq) in the past but always from piecing together instructions from multiple Google queries and forum searches. I\u2019m creating this document so it will be helpful for somebody&#8217;s future Google search.<br \/>\n<!--more--><br \/>\nAfter the Ubuntu installation here are ALL the steps you can\/should take to compile Nmap for Android. I like vim as my command-line editor. You can use which ever editor you prefer.<\/p>\n<p>Here is a quick rundown of what is done. Everything (almost) is done from a terminal window.<\/p>\n<ol>\n<li>I update all Ubuntu software and install all files and tools to compile software on Ubuntu<\/li>\n<li>I download the software required to compile for Android<\/li>\n<li>Setup the environment to compile for Android<\/li>\n<li>I create a source folder in the home directory for downloading and compiling the software.<\/li>\n<li>Download the software, patch, configure, and compile.<\/li>\n<li>Install Android SDK Platform Tools to copy files to your phone<\/li>\n<li>Copy files to the phone and set PATH environment variable.<\/li>\n<\/ol>\n<p><pre><code>\n$sudo -s\n#apt-get update\n#apt-get upgrade\n#apt-get install vim build-essential\n#cd \/usr\/local\n#wget https:\/\/sourcery.mentor.com\/sgpp\/lite\/arm\/portal\/package9728\/public\/arm-none-linux-gnueabi\/arm-2011.09-70-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2\n#tar jxf arm-2011.09-70-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2\n#rm arm-2011.09-70-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2\n#exit\n$\n<\/code><\/pre><\/p>\n<p>Ubuntu is now current with the tools required to compile for Android. Now to create a simple shell script to setup the environment variables for cross compiling.<br \/>\n<pre><code>\n$mkdir ~\/source\n$cd ~\/source\n$vim setenv.sh\n<\/code><\/pre><br \/>\nInclude the following information in setenv.sh. This script will set the environment to allow you to use the Android \/ ARM compiler instead of the native compiler.<br \/>\n<span style=\"font-family: courier new; font-size: x-small;\"><br \/>\n#!\/bin\/bash<br \/>\nexport ac_cv_linux_vers=2<br \/>\nexport CC=\/usr\/local\/arm-2011.09\/bin\/arm-none-linux-gnueabi-gcc<br \/>\nexport GCC=\/usr\/local\/arm-2011.09\/bin\/arm-none-linux-gnueabi-gcc<br \/>\nexport CXX=\/usr\/local\/arm-2011.09\/bin\/arm-none-linux-gnueabi-g++<br \/>\nexport CPP=\/usr\/local\/arm-2011.09\/bin\/arm-none-linux-gnueabi-cpp<br \/>\nexport LD=\/usr\/local\/arm-2011.09\/bin\/arm-none-linux-gnueabi-ld<br \/>\nexport AR=\/usr\/local\/arm-2011.09\/bin\/arm-none-linux-gnueabi-ar<br \/>\nexport AS=\/usr\/local\/arm-2011.09\/bin\/arm-none-linux-gnueabi-as<br \/>\nexport NM=\/usr\/local\/arm-2011.09\/bin\/arm-none-linux-gnueabi-nm<br \/>\nexport RANLIB=\/usr\/local\/arm-2011.09\/arm-none-linux-gnueabi\/bin\/ranlib<br \/>\nexport CC1=\/usr\/local\/arm-2011.09\/libexec\/gcc\/arm-none-linux-gnueabi\/4.6.1\/cc1<br \/>\nexport PATH=\/usr\/local\/arm-2011.09\/bin:\/usr\/local\/arm-2011.09\/:\/usr\/local\/arm-2011.09\/lib:\/usr\/local\/arm-2011.09\/libexec\/gcc\/arm-none-linux-gnueabi\/4.6.1:$PATH<br \/>\nexport LDFLAGS=&#8221;-static&#8221;<br \/>\nexport CFLAGS=&#8221;-Os -s&#8221;<br \/>\n<\/span><br \/>\n<pre><code>$source setenv.sh\n$wget http:\/\/nmap.org\/dist\/nmap-5.61TEST4.tar.bz2\n$tar jxf nmap-5.61TEST4.tar.bz2\n$cd nmap-5.61TEST4\n<\/code><\/pre><br \/>\nAt this point you can configure and compile just Nmap. This will be without LUA library support (&#8211;without-liblua) which will disable all of the NSE scripts that have been created for Nmap as well as the additional command line tools ncat, ndiff, and nping.<\/p>\n<p><pre><code>\n$ .\/configure --host=arm-linux-androideabi --without-zenmap --without-liblua --without-nping --without-ndiff --without-ncat --with-libpcap=internal --with-pcap=linux --enable-static --prefix=\/data\/opt\n<\/code><\/pre><br \/>\nIf you want to include these scripts and tools you will have to modify the Nmap source code. If you try to compile with LUA support you will get this error.<\/p>\n<p><span style=\"font-family: courier new; font-size: x-small;\"><br \/>\nstrict-aliasing -DLUA_USE_POSIX -DLUA_USE_DLOPEN -c -o llex.o llex.c<br \/>\nllex.c: In function &#8216;trydecpoint&#8217;:<br \/>\nllex.c:181: error: &#8216;struct lconv&#8217; has no member named &#8216;decimal_point&#8217;<br \/>\nmake[1]: *** [llex.o] Error 1<br \/>\nmake[1]: Leaving directory `\/home\/edge\/source\/nmap-5.51\/liblua&#8217;<br \/>\nmake: *** [lua_build] Error 2<br \/>\n<\/span><\/p>\n<p>If you try to compile without LUA but want nping you get this error.<br \/>\n<span style=\"font-family: courier new; font-size: x-small;\"><br \/>\nIn file included from ArgParser.cc:94:<br \/>\nnping.h:116:26: error: sysexits.h: No such file or directory<br \/>\nmake[3]: *** [ArgParser.o] Error 1<br \/>\nmake[3]: Leaving directory `\/home\/edge\/source\/nmap-5.51\/nping&#8217;<br \/>\nmake[2]: *** [all] Error 2<br \/>\nmake[2]: Leaving directory `\/home\/edge\/source\/nmap-5.51\/nping&#8217;<br \/>\nmake[1]: *** [build-nping] Error 2<br \/>\nmake[1]: Leaving directory `\/home\/edge\/source\/nmap-5.51&#8242;<br \/>\nmake: *** [all] Error 2<br \/>\n<\/span><br \/>\nVlatko Kosturjak &lt;kost () linux hr&gt; comes to the rescue with his patch that allows you to compile with LUA and nping. I\u2019m hosting the patch from my site just in case it is removed from the forums where he posted it.<br \/>\n<pre><code>\n$cd ~\/source\/ nmap-5.61TEST4\n$mkdir android\n$wget http:\/\/www.jedge.com\/code\/nmap.android.patches.diff -O android\/ nmap.android.patches.diff\n$patch -N -p1 &amp;lt; android\/nmap.android.patches.diff\n$ .\/configure --host=arm-linux-androideabi --without-zenmap --with-liblua=included --with-libpcap=internal --with-pcap=linux --enable-static --prefix=\/data\/opt\n$make\n$sudo make install\n<\/code><\/pre><br \/>\nOne my phone I created the directory opt in the data directory where I install all of my tools (\/data\/opt). That is why you see &#8211;prefix set to \/data\/opt. You can set it to whatever directory you want but remember I use this directory throughout my instructions. When you \u201cinstall\u201d nmap on your Linux host system it will be placed in \/data\/opt\/bin and \/data\/opt\/share. I mirror these same directories on my Android phone.<\/p>\n<p>I believe you can run nmap on a phone that has not been rooted by sticking the files in \/data\/data\/&lt;terminal_app_directory&gt;\/bin but I will not be discussing how to accomplish that or what pitfalls exist. My phone is already rooted and yours should be too if you want to be successful with this tutorial. Rooting your phone is outside the scope of this tutorial.<br \/>\nInstall Android SDK and pushing files to the phone<\/p>\n<p>One of the best ways to get files copied to your Android phone is to use the command \u2018adb\u2019 which is part of the platform-tools of the Android SDK. Below are the steps to obtain the SDK and use \u2018adb\u2019 to push the compiled nmap files to your phone.<br \/>\n<pre><code>\n$sudo \u2013s\n#apt-get install openjdk-7-jdk\n#cd \/usr\/local\n# wget http:\/\/dl.google.com\/android\/android-sdk_r16-linux.tgz\n#tar android-sdk_r16-linux.tgz\n<\/code><\/pre><br \/>\nThis next step is the only part where you need a GUI. Running \/usr\/local\/android-sdk-linux\/tools\/android will open up a window where you need to select Android SDK Platform Tools, deselect Android 4.0.x, and click Install 1 package&#8230; (See Screenshot below).<\/p>\n<p><pre><code>\n#android-sdk-linux\/tools\/android &amp;amp;\n<\/code><\/pre><\/p>\n<figure class=\"thumbnail wp-caption alignnone\" style=\"width: 467px\"><img loading=\"lazy\" decoding=\"async\" title=\"Android SDK Manager\" src=\"http:\/\/www.jedge.com\/images\/android_sdk_manager.png\" alt=\"\" width=\"457\" height=\"302\" \/><figcaption class=\"caption wp-caption-text\">Android SDK Manager<\/figcaption><\/figure>\n<p><pre><code>\n#export PATH=\/usr\/local\/android-sdk-linux\/platform-tools:$PATH\n#adb devices\n<\/code><\/pre><br \/>\nOutput examples<br \/>\n<kbd><br \/>\nList of devices attached<br \/>\n???????????? offline<br \/>\n<\/kbd><br \/>\nUnplug your phone and plug it back in. You should see the following output.<br \/>\n<kbd><br \/>\nList of devices attached<br \/>\n364247A74CE500FD device<br \/>\n<\/kbd><br \/>\n<pre><code>\n#adb remount\n#adb shell mkdir \/data\/opt\n#adb chmod 755 \/data\/opt\n#adb push \/data\/opt \/data\/opt\n<\/code><\/pre><br \/>\nThis will push the bin and share directories created on Ubuntu that were installed when you ran \u2018make install\u2019 from the Nmap directory. They will be pushed to the corresponding directory on the phone.<br \/>\nRunning Nmap on your phone<\/p>\n<p>I use BTEP (Better Terminal Emulator Pro) as my terminal of choice on my Android phone. The home directory is located in \/data\/data\/com.magicandroidapps.bettertermpro\/home<br \/>\nI also use Root Explorer to traverse the file structure and open up files for editing.<\/p>\n<p>All applications I compile for Android I place in my \/data\/opt directory and I modify .profile of BTEP to include the executable directory in my PATH (\/data\/opt\/bin). I also include \/data\/opt\/lib in LD_LIBRARY_PATH.<\/p>\n<figure class=\"thumbnail wp-caption aligncenter\" style=\"width: 490px\"><img loading=\"lazy\" decoding=\"async\" class=\" \" title=\"Root Explorer .profile access.\" src=\"http:\/\/www.jedge.com\/images\/screen_20120228_1132.png\" alt=\"\" width=\"480\" height=\"288\" \/><figcaption class=\"caption wp-caption-text\">Use Root Explorer and traverse to the home directory of BTEP<\/figcaption><\/figure>\n<figure class=\"thumbnail wp-caption aligncenter\" style=\"width: 490px\"><img loading=\"lazy\" decoding=\"async\" class=\" \" title=\"Open .profile\" src=\"http:\/\/www.jedge.com\/images\/screen_20120228_1132_2.png\" alt=\"\" width=\"480\" height=\"288\" \/><figcaption class=\"caption wp-caption-text\">Long press .profile to bring up this menu and choose Open With<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure class=\"thumbnail wp-caption aligncenter\" style=\"width: 490px\"><a href=\"Open .profile with the Text Editor\"><img loading=\"lazy\" decoding=\"async\" title=\"Open with Text Editor\" src=\"http:\/\/www.jedge.com\/images\/screen_20120228_1132_3.png\" alt=\"\" width=\"480\" height=\"288\" \/><\/a><figcaption class=\"caption wp-caption-text\">Open with Text Editor<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure class=\"thumbnail wp-caption aligncenter\" style=\"width: 490px\"><img loading=\"lazy\" decoding=\"async\" class=\" \" title=\"Edit .profile PATH and LD_LIBRARY_PATH\" src=\"http:\/\/www.jedge.com\/images\/screen_20120228_1133.png\" alt=\"\" width=\"480\" height=\"288\" \/><figcaption class=\"caption wp-caption-text\">Edit .profile PATH and LD_LIBRARY_PATH<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure class=\"thumbnail wp-caption aligncenter\" style=\"width: 490px\"><img loading=\"lazy\" decoding=\"async\" class=\" \" title=\"Hit your phones menu but and Save and Exit\" src=\"http:\/\/www.jedge.com\/images\/screen_20120228_1133_2.png\" alt=\"\" width=\"480\" height=\"288\" \/><figcaption class=\"caption wp-caption-text\">Hit your phones menu but and Save and Exit<\/figcaption><\/figure>\n<p>To have your changes take effect you can close and reopen BTEP or run #source .profile from the command line.<\/p>\n<p>You can now run Nmap from your Android phone. A program you successfully cross compiled yourself. These steps can be modified to compile other software for your phone. Your mileage will vary with other software. Especially since Android uses a stripped down libc called Bionic which will prevent software from compiling or running correctly.<\/p>\n<p>&nbsp;<\/p>\n<p>Special Thanks to Vlatko Kosturjak &lt;kost () linux hr&gt; <a href=\"http:\/\/k0st.wordpress.com\/\" target=\"_blank\">http:\/\/k0st.wordpress.com\/<\/a> who got nmap to compile with liblua support as well as nping to compile.<\/p>\n<p><a href=\"https:\/\/secwiki.org\/w\/Nmap\/Android\" target=\"_blank\">https:\/\/secwiki.org\/w\/Nmap\/Android<\/a><br \/>\n<a href=\"http:\/\/seclists.org\/nmap-dev\/2012\/q1\/135\" target=\"_blank\">http:\/\/seclists.org\/nmap-dev\/2012\/q1\/135<\/a><br \/>\n<a href=\"http:\/\/seclists.org\/nmap-dev\/2010\/q2\/1021\" target=\"_blank\">http:\/\/seclists.org\/nmap-dev\/2010\/q2\/1021<\/a><br \/>\n<a href=\"http:\/\/k0st.wordpress.com\/2012\/01\/12\/nmap-5-61test4-on-android\/\" target=\"_blank\">http:\/\/k0st.wordpress.com\/2012\/01\/12\/nmap-5-61test4-on-android\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a title=\"Compile Nmap for Android PDF Document\" href=\"http:\/\/www.jedge.com\/docs\/Compile%20Nmap%20for%20Android.pdf\"> (download PDF)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Compile Nmap for Android This tutorial will show you how to compile the latest version of Nmap for your Android device starting with a standard Ubuntu install. I will offer instructions on how to obtain two versions of compiler that I\u2019ve had success compiling software for Android. I will show the Android NDK and the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[113,3,5],"tags":[102,69,103,57,21,56,24,59],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-compiling","category-configuration","category-installing-using-tools","tag-android","tag-command-line","tag-cross-compile","tag-install","tag-nmap","tag-penetration-testing","tag-tutorial","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":7,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":576,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/posts\/457\/revisions\/576"}],"wp:attachment":[{"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}