WiFiScan.cpp 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. #include "WiFiScan.h"
  2. //esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  3. //int num_beacon = 0;
  4. int num_beacon = 0;
  5. int num_deauth = 0;
  6. int num_probe = 0;
  7. int num_eapol = 0;
  8. class bluetoothScanAllCallback: public BLEAdvertisedDeviceCallbacks {
  9. /* Original BLE */
  10. //void onResult(BLEAdvertisedDevice advertisedDevice) {
  11. /* NimBLE */
  12. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  13. //advertisedDevice.getScan()->stop();
  14. String display_string = "";
  15. if (display_obj.display_buffer->size() >= 0)
  16. {
  17. display_string.concat(" RSSI: ");
  18. display_string.concat(advertisedDevice->getRSSI());
  19. Serial.print(" RSSI: ");
  20. Serial.print(advertisedDevice->getRSSI());
  21. display_string.concat(" ");
  22. Serial.print(" ");
  23. Serial.print("Device: ");
  24. if(advertisedDevice->getName().length() != 0)
  25. {
  26. display_string.concat(advertisedDevice->getName().c_str());
  27. Serial.print(advertisedDevice->getName().c_str());
  28. }
  29. else
  30. {
  31. display_string.concat(advertisedDevice->getAddress().toString().c_str());
  32. Serial.print(advertisedDevice->getAddress().toString().c_str());
  33. }
  34. int temp_len = display_string.length();
  35. for (int i = 0; i < 40 - temp_len; i++)
  36. {
  37. display_string.concat(" ");
  38. }
  39. Serial.println();
  40. while (display_obj.printing)
  41. delay(1);
  42. display_obj.loading = true;
  43. display_obj.display_buffer->add(display_string);
  44. display_obj.loading = false;
  45. }
  46. }
  47. };
  48. class bluetoothScanSkimmersCallback: public BLEAdvertisedDeviceCallbacks {
  49. /* Original BLE */
  50. //void onResult(BLEAdvertisedDevice advertisedDevice) {
  51. /* NimBLE */
  52. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  53. String bad_list[bad_list_length] = {"HC-03", "HC-05", "HC-06"};
  54. if (display_obj.display_buffer->size() >= 0)
  55. {
  56. Serial.print("Device: ");
  57. String display_string = "";
  58. //display_string.concat(" RSSI: ");
  59. //display_string.concat(advertisedDevice.getRSSI());
  60. //display_string.concat(" ");
  61. if(advertisedDevice->getName().length() != 0)
  62. {
  63. //display_string.concat(advertisedDevice.getName().c_str());
  64. Serial.print(advertisedDevice->getName().c_str());
  65. for(int i = 0; i < bad_list_length; i++)
  66. {
  67. if(strcmp(advertisedDevice->getName().c_str(), bad_list[i].c_str()) == 0)
  68. {
  69. display_string.concat("Potential Skimmer: ");
  70. display_string.concat(" ");
  71. display_string.concat(advertisedDevice->getName().c_str());
  72. int temp_len = display_string.length();
  73. for (int i = 0; i < 40 - temp_len; i++)
  74. {
  75. display_string.concat(" ");
  76. }
  77. while (display_obj.printing)
  78. delay(1);
  79. display_obj.loading = true;
  80. display_obj.display_buffer->add(display_string);
  81. display_obj.loading = false;
  82. }
  83. }
  84. }
  85. else
  86. {
  87. Serial.print(advertisedDevice->getAddress().toString().c_str());
  88. //display_string.concat(advertisedDevice.getAddress().toString().c_str());
  89. }
  90. /*
  91. int temp_len = display_string.length();
  92. for (int i = 0; i < 40 - temp_len; i++)
  93. {
  94. display_string.concat(" ");
  95. }
  96. */
  97. Serial.print(" RSSI: ");
  98. Serial.println(advertisedDevice->getRSSI());
  99. /*
  100. while (display_obj.printing)
  101. delay(1);
  102. display_obj.loading = true;
  103. display_obj.display_buffer->add(display_string);
  104. display_obj.loading = false;
  105. */
  106. }
  107. }
  108. };
  109. WiFiScan::WiFiScan()
  110. {
  111. }
  112. // Function to prepare to run a specific scan
  113. void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
  114. {
  115. //Serial.println("Starting Scan...");
  116. if (scan_mode == WIFI_SCAN_OFF)
  117. StopScan(scan_mode);
  118. else if (scan_mode == WIFI_SCAN_PROBE)
  119. RunProbeScan(scan_mode, color);
  120. else if (scan_mode == WIFI_SCAN_EAPOL)
  121. RunEapolScan(scan_mode, color);
  122. else if (scan_mode == WIFI_SCAN_AP)
  123. RunBeaconScan(scan_mode, color);
  124. else if (scan_mode == WIFI_SCAN_PWN)
  125. RunPwnScan(scan_mode, color);
  126. else if (scan_mode == WIFI_SCAN_DEAUTH)
  127. RunDeauthScan(scan_mode, color);
  128. else if (scan_mode == WIFI_PACKET_MONITOR)
  129. RunPacketMonitor(scan_mode, color);
  130. else if (scan_mode == WIFI_ATTACK_BEACON_SPAM)
  131. RunBeaconSpam(scan_mode, color);
  132. else if (scan_mode == WIFI_ATTACK_RICK_ROLL)
  133. RunRickRoll(scan_mode, color);
  134. else if (scan_mode == BT_SCAN_ALL)
  135. RunBluetoothScan(scan_mode, color);
  136. else if (scan_mode == BT_SCAN_SKIMMERS)
  137. RunBluetoothScan(scan_mode, color);
  138. else if (scan_mode == WIFI_SCAN_ESPRESSIF)
  139. RunEspressifScan(scan_mode, color);
  140. //else if (scan_mode == LV_JOIN_WIFI)
  141. // RunLvJoinWiFi(scan_mode, color);
  142. WiFiScan::currentScanMode = scan_mode;
  143. }
  144. void WiFiScan::shutdownWiFi() {
  145. Serial.println("Ahhh yes...promiscuity will end");
  146. esp_wifi_set_promiscuous(false);
  147. //WiFi.persistent(false);
  148. WiFi.disconnect(true);
  149. WiFi.mode(WIFI_OFF);
  150. esp_wifi_set_mode(WIFI_MODE_NULL);
  151. esp_wifi_stop();
  152. esp_wifi_deinit();
  153. }
  154. // Function to stop all wifi scans
  155. void WiFiScan::StopScan(uint8_t scan_mode)
  156. {
  157. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  158. (currentScanMode == WIFI_SCAN_AP) ||
  159. (currentScanMode == WIFI_SCAN_PWN) ||
  160. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  161. (currentScanMode == WIFI_SCAN_EAPOL) ||
  162. (currentScanMode == WIFI_SCAN_ALL) ||
  163. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  164. (currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  165. (currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  166. (currentScanMode == WIFI_PACKET_MONITOR))
  167. {
  168. this->shutdownWiFi();
  169. }
  170. else if ((currentScanMode == BT_SCAN_ALL) ||
  171. (currentScanMode == BT_SCAN_SKIMMERS))
  172. {
  173. Serial.println("Stopping BLE scan...");
  174. pBLEScan->stop();
  175. Serial.println("BLE Scan Stopped");
  176. Serial.println("Clearing BLE Results...");
  177. pBLEScan->clearResults();
  178. Serial.println("Deinitializing BT Controller...");
  179. BLEDevice::deinit();
  180. //Serial.println("Disable and Deinit BLE...");
  181. //esp_bt_controller_disable();
  182. //esp_bt_controller_deinit();
  183. //Serial.println("Releasing BLE Memory...");
  184. //esp_bt_controller_mem_release(ESP_BT_MODE_BLE);
  185. //Serial.println("BT Controller Status: " + (String)esp_bt_controller_get_status());
  186. }
  187. display_obj.display_buffer->clear();
  188. Serial.print("display_buffer->size(): ");
  189. Serial.println(display_obj.display_buffer->size());
  190. display_obj.tteBar = false;
  191. }
  192. String WiFiScan::getStaMAC()
  193. {
  194. char *buf;
  195. uint8_t mac[6];
  196. char macAddrChr[18] = {0};
  197. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  198. esp_wifi_init(&cfg);
  199. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  200. esp_wifi_set_mode(WIFI_MODE_NULL);
  201. esp_wifi_start();
  202. esp_err_t mac_status = esp_wifi_get_mac(ESP_IF_WIFI_STA, mac);
  203. sprintf(macAddrChr,
  204. "%02X:%02X:%02X:%02X:%02X:%02X",
  205. mac[0],
  206. mac[1],
  207. mac[2],
  208. mac[3],
  209. mac[4],
  210. mac[5]);
  211. this->shutdownWiFi();
  212. return String(macAddrChr);
  213. }
  214. String WiFiScan::getApMAC()
  215. {
  216. char *buf;
  217. uint8_t mac[6];
  218. char macAddrChr[18] = {0};
  219. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  220. esp_wifi_init(&cfg);
  221. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  222. esp_wifi_set_mode(WIFI_MODE_NULL);
  223. esp_wifi_start();
  224. esp_err_t mac_status = esp_wifi_get_mac(ESP_IF_WIFI_AP, mac);
  225. sprintf(macAddrChr,
  226. "%02X:%02X:%02X:%02X:%02X:%02X",
  227. mac[0],
  228. mac[1],
  229. mac[2],
  230. mac[3],
  231. mac[4],
  232. mac[5]);
  233. this->shutdownWiFi();
  234. return String(macAddrChr);
  235. }
  236. String WiFiScan::freeRAM()
  237. {
  238. char s[150];
  239. sprintf(s, "RAM Free: %u bytes", system_get_free_heap_size());
  240. this->free_ram = String(system_get_free_heap_size());
  241. return String(s);
  242. }
  243. /*
  244. void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
  245. display_obj.tft.init();
  246. display_obj.tft.setRotation(1);
  247. #ifdef TFT_SHIELD
  248. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  249. Serial.println("Using TFT Shield");
  250. #else if defined(TFT_DIY)
  251. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  252. Serial.println("Using TFT DIY");
  253. #endif
  254. display_obj.tft.setTouch(calData);
  255. display_obj.initLVGL();
  256. lv_obj_t * scr = lv_cont_create(NULL, NULL);
  257. lv_disp_load_scr(scr);
  258. display_obj.joinWiFiGFX();
  259. }*/
  260. void WiFiScan::RunInfo()
  261. {
  262. String sta_mac = this->getStaMAC();
  263. String ap_mac = this->getApMAC();
  264. String free_ram = this->freeRAM();
  265. //Serial.print("STA MAC: ");
  266. //Serial.println(sta_mac);
  267. //Serial.print("AP MAC: ");
  268. //Serial.println(ap_mac);
  269. Serial.println(free_ram);
  270. display_obj.tft.setTextWrap(false);
  271. display_obj.tft.setFreeFont(NULL);
  272. display_obj.tft.setCursor(0, 100);
  273. display_obj.tft.setTextSize(1);
  274. display_obj.tft.setTextColor(TFT_CYAN);
  275. display_obj.tft.println(" Firmware: Marauder");
  276. display_obj.tft.println(" Version: " + display_obj.version_number + "\n");
  277. display_obj.tft.println(" Station MAC: " + sta_mac);
  278. display_obj.tft.println(" AP MAC: " + ap_mac);
  279. display_obj.tft.println(" " + free_ram);
  280. if (sd_obj.supported) {
  281. display_obj.tft.println(" SD Card: Connected");
  282. display_obj.tft.print(" SD Card Size: ");
  283. display_obj.tft.print(sd_obj.card_sz);
  284. display_obj.tft.println("MB");
  285. }
  286. else {
  287. display_obj.tft.println(" SD Card: Not Connected");
  288. display_obj.tft.println(" SD Card Size: 0");
  289. }
  290. battery_obj.battery_level = battery_obj.getBatteryLevel();
  291. if (battery_obj.i2c_supported) {
  292. display_obj.tft.println(" IP5306 I2C: supported");
  293. display_obj.tft.println(" Battery Lvl: " + (String)battery_obj.battery_level + "%");
  294. }
  295. else
  296. display_obj.tft.println(" IP5306 I2C: not supported");
  297. display_obj.tft.println("Internal temp: " + (String)temp_obj.current_temp + " C");
  298. }
  299. void WiFiScan::RunEspressifScan(uint8_t scan_mode, uint16_t color) {
  300. sd_obj.openCapture("espressif");
  301. display_obj.TOP_FIXED_AREA_2 = 48;
  302. display_obj.tteBar = true;
  303. display_obj.print_delay_1 = 15;
  304. display_obj.print_delay_2 = 10;
  305. //display_obj.clearScreen();
  306. display_obj.initScrollValues(true);
  307. display_obj.tft.setTextWrap(false);
  308. display_obj.tft.setTextColor(TFT_WHITE, color);
  309. display_obj.tft.fillRect(0,16,240,16, color);
  310. display_obj.tft.drawCentreString(" Detect Espressif ",120,16,2);
  311. display_obj.touchToExit();
  312. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  313. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  314. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  315. esp_wifi_init(&cfg);
  316. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  317. esp_wifi_set_mode(WIFI_MODE_NULL);
  318. esp_wifi_start();
  319. esp_wifi_set_promiscuous(true);
  320. esp_wifi_set_promiscuous_filter(&filt);
  321. esp_wifi_set_promiscuous_rx_cb(&espressifSnifferCallback);
  322. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  323. initTime = millis();
  324. }
  325. void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
  326. {
  327. display_obj.tft.init();
  328. display_obj.tft.setRotation(1);
  329. display_obj.tft.fillScreen(TFT_BLACK);
  330. sd_obj.openCapture("packet_monitor");
  331. #ifdef TFT_SHIELD
  332. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  333. Serial.println("Using TFT Shield");
  334. #else if defined(TFT_DIY)
  335. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  336. Serial.println("Using TFT DIY");
  337. #endif
  338. display_obj.tft.setTouch(calData);
  339. //display_obj.tft.setFreeFont(1);
  340. display_obj.tft.setFreeFont(NULL);
  341. display_obj.tft.setTextSize(1);
  342. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  343. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  344. delay(10);
  345. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  346. display_obj.tftDrawColorKey();
  347. display_obj.tftDrawXScaleButtons(x_scale);
  348. display_obj.tftDrawYScaleButtons(y_scale);
  349. display_obj.tftDrawChannelScaleButtons(set_channel);
  350. display_obj.tftDrawExitScaleButtons();
  351. Serial.println("Running packet scan...");
  352. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  353. esp_wifi_init(&cfg);
  354. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  355. esp_wifi_set_mode(WIFI_MODE_NULL);
  356. esp_wifi_start();
  357. esp_wifi_set_promiscuous(true);
  358. esp_wifi_set_promiscuous_filter(&filt);
  359. esp_wifi_set_promiscuous_rx_cb(&wifiSnifferCallback);
  360. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  361. uint32_t initTime = millis();
  362. }
  363. void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
  364. {
  365. num_eapol = 0;
  366. display_obj.tft.init();
  367. display_obj.tft.setRotation(1);
  368. display_obj.tft.fillScreen(TFT_BLACK);
  369. sd_obj.openCapture("eapol");
  370. #ifdef TFT_SHIELD
  371. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  372. Serial.println("Using TFT Shield");
  373. #else if defined(TFT_DIY)
  374. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  375. Serial.println("Using TFT DIY");
  376. #endif
  377. display_obj.tft.setTouch(calData);
  378. //display_obj.tft.setFreeFont(1);
  379. display_obj.tft.setFreeFont(NULL);
  380. display_obj.tft.setTextSize(1);
  381. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  382. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  383. delay(10);
  384. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  385. display_obj.tftDrawEapolColorKey();
  386. //display_obj.tftDrawXScaleButtons(x_scale);
  387. //display_obj.tftDrawYScaleButtons(y_scale);
  388. display_obj.tftDrawChannelScaleButtons(set_channel);
  389. display_obj.tftDrawExitScaleButtons();
  390. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  391. esp_wifi_init(&cfg);
  392. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  393. esp_wifi_set_mode(WIFI_MODE_NULL);
  394. esp_wifi_start();
  395. esp_wifi_set_promiscuous(true);
  396. esp_wifi_set_promiscuous_filter(&filt);
  397. esp_wifi_set_promiscuous_rx_cb(&eapolSnifferCallback);
  398. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  399. initTime = millis();
  400. }
  401. void WiFiScan::RunRickRoll(uint8_t scan_mode, uint16_t color)
  402. {
  403. //Serial.println("Rick Roll...");
  404. display_obj.TOP_FIXED_AREA_2 = 48;
  405. display_obj.tteBar = true;
  406. display_obj.print_delay_1 = 15;
  407. display_obj.print_delay_2 = 10;
  408. //display_obj.clearScreen();
  409. display_obj.initScrollValues(true);
  410. display_obj.tft.setTextWrap(false);
  411. display_obj.tft.setTextColor(TFT_BLACK, color);
  412. display_obj.tft.fillRect(0,16,240,16, color);
  413. display_obj.tft.drawCentreString(" Rick Roll Beacon ",120,16,2);
  414. display_obj.touchToExit();
  415. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  416. packets_sent = 0;
  417. //esp_wifi_set_mode(WIFI_MODE_STA);
  418. WiFi.mode(WIFI_AP_STA);
  419. esp_wifi_start();
  420. esp_wifi_set_promiscuous_filter(NULL);
  421. esp_wifi_set_promiscuous(true);
  422. esp_wifi_set_max_tx_power(78);
  423. initTime = millis();
  424. //display_obj.clearScreen();
  425. //Serial.println("End of func");
  426. }
  427. // Function to prepare for beacon spam
  428. void WiFiScan::RunBeaconSpam(uint8_t scan_mode, uint16_t color)
  429. {
  430. //Serial.println("Beacon Spam...");
  431. display_obj.TOP_FIXED_AREA_2 = 48;
  432. display_obj.tteBar = true;
  433. display_obj.print_delay_1 = 15;
  434. display_obj.print_delay_2 = 10;
  435. //display_obj.clearScreen();
  436. display_obj.initScrollValues(true);
  437. display_obj.tft.setTextWrap(false);
  438. display_obj.tft.setTextColor(TFT_BLACK, color);
  439. display_obj.tft.fillRect(0,16,240,16, color);
  440. display_obj.tft.drawCentreString(" Beacon Spam Random ",120,16,2);
  441. display_obj.touchToExit();
  442. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  443. packets_sent = 0;
  444. //esp_wifi_set_mode(WIFI_MODE_STA);
  445. //WiFi.mode(WIFI_AP_STA);
  446. esp_wifi_init(&cfg);
  447. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  448. //WiFi.mode(WIFI_AP_STA);
  449. esp_wifi_set_mode(WIFI_AP_STA);
  450. esp_wifi_start();
  451. esp_wifi_set_promiscuous_filter(NULL);
  452. esp_wifi_set_promiscuous(true);
  453. esp_wifi_set_max_tx_power(78);
  454. initTime = millis();
  455. //display_obj.clearScreen();
  456. //Serial.println("End of func");
  457. }
  458. void WiFiScan::RunPwnScan(uint8_t scan_mode, uint16_t color)
  459. {
  460. sd_obj.openCapture("pwnagotchi");
  461. display_obj.TOP_FIXED_AREA_2 = 48;
  462. display_obj.tteBar = true;
  463. display_obj.print_delay_1 = 15;
  464. display_obj.print_delay_2 = 10;
  465. //display_obj.clearScreen();
  466. display_obj.initScrollValues(true);
  467. display_obj.tft.setTextWrap(false);
  468. display_obj.tft.setTextColor(TFT_WHITE, color);
  469. display_obj.tft.fillRect(0,16,240,16, color);
  470. display_obj.tft.drawCentreString(" Detect Pwnagotchi ",120,16,2);
  471. display_obj.touchToExit();
  472. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  473. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  474. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  475. esp_wifi_init(&cfg);
  476. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  477. esp_wifi_set_mode(WIFI_MODE_NULL);
  478. esp_wifi_start();
  479. esp_wifi_set_promiscuous(true);
  480. esp_wifi_set_promiscuous_filter(&filt);
  481. esp_wifi_set_promiscuous_rx_cb(&pwnSnifferCallback);
  482. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  483. initTime = millis();
  484. }
  485. // Function to start running a beacon scan
  486. void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color)
  487. {
  488. sd_obj.openCapture("beacon");
  489. display_obj.TOP_FIXED_AREA_2 = 48;
  490. display_obj.tteBar = true;
  491. display_obj.print_delay_1 = 15;
  492. display_obj.print_delay_2 = 10;
  493. //display_obj.clearScreen();
  494. display_obj.initScrollValues(true);
  495. display_obj.tft.setTextWrap(false);
  496. display_obj.tft.setTextColor(TFT_WHITE, color);
  497. display_obj.tft.fillRect(0,16,240,16, color);
  498. display_obj.tft.drawCentreString(" Beacon Sniffer ",120,16,2);
  499. display_obj.touchToExit();
  500. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  501. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  502. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  503. esp_wifi_init(&cfg);
  504. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  505. esp_wifi_set_mode(WIFI_MODE_NULL);
  506. esp_wifi_start();
  507. esp_wifi_set_promiscuous(true);
  508. esp_wifi_set_promiscuous_filter(&filt);
  509. esp_wifi_set_promiscuous_rx_cb(&beaconSnifferCallback);
  510. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  511. initTime = millis();
  512. }
  513. void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color)
  514. {
  515. sd_obj.openCapture("deauth");
  516. display_obj.TOP_FIXED_AREA_2 = 48;
  517. display_obj.tteBar = true;
  518. display_obj.print_delay_1 = 15;
  519. display_obj.print_delay_2 = 10;
  520. //display_obj.clearScreen();
  521. display_obj.initScrollValues(true);
  522. display_obj.tft.setTextWrap(false);
  523. display_obj.tft.setTextColor(TFT_BLACK, color);
  524. display_obj.tft.fillRect(0,16,240,16, color);
  525. display_obj.tft.drawCentreString(" Deauthentication Sniffer ",120,16,2);
  526. display_obj.touchToExit();
  527. display_obj.tft.setTextColor(TFT_RED, TFT_BLACK);
  528. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  529. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  530. esp_wifi_init(&cfg);
  531. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  532. esp_wifi_set_mode(WIFI_MODE_NULL);
  533. esp_wifi_start();
  534. esp_wifi_set_promiscuous(true);
  535. esp_wifi_set_promiscuous_filter(&filt);
  536. esp_wifi_set_promiscuous_rx_cb(&deauthSnifferCallback);
  537. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  538. initTime = millis();
  539. }
  540. // Function for running probe request scan
  541. void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color)
  542. {
  543. sd_obj.openCapture("probe");
  544. display_obj.TOP_FIXED_AREA_2 = 48;
  545. display_obj.tteBar = true;
  546. display_obj.print_delay_1 = 15;
  547. display_obj.print_delay_2 = 10;
  548. //display_obj.clearScreen();
  549. display_obj.initScrollValues(true);
  550. display_obj.tft.setTextWrap(false);
  551. display_obj.tft.setTextColor(TFT_BLACK, color);
  552. display_obj.tft.fillRect(0,16,240,16, color);
  553. display_obj.tft.drawCentreString(" Probe Request Sniffer ",120,16,2);
  554. display_obj.touchToExit();
  555. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  556. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  557. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  558. esp_wifi_init(&cfg);
  559. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  560. esp_wifi_set_mode(WIFI_MODE_NULL);
  561. esp_wifi_start();
  562. esp_wifi_set_promiscuous(true);
  563. esp_wifi_set_promiscuous_filter(&filt);
  564. esp_wifi_set_promiscuous_rx_cb(&probeSnifferCallback);
  565. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  566. initTime = millis();
  567. }
  568. // Function to start running any BLE scan
  569. void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color)
  570. {
  571. display_obj.print_delay_1 = 50;
  572. display_obj.print_delay_2 = 20;
  573. /*
  574. esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
  575. esp_err_t init_ret = esp_bt_controller_init(&bt_cfg);
  576. if (init_ret != ESP_OK)
  577. Serial.println("Could not initialize BT Controller: " + (String)init_ret);
  578. //esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT);
  579. //esp_bt_controller_disable();
  580. esp_err_t ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
  581. if (ret != ESP_OK)
  582. Serial.println("Could not enable BT Controller: " + (String)ret);
  583. Serial.println("BT Controller Status: " + (String)esp_bt_controller_get_status());
  584. */
  585. BLEDevice::init("");
  586. pBLEScan = BLEDevice::getScan(); //create new scan
  587. if (scan_mode == BT_SCAN_ALL)
  588. {
  589. display_obj.TOP_FIXED_AREA_2 = 48;
  590. display_obj.tteBar = true;
  591. //display_obj.clearScreen();
  592. display_obj.initScrollValues(true);
  593. display_obj.tft.setTextWrap(false);
  594. display_obj.tft.setTextColor(TFT_BLACK, color);
  595. display_obj.tft.fillRect(0,16,240,16, color);
  596. display_obj.tft.drawCentreString(" Bluetooth Sniff ",120,16,2);
  597. display_obj.touchToExit();
  598. display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
  599. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  600. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback());
  601. //bluetoothScanAllCallback myCallbacks;
  602. //pBLEScan->setAdvertisedDeviceCallbacks(&myCallbacks);
  603. }
  604. else if (scan_mode == BT_SCAN_SKIMMERS)
  605. {
  606. display_obj.TOP_FIXED_AREA_2 = 160;
  607. display_obj.tteBar = true;
  608. //display_obj.clearScreen();
  609. display_obj.tft.fillScreen(TFT_DARKGREY);
  610. display_obj.initScrollValues(true);
  611. display_obj.tft.setTextWrap(false);
  612. display_obj.tft.setTextColor(TFT_BLACK, color);
  613. display_obj.tft.fillRect(0,16,240,16, color);
  614. display_obj.tft.drawCentreString(" Detect Card Skimmers ",120,16,2);
  615. display_obj.twoPartDisplay("Scanning for\nBluetooth-enabled skimmers\nHC-03, HC-05, and HC-06...");
  616. display_obj.tft.setTextColor(TFT_BLACK, TFT_DARKGREY);
  617. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  618. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanSkimmersCallback());
  619. }
  620. pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  621. pBLEScan->setInterval(100);
  622. pBLEScan->setWindow(99); // less or equal setInterval value
  623. pBLEScan->start(0, scanCompleteCB);
  624. Serial.println("Started BLE Scan");
  625. initTime = millis();
  626. }
  627. // Function that is called when BLE scan is completed
  628. void WiFiScan::scanCompleteCB(BLEScanResults scanResults) {
  629. printf("Scan complete!\n");
  630. printf("Found %d devices\n", scanResults.getCount());
  631. scanResults.dump();
  632. } // scanCompleteCB
  633. // Function to extract MAC addr from a packet at given offset
  634. void WiFiScan::getMAC(char *addr, uint8_t* data, uint16_t offset) {
  635. sprintf(addr, "%02x:%02x:%02x:%02x:%02x:%02x", data[offset+0], data[offset+1], data[offset+2], data[offset+3], data[offset+4], data[offset+5]);
  636. }
  637. void WiFiScan::espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  638. {
  639. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  640. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  641. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  642. int len = snifferPacket->rx_ctrl.sig_len;
  643. String display_string = "";
  644. String src_addr_string = "";
  645. if (type == WIFI_PKT_MGMT)
  646. {
  647. len -= 4;
  648. }
  649. int fctl = ntohs(frameControl->fctl);
  650. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  651. const WifiMgmtHdr *hdr = &ipkt->hdr;
  652. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  653. //if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  654. //{
  655. char addr[] = "00:00:00:00:00:00";
  656. getMAC(addr, snifferPacket->payload, 10);
  657. src_addr_string.concat(addr);
  658. bool match = false;
  659. for (int i = 0; i < (sizeof(espressif_macs) / sizeof(espressif_macs[0])); i++) {
  660. if (src_addr_string.startsWith(espressif_macs[i])) {
  661. match = true;
  662. break;
  663. }
  664. }
  665. if (!match)
  666. return;
  667. delay(random(0, 10));
  668. Serial.print("RSSI: ");
  669. Serial.print(snifferPacket->rx_ctrl.rssi);
  670. Serial.print(" Ch: ");
  671. Serial.print(snifferPacket->rx_ctrl.channel);
  672. Serial.print(" BSSID: ");
  673. Serial.print(addr);
  674. //display_string.concat(" RSSI: ");
  675. //display_string.concat(snifferPacket->rx_ctrl.rssi);
  676. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  677. //display_string.concat(" ");
  678. display_string.concat(" -> ");
  679. display_string.concat(addr);
  680. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  681. {
  682. display_string.concat(" ");
  683. }
  684. Serial.print(" ");
  685. //if (display_obj.display_buffer->size() == 0)
  686. //{
  687. display_obj.loading = true;
  688. display_obj.display_buffer->add(display_string);
  689. display_obj.loading = false;
  690. //}
  691. Serial.println();
  692. sd_obj.addPacket(snifferPacket->payload, len);
  693. //}
  694. }
  695. void WiFiScan::pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  696. {
  697. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  698. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  699. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  700. int len = snifferPacket->rx_ctrl.sig_len;
  701. String display_string = "";
  702. String src = "";
  703. String essid = "";
  704. if (type == WIFI_PKT_MGMT)
  705. {
  706. len -= 4;
  707. int fctl = ntohs(frameControl->fctl);
  708. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  709. const WifiMgmtHdr *hdr = &ipkt->hdr;
  710. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  711. if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  712. {
  713. char addr[] = "00:00:00:00:00:00";
  714. getMAC(addr, snifferPacket->payload, 10);
  715. src.concat(addr);
  716. if (src == "de:ad:be:ef:de:ad") {
  717. delay(random(0, 10));
  718. Serial.print("RSSI: ");
  719. Serial.print(snifferPacket->rx_ctrl.rssi);
  720. Serial.print(" Ch: ");
  721. Serial.print(snifferPacket->rx_ctrl.channel);
  722. Serial.print(" BSSID: ");
  723. Serial.print(addr);
  724. //display_string.concat(addr);
  725. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  726. Serial.print(" ESSID: ");
  727. display_string.concat(" -> ");
  728. // Just grab the first 255 bytes of the pwnagotchi beacon
  729. // because that is where the name is
  730. //for (int i = 0; i < snifferPacket->payload[37]; i++)
  731. for (int i = 0; i < len - 37; i++)
  732. {
  733. Serial.print((char)snifferPacket->payload[i + 38]);
  734. //display_string.concat((char)snifferPacket->payload[i + 38]);
  735. if (isAscii(snifferPacket->payload[i + 38]))
  736. essid.concat((char)snifferPacket->payload[i + 38]);
  737. else
  738. Serial.println("Got non-ascii character: " + (String)(char)snifferPacket->payload[i + 38]);
  739. }
  740. //essid.concat("\": \"\"}}");
  741. //Serial.println("\n" + (String)(snifferPacket->payload[37]) + " -> " + essid);
  742. // Load json
  743. DynamicJsonBuffer jsonBuffer;
  744. JsonObject& json = jsonBuffer.parseObject(essid);
  745. if (!json.success()) {
  746. Serial.println("\nCould not parse Pwnagotchi json");
  747. display_string.concat(essid);
  748. }
  749. else {
  750. Serial.println("\nSuccessfully parsed json");
  751. String json_output;
  752. json.printTo(json_output);
  753. Serial.println(json_output);
  754. display_string.concat(json["name"].as<String>() + " pwnd: " + json["pwnd_tot"].as<String>());
  755. }
  756. int temp_len = display_string.length();
  757. for (int i = 0; i < 40 - temp_len; i++)
  758. {
  759. display_string.concat(" ");
  760. }
  761. Serial.print(" ");
  762. if (display_obj.display_buffer->size() == 0)
  763. {
  764. display_obj.loading = true;
  765. display_obj.display_buffer->add(display_string);
  766. display_obj.loading = false;
  767. }
  768. Serial.println();
  769. sd_obj.addPacket(snifferPacket->payload, len);
  770. }
  771. }
  772. }
  773. }
  774. void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  775. {
  776. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  777. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  778. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  779. int len = snifferPacket->rx_ctrl.sig_len;
  780. String display_string = "";
  781. if (type == WIFI_PKT_MGMT)
  782. {
  783. len -= 4;
  784. int fctl = ntohs(frameControl->fctl);
  785. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  786. const WifiMgmtHdr *hdr = &ipkt->hdr;
  787. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  788. if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  789. {
  790. delay(random(0, 10));
  791. Serial.print("RSSI: ");
  792. Serial.print(snifferPacket->rx_ctrl.rssi);
  793. Serial.print(" Ch: ");
  794. Serial.print(snifferPacket->rx_ctrl.channel);
  795. Serial.print(" BSSID: ");
  796. char addr[] = "00:00:00:00:00:00";
  797. getMAC(addr, snifferPacket->payload, 10);
  798. Serial.print(addr);
  799. display_string.concat(addr);
  800. Serial.print(" ESSID: ");
  801. display_string.concat(" -> ");
  802. for (int i = 0; i < snifferPacket->payload[37]; i++)
  803. {
  804. Serial.print((char)snifferPacket->payload[i + 38]);
  805. display_string.concat((char)snifferPacket->payload[i + 38]);
  806. }
  807. int temp_len = display_string.length();
  808. for (int i = 0; i < 40 - temp_len; i++)
  809. {
  810. display_string.concat(" ");
  811. }
  812. Serial.print(" ");
  813. if (display_obj.display_buffer->size() == 0)
  814. {
  815. display_obj.loading = true;
  816. display_obj.display_buffer->add(display_string);
  817. display_obj.loading = false;
  818. }
  819. Serial.println();
  820. sd_obj.addPacket(snifferPacket->payload, len);
  821. }
  822. }
  823. }
  824. void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  825. {
  826. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  827. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  828. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  829. int len = snifferPacket->rx_ctrl.sig_len;
  830. String display_string = "";
  831. if (type == WIFI_PKT_MGMT)
  832. {
  833. len -= 4;
  834. int fctl = ntohs(frameControl->fctl);
  835. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  836. const WifiMgmtHdr *hdr = &ipkt->hdr;
  837. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  838. if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ) && (display_obj.display_buffer->size() == 0))
  839. {
  840. delay(random(0, 10));
  841. Serial.print("RSSI: ");
  842. Serial.print(snifferPacket->rx_ctrl.rssi);
  843. Serial.print(" Ch: ");
  844. Serial.print(snifferPacket->rx_ctrl.channel);
  845. Serial.print(" BSSID: ");
  846. char addr[] = "00:00:00:00:00:00";
  847. getMAC(addr, snifferPacket->payload, 10);
  848. Serial.print(addr);
  849. display_string.concat(" RSSI: ");
  850. display_string.concat(snifferPacket->rx_ctrl.rssi);
  851. display_string.concat(" ");
  852. display_string.concat(addr);
  853. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  854. {
  855. display_string.concat(" ");
  856. }
  857. Serial.print(" ");
  858. if (display_obj.display_buffer->size() == 0)
  859. {
  860. display_obj.loading = true;
  861. display_obj.display_buffer->add(display_string);
  862. display_obj.loading = false;
  863. }
  864. Serial.println();
  865. sd_obj.addPacket(snifferPacket->payload, len);
  866. }
  867. }
  868. }
  869. void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  870. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  871. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  872. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  873. int len = snifferPacket->rx_ctrl.sig_len;
  874. String display_string = "";
  875. if (type == WIFI_PKT_MGMT)
  876. {
  877. len -= 4;
  878. int fctl = ntohs(frameControl->fctl);
  879. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  880. const WifiMgmtHdr *hdr = &ipkt->hdr;
  881. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  882. if ((snifferPacket->payload[0] == 0x40) && (display_obj.display_buffer->size() == 0))
  883. {
  884. delay(random(0, 10));
  885. Serial.print("RSSI: ");
  886. Serial.print(snifferPacket->rx_ctrl.rssi);
  887. Serial.print(" Ch: ");
  888. Serial.print(snifferPacket->rx_ctrl.channel);
  889. Serial.print(" Client: ");
  890. char addr[] = "00:00:00:00:00:00";
  891. getMAC(addr, snifferPacket->payload, 10);
  892. Serial.print(addr);
  893. display_string.concat(addr);
  894. Serial.print(" Requesting: ");
  895. display_string.concat(" -> ");
  896. for (int i = 0; i < snifferPacket->payload[25]; i++)
  897. {
  898. Serial.print((char)snifferPacket->payload[26 + i]);
  899. display_string.concat((char)snifferPacket->payload[26 + i]);
  900. }
  901. // Print spaces because of the rotating lines of the hardware scroll.
  902. // The same characters print from previous lines so I just overwrite them
  903. // with spaces.
  904. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  905. {
  906. display_string.concat(" ");
  907. }
  908. if (display_obj.display_buffer->size() == 0)
  909. {
  910. //while (display_obj.printing)
  911. // delay(1);
  912. display_obj.loading = true;
  913. display_obj.display_buffer->add(display_string);
  914. display_obj.loading = false;
  915. }
  916. Serial.println();
  917. sd_obj.addPacket(snifferPacket->payload, len);
  918. }
  919. }
  920. }
  921. // Function to send beacons with random ESSID length
  922. void WiFiScan::broadcastSetSSID(uint32_t current_time, char* ESSID) {
  923. set_channel = random(1,12);
  924. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  925. delay(1);
  926. // Randomize SRC MAC
  927. packet[10] = packet[16] = random(256);
  928. packet[11] = packet[17] = random(256);
  929. packet[12] = packet[18] = random(256);
  930. packet[13] = packet[19] = random(256);
  931. packet[14] = packet[20] = random(256);
  932. packet[15] = packet[21] = random(256);
  933. /////////////////////////////
  934. //int essid_len = random(6, 10);
  935. // random prefix to beacon essid
  936. //uint8_t rand_reg[essid_len] = {};
  937. //for (int i = 0; i < essid_len; i++)
  938. // rand_reg[i] = alfa[random(65)];
  939. int ssidLen = strlen(ESSID);
  940. //int rand_len = sizeof(rand_reg);
  941. int fullLen = ssidLen;
  942. packet[37] = fullLen;
  943. // Insert random prefix
  944. //for (int i = 0; i < rand_len; i++)
  945. // packet[38+i] = rand_reg[i];
  946. // Insert my tag
  947. for(int i = 0; i < ssidLen; i++)
  948. packet[38 + i] = ESSID[i];
  949. /////////////////////////////
  950. packet[50 + fullLen] = set_channel;
  951. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  952. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  953. // Add everything that goes after the SSID
  954. for(int i = 0; i < 12; i++)
  955. packet[38 + fullLen + i] = postSSID[i];
  956. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  957. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  958. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  959. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  960. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  961. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  962. packets_sent = packets_sent + 3;
  963. }
  964. // Function for sending crafted beacon frames
  965. void WiFiScan::broadcastRandomSSID(uint32_t currentTime) {
  966. set_channel = random(1,12);
  967. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  968. delay(1);
  969. // Randomize SRC MAC
  970. packet[10] = packet[16] = random(256);
  971. packet[11] = packet[17] = random(256);
  972. packet[12] = packet[18] = random(256);
  973. packet[13] = packet[19] = random(256);
  974. packet[14] = packet[20] = random(256);
  975. packet[15] = packet[21] = random(256);
  976. packet[37] = 6;
  977. // Randomize SSID (Fixed size 6. Lazy right?)
  978. packet[38] = alfa[random(65)];
  979. packet[39] = alfa[random(65)];
  980. packet[40] = alfa[random(65)];
  981. packet[41] = alfa[random(65)];
  982. packet[42] = alfa[random(65)];
  983. packet[43] = alfa[random(65)];
  984. packet[56] = set_channel;
  985. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  986. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  987. // Add everything that goes after the SSID
  988. for(int i = 0; i < 12; i++)
  989. packet[38 + 6 + i] = postSSID[i];
  990. //Serial.println("About to send packets...");
  991. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  992. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  993. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  994. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  995. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  996. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  997. packets_sent = packets_sent + 3;
  998. //Serial.print("Packets sent: ");
  999. //Serial.println(packets_sent);
  1000. //Serial.println("Sent packets");
  1001. }
  1002. void WiFiScan::wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1003. {
  1004. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1005. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1006. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1007. int len = snifferPacket->rx_ctrl.sig_len;
  1008. if (type == WIFI_PKT_MGMT)
  1009. {
  1010. len -= 4;
  1011. int fctl = ntohs(frameControl->fctl);
  1012. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1013. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1014. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1015. if (snifferPacket->payload[0] == 0x80)
  1016. {
  1017. num_beacon++;
  1018. }
  1019. else if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ))
  1020. {
  1021. num_deauth++;
  1022. }
  1023. else if (snifferPacket->payload[0] == 0x40)
  1024. {
  1025. num_probe++;
  1026. }
  1027. sd_obj.addPacket(snifferPacket->payload, len);
  1028. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) ))
  1029. Serial.println("Oh god mgmt EAPOL");
  1030. }
  1031. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  1032. Serial.println("EAPOL!!");
  1033. //sd_obj.addPacket(snifferPacket->payload, len);
  1034. }
  1035. }
  1036. void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1037. {
  1038. /*
  1039. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1040. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1041. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1042. int len = snifferPacket->rx_ctrl.sig_len;
  1043. String display_string = "";
  1044. if (type == WIFI_PKT_MGMT)
  1045. {
  1046. len -= 4;
  1047. int fctl = ntohs(frameControl->fctl);
  1048. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1049. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1050. }
  1051. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  1052. delay(random(0, 10));
  1053. Serial.print((String)random(0, 5) + "EAPOL: ");
  1054. char srcaddr[] = "00:00:00:00:00:00";
  1055. getMAC(srcaddr, snifferPacket->payload, 10);
  1056. Serial.print(srcaddr);
  1057. display_string.concat(srcaddr);
  1058. Serial.print(" -> ");
  1059. display_string.concat(" -> ");
  1060. char desaddr[] = "00:00:00:00:00:00";
  1061. getMAC(desaddr, snifferPacket->payload, 4);
  1062. Serial.print(desaddr);
  1063. display_string.concat(desaddr);
  1064. // Print spaces because of the rotating lines of the hardware scroll.
  1065. // The same characters print from previous lines so I just overwrite them
  1066. // with spaces.
  1067. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  1068. {
  1069. display_string.concat(" ");
  1070. }
  1071. if (display_obj.display_buffer->size() == 0)
  1072. {
  1073. //while (display_obj.printing)
  1074. // delay(1);
  1075. display_obj.loading = true;
  1076. display_obj.display_buffer->add(display_string);
  1077. display_obj.loading = false;
  1078. }
  1079. Serial.println();
  1080. sd_obj.addPacket(snifferPacket->payload, len);
  1081. }
  1082. */
  1083. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1084. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1085. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1086. int len = snifferPacket->rx_ctrl.sig_len;
  1087. if (len == 173) {
  1088. Serial.println("Maybe the PMKID");
  1089. //sd_obj.addPacket(snifferPacket->payload, len);
  1090. }
  1091. if (type == WIFI_PKT_MGMT)
  1092. {
  1093. len -= 4;
  1094. int fctl = ntohs(frameControl->fctl);
  1095. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1096. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1097. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1098. /*
  1099. if (snifferPacket->payload[0] == 0x80)
  1100. {
  1101. num_beacon++;
  1102. }
  1103. else if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ))
  1104. {
  1105. num_deauth++;
  1106. }
  1107. else if (snifferPacket->payload[0] == 0x40)
  1108. {
  1109. num_probe++;
  1110. }
  1111. */
  1112. //sd_obj.addPacket(snifferPacket->payload, len);
  1113. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) ))
  1114. Serial.println("Oh god mgmt EAPOL");
  1115. }
  1116. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  1117. Serial.println("EAPOL!!");
  1118. //sd_obj.addPacket(snifferPacket->payload, len);
  1119. num_eapol++;
  1120. }
  1121. sd_obj.addPacket(snifferPacket->payload, len);
  1122. }
  1123. void WiFiScan::eapolMonitorMain(uint32_t currentTime)
  1124. {
  1125. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  1126. // for (x_pos = (11 + x_scale); x_pos <= 320; x_pos += x_scale) //go along every point on the x axis and do something, start over when finished
  1127. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  1128. {
  1129. currentTime = millis();
  1130. do_break = false;
  1131. y_pos_x = 0;
  1132. y_pos_y = 0;
  1133. y_pos_z = 0;
  1134. boolean pressed = false;
  1135. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  1136. // Do the touch stuff
  1137. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  1138. if (pressed) {
  1139. Serial.print("Got touch | X: ");
  1140. Serial.print(t_x);
  1141. Serial.print(" Y: ");
  1142. Serial.println(t_y);
  1143. }
  1144. // Check buttons for presses
  1145. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1146. {
  1147. if (pressed && display_obj.key[b].contains(t_x, t_y))
  1148. {
  1149. display_obj.key[b].press(true);
  1150. } else {
  1151. display_obj.key[b].press(false);
  1152. }
  1153. }
  1154. // Which buttons pressed
  1155. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1156. {
  1157. if (display_obj.key[b].justPressed())
  1158. {
  1159. Serial.println("Bro, key pressed");
  1160. //do_break = true;
  1161. }
  1162. if (display_obj.key[b].justReleased())
  1163. {
  1164. do_break = true;
  1165. /*
  1166. // X - button pressed
  1167. if (b == 0) {
  1168. if (x_scale > 1) {
  1169. x_scale--;
  1170. delay(70);
  1171. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1172. display_obj.tftDrawXScaleButtons(x_scale);
  1173. display_obj.tftDrawYScaleButtons(y_scale);
  1174. display_obj.tftDrawChannelScaleButtons(set_channel);
  1175. display_obj.tftDrawExitScaleButtons();
  1176. break;
  1177. }
  1178. }
  1179. // X + button pressed
  1180. else if (b == 1) {
  1181. if (x_scale < 6) {
  1182. x_scale++;
  1183. delay(70);
  1184. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1185. display_obj.tftDrawXScaleButtons(x_scale);
  1186. display_obj.tftDrawYScaleButtons(y_scale);
  1187. display_obj.tftDrawChannelScaleButtons(set_channel);
  1188. display_obj.tftDrawExitScaleButtons();
  1189. break;
  1190. }
  1191. }
  1192. // Y - button pressed
  1193. else if (b == 2) {
  1194. if (y_scale > 1) {
  1195. y_scale--;
  1196. delay(70);
  1197. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1198. display_obj.tftDrawXScaleButtons(x_scale);
  1199. display_obj.tftDrawYScaleButtons(y_scale);
  1200. display_obj.tftDrawChannelScaleButtons(set_channel);
  1201. display_obj.tftDrawExitScaleButtons();
  1202. //updateMidway();
  1203. break;
  1204. }
  1205. }
  1206. // Y + button pressed
  1207. else if (b == 3) {
  1208. if (y_scale < 9) {
  1209. y_scale++;
  1210. delay(70);
  1211. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1212. display_obj.tftDrawXScaleButtons(x_scale);
  1213. display_obj.tftDrawYScaleButtons(y_scale);
  1214. display_obj.tftDrawChannelScaleButtons(set_channel);
  1215. display_obj.tftDrawExitScaleButtons();
  1216. //updateMidway();
  1217. break;
  1218. }
  1219. }*/
  1220. // Channel - button pressed
  1221. //else if (b == 4) {
  1222. if (b == 4) {
  1223. if (set_channel > 1) {
  1224. Serial.println("Shit channel down");
  1225. set_channel--;
  1226. delay(70);
  1227. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1228. //display_obj.tftDrawXScaleButtons(x_scale);
  1229. //display_obj.tftDrawYScaleButtons(y_scale);
  1230. display_obj.tftDrawChannelScaleButtons(set_channel);
  1231. display_obj.tftDrawExitScaleButtons();
  1232. changeChannel();
  1233. break;
  1234. }
  1235. }
  1236. // Channel + button pressed
  1237. else if (b == 5) {
  1238. if (set_channel < MAX_CHANNEL) {
  1239. Serial.println("Shit channel up");
  1240. set_channel++;
  1241. delay(70);
  1242. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1243. //display_obj.tftDrawXScaleButtons(x_scale);
  1244. //display_obj.tftDrawYScaleButtons(y_scale);
  1245. display_obj.tftDrawChannelScaleButtons(set_channel);
  1246. display_obj.tftDrawExitScaleButtons();
  1247. changeChannel();
  1248. break;
  1249. }
  1250. }
  1251. else if (b == 6) {
  1252. Serial.println("Exiting packet monitor...");
  1253. this->StartScan(WIFI_SCAN_OFF);
  1254. //display_obj.tft.init();
  1255. this->orient_display = true;
  1256. return;
  1257. }
  1258. }
  1259. }
  1260. if (currentTime - initTime >= (GRAPH_REFRESH * 5)) {
  1261. //Serial.println("-----------------------------------------");
  1262. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  1263. x_pos += x_scale;
  1264. initTime = millis();
  1265. y_pos_x = ((-num_eapol * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  1266. if (y_pos_x >= HEIGHT_1) {
  1267. Serial.println("Max EAPOL number reached. Adjusting...");
  1268. num_eapol = 0;
  1269. }
  1270. //y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  1271. //y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  1272. //Serial.println("num_beacon: " + (String)num_beacon);
  1273. //Serial.println("num_deauth: " + (String)num_deauth);
  1274. //Serial.println(" num_probe: " + (String)num_probe);
  1275. //num_beacon = 0;
  1276. //num_probe = 0;
  1277. //num_deauth = 0;
  1278. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  1279. //Plot "X" value
  1280. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_CYAN);
  1281. //Plot "Z" value
  1282. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  1283. //Plot "Y" value
  1284. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  1285. //Draw preceding black 'boxes' to erase old plot lines, !!!WEIRD CODE TO COMPENSATE FOR BUTTONS AND COLOR KEY SO 'ERASER' DOESN'T ERASE BUTTONS AND COLOR KEY!!!
  1286. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  1287. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  1288. {
  1289. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  1290. }
  1291. else
  1292. {
  1293. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  1294. }
  1295. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  1296. //if (x_pos <= 90)
  1297. if (x_pos < 0) // below x axis
  1298. {
  1299. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  1300. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  1301. }
  1302. else
  1303. {
  1304. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  1305. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  1306. }
  1307. //tftDisplayTime();
  1308. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  1309. {
  1310. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  1311. }
  1312. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  1313. //y_pos_y_old = y_pos_y;
  1314. //y_pos_z_old = y_pos_z;
  1315. //delay(50);
  1316. }
  1317. sd_obj.main();
  1318. }
  1319. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  1320. //tft.fillRect(56, 0, 66, 32, TFT_ORANGE); //erase time and color key and any stray lines behind them
  1321. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  1322. //display_obj.tftDrawXScaleButtons(x_scale); //redraw stuff
  1323. //display_obj.tftDrawYScaleButtons(y_scale);
  1324. display_obj.tftDrawChannelScaleButtons(set_channel);
  1325. display_obj.tftDrawExitScaleButtons();
  1326. display_obj.tftDrawEapolColorKey();
  1327. display_obj.tftDrawGraphObjects(x_scale);
  1328. }
  1329. void WiFiScan::packetMonitorMain(uint32_t currentTime)
  1330. {
  1331. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  1332. // for (x_pos = (11 + x_scale); x_pos <= 320; x_pos += x_scale) //go along every point on the x axis and do something, start over when finished
  1333. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  1334. {
  1335. currentTime = millis();
  1336. do_break = false;
  1337. y_pos_x = 0;
  1338. y_pos_y = 0;
  1339. y_pos_z = 0;
  1340. boolean pressed = false;
  1341. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  1342. // Do the touch stuff
  1343. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  1344. if (pressed) {
  1345. Serial.print("Got touch | X: ");
  1346. Serial.print(t_x);
  1347. Serial.print(" Y: ");
  1348. Serial.println(t_y);
  1349. }
  1350. // Check buttons for presses
  1351. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1352. {
  1353. if (pressed && display_obj.key[b].contains(t_x, t_y))
  1354. {
  1355. display_obj.key[b].press(true);
  1356. } else {
  1357. display_obj.key[b].press(false);
  1358. }
  1359. }
  1360. // Which buttons pressed
  1361. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1362. {
  1363. if (display_obj.key[b].justPressed())
  1364. {
  1365. Serial.println("Bro, key pressed");
  1366. //do_break = true;
  1367. }
  1368. if (display_obj.key[b].justReleased())
  1369. {
  1370. do_break = true;
  1371. // X - button pressed
  1372. if (b == 0) {
  1373. if (x_scale > 1) {
  1374. x_scale--;
  1375. delay(70);
  1376. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1377. display_obj.tftDrawXScaleButtons(x_scale);
  1378. display_obj.tftDrawYScaleButtons(y_scale);
  1379. display_obj.tftDrawChannelScaleButtons(set_channel);
  1380. display_obj.tftDrawExitScaleButtons();
  1381. break;
  1382. }
  1383. }
  1384. // X + button pressed
  1385. else if (b == 1) {
  1386. if (x_scale < 6) {
  1387. x_scale++;
  1388. delay(70);
  1389. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1390. display_obj.tftDrawXScaleButtons(x_scale);
  1391. display_obj.tftDrawYScaleButtons(y_scale);
  1392. display_obj.tftDrawChannelScaleButtons(set_channel);
  1393. display_obj.tftDrawExitScaleButtons();
  1394. break;
  1395. }
  1396. }
  1397. // Y - button pressed
  1398. else if (b == 2) {
  1399. if (y_scale > 1) {
  1400. y_scale--;
  1401. delay(70);
  1402. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1403. display_obj.tftDrawXScaleButtons(x_scale);
  1404. display_obj.tftDrawYScaleButtons(y_scale);
  1405. display_obj.tftDrawChannelScaleButtons(set_channel);
  1406. display_obj.tftDrawExitScaleButtons();
  1407. //updateMidway();
  1408. break;
  1409. }
  1410. }
  1411. // Y + button pressed
  1412. else if (b == 3) {
  1413. if (y_scale < 9) {
  1414. y_scale++;
  1415. delay(70);
  1416. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1417. display_obj.tftDrawXScaleButtons(x_scale);
  1418. display_obj.tftDrawYScaleButtons(y_scale);
  1419. display_obj.tftDrawChannelScaleButtons(set_channel);
  1420. display_obj.tftDrawExitScaleButtons();
  1421. //updateMidway();
  1422. break;
  1423. }
  1424. }
  1425. // Channel - button pressed
  1426. else if (b == 4) {
  1427. if (set_channel > 1) {
  1428. Serial.println("Shit channel down");
  1429. set_channel--;
  1430. delay(70);
  1431. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1432. display_obj.tftDrawXScaleButtons(x_scale);
  1433. display_obj.tftDrawYScaleButtons(y_scale);
  1434. display_obj.tftDrawChannelScaleButtons(set_channel);
  1435. display_obj.tftDrawExitScaleButtons();
  1436. changeChannel();
  1437. break;
  1438. }
  1439. }
  1440. // Channel + button pressed
  1441. else if (b == 5) {
  1442. if (set_channel < MAX_CHANNEL) {
  1443. Serial.println("Shit channel up");
  1444. set_channel++;
  1445. delay(70);
  1446. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1447. display_obj.tftDrawXScaleButtons(x_scale);
  1448. display_obj.tftDrawYScaleButtons(y_scale);
  1449. display_obj.tftDrawChannelScaleButtons(set_channel);
  1450. display_obj.tftDrawExitScaleButtons();
  1451. changeChannel();
  1452. break;
  1453. }
  1454. }
  1455. else if (b == 6) {
  1456. Serial.println("Exiting packet monitor...");
  1457. this->StartScan(WIFI_SCAN_OFF);
  1458. //display_obj.tft.init();
  1459. this->orient_display = true;
  1460. return;
  1461. }
  1462. }
  1463. }
  1464. if (currentTime - initTime >= GRAPH_REFRESH) {
  1465. //Serial.println("-----------------------------------------");
  1466. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  1467. x_pos += x_scale;
  1468. initTime = millis();
  1469. y_pos_x = ((-num_beacon * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  1470. y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  1471. y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  1472. //Serial.println("num_beacon: " + (String)num_beacon);
  1473. //Serial.println("num_deauth: " + (String)num_deauth);
  1474. //Serial.println(" num_probe: " + (String)num_probe);
  1475. num_beacon = 0;
  1476. num_probe = 0;
  1477. num_deauth = 0;
  1478. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  1479. //Plot "X" value
  1480. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_GREEN);
  1481. //Plot "Z" value
  1482. display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  1483. //Plot "Y" value
  1484. display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  1485. //Draw preceding black 'boxes' to erase old plot lines, !!!WEIRD CODE TO COMPENSATE FOR BUTTONS AND COLOR KEY SO 'ERASER' DOESN'T ERASE BUTTONS AND COLOR KEY!!!
  1486. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  1487. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  1488. {
  1489. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  1490. }
  1491. else
  1492. {
  1493. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  1494. }
  1495. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  1496. //if (x_pos <= 90)
  1497. if (x_pos < 0) // below x axis
  1498. {
  1499. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  1500. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  1501. }
  1502. else
  1503. {
  1504. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  1505. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  1506. }
  1507. //tftDisplayTime();
  1508. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  1509. {
  1510. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  1511. }
  1512. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  1513. y_pos_y_old = y_pos_y;
  1514. y_pos_z_old = y_pos_z;
  1515. //delay(50);
  1516. }
  1517. sd_obj.main();
  1518. }
  1519. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  1520. //tft.fillRect(56, 0, 66, 32, TFT_ORANGE); //erase time and color key and any stray lines behind them
  1521. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  1522. display_obj.tftDrawXScaleButtons(x_scale); //redraw stuff
  1523. display_obj.tftDrawYScaleButtons(y_scale);
  1524. display_obj.tftDrawChannelScaleButtons(set_channel);
  1525. display_obj.tftDrawExitScaleButtons();
  1526. display_obj.tftDrawColorKey();
  1527. display_obj.tftDrawGraphObjects(x_scale);
  1528. }
  1529. //void WiFiScan::sniffer_callback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1530. // wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1531. // showMetadata(snifferPacket, type);
  1532. //}
  1533. void WiFiScan::changeChannel()
  1534. {
  1535. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1536. delay(1);
  1537. }
  1538. // Function to cycle to the next channel
  1539. void WiFiScan::channelHop()
  1540. {
  1541. set_channel = set_channel + 1;
  1542. if (set_channel > 13) {
  1543. set_channel = 1;
  1544. }
  1545. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1546. delay(1);
  1547. }
  1548. // Function for updating scan status
  1549. void WiFiScan::main(uint32_t currentTime)
  1550. {
  1551. // WiFi operations
  1552. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  1553. (currentScanMode == WIFI_SCAN_AP) ||
  1554. (currentScanMode == WIFI_SCAN_PWN) ||
  1555. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  1556. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  1557. (currentScanMode == WIFI_SCAN_ALL))
  1558. {
  1559. if (currentTime - initTime >= 1000)
  1560. {
  1561. initTime = millis();
  1562. channelHop();
  1563. }
  1564. }
  1565. else if (currentScanMode == WIFI_PACKET_MONITOR)
  1566. {
  1567. packetMonitorMain(currentTime);
  1568. }
  1569. else if (currentScanMode == WIFI_SCAN_EAPOL)
  1570. {
  1571. eapolMonitorMain(currentTime);
  1572. }
  1573. else if ((currentScanMode == WIFI_ATTACK_BEACON_SPAM))
  1574. {
  1575. // Need this for loop because getTouch causes ~10ms delay
  1576. // which makes beacon spam less effective
  1577. for (int i = 0; i < 55; i++)
  1578. broadcastRandomSSID(currentTime);
  1579. if (currentTime - initTime >= 1000)
  1580. {
  1581. initTime = millis();
  1582. //Serial.print("packets/sec: ");
  1583. //Serial.println(packets_sent);
  1584. String displayString = "";
  1585. String displayString2 = "";
  1586. displayString.concat("packets/sec: ");
  1587. displayString.concat(packets_sent);
  1588. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  1589. displayString2.concat(" ");
  1590. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1591. display_obj.showCenterText(displayString2, 160);
  1592. display_obj.showCenterText(displayString, 160);
  1593. packets_sent = 0;
  1594. }
  1595. }
  1596. else if ((currentScanMode == WIFI_ATTACK_RICK_ROLL))
  1597. {
  1598. // Need this for loop because getTouch causes ~10ms delay
  1599. // which makes beacon spam less effective
  1600. for (int i = 0; i < 7; i++)
  1601. {
  1602. for (int x = 0; x < (sizeof(rick_roll)/sizeof(char *)); x++)
  1603. {
  1604. broadcastSetSSID(currentTime, rick_roll[x]);
  1605. }
  1606. }
  1607. if (currentTime - initTime >= 1000)
  1608. {
  1609. initTime = millis();
  1610. //Serial.print("packets/sec: ");
  1611. //Serial.println(packets_sent);
  1612. String displayString = "";
  1613. String displayString2 = "";
  1614. displayString.concat("packets/sec: ");
  1615. displayString.concat(packets_sent);
  1616. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  1617. displayString2.concat(" ");
  1618. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1619. display_obj.showCenterText(displayString2, 160);
  1620. display_obj.showCenterText(displayString, 160);
  1621. packets_sent = 0;
  1622. }
  1623. }
  1624. //else if (currentScanMode == LV_JOIN_WIFI)
  1625. // lv_task_handler();
  1626. }