wifi_marauder_script_executor.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. #include "../wifi_marauder_app_i.h"
  2. #include "wifi_marauder_script_executor.h"
  3. void _wifi_marauder_script_delay(WifiMarauderScriptWorker* worker, uint32_t delay_secs) {
  4. for(uint32_t i = 0; i < delay_secs && worker->is_running; i++) furi_delay_ms(1000);
  5. }
  6. void _send_stop(WifiMarauderScriptWorker* worker) {
  7. const char stop_command[] = "stopscan\n";
  8. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(stop_command), strlen(stop_command));
  9. }
  10. void _send_line_break(WifiMarauderScriptWorker* worker) {
  11. wifi_marauder_uart_tx(worker->uart, (uint8_t*)("\n"), 1);
  12. }
  13. void _send_channel_select(WifiMarauderScriptWorker* worker, int channel) {
  14. char command[30];
  15. _send_line_break(worker);
  16. snprintf(command, sizeof(command), "channel -s %d\n", channel);
  17. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(command), strlen(command));
  18. }
  19. void _wifi_marauder_script_execute_scan(
  20. WifiMarauderScriptStageScan* stage,
  21. WifiMarauderScriptWorker* worker) {
  22. char command[15];
  23. // Set channel
  24. if(stage->channel > 0) {
  25. _send_channel_select(worker, stage->channel);
  26. }
  27. // Start scan
  28. if(stage->type == WifiMarauderScriptScanTypeAp) {
  29. snprintf(command, sizeof(command), "scanap\n");
  30. } else {
  31. snprintf(command, sizeof(command), "scansta\n");
  32. }
  33. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(command), strlen(command));
  34. _wifi_marauder_script_delay(worker, stage->timeout);
  35. _send_stop(worker);
  36. }
  37. void _wifi_marauder_script_execute_select(
  38. WifiMarauderScriptStageSelect* stage,
  39. WifiMarauderScriptWorker* worker) {
  40. const char* select_type = NULL;
  41. switch(stage->type) {
  42. case WifiMarauderScriptSelectTypeAp:
  43. select_type = "-a";
  44. break;
  45. case WifiMarauderScriptSelectTypeStation:
  46. select_type = "-c";
  47. break;
  48. case WifiMarauderScriptSelectTypeSsid:
  49. select_type = "-s";
  50. break;
  51. default:
  52. return; // invalid stage
  53. }
  54. char command[256];
  55. size_t command_length = 0;
  56. if(stage->indexes != NULL && stage->index_count > 0) {
  57. command_length = snprintf(command, sizeof(command), "select %s ", select_type);
  58. for(int i = 0; i < stage->index_count; i++) {
  59. int index = stage->indexes[i];
  60. command_length += snprintf(
  61. command + command_length, sizeof(command) - command_length, "%d, ", index);
  62. }
  63. // Remove the trailing comma and space
  64. command_length -= 2;
  65. command[command_length] = '\n';
  66. command_length++;
  67. } else if(stage->filter == NULL || strcmp(stage->filter, "all") == 0) {
  68. command_length = snprintf(command, sizeof(command), "select %s all\n", select_type);
  69. } else {
  70. command_length = snprintf(
  71. command, sizeof(command), "select %s -f \"%s\"\n", select_type, stage->filter);
  72. }
  73. wifi_marauder_uart_tx(worker->uart, (uint8_t*)command, command_length);
  74. }
  75. void _wifi_marauder_script_execute_deauth(
  76. WifiMarauderScriptStageDeauth* stage,
  77. WifiMarauderScriptWorker* worker) {
  78. const char attack_command[] = "attack -t deauth\n";
  79. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(attack_command), strlen(attack_command));
  80. _wifi_marauder_script_delay(worker, stage->timeout);
  81. _send_stop(worker);
  82. }
  83. void _wifi_marauder_script_execute_probe(
  84. WifiMarauderScriptStageProbe* stage,
  85. WifiMarauderScriptWorker* worker) {
  86. const char attack_command[] = "attack -t probe\n";
  87. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(attack_command), strlen(attack_command));
  88. _wifi_marauder_script_delay(worker, stage->timeout);
  89. _send_stop(worker);
  90. }
  91. void _wifi_marauder_script_execute_sniff_raw(
  92. WifiMarauderScriptStageSniffRaw* stage,
  93. WifiMarauderScriptWorker* worker) {
  94. const char sniff_command[] = "sniffraw";
  95. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  96. if(((WifiMarauderScript*)worker->context)->save_pcap != WifiMarauderScriptBooleanFalse) {
  97. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(" -serial\n"), strlen(" -serial\n"));
  98. } else {
  99. wifi_marauder_uart_tx(worker->uart, (uint8_t*)("\n"), 1);
  100. }
  101. _wifi_marauder_script_delay(worker, stage->timeout);
  102. _send_stop(worker);
  103. }
  104. void _wifi_marauder_script_execute_sniff_beacon(
  105. WifiMarauderScriptStageSniffBeacon* stage,
  106. WifiMarauderScriptWorker* worker) {
  107. const char sniff_command[] = "sniffbeacon";
  108. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  109. if(((WifiMarauderScript*)worker->context)->save_pcap != WifiMarauderScriptBooleanFalse) {
  110. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(" -serial\n"), strlen(" -serial\n"));
  111. } else {
  112. wifi_marauder_uart_tx(worker->uart, (uint8_t*)("\n"), 1);
  113. }
  114. _wifi_marauder_script_delay(worker, stage->timeout);
  115. _send_stop(worker);
  116. }
  117. void _wifi_marauder_script_execute_sniff_deauth(
  118. WifiMarauderScriptStageSniffDeauth* stage,
  119. WifiMarauderScriptWorker* worker) {
  120. const char sniff_command[] = "sniffdeauth";
  121. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  122. if(((WifiMarauderScript*)worker->context)->save_pcap != WifiMarauderScriptBooleanFalse) {
  123. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(" -serial\n"), strlen(" -serial\n"));
  124. } else {
  125. wifi_marauder_uart_tx(worker->uart, (uint8_t*)("\n"), 1);
  126. }
  127. _wifi_marauder_script_delay(worker, stage->timeout);
  128. _send_stop(worker);
  129. }
  130. void _wifi_marauder_script_execute_sniff_esp(
  131. WifiMarauderScriptStageSniffEsp* stage,
  132. WifiMarauderScriptWorker* worker) {
  133. const char sniff_command[] = "sniffesp";
  134. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  135. if(((WifiMarauderScript*)worker->context)->save_pcap != WifiMarauderScriptBooleanFalse) {
  136. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(" -serial\n"), strlen(" -serial\n"));
  137. } else {
  138. wifi_marauder_uart_tx(worker->uart, (uint8_t*)("\n"), 1);
  139. }
  140. _wifi_marauder_script_delay(worker, stage->timeout);
  141. _send_stop(worker);
  142. }
  143. void _wifi_marauder_script_execute_sniff_pmkid(
  144. WifiMarauderScriptStageSniffPmkid* stage,
  145. WifiMarauderScriptWorker* worker) {
  146. // If channel hopping is enabled, loop through channels 1-11
  147. if(stage->hop_channels) {
  148. for(int i = 1; i <= 11; i++) {
  149. char attack_command[50] = "sniffpmkid";
  150. int len = strlen(attack_command);
  151. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -c %d", i);
  152. if(stage->force_deauth) {
  153. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -d");
  154. }
  155. if(((WifiMarauderScript*)worker->context)->save_pcap !=
  156. WifiMarauderScriptBooleanFalse) {
  157. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -serial\n");
  158. } else {
  159. len += snprintf(attack_command + len, sizeof(attack_command) - len, "\n");
  160. }
  161. wifi_marauder_uart_tx(worker->uart, (uint8_t*)attack_command, len);
  162. _wifi_marauder_script_delay(worker, stage->timeout);
  163. _send_stop(worker);
  164. }
  165. } else {
  166. char attack_command[50] = "sniffpmkid";
  167. int len = strlen(attack_command);
  168. if(stage->channel > 0) {
  169. len += snprintf(
  170. attack_command + len, sizeof(attack_command) - len, " -c %d", stage->channel);
  171. }
  172. if(stage->force_deauth) {
  173. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -d");
  174. }
  175. if(((WifiMarauderScript*)worker->context)->save_pcap != WifiMarauderScriptBooleanFalse) {
  176. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -serial\n");
  177. } else {
  178. len += snprintf(attack_command + len, sizeof(attack_command) - len, "\n");
  179. }
  180. wifi_marauder_uart_tx(worker->uart, (uint8_t*)attack_command, len);
  181. _wifi_marauder_script_delay(worker, stage->timeout);
  182. _send_stop(worker);
  183. }
  184. }
  185. void _wifi_marauder_script_execute_sniff_pwn(
  186. WifiMarauderScriptStageSniffPwn* stage,
  187. WifiMarauderScriptWorker* worker) {
  188. const char sniff_command[] = "sniffpwn";
  189. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  190. if(((WifiMarauderScript*)worker->context)->save_pcap != WifiMarauderScriptBooleanFalse) {
  191. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(" -serial\n"), strlen(" -serial\n"));
  192. } else {
  193. wifi_marauder_uart_tx(worker->uart, (uint8_t*)("\n"), 1);
  194. }
  195. _wifi_marauder_script_delay(worker, stage->timeout);
  196. _send_stop(worker);
  197. }
  198. void _wifi_marauder_script_execute_beacon_list(
  199. WifiMarauderScriptStageBeaconList* stage,
  200. WifiMarauderScriptWorker* worker) {
  201. const char clearlist_command[] = "clearlist -s\n";
  202. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(clearlist_command), strlen(clearlist_command));
  203. char command[100];
  204. char* ssid;
  205. for(int i = 0; i < stage->ssid_count; i++) {
  206. ssid = stage->ssids[i];
  207. snprintf(command, sizeof(command), "ssid -a -n \"%s\"", ssid);
  208. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(command), strlen(command));
  209. _send_line_break(worker);
  210. }
  211. if(stage->random_ssids > 0) {
  212. char add_random_command[50];
  213. snprintf(
  214. add_random_command,
  215. sizeof(add_random_command),
  216. "ssid -a -r -g %d\n",
  217. stage->random_ssids);
  218. wifi_marauder_uart_tx(
  219. worker->uart, (uint8_t*)add_random_command, strlen(add_random_command));
  220. }
  221. const char attack_command[] = "attack -t beacon -l\n";
  222. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(attack_command), strlen(attack_command));
  223. _wifi_marauder_script_delay(worker, stage->timeout);
  224. _send_stop(worker);
  225. }
  226. void _wifi_marauder_script_execute_beacon_ap(
  227. WifiMarauderScriptStageBeaconAp* stage,
  228. WifiMarauderScriptWorker* worker) {
  229. const char command[] = "attack -t beacon -a\n";
  230. wifi_marauder_uart_tx(worker->uart, (uint8_t*)command, strlen(command));
  231. _wifi_marauder_script_delay(worker, stage->timeout);
  232. _send_stop(worker);
  233. }
  234. void _wifi_marauder_script_execute_exec(
  235. WifiMarauderScriptStageExec* stage,
  236. WifiMarauderScriptWorker* worker) {
  237. if(stage->command != NULL) {
  238. wifi_marauder_uart_tx(worker->uart, (uint8_t*)stage->command, strlen(stage->command));
  239. _send_line_break(worker);
  240. }
  241. }
  242. void _wifi_marauder_script_execute_delay(
  243. WifiMarauderScriptStageDelay* stage,
  244. WifiMarauderScriptWorker* worker) {
  245. _wifi_marauder_script_delay(worker, stage->timeout);
  246. }
  247. void wifi_marauder_script_execute_start(void* context) {
  248. furi_assert(context);
  249. WifiMarauderScriptWorker* worker = context;
  250. WifiMarauderScript* script = worker->script;
  251. char command[100];
  252. // Enables or disables the LED according to script settings
  253. if(script->enable_led != WifiMarauderScriptBooleanUndefined) {
  254. snprintf(
  255. command,
  256. sizeof(command),
  257. "settings -s EnableLED %s",
  258. script->enable_led ? "enable" : "disable");
  259. wifi_marauder_uart_tx(worker->uart, (uint8_t*)command, strlen(command));
  260. _send_line_break(worker);
  261. }
  262. // Enables or disables PCAP saving according to script settings
  263. if(script->save_pcap != WifiMarauderScriptBooleanUndefined) {
  264. snprintf(
  265. command,
  266. sizeof(command),
  267. "settings -s SavePCAP %s",
  268. script->save_pcap ? "enable" : "disable");
  269. wifi_marauder_uart_tx(worker->uart, (uint8_t*)command, strlen(command));
  270. _send_line_break(worker);
  271. }
  272. }
  273. void wifi_marauder_script_execute_stage(WifiMarauderScriptStage* stage, void* context) {
  274. furi_assert(context);
  275. WifiMarauderScriptWorker* worker = context;
  276. void* stage_data = stage->stage;
  277. switch(stage->type) {
  278. case WifiMarauderScriptStageTypeScan:
  279. _wifi_marauder_script_execute_scan((WifiMarauderScriptStageScan*)stage_data, worker);
  280. break;
  281. case WifiMarauderScriptStageTypeSelect:
  282. _wifi_marauder_script_execute_select((WifiMarauderScriptStageSelect*)stage_data, worker);
  283. break;
  284. case WifiMarauderScriptStageTypeDeauth:
  285. _wifi_marauder_script_execute_deauth((WifiMarauderScriptStageDeauth*)stage_data, worker);
  286. break;
  287. case WifiMarauderScriptStageTypeProbe:
  288. _wifi_marauder_script_execute_probe((WifiMarauderScriptStageProbe*)stage_data, worker);
  289. break;
  290. case WifiMarauderScriptStageTypeSniffRaw:
  291. _wifi_marauder_script_execute_sniff_raw(
  292. (WifiMarauderScriptStageSniffRaw*)stage_data, worker);
  293. break;
  294. case WifiMarauderScriptStageTypeSniffBeacon:
  295. _wifi_marauder_script_execute_sniff_beacon(
  296. (WifiMarauderScriptStageSniffBeacon*)stage_data, worker);
  297. break;
  298. case WifiMarauderScriptStageTypeSniffDeauth:
  299. _wifi_marauder_script_execute_sniff_deauth(
  300. (WifiMarauderScriptStageSniffDeauth*)stage_data, worker);
  301. break;
  302. case WifiMarauderScriptStageTypeSniffEsp:
  303. _wifi_marauder_script_execute_sniff_esp(
  304. (WifiMarauderScriptStageSniffEsp*)stage_data, worker);
  305. break;
  306. case WifiMarauderScriptStageTypeSniffPmkid:
  307. _wifi_marauder_script_execute_sniff_pmkid(
  308. (WifiMarauderScriptStageSniffPmkid*)stage_data, worker);
  309. break;
  310. case WifiMarauderScriptStageTypeSniffPwn:
  311. _wifi_marauder_script_execute_sniff_pwn(
  312. (WifiMarauderScriptStageSniffPwn*)stage_data, worker);
  313. break;
  314. case WifiMarauderScriptStageTypeBeaconList:
  315. _wifi_marauder_script_execute_beacon_list(
  316. (WifiMarauderScriptStageBeaconList*)stage_data, worker);
  317. break;
  318. case WifiMarauderScriptStageTypeBeaconAp:
  319. _wifi_marauder_script_execute_beacon_ap(
  320. (WifiMarauderScriptStageBeaconAp*)stage_data, worker);
  321. break;
  322. case WifiMarauderScriptStageTypeExec:
  323. _wifi_marauder_script_execute_exec((WifiMarauderScriptStageExec*)stage_data, worker);
  324. break;
  325. case WifiMarauderScriptStageTypeDelay:
  326. _wifi_marauder_script_execute_delay((WifiMarauderScriptStageDelay*)stage_data, worker);
  327. break;
  328. }
  329. }