|
|
@@ -15,12 +15,19 @@ WifiMarauderScript *wifi_marauder_script_alloc() {
|
|
|
script->name = NULL;
|
|
|
script->description = NULL;
|
|
|
script->first_stage = NULL;
|
|
|
+ script->last_stage = NULL;
|
|
|
script->enable_led = WifiMarauderScriptBooleanUndefined;
|
|
|
script->save_pcap = WifiMarauderScriptBooleanUndefined;
|
|
|
script->repeat = 1;
|
|
|
return script;
|
|
|
}
|
|
|
|
|
|
+WifiMarauderScript* wifi_marauder_script_create(const char* script_name) {
|
|
|
+ WifiMarauderScript *script = wifi_marauder_script_alloc();
|
|
|
+ script->name = strdup(script_name);
|
|
|
+ return script;
|
|
|
+}
|
|
|
+
|
|
|
void _wifi_marauder_script_load_meta(WifiMarauderScript *script, cJSON *meta_section) {
|
|
|
if (meta_section != NULL) {
|
|
|
// Script description
|
|
|
@@ -329,137 +336,44 @@ WifiMarauderScriptStage* _wifi_marauder_script_create_stage(WifiMarauderScriptSt
|
|
|
return stage;
|
|
|
}
|
|
|
|
|
|
-void _wifi_marauder_script_add_stage(WifiMarauderScript *script, WifiMarauderScriptStage *stage, WifiMarauderScriptStage **prev_stage) {
|
|
|
- if (*prev_stage != NULL) {
|
|
|
- (*prev_stage)->next_stage = stage;
|
|
|
+void wifi_marauder_script_add_stage(WifiMarauderScript *script, WifiMarauderScriptStageType stage_type, void* stage_data) {
|
|
|
+ if (script == NULL || stage_data == NULL) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ WifiMarauderScriptStage* stage = _wifi_marauder_script_create_stage(stage_type, stage_data);
|
|
|
+ if (script->last_stage != NULL) {
|
|
|
+ script->last_stage->next_stage = stage;
|
|
|
} else {
|
|
|
script->first_stage = stage;
|
|
|
}
|
|
|
- *prev_stage = stage;
|
|
|
+ script->last_stage = stage;
|
|
|
}
|
|
|
|
|
|
void _wifi_marauder_script_load_stages(WifiMarauderScript *script, cJSON *stages) {
|
|
|
- WifiMarauderScriptStage *prev_stage = wifi_marauder_script_get_last_stage(script);
|
|
|
-
|
|
|
// Scan stage
|
|
|
- WifiMarauderScriptStageScan *stage_scan = _wifi_marauder_script_get_stage_scan(stages);
|
|
|
- if (stage_scan != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeScan, stage_scan),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeScan, _wifi_marauder_script_get_stage_scan(stages));
|
|
|
// Select stage
|
|
|
- WifiMarauderScriptStageSelect *stage_select = _wifi_marauder_script_get_stage_select(stages);
|
|
|
- if (stage_select != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeSelect, stage_select),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeSelect, _wifi_marauder_script_get_stage_select(stages));
|
|
|
// Deauth stage
|
|
|
- WifiMarauderScriptStageDeauth *stage_deauth = _wifi_marauder_script_get_stage_deauth(stages);
|
|
|
- if (stage_deauth != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeDeauth, stage_deauth),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeDeauth, _wifi_marauder_script_get_stage_deauth(stages));
|
|
|
// Probe stage
|
|
|
- WifiMarauderScriptStageProbe *stage_probe = _wifi_marauder_script_get_stage_probe(stages);
|
|
|
- if (stage_probe != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeProbe, stage_probe),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeProbe, _wifi_marauder_script_get_stage_probe(stages));
|
|
|
// Sniff raw stage
|
|
|
- WifiMarauderScriptStageSniffRaw *sniff_raw = _wifi_marauder_script_get_stage_sniff_raw(stages);
|
|
|
- if (sniff_raw != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeSniffRaw, sniff_raw),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeSniffRaw, _wifi_marauder_script_get_stage_sniff_raw(stages));
|
|
|
// Sniff beacon stage
|
|
|
- WifiMarauderScriptStageSniffBeacon *sniff_beacon = _wifi_marauder_script_get_stage_sniff_beacon(stages);
|
|
|
- if (sniff_beacon != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeSniffBeacon, sniff_beacon),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeSniffBeacon, _wifi_marauder_script_get_stage_sniff_beacon(stages));
|
|
|
// Sniff deauth stage
|
|
|
- WifiMarauderScriptStageSniffDeauth *sniff_deauth = _wifi_marauder_script_get_stage_sniff_deauth(stages);
|
|
|
- if (sniff_deauth != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeSniffDeauth, sniff_deauth),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeSniffDeauth, _wifi_marauder_script_get_stage_sniff_deauth(stages));
|
|
|
// Sniff esp stage
|
|
|
- WifiMarauderScriptStageSniffEsp *sniff_esp = _wifi_marauder_script_get_stage_sniff_esp(stages);
|
|
|
- if (sniff_esp != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeSniffEsp, sniff_esp),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeSniffEsp, _wifi_marauder_script_get_stage_sniff_esp(stages));
|
|
|
// Sniff PMKID stage
|
|
|
- WifiMarauderScriptStageSniffPmkid *sniff_pmkid = _wifi_marauder_script_get_stage_sniff_pmkid(stages);
|
|
|
- if (sniff_pmkid != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeSniffPmkid, sniff_pmkid),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeSniffPmkid, _wifi_marauder_script_get_stage_sniff_pmkid(stages));
|
|
|
// Sniff pwn stage
|
|
|
- WifiMarauderScriptStageSniffPwn *sniff_pwn = _wifi_marauder_script_get_stage_sniff_pwn(stages);
|
|
|
- if (sniff_pwn != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeSniffPwn, sniff_pwn),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeSniffPwn, _wifi_marauder_script_get_stage_sniff_pwn(stages));
|
|
|
// Beacon List stage
|
|
|
- WifiMarauderScriptStageBeaconList *stage_beacon_list = _wifi_marauder_script_get_stage_beacon_list(stages);
|
|
|
- if (stage_beacon_list != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeBeaconList, stage_beacon_list),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeBeaconList, _wifi_marauder_script_get_stage_beacon_list(stages));
|
|
|
// Beacon Ap stage
|
|
|
- WifiMarauderScriptStageBeaconAp *stage_beacon_ap = _wifi_marauder_script_get_stage_beacon_ap(stages);
|
|
|
- if (stage_beacon_ap != NULL) {
|
|
|
- _wifi_marauder_script_add_stage(
|
|
|
- script,
|
|
|
- _wifi_marauder_script_create_stage(WifiMarauderScriptStageTypeBeaconAp, stage_beacon_ap),
|
|
|
- &prev_stage
|
|
|
- );
|
|
|
- }
|
|
|
+ wifi_marauder_script_add_stage(script, WifiMarauderScriptStageTypeBeaconAp, _wifi_marauder_script_get_stage_beacon_ap(stages));
|
|
|
}
|
|
|
|
|
|
WifiMarauderScript *wifi_marauder_script_parse_raw(const char* json_raw) {
|
|
|
@@ -487,7 +401,7 @@ WifiMarauderScript *wifi_marauder_script_parse_raw(const char* json_raw) {
|
|
|
return script;
|
|
|
}
|
|
|
|
|
|
-WifiMarauderScript *wifi_marauder_script_parse_file(const char* file_path, Storage* storage) {
|
|
|
+WifiMarauderScript *wifi_marauder_script_parse_json(Storage* storage, const char* file_path) {
|
|
|
WifiMarauderScript *script = NULL;
|
|
|
File* script_file = storage_file_alloc(storage);
|
|
|
|
|
|
@@ -512,29 +426,171 @@ WifiMarauderScript *wifi_marauder_script_parse_file(const char* file_path, Stora
|
|
|
return script;
|
|
|
}
|
|
|
|
|
|
-WifiMarauderScriptStage* wifi_marauder_script_get_stage(WifiMarauderScript* script, WifiMarauderScriptStageType stage_type) {
|
|
|
- if (script == NULL) {
|
|
|
- return NULL;
|
|
|
+cJSON* _wifi_marauder_script_create_json_meta(WifiMarauderScript *script) {
|
|
|
+ cJSON* meta_json = cJSON_CreateObject();
|
|
|
+ if (script->description != NULL) {
|
|
|
+ cJSON_AddStringToObject(meta_json, "description", script->description);
|
|
|
+ } else {
|
|
|
+ cJSON_AddStringToObject(meta_json, "description", "My Script");
|
|
|
}
|
|
|
- WifiMarauderScriptStage* current_stage = script->first_stage;
|
|
|
- while (current_stage != NULL) {
|
|
|
- if (current_stage->type == stage_type) {
|
|
|
- return current_stage;
|
|
|
+ if (script->enable_led != WifiMarauderScriptBooleanUndefined) {
|
|
|
+ cJSON_AddBoolToObject(meta_json, "enable_led", (script->enable_led == WifiMarauderScriptBooleanTrue));
|
|
|
+ }
|
|
|
+ if (script->save_pcap != WifiMarauderScriptBooleanUndefined) {
|
|
|
+ cJSON_AddBoolToObject(meta_json, "save_pcap", (script->save_pcap == WifiMarauderScriptBooleanTrue));
|
|
|
+ }
|
|
|
+ cJSON_AddNumberToObject(meta_json, "repeat", script->repeat);
|
|
|
+ return meta_json;
|
|
|
+}
|
|
|
+
|
|
|
+cJSON* _wifi_marauder_script_create_json_scan(WifiMarauderScriptStageScan* scan_stage) {
|
|
|
+ cJSON* stage_json = cJSON_CreateObject();
|
|
|
+ cJSON_AddItemToObject(stage_json, "scan", cJSON_CreateObject());
|
|
|
+ cJSON* scan_json = cJSON_GetObjectItem(stage_json, "scan");
|
|
|
+ // Scan type
|
|
|
+ cJSON_AddStringToObject(scan_json, "type", scan_stage->type == WifiMarauderScriptScanTypeAp ? "ap" : "station");
|
|
|
+ // Channel
|
|
|
+ if (scan_stage->channel > 0) {
|
|
|
+ cJSON_AddNumberToObject(scan_json, "channel", scan_stage->channel);
|
|
|
+ }
|
|
|
+ // Timeout
|
|
|
+ if (scan_stage->timeout > 0) {
|
|
|
+ cJSON_AddNumberToObject(scan_json, "timeout", scan_stage->timeout);
|
|
|
+ }
|
|
|
+ return stage_json;
|
|
|
+}
|
|
|
+
|
|
|
+cJSON* _wifi_marauder_script_create_json_select(WifiMarauderScriptStageSelect* select_stage) {
|
|
|
+ cJSON* stage_json = cJSON_CreateObject();
|
|
|
+ cJSON_AddItemToObject(stage_json, "select", cJSON_CreateObject());
|
|
|
+ cJSON* select_json = cJSON_GetObjectItem(stage_json, "select");
|
|
|
+ // Select type
|
|
|
+ cJSON_AddStringToObject(select_json, "type", select_stage->type == WifiMarauderScriptSelectTypeAp ? "ap" : select_stage->type == WifiMarauderScriptSelectTypeStation ? "station" : "ssid");
|
|
|
+ if (select_stage->filter != NULL) {
|
|
|
+ cJSON_AddStringToObject(select_json, "filter", select_stage->filter);
|
|
|
+ }
|
|
|
+ // Indexes
|
|
|
+ if (select_stage->indexes != NULL) {
|
|
|
+ cJSON* indexes_json = cJSON_CreateArray();
|
|
|
+ int* index_ptr = select_stage->indexes;
|
|
|
+ while (*index_ptr != -1) {
|
|
|
+ cJSON_AddItemToArray(indexes_json, cJSON_CreateNumber(*index_ptr));
|
|
|
+ index_ptr++;
|
|
|
+ }
|
|
|
+ if (cJSON_GetArraySize(indexes_json) > 0) {
|
|
|
+ cJSON_AddItemToObject(select_json, "indexes", indexes_json);
|
|
|
}
|
|
|
- current_stage = current_stage->next_stage;
|
|
|
}
|
|
|
- return NULL;
|
|
|
+ return select_json;
|
|
|
}
|
|
|
|
|
|
-WifiMarauderScriptStage* wifi_marauder_script_get_last_stage(WifiMarauderScript* script) {
|
|
|
- if (script == NULL || script->first_stage == NULL) {
|
|
|
- return NULL;
|
|
|
+cJSON* _wifi_marauder_script_create_json_deauth(WifiMarauderScriptStageDeauth* deauth_stage) {
|
|
|
+ cJSON* stage_json = cJSON_CreateObject();
|
|
|
+ cJSON_AddItemToObject(stage_json, "deauth", cJSON_CreateObject());
|
|
|
+ cJSON* deauth_json = cJSON_GetObjectItem(stage_json, "deauth");
|
|
|
+ // Timeout
|
|
|
+ if (deauth_stage->timeout > 0) {
|
|
|
+ cJSON_AddNumberToObject(deauth_json, "timeout", deauth_stage->timeout);
|
|
|
+ }
|
|
|
+ return stage_json;
|
|
|
+}
|
|
|
+
|
|
|
+cJSON* _wifi_marauder_script_create_json_beaconlist(WifiMarauderScriptStageBeaconList* beaconlist_stage) {
|
|
|
+ cJSON* stage_json = cJSON_CreateObject();
|
|
|
+ cJSON_AddItemToObject(stage_json, "beaconList", cJSON_CreateObject());
|
|
|
+ cJSON* beaconlist_json = cJSON_GetObjectItem(stage_json, "beaconList");
|
|
|
+ // SSIDs
|
|
|
+ if (beaconlist_stage->ssids != NULL) {
|
|
|
+ cJSON* ssids_json = cJSON_CreateStringArray((const char**)beaconlist_stage->ssids, beaconlist_stage->ssid_count);
|
|
|
+ cJSON_AddItemToObject(beaconlist_json, "ssids", ssids_json);
|
|
|
+ }
|
|
|
+ // Random SSIDs
|
|
|
+ if (beaconlist_stage->random_ssids > 0) {
|
|
|
+ cJSON_AddNumberToObject(beaconlist_json, "generate", beaconlist_stage->random_ssids);
|
|
|
+ }
|
|
|
+ // Timeout
|
|
|
+ if (beaconlist_stage->timeout > 0) {
|
|
|
+ cJSON_AddNumberToObject(beaconlist_json, "timeout", beaconlist_stage->timeout);
|
|
|
+ }
|
|
|
+ return stage_json;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void wifi_marauder_script_save_json(Storage* storage, const char* file_path, WifiMarauderScript* script) {
|
|
|
+ File* script_file = storage_file_alloc(storage);
|
|
|
+
|
|
|
+ if (storage_file_open(script_file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
|
|
|
+ cJSON* root_json = cJSON_CreateObject();
|
|
|
+
|
|
|
+ // Meta info
|
|
|
+ cJSON* meta_json = _wifi_marauder_script_create_json_meta(script);
|
|
|
+ cJSON_AddItemToObject(root_json, "meta", meta_json);
|
|
|
+
|
|
|
+ // Create array for stages
|
|
|
+ cJSON* stages_array = cJSON_CreateArray();
|
|
|
+ cJSON_AddItemToObject(root_json, "stages", stages_array);
|
|
|
+
|
|
|
+ // Iterate over each stage and create the corresponding JSON object
|
|
|
+ WifiMarauderScriptStage* stage = script->first_stage;
|
|
|
+ while (stage != NULL) {
|
|
|
+ cJSON* stage_json = NULL;
|
|
|
+
|
|
|
+ switch (stage->type) {
|
|
|
+ case WifiMarauderScriptStageTypeScan: {
|
|
|
+ WifiMarauderScriptStageScan* scan_stage = (WifiMarauderScriptStageScan*) stage->stage;
|
|
|
+ stage_json = _wifi_marauder_script_create_json_scan(scan_stage);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case WifiMarauderScriptStageTypeSelect: {
|
|
|
+ WifiMarauderScriptStageSelect* select_stage = (WifiMarauderScriptStageSelect*) stage->stage;
|
|
|
+ stage_json = _wifi_marauder_script_create_json_select(select_stage);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case WifiMarauderScriptStageTypeDeauth: {
|
|
|
+ WifiMarauderScriptStageDeauth* deauth_stage = (WifiMarauderScriptStageDeauth*) stage->stage;
|
|
|
+ stage_json = _wifi_marauder_script_create_json_deauth(deauth_stage);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case WifiMarauderScriptStageTypeBeaconList: {
|
|
|
+ WifiMarauderScriptStageBeaconList* beaconlist_stage = (WifiMarauderScriptStageBeaconList*) stage->stage;
|
|
|
+ stage_json = _wifi_marauder_script_create_json_beaconlist(beaconlist_stage);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // TODO: Implement other stages
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add the stage JSON object to the "stages" array
|
|
|
+ if (stage_json != NULL) {
|
|
|
+ cJSON_AddItemToArray(stages_array, stage_json);
|
|
|
+ }
|
|
|
+
|
|
|
+ stage = stage->next_stage;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Write JSON to file
|
|
|
+ char* json_str = cJSON_Print(root_json);
|
|
|
+ storage_file_write(script_file, json_str, strlen(json_str));
|
|
|
+
|
|
|
+ //free(json_str);
|
|
|
+ storage_file_close(script_file);
|
|
|
+ }
|
|
|
+ storage_file_free(script_file);
|
|
|
+}
|
|
|
+
|
|
|
+bool wifi_marauder_script_has_stage(WifiMarauderScript* script, WifiMarauderScriptStageType stage_type) {
|
|
|
+ if (script == NULL) {
|
|
|
+ return false;
|
|
|
}
|
|
|
WifiMarauderScriptStage* current_stage = script->first_stage;
|
|
|
- while (current_stage->next_stage != NULL) {
|
|
|
+ while (current_stage != NULL) {
|
|
|
+ if (current_stage->type == stage_type) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
current_stage = current_stage->next_stage;
|
|
|
}
|
|
|
- return current_stage;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
void wifi_marauder_script_free(WifiMarauderScript *script) {
|