WiFiScan.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #ifndef WiFiScan_h
  2. #define WiFiScan_h
  3. #include "configs.h"
  4. //#include <BLEDevice.h>
  5. //#include <BLEUtils.h>
  6. //#include <BLEScan.h>
  7. //#include <BLEAdvertisedDevice.h>
  8. #include <ArduinoJson.h>
  9. // Testing NimBLE
  10. #ifdef HAS_BT
  11. #include <NimBLEDevice.h>
  12. #endif
  13. #include <WiFi.h>
  14. #include <math.h>
  15. #include "esp_wifi.h"
  16. #include "esp_wifi_types.h"
  17. #ifdef HAS_BT
  18. #include "esp_bt.h"
  19. #endif
  20. #ifdef HAS_SCREEN
  21. #include "Display.h"
  22. #endif
  23. #ifdef USE_SD_MMC_ALTERNATIVE
  24. #include "SD_MMCInterface.h"
  25. #else
  26. #include "SDInterface.h"
  27. #endif
  28. #include "Buffer.h"
  29. #include "BatteryInterface.h"
  30. #include "TemperatureInterface.h"
  31. #include "settings.h"
  32. #include "Assets.h"
  33. #include "flipperLED.h"
  34. #include "LedInterface.h"
  35. //#include "MenuFunctions.h"
  36. #define bad_list_length 3
  37. #define OTA_UPDATE 100
  38. #define SHOW_INFO 101
  39. #define ESP_UPDATE 102
  40. #define WIFI_SCAN_OFF 0
  41. #define WIFI_SCAN_PROBE 1
  42. #define WIFI_SCAN_AP 2
  43. #define WIFI_SCAN_PWN 3
  44. #define WIFI_SCAN_EAPOL 4
  45. #define WIFI_SCAN_DEAUTH 5
  46. #define WIFI_SCAN_ALL 6
  47. #define WIFI_PACKET_MONITOR 7
  48. #define WIFI_ATTACK_BEACON_SPAM 8
  49. #define WIFI_ATTACK_RICK_ROLL 9
  50. #define BT_SCAN_ALL 10
  51. #define BT_SCAN_SKIMMERS 11
  52. #define WIFI_SCAN_ESPRESSIF 12
  53. #define LV_JOIN_WIFI 13
  54. #define LV_ADD_SSID 14
  55. #define WIFI_ATTACK_BEACON_LIST 15
  56. #define WIFI_SCAN_TARGET_AP 16
  57. #define LV_SELECT_AP 17
  58. #define WIFI_ATTACK_AUTH 18
  59. #define WIFI_ATTACK_MIMIC 19
  60. #define WIFI_ATTACK_DEAUTH 20
  61. #define WIFI_ATTACK_AP_SPAM 21
  62. #define WIFI_SCAN_TARGET_AP_FULL 22
  63. #define WIFI_SCAN_ACTIVE_EAPOL 23
  64. #define WIFI_ATTACK_DEAUTH_MANUAL 24
  65. #define WIFI_SCAN_RAW_CAPTURE 25
  66. #define WIFI_SCAN_STATION 26
  67. #define WIFI_ATTACK_DEAUTH_TARGETED 27
  68. #define GRAPH_REFRESH 100
  69. #define MAX_CHANNEL 14
  70. #ifdef HAS_SCREEN
  71. extern Display display_obj;
  72. #endif
  73. extern SDInterface sd_obj;
  74. extern Buffer buffer_obj;
  75. extern BatteryInterface battery_obj;
  76. extern TemperatureInterface temp_obj;
  77. extern Settings settings_obj;
  78. extern flipperLED flipper_led;
  79. extern LedInterface led_obj;
  80. esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  81. //int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32_t arg3);
  82. struct ssid {
  83. String essid;
  84. int bssid[6];
  85. bool selected;
  86. };
  87. struct AccessPoint {
  88. String essid;
  89. int channel;
  90. int bssid[6];
  91. bool selected;
  92. LinkedList<char>* beacon;
  93. int rssi;
  94. LinkedList<int>* stations;
  95. };
  96. struct Station {
  97. uint8_t mac[6];
  98. bool selected;
  99. };
  100. class WiFiScan
  101. {
  102. private:
  103. // Settings
  104. int channel_hop_delay = 1;
  105. bool force_pmkid = false;
  106. bool force_probe = false;
  107. bool save_pcap = false;
  108. int x_pos; //position along the graph x axis
  109. float y_pos_x; //current graph y axis position of X value
  110. float y_pos_x_old = 120; //old y axis position of X value
  111. float y_pos_y; //current graph y axis position of Y value
  112. float y_pos_y_old = 120; //old y axis position of Y value
  113. float y_pos_z; //current graph y axis position of Z value
  114. float y_pos_z_old = 120; //old y axis position of Z value
  115. int midway = 0;
  116. byte x_scale = 1; //scale of graph x axis, controlled by touchscreen buttons
  117. byte y_scale = 1;
  118. bool do_break = false;
  119. bool wsl_bypass_enabled = false;
  120. //int num_beacon = 0; // GREEN
  121. //int num_probe = 0; // BLUE
  122. //int num_deauth = 0; // RED
  123. uint32_t initTime = 0;
  124. bool run_setup = true;
  125. void initWiFi(uint8_t scan_mode);
  126. int bluetoothScanTime = 5;
  127. int packets_sent = 0;
  128. const wifi_promiscuous_filter_t filt = {.filter_mask=WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA};
  129. #ifdef HAS_BT
  130. NimBLEScan* pBLEScan;
  131. #endif
  132. //String connected_network = "";
  133. String alfa = "1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_";
  134. char* rick_roll[8] = {
  135. "01 Never gonna give you up",
  136. "02 Never gonna let you down",
  137. "03 Never gonna run around",
  138. "04 and desert you",
  139. "05 Never gonna make you cry",
  140. "06 Never gonna say goodbye",
  141. "07 Never gonna tell a lie",
  142. "08 and hurt you"
  143. };
  144. char* prefix = "G";
  145. typedef struct
  146. {
  147. int16_t fctl;
  148. int16_t duration;
  149. uint8_t da;
  150. uint8_t sa;
  151. uint8_t bssid;
  152. int16_t seqctl;
  153. unsigned char payload[];
  154. } __attribute__((packed)) WifiMgmtHdr;
  155. typedef struct {
  156. uint8_t payload[0];
  157. WifiMgmtHdr hdr;
  158. } wifi_ieee80211_packet_t;
  159. // barebones packet
  160. uint8_t packet[128] = { 0x80, 0x00, 0x00, 0x00, //Frame Control, Duration
  161. /*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Destination address
  162. /*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //Source address - overwritten later
  163. /*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //BSSID - overwritten to the same as the source address
  164. /*22*/ 0xc0, 0x6c, //Seq-ctl
  165. /*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, //timestamp - the number of microseconds the AP has been active
  166. /*32*/ 0x64, 0x00, //Beacon interval
  167. /*34*/ 0x01, 0x04, //Capability info
  168. /* SSID */
  169. /*36*/ 0x00
  170. };
  171. /*uint8_t auth_packet[128] = {0xB0, 0x00, 0x3C, 0x00, // Frame Control, Duration
  172. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Dest
  173. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
  174. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Dest BSSID
  175. 0x00, 0x01, // Sequence number
  176. 0x00, 0x00, // Algo
  177. 0x01, 0x00, // Auth sequence number
  178. 0x00, 0x00, // Status Code
  179. 0x7F, 0x08,
  180. 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x40,
  181. 0xDD, 0x0B, 0x00, 0x17, 0xF2, 0x0A, 0x00, 0x01, // Say it was Apple
  182. 0x04, 0x00, 0x00, 0x00, 0x00, 0xDD, 0x0A, 0x00,
  183. 0x10, 0x18, 0x02, 0x00, 0x00, 0x10, 0x00, 0x00,
  184. 0x00
  185. };*/
  186. uint8_t auth_packet[65] = {0xb0, 0x00, 0x3c, 0x00,
  187. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
  188. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
  189. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
  190. 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  191. 0x7f, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  192. 0x00, 0x40, 0xdd, 0x0b, 0x00, 0x17, 0xf2, 0x0a,
  193. 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0xdd,
  194. 0x0a, 0x00, 0x10, 0x18, 0x02, 0x00, 0x00, 0x10,
  195. 0x00, 0x00, 0x00};
  196. uint8_t prob_req_packet[128] = {0x40, 0x00, 0x00, 0x00,
  197. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Destination
  198. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
  199. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Dest
  200. 0x01, 0x00, // Sequence
  201. 0x00, // SSID Parameter
  202. 0x00, // SSID Length
  203. /* SSID */
  204. };
  205. uint8_t deauth_frame_default[26] = {
  206. 0xc0, 0x00, 0x3a, 0x01,
  207. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  208. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  209. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  210. 0xf0, 0xff, 0x02, 0x00
  211. };
  212. void startWiFiAttacks(uint8_t scan_mode, uint16_t color, String title_string);
  213. void packetMonitorMain(uint32_t currentTime);
  214. void eapolMonitorMain(uint32_t currentTime);
  215. void updateMidway();
  216. void tftDrawXScalButtons();
  217. void tftDrawYScaleButtons();
  218. void tftDrawChannelScaleButtons();
  219. void tftDrawColorKey();
  220. void tftDrawGraphObjects();
  221. void sendProbeAttack(uint32_t currentTime);
  222. void sendDeauthAttack(uint32_t currentTime, String dst_mac_str = "ff:ff:ff:ff:ff:ff");
  223. void sendDeauthFrame(uint8_t bssid[6], int channel, String dst_mac_str = "ff:ff:ff:ff:ff:ff");
  224. void sendDeauthFrame(int bssid[6], int channel, uint8_t mac[6]);
  225. void broadcastRandomSSID(uint32_t currentTime);
  226. void broadcastCustomBeacon(uint32_t current_time, ssid custom_ssid);
  227. void broadcastCustomBeacon(uint32_t current_time, AccessPoint custom_ssid);
  228. void broadcastSetSSID(uint32_t current_time, char* ESSID);
  229. void RunAPScan(uint8_t scan_mode, uint16_t color);
  230. //void RunRickRoll(uint8_t scan_mode, uint16_t color);
  231. //void RunBeaconSpam(uint8_t scan_mode, uint16_t color);
  232. //void RunProbeFlood(uint8_t scan_mode, uint16_t color);
  233. //void RunDeauthFlood(uint8_t scan_mode, uint16_t color);
  234. void RunMimicFlood(uint8_t scan_mode, uint16_t color);
  235. //void RunBeaconList(uint8_t scan_mode, uint16_t color);
  236. void RunEspressifScan(uint8_t scan_mode, uint16_t color);
  237. void RunPwnScan(uint8_t scan_mode, uint16_t color);
  238. void RunBeaconScan(uint8_t scan_mode, uint16_t color);
  239. void RunRawScan(uint8_t scan_mode, uint16_t color);
  240. void RunStationScan(uint8_t scan_mode, uint16_t color);
  241. void RunDeauthScan(uint8_t scan_mode, uint16_t color);
  242. void RunEapolScan(uint8_t scan_mode, uint16_t color);
  243. void RunProbeScan(uint8_t scan_mode, uint16_t color);
  244. void RunPacketMonitor(uint8_t scan_mode, uint16_t color);
  245. void RunBluetoothScan(uint8_t scan_mode, uint16_t color);
  246. void RunLvJoinWiFi(uint8_t scan_mode, uint16_t color);
  247. #ifdef HAS_BT
  248. static void scanCompleteCB(BLEScanResults scanResults);
  249. #endif
  250. //int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32_t arg3);
  251. public:
  252. WiFiScan();
  253. //AccessPoint ap_list;
  254. //LinkedList<ssid>* ssids;
  255. int set_channel = 1;
  256. int old_channel = 0;
  257. bool orient_display = false;
  258. bool wifi_initialized = false;
  259. bool ble_initialized = false;
  260. String free_ram = "";
  261. String old_free_ram = "";
  262. String connected_network = "";
  263. String dst_mac = "ff:ff:ff:ff:ff:ff";
  264. byte src_mac[6] = {};
  265. //lv_obj_t * scr = lv_cont_create(NULL, NULL);
  266. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  267. char* stringToChar(String string);
  268. void RunSetup();
  269. int clearSSIDs();
  270. int clearAPs();
  271. int clearStations();
  272. bool addSSID(String essid);
  273. int generateSSIDs(int count = 20);
  274. bool shutdownWiFi();
  275. bool shutdownBLE();
  276. bool scanning();
  277. void joinWiFi(String ssid, String password);
  278. String getStaMAC();
  279. String getApMAC();
  280. String freeRAM();
  281. void changeChannel();
  282. void changeChannel(int chan);
  283. void RunInfo();
  284. void RunShutdownWiFi();
  285. void RunShutdownBLE();
  286. void RunGenerateSSIDs(int count = 20);
  287. void RunClearSSIDs();
  288. void RunClearAPs();
  289. void RunClearStations();
  290. void channelHop();
  291. uint8_t currentScanMode = 0;
  292. void main(uint32_t currentTime);
  293. void StartScan(uint8_t scan_mode, uint16_t color = 0);
  294. void StopScan(uint8_t scan_mode);
  295. static void getMAC(char *addr, uint8_t* data, uint16_t offset);
  296. static void espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  297. static void pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  298. static void beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  299. static void rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  300. static void stationSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  301. static void apSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  302. static void apSnifferCallbackFull(void* buf, wifi_promiscuous_pkt_type_t type);
  303. static void deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  304. static void probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  305. static void beaconListSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  306. static void activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  307. static void eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  308. static void wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  309. };
  310. #endif