Nmap on 4MB Flash device

Hello OpenWrt community,

I would like to install Nmap on a small router that only has 4MB of flash memory. I tried via the image builder (18.06) to remove all packages, Luci web interface etc..., and keep only Nmap but it did not work.
Is there any way to make this possible? Does a "Nmap light" package exist?

Thanks.

Routers with 4MB ram is too low to fit nmap.

Probably you can get nmap, unpack it and later transfer it to /tmp using ssh. But this will eat you RAM... and if you're on device with 4/32 then you will be out of luck.

This will works if you're on device like 4/64.

Hey @peternikolow,

Thanks for your answer. So, yes I know that Nmap is too fit for 4MB devices. But if I created this post it's to know what are the possible alternatives to make this possible.

As I said, I only need a device that can run Nmap and connect to it via SSH.

For now here are the alternatives:

  • Unpack Nmap package and directly import the binary in /tmp.
  • If the device has a USB port, expand the root filesystem.
  • Upgrading router flash by soldering a new and more powerful flash chip.

Any other ideas?

maybe you don't need nmap, and it can be done by other commands or by a script.
What are you trying to do exactly (nmap command)?

1 Like

I'm afraid that you didn't have more options.

Hey @bobafetthotmail,

Thanks for this idea, a re-code of Nmap tailored for my need!
I've actually already thought about it but I really need everything from the whole Nmap library in some way. In fact I'm currently working on a generic build that allows to transform any OpenWrt router compatible in Hak5's Shark Jack. And as this tool is mainly based on Nmap payload execution I can't do without it.

@peternikolow, I see... anyway thanks for your help :slight_smile:

@Naqwada - there is another one...

First you need to get OpenWrt and to be able to compile it on your system. Then you must make an new build based on OpenWrt but to NOT INCLUDE some software. For example - you may not need LuCI, DHCP server, PPTP and even wireless drivers. This will save approx 2MB and there you can include Nmap.

As you said - you only need DHCP client, SSH and Nmap.

I guess your tool will have to cut out 4MB devices then.

This isn't a huge issue imho, companies like GL.inet make plenty of cheap minirouters with good amounts of flash storage https://www.gl-inet.com/products/ so if you want a "pocketable tool" you are not limited to the old ones from tp-link that do have 4MB of flash

@peternikolow - That is correct, I only need SSH and Nmap. I tried to build an image (OpenWrt 18.6) with only Nmap in it but it didn't work...

Building images for ramips - A5-V11
Packages: nmap kernel libc libgcc

Installing packages...
Installing libc (1.1.19-2) to root...
Installing libgcc (7.3.0-2) to root...
Copying openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/dl/libgcc_7.3.0-2_mipsel_24kc.ipk.
Configuring libgcc.
Configuring libc.
Installing kernel (4.14.206-1-60f0d10cd039c8607daec8f870b93555) to root...
Configuring kernel.
Installing nmap (7.70-1) to root...
Copying openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/dl/nmap_7.70-1_mipsel_24kc.ipk.
Installing libpcap (1.9.1-1) to root...
Copying openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/dl/libpcap_1.9.1-1_mipsel_24kc.ipk.
Installing libstdcpp (7.3.0-2) to root...
Copying openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/dl/libstdcpp_7.3.0-2_mipsel_24kc.ipk.
Installing zlib (1.2.11-2) to root...
Copying openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/dl/zlib_1.2.11-2_mipsel_24kc.ipk.
Installing libpcre (8.41-2) to root...
Copying openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/dl/libpcre_8.41-2_mipsel_24kc.ipk.
Package kernel (4.14.206-1-60f0d10cd039c8607daec8f870b93555) installed in root is up to date.
Package libc (1.1.19-2) installed in root is up to date.
Package libgcc (7.3.0-2) installed in root is up to date.
Configuring libpcre.
Configuring libpcap.
Configuring libstdcpp.
Configuring zlib.
Configuring nmap.

Finalizing root filesystem...

Building images...
Unable to open feeds configuration at openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/scripts/feeds line 48.
Image Name:   MIPS OpenWrt Linux-4.14.206
Created:      Mon Nov 22 08:31:03 2021
Image Type:   MIPS Linux Kernel Image (lzma compressed)
Data Size:    1384924 Bytes = 1352.46 KiB = 1.32 MiB
Load Address: 80000000
Entry Point:  80000000
Parallel mksquashfs: Using 1 processor
Creating 4.0 filesystem on openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/build_dir/target-mipsel_24kc_musl/linux-ramips_rt305x/root.squashfs, block size 262144.
[=============================================================================================================================|] 90/90 100%
Exportable Squashfs 4.0 filesystem, xz compressed, data block size 262144
  compressed data, compressed metadata, compressed fragments, no xattrs
  duplicates are removed
