wifi_marauder_script_executor.c 14 KB

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