WiFiScan.cpp 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097
  1. #include "WiFiScan.h"
  2. //esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  3. //int num_beacon = 0;
  4. int num_beacon = 0;
  5. int num_deauth = 0;
  6. int num_probe = 0;
  7. int num_eapol = 0;
  8. class bluetoothScanAllCallback: public BLEAdvertisedDeviceCallbacks {
  9. /* Original BLE */
  10. //void onResult(BLEAdvertisedDevice advertisedDevice) {
  11. /* NimBLE */
  12. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  13. //advertisedDevice.getScan()->stop();
  14. String display_string = "";
  15. if (display_obj.display_buffer->size() >= 0)
  16. {
  17. display_string.concat(" RSSI: ");
  18. display_string.concat(advertisedDevice->getRSSI());
  19. Serial.print(" RSSI: ");
  20. Serial.print(advertisedDevice->getRSSI());
  21. display_string.concat(" ");
  22. Serial.print(" ");
  23. Serial.print("Device: ");
  24. if(advertisedDevice->getName().length() != 0)
  25. {
  26. display_string.concat(advertisedDevice->getName().c_str());
  27. Serial.print(advertisedDevice->getName().c_str());
  28. }
  29. else
  30. {
  31. display_string.concat(advertisedDevice->getAddress().toString().c_str());
  32. Serial.print(advertisedDevice->getAddress().toString().c_str());
  33. }
  34. uint8_t temp_len = display_string.length();
  35. for (uint8_t i = 0; i < 40 - temp_len; i++)
  36. {
  37. display_string.concat(" ");
  38. }
  39. Serial.println();
  40. while (display_obj.printing)
  41. delay(1);
  42. display_obj.loading = true;
  43. display_obj.display_buffer->add(display_string);
  44. display_obj.loading = false;
  45. }
  46. }
  47. };
  48. class bluetoothScanSkimmersCallback: public BLEAdvertisedDeviceCallbacks {
  49. /* Original BLE */
  50. //void onResult(BLEAdvertisedDevice advertisedDevice) {
  51. /* NimBLE */
  52. void onResult(BLEAdvertisedDevice *advertisedDevice) {
  53. String bad_list[bad_list_length] = {"HC-03", "HC-05", "HC-06"};
  54. if (display_obj.display_buffer->size() >= 0)
  55. {
  56. Serial.print("Device: ");
  57. String display_string = "";
  58. //display_string.concat(" RSSI: ");
  59. //display_string.concat(advertisedDevice.getRSSI());
  60. //display_string.concat(" ");
  61. if(advertisedDevice->getName().length() != 0)
  62. {
  63. //display_string.concat(advertisedDevice.getName().c_str());
  64. Serial.print(advertisedDevice->getName().c_str());
  65. for(uint8_t i = 0; i < bad_list_length; i++)
  66. {
  67. if(strcmp(advertisedDevice->getName().c_str(), bad_list[i].c_str()) == 0)
  68. {
  69. display_string.concat("Potential Skimmer: ");
  70. display_string.concat(" ");
  71. display_string.concat(advertisedDevice->getName().c_str());
  72. uint8_t temp_len = display_string.length();
  73. for (uint8_t i = 0; i < 40 - temp_len; i++)
  74. {
  75. display_string.concat(" ");
  76. }
  77. while (display_obj.printing)
  78. delay(1);
  79. display_obj.loading = true;
  80. display_obj.display_buffer->add(display_string);
  81. display_obj.loading = false;
  82. }
  83. }
  84. }
  85. else
  86. {
  87. Serial.print(advertisedDevice->getAddress().toString().c_str());
  88. //display_string.concat(advertisedDevice.getAddress().toString().c_str());
  89. }
  90. /*
  91. int temp_len = display_string.length();
  92. for (int i = 0; i < 40 - temp_len; i++)
  93. {
  94. display_string.concat(" ");
  95. }
  96. */
  97. Serial.print(" RSSI: ");
  98. Serial.println(advertisedDevice->getRSSI());
  99. /*
  100. while (display_obj.printing)
  101. delay(1);
  102. display_obj.loading = true;
  103. display_obj.display_buffer->add(display_string);
  104. display_obj.loading = false;
  105. */
  106. }
  107. }
  108. };
  109. WiFiScan::WiFiScan()
  110. {
  111. }
  112. void WiFiScan::RunSetup() {
  113. ssids = new LinkedList<ssid>();
  114. BLEDevice::init("");
  115. pBLEScan = BLEDevice::getScan(); //create new scan
  116. this->ble_initialized = true;
  117. this->shutdownBLE();
  118. }
  119. int WiFiScan::clearSSIDs() {
  120. int num_cleared = this->ssids->size();
  121. this->ssids->clear();
  122. Serial.println("ssids: " + (String)this->ssids->size());
  123. return num_cleared;
  124. }
  125. int WiFiScan::generateSSIDs() {
  126. uint8_t num_gen = 20;
  127. for (uint8_t x = 0; x < num_gen; x++) {
  128. String essid = "";
  129. for (uint8_t i = 0; i < 6; i++)
  130. essid.concat(alfa[random(65)]);
  131. ssid s = {essid, {random(256), random(256), random(256), random(256), random(256), random(256)}};
  132. this->ssids->add(s);
  133. Serial.println(this->ssids->get(this->ssids->size() - 1).essid);
  134. }
  135. return num_gen;
  136. }
  137. void WiFiScan::joinWiFi(String ssid, String password)
  138. {
  139. static const char * btns[] ={"Close", ""};
  140. int count = 0;
  141. if ((WiFi.status() == WL_CONNECTED) && (ssid == connected_network) && (ssid != "")) {
  142. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  143. lv_msgbox_set_text(mbox1, "Already Connected");
  144. lv_msgbox_add_btns(mbox1, btns);
  145. lv_obj_set_width(mbox1, 200);
  146. //lv_obj_set_event_cb(mbox1, event_handler);
  147. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  148. this->wifi_initialized = true;
  149. return;
  150. }
  151. else if (WiFi.status() == WL_CONNECTED) {
  152. Serial.println("Already connected. Disconnecting...");
  153. WiFi.disconnect();
  154. }
  155. esp_wifi_init(&cfg);
  156. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  157. esp_wifi_set_mode(WIFI_MODE_NULL);
  158. esp_wifi_start();
  159. WiFi.begin(ssid.c_str(), password.c_str());
  160. Serial.print("Connecting to WiFi");
  161. while (WiFi.status() != WL_CONNECTED) {
  162. delay(500);
  163. Serial.print(".");
  164. count++;
  165. if (count == 10)
  166. {
  167. Serial.println("\nCould not connect to WiFi network");
  168. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  169. lv_msgbox_set_text(mbox1, "Failed to connect");
  170. lv_msgbox_add_btns(mbox1, btns);
  171. lv_obj_set_width(mbox1, 200);
  172. //lv_obj_set_event_cb(mbox1, event_handler);
  173. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  174. WiFi.mode(WIFI_OFF);
  175. return;
  176. }
  177. }
  178. lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
  179. lv_msgbox_set_text(mbox1, "Connected");
  180. lv_msgbox_add_btns(mbox1, btns);
  181. lv_obj_set_width(mbox1, 200);
  182. //lv_obj_set_event_cb(mbox1, event_handler);
  183. lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
  184. connected_network = ssid;
  185. Serial.println("\nConnected to the WiFi network");
  186. Serial.print("IP address: ");
  187. Serial.println(WiFi.localIP());
  188. this->wifi_initialized = true;
  189. }
  190. // Function to prepare to run a specific scan
  191. void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
  192. {
  193. //Serial.println("Starting Scan...");
  194. if (scan_mode == WIFI_SCAN_OFF)
  195. StopScan(scan_mode);
  196. else if (scan_mode == WIFI_SCAN_PROBE)
  197. RunProbeScan(scan_mode, color);
  198. else if (scan_mode == WIFI_SCAN_EAPOL)
  199. RunEapolScan(scan_mode, color);
  200. else if (scan_mode == WIFI_SCAN_AP)
  201. RunBeaconScan(scan_mode, color);
  202. else if (scan_mode == WIFI_SCAN_PWN)
  203. RunPwnScan(scan_mode, color);
  204. else if (scan_mode == WIFI_SCAN_DEAUTH)
  205. RunDeauthScan(scan_mode, color);
  206. else if (scan_mode == WIFI_PACKET_MONITOR)
  207. RunPacketMonitor(scan_mode, color);
  208. else if (scan_mode == WIFI_ATTACK_BEACON_SPAM)
  209. RunBeaconSpam(scan_mode, color);
  210. else if (scan_mode == WIFI_ATTACK_RICK_ROLL)
  211. RunRickRoll(scan_mode, color);
  212. else if (scan_mode == BT_SCAN_ALL)
  213. RunBluetoothScan(scan_mode, color);
  214. else if (scan_mode == BT_SCAN_SKIMMERS)
  215. RunBluetoothScan(scan_mode, color);
  216. else if (scan_mode == WIFI_SCAN_ESPRESSIF)
  217. RunEspressifScan(scan_mode, color);
  218. else if (scan_mode == LV_JOIN_WIFI)
  219. RunLvJoinWiFi(scan_mode, color);
  220. WiFiScan::currentScanMode = scan_mode;
  221. }
  222. bool WiFiScan::shutdownWiFi() {
  223. if (this->wifi_initialized) {
  224. Serial.println("Ahhh yes...promiscuity will end");
  225. esp_wifi_set_promiscuous(false);
  226. //WiFi.persistent(false);
  227. WiFi.disconnect();
  228. WiFi.mode(WIFI_OFF);
  229. esp_wifi_set_mode(WIFI_MODE_NULL);
  230. esp_wifi_stop();
  231. esp_wifi_deinit();
  232. this->wifi_initialized = false;
  233. return true;
  234. }
  235. else {
  236. Serial.println(F("WiFi is not currently running"));
  237. return false;
  238. }
  239. }
  240. bool WiFiScan::shutdownBLE() {
  241. if (this->ble_initialized) {
  242. Serial.println("Stopping BLE scan...");
  243. pBLEScan->stop();
  244. Serial.println("BLE Scan Stopped");
  245. Serial.println("Clearing BLE Results...");
  246. pBLEScan->clearResults();
  247. Serial.println("Deinitializing BT Controller...");
  248. BLEDevice::deinit();
  249. //Serial.println("Disable and Deinit BLE...");
  250. //esp_bt_controller_disable();
  251. //esp_bt_controller_deinit();
  252. //Serial.println("Releasing BLE Memory...");
  253. //esp_bt_controller_mem_release(ESP_BT_MODE_BLE);
  254. //Serial.println("BT Controller Status: " + (String)esp_bt_controller_get_status());
  255. this->ble_initialized = false;
  256. return true;
  257. }
  258. else {
  259. Serial.println(F("BLE is not currently running"));
  260. return false;
  261. }
  262. }
  263. // Function to stop all wifi scans
  264. void WiFiScan::StopScan(uint8_t scan_mode)
  265. {
  266. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  267. (currentScanMode == WIFI_SCAN_AP) ||
  268. (currentScanMode == WIFI_SCAN_PWN) ||
  269. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  270. (currentScanMode == WIFI_SCAN_EAPOL) ||
  271. (currentScanMode == WIFI_SCAN_ALL) ||
  272. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  273. (currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
  274. (currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
  275. (currentScanMode == WIFI_PACKET_MONITOR) ||
  276. (currentScanMode == LV_JOIN_WIFI))
  277. {
  278. this->shutdownWiFi();
  279. }
  280. else if ((currentScanMode == BT_SCAN_ALL) ||
  281. (currentScanMode == BT_SCAN_SKIMMERS))
  282. {
  283. //Serial.println("Stopping BLE scan...");
  284. //pBLEScan->stop();
  285. //Serial.println("BLE Scan Stopped");
  286. //Serial.println("Clearing BLE Results...");
  287. //pBLEScan->clearResults();
  288. /*Serial.println("Deinitializing BT Controller...");
  289. BLEDevice::deinit();
  290. //Serial.println("Disable and Deinit BLE...");
  291. //esp_bt_controller_disable();
  292. //esp_bt_controller_deinit();
  293. //Serial.println("Releasing BLE Memory...");
  294. //esp_bt_controller_mem_release(ESP_BT_MODE_BLE);
  295. //Serial.println("BT Controller Status: " + (String)esp_bt_controller_get_status());
  296. */
  297. this->shutdownBLE();
  298. }
  299. display_obj.display_buffer->clear();
  300. Serial.print("display_buffer->size(): ");
  301. Serial.println(display_obj.display_buffer->size());
  302. display_obj.tteBar = false;
  303. }
  304. String WiFiScan::getStaMAC()
  305. {
  306. char *buf;
  307. uint8_t mac[6];
  308. char macAddrChr[18] = {0};
  309. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  310. esp_wifi_init(&cfg);
  311. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  312. esp_wifi_set_mode(WIFI_MODE_NULL);
  313. esp_wifi_start();
  314. esp_err_t mac_status = esp_wifi_get_mac(ESP_IF_WIFI_STA, mac);
  315. sprintf(macAddrChr,
  316. "%02X:%02X:%02X:%02X:%02X:%02X",
  317. mac[0],
  318. mac[1],
  319. mac[2],
  320. mac[3],
  321. mac[4],
  322. mac[5]);
  323. this->shutdownWiFi();
  324. return String(macAddrChr);
  325. }
  326. String WiFiScan::getApMAC()
  327. {
  328. char *buf;
  329. uint8_t mac[6];
  330. char macAddrChr[18] = {0};
  331. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  332. esp_wifi_init(&cfg);
  333. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  334. esp_wifi_set_mode(WIFI_MODE_NULL);
  335. esp_wifi_start();
  336. esp_err_t mac_status = esp_wifi_get_mac(ESP_IF_WIFI_AP, mac);
  337. sprintf(macAddrChr,
  338. "%02X:%02X:%02X:%02X:%02X:%02X",
  339. mac[0],
  340. mac[1],
  341. mac[2],
  342. mac[3],
  343. mac[4],
  344. mac[5]);
  345. this->shutdownWiFi();
  346. return String(macAddrChr);
  347. }
  348. String WiFiScan::freeRAM()
  349. {
  350. char s[150];
  351. sprintf(s, "RAM Free: %u bytes", system_get_free_heap_size());
  352. this->free_ram = String(system_get_free_heap_size());
  353. return String(s);
  354. }
  355. void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
  356. display_obj.tft.init();
  357. display_obj.tft.setRotation(1);
  358. #ifdef TFT_SHIELD
  359. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  360. Serial.println("Using TFT Shield");
  361. #else if defined(TFT_DIY)
  362. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  363. Serial.println("Using TFT DIY");
  364. #endif
  365. display_obj.tft.setTouch(calData);
  366. //display_obj.initLVGL();
  367. lv_obj_t * scr = lv_cont_create(NULL, NULL);
  368. lv_disp_load_scr(scr);
  369. //display_obj.joinWiFiGFX();
  370. }
  371. void WiFiScan::RunClearSSIDs() {
  372. display_obj.tft.setTextWrap(false);
  373. display_obj.tft.setFreeFont(NULL);
  374. display_obj.tft.setCursor(0, 100);
  375. display_obj.tft.setTextSize(1);
  376. display_obj.tft.setTextColor(TFT_CYAN);
  377. display_obj.tft.println(F("Clearing SSIDs..."));
  378. display_obj.tft.println("SSIDs Cleared: " + (String)this->clearSSIDs());
  379. }
  380. void WiFiScan::RunGenerateSSIDs() {
  381. display_obj.tft.setTextWrap(false);
  382. display_obj.tft.setFreeFont(NULL);
  383. display_obj.tft.setCursor(0, 100);
  384. display_obj.tft.setTextSize(1);
  385. display_obj.tft.setTextColor(TFT_CYAN);
  386. display_obj.tft.println(F("Generating SSIDs..."));
  387. display_obj.tft.println("SSIDs Generated: " + (String)this->generateSSIDs());
  388. display_obj.tft.println(" Total SSIDs: " + (String)this->ssids->size());
  389. }
  390. void WiFiScan::RunShutdownWiFi() {
  391. display_obj.tft.setTextWrap(false);
  392. display_obj.tft.setFreeFont(NULL);
  393. display_obj.tft.setCursor(0, 100);
  394. display_obj.tft.setTextSize(1);
  395. display_obj.tft.setTextColor(TFT_CYAN);
  396. display_obj.tft.print(F("Shutting down WiFi..."));
  397. if (this->wifi_initialized) {
  398. this->shutdownWiFi();
  399. display_obj.tft.setTextColor(TFT_GREEN);
  400. display_obj.tft.println(F("OK"));
  401. }
  402. else {
  403. display_obj.tft.setTextColor(TFT_RED);
  404. display_obj.tft.println(F("FAIL"));
  405. display_obj.tft.println(F("WiFi not currently initialized"));
  406. }
  407. }
  408. void WiFiScan::RunShutdownBLE() {
  409. display_obj.tft.setTextWrap(false);
  410. display_obj.tft.setFreeFont(NULL);
  411. display_obj.tft.setCursor(0, 100);
  412. display_obj.tft.setTextSize(1);
  413. display_obj.tft.setTextColor(TFT_CYAN);
  414. display_obj.tft.print(F("Shutting down BLE..."));
  415. if (this->ble_initialized) {
  416. this->shutdownBLE();
  417. display_obj.tft.setTextColor(TFT_GREEN);
  418. display_obj.tft.println(F("OK"));
  419. }
  420. else {
  421. display_obj.tft.setTextColor(TFT_RED);
  422. display_obj.tft.println(F("FAIL"));
  423. display_obj.tft.println(F("BLE not currently initialized"));
  424. }
  425. }
  426. void WiFiScan::RunInfo()
  427. {
  428. String sta_mac = this->getStaMAC();
  429. String ap_mac = this->getApMAC();
  430. String free_ram = this->freeRAM();
  431. //Serial.print("STA MAC: ");
  432. //Serial.println(sta_mac);
  433. //Serial.print("AP MAC: ");
  434. //Serial.println(ap_mac);
  435. Serial.println(free_ram);
  436. display_obj.tft.setTextWrap(false);
  437. display_obj.tft.setFreeFont(NULL);
  438. display_obj.tft.setCursor(0, 100);
  439. display_obj.tft.setTextSize(1);
  440. display_obj.tft.setTextColor(TFT_CYAN);
  441. display_obj.tft.println(" Firmware: Marauder");
  442. display_obj.tft.println(" Version: " + display_obj.version_number + "\n");
  443. display_obj.tft.println(" Station MAC: " + sta_mac);
  444. display_obj.tft.println(" AP MAC: " + ap_mac);
  445. display_obj.tft.println(" " + free_ram);
  446. if (sd_obj.supported) {
  447. display_obj.tft.println(" SD Card: Connected");
  448. display_obj.tft.print(" SD Card Size: ");
  449. display_obj.tft.print(sd_obj.card_sz);
  450. display_obj.tft.println("MB");
  451. }
  452. else {
  453. display_obj.tft.println(" SD Card: Not Connected");
  454. display_obj.tft.println(" SD Card Size: 0");
  455. }
  456. battery_obj.battery_level = battery_obj.getBatteryLevel();
  457. if (battery_obj.i2c_supported) {
  458. display_obj.tft.println(" IP5306 I2C: supported");
  459. display_obj.tft.println(" Battery Lvl: " + (String)battery_obj.battery_level + "%");
  460. }
  461. else
  462. display_obj.tft.println(" IP5306 I2C: not supported");
  463. display_obj.tft.println("Internal temp: " + (String)temp_obj.current_temp + " C");
  464. }
  465. void WiFiScan::RunEspressifScan(uint8_t scan_mode, uint16_t color) {
  466. sd_obj.openCapture("espressif");
  467. display_obj.TOP_FIXED_AREA_2 = 48;
  468. display_obj.tteBar = true;
  469. display_obj.print_delay_1 = 15;
  470. display_obj.print_delay_2 = 10;
  471. //display_obj.clearScreen();
  472. display_obj.initScrollValues(true);
  473. display_obj.tft.setTextWrap(false);
  474. display_obj.tft.setTextColor(TFT_WHITE, color);
  475. display_obj.tft.fillRect(0,16,240,16, color);
  476. display_obj.tft.drawCentreString(" Detect Espressif ",120,16,2);
  477. display_obj.touchToExit();
  478. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  479. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  480. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  481. esp_wifi_init(&cfg);
  482. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  483. esp_wifi_set_mode(WIFI_MODE_NULL);
  484. esp_wifi_start();
  485. esp_wifi_set_promiscuous(true);
  486. esp_wifi_set_promiscuous_filter(&filt);
  487. esp_wifi_set_promiscuous_rx_cb(&espressifSnifferCallback);
  488. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  489. this->wifi_initialized = true;
  490. initTime = millis();
  491. }
  492. void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
  493. {
  494. display_obj.tft.init();
  495. display_obj.tft.setRotation(1);
  496. display_obj.tft.fillScreen(TFT_BLACK);
  497. sd_obj.openCapture("packet_monitor");
  498. #ifdef TFT_SHIELD
  499. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  500. Serial.println("Using TFT Shield");
  501. #else if defined(TFT_DIY)
  502. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  503. Serial.println("Using TFT DIY");
  504. #endif
  505. display_obj.tft.setTouch(calData);
  506. //display_obj.tft.setFreeFont(1);
  507. display_obj.tft.setFreeFont(NULL);
  508. display_obj.tft.setTextSize(1);
  509. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  510. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  511. delay(10);
  512. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  513. display_obj.tftDrawColorKey();
  514. display_obj.tftDrawXScaleButtons(x_scale);
  515. display_obj.tftDrawYScaleButtons(y_scale);
  516. display_obj.tftDrawChannelScaleButtons(set_channel);
  517. display_obj.tftDrawExitScaleButtons();
  518. Serial.println("Running packet scan...");
  519. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  520. esp_wifi_init(&cfg);
  521. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  522. esp_wifi_set_mode(WIFI_MODE_NULL);
  523. esp_wifi_start();
  524. esp_wifi_set_promiscuous(true);
  525. esp_wifi_set_promiscuous_filter(&filt);
  526. esp_wifi_set_promiscuous_rx_cb(&wifiSnifferCallback);
  527. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  528. this->wifi_initialized = true;
  529. uint32_t initTime = millis();
  530. }
  531. void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
  532. {
  533. num_eapol = 0;
  534. display_obj.tft.init();
  535. display_obj.tft.setRotation(1);
  536. display_obj.tft.fillScreen(TFT_BLACK);
  537. sd_obj.openCapture("eapol");
  538. #ifdef TFT_SHIELD
  539. uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
  540. Serial.println("Using TFT Shield");
  541. #else if defined(TFT_DIY)
  542. uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
  543. Serial.println("Using TFT DIY");
  544. #endif
  545. display_obj.tft.setTouch(calData);
  546. //display_obj.tft.setFreeFont(1);
  547. display_obj.tft.setFreeFont(NULL);
  548. display_obj.tft.setTextSize(1);
  549. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); // Buttons
  550. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // color key
  551. delay(10);
  552. display_obj.tftDrawGraphObjects(x_scale); //draw graph objects
  553. display_obj.tftDrawEapolColorKey();
  554. //display_obj.tftDrawXScaleButtons(x_scale);
  555. //display_obj.tftDrawYScaleButtons(y_scale);
  556. display_obj.tftDrawChannelScaleButtons(set_channel);
  557. display_obj.tftDrawExitScaleButtons();
  558. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  559. esp_wifi_init(&cfg);
  560. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  561. esp_wifi_set_mode(WIFI_MODE_NULL);
  562. esp_wifi_start();
  563. esp_wifi_set_promiscuous(true);
  564. esp_wifi_set_promiscuous_filter(&filt);
  565. esp_wifi_set_promiscuous_rx_cb(&eapolSnifferCallback);
  566. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  567. this->wifi_initialized = true;
  568. initTime = millis();
  569. }
  570. void WiFiScan::RunRickRoll(uint8_t scan_mode, uint16_t color)
  571. {
  572. //Serial.println("Rick Roll...");
  573. display_obj.TOP_FIXED_AREA_2 = 48;
  574. display_obj.tteBar = true;
  575. display_obj.print_delay_1 = 15;
  576. display_obj.print_delay_2 = 10;
  577. //display_obj.clearScreen();
  578. display_obj.initScrollValues(true);
  579. display_obj.tft.setTextWrap(false);
  580. display_obj.tft.setTextColor(TFT_BLACK, color);
  581. display_obj.tft.fillRect(0,16,240,16, color);
  582. display_obj.tft.drawCentreString(" Rick Roll Beacon ",120,16,2);
  583. display_obj.touchToExit();
  584. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  585. packets_sent = 0;
  586. //esp_wifi_set_mode(WIFI_MODE_STA);
  587. WiFi.mode(WIFI_AP_STA);
  588. esp_wifi_start();
  589. esp_wifi_set_promiscuous_filter(NULL);
  590. esp_wifi_set_promiscuous(true);
  591. esp_wifi_set_max_tx_power(78);
  592. this->wifi_initialized = true;
  593. initTime = millis();
  594. //display_obj.clearScreen();
  595. //Serial.println("End of func");
  596. }
  597. // Function to prepare for beacon spam
  598. void WiFiScan::RunBeaconSpam(uint8_t scan_mode, uint16_t color)
  599. {
  600. //Serial.println("Beacon Spam...");
  601. display_obj.TOP_FIXED_AREA_2 = 48;
  602. display_obj.tteBar = true;
  603. display_obj.print_delay_1 = 15;
  604. display_obj.print_delay_2 = 10;
  605. //display_obj.clearScreen();
  606. display_obj.initScrollValues(true);
  607. display_obj.tft.setTextWrap(false);
  608. display_obj.tft.setTextColor(TFT_BLACK, color);
  609. display_obj.tft.fillRect(0,16,240,16, color);
  610. display_obj.tft.drawCentreString(" Beacon Spam Random ",120,16,2);
  611. display_obj.touchToExit();
  612. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  613. packets_sent = 0;
  614. //esp_wifi_set_mode(WIFI_MODE_STA);
  615. //WiFi.mode(WIFI_AP_STA);
  616. esp_wifi_init(&cfg);
  617. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  618. //WiFi.mode(WIFI_AP_STA);
  619. esp_wifi_set_mode(WIFI_AP_STA);
  620. esp_wifi_start();
  621. esp_wifi_set_promiscuous_filter(NULL);
  622. esp_wifi_set_promiscuous(true);
  623. esp_wifi_set_max_tx_power(78);
  624. this->wifi_initialized = true;
  625. initTime = millis();
  626. //display_obj.clearScreen();
  627. //Serial.println("End of func");
  628. }
  629. void WiFiScan::RunPwnScan(uint8_t scan_mode, uint16_t color)
  630. {
  631. sd_obj.openCapture("pwnagotchi");
  632. display_obj.TOP_FIXED_AREA_2 = 48;
  633. display_obj.tteBar = true;
  634. display_obj.print_delay_1 = 15;
  635. display_obj.print_delay_2 = 10;
  636. //display_obj.clearScreen();
  637. display_obj.initScrollValues(true);
  638. display_obj.tft.setTextWrap(false);
  639. display_obj.tft.setTextColor(TFT_WHITE, color);
  640. display_obj.tft.fillRect(0,16,240,16, color);
  641. display_obj.tft.drawCentreString(" Detect Pwnagotchi ",120,16,2);
  642. display_obj.touchToExit();
  643. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  644. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  645. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  646. esp_wifi_init(&cfg);
  647. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  648. esp_wifi_set_mode(WIFI_MODE_NULL);
  649. esp_wifi_start();
  650. esp_wifi_set_promiscuous(true);
  651. esp_wifi_set_promiscuous_filter(&filt);
  652. esp_wifi_set_promiscuous_rx_cb(&pwnSnifferCallback);
  653. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  654. this->wifi_initialized = true;
  655. initTime = millis();
  656. }
  657. // Function to start running a beacon scan
  658. void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color)
  659. {
  660. sd_obj.openCapture("beacon");
  661. display_obj.TOP_FIXED_AREA_2 = 48;
  662. display_obj.tteBar = true;
  663. display_obj.print_delay_1 = 15;
  664. display_obj.print_delay_2 = 10;
  665. //display_obj.clearScreen();
  666. display_obj.initScrollValues(true);
  667. display_obj.tft.setTextWrap(false);
  668. display_obj.tft.setTextColor(TFT_WHITE, color);
  669. display_obj.tft.fillRect(0,16,240,16, color);
  670. display_obj.tft.drawCentreString(" Beacon Sniffer ",120,16,2);
  671. display_obj.touchToExit();
  672. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  673. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  674. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  675. esp_wifi_init(&cfg);
  676. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  677. esp_wifi_set_mode(WIFI_MODE_NULL);
  678. esp_wifi_start();
  679. esp_wifi_set_promiscuous(true);
  680. esp_wifi_set_promiscuous_filter(&filt);
  681. esp_wifi_set_promiscuous_rx_cb(&beaconSnifferCallback);
  682. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  683. this->wifi_initialized = true;
  684. initTime = millis();
  685. }
  686. void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color)
  687. {
  688. sd_obj.openCapture("deauth");
  689. display_obj.TOP_FIXED_AREA_2 = 48;
  690. display_obj.tteBar = true;
  691. display_obj.print_delay_1 = 15;
  692. display_obj.print_delay_2 = 10;
  693. //display_obj.clearScreen();
  694. display_obj.initScrollValues(true);
  695. display_obj.tft.setTextWrap(false);
  696. display_obj.tft.setTextColor(TFT_BLACK, color);
  697. display_obj.tft.fillRect(0,16,240,16, color);
  698. display_obj.tft.drawCentreString(" Deauthentication Sniffer ",120,16,2);
  699. display_obj.touchToExit();
  700. display_obj.tft.setTextColor(TFT_RED, TFT_BLACK);
  701. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  702. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  703. esp_wifi_init(&cfg);
  704. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  705. esp_wifi_set_mode(WIFI_MODE_NULL);
  706. esp_wifi_start();
  707. esp_wifi_set_promiscuous(true);
  708. esp_wifi_set_promiscuous_filter(&filt);
  709. esp_wifi_set_promiscuous_rx_cb(&deauthSnifferCallback);
  710. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  711. this->wifi_initialized = true;
  712. initTime = millis();
  713. }
  714. // Function for running probe request scan
  715. void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color)
  716. {
  717. sd_obj.openCapture("probe");
  718. display_obj.TOP_FIXED_AREA_2 = 48;
  719. display_obj.tteBar = true;
  720. display_obj.print_delay_1 = 15;
  721. display_obj.print_delay_2 = 10;
  722. //display_obj.clearScreen();
  723. display_obj.initScrollValues(true);
  724. display_obj.tft.setTextWrap(false);
  725. display_obj.tft.setTextColor(TFT_BLACK, color);
  726. display_obj.tft.fillRect(0,16,240,16, color);
  727. display_obj.tft.drawCentreString(" Probe Request Sniffer ",120,16,2);
  728. display_obj.touchToExit();
  729. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  730. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  731. //wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  732. esp_wifi_init(&cfg);
  733. esp_wifi_set_storage(WIFI_STORAGE_RAM);
  734. esp_wifi_set_mode(WIFI_MODE_NULL);
  735. esp_wifi_start();
  736. esp_wifi_set_promiscuous(true);
  737. esp_wifi_set_promiscuous_filter(&filt);
  738. esp_wifi_set_promiscuous_rx_cb(&probeSnifferCallback);
  739. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  740. this->wifi_initialized = true;
  741. initTime = millis();
  742. }
  743. // Function to start running any BLE scan
  744. void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color)
  745. {
  746. display_obj.print_delay_1 = 50;
  747. display_obj.print_delay_2 = 20;
  748. /*
  749. esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
  750. esp_err_t init_ret = esp_bt_controller_init(&bt_cfg);
  751. if (init_ret != ESP_OK)
  752. Serial.println("Could not initialize BT Controller: " + (String)init_ret);
  753. //esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT);
  754. //esp_bt_controller_disable();
  755. esp_err_t ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
  756. if (ret != ESP_OK)
  757. Serial.println("Could not enable BT Controller: " + (String)ret);
  758. Serial.println("BT Controller Status: " + (String)esp_bt_controller_get_status());
  759. */
  760. BLEDevice::init("");
  761. pBLEScan = BLEDevice::getScan(); //create new scan
  762. if (scan_mode == BT_SCAN_ALL)
  763. {
  764. display_obj.TOP_FIXED_AREA_2 = 48;
  765. display_obj.tteBar = true;
  766. //display_obj.clearScreen();
  767. display_obj.initScrollValues(true);
  768. display_obj.tft.setTextWrap(false);
  769. display_obj.tft.setTextColor(TFT_BLACK, color);
  770. display_obj.tft.fillRect(0,16,240,16, color);
  771. display_obj.tft.drawCentreString(" Bluetooth Sniff ",120,16,2);
  772. display_obj.touchToExit();
  773. display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
  774. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  775. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback());
  776. //bluetoothScanAllCallback myCallbacks;
  777. //pBLEScan->setAdvertisedDeviceCallbacks(&myCallbacks);
  778. }
  779. else if (scan_mode == BT_SCAN_SKIMMERS)
  780. {
  781. display_obj.TOP_FIXED_AREA_2 = 160;
  782. display_obj.tteBar = true;
  783. //display_obj.clearScreen();
  784. display_obj.tft.fillScreen(TFT_DARKGREY);
  785. display_obj.initScrollValues(true);
  786. display_obj.tft.setTextWrap(false);
  787. display_obj.tft.setTextColor(TFT_BLACK, color);
  788. display_obj.tft.fillRect(0,16,240,16, color);
  789. display_obj.tft.drawCentreString(" Detect Card Skimmers ",120,16,2);
  790. display_obj.twoPartDisplay("Scanning for\nBluetooth-enabled skimmers\nHC-03, HC-05, and HC-06...");
  791. display_obj.tft.setTextColor(TFT_BLACK, TFT_DARKGREY);
  792. display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
  793. pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanSkimmersCallback());
  794. }
  795. pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  796. pBLEScan->setInterval(100);
  797. pBLEScan->setWindow(99); // less or equal setInterval value
  798. pBLEScan->start(0, scanCompleteCB);
  799. Serial.println("Started BLE Scan");
  800. this->ble_initialized = true;
  801. initTime = millis();
  802. }
  803. // Function that is called when BLE scan is completed
  804. void WiFiScan::scanCompleteCB(BLEScanResults scanResults) {
  805. printf("Scan complete!\n");
  806. printf("Found %d devices\n", scanResults.getCount());
  807. scanResults.dump();
  808. } // scanCompleteCB
  809. // Function to extract MAC addr from a packet at given offset
  810. void WiFiScan::getMAC(char *addr, uint8_t* data, uint16_t offset) {
  811. 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]);
  812. }
  813. void WiFiScan::espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  814. {
  815. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  816. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  817. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  818. int len = snifferPacket->rx_ctrl.sig_len;
  819. String display_string = "";
  820. String src_addr_string = "";
  821. if (type == WIFI_PKT_MGMT)
  822. {
  823. len -= 4;
  824. }
  825. int fctl = ntohs(frameControl->fctl);
  826. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  827. const WifiMgmtHdr *hdr = &ipkt->hdr;
  828. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  829. //if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  830. //{
  831. char addr[] = "00:00:00:00:00:00";
  832. getMAC(addr, snifferPacket->payload, 10);
  833. src_addr_string.concat(addr);
  834. bool match = false;
  835. for (int i = 0; i < (sizeof(espressif_macs) / sizeof(espressif_macs[0])); i++) {
  836. if (src_addr_string.startsWith(espressif_macs[i])) {
  837. match = true;
  838. break;
  839. }
  840. }
  841. if (!match)
  842. return;
  843. delay(random(0, 10));
  844. Serial.print("RSSI: ");
  845. Serial.print(snifferPacket->rx_ctrl.rssi);
  846. Serial.print(" Ch: ");
  847. Serial.print(snifferPacket->rx_ctrl.channel);
  848. Serial.print(" BSSID: ");
  849. Serial.print(addr);
  850. //display_string.concat(" RSSI: ");
  851. //display_string.concat(snifferPacket->rx_ctrl.rssi);
  852. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  853. //display_string.concat(" ");
  854. display_string.concat(" -> ");
  855. display_string.concat(addr);
  856. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  857. {
  858. display_string.concat(" ");
  859. }
  860. Serial.print(" ");
  861. //if (display_obj.display_buffer->size() == 0)
  862. //{
  863. display_obj.loading = true;
  864. display_obj.display_buffer->add(display_string);
  865. display_obj.loading = false;
  866. //}
  867. Serial.println();
  868. sd_obj.addPacket(snifferPacket->payload, len);
  869. //}
  870. }
  871. void WiFiScan::pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  872. {
  873. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  874. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  875. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  876. int len = snifferPacket->rx_ctrl.sig_len;
  877. String display_string = "";
  878. String src = "";
  879. String essid = "";
  880. if (type == WIFI_PKT_MGMT)
  881. {
  882. len -= 4;
  883. int fctl = ntohs(frameControl->fctl);
  884. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  885. const WifiMgmtHdr *hdr = &ipkt->hdr;
  886. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  887. if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  888. {
  889. char addr[] = "00:00:00:00:00:00";
  890. getMAC(addr, snifferPacket->payload, 10);
  891. src.concat(addr);
  892. if (src == "de:ad:be:ef:de:ad") {
  893. delay(random(0, 10));
  894. Serial.print("RSSI: ");
  895. Serial.print(snifferPacket->rx_ctrl.rssi);
  896. Serial.print(" Ch: ");
  897. Serial.print(snifferPacket->rx_ctrl.channel);
  898. Serial.print(" BSSID: ");
  899. Serial.print(addr);
  900. //display_string.concat(addr);
  901. display_string.concat("CH: " + (String)snifferPacket->rx_ctrl.channel);
  902. Serial.print(" ESSID: ");
  903. display_string.concat(" -> ");
  904. // Just grab the first 255 bytes of the pwnagotchi beacon
  905. // because that is where the name is
  906. //for (int i = 0; i < snifferPacket->payload[37]; i++)
  907. for (int i = 0; i < len - 37; i++)
  908. {
  909. Serial.print((char)snifferPacket->payload[i + 38]);
  910. //display_string.concat((char)snifferPacket->payload[i + 38]);
  911. if (isAscii(snifferPacket->payload[i + 38]))
  912. essid.concat((char)snifferPacket->payload[i + 38]);
  913. else
  914. Serial.println("Got non-ascii character: " + (String)(char)snifferPacket->payload[i + 38]);
  915. }
  916. //essid.concat("\": \"\"}}");
  917. //Serial.println("\n" + (String)(snifferPacket->payload[37]) + " -> " + essid);
  918. // Load json
  919. DynamicJsonBuffer jsonBuffer;
  920. JsonObject& json = jsonBuffer.parseObject(essid);
  921. if (!json.success()) {
  922. Serial.println("\nCould not parse Pwnagotchi json");
  923. display_string.concat(essid);
  924. }
  925. else {
  926. Serial.println("\nSuccessfully parsed json");
  927. String json_output;
  928. json.printTo(json_output);
  929. Serial.println(json_output);
  930. display_string.concat(json["name"].as<String>() + " pwnd: " + json["pwnd_tot"].as<String>());
  931. }
  932. int temp_len = display_string.length();
  933. for (int i = 0; i < 40 - temp_len; i++)
  934. {
  935. display_string.concat(" ");
  936. }
  937. Serial.print(" ");
  938. if (display_obj.display_buffer->size() == 0)
  939. {
  940. display_obj.loading = true;
  941. display_obj.display_buffer->add(display_string);
  942. display_obj.loading = false;
  943. }
  944. Serial.println();
  945. sd_obj.addPacket(snifferPacket->payload, len);
  946. }
  947. }
  948. }
  949. }
  950. void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  951. {
  952. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  953. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  954. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  955. int len = snifferPacket->rx_ctrl.sig_len;
  956. String display_string = "";
  957. if (type == WIFI_PKT_MGMT)
  958. {
  959. len -= 4;
  960. int fctl = ntohs(frameControl->fctl);
  961. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  962. const WifiMgmtHdr *hdr = &ipkt->hdr;
  963. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  964. if ((snifferPacket->payload[0] == 0x80) && (display_obj.display_buffer->size() == 0))
  965. {
  966. delay(random(0, 10));
  967. Serial.print("RSSI: ");
  968. Serial.print(snifferPacket->rx_ctrl.rssi);
  969. Serial.print(" Ch: ");
  970. Serial.print(snifferPacket->rx_ctrl.channel);
  971. Serial.print(" BSSID: ");
  972. char addr[] = "00:00:00:00:00:00";
  973. getMAC(addr, snifferPacket->payload, 10);
  974. Serial.print(addr);
  975. display_string.concat(addr);
  976. Serial.print(" ESSID: ");
  977. display_string.concat(" -> ");
  978. for (int i = 0; i < snifferPacket->payload[37]; i++)
  979. {
  980. Serial.print((char)snifferPacket->payload[i + 38]);
  981. display_string.concat((char)snifferPacket->payload[i + 38]);
  982. }
  983. int temp_len = display_string.length();
  984. for (int i = 0; i < 40 - temp_len; i++)
  985. {
  986. display_string.concat(" ");
  987. }
  988. Serial.print(" ");
  989. if (display_obj.display_buffer->size() == 0)
  990. {
  991. display_obj.loading = true;
  992. display_obj.display_buffer->add(display_string);
  993. display_obj.loading = false;
  994. }
  995. Serial.println();
  996. sd_obj.addPacket(snifferPacket->payload, len);
  997. }
  998. }
  999. }
  1000. void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1001. {
  1002. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1003. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1004. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1005. int len = snifferPacket->rx_ctrl.sig_len;
  1006. String display_string = "";
  1007. if (type == WIFI_PKT_MGMT)
  1008. {
  1009. len -= 4;
  1010. int fctl = ntohs(frameControl->fctl);
  1011. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1012. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1013. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1014. if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ) && (display_obj.display_buffer->size() == 0))
  1015. {
  1016. delay(random(0, 10));
  1017. Serial.print("RSSI: ");
  1018. Serial.print(snifferPacket->rx_ctrl.rssi);
  1019. Serial.print(" Ch: ");
  1020. Serial.print(snifferPacket->rx_ctrl.channel);
  1021. Serial.print(" BSSID: ");
  1022. char addr[] = "00:00:00:00:00:00";
  1023. getMAC(addr, snifferPacket->payload, 10);
  1024. Serial.print(addr);
  1025. display_string.concat(" RSSI: ");
  1026. display_string.concat(snifferPacket->rx_ctrl.rssi);
  1027. display_string.concat(" ");
  1028. display_string.concat(addr);
  1029. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  1030. {
  1031. display_string.concat(" ");
  1032. }
  1033. Serial.print(" ");
  1034. if (display_obj.display_buffer->size() == 0)
  1035. {
  1036. display_obj.loading = true;
  1037. display_obj.display_buffer->add(display_string);
  1038. display_obj.loading = false;
  1039. }
  1040. Serial.println();
  1041. sd_obj.addPacket(snifferPacket->payload, len);
  1042. }
  1043. }
  1044. }
  1045. void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1046. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1047. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1048. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1049. int len = snifferPacket->rx_ctrl.sig_len;
  1050. String display_string = "";
  1051. if (type == WIFI_PKT_MGMT)
  1052. {
  1053. len -= 4;
  1054. int fctl = ntohs(frameControl->fctl);
  1055. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1056. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1057. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1058. if ((snifferPacket->payload[0] == 0x40) && (display_obj.display_buffer->size() == 0))
  1059. {
  1060. delay(random(0, 10));
  1061. Serial.print("RSSI: ");
  1062. Serial.print(snifferPacket->rx_ctrl.rssi);
  1063. Serial.print(" Ch: ");
  1064. Serial.print(snifferPacket->rx_ctrl.channel);
  1065. Serial.print(" Client: ");
  1066. char addr[] = "00:00:00:00:00:00";
  1067. getMAC(addr, snifferPacket->payload, 10);
  1068. Serial.print(addr);
  1069. display_string.concat(addr);
  1070. Serial.print(" Requesting: ");
  1071. display_string.concat(" -> ");
  1072. for (int i = 0; i < snifferPacket->payload[25]; i++)
  1073. {
  1074. Serial.print((char)snifferPacket->payload[26 + i]);
  1075. display_string.concat((char)snifferPacket->payload[26 + i]);
  1076. }
  1077. // Print spaces because of the rotating lines of the hardware scroll.
  1078. // The same characters print from previous lines so I just overwrite them
  1079. // with spaces.
  1080. for (int i = 0; i < 19 - snifferPacket->payload[25]; i++)
  1081. {
  1082. display_string.concat(" ");
  1083. }
  1084. if (display_obj.display_buffer->size() == 0)
  1085. {
  1086. //while (display_obj.printing)
  1087. // delay(1);
  1088. display_obj.loading = true;
  1089. display_obj.display_buffer->add(display_string);
  1090. display_obj.loading = false;
  1091. }
  1092. Serial.println();
  1093. sd_obj.addPacket(snifferPacket->payload, len);
  1094. }
  1095. }
  1096. }
  1097. // Function to send beacons with random ESSID length
  1098. void WiFiScan::broadcastSetSSID(uint32_t current_time, char* ESSID) {
  1099. set_channel = random(1,12);
  1100. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1101. delay(1);
  1102. // Randomize SRC MAC
  1103. packet[10] = packet[16] = random(256);
  1104. packet[11] = packet[17] = random(256);
  1105. packet[12] = packet[18] = random(256);
  1106. packet[13] = packet[19] = random(256);
  1107. packet[14] = packet[20] = random(256);
  1108. packet[15] = packet[21] = random(256);
  1109. /////////////////////////////
  1110. //int essid_len = random(6, 10);
  1111. // random prefix to beacon essid
  1112. //uint8_t rand_reg[essid_len] = {};
  1113. //for (int i = 0; i < essid_len; i++)
  1114. // rand_reg[i] = alfa[random(65)];
  1115. int ssidLen = strlen(ESSID);
  1116. //int rand_len = sizeof(rand_reg);
  1117. int fullLen = ssidLen;
  1118. packet[37] = fullLen;
  1119. // Insert random prefix
  1120. //for (int i = 0; i < rand_len; i++)
  1121. // packet[38+i] = rand_reg[i];
  1122. // Insert my tag
  1123. for(int i = 0; i < ssidLen; i++)
  1124. packet[38 + i] = ESSID[i];
  1125. /////////////////////////////
  1126. packet[50 + fullLen] = set_channel;
  1127. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  1128. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  1129. // Add everything that goes after the SSID
  1130. for(int i = 0; i < 12; i++)
  1131. packet[38 + fullLen + i] = postSSID[i];
  1132. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1133. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1134. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1135. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1136. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1137. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1138. packets_sent = packets_sent + 3;
  1139. }
  1140. // Function for sending crafted beacon frames
  1141. void WiFiScan::broadcastRandomSSID(uint32_t currentTime) {
  1142. set_channel = random(1,12);
  1143. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1144. delay(1);
  1145. // Randomize SRC MAC
  1146. packet[10] = packet[16] = random(256);
  1147. packet[11] = packet[17] = random(256);
  1148. packet[12] = packet[18] = random(256);
  1149. packet[13] = packet[19] = random(256);
  1150. packet[14] = packet[20] = random(256);
  1151. packet[15] = packet[21] = random(256);
  1152. packet[37] = 6;
  1153. // Randomize SSID (Fixed size 6. Lazy right?)
  1154. packet[38] = alfa[random(65)];
  1155. packet[39] = alfa[random(65)];
  1156. packet[40] = alfa[random(65)];
  1157. packet[41] = alfa[random(65)];
  1158. packet[42] = alfa[random(65)];
  1159. packet[43] = alfa[random(65)];
  1160. packet[56] = set_channel;
  1161. uint8_t postSSID[13] = {0x01, 0x08, 0x82, 0x84, 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, //supported rate
  1162. 0x03, 0x01, 0x04 /*DSSS (Current Channel)*/ };
  1163. // Add everything that goes after the SSID
  1164. for(int i = 0; i < 12; i++)
  1165. packet[38 + 6 + i] = postSSID[i];
  1166. //Serial.println("About to send packets...");
  1167. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1168. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1169. esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1170. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1171. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1172. //esp_wifi_80211_tx(WIFI_IF_AP, packet, sizeof(packet), false);
  1173. packets_sent = packets_sent + 3;
  1174. //Serial.print("Packets sent: ");
  1175. //Serial.println(packets_sent);
  1176. //Serial.println("Sent packets");
  1177. }
  1178. void WiFiScan::wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1179. {
  1180. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1181. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1182. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1183. int len = snifferPacket->rx_ctrl.sig_len;
  1184. if (type == WIFI_PKT_MGMT)
  1185. {
  1186. len -= 4;
  1187. int fctl = ntohs(frameControl->fctl);
  1188. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1189. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1190. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1191. if (snifferPacket->payload[0] == 0x80)
  1192. {
  1193. num_beacon++;
  1194. }
  1195. else if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ))
  1196. {
  1197. num_deauth++;
  1198. }
  1199. else if (snifferPacket->payload[0] == 0x40)
  1200. {
  1201. num_probe++;
  1202. }
  1203. sd_obj.addPacket(snifferPacket->payload, len);
  1204. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) ))
  1205. Serial.println("Oh god mgmt EAPOL");
  1206. }
  1207. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  1208. Serial.println("EAPOL!!");
  1209. //sd_obj.addPacket(snifferPacket->payload, len);
  1210. }
  1211. }
  1212. void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
  1213. {
  1214. /*
  1215. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1216. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1217. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1218. int len = snifferPacket->rx_ctrl.sig_len;
  1219. String display_string = "";
  1220. if (type == WIFI_PKT_MGMT)
  1221. {
  1222. len -= 4;
  1223. int fctl = ntohs(frameControl->fctl);
  1224. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1225. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1226. }
  1227. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  1228. delay(random(0, 10));
  1229. Serial.print((String)random(0, 5) + "EAPOL: ");
  1230. char srcaddr[] = "00:00:00:00:00:00";
  1231. getMAC(srcaddr, snifferPacket->payload, 10);
  1232. Serial.print(srcaddr);
  1233. display_string.concat(srcaddr);
  1234. Serial.print(" -> ");
  1235. display_string.concat(" -> ");
  1236. char desaddr[] = "00:00:00:00:00:00";
  1237. getMAC(desaddr, snifferPacket->payload, 4);
  1238. Serial.print(desaddr);
  1239. display_string.concat(desaddr);
  1240. // Print spaces because of the rotating lines of the hardware scroll.
  1241. // The same characters print from previous lines so I just overwrite them
  1242. // with spaces.
  1243. for (int i = 0; i < 19 - snifferPacket->payload[37]; i++)
  1244. {
  1245. display_string.concat(" ");
  1246. }
  1247. if (display_obj.display_buffer->size() == 0)
  1248. {
  1249. //while (display_obj.printing)
  1250. // delay(1);
  1251. display_obj.loading = true;
  1252. display_obj.display_buffer->add(display_string);
  1253. display_obj.loading = false;
  1254. }
  1255. Serial.println();
  1256. sd_obj.addPacket(snifferPacket->payload, len);
  1257. }
  1258. */
  1259. wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1260. WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
  1261. wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
  1262. int len = snifferPacket->rx_ctrl.sig_len;
  1263. if (len == 173) {
  1264. Serial.println("Maybe the PMKID");
  1265. //sd_obj.addPacket(snifferPacket->payload, len);
  1266. }
  1267. if (type == WIFI_PKT_MGMT)
  1268. {
  1269. len -= 4;
  1270. int fctl = ntohs(frameControl->fctl);
  1271. const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
  1272. const WifiMgmtHdr *hdr = &ipkt->hdr;
  1273. // If we dont the buffer size is not 0, don't write or else we get CORRUPT_HEAP
  1274. /*
  1275. if (snifferPacket->payload[0] == 0x80)
  1276. {
  1277. num_beacon++;
  1278. }
  1279. else if ((snifferPacket->payload[0] == 0xA0 || snifferPacket->payload[0] == 0xC0 ))
  1280. {
  1281. num_deauth++;
  1282. }
  1283. else if (snifferPacket->payload[0] == 0x40)
  1284. {
  1285. num_probe++;
  1286. }
  1287. */
  1288. //sd_obj.addPacket(snifferPacket->payload, len);
  1289. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) ))
  1290. Serial.println("Oh god mgmt EAPOL");
  1291. }
  1292. if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
  1293. Serial.println("EAPOL!!");
  1294. //sd_obj.addPacket(snifferPacket->payload, len);
  1295. num_eapol++;
  1296. }
  1297. sd_obj.addPacket(snifferPacket->payload, len);
  1298. }
  1299. void WiFiScan::eapolMonitorMain(uint32_t currentTime)
  1300. {
  1301. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  1302. // 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
  1303. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  1304. {
  1305. currentTime = millis();
  1306. do_break = false;
  1307. y_pos_x = 0;
  1308. y_pos_y = 0;
  1309. y_pos_z = 0;
  1310. boolean pressed = false;
  1311. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  1312. // Do the touch stuff
  1313. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  1314. if (pressed) {
  1315. Serial.print("Got touch | X: ");
  1316. Serial.print(t_x);
  1317. Serial.print(" Y: ");
  1318. Serial.println(t_y);
  1319. }
  1320. // Check buttons for presses
  1321. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1322. {
  1323. if (pressed && display_obj.key[b].contains(t_x, t_y))
  1324. {
  1325. display_obj.key[b].press(true);
  1326. } else {
  1327. display_obj.key[b].press(false);
  1328. }
  1329. }
  1330. // Which buttons pressed
  1331. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1332. {
  1333. if (display_obj.key[b].justPressed())
  1334. {
  1335. Serial.println("Bro, key pressed");
  1336. //do_break = true;
  1337. }
  1338. if (display_obj.key[b].justReleased())
  1339. {
  1340. do_break = true;
  1341. /*
  1342. // X - button pressed
  1343. if (b == 0) {
  1344. if (x_scale > 1) {
  1345. x_scale--;
  1346. delay(70);
  1347. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1348. display_obj.tftDrawXScaleButtons(x_scale);
  1349. display_obj.tftDrawYScaleButtons(y_scale);
  1350. display_obj.tftDrawChannelScaleButtons(set_channel);
  1351. display_obj.tftDrawExitScaleButtons();
  1352. break;
  1353. }
  1354. }
  1355. // X + button pressed
  1356. else if (b == 1) {
  1357. if (x_scale < 6) {
  1358. x_scale++;
  1359. delay(70);
  1360. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1361. display_obj.tftDrawXScaleButtons(x_scale);
  1362. display_obj.tftDrawYScaleButtons(y_scale);
  1363. display_obj.tftDrawChannelScaleButtons(set_channel);
  1364. display_obj.tftDrawExitScaleButtons();
  1365. break;
  1366. }
  1367. }
  1368. // Y - button pressed
  1369. else if (b == 2) {
  1370. if (y_scale > 1) {
  1371. y_scale--;
  1372. delay(70);
  1373. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1374. display_obj.tftDrawXScaleButtons(x_scale);
  1375. display_obj.tftDrawYScaleButtons(y_scale);
  1376. display_obj.tftDrawChannelScaleButtons(set_channel);
  1377. display_obj.tftDrawExitScaleButtons();
  1378. //updateMidway();
  1379. break;
  1380. }
  1381. }
  1382. // Y + button pressed
  1383. else if (b == 3) {
  1384. if (y_scale < 9) {
  1385. y_scale++;
  1386. delay(70);
  1387. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1388. display_obj.tftDrawXScaleButtons(x_scale);
  1389. display_obj.tftDrawYScaleButtons(y_scale);
  1390. display_obj.tftDrawChannelScaleButtons(set_channel);
  1391. display_obj.tftDrawExitScaleButtons();
  1392. //updateMidway();
  1393. break;
  1394. }
  1395. }*/
  1396. // Channel - button pressed
  1397. //else if (b == 4) {
  1398. if (b == 4) {
  1399. if (set_channel > 1) {
  1400. Serial.println("Shit channel down");
  1401. set_channel--;
  1402. delay(70);
  1403. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1404. //display_obj.tftDrawXScaleButtons(x_scale);
  1405. //display_obj.tftDrawYScaleButtons(y_scale);
  1406. display_obj.tftDrawChannelScaleButtons(set_channel);
  1407. display_obj.tftDrawExitScaleButtons();
  1408. changeChannel();
  1409. break;
  1410. }
  1411. }
  1412. // Channel + button pressed
  1413. else if (b == 5) {
  1414. if (set_channel < MAX_CHANNEL) {
  1415. Serial.println("Shit channel up");
  1416. set_channel++;
  1417. delay(70);
  1418. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1419. //display_obj.tftDrawXScaleButtons(x_scale);
  1420. //display_obj.tftDrawYScaleButtons(y_scale);
  1421. display_obj.tftDrawChannelScaleButtons(set_channel);
  1422. display_obj.tftDrawExitScaleButtons();
  1423. changeChannel();
  1424. break;
  1425. }
  1426. }
  1427. else if (b == 6) {
  1428. Serial.println("Exiting packet monitor...");
  1429. this->StartScan(WIFI_SCAN_OFF);
  1430. //display_obj.tft.init();
  1431. this->orient_display = true;
  1432. return;
  1433. }
  1434. }
  1435. }
  1436. if (currentTime - initTime >= (GRAPH_REFRESH * 5)) {
  1437. //Serial.println("-----------------------------------------");
  1438. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  1439. x_pos += x_scale;
  1440. initTime = millis();
  1441. y_pos_x = ((-num_eapol * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  1442. if (y_pos_x >= HEIGHT_1) {
  1443. Serial.println("Max EAPOL number reached. Adjusting...");
  1444. num_eapol = 0;
  1445. }
  1446. //y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  1447. //y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  1448. //Serial.println("num_beacon: " + (String)num_beacon);
  1449. //Serial.println("num_deauth: " + (String)num_deauth);
  1450. //Serial.println(" num_probe: " + (String)num_probe);
  1451. //num_beacon = 0;
  1452. //num_probe = 0;
  1453. //num_deauth = 0;
  1454. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  1455. //Plot "X" value
  1456. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_CYAN);
  1457. //Plot "Z" value
  1458. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  1459. //Plot "Y" value
  1460. //display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  1461. //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!!!
  1462. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  1463. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  1464. {
  1465. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  1466. }
  1467. else
  1468. {
  1469. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  1470. }
  1471. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  1472. //if (x_pos <= 90)
  1473. if (x_pos < 0) // below x axis
  1474. {
  1475. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  1476. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  1477. }
  1478. else
  1479. {
  1480. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  1481. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  1482. }
  1483. //tftDisplayTime();
  1484. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  1485. {
  1486. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  1487. }
  1488. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  1489. //y_pos_y_old = y_pos_y;
  1490. //y_pos_z_old = y_pos_z;
  1491. //delay(50);
  1492. }
  1493. sd_obj.main();
  1494. }
  1495. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  1496. //tft.fillRect(56, 0, 66, 32, TFT_ORANGE); //erase time and color key and any stray lines behind them
  1497. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  1498. //display_obj.tftDrawXScaleButtons(x_scale); //redraw stuff
  1499. //display_obj.tftDrawYScaleButtons(y_scale);
  1500. display_obj.tftDrawChannelScaleButtons(set_channel);
  1501. display_obj.tftDrawExitScaleButtons();
  1502. display_obj.tftDrawEapolColorKey();
  1503. display_obj.tftDrawGraphObjects(x_scale);
  1504. }
  1505. void WiFiScan::packetMonitorMain(uint32_t currentTime)
  1506. {
  1507. //---------MAIN 'FOR' LOOP! THIS IS WHERE ALL THE ACTION HAPPENS! HAS TO BE FAST!!!!!---------\\
  1508. // 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
  1509. for (x_pos = (11 + x_scale); x_pos <= 320; x_pos = x_pos)
  1510. {
  1511. currentTime = millis();
  1512. do_break = false;
  1513. y_pos_x = 0;
  1514. y_pos_y = 0;
  1515. y_pos_z = 0;
  1516. boolean pressed = false;
  1517. uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
  1518. // Do the touch stuff
  1519. pressed = display_obj.tft.getTouch(&t_x, &t_y);
  1520. if (pressed) {
  1521. Serial.print("Got touch | X: ");
  1522. Serial.print(t_x);
  1523. Serial.print(" Y: ");
  1524. Serial.println(t_y);
  1525. }
  1526. // Check buttons for presses
  1527. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1528. {
  1529. if (pressed && display_obj.key[b].contains(t_x, t_y))
  1530. {
  1531. display_obj.key[b].press(true);
  1532. } else {
  1533. display_obj.key[b].press(false);
  1534. }
  1535. }
  1536. // Which buttons pressed
  1537. for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
  1538. {
  1539. if (display_obj.key[b].justPressed())
  1540. {
  1541. Serial.println("Bro, key pressed");
  1542. //do_break = true;
  1543. }
  1544. if (display_obj.key[b].justReleased())
  1545. {
  1546. do_break = true;
  1547. // X - button pressed
  1548. if (b == 0) {
  1549. if (x_scale > 1) {
  1550. x_scale--;
  1551. delay(70);
  1552. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1553. display_obj.tftDrawXScaleButtons(x_scale);
  1554. display_obj.tftDrawYScaleButtons(y_scale);
  1555. display_obj.tftDrawChannelScaleButtons(set_channel);
  1556. display_obj.tftDrawExitScaleButtons();
  1557. break;
  1558. }
  1559. }
  1560. // X + button pressed
  1561. else if (b == 1) {
  1562. if (x_scale < 6) {
  1563. x_scale++;
  1564. delay(70);
  1565. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1566. display_obj.tftDrawXScaleButtons(x_scale);
  1567. display_obj.tftDrawYScaleButtons(y_scale);
  1568. display_obj.tftDrawChannelScaleButtons(set_channel);
  1569. display_obj.tftDrawExitScaleButtons();
  1570. break;
  1571. }
  1572. }
  1573. // Y - button pressed
  1574. else if (b == 2) {
  1575. if (y_scale > 1) {
  1576. y_scale--;
  1577. delay(70);
  1578. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1579. display_obj.tftDrawXScaleButtons(x_scale);
  1580. display_obj.tftDrawYScaleButtons(y_scale);
  1581. display_obj.tftDrawChannelScaleButtons(set_channel);
  1582. display_obj.tftDrawExitScaleButtons();
  1583. //updateMidway();
  1584. break;
  1585. }
  1586. }
  1587. // Y + button pressed
  1588. else if (b == 3) {
  1589. if (y_scale < 9) {
  1590. y_scale++;
  1591. delay(70);
  1592. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1593. display_obj.tftDrawXScaleButtons(x_scale);
  1594. display_obj.tftDrawYScaleButtons(y_scale);
  1595. display_obj.tftDrawChannelScaleButtons(set_channel);
  1596. display_obj.tftDrawExitScaleButtons();
  1597. //updateMidway();
  1598. break;
  1599. }
  1600. }
  1601. // Channel - button pressed
  1602. else if (b == 4) {
  1603. if (set_channel > 1) {
  1604. Serial.println("Shit channel down");
  1605. set_channel--;
  1606. delay(70);
  1607. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1608. display_obj.tftDrawXScaleButtons(x_scale);
  1609. display_obj.tftDrawYScaleButtons(y_scale);
  1610. display_obj.tftDrawChannelScaleButtons(set_channel);
  1611. display_obj.tftDrawExitScaleButtons();
  1612. changeChannel();
  1613. break;
  1614. }
  1615. }
  1616. // Channel + button pressed
  1617. else if (b == 5) {
  1618. if (set_channel < MAX_CHANNEL) {
  1619. Serial.println("Shit channel up");
  1620. set_channel++;
  1621. delay(70);
  1622. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
  1623. display_obj.tftDrawXScaleButtons(x_scale);
  1624. display_obj.tftDrawYScaleButtons(y_scale);
  1625. display_obj.tftDrawChannelScaleButtons(set_channel);
  1626. display_obj.tftDrawExitScaleButtons();
  1627. changeChannel();
  1628. break;
  1629. }
  1630. }
  1631. else if (b == 6) {
  1632. Serial.println("Exiting packet monitor...");
  1633. this->StartScan(WIFI_SCAN_OFF);
  1634. //display_obj.tft.init();
  1635. this->orient_display = true;
  1636. return;
  1637. }
  1638. }
  1639. }
  1640. if (currentTime - initTime >= GRAPH_REFRESH) {
  1641. //Serial.println("-----------------------------------------");
  1642. //Serial.println("Time elapsed: " + (String)(currentTime - initTime) + "ms");
  1643. x_pos += x_scale;
  1644. initTime = millis();
  1645. y_pos_x = ((-num_beacon * (y_scale * 3)) + (HEIGHT_1 - 2)); // GREEN
  1646. y_pos_y = ((-num_deauth * (y_scale * 3)) + (HEIGHT_1 - 2)); // RED
  1647. y_pos_z = ((-num_probe * (y_scale * 3)) + (HEIGHT_1 - 2)); // BLUE
  1648. //Serial.println("num_beacon: " + (String)num_beacon);
  1649. //Serial.println("num_deauth: " + (String)num_deauth);
  1650. //Serial.println(" num_probe: " + (String)num_probe);
  1651. num_beacon = 0;
  1652. num_probe = 0;
  1653. num_deauth = 0;
  1654. //CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
  1655. //Plot "X" value
  1656. display_obj.tft.drawLine(x_pos - x_scale, y_pos_x_old, x_pos, y_pos_x, TFT_GREEN);
  1657. //Plot "Z" value
  1658. display_obj.tft.drawLine(x_pos - x_scale, y_pos_z_old, x_pos, y_pos_z, TFT_BLUE);
  1659. //Plot "Y" value
  1660. display_obj.tft.drawLine(x_pos - x_scale, y_pos_y_old, x_pos, y_pos_y, TFT_RED);
  1661. //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!!!
  1662. //if ((x_pos <= 90) || ((x_pos >= 198) && (x_pos <= 320))) //above x axis
  1663. if ((x_pos <= 90) || ((x_pos >= 117) && (x_pos <= 320))) //above x axis
  1664. {
  1665. display_obj.tft.fillRect(x_pos+1, 28, 10, 93, TFT_BLACK); //compensate for buttons!
  1666. }
  1667. else
  1668. {
  1669. display_obj.tft.fillRect(x_pos+1, 0, 10, 121, TFT_BLACK); //don't compensate for buttons!
  1670. }
  1671. //if ((x_pos >= 254) && (x_pos <= 320)) //below x axis
  1672. //if (x_pos <= 90)
  1673. if (x_pos < 0) // below x axis
  1674. {
  1675. //tft.fillRect(x_pos+1, 121, 10, 88, TFT_BLACK);
  1676. display_obj.tft.fillRect(x_pos+1, 121, 10, 88, TFT_CYAN);
  1677. }
  1678. else
  1679. {
  1680. //tft.fillRect(x_pos+1, 121, 10, 119, TFT_BLACK);
  1681. display_obj.tft.fillRect(x_pos+1, 121, 10, 118, TFT_BLACK);
  1682. }
  1683. //tftDisplayTime();
  1684. if ( (y_pos_x == 120) || (y_pos_y == 120) || (y_pos_z == 120) )
  1685. {
  1686. display_obj.tft.drawFastHLine(10, 120, 310, TFT_WHITE); // x axis
  1687. }
  1688. y_pos_x_old = y_pos_x; //set old y pos values to current y pos values
  1689. y_pos_y_old = y_pos_y;
  1690. y_pos_z_old = y_pos_z;
  1691. //delay(50);
  1692. }
  1693. sd_obj.main();
  1694. }
  1695. display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK); //erase XY buttons and any lines behind them
  1696. //tft.fillRect(56, 0, 66, 32, TFT_ORANGE); //erase time and color key and any stray lines behind them
  1697. display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
  1698. display_obj.tftDrawXScaleButtons(x_scale); //redraw stuff
  1699. display_obj.tftDrawYScaleButtons(y_scale);
  1700. display_obj.tftDrawChannelScaleButtons(set_channel);
  1701. display_obj.tftDrawExitScaleButtons();
  1702. display_obj.tftDrawColorKey();
  1703. display_obj.tftDrawGraphObjects(x_scale);
  1704. }
  1705. //void WiFiScan::sniffer_callback(void* buf, wifi_promiscuous_pkt_type_t type) {
  1706. // wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
  1707. // showMetadata(snifferPacket, type);
  1708. //}
  1709. void WiFiScan::changeChannel()
  1710. {
  1711. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1712. delay(1);
  1713. }
  1714. // Function to cycle to the next channel
  1715. void WiFiScan::channelHop()
  1716. {
  1717. set_channel = set_channel + 1;
  1718. if (set_channel > 13) {
  1719. set_channel = 1;
  1720. }
  1721. esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
  1722. delay(1);
  1723. }
  1724. // Function for updating scan status
  1725. void WiFiScan::main(uint32_t currentTime)
  1726. {
  1727. // WiFi operations
  1728. if ((currentScanMode == WIFI_SCAN_PROBE) ||
  1729. (currentScanMode == WIFI_SCAN_AP) ||
  1730. (currentScanMode == WIFI_SCAN_PWN) ||
  1731. (currentScanMode == WIFI_SCAN_ESPRESSIF) ||
  1732. (currentScanMode == WIFI_SCAN_DEAUTH) ||
  1733. (currentScanMode == WIFI_SCAN_ALL))
  1734. {
  1735. if (currentTime - initTime >= 1000)
  1736. {
  1737. initTime = millis();
  1738. channelHop();
  1739. }
  1740. }
  1741. else if (currentScanMode == WIFI_PACKET_MONITOR)
  1742. {
  1743. packetMonitorMain(currentTime);
  1744. }
  1745. else if (currentScanMode == WIFI_SCAN_EAPOL)
  1746. {
  1747. eapolMonitorMain(currentTime);
  1748. }
  1749. else if ((currentScanMode == WIFI_ATTACK_BEACON_SPAM))
  1750. {
  1751. // Need this for loop because getTouch causes ~10ms delay
  1752. // which makes beacon spam less effective
  1753. for (int i = 0; i < 55; i++)
  1754. broadcastRandomSSID(currentTime);
  1755. if (currentTime - initTime >= 1000)
  1756. {
  1757. initTime = millis();
  1758. //Serial.print("packets/sec: ");
  1759. //Serial.println(packets_sent);
  1760. String displayString = "";
  1761. String displayString2 = "";
  1762. displayString.concat("packets/sec: ");
  1763. displayString.concat(packets_sent);
  1764. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  1765. displayString2.concat(" ");
  1766. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1767. display_obj.showCenterText(displayString2, 160);
  1768. display_obj.showCenterText(displayString, 160);
  1769. packets_sent = 0;
  1770. }
  1771. }
  1772. else if ((currentScanMode == WIFI_ATTACK_RICK_ROLL))
  1773. {
  1774. // Need this for loop because getTouch causes ~10ms delay
  1775. // which makes beacon spam less effective
  1776. for (int i = 0; i < 7; i++)
  1777. {
  1778. for (int x = 0; x < (sizeof(rick_roll)/sizeof(char *)); x++)
  1779. {
  1780. broadcastSetSSID(currentTime, rick_roll[x]);
  1781. }
  1782. }
  1783. if (currentTime - initTime >= 1000)
  1784. {
  1785. initTime = millis();
  1786. //Serial.print("packets/sec: ");
  1787. //Serial.println(packets_sent);
  1788. String displayString = "";
  1789. String displayString2 = "";
  1790. displayString.concat("packets/sec: ");
  1791. displayString.concat(packets_sent);
  1792. for (int x = 0; x < STANDARD_FONT_CHAR_LIMIT; x++)
  1793. displayString2.concat(" ");
  1794. display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
  1795. display_obj.showCenterText(displayString2, 160);
  1796. display_obj.showCenterText(displayString, 160);
  1797. packets_sent = 0;
  1798. }
  1799. }
  1800. //else if (currentScanMode == LV_JOIN_WIFI)
  1801. // lv_task_handler();
  1802. }