CommandLine.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. #include "CommandLine.h"
  2. #ifdef ESP32_CAM
  3. bool is_configESPCamera = false;
  4. bool is_initMicroSDCard = false;
  5. #include "FS.h" // SD Card ESP32
  6. #include "SD_MMC.h" // SD Card ESP32
  7. #include "esp_camera.h"
  8. #include "soc/soc.h" // Disable brownout problems
  9. #include "soc/rtc_cntl_reg.h" // Disable brownout problems
  10. #include "driver/rtc_io.h"
  11. // Pin definition for CAMERA_MODEL_AI_THINKER
  12. #define PWDN_GPIO_NUM 32
  13. #define RESET_GPIO_NUM -1
  14. #define XCLK_GPIO_NUM 0
  15. #define SIOD_GPIO_NUM 26
  16. #define SIOC_GPIO_NUM 27
  17. #define Y9_GPIO_NUM 35
  18. #define Y8_GPIO_NUM 34
  19. #define Y7_GPIO_NUM 39
  20. #define Y6_GPIO_NUM 36
  21. #define Y5_GPIO_NUM 21
  22. #define Y4_GPIO_NUM 19
  23. #define Y3_GPIO_NUM 18
  24. #define Y2_GPIO_NUM 5
  25. #define VSYNC_GPIO_NUM 25
  26. #define HREF_GPIO_NUM 23
  27. #define PCLK_GPIO_NUM 22
  28. void configESPCamera() {
  29. if (is_configESPCamera) {
  30. Serial.println("cam1");
  31. return;
  32. }
  33. else is_configESPCamera = true;
  34. Serial.println("cam2");
  35. WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
  36. // Configure Camera parameters
  37. // Object to store the camera configuration parameters
  38. camera_config_t config;
  39. config.ledc_channel = LEDC_CHANNEL_0;
  40. config.ledc_timer = LEDC_TIMER_0;
  41. config.pin_d0 = Y2_GPIO_NUM;
  42. config.pin_d1 = Y3_GPIO_NUM;
  43. config.pin_d2 = Y4_GPIO_NUM;
  44. config.pin_d3 = Y5_GPIO_NUM;
  45. config.pin_d4 = Y6_GPIO_NUM;
  46. config.pin_d5 = Y7_GPIO_NUM;
  47. config.pin_d6 = Y8_GPIO_NUM;
  48. config.pin_d7 = Y9_GPIO_NUM;
  49. config.pin_xclk = XCLK_GPIO_NUM;
  50. config.pin_pclk = PCLK_GPIO_NUM;
  51. config.pin_vsync = VSYNC_GPIO_NUM;
  52. config.pin_href = HREF_GPIO_NUM;
  53. config.pin_sscb_sda = SIOD_GPIO_NUM;
  54. config.pin_sscb_scl = SIOC_GPIO_NUM;
  55. config.pin_pwdn = PWDN_GPIO_NUM;
  56. config.pin_reset = RESET_GPIO_NUM;
  57. config.xclk_freq_hz = 20000000;
  58. config.pixel_format = PIXFORMAT_JPEG; // Choices are YUV422, GRAYSCALE, RGB565, JPEG
  59. // Select lower framesize if the camera doesn't support PSRAM
  60. if (psramFound()) {
  61. config.frame_size = FRAMESIZE_UXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
  62. config.jpeg_quality = 10; //10-63 lower number means higher quality
  63. config.fb_count = 2;
  64. } else {
  65. config.frame_size = FRAMESIZE_SVGA;
  66. config.jpeg_quality = 12;
  67. config.fb_count = 1;
  68. }
  69. // Initialize the Camera
  70. esp_err_t err = esp_camera_init(&config);
  71. if (err != ESP_OK) {
  72. Serial.printf("Camera init failed with error 0x%x", err);
  73. return;
  74. }
  75. // Camera quality adjustments
  76. sensor_t * s = esp_camera_sensor_get();
  77. // BRIGHTNESS (-2 to 2)
  78. s->set_brightness(s, 0);
  79. // CONTRAST (-2 to 2)
  80. s->set_contrast(s, 0);
  81. // SATURATION (-2 to 2)
  82. s->set_saturation(s, 0);
  83. // SPECIAL EFFECTS (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
  84. s->set_special_effect(s, 0);
  85. // WHITE BALANCE (0 = Disable , 1 = Enable)
  86. s->set_whitebal(s, 1);
  87. // AWB GAIN (0 = Disable , 1 = Enable)
  88. s->set_awb_gain(s, 1);
  89. // WB MODES (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
  90. s->set_wb_mode(s, 0);
  91. // EXPOSURE CONTROLS (0 = Disable , 1 = Enable)
  92. s->set_exposure_ctrl(s, 1);
  93. // AEC2 (0 = Disable , 1 = Enable)
  94. s->set_aec2(s, 0);
  95. // AE LEVELS (-2 to 2)
  96. s->set_ae_level(s, 0);
  97. // AEC VALUES (0 to 1200)
  98. s->set_aec_value(s, 300);
  99. // GAIN CONTROLS (0 = Disable , 1 = Enable)
  100. s->set_gain_ctrl(s, 1);
  101. // AGC GAIN (0 to 30)
  102. s->set_agc_gain(s, 0);
  103. // GAIN CEILING (0 to 6)
  104. s->set_gainceiling(s, (gainceiling_t)0);
  105. // BPC (0 = Disable , 1 = Enable)
  106. s->set_bpc(s, 0);
  107. // WPC (0 = Disable , 1 = Enable)
  108. s->set_wpc(s, 1);
  109. // RAW GMA (0 = Disable , 1 = Enable)
  110. s->set_raw_gma(s, 1);
  111. // LENC (0 = Disable , 1 = Enable)
  112. s->set_lenc(s, 1);
  113. // HORIZ MIRROR (0 = Disable , 1 = Enable)
  114. s->set_hmirror(s, 0);
  115. // VERT FLIP (0 = Disable , 1 = Enable)
  116. s->set_vflip(s, 0);
  117. // DCW (0 = Disable , 1 = Enable)
  118. s->set_dcw(s, 1);
  119. // COLOR BAR PATTERN (0 = Disable , 1 = Enable)
  120. s->set_colorbar(s, 0);
  121. }
  122. void initMicroSDCard() {
  123. /*if(is_initMicroSDCard) { Serial.println("sd1"); return; }
  124. else is_initMicroSDCard = true;
  125. Serial.println("sd2");*/
  126. // Start the MicroSD card
  127. Serial.println("Mounting MicroSD Card");
  128. if (!SD_MMC.begin("/sdcard", true, false, SDMMC_FREQ_DEFAULT)) {
  129. Serial.println("MicroSD Card Mount Failed");
  130. return;
  131. }
  132. uint8_t cardType = SD_MMC.cardType();
  133. if (cardType == CARD_NONE) {
  134. Serial.println("No MicroSD Card found");
  135. return;
  136. }
  137. }
  138. void takeNewPhoto(String path) {
  139. // Take Picture with Camera
  140. // Setup frame buffer
  141. camera_fb_t * fb = esp_camera_fb_get();
  142. if (!fb) {
  143. Serial.println("Camera capture failed");
  144. return;
  145. }
  146. // Save picture to microSD card
  147. fs::FS &fs = SD_MMC;
  148. File file = fs.open(path.c_str(), FILE_WRITE);
  149. if (!file) {
  150. Serial.println("Failed to open file in write mode");
  151. }
  152. else {
  153. file.write(fb->buf, fb->len); // payload (image), payload length
  154. Serial.printf("Saved file to path: %s\n", path.c_str());
  155. }
  156. // Close the file
  157. file.close();
  158. // Return the frame buffer back to the driver for reuse
  159. esp_camera_fb_return(fb);
  160. }
  161. #endif
  162. CommandLine::CommandLine() {
  163. }
  164. void CommandLine::RunSetup() {
  165. Serial.println(this->ascii_art);
  166. Serial.println(F("\n\n--------------------------------\n"));
  167. Serial.println(F(" ESP32 Marauder \n"));
  168. Serial.println(" " + version_number + "\n");
  169. Serial.println(F(" By: justcallmekoko\n"));
  170. Serial.println(F("--------------------------------\n\n"));
  171. Serial.print("> ");
  172. }
  173. String CommandLine::getSerialInput() {
  174. String input = "";
  175. if (Serial.available() > 0)
  176. input = Serial.readStringUntil('\n');
  177. input.trim();
  178. return input;
  179. }
  180. void CommandLine::main(uint32_t currentTime) {
  181. String input = this->getSerialInput();
  182. this->runCommand(input);
  183. if (input != "")
  184. Serial.print("> ");
  185. }
  186. LinkedList<String> CommandLine::parseCommand(String input, char* delim) {
  187. LinkedList<String> cmd_args;
  188. if (input != "") {
  189. char fancy[input.length() + 1] = {};
  190. input.toCharArray(fancy, input.length() + 1);
  191. char* ptr = strtok(fancy, delim);
  192. while (ptr != NULL) {
  193. cmd_args.add(String(ptr));
  194. ptr = strtok(NULL, delim);
  195. }
  196. }
  197. return cmd_args;
  198. }
  199. int CommandLine::argSearch(LinkedList<String>* cmd_args_list, String key) {
  200. for (int i = 0; i < cmd_args_list->size(); i++) {
  201. if (cmd_args_list->get(i) == key)
  202. return i;
  203. }
  204. return -1;
  205. }
  206. bool CommandLine::checkValueExists(LinkedList<String>* cmd_args_list, int index) {
  207. if (index < cmd_args_list->size() - 1)
  208. return true;
  209. return false;
  210. }
  211. bool CommandLine::inRange(int max, int index) {
  212. if ((index >= 0) && (index < max))
  213. return true;
  214. return false;
  215. }
  216. bool CommandLine::apSelected() {
  217. for (int i = 0; i < access_points->size(); i++) {
  218. if (access_points->get(i).selected)
  219. return true;
  220. }
  221. return false;
  222. }
  223. bool CommandLine::hasSSIDs() {
  224. if (ssids->size() == 0)
  225. return false;
  226. return true;
  227. }
  228. void CommandLine::runCommand(String input) {
  229. if (input != "")
  230. Serial.println("#" + input);
  231. else
  232. return;
  233. LinkedList<String> cmd_args = this->parseCommand(input, " ");
  234. //// Admin commands
  235. // Help
  236. if (cmd_args.get(0) == HELP_CMD) {
  237. Serial.println(HELP_HEAD);
  238. Serial.println(HELP_CH_CMD);
  239. Serial.println(HELP_SETTINGS_CMD);
  240. Serial.println(HELP_CLEARAP_CMD_A);
  241. Serial.println(HELP_REBOOT_CMD);
  242. Serial.println(HELP_UPDATE_CMD_A);
  243. // WiFi sniff/scan
  244. Serial.println(HELP_SCANAP_CMD);
  245. Serial.println(HELP_SCANSTA_CMD);
  246. Serial.println(HELP_SNIFF_RAW_CMD);
  247. Serial.println(HELP_SNIFF_BEACON_CMD);
  248. Serial.println(HELP_SNIFF_PROBE_CMD);
  249. Serial.println(HELP_SNIFF_PWN_CMD);
  250. Serial.println(HELP_SNIFF_ESP_CMD);
  251. Serial.println(HELP_SNIFF_DEAUTH_CMD);
  252. Serial.println(HELP_SNIFF_PMKID_CMD);
  253. Serial.println(HELP_STOPSCAN_CMD);
  254. // WiFi attack
  255. Serial.println(HELP_ATTACK_CMD);
  256. // WiFi Aux
  257. Serial.println(HELP_LIST_AP_CMD_A);
  258. Serial.println(HELP_LIST_AP_CMD_B);
  259. Serial.println(HELP_LIST_AP_CMD_C);
  260. Serial.println(HELP_SEL_CMD_A);
  261. Serial.println(HELP_SSID_CMD_A);
  262. Serial.println(HELP_SSID_CMD_B);
  263. // Bluetooth sniff/scan
  264. Serial.println(HELP_BT_SNIFF_CMD);
  265. Serial.println(HELP_BT_SKIM_CMD);
  266. Serial.println(HELP_FOOT);
  267. return;
  268. }
  269. // Stop Scan
  270. if (cmd_args.get(0) == STOPSCAN_CMD) {
  271. if (wifi_scan_obj.currentScanMode == OTA_UPDATE) {
  272. wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
  273. //#ifdef HAS_SCREEN
  274. // menu_function_obj.changeMenu(menu_function_obj.updateMenu.parentMenu);
  275. //#endif
  276. WiFi.softAPdisconnect(true);
  277. web_obj.shutdownServer();
  278. return;
  279. }
  280. wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
  281. Serial.println("Stopping WiFi tran/recv");
  282. // If we don't do this, the text and button coordinates will be off
  283. #ifdef HAS_SCREEN
  284. display_obj.tft.init();
  285. menu_function_obj.changeMenu(menu_function_obj.current_menu);
  286. #endif
  287. }
  288. // Channel command
  289. else if (cmd_args.get(0) == CH_CMD) {
  290. // Search for channel set arg
  291. int ch_set = this->argSearch(&cmd_args, "-s");
  292. if (cmd_args.size() == 1) {
  293. Serial.println("Current channel: " + (String)wifi_scan_obj.set_channel);
  294. }
  295. else if (ch_set != -1) {
  296. wifi_scan_obj.set_channel = cmd_args.get(ch_set + 1).toInt();
  297. wifi_scan_obj.changeChannel();
  298. Serial.println("Set channel: " + (String)wifi_scan_obj.set_channel);
  299. }
  300. }
  301. #ifdef ESP32_CAM
  302. else if (cmd_args.get(0) == CAM_FLASHLIGHT) {
  303. pinMode(4, OUTPUT);
  304. digitalWrite(4, !digitalRead(4));
  305. }
  306. else if (cmd_args.get(0) == CAM_PHOTO) {
  307. Serial.println("Camera capture start");
  308. pinMode(4, OUTPUT);
  309. digitalWrite(4, HIGH);
  310. // Initialize the camera
  311. configESPCamera(); Serial.println("Camera OK!");
  312. // Initialize the MicroSD
  313. Serial.print("Initializing the MicroSD card module... ");
  314. initMicroSDCard();
  315. int i = 0;
  316. while (true)
  317. {
  318. String path = "/photo_" + String(i++) + ".jpg";
  319. if (!SD_MMC.exists(path.c_str()))
  320. {
  321. takeNewPhoto(path);
  322. break;
  323. }
  324. }
  325. // Turns off the ESP32-CAM white on-board LED (flash) connected to GPIO 4
  326. digitalWrite(4, LOW);
  327. //rtc_gpio_hold_en(GPIO_NUM_4);
  328. Serial.println("Camera capture finish");
  329. }
  330. #endif
  331. // Clear APs
  332. else if (cmd_args.get(0) == CLEARAP_CMD) {
  333. int ap_sw = this->argSearch(&cmd_args, "-a"); // APs
  334. int ss_sw = this->argSearch(&cmd_args, "-s"); // SSIDs
  335. int cl_sw = this->argSearch(&cmd_args, "-c"); // Stations
  336. if (ap_sw != -1) {
  337. #ifdef HAS_SCREEN
  338. menu_function_obj.changeMenu(&menu_function_obj.clearAPsMenu);
  339. #endif
  340. wifi_scan_obj.RunClearAPs();
  341. }
  342. if (ss_sw != -1) {
  343. #ifdef HAS_SCREEN
  344. menu_function_obj.changeMenu(&menu_function_obj.clearSSIDsMenu);
  345. #endif
  346. wifi_scan_obj.RunClearSSIDs();
  347. }
  348. if (cl_sw != -1) {
  349. #ifdef HAS_SCREEN
  350. menu_function_obj.changeMenu(&menu_function_obj.clearAPsMenu);
  351. #endif
  352. wifi_scan_obj.RunClearStations();
  353. }
  354. }
  355. else if (cmd_args.get(0) == SETTINGS_CMD) {
  356. int ss_sw = this->argSearch(&cmd_args, "-s"); // Set setting
  357. int re_sw = this->argSearch(&cmd_args, "-r"); // Reset setting
  358. int en_sw = this->argSearch(&cmd_args, "enable"); // enable setting
  359. int da_sw = this->argSearch(&cmd_args, "disable"); // disable setting
  360. if (re_sw != -1) {
  361. settings_obj.createDefaultSettings(SPIFFS);
  362. return;
  363. }
  364. if (ss_sw == -1) {
  365. settings_obj.printJsonSettings(settings_obj.getSettingsString());
  366. }
  367. else {
  368. bool result = false;
  369. String setting_name = cmd_args.get(ss_sw + 1);
  370. if (en_sw != -1)
  371. result = settings_obj.saveSetting<bool>(setting_name, true);
  372. else if (da_sw != -1)
  373. result = settings_obj.saveSetting<bool>(setting_name, false);
  374. else {
  375. Serial.println("You did not properly enable/disable this setting.");
  376. return;
  377. }
  378. if (!result) {
  379. Serial.println("Could not successfully update setting \"" + setting_name + "\"");
  380. return;
  381. }
  382. }
  383. }
  384. else if (cmd_args.get(0) == REBOOT_CMD) {
  385. Serial.println("Rebooting...");
  386. ESP.restart();
  387. }
  388. //// WiFi/Bluetooth Scan/Attack commands
  389. if (!wifi_scan_obj.scanning()) {
  390. // AP Scan
  391. if (cmd_args.get(0) == SCANAP_CMD) {
  392. int full_sw = -1;
  393. #ifdef HAS_SCREEN
  394. display_obj.clearScreen();
  395. menu_function_obj.drawStatusBar();
  396. #endif
  397. if (full_sw == -1) {
  398. Serial.println("Starting AP scan. Stop with " + (String)STOPSCAN_CMD);
  399. wifi_scan_obj.StartScan(WIFI_SCAN_TARGET_AP, TFT_MAGENTA);
  400. }
  401. else {
  402. Serial.println("Starting Full AP scan. Stop with " + (String)STOPSCAN_CMD);
  403. wifi_scan_obj.StartScan(WIFI_SCAN_TARGET_AP_FULL, TFT_MAGENTA);
  404. }
  405. }
  406. // Raw sniff
  407. else if (cmd_args.get(0) == SNIFF_RAW_CMD) {
  408. Serial.println("Starting Raw sniff. Stop with " + (String)STOPSCAN_CMD);
  409. #ifdef HAS_SCREEN
  410. display_obj.clearScreen();
  411. menu_function_obj.drawStatusBar();
  412. #endif
  413. wifi_scan_obj.StartScan(WIFI_SCAN_RAW_CAPTURE, TFT_WHITE);
  414. }
  415. // Scan stations
  416. else if (cmd_args.get(0) == SCANSTA_CMD) {
  417. Serial.println("Starting Station scan. Stop with " + (String)STOPSCAN_CMD);
  418. #ifdef HAS_SCREEN
  419. display_obj.clearScreen();
  420. menu_function_obj.drawStatusBar();
  421. #endif
  422. wifi_scan_obj.StartScan(WIFI_SCAN_STATION, TFT_ORANGE);
  423. }
  424. // Beacon sniff
  425. else if (cmd_args.get(0) == SNIFF_BEACON_CMD) {
  426. Serial.println("Starting Beacon sniff. Stop with " + (String)STOPSCAN_CMD);
  427. #ifdef HAS_SCREEN
  428. display_obj.clearScreen();
  429. menu_function_obj.drawStatusBar();
  430. #endif
  431. wifi_scan_obj.StartScan(WIFI_SCAN_AP, TFT_MAGENTA);
  432. }
  433. // Probe sniff
  434. else if (cmd_args.get(0) == SNIFF_PROBE_CMD) {
  435. Serial.println("Starting Probe sniff. Stop with " + (String)STOPSCAN_CMD);
  436. #ifdef HAS_SCREEN
  437. display_obj.clearScreen();
  438. menu_function_obj.drawStatusBar();
  439. #endif
  440. wifi_scan_obj.StartScan(WIFI_SCAN_PROBE, TFT_MAGENTA);
  441. }
  442. // Deauth sniff
  443. else if (cmd_args.get(0) == SNIFF_DEAUTH_CMD) {
  444. Serial.println("Starting Deauth sniff. Stop with " + (String)STOPSCAN_CMD);
  445. #ifdef HAS_SCREEN
  446. display_obj.clearScreen();
  447. menu_function_obj.drawStatusBar();
  448. #endif
  449. wifi_scan_obj.StartScan(WIFI_SCAN_DEAUTH, TFT_RED);
  450. }
  451. // Pwn sniff
  452. else if (cmd_args.get(0) == SNIFF_PWN_CMD) {
  453. Serial.println("Starting Pwnagotchi sniff. Stop with " + (String)STOPSCAN_CMD);
  454. #ifdef HAS_SCREEN
  455. display_obj.clearScreen();
  456. menu_function_obj.drawStatusBar();
  457. #endif
  458. wifi_scan_obj.StartScan(WIFI_SCAN_PWN, TFT_MAGENTA);
  459. }
  460. // Espressif sniff
  461. else if (cmd_args.get(0) == SNIFF_ESP_CMD) {
  462. Serial.println("Starting Espressif device sniff. Stop with " + (String)STOPSCAN_CMD);
  463. #ifdef HAS_SCREEN
  464. display_obj.clearScreen();
  465. menu_function_obj.drawStatusBar();
  466. #endif
  467. wifi_scan_obj.StartScan(WIFI_SCAN_ESPRESSIF, TFT_MAGENTA);
  468. }
  469. // PMKID sniff
  470. else if (cmd_args.get(0) == SNIFF_PMKID_CMD) {
  471. int ch_sw = this->argSearch(&cmd_args, "-c");
  472. int d_sw = this->argSearch(&cmd_args, "-d"); // Deauth for pmkid
  473. if (ch_sw != -1) {
  474. wifi_scan_obj.set_channel = cmd_args.get(ch_sw + 1).toInt();
  475. wifi_scan_obj.changeChannel();
  476. Serial.println("Set channel: " + (String)wifi_scan_obj.set_channel);
  477. }
  478. if (d_sw == -1) {
  479. Serial.println("Starting PMKID sniff on channel " + (String)wifi_scan_obj.set_channel + ". Stop with " + (String)STOPSCAN_CMD);
  480. wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
  481. }
  482. else {
  483. Serial.println("Starting PMKID sniff with deauthentication on channel " + (String)wifi_scan_obj.set_channel + ". Stop with " + (String)STOPSCAN_CMD);
  484. wifi_scan_obj.StartScan(WIFI_SCAN_ACTIVE_EAPOL, TFT_VIOLET);
  485. }
  486. }
  487. //// WiFi attack commands
  488. // attack
  489. if (cmd_args.get(0) == ATTACK_CMD) {
  490. int attack_type_switch = this->argSearch(&cmd_args, "-t"); // Required
  491. int list_beacon_sw = this->argSearch(&cmd_args, "-l");
  492. int rand_beacon_sw = this->argSearch(&cmd_args, "-r");
  493. int ap_beacon_sw = this->argSearch(&cmd_args, "-a");
  494. int src_addr_sw = this->argSearch(&cmd_args, "-s");
  495. int dst_addr_sw = this->argSearch(&cmd_args, "-d");
  496. int targ_sw = this->argSearch(&cmd_args, "-c");
  497. if (attack_type_switch == -1) {
  498. Serial.println("You must specify an attack type");
  499. return;
  500. }
  501. else {
  502. String attack_type = cmd_args.get(attack_type_switch + 1);
  503. // Branch on attack type
  504. // Deauth
  505. if (attack_type == ATTACK_TYPE_DEAUTH) {
  506. // Default to broadcast
  507. if ((dst_addr_sw == -1) && (targ_sw == -1)) {
  508. Serial.println("Sending to broadcast...");
  509. wifi_scan_obj.dst_mac = "ff:ff:ff:ff:ff:ff";
  510. }
  511. // Dest addr specified
  512. else if (dst_addr_sw != -1) {
  513. wifi_scan_obj.dst_mac = cmd_args.get(dst_addr_sw + 1);
  514. Serial.println("Sending to " + wifi_scan_obj.dst_mac + "...");
  515. }
  516. // Station list specified
  517. else if (targ_sw != -1)
  518. Serial.println("Sending to Station list");
  519. // Source addr not specified
  520. if (src_addr_sw == -1) {
  521. if (!this->apSelected()) {
  522. Serial.println("You don't have any targets selected. Use " + (String)SEL_CMD);
  523. return;
  524. }
  525. #ifdef HAS_SCREEN
  526. display_obj.clearScreen();
  527. menu_function_obj.drawStatusBar();
  528. #endif
  529. Serial.println("Starting Deauthentication attack. Stop with " + (String)STOPSCAN_CMD);
  530. // Station list not specified
  531. if (targ_sw == -1)
  532. wifi_scan_obj.StartScan(WIFI_ATTACK_DEAUTH, TFT_RED);
  533. // Station list specified
  534. else
  535. wifi_scan_obj.StartScan(WIFI_ATTACK_DEAUTH_TARGETED, TFT_ORANGE);
  536. }
  537. // Source addr specified
  538. else {
  539. String src_mac_str = cmd_args.get(src_addr_sw + 1);
  540. sscanf(src_mac_str.c_str(), "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
  541. &wifi_scan_obj.src_mac[0], &wifi_scan_obj.src_mac[1], &wifi_scan_obj.src_mac[2], &wifi_scan_obj.src_mac[3], &wifi_scan_obj.src_mac[4], &wifi_scan_obj.src_mac[5]);
  542. #ifdef HAS_SCREEN
  543. display_obj.clearScreen();
  544. menu_function_obj.drawStatusBar();
  545. #endif
  546. Serial.println("Starting Manual Deauthentication attack. Stop with " + (String)STOPSCAN_CMD);
  547. wifi_scan_obj.StartScan(WIFI_ATTACK_DEAUTH_MANUAL, TFT_RED);
  548. }
  549. }
  550. // Beacon
  551. else if (attack_type == ATTACK_TYPE_BEACON) {
  552. // spam by list
  553. if (list_beacon_sw != -1) {
  554. if (!this->hasSSIDs()) {
  555. Serial.println("You don't have any SSIDs in your list. Use " + (String)SSID_CMD);
  556. return;
  557. }
  558. #ifdef HAS_SCREEN
  559. display_obj.clearScreen();
  560. menu_function_obj.drawStatusBar();
  561. #endif
  562. Serial.println("Starting Beacon list spam. Stop with " + (String)STOPSCAN_CMD);
  563. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_LIST, TFT_RED);
  564. }
  565. // spam with random
  566. else if (rand_beacon_sw != -1) {
  567. #ifdef HAS_SCREEN
  568. display_obj.clearScreen();
  569. menu_function_obj.drawStatusBar();
  570. #endif
  571. Serial.println("Starting random Beacon spam. Stop with " + (String)STOPSCAN_CMD);
  572. wifi_scan_obj.StartScan(WIFI_ATTACK_BEACON_SPAM, TFT_ORANGE);
  573. }
  574. // Spam from AP list
  575. else if (ap_beacon_sw != -1) {
  576. if (!this->apSelected()) {
  577. Serial.println("You don't have any targets selected. Use " + (String)SEL_CMD);
  578. return;
  579. }
  580. #ifdef HAS_SCREEN
  581. display_obj.clearScreen();
  582. menu_function_obj.drawStatusBar();
  583. #endif
  584. Serial.println("Starting Targeted AP Beacon spam. Stop with " + (String)STOPSCAN_CMD);
  585. wifi_scan_obj.StartScan(WIFI_ATTACK_AP_SPAM, TFT_MAGENTA);
  586. }
  587. else {
  588. Serial.println("You did not specify a beacon attack type");
  589. }
  590. }
  591. else if (attack_type == ATTACK_TYPE_PROBE) {
  592. if (!this->apSelected()) {
  593. Serial.println("You don't have any targets selected. Use " + (String)SEL_CMD);
  594. return;
  595. }
  596. Serial.println("Starting Probe spam. Stop with " + (String)STOPSCAN_CMD);
  597. #ifdef HAS_SCREEN
  598. display_obj.clearScreen();
  599. menu_function_obj.drawStatusBar();
  600. #endif
  601. wifi_scan_obj.StartScan(WIFI_ATTACK_AUTH, TFT_RED);
  602. }
  603. else if (attack_type == ATTACK_TYPE_RR) {
  604. Serial.println("Starting Rick Roll Beacon spam. Stop with " + (String)STOPSCAN_CMD);
  605. #ifdef HAS_SCREEN
  606. display_obj.clearScreen();
  607. menu_function_obj.drawStatusBar();
  608. #endif
  609. wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);
  610. }
  611. else {
  612. Serial.println("Attack type not properly defined");
  613. return;
  614. }
  615. }
  616. }
  617. //// Bluetooth scan/attack commands
  618. // Bluetooth scan
  619. if (cmd_args.get(0) == BT_SNIFF_CMD) {
  620. Serial.println("Starting Bluetooth scan. Stop with " + (String)STOPSCAN_CMD);
  621. #ifdef HAS_SCREEN
  622. display_obj.clearScreen();
  623. menu_function_obj.drawStatusBar();
  624. #endif
  625. wifi_scan_obj.StartScan(BT_SCAN_ALL, TFT_GREEN);
  626. }
  627. // Bluetooth CC Skimmer scan
  628. else if (cmd_args.get(0) == BT_SKIM_CMD) {
  629. Serial.println("Starting Bluetooth CC Skimmer scan. Stop with " + (String)STOPSCAN_CMD);
  630. #ifdef HAS_SCREEN
  631. display_obj.clearScreen();
  632. menu_function_obj.drawStatusBar();
  633. #endif
  634. wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA);
  635. }
  636. // Update command
  637. if (cmd_args.get(0) == UPDATE_CMD) {
  638. int w_sw = this->argSearch(&cmd_args, "-w"); // Web update
  639. int sd_sw = this->argSearch(&cmd_args, "-s"); // SD Update
  640. // Update via OTA
  641. if (w_sw != -1) {
  642. Serial.println("Starting Marauder OTA Update. Stop with " + (String)STOPSCAN_CMD);
  643. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  644. //#ifdef HAS_SCREEN
  645. // menu_function_obj.changeMenu(menu_function_obj.updateMenu);
  646. //#endif
  647. web_obj.setupOTAupdate();
  648. }
  649. // Update via SD
  650. else if (sd_sw != -1) {
  651. if (!sd_obj.supported) {
  652. Serial.println("SD card is not connected. Cannot perform SD Update");
  653. return;
  654. }
  655. wifi_scan_obj.currentScanMode = OTA_UPDATE;
  656. sd_obj.runUpdate();
  657. }
  658. }
  659. }
  660. //// WiFi aux commands
  661. // List access points
  662. if (cmd_args.get(0) == LIST_AP_CMD) {
  663. int ap_sw = this->argSearch(&cmd_args, "-a");
  664. int ss_sw = this->argSearch(&cmd_args, "-s");
  665. int cl_sw = this->argSearch(&cmd_args, "-c");
  666. // List APs
  667. if (ap_sw != -1) {
  668. for (int i = 0; i < access_points->size(); i++) {
  669. if (access_points->get(i).selected)
  670. Serial.println("[" + (String)i + "] " + access_points->get(i).essid + " " + (String)access_points->get(i).rssi + " (selected)");
  671. else
  672. Serial.println("[" + (String)i + "] " + access_points->get(i).essid + " " + (String)access_points->get(i).rssi);
  673. }
  674. }
  675. // List SSIDs
  676. else if (ss_sw != -1) {
  677. for (int i = 0; i < ssids->size(); i++) {
  678. if (ssids->get(i).selected)
  679. Serial.println("[" + (String)i + "] " + ssids->get(i).essid + " (selected)");
  680. else
  681. Serial.println("[" + (String)i + "] " + ssids->get(i).essid);
  682. }
  683. }
  684. // List Stations
  685. else if (cl_sw != -1) {
  686. char sta_mac[] = "00:00:00:00:00:00";
  687. for (int x = 0; x < access_points->size(); x++) {
  688. Serial.println("[" + (String)x + "] " + access_points->get(x).essid + " " + (String)access_points->get(x).rssi + ":");
  689. for (int i = 0; i < access_points->get(x).stations->size(); i++) {
  690. wifi_scan_obj.getMAC(sta_mac, stations->get(access_points->get(x).stations->get(i)).mac, 0);
  691. if (stations->get(access_points->get(x).stations->get(i)).selected) {
  692. Serial.print(" [" + (String)access_points->get(x).stations->get(i) + "] ");
  693. Serial.print(sta_mac);
  694. Serial.println(" (selected)");
  695. }
  696. else {
  697. Serial.print(" [" + (String)access_points->get(x).stations->get(i) + "] ");
  698. Serial.println(sta_mac);
  699. }
  700. }
  701. }
  702. }
  703. else {
  704. Serial.println("You did not specify which list to show");
  705. return;
  706. }
  707. }
  708. // Select access points or stations
  709. else if (cmd_args.get(0) == SEL_CMD) {
  710. // Get switches
  711. int ap_sw = this->argSearch(&cmd_args, "-a");
  712. int ss_sw = this->argSearch(&cmd_args, "-s");
  713. int cl_sw = this->argSearch(&cmd_args, "-c");
  714. // select Access points
  715. if (ap_sw != -1) {
  716. // Get list of indices
  717. LinkedList<String> ap_index = this->parseCommand(cmd_args.get(ap_sw + 1), ",");
  718. // Select ALL APs
  719. if (cmd_args.get(ap_sw + 1) == "all") {
  720. for (int i = 0; i < access_points->size(); i++) {
  721. if (access_points->get(i).selected) {
  722. // Unselect "selected" ap
  723. AccessPoint new_ap = access_points->get(i);
  724. new_ap.selected = false;
  725. access_points->set(i, new_ap);
  726. }
  727. else {
  728. // Select "unselected" ap
  729. AccessPoint new_ap = access_points->get(i);
  730. new_ap.selected = true;
  731. access_points->set(i, new_ap);
  732. }
  733. }
  734. }
  735. // Select specific APs
  736. else {
  737. // Mark APs as selected
  738. for (int i = 0; i < ap_index.size(); i++) {
  739. int index = ap_index.get(i).toInt();
  740. if (!this->inRange(access_points->size(), index)) {
  741. Serial.println("Index not in range: " + (String)index);
  742. continue;
  743. }
  744. if (access_points->get(index).selected) {
  745. // Unselect "selected" ap
  746. AccessPoint new_ap = access_points->get(index);
  747. new_ap.selected = false;
  748. access_points->set(index, new_ap);
  749. }
  750. else {
  751. // Select "unselected" ap
  752. AccessPoint new_ap = access_points->get(index);
  753. new_ap.selected = true;
  754. access_points->set(index, new_ap);
  755. }
  756. }
  757. }
  758. }
  759. else if (cl_sw != -1) {
  760. LinkedList<String> sta_index = this->parseCommand(cmd_args.get(cl_sw + 1), ",");
  761. // Select all Stations
  762. if (cmd_args.get(cl_sw + 1) == "all") {
  763. for (int i = 0; i < stations->size(); i++) {
  764. if (stations->get(i).selected) {
  765. // Unselect "selected" ap
  766. Station new_sta = stations->get(i);
  767. new_sta.selected = false;
  768. stations->set(i, new_sta);
  769. }
  770. else {
  771. // Select "unselected" ap
  772. Station new_sta = stations->get(i);
  773. new_sta.selected = true;
  774. stations->set(i, new_sta);
  775. }
  776. }
  777. }
  778. // Select specific Stations
  779. else {
  780. // Mark Stations as selected
  781. for (int i = 0; i < sta_index.size(); i++) {
  782. int index = sta_index.get(i).toInt();
  783. if (!this->inRange(stations->size(), index)) {
  784. Serial.println("Index not in range: " + (String)index);
  785. continue;
  786. }
  787. if (stations->get(index).selected) {
  788. // Unselect "selected" ap
  789. Station new_sta = stations->get(index);
  790. new_sta.selected = false;
  791. stations->set(index, new_sta);
  792. }
  793. else {
  794. // Select "unselected" ap
  795. Station new_sta = stations->get(index);
  796. new_sta.selected = true;
  797. stations->set(index, new_sta);
  798. }
  799. }
  800. }
  801. }
  802. // select ssids
  803. else if (ss_sw != -1) {
  804. // Get list of indices
  805. LinkedList<String> ss_index = this->parseCommand(cmd_args.get(ss_sw + 1), ",");
  806. // Mark APs as selected
  807. for (int i = 0; i < ss_index.size(); i++) {
  808. int index = ss_index.get(i).toInt();
  809. if (!this->inRange(ssids->size(), index)) {
  810. Serial.println("Index not in range: " + (String)index);
  811. continue;
  812. }
  813. if (ssids->get(index).selected) {
  814. // Unselect "selected" ap
  815. ssid new_ssid = ssids->get(index);
  816. new_ssid.selected = false;
  817. ssids->set(index, new_ssid);
  818. }
  819. else {
  820. // Select "unselected" ap
  821. ssid new_ssid = ssids->get(index);
  822. new_ssid.selected = true;
  823. ssids->set(index, new_ssid);
  824. }
  825. }
  826. }
  827. else {
  828. Serial.println("You did not specify which list to select from");
  829. return;
  830. }
  831. }
  832. // SSID stuff
  833. else if (cmd_args.get(0) == SSID_CMD) {
  834. int add_sw = this->argSearch(&cmd_args, "-a");
  835. int gen_sw = this->argSearch(&cmd_args, "-g");
  836. int spc_sw = this->argSearch(&cmd_args, "-n");
  837. int rem_sw = this->argSearch(&cmd_args, "-r");
  838. // Add ssid
  839. if (add_sw != -1) {
  840. // Generate random
  841. if (gen_sw != -1) {
  842. int gen_count = cmd_args.get(gen_sw + 1).toInt();
  843. wifi_scan_obj.generateSSIDs(gen_count);
  844. }
  845. // Add specific
  846. else if (spc_sw != -1) {
  847. String essid = cmd_args.get(spc_sw + 1);
  848. wifi_scan_obj.addSSID(essid);
  849. }
  850. else {
  851. Serial.println("You did not specify how to add SSIDs");
  852. }
  853. }
  854. // Remove SSID
  855. else if (rem_sw != -1) {
  856. int index = cmd_args.get(rem_sw + 1).toInt();
  857. if (!this->inRange(ssids->size(), index)) {
  858. Serial.println("Index not in range: " + (String)index);
  859. return;
  860. }
  861. ssids->remove(index);
  862. }
  863. else {
  864. Serial.println("You did not specify whether to add or remove SSIDs");
  865. return;
  866. }
  867. }
  868. }