WiFiScan.h 11 KB

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