WiFiScan.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #ifndef WiFiScan_h
  2. #define WiFiScan_h
  3. //#include <BLEDevice.h>
  4. //#include <BLEUtils.h>
  5. //#include <BLEScan.h>
  6. //#include <BLEAdvertisedDevice.h>
  7. #include <ArduinoJson.h>
  8. // Testing NimBLE
  9. #include <NimBLEDevice.h>
  10. #include <NimBLEAdvertisedDevice.h>
  11. #include <WiFi.h>
  12. #include <math.h>
  13. #include "esp_wifi.h"
  14. #include "esp_wifi_types.h"
  15. #include "esp_bt.h"
  16. #include "Display.h"
  17. #include "SDInterface.h"
  18. #include "Buffer.h"
  19. #include "BatteryInterface.h"
  20. #include "TemperatureInterface.h"
  21. #include "Assets.h"
  22. //#include "MenuFunctions.h"
  23. #define bad_list_length 3
  24. #define OTA_UPDATE 100
  25. #define SHOW_INFO 101
  26. #define WIFI_SCAN_OFF 0
  27. #define WIFI_SCAN_PROBE 1
  28. #define WIFI_SCAN_AP 2
  29. #define WIFI_SCAN_PWN 3
  30. #define WIFI_SCAN_EAPOL 4
  31. #define WIFI_SCAN_DEAUTH 5
  32. #define WIFI_SCAN_ALL 6
  33. #define WIFI_PACKET_MONITOR 7
  34. #define WIFI_ATTACK_BEACON_SPAM 8
  35. #define WIFI_ATTACK_RICK_ROLL 9
  36. #define BT_SCAN_ALL 10
  37. #define BT_SCAN_SKIMMERS 11
  38. #define WIFI_SCAN_ESPRESSIF 12
  39. //#define LV_JOIN_WIFI 12
  40. #define GRAPH_REFRESH 100
  41. #define MAX_CHANNEL 14
  42. extern Display display_obj;
  43. extern SDInterface sd_obj;
  44. extern Buffer buffer_obj;
  45. extern BatteryInterface battery_obj;
  46. extern TemperatureInterface temp_obj;
  47. esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  48. class WiFiScan
  49. {
  50. private:
  51. int x_pos; //position along the graph x axis
  52. float y_pos_x; //current graph y axis position of X value
  53. float y_pos_x_old = 120; //old y axis position of X value
  54. float y_pos_y; //current graph y axis position of Y value
  55. float y_pos_y_old = 120; //old y axis position of Y value
  56. float y_pos_z; //current graph y axis position of Z value
  57. float y_pos_z_old = 120; //old y axis position of Z value
  58. int midway = 0;
  59. byte x_scale = 1; //scale of graph x axis, controlled by touchscreen buttons
  60. byte y_scale = 1;
  61. bool do_break = false;
  62. //int num_beacon = 0; // GREEN
  63. //int num_probe = 0; // BLUE
  64. //int num_deauth = 0; // RED
  65. uint32_t initTime = 0;
  66. bool run_setup = true;
  67. int bluetoothScanTime = 5;
  68. int packets_sent = 0;
  69. const wifi_promiscuous_filter_t filt = {.filter_mask=WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA};
  70. BLEScan* pBLEScan;
  71. String connected_network = "";
  72. String alfa = "1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_";
  73. char* rick_roll[8] = {
  74. "01 Never gonna give you up",
  75. "02 Never gonna let you down",
  76. "03 Never gonna run around",
  77. "04 and desert you",
  78. "05 Never gonna make you cry",
  79. "06 Never gonna say goodbye",
  80. "07 Never gonna tell a lie",
  81. "08 and hurt you"
  82. };
  83. char* prefix = "G";
  84. typedef struct
  85. {
  86. int16_t fctl;
  87. int16_t duration;
  88. uint8_t da;
  89. uint8_t sa;
  90. uint8_t bssid;
  91. int16_t seqctl;
  92. unsigned char payload[];
  93. } __attribute__((packed)) WifiMgmtHdr;
  94. typedef struct {
  95. WifiMgmtHdr hdr;
  96. uint8_t payload[0];
  97. } wifi_ieee80211_packet_t;
  98. // barebones packet
  99. uint8_t packet[128] = { 0x80, 0x00, 0x00, 0x00, //Frame Control, Duration
  100. /*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Destination address
  101. /*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //Source address - overwritten later
  102. /*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //BSSID - overwritten to the same as the source address
  103. /*22*/ 0xc0, 0x6c, //Seq-ctl
  104. /*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, //timestamp - the number of microseconds the AP has been active
  105. /*32*/ 0x64, 0x00, //Beacon interval
  106. /*34*/ 0x01, 0x04, //Capability info
  107. /* SSID */
  108. /*36*/ 0x00
  109. };
  110. void packetMonitorMain(uint32_t currentTime);
  111. void eapolMonitorMain(uint32_t currentTime);
  112. void changeChannel();
  113. void updateMidway();
  114. void tftDrawXScalButtons();
  115. void tftDrawYScaleButtons();
  116. void tftDrawChannelScaleButtons();
  117. void tftDrawColorKey();
  118. void tftDrawGraphObjects();
  119. void broadcastRandomSSID(uint32_t currentTime);
  120. void broadcastSetSSID(uint32_t current_time, char* ESSID);
  121. void RunRickRoll(uint8_t scan_mode, uint16_t color);
  122. void RunBeaconSpam(uint8_t scan_mode, uint16_t color);
  123. void RunEspressifScan(uint8_t scan_mode, uint16_t color);
  124. void RunPwnScan(uint8_t scan_mode, uint16_t color);
  125. void RunBeaconScan(uint8_t scan_mode, uint16_t color);
  126. void RunDeauthScan(uint8_t scan_mode, uint16_t color);
  127. void RunEapolScan(uint8_t scan_mode, uint16_t color);
  128. void RunProbeScan(uint8_t scan_mode, uint16_t color);
  129. void RunPacketMonitor(uint8_t scan_mode, uint16_t color);
  130. void RunBluetoothScan(uint8_t scan_mode, uint16_t color);
  131. //void RunLvJoinWiFi(uint8_t scan_mode, uint16_t color);
  132. static void scanCompleteCB(BLEScanResults scanResults);
  133. public:
  134. WiFiScan();
  135. int set_channel = 1;
  136. int old_channel = 0;
  137. bool orient_display = false;
  138. String free_ram = "";
  139. String old_free_ram = "";
  140. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  141. String getStaMAC();
  142. String getApMAC();
  143. String freeRAM();
  144. void RunInfo();
  145. void channelHop();
  146. uint8_t currentScanMode = 0;
  147. void main(uint32_t currentTime);
  148. void StartScan(uint8_t scan_mode, uint16_t color = 0);
  149. void shutdownWiFi();
  150. void StopScan(uint8_t scan_mode);
  151. static void getMAC(char *addr, uint8_t* data, uint16_t offset);
  152. static void espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  153. static void pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  154. static void beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  155. static void deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  156. static void probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  157. static void eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  158. static void wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  159. };
  160. #endif