Tuesday, 12 September 2017

Make R-PI, NanoPi, C.H.I.P a WiFi Access Point (HOSTAP)

Make R-PI, CHIP, Nano-PiNeo-2 a Wifi Hot Spot.


I wrote an automated script (makeThisHostApt.sh) for https://github.com/comarius/liveimage to setup easy any device into a host spot by simply running a script.
The script is tuned for 'liveimage' project and would configure 'liveimage' and 'lighthttpd' and requires few small changes after installation.

  • Prerequisites for Wifi AP
    • apt-get -y install --reinstall hostapd 
    • apt-get install dnsmasq
  • Prerequisites for local web server (optional)
    • apt-get -y install lighttpd php5-cgi
      • lighttpd would be reconfigured to run under $USER
  • One time commands
    • lighty-enable-mod fastcgi-php  
    • sudo service lighttpd stop (would be ran from another startup script)
    • sudo usermod -a -G www-data $USER




Making a Wi-Fi Hot-Spot implies to change these files:

  • /etc/network/interfaces           Setup the AP IP/Network
  • /etc/hostapd/hostapd.conf       SSID name, AP-channel, password
  • /etc/dnsmasq.conf                   DNS server for clients
  • /etc/dhcp/dhcp.conf                 IP range DHCP for wifi clients
For a lighttp server (optional)
  • /etc/init.d/lighttpd                   Modified scrip to run under $USER
  • /etc/lighttpd/lighttpd.conf      config modified to run php, and to tun as $USER

For Nano-Pi Neo-2 use
  • sudo turn-wifi-into-apmode yes/no
    • and ignore the script.

Furthermore if you want the WifiHost to trap any incoming http request and to redirect it to local HTTP server you can run alternatively setupHoneyPot.sh

To run the script clone the git and delete everything except HOSTAPD folder. The folder contains the template files for the system used by the script.

The script can be ran in test mode, and would generate a folder called OUT where you would find generated /  changed files for the root file system. Either can copy them on the roof file system, or rerun in deploy mode.


The tree structure for generated files which patches the rootfs is:

.
├── etc
│   ├── dhcp
│   │   └── dhcp.conf
│   ├── dnsmasq.conf
│   ├── hostapd
│   │   └── hostapd.conf
│   ├── init.d
│   │   ├── autostart
│   │   └── lighttpd
│   ├── lighttpd
│   │   └── lighttpd.conf
│   └── network
│       └── interfaces
└── home
    └── pi
        └── .autostart



  • Delete related liveimage stuff
    • /home/<pi> /.autostart
  • If there is no http server required
    • shell: $sudo apt-remove --purge lighttpd 
    • /home/<pi> /.autostart
      • remove from line 7 to line 15  (these are lines in original file)
      • shell:  sudo update-rc.d lighttpd remove
  •  For AP honeypot
    • setupHoneyPot.sh
      • change line ./resetip.sh $WLAN with sudo iptables -F if was not already changed
  • If !@#%^@!
    • kill wpa-suplicant
    • add a line to $HOME/.autostart to kill the process early.




Sept 12 2017, Marius C, Toronto












No comments:

Post a Comment