wifi_marauder_script_executor.c 12 KB

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