Skip to content

Commit 21423f0

Browse files
authored
added an option to hop all channels on sniffpmkid. fixed a bug on custom command (#26)
1 parent 4ecee57 commit 21423f0

5 files changed

+88
-22
lines changed

script/menu/wifi_marauder_script_stage_menu_sniffpmkid.c

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
#include "../../wifi_marauder_app_i.h"
22

3+
static void wifi_marauder_sniffpmkid_stage_hop_channels_setup_callback(VariableItem* item) {
4+
WifiMarauderApp* app = variable_item_get_context(item);
5+
WifiMarauderScriptStageSniffPmkid* stage = app->script_edit_selected_stage->stage;
6+
variable_item_set_current_value_index(item, stage->hop_channels);
7+
}
8+
9+
static void wifi_marauder_sniffpmkid_stage_hop_channels_change_callback(VariableItem* item) {
10+
WifiMarauderApp* app = variable_item_get_context(item);
11+
12+
uint8_t current_stage_index = variable_item_list_get_selected_item_index(app->var_item_list);
13+
const WifiMarauderScriptMenuItem* menu_item =
14+
&app->script_stage_menu->items[current_stage_index];
15+
16+
uint8_t option_index = variable_item_get_current_value_index(item);
17+
variable_item_set_current_value_text(item, menu_item->options[option_index]);
18+
19+
WifiMarauderScriptStageSniffPmkid* stage = app->script_edit_selected_stage->stage;
20+
stage->hop_channels = option_index;
21+
}
22+
23+
324
static void wifi_marauder_sniffpmkid_stage_force_deauth_setup_callback(VariableItem* item) {
425
WifiMarauderApp* app = variable_item_get_context(item);
526
WifiMarauderScriptStageSniffPmkid* stage = app->script_edit_selected_stage->stage;
@@ -65,8 +86,8 @@ static void wifi_marauder_sniffpmkid_stage_timeout_select_callback(void* context
6586
}
6687

6788
void wifi_marauder_script_stage_menu_sniffpmkid_load(WifiMarauderScriptStageMenu* stage_menu) {
68-
stage_menu->num_items = 3;
69-
stage_menu->items = malloc(3 * sizeof(WifiMarauderScriptMenuItem));
89+
stage_menu->num_items = 4;
90+
stage_menu->items = malloc(4 * sizeof(WifiMarauderScriptMenuItem));
7091

7192
stage_menu->items[0] = (WifiMarauderScriptMenuItem){
7293
.name = strdup("Force deauth"),
@@ -88,4 +109,11 @@ void wifi_marauder_script_stage_menu_sniffpmkid_load(WifiMarauderScriptStageMenu
88109
.num_options = 1,
89110
.setup_callback = wifi_marauder_sniffpmkid_stage_timeout_setup_callback,
90111
.select_callback = wifi_marauder_sniffpmkid_stage_timeout_select_callback};
112+
stage_menu->items[3] = (WifiMarauderScriptMenuItem){
113+
.name = strdup("Hop Channels"),
114+
.type = WifiMarauderScriptMenuItemTypeOptionsString,
115+
.num_options = 2,
116+
.options = {"no", "yes"},
117+
.setup_callback = wifi_marauder_sniffpmkid_stage_hop_channels_setup_callback,
118+
.change_callback = wifi_marauder_sniffpmkid_stage_hop_channels_change_callback};
91119
}

script/wifi_marauder_script.c

+19-3
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,35 @@ WifiMarauderScriptStageSniffPmkid* _wifi_marauder_script_get_stage_sniff_pmkid(c
244244

245245
cJSON* channel_json = cJSON_GetObjectItem(sniffpmkid_stage_json, "channel");
246246
int channel = channel_json != NULL ? (int)cJSON_GetNumberValue(channel_json) : 0;
247+
247248
cJSON* timeout_json = cJSON_GetObjectItem(sniffpmkid_stage_json, "timeout");
248249
int timeout = timeout_json != NULL ? (int)cJSON_GetNumberValue(timeout_json) :
249-
WIFI_MARAUDER_DEFAULT_TIMEOUT_SNIFF;
250+
WIFI_MARAUDER_DEFAULT_TIMEOUT_SNIFF;
251+
250252
cJSON* force_deauth_json =
251-
cJSON_GetObjectItemCaseSensitive(sniffpmkid_stage_json, "forceDeauth");
253+
cJSON_GetObjectItemCaseSensitive(sniffpmkid_stage_json, "forceDeauth");
252254
bool force_deauth = cJSON_IsBool(force_deauth_json) ? force_deauth_json->valueint : true;
253255

256+
cJSON* hop_channels_json =
257+
cJSON_GetObjectItemCaseSensitive(sniffpmkid_stage_json, "hopChannels");
258+
bool hop_channels = cJSON_IsBool(hop_channels_json) ? hop_channels_json->valueint : false;
259+
254260
WifiMarauderScriptStageSniffPmkid* sniff_pmkid_stage =
255-
(WifiMarauderScriptStageSniffPmkid*)malloc(sizeof(WifiMarauderScriptStageSniffPmkid));
261+
(WifiMarauderScriptStageSniffPmkid*)malloc(sizeof(WifiMarauderScriptStageSniffPmkid));
262+
263+
if (sniff_pmkid_stage == NULL) {
264+
// Handle memory allocation error
265+
return NULL;
266+
}
256267
sniff_pmkid_stage->channel = channel;
257268
sniff_pmkid_stage->timeout = timeout;
258269
sniff_pmkid_stage->force_deauth = force_deauth;
270+
sniff_pmkid_stage->hop_channels = hop_channels;
259271

260272
return sniff_pmkid_stage;
261273
}
262274

275+
263276
WifiMarauderScriptStageSniffPwn* _wifi_marauder_script_get_stage_sniff_pwn(cJSON* stages) {
264277
cJSON* sniffpwn_stage_json = cJSON_GetObjectItem(stages, "sniffpwn");
265278
if(sniffpwn_stage_json == NULL) {
@@ -659,6 +672,9 @@ cJSON* _wifi_marauder_script_create_json_sniffpmkid(
659672
if(sniffpmkid_stage->timeout > 0) {
660673
cJSON_AddNumberToObject(sniffpmkid_json, "timeout", sniffpmkid_stage->timeout);
661674
}
675+
// Hop channels
676+
cJSON_AddBoolToObject(sniffpmkid_json, "hopChannels", sniffpmkid_stage->hop_channels);
677+
662678
return stage_json;
663679
}
664680

script/wifi_marauder_script.h

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ typedef struct WifiMarauderScriptStageSniffEsp {
196196

197197
typedef struct WifiMarauderScriptStageSniffPmkid {
198198
bool force_deauth;
199+
bool hop_channels;
199200
int channel;
200201
int timeout;
201202
} WifiMarauderScriptStageSniffPmkid;

script/wifi_marauder_script_executor.c

+36-17
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ void _send_line_break() {
1414
wifi_marauder_uart_tx((uint8_t*)("\n"), 1);
1515
}
1616

17+
1718
void _send_channel_select(int channel) {
1819
char command[30];
19-
wifi_marauder_uart_tx((uint8_t*)("\n"), 1);
20+
_send_line_break();
2021
snprintf(command, sizeof(command), "channel -s %d\n", channel);
2122
wifi_marauder_uart_tx((uint8_t*)(command), strlen(command));
2223
}
@@ -137,25 +138,42 @@ void _wifi_marauder_script_execute_sniff_esp(
137138
}
138139

139140
void _wifi_marauder_script_execute_sniff_pmkid(
140-
WifiMarauderScriptStageSniffPmkid* stage,
141-
WifiMarauderScriptWorker* worker) {
142-
char attack_command[50] = "sniffpmkid";
143-
int len = strlen(attack_command);
141+
WifiMarauderScriptStageSniffPmkid* stage,
142+
WifiMarauderScriptWorker* worker) {
143+
144+
// If channel hopping is enabled, loop through channels 1-11
145+
if(stage->hop_channels) {
146+
for(int i = 1; i <= 11; i++) {
147+
char attack_command[50] = "sniffpmkid";
148+
int len = strlen(attack_command);
149+
150+
len += snprintf(attack_command + len, sizeof(attack_command) - len, " -c %d", i);
151+
if(stage->force_deauth) {
152+
len += snprintf(attack_command + len, sizeof(attack_command) - len, " -d");
153+
}
154+
155+
len += snprintf(attack_command + len, sizeof(attack_command) - len, "\n");
156+
wifi_marauder_uart_tx((uint8_t*)attack_command, len);
157+
_wifi_marauder_script_delay(worker, stage->timeout);
158+
_send_stop();
159+
}
160+
} else {
161+
char attack_command[50] = "sniffpmkid";
162+
int len = strlen(attack_command);
144163

145-
if(stage->channel > 0) {
146-
len +=
147-
snprintf(attack_command + len, sizeof(attack_command) - len, " -c %d", stage->channel);
148-
}
164+
if(stage->channel > 0) {
165+
len +=
166+
snprintf(attack_command + len, sizeof(attack_command) - len, " -c %d", stage->channel);
167+
}
149168

150-
if(stage->force_deauth) {
151-
len += snprintf(attack_command + len, sizeof(attack_command) - len, " -d");
169+
if(stage->force_deauth) {
170+
len += snprintf(attack_command + len, sizeof(attack_command) - len, " -d");
171+
}
172+
len += snprintf(attack_command + len, sizeof(attack_command) - len, "\n");
173+
wifi_marauder_uart_tx((uint8_t*)attack_command, len);
174+
_wifi_marauder_script_delay(worker, stage->timeout);
175+
_send_stop();
152176
}
153-
154-
len += snprintf(attack_command + len, sizeof(attack_command) - len, "\n");
155-
156-
wifi_marauder_uart_tx((uint8_t*)attack_command, len);
157-
_wifi_marauder_script_delay(worker, stage->timeout);
158-
_send_stop();
159177
}
160178

161179
void _wifi_marauder_script_execute_sniff_pwn(
@@ -209,6 +227,7 @@ void _wifi_marauder_script_execute_beacon_ap(
209227
void _wifi_marauder_script_execute_exec(WifiMarauderScriptStageExec* stage) {
210228
if(stage->command != NULL) {
211229
wifi_marauder_uart_tx((uint8_t*)stage->command, strlen(stage->command));
230+
_send_line_break();
212231
}
213232
}
214233

script/wifi_marauder_script_worker.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "../wifi_marauder_app_i.h"
22
#include "wifi_marauder_script_worker.h"
33

4+
45
WifiMarauderScriptWorker* wifi_marauder_script_worker_alloc() {
56
WifiMarauderScriptWorker* worker = malloc(sizeof(WifiMarauderScriptWorker));
67
if(worker == NULL) {
@@ -39,6 +40,7 @@ int32_t _wifi_marauder_script_worker_task(void* worker) {
3940
}
4041

4142
script_worker->is_running = false;
43+
4244
return WifiMarauderScriptWorkerStatusSuccess;
4345
}
4446

0 commit comments

Comments
 (0)