WiFiScan.h 9.5 KB

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