WiFiScan.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #include <WiFi.h>
  9. #include <math.h>
  10. #include "esp_wifi.h"
  11. #include "esp_wifi_types.h"
  12. #include "esp_bt.h"
  13. #include "Display.h"
  14. #include "SDInterface.h"
  15. #include "Buffer.h"
  16. #include "BatteryInterface.h"
  17. #include "TemperatureInterface.h"
  18. //#include "MenuFunctions.h"
  19. #define bad_list_length 3
  20. #define OTA_UPDATE 100
  21. #define SHOW_INFO 101
  22. #define WIFI_SCAN_OFF 0
  23. #define WIFI_SCAN_PROBE 1
  24. #define WIFI_SCAN_AP 2
  25. #define WIFI_SCAN_PWN 3
  26. #define WIFI_SCAN_EAPOL 4
  27. #define WIFI_SCAN_DEAUTH 5
  28. #define WIFI_SCAN_ALL 6
  29. #define WIFI_PACKET_MONITOR 7
  30. #define WIFI_ATTACK_BEACON_SPAM 8
  31. #define WIFI_ATTACK_RICK_ROLL 9
  32. #define BT_SCAN_ALL 10
  33. #define BT_SCAN_SKIMMERS 11
  34. #define GRAPH_REFRESH 100
  35. #define MAX_CHANNEL 14
  36. extern Display display_obj;
  37. extern SDInterface sd_obj;
  38. extern Buffer buffer_obj;
  39. extern BatteryInterface battery_obj;
  40. extern TemperatureInterface temp_obj;
  41. esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  42. class WiFiScan
  43. {
  44. private:
  45. int x_pos; //position along the graph x axis
  46. float y_pos_x; //current graph y axis position of X value
  47. float y_pos_x_old = 120; //old y axis position of X value
  48. float y_pos_y; //current graph y axis position of Y value
  49. float y_pos_y_old = 120; //old y axis position of Y value
  50. float y_pos_z; //current graph y axis position of Z value
  51. float y_pos_z_old = 120; //old y axis position of Z value
  52. int midway = 0;
  53. byte x_scale = 1; //scale of graph x axis, controlled by touchscreen buttons
  54. byte y_scale = 1;
  55. bool do_break = false;
  56. //int num_beacon = 0; // GREEN
  57. //int num_probe = 0; // BLUE
  58. //int num_deauth = 0; // RED
  59. uint32_t initTime = 0;
  60. bool run_setup = true;
  61. int set_channel = 1;
  62. int bluetoothScanTime = 5;
  63. int packets_sent = 0;
  64. const wifi_promiscuous_filter_t filt = {.filter_mask=WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA};
  65. BLEScan* pBLEScan;
  66. String alfa = "1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_";
  67. char* rick_roll[8] = {
  68. "01 Never gonna give you up",
  69. "02 Never gonna let you down",
  70. "03 Never gonna run around",
  71. "04 and desert you",
  72. "05 Never gonna make you cry",
  73. "06 Never gonna say goodbye",
  74. "07 Never gonna tell a lie",
  75. "08 and hurt you"
  76. };
  77. char* prefix = "G";
  78. typedef struct
  79. {
  80. int16_t fctl;
  81. int16_t duration;
  82. uint8_t da;
  83. uint8_t sa;
  84. uint8_t bssid;
  85. int16_t seqctl;
  86. unsigned char payload[];
  87. } __attribute__((packed)) WifiMgmtHdr;
  88. typedef struct {
  89. WifiMgmtHdr hdr;
  90. uint8_t payload[0];
  91. } wifi_ieee80211_packet_t;
  92. // barebones packet
  93. uint8_t packet[128] = { 0x80, 0x00, 0x00, 0x00, //Frame Control, Duration
  94. /*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Destination address
  95. /*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //Source address - overwritten later
  96. /*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //BSSID - overwritten to the same as the source address
  97. /*22*/ 0xc0, 0x6c, //Seq-ctl
  98. /*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, //timestamp - the number of microseconds the AP has been active
  99. /*32*/ 0x64, 0x00, //Beacon interval
  100. /*34*/ 0x01, 0x04, //Capability info
  101. /* SSID */
  102. /*36*/ 0x00
  103. };
  104. void packetMonitorMain(uint32_t currentTime);
  105. void eapolMonitorMain(uint32_t currentTime);
  106. void changeChannel();
  107. void updateMidway();
  108. void tftDrawXScalButtons();
  109. void tftDrawYScaleButtons();
  110. void tftDrawChannelScaleButtons();
  111. void tftDrawColorKey();
  112. void tftDrawGraphObjects();
  113. void broadcastRandomSSID(uint32_t currentTime);
  114. void broadcastSetSSID(uint32_t current_time, char* ESSID);
  115. void RunRickRoll(uint8_t scan_mode, uint16_t color);
  116. void RunBeaconSpam(uint8_t scan_mode, uint16_t color);
  117. void RunPwnScan(uint8_t scan_mode, uint16_t color);
  118. void RunBeaconScan(uint8_t scan_mode, uint16_t color);
  119. void RunDeauthScan(uint8_t scan_mode, uint16_t color);
  120. void RunEapolScan(uint8_t scan_mode, uint16_t color);
  121. void RunProbeScan(uint8_t scan_mode, uint16_t color);
  122. void RunPacketMonitor(uint8_t scan_mode, uint16_t color);
  123. void RunBluetoothScan(uint8_t scan_mode, uint16_t color);
  124. static void scanCompleteCB(BLEScanResults scanResults);
  125. public:
  126. WiFiScan();
  127. bool orient_display = false;
  128. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  129. String getStaMAC();
  130. String getApMAC();
  131. String freeRAM();
  132. void RunInfo();
  133. void channelHop();
  134. uint8_t currentScanMode = 0;
  135. void main(uint32_t currentTime);
  136. void StartScan(uint8_t scan_mode, uint16_t color = 0);
  137. void StopScan(uint8_t scan_mode);
  138. static void getMAC(char *addr, uint8_t* data, uint16_t offset);
  139. static void pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  140. static void beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  141. static void deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  142. static void probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  143. static void eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  144. static void wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  145. };
  146. #endif