Advertisement
michalmonday

esp8266_deauther examine setup routine (15/07/2018)

Jul 15th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.08 KB | None | 0 0
  1. /*
  2.    ===========================================
  3.       Copyright (c) 2018 Stefan Kremser
  4.              github.com/spacehuhn
  5.    ===========================================
  6.  */
  7. extern "C" {
  8.   #include "user_interface.h"
  9. }
  10. #include <EEPROM.h>
  11. #include "oui.h"
  12. #include "language.h"
  13. #include "functions.h"
  14. #include "Settings.h"
  15. #include "Names.h"
  16. #include "SSIDs.h"
  17. #include "Scan.h"
  18. #include "Attack.h"
  19. #include "SerialInterface.h"
  20. #include "DisplayUI.h"
  21. #include "A_config.h"
  22. #include "webfiles.h"
  23.  
  24. #include "LEDController.h"
  25.  
  26. // Run-Time Variables //
  27. LEDController* led;
  28. Settings settings;
  29. Names    names;
  30. SSIDs    ssids;
  31. Accesspoints accesspoints;
  32. Stations     stations;
  33. Scan   scan;
  34. Attack attack;
  35. SerialInterface serialInterface;
  36. DisplayUI displayUI;
  37.  
  38. #include "wifi.h"
  39.  
  40. uint32_t autosaveTime = 0;
  41. uint32_t currentTime  = 0;
  42.  
  43. bool booted = false;
  44.  
  45. void setup() {
  46.  
  47.  
  48.     // for random generator
  49.     randomSeed(os_random());
  50.  
  51.     // start serial
  52.     Serial.begin(115200);
  53.     Serial.println();
  54.  
  55.     delay(6000);
  56.     Serial.println("1");
  57.     delay(500);
  58.  
  59.     // start SPIFFS
  60.     prnt(SETUP_MOUNT_SPIFFS);
  61.     Serial.println("2");
  62.     delay(500);
  63.     prntln(SPIFFS.begin() ? SETUP_OK : SETUP_ERROR);
  64.  
  65.     Serial.println("3");
  66.     delay(500);
  67.  
  68.     // Start EEPROM
  69.     EEPROM.begin(4096);
  70.  
  71.     Serial.println("4");
  72.     delay(500);
  73.  
  74.     // auto repair when in boot-loop
  75.     uint8_t bootCounter = EEPROM.read(0);
  76.  
  77.     Serial.println("5");
  78.     delay(500);
  79.  
  80.     if (bootCounter >= 3) {
  81.         Serial.println("6a");
  82.         delay(500);
  83.         prnt(SETUP_FORMAT_SPIFFS);
  84.         SPIFFS.format();
  85.         prntln(SETUP_OK);
  86.         Serial.println("7a");
  87.         delay(500);
  88.     } else {
  89.       Serial.println("6b");
  90.       delay(500);
  91.         EEPROM.write(0, bootCounter + 1); // add 1 to the boot counter
  92.         Serial.println("7b");
  93.         delay(500);
  94.         EEPROM.commit();
  95.  
  96.         Serial.println("7c");
  97.         delay(500);
  98.        
  99.     }
  100.  
  101.     // get time
  102.     currentTime = millis();
  103.  
  104.     Serial.println("8");
  105.     delay(500);
  106.     // load settings
  107.     settings.load();
  108.  
  109.     Serial.println("9");
  110.     delay(500);
  111.     // set mac for access point
  112.     wifi_set_macaddr(SOFTAP_IF, settings.getMacAP());
  113.  
  114.     Serial.println("10");
  115.     delay(500);
  116.     // start WiFi
  117.     WiFi.mode(WIFI_OFF);
  118.     wifi_set_opmode(STATION_MODE);
  119.     wifi_set_promiscuous_rx_cb([](uint8_t* buf, uint16_t len) {
  120.         scan.sniffer(buf, len);
  121.     });
  122.  
  123.     // set mac for station
  124.     wifi_set_macaddr(STATION_IF, settings.getMacSt());
  125.  
  126.     Serial.println("11");
  127.     delay(500);
  128.  
  129.     // start display
  130.     if (settings.getDisplayInterface()) {
  131.         displayUI.setup();
  132.         displayUI.mode = SCREEN_MODE_INTRO;
  133.     }
  134.  
  135.     Serial.println("12");
  136.     delay(500);
  137.  
  138.     // copy web files to SPIFFS
  139.     copyWebFiles(false);
  140.  
  141.     Serial.println("13");
  142.     delay(500);
  143.  
  144.     // load everything else
  145.     names.load();
  146.     ssids.load();
  147.     serialInterface.load();
  148.  
  149.     Serial.println("14");
  150.     delay(500);
  151.  
  152.     // create scan.json
  153.     scan.setup();
  154.  
  155.     Serial.println("15");
  156.     delay(500);
  157.  
  158.     // setup LED
  159.     led = new LEDController();
  160.     led->setup();
  161.  
  162.     Serial.println("16");
  163.     delay(500);
  164.  
  165.     // set channel
  166.     setWifiChannel(settings.getChannel());
  167.  
  168.     Serial.println("17");
  169.     delay(500);
  170.  
  171.     // load Wifi settings: SSID, password,...
  172.     #ifdef DEFAULT_SSID
  173.       if(settings.getSSID() == "pwned") settings.setSSID(DEFAULT_SSID);
  174.     #endif
  175.     loadWifiConfigDefaults();
  176.  
  177.     Serial.println("18");
  178.     delay(500);
  179.  
  180.     // dis/enable serial command interface
  181.     if (settings.getSerialInterface()) {
  182.         serialInterface.enable();
  183.     } else {
  184.         prntln(SETUP_SERIAL_WARNING);
  185.         Serial.flush();
  186.         Serial.end();
  187.     }
  188.  
  189.     Serial.println("19");
  190.     delay(500);
  191.  
  192.     // start access point/web interface
  193.     if (settings.getWebInterface()) startAP();
  194.  
  195.     Serial.println("20");
  196.     delay(500);
  197.  
  198.     // STARTED
  199.     prntln(SETUP_STARTED);
  200.  
  201.     // version
  202.     prntln(settings.getVersion());
  203.  
  204.     Serial.println("Setup routine is completed (loop function should be executed now over and over again)");
  205.     delay(500);
  206.  
  207.    
  208. }
  209.  
  210. void loop() {
  211.     Serial.println("void loop() is being executed " + String(millis()));
  212.     delay(500);
  213.  
  214.     currentTime = millis();
  215.  
  216.     wifiUpdate();             // manage access point
  217.  
  218.     attack.update();          // run attacks
  219.     displayUI.update();
  220.     serialInterface.update(); // read and run serial input
  221.     scan.update();            // run scan
  222.     ssids.update();           // run random mode, if enabled
  223.     led->update();            // update LED color
  224.  
  225.     // auto-save
  226.     if (settings.getAutosave() && (currentTime - autosaveTime > settings.getAutosaveTime())) {
  227.         autosaveTime = currentTime;
  228.         names.save(false);
  229.         ssids.save(false);
  230.         settings.save(false);
  231.     }
  232.  
  233.     if (!booted) {
  234.         // reset boot counter
  235.         EEPROM.write(0, 0);
  236.         EEPROM.commit();
  237.         booted = true;
  238.     }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement