WiFiScan.h 9.8 KB

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