WiFiScan.h 11 KB

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