wifi_marauder_script_executor.c 11 KB

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