WiFiScan.h 11 KB

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