WiFiScan.h 6.8 KB

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