WiFiScan.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <WiFi.h>
  8. #include "esp_wifi.h"
  9. #include "esp_wifi_types.h"
  10. #include "Display.h"
  11. //#include "MenuFunctions.h"
  12. #define bad_list_length 3
  13. #define WIFI_SCAN_OFF 0
  14. #define WIFI_SCAN_PROBE 1
  15. #define WIFI_SCAN_AP 2
  16. #define WIFI_SCAN_ST 3
  17. #define WIFI_SCAN_ALL 4
  18. #define WIFI_ATTACK_BEACON_SPAM 5
  19. #define BT_SCAN_ALL 6
  20. #define BT_SCAN_SKIMMERS 7
  21. extern Display display_obj;
  22. esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  23. class WiFiScan
  24. {
  25. private:
  26. uint32_t initTime = 0;
  27. bool run_setup = true;
  28. int set_channel = 1;
  29. int bluetoothScanTime = 5;
  30. int packets_sent = 0;
  31. const wifi_promiscuous_filter_t filt = {.filter_mask=WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA};
  32. BLEScan* pBLEScan;
  33. String alfa = "1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_";
  34. char* prefix = "G";
  35. typedef struct
  36. {
  37. int16_t fctl;
  38. int16_t duration;
  39. uint8_t da;
  40. uint8_t sa;
  41. uint8_t bssid;
  42. int16_t seqctl;
  43. unsigned char payload[];
  44. } __attribute__((packed)) WifiMgmtHdr;
  45. typedef struct {
  46. WifiMgmtHdr hdr;
  47. uint8_t payload[0];
  48. } wifi_ieee80211_packet_t;
  49. // barebones packet
  50. uint8_t packet[128] = { 0x80, 0x00, 0x00, 0x00, //Frame Control, Duration
  51. /*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Destination address
  52. /*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //Source address - overwritten later
  53. /*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //BSSID - overwritten to the same as the source address
  54. /*22*/ 0xc0, 0x6c, //Seq-ctl
  55. /*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, //timestamp - the number of microseconds the AP has been active
  56. /*32*/ 0x64, 0x00, //Beacon interval
  57. /*34*/ 0x01, 0x04, //Capability info
  58. /* SSID */
  59. /*36*/ 0x00
  60. };
  61. void broadcastRandomSSID(uint32_t currentTime);
  62. void RunBeaconSpam(uint8_t scan_mode, uint16_t color);
  63. void RunBeaconScan(uint8_t scan_mode, uint16_t color);
  64. void RunProbeScan(uint8_t scan_mode, uint16_t color);
  65. void RunBluetoothScan(uint8_t scan_mode, uint16_t color);
  66. static void scanCompleteCB(BLEScanResults scanResults);
  67. public:
  68. WiFiScan();
  69. void channelHop();
  70. uint8_t currentScanMode = 0;
  71. void main(uint32_t currentTime);
  72. void StartScan(uint8_t scan_mode, uint16_t color = 0);
  73. void StopScan(uint8_t scan_mode);
  74. static void getMAC(char *addr, uint8_t* data, uint16_t offset);
  75. static void beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  76. static void probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  77. };
  78. #endif