oooo   o8o
                                                                            `888   `"'
                                                                   .oooo.    888  oooo      ooo. .oo.  .oo.
                                                                  `P  )88b   888  `888      `888P"Y88bP"Y88b
                                                                   .oP"888   888   888       888   888   888
                                                                  d8(  888   888   888  .o.  888   888   888
                                                                  `Y888""8o o888o o888o Y8P o888o o888o o888o

0x10 ESP32 Wardriver

Background

One of my classes allowed me to choose my final project for the semester as long
as I used Arduino, had a couple sensors, and balanced hardware + software. The
same semester, I took part in a competition called: 'National Cyber League'.
One of the OSINT problems was to discover the ESSID of a network given the
BSSID. Wigle is a website that could solve this problem as it is a database
of networks that people from all around the world had logged and uploaded.

Wardriving is essentially the method these people used; the name sounds cool
but essentially it is logging networks and dumping it in a database. The idea
is simple and fundamentally not much knowledge is required to try this for
myself. Decided for my final project to create a wardriver, or something
similar, which entailed the collection, storage, and parsing of network data.
Multiple sensors were used to fill the requirements for this project.

Initial Research

	  Requirements: Balanced Hardware and Software.
		        Lots of sensors.
		        Arduino based.
		        All scripts written by me.

Given the simple requirements above, we could simply search for network modules
that work with the Arduino Uno R3. The ESP8266 and ESP32 were stable modules that
worked similarly. The newer version (ESP32) had encryption capabilities while the
8266 did not. The older version also required input voltage of 3.3V which would
be a hassle to work with. Considering I had burnt 1 of 2 of my ESP8266 modules
I decided to use the newer version for this project. Display modules were
either: LCD1602 (or similar PMOD CLS LCDs), or the SSD1306. Number of I/O is one
thing to keep in mind, since the SSD3106 display uses I2C that would work best.
GPS location was captured via a NEO-6M GPS module. Parsing of networks was done
through a simple 4 pin push button. Sample log file output:

			03:52A 1234N, 5678E HOGWARTS WPA2

Since a while after this project was completed, still quite annoyed not enough
hardware and sensors were used in this project. I question why my instructor
had given full credits for this project.

November 13

	  Modules Used:	ESP32 WROOM Dev Board (2.4GHz).
	  		NEO-6M GPS.
			LCD1602 Display.
			RTC Via GPS Module.
			4 Pin Push Button.

First day got my hands on an ESP32 so first day of work. Started playing around
with the modules at 5A and stopped around 5P. Time captured by connecting to a
local network and pulling off the internet; don't think that's possible to
present in class, will be changed. Sniffing of networks done by ESP32 module,
super easy to do given WiFiScan example. GPS needs a solder before it can work,
and display not here yet. Had to resume work on this on Monday after soldering
connections to the GPS Module.

After First Day

November 17

	          Done: ESP32 WROOM Dev Board (2.4GHz).
		  	4 Pin Push Button.
	      Not Done: NEO-6M GPS Module.
	      		SSD136 Display Modules.
			RTC Via GPS Module.

Got to play around with the NEO-6M module after soldering the connection pins
on. Found out that a lot more information and data could be output by this tiny
GPS than anticipated which is super cool; how many satellites you're connected
to, the speed you're going, time, and so much more. Major drawback of this
component is that the satellite on it is mediocre and does not work at all
inside of buildings. This was dreadful since I had to present in a full concrete
wall classroom (presentation did not happen, professor called it off!). I had
been given an Arduino Sensor Kit (SEEED) by my professor to play around with.
GPS Example

November 20 & 21


	          Done: ESP32 WROOM Dev Board (2.4GHz).
		  	4 Pin Push Button.
	      		NEO-6M GPS Module.
			RTC Via GPS Module.
	      Not Done: SSD136 Display Modules.

