wifi_marauder_script_executor.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 -serial\n";
  96. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  97. _wifi_marauder_script_delay(worker, stage->timeout);
  98. _send_stop(worker);
  99. }
  100. void _wifi_marauder_script_execute_sniff_beacon(
  101. WifiMarauderScriptStageSniffBeacon* stage,
  102. WifiMarauderScriptWorker* worker) {
  103. const char sniff_command[] = "sniffbeacon -serial\n";
  104. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  105. _wifi_marauder_script_delay(worker, stage->timeout);
  106. _send_stop(worker);
  107. }
  108. void _wifi_marauder_script_execute_sniff_deauth(
  109. WifiMarauderScriptStageSniffDeauth* stage,
  110. WifiMarauderScriptWorker* worker) {
  111. const char sniff_command[] = "sniffdeauth -serial\n";
  112. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  113. _wifi_marauder_script_delay(worker, stage->timeout);
  114. _send_stop(worker);
  115. }
  116. void _wifi_marauder_script_execute_sniff_esp(
  117. WifiMarauderScriptStageSniffEsp* stage,
  118. WifiMarauderScriptWorker* worker) {
  119. const char sniff_command[] = "sniffesp -serial\n";
  120. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  121. _wifi_marauder_script_delay(worker, stage->timeout);
  122. _send_stop(worker);
  123. }
  124. void _wifi_marauder_script_execute_sniff_pmkid(
  125. WifiMarauderScriptStageSniffPmkid* stage,
  126. WifiMarauderScriptWorker* worker) {
  127. // If channel hopping is enabled, loop through channels 1-11
  128. if(stage->hop_channels) {
  129. for(int i = 1; i <= 11; i++) {
  130. char attack_command[50] = "sniffpmkid";
  131. int len = strlen(attack_command);
  132. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -c %d", i);
  133. if(stage->force_deauth) {
  134. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -d");
  135. }
  136. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -serial\n");
  137. wifi_marauder_uart_tx(worker->uart, (uint8_t*)attack_command, len);
  138. _wifi_marauder_script_delay(worker, stage->timeout);
  139. _send_stop(worker);
  140. }
  141. } else {
  142. char attack_command[50] = "sniffpmkid";
  143. int len = strlen(attack_command);
  144. if(stage->channel > 0) {
  145. len += snprintf(
  146. attack_command + len, sizeof(attack_command) - len, " -c %d", stage->channel);
  147. }
  148. if(stage->force_deauth) {
  149. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -d");
  150. }
  151. len += snprintf(attack_command + len, sizeof(attack_command) - len, " -serial\n");
  152. wifi_marauder_uart_tx(worker->uart, (uint8_t*)attack_command, len);
  153. _wifi_marauder_script_delay(worker, stage->timeout);
  154. _send_stop(worker);
  155. }
  156. }
  157. void _wifi_marauder_script_execute_sniff_pwn(
  158. WifiMarauderScriptStageSniffPwn* stage,
  159. WifiMarauderScriptWorker* worker) {
  160. const char sniff_command[] = "sniffpwn -serial\n";
  161. wifi_marauder_uart_tx(worker->uart, (uint8_t*)sniff_command, strlen(sniff_command));
  162. _wifi_marauder_script_delay(worker, stage->timeout);
  163. _send_stop(worker);
  164. }
  165. void _wifi_marauder_script_execute_beacon_list(
  166. WifiMarauderScriptStageBeaconList* stage,
  167. WifiMarauderScriptWorker* worker) {
  168. const char clearlist_command[] = "clearlist -s\n";
  169. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(clearlist_command), strlen(clearlist_command));
  170. char command[100];
  171. char* ssid;
  172. for(int i = 0; i < stage->ssid_count; i++) {
  173. ssid = stage->ssids[i];
  174. snprintf(command, sizeof(command), "ssid -a -n \"%s\"", ssid);
  175. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(command), strlen(command));
  176. _send_line_break(worker);
  177. }
  178. if(stage->random_ssids > 0) {
  179. char add_random_command[50];
  180. snprintf(
  181. add_random_command,
  182. sizeof(add_random_command),
  183. "ssid -a -r -g %d\n",
  184. stage->random_ssids);
  185. wifi_marauder_uart_tx(
  186. worker->uart, (uint8_t*)add_random_command, strlen(add_random_command));
  187. }
  188. const char attack_command[] = "attack -t beacon -l\n";
  189. wifi_marauder_uart_tx(worker->uart, (uint8_t*)(attack_command), strlen(attack_command));
  190. _wifi_marauder_script_delay(worker, stage->timeout);
  191. _send_stop(worker);
  192. }
  193. void _wifi_marauder_script_execute_beacon_ap(
  194. WifiMarauderScriptStageBeaconAp* stage,
  195. WifiMarauderScriptWorker* worker) {
  196. const char command[] = "attack -t beacon -a\n";
  197. wifi_marauder_uart_tx(worker->uart, (uint8_t*)command, strlen(command));
  198. _wifi_marauder_script_delay(worker, stage->timeout);
  199. _send_stop(worker);
  200. }
  201. void _wifi_marauder_script_execute_exec(
  202. WifiMarauderScriptStageExec* stage,
  203. WifiMarauderScriptWorker* worker) {
  204. if(stage->command != NULL) {
  205. wifi_marauder_uart_tx(worker->uart, (uint8_t*)stage->command, strlen(stage->command));
  206. _send_line_break(worker);
  207. }
  208. }
  209. void _wifi_marauder_script_execute_delay(
  210. WifiMarauderScriptStageDelay* stage,
  211. WifiMarauderScriptWorker* worker) {
  212. _wifi_marauder_script_delay(worker, stage->timeout);
  213. }
  214. void wifi_marauder_script_execute_start(void* context) {
  215. furi_assert(context);
  216. WifiMarauderScriptWorker* worker = context;
  217. WifiMarauderScript* script = worker->script;
  218. char command[100];
  219. // Enables or disables the LED according to script settings
  220. if(script->enable_led != WifiMarauderScriptBooleanUndefined) {
  221. snprintf(
  222. command,
  223. sizeof(command),
  224. "settings -s EnableLED %s",
  225. script->enable_led ? "enable" : "disable");
  226. wifi_marauder_uart_tx(worker->uart, (uint8_t*)command, strlen(command));
  227. _send_line_break(worker);
  228. }
  229. // Enables or disables PCAP saving according to script settings
  230. if(script->save_pcap != WifiMarauderScriptBooleanUndefined) {
  231. snprintf(
  232. command,
  233. sizeof(command),
  234. "settings -s SavePCAP %s",
  235. script->save_pcap ? "enable" : "disable");
  236. wifi_marauder_uart_tx(worker->uart, (uint8_t*)command, strlen(command));
  237. _send_line_break(worker);
  238. }
  239. }
  240. void wifi_marauder_script_execute_stage(WifiMarauderScriptStage* stage, void* context) {
  241. furi_assert(context);
  242. WifiMarauderScriptWorker* worker = context;
  243. void* stage_data = stage->stage;
  244. switch(stage->type) {
  245. case WifiMarauderScriptStageTypeScan:
  246. _wifi_marauder_script_execute_scan((WifiMarauderScriptStageScan*)stage_data, worker);
  247. break;
  248. case WifiMarauderScriptStageTypeSelect:
  249. _wifi_marauder_script_execute_select((WifiMarauderScriptStageSelect*)stage_data, worker);
  250. break;
  251. case WifiMarauderScriptStageTypeDeauth:
  252. _wifi_marauder_script_execute_deauth((WifiMarauderScriptStageDeauth*)stage_data, worker);
  253. break;
  254. case WifiMarauderScriptStageTypeProbe:
  255. _wifi_marauder_script_execute_probe((WifiMarauderScriptStageProbe*)stage_data, worker);
  256. break;
  257. case WifiMarauderScriptStageTypeSniffRaw:
  258. _wifi_marauder_script_execute_sniff_raw(
  259. (WifiMarauderScriptStageSniffRaw*)stage_data, worker);
  260. break;
  261. case WifiMarauderScriptStageTypeSniffBeacon:
  262. _wifi_marauder_script_execute_sniff_beacon(
  263. (WifiMarauderScriptStageSniffBeacon*)stage_data, worker);
  264. break;
  265. case WifiMarauderScriptStageTypeSniffDeauth:
  266. _wifi_marauder_script_execute_sniff_deauth(
  267. (WifiMarauderScriptStageSniffDeauth*)stage_data, worker);
  268. break;
  269. case WifiMarauderScriptStageTypeSniffEsp:
  270. _wifi_marauder_script_execute_sniff_esp(
  271. (WifiMarauderScriptStageSniffEsp*)stage_data, worker);
  272. break;
  273. case WifiMarauderScriptStageTypeSniffPmkid:
  274. _wifi_marauder_script_execute_sniff_pmkid(
  275. (WifiMarauderScriptStageSniffPmkid*)stage_data, worker);
  276. break;
  277. case WifiMarauderScriptStageTypeSniffPwn:
  278. _wifi_marauder_script_execute_sniff_pwn(
  279. (WifiMarauderScriptStageSniffPwn*)stage_data, worker);
  280. break;
  281. case WifiMarauderScriptStageTypeBeaconList:
  282. _wifi_marauder_script_execute_beacon_list(
  283. (WifiMarauderScriptStageBeaconList*)stage_data, worker);
  284. break;
  285. case WifiMarauderScriptStageTypeBeaconAp:
  286. _wifi_marauder_script_execute_beacon_ap(
  287. (WifiMarauderScriptStageBeaconAp*)stage_data, worker);
  288. break;
  289. case WifiMarauderScriptStageTypeExec:
  290. _wifi_marauder_script_execute_exec((WifiMarauderScriptStageExec*)stage_data, worker);
  291. break;
  292. case WifiMarauderScriptStageTypeDelay:
  293. _wifi_marauder_script_execute_delay((WifiMarauderScriptStageDelay*)stage_data, worker);
  294. break;
  295. }
  296. }