wifi_marauder_script_executor.c 12 KB

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