This was around Thanksgiving time so lots of time to work on this; but
definitely was the most stressful. NEO-6M module was magic, one minute it would
work and another it wouldn't. The display had yet to arrive and time was ticking.
All the work hardware side was done, could only wait for the display to arrive.
Software was the only thing that needed a bit of work but research was still
not done. I was toying around the idea of creating a mariadb database, hosting
a webserver, and accept post requests from the computer connected to the ESP32
itself. Most stressful times but probably most fun times staying up late
researching different ideas and trying to solve problems. This was the first
time in my life that I been in a situation where I needed to solve problems that
I felt were the exact problems people in professional work environments would
face. Sample GPS code:

---[ 32_neo6m.ino ]---
		while (alti == 0) {
	       	  while (ss.available() > 0) {
	            gps.encode(ss.read());
		    if (gps.location.isUpdated()) {
		      longi = gps.location.lng();
		      lati  = gps.location.lat();
	   	      alti  = gps.altitude.meters();
		    }
		   }
		 }	
ESP32+GPS Working

November 27

	          Done: ESP32 WROOM Dev Board (2.4GHz).
		  	4 Pin Push Button.
	      		NEO-6M GPS Module.
			RTC Via GPS Module.
	      		SSD136 Display Modules.
	      Not Done: Script to store logs into txt file.
	      		Script to send to remote webserver.

Took a small break during Thanksgiving, felt a little burnt out playing around
with these modules everyday for many hours at a time. Display had finally
arrived during Thanksgiving, and I worked on getting it to work and printing
some same logs onto the screen. This was the finaly stretch, there was not much
time left till I had to present this project. I decided getting a database
and scripting requests would take a lot of time so software was going to be the
bare minimumum. Python script that logs data into a text file. Bash script that
would SCP the logs to a Raspberry Pi I had back home. Browser would auto popup
showing the logs. Sample display code:

---[ 32_display.ino ]---
		#include 
		#include 

		SSD1306 display(0x3c, 21, 22);

		void setup() {
		  display.init();
		  display.drawString(0,0,"GPS: ...");
		  display.drawString(0,10,"----------------");
		  display.drawString(0,20,"-90dB UDConnect");
		  display.flipScreenVertically();
		  display.display();
		}
Display Working

Dec. 1 & 2

	          Done: ESP32 WROOM Dev Board (2.4GHz).
		  	4 Pin Push Button.
	      		NEO-6M GPS Module.
			RTC Via GPS Module.
	      		SSD136 Display Modules.
	      		Script to store logs into txt file.
	      		Script to send to remote webserver.

Project deadline was a couple days away, giving me enough time to write the
final report on this thing and close this project for good. Software side was
not bad, but took some time since this was the first time I had ever used a
Raspberry Pi to host a webserver and port forward connects to it. I learnt more
networking in the last couple days setting up a simple website than I had ever
did in any networking class ever. Scripts below:

---[ logCollector.py ]---
		import serial
		port = '/dev/ttyUSB0';  // Change this to correct port
		baud = 115200;          // Esp32 baud rate
		file = "output.txt";    // Output file name

		out = open(file, "w+");
		ser = serial.Serial(port, baud)
		while True:
			line = ser.readline();
			line = line.decode("utf-8")
			print(line);
			out.write(line);

---[ upload.sh ]---
		#!/bin/sh

		cat ./found.txt ./output.txt >> ./found.txt
		scp ./found.txt pi@[IPAD]:/var/www/html
		firefox "https://[IPAD]/found.txt"

Closing Thoughts

This article does not suffice when it comes to all the codes and scripts that
were written during the project; it would be best to look at them in my github
page. The final report for this project is a 22 page report that gives an
explanation to everything: why things were done the way they were, why these
modules, problems that occured that did not get put in this article (brownout
problems, logistical problems, more requirements, so on). If you'd like a copy
then email me and I may send you it depending on what it will be used for.
Absolutely loved working this project and hope to do more with Arduino's,
Raspberry Pi's, building networks, breaking things and solving more problems.
Absolutely wonderful.