WiFiScan.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 WIFI_SCAN_TARGET_AP 16
  44. #define LV_SELECT_AP 17
  45. #define WIFI_ATTACK_AUTH 18
  46. #define WIFI_ATTACK_MIMIC 19
  47. #define GRAPH_REFRESH 100
  48. #define MAX_CHANNEL 14
  49. extern Display display_obj;
  50. extern SDInterface sd_obj;
  51. extern Buffer buffer_obj;
  52. extern BatteryInterface battery_obj;
  53. extern TemperatureInterface temp_obj;
  54. esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  55. struct ssid {
  56. String essid;
  57. int bssid[6];
  58. };
  59. struct AccessPoint {
  60. String essid;
  61. int channel;
  62. int bssid[6];
  63. bool selected;
  64. };
  65. class WiFiScan
  66. {
  67. private:
  68. int x_pos; //position along the graph x axis
  69. float y_pos_x; //current graph y axis position of X value
  70. float y_pos_x_old = 120; //old y axis position of X value
  71. float y_pos_y; //current graph y axis position of Y value
  72. float y_pos_y_old = 120; //old y axis position of Y value
  73. float y_pos_z; //current graph y axis position of Z value
  74. float y_pos_z_old = 120; //old y axis position of Z value
  75. int midway = 0;
  76. byte x_scale = 1; //scale of graph x axis, controlled by touchscreen buttons
  77. byte y_scale = 1;
  78. bool do_break = false;
  79. //int num_beacon = 0; // GREEN
  80. //int num_probe = 0; // BLUE
  81. //int num_deauth = 0; // RED
  82. uint32_t initTime = 0;
  83. bool run_setup = true;
  84. int bluetoothScanTime = 5;
  85. int packets_sent = 0;
  86. const wifi_promiscuous_filter_t filt = {.filter_mask=WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA};
  87. BLEScan* pBLEScan;
  88. //String connected_network = "";
  89. String alfa = "1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_";
  90. char* rick_roll[8] = {
  91. "01 Never gonna give you up",
  92. "02 Never gonna let you down",
  93. "03 Never gonna run around",
  94. "04 and desert you",
  95. "05 Never gonna make you cry",
  96. "06 Never gonna say goodbye",
  97. "07 Never gonna tell a lie",
  98. "08 and hurt you"
  99. };
  100. char* prefix = "G";
  101. typedef struct
  102. {
  103. int16_t fctl;
  104. int16_t duration;
  105. uint8_t da;
  106. uint8_t sa;
  107. uint8_t bssid;
  108. int16_t seqctl;
  109. unsigned char payload[];
  110. } __attribute__((packed)) WifiMgmtHdr;
  111. typedef struct {
  112. WifiMgmtHdr hdr;
  113. uint8_t payload[0];
  114. } wifi_ieee80211_packet_t;
  115. // barebones packet
  116. uint8_t packet[128] = { 0x80, 0x00, 0x00, 0x00, //Frame Control, Duration
  117. /*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Destination address
  118. /*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //Source address - overwritten later
  119. /*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //BSSID - overwritten to the same as the source address
  120. /*22*/ 0xc0, 0x6c, //Seq-ctl
  121. /*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, //timestamp - the number of microseconds the AP has been active
  122. /*32*/ 0x64, 0x00, //Beacon interval
  123. /*34*/ 0x01, 0x04, //Capability info
  124. /* SSID */
  125. /*36*/ 0x00
  126. };
  127. /*uint8_t auth_packet[128] = {0xB0, 0x00, 0x3C, 0x00, // Frame Control, Duration
  128. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Dest
  129. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
  130. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Dest BSSID
  131. 0x00, 0x01, // Sequence number
  132. 0x00, 0x00, // Algo
  133. 0x01, 0x00, // Auth sequence number
  134. 0x00, 0x00, // Status Code
  135. 0x7F, 0x08,
  136. 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x40,
  137. 0xDD, 0x0B, 0x00, 0x17, 0xF2, 0x0A, 0x00, 0x01, // Say it was Apple
  138. 0x04, 0x00, 0x00, 0x00, 0x00, 0xDD, 0x0A, 0x00,
  139. 0x10, 0x18, 0x02, 0x00, 0x00, 0x10, 0x00, 0x00,
  140. 0x00
  141. };*/
  142. uint8_t auth_packet[65] = {0xb0, 0x00, 0x3c, 0x00,
  143. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
  144. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
  145. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
  146. 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  147. 0x7f, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  148. 0x00, 0x40, 0xdd, 0x0b, 0x00, 0x17, 0xf2, 0x0a,
  149. 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0xdd,
  150. 0x0a, 0x00, 0x10, 0x18, 0x02, 0x00, 0x00, 0x10,
  151. 0x00, 0x00, 0x00};
  152. uint8_t prob_req_packet[128] = {0x40, 0x00, 0x00, 0x00,
  153. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Destination
  154. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
  155. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Dest
  156. 0x01, 0x00, // Sequence
  157. 0x00, // SSID Parameter
  158. 0x00, // SSID Length
  159. /* SSID */
  160. };
  161. void packetMonitorMain(uint32_t currentTime);
  162. void eapolMonitorMain(uint32_t currentTime);
  163. void changeChannel();
  164. void updateMidway();
  165. void tftDrawXScalButtons();
  166. void tftDrawYScaleButtons();
  167. void tftDrawChannelScaleButtons();
  168. void tftDrawColorKey();
  169. void tftDrawGraphObjects();
  170. void sendProbeAttack(uint32_t currentTime);
  171. void broadcastRandomSSID(uint32_t currentTime);
  172. void broadcastCustomBeacon(uint32_t current_time, ssid custom_ssid);
  173. void broadcastSetSSID(uint32_t current_time, char* ESSID);
  174. void RunAPScan(uint8_t scan_mode, uint16_t color);
  175. void RunRickRoll(uint8_t scan_mode, uint16_t color);
  176. void RunBeaconSpam(uint8_t scan_mode, uint16_t color);
  177. void RunProbeFlood(uint8_t scan_mode, uint16_t color);
  178. void RunMimicFlood(uint8_t scan_mode, uint16_t color);
  179. void RunBeaconList(uint8_t scan_mode, uint16_t color);
  180. void RunEspressifScan(uint8_t scan_mode, uint16_t color);
  181. void RunPwnScan(uint8_t scan_mode, uint16_t color);
  182. void RunBeaconScan(uint8_t scan_mode, uint16_t color);
  183. void RunDeauthScan(uint8_t scan_mode, uint16_t color);
  184. void RunEapolScan(uint8_t scan_mode, uint16_t color);
  185. void RunProbeScan(uint8_t scan_mode, uint16_t color);
  186. void RunPacketMonitor(uint8_t scan_mode, uint16_t color);
  187. void RunBluetoothScan(uint8_t scan_mode, uint16_t color);
  188. void RunLvJoinWiFi(uint8_t scan_mode, uint16_t color);
  189. static void scanCompleteCB(BLEScanResults scanResults);
  190. public:
  191. WiFiScan();
  192. //AccessPoint ap_list;
  193. //LinkedList<ssid>* ssids;
  194. int set_channel = 1;
  195. int old_channel = 0;
  196. bool orient_display = false;
  197. bool wifi_initialized = false;
  198. bool ble_initialized = false;
  199. String free_ram = "";
  200. String old_free_ram = "";
  201. String connected_network = "";
  202. //lv_obj_t * scr = lv_cont_create(NULL, NULL);
  203. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  204. char* stringToChar(String string);
  205. void RunSetup();
  206. int clearSSIDs();
  207. int clearAPs();
  208. bool addSSID(String essid);
  209. int generateSSIDs();
  210. bool shutdownWiFi();
  211. bool shutdownBLE();
  212. void joinWiFi(String ssid, String password);
  213. String getStaMAC();
  214. String getApMAC();
  215. String freeRAM();
  216. void RunInfo();
  217. void RunShutdownWiFi();
  218. void RunShutdownBLE();
  219. void RunGenerateSSIDs();
  220. void RunClearSSIDs();
  221. void RunClearAPs();
  222. void channelHop();
  223. uint8_t currentScanMode = 0;
  224. void main(uint32_t currentTime);
  225. void StartScan(uint8_t scan_mode, uint16_t color = 0);
  226. void StopScan(uint8_t scan_mode);
  227. static void getMAC(char *addr, uint8_t* data, uint16_t offset);
  228. static void espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  229. static void pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  230. static void beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  231. static void apSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  232. static void deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  233. static void probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  234. static void beaconListSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  235. static void eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  236. static void wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  237. };
  238. #endif