wifi_marauder_script_executor.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. wifi_marauder_uart_tx((uint8_t*)("\n"), 1);
  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. char attack_command[50] = "sniffpmkid";
  125. int len = strlen(attack_command);
  126. if(stage->channel > 0) {
  127. len +=
  128. snprintf(attack_command + len, sizeof(attack_command) - len, " -c %d", stage->channel);
  129. }
  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. void _wifi_marauder_script_execute_sniff_pwn(
  139. WifiMarauderScriptStageSniffPwn* stage,
  140. WifiMarauderScriptWorker* worker) {
  141. const char sniff_command[] = "sniffpwn\n";
  142. wifi_marauder_uart_tx((uint8_t*)sniff_command, strlen(sniff_command));
  143. _wifi_marauder_script_delay(worker, stage->timeout);
  144. _send_stop();
  145. }
  146. void _wifi_marauder_script_execute_beacon_list(
  147. WifiMarauderScriptStageBeaconList* stage,
  148. WifiMarauderScriptWorker* worker) {
  149. const char clearlist_command[] = "clearlist -s\n";
  150. wifi_marauder_uart_tx((uint8_t*)(clearlist_command), strlen(clearlist_command));
  151. char command[100];
  152. char* ssid;
  153. for(int i = 0; i < stage->ssid_count; i++) {
  154. ssid = stage->ssids[i];
  155. snprintf(command, sizeof(command), "ssid -a -n \"%s\"", ssid);
  156. wifi_marauder_uart_tx((uint8_t*)(command), strlen(command));
  157. _send_line_break();
  158. }
  159. if(stage->random_ssids > 0) {
  160. char add_random_command[50];
  161. snprintf(
  162. add_random_command,
  163. sizeof(add_random_command),
  164. "ssid -a -r -g %d\n",
  165. stage->random_ssids);
  166. wifi_marauder_uart_tx((uint8_t*)add_random_command, strlen(add_random_command));
  167. }
  168. const char attack_command[] = "attack -t beacon -l\n";
  169. wifi_marauder_uart_tx((uint8_t*)(attack_command), strlen(attack_command));
  170. _wifi_marauder_script_delay(worker, stage->timeout);
  171. _send_stop();
  172. }
  173. void _wifi_marauder_script_execute_beacon_ap(
  174. WifiMarauderScriptStageBeaconAp* stage,
  175. WifiMarauderScriptWorker* worker) {
  176. const char command[] = "attack -t beacon -a\n";
  177. wifi_marauder_uart_tx((uint8_t*)command, strlen(command));
  178. _wifi_marauder_script_delay(worker, stage->timeout);
  179. _send_stop();
  180. }
  181. void _wifi_marauder_script_execute_exec(WifiMarauderScriptStageExec* stage) {
  182. if(stage->command != NULL) {
  183. wifi_marauder_uart_tx((uint8_t*)stage->command, strlen(stage->command));
  184. }
  185. }
  186. void _wifi_marauder_script_execute_delay(
  187. WifiMarauderScriptStageDelay* stage,
  188. WifiMarauderScriptWorker* worker) {
  189. _wifi_marauder_script_delay(worker, stage->timeout);
  190. }
  191. void wifi_marauder_script_execute_start(void* context) {
  192. furi_assert(context);
  193. WifiMarauderScriptWorker* worker = context;
  194. WifiMarauderScript* script = worker->script;
  195. char command[100];
  196. // Enables or disables the LED according to script settings
  197. if(script->enable_led != WifiMarauderScriptBooleanUndefined) {
  198. snprintf(
  199. command,
  200. sizeof(command),
  201. "settings -s EnableLED %s",
  202. script->enable_led ? "enable" : "disable");
  203. wifi_marauder_uart_tx((uint8_t*)command, strlen(command));
  204. _send_line_break();
  205. }
  206. // Enables or disables PCAP saving according to script settings
  207. if(script->save_pcap != WifiMarauderScriptBooleanUndefined) {
  208. snprintf(
  209. command,
  210. sizeof(command),
  211. "settings -s SavePCAP %s",
  212. script->save_pcap ? "enable" : "disable");
  213. wifi_marauder_uart_tx((uint8_t*)command, strlen(command));
  214. _send_line_break();
  215. }
  216. }
  217. void wifi_marauder_script_execute_stage(WifiMarauderScriptStage* stage, void* context) {
  218. furi_assert(context);
  219. WifiMarauderScriptWorker* worker = context;
  220. void* stage_data = stage->stage;
  221. switch(stage->type) {
  222. case WifiMarauderScriptStageTypeScan:
  223. _wifi_marauder_script_execute_scan((WifiMarauderScriptStageScan*)stage_data, worker);
  224. break;
  225. case WifiMarauderScriptStageTypeSelect:
  226. _wifi_marauder_script_execute_select((WifiMarauderScriptStageSelect*)stage_data);
  227. break;
  228. case WifiMarauderScriptStageTypeDeauth:
  229. _wifi_marauder_script_execute_deauth((WifiMarauderScriptStageDeauth*)stage_data, worker);
  230. break;
  231. case WifiMarauderScriptStageTypeProbe:
  232. _wifi_marauder_script_execute_probe((WifiMarauderScriptStageProbe*)stage_data, worker);
  233. break;
  234. case WifiMarauderScriptStageTypeSniffRaw:
  235. _wifi_marauder_script_execute_sniff_raw(
  236. (WifiMarauderScriptStageSniffRaw*)stage_data, worker);
  237. break;
  238. case WifiMarauderScriptStageTypeSniffBeacon:
  239. _wifi_marauder_script_execute_sniff_beacon(
  240. (WifiMarauderScriptStageSniffBeacon*)stage_data, worker);
  241. break;
  242. case WifiMarauderScriptStageTypeSniffDeauth:
  243. _wifi_marauder_script_execute_sniff_deauth(
  244. (WifiMarauderScriptStageSniffDeauth*)stage_data, worker);
  245. break;
  246. case WifiMarauderScriptStageTypeSniffEsp:
  247. _wifi_marauder_script_execute_sniff_esp(
  248. (WifiMarauderScriptStageSniffEsp*)stage_data, worker);
  249. break;
  250. case WifiMarauderScriptStageTypeSniffPmkid:
  251. _wifi_marauder_script_execute_sniff_pmkid(
  252. (WifiMarauderScriptStageSniffPmkid*)stage_data, worker);
  253. break;
  254. case WifiMarauderScriptStageTypeSniffPwn:
  255. _wifi_marauder_script_execute_sniff_pwn(
  256. (WifiMarauderScriptStageSniffPwn*)stage_data, worker);
  257. break;
  258. case WifiMarauderScriptStageTypeBeaconList:
  259. _wifi_marauder_script_execute_beacon_list(
  260. (WifiMarauderScriptStageBeaconList*)stage_data, worker);
  261. break;
  262. case WifiMarauderScriptStageTypeBeaconAp:
  263. _wifi_marauder_script_execute_beacon_ap(
  264. (WifiMarauderScriptStageBeaconAp*)stage_data, worker);
  265. break;
  266. case WifiMarauderScriptStageTypeExec:
  267. _wifi_marauder_script_execute_exec((WifiMarauderScriptStageExec*)stage_data);
  268. break;
  269. case WifiMarauderScriptStageTypeDelay:
  270. _wifi_marauder_script_execute_delay((WifiMarauderScriptStageDelay*)stage_data, worker);
  271. break;
  272. }
  273. }