Filesystem size 2493.45 Kbytes (2.44 Mbytes)
  18.32% of uncompressed filesystem size (13609.67 Kbytes)
Inode table size 842 bytes (0.82 Kbytes)
  34.38% of uncompressed inode table size (2449 bytes)
Directory table size 786 bytes (0.77 Kbytes)
  56.83% of uncompressed directory table size (1383 bytes)
Number of duplicate files found 8
Number of inodes 68
Number of files 43
Number of fragments 4
Number of symbolic links  9
Number of device nodes 1
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 15
Number of ids (unique uids + gids) 1
Number of uids 1
  unknown (0)
Number of gids 1
  unknown (0)
2708+1 records in
2708+1 records out
1386741 bytes (1.4 MB, 1.3 MiB) copied, 0.012664 s, 110 MB/s
4986+1 records in
4986+1 records out
2553288 bytes (2.6 MB, 2.4 MiB) copied, 0.0110554 s, 231 MB/s
padding image to 003c2000
padding image to 003c4000
padding image to 003d0000
padding image to 003e0000
padding image to 00400000
WARNING: Image file openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/build_dir/target-mipsel_24kc_musl/linux-ramips_rt305x/tmp/openwrt-18.06.9-ramips-rt305x-a5-v11-squashfs-sysupgrade.bin is too big
cp: cannot stat 'openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/build_dir/target-mipsel_24kc_musl/linux-ramips_rt305x/tmp/openwrt-18.06.9-ramips-rt305x-a5-v11-squashfs-sysupgrade.bin': No such file or directory
2708+1 records in
2708+1 records out
1386741 bytes (1.4 MB, 1.3 MiB) copied, 0.00623751 s, 222 MB/s
4986+1 records in
4986+1 records out
2553288 bytes (2.6 MB, 2.4 MiB) copied, 0.0216499 s, 118 MB/s
padding image to 003c2000
padding image to 003c4000
padding image to 003d0000
padding image to 003e0000
padding image to 00400000
WARNING: Image file openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/build_dir/target-mipsel_24kc_musl/linux-ramips_rt305x/tmp/openwrt-18.06.9-ramips-rt305x-a5-v11-squashfs-factory.bin is too big
[mkporayfw] *** error: stat failed on openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/build_dir/target-mipsel_24kc_musl/linux-ramips_rt305x/tmp/openwrt-18.06.9-ramips-rt305x-a5-v11-squashfs-factory.bin:No such file or directory
make[3]: *** [Makefile:290: openwrt-imagebuilder-18.06.9-ramips-rt305x.Linux-x86_64/build_dir/target-mipsel_24kc_musl/linux-ramips_rt305x/tmp/openwrt-18.06.9-ramips-rt305x-a5-v11-squashfs-factory.bin] Error 255
make[2]: *** [Makefile:165: build_image] Error 2
make[1]: *** [Makefile:116: _call_image] Error 2
make: *** [Makefile:193: image] Error 2

@bobafetthotmail - Yes I know the GL.inet products pretty well. But I find them a bit too big physically speaking :sweat_smile:. For the moment I did my tests on the Elecom WRH-300CR and the Buffalo WMR-300 which worked very well because more than 4MB flash. But now I'm working on adapting the image for the A5-V11 and especially the MPR-A1 which include a battery but unfortunately have only 4MB flash. The good news is that they have a USB port that allows me to expand the root filesystem during the first boot.

You need to see why it's too big

It is too big because Nmap takes too much space but if I remove Nmap, the image compiles without any problem.

That's actually why I created this topic, to see the possible alternatives.

A nice collection of tiny devices. You might want to add a VoCore2 to that list too https://vocore.io/v2.html it's a small SOM (a port-less motherboard) that is easy to integrate anywhere, maybe even replacing the insides of the MPR-A1 or any other random chinese travel router.

Then you can try to compress nmap using upx packer.

1 Like

@bobafetthotmail - Oh wow! This is the first time I hear about the VoCore2, indeed it would be nice to add it to the list, it fits well with the router criteria that I'm looking for. I'm going to order one to see what it has in the belly! Anyway thanks for sharing, if you discover any other micro routers feel free to share!

@peternikolow - Interesting! I will test this compression method this weekend and give you my feedback :slight_smile:

Hey guys hope you are good!

@peternikolow - Well, I tried upx packer and it worked fine but the packet seems still too big for 4MB flash device. I think I'll give up with it for now and just expand the partition with a mini USB drive.

@bobafetthotmail - I ordered the VoCore2, can't wait to test it with my project :slight_smile:

Alright, again thank you both for your great suggestions!

I just think for other way.

Some routers have GPIO ports and there was module for that:

All you need is to find suitable device like this:

and to solder few cables.

Other alternative is to solder USB:

But then 32MB can be too low for that too.