mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 21:28:36 -07:00
Support Marauder CLI in Evil Portal app
THANKS @0xchocolate for implementing this!
This commit is contained in:
@@ -25,13 +25,12 @@ static void evil_portal_app_tick_event_callback(void* context) {
|
|||||||
Evil_PortalApp* evil_portal_app_alloc() {
|
Evil_PortalApp* evil_portal_app_alloc() {
|
||||||
Evil_PortalApp* app = malloc(sizeof(Evil_PortalApp));
|
Evil_PortalApp* app = malloc(sizeof(Evil_PortalApp));
|
||||||
|
|
||||||
app->sent_html = false;
|
|
||||||
app->sent_ap = false;
|
|
||||||
app->sent_reset = false;
|
app->sent_reset = false;
|
||||||
app->has_command_queue = false;
|
|
||||||
app->command_index = 0;
|
|
||||||
app->portal_logs = furi_string_alloc();
|
app->portal_logs = furi_string_alloc();
|
||||||
|
|
||||||
|
app->capture_line = false;
|
||||||
|
app->captured_line = furi_string_alloc();
|
||||||
|
|
||||||
app->dialogs = furi_record_open(RECORD_DIALOGS);
|
app->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||||
app->file_path = furi_string_alloc();
|
app->file_path = furi_string_alloc();
|
||||||
|
|
||||||
@@ -88,6 +87,8 @@ void evil_portal_app_free(Evil_PortalApp* app) {
|
|||||||
furi_string_free(app->portal_logs);
|
furi_string_free(app->portal_logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
furi_string_free(app->captured_line);
|
||||||
|
|
||||||
// Send reset event to dev board
|
// Send reset event to dev board
|
||||||
evil_portal_uart_tx((uint8_t*)(RESET_CMD), strlen(RESET_CMD));
|
evil_portal_uart_tx((uint8_t*)(RESET_CMD), strlen(RESET_CMD));
|
||||||
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ struct Evil_PortalApp {
|
|||||||
SceneManager* scene_manager;
|
SceneManager* scene_manager;
|
||||||
|
|
||||||
FuriString* portal_logs;
|
FuriString* portal_logs;
|
||||||
const char* command_queue[1];
|
|
||||||
int command_index;
|
|
||||||
bool has_command_queue;
|
|
||||||
|
|
||||||
FuriString* text_box_store;
|
FuriString* text_box_store;
|
||||||
size_t text_box_store_strlen;
|
size_t text_box_store_strlen;
|
||||||
@@ -57,12 +54,13 @@ struct Evil_PortalApp {
|
|||||||
bool is_custom_tx_string;
|
bool is_custom_tx_string;
|
||||||
bool focus_console_start;
|
bool focus_console_start;
|
||||||
bool show_stopscan_tip;
|
bool show_stopscan_tip;
|
||||||
bool sent_ap;
|
|
||||||
bool sent_html;
|
|
||||||
bool sent_reset;
|
bool sent_reset;
|
||||||
int BAUDRATE;
|
int BAUDRATE;
|
||||||
char text_store[2][128 + 1];
|
char text_store[2][128 + 1];
|
||||||
|
|
||||||
|
bool capture_line;
|
||||||
|
FuriString* captured_line;
|
||||||
|
|
||||||
uint8_t* index_html;
|
uint8_t* index_html;
|
||||||
uint8_t* ap_name;
|
uint8_t* ap_name;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -48,34 +48,6 @@ static int32_t uart_worker(void* context) {
|
|||||||
if(uart->handle_rx_data_cb) {
|
if(uart->handle_rx_data_cb) {
|
||||||
uart->handle_rx_data_cb(uart->rx_buf, len, uart->app);
|
uart->handle_rx_data_cb(uart->rx_buf, len, uart->app);
|
||||||
|
|
||||||
if(uart->app->has_command_queue) {
|
|
||||||
if(uart->app->command_index < 1) {
|
|
||||||
if(0 == strncmp(
|
|
||||||
SET_AP_CMD,
|
|
||||||
uart->app->command_queue[uart->app->command_index],
|
|
||||||
strlen(SET_AP_CMD))) {
|
|
||||||
FuriString* out_data = furi_string_alloc();
|
|
||||||
|
|
||||||
furi_string_cat(out_data, "setap=");
|
|
||||||
furi_string_cat(out_data, (char*)uart->app->ap_name);
|
|
||||||
|
|
||||||
evil_portal_uart_tx(
|
|
||||||
(uint8_t*)(furi_string_get_cstr(out_data)),
|
|
||||||
strlen(furi_string_get_cstr(out_data)));
|
|
||||||
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
|
||||||
|
|
||||||
uart->app->sent_ap = true;
|
|
||||||
|
|
||||||
free(out_data);
|
|
||||||
free(uart->app->ap_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
uart->app->command_index = 0;
|
|
||||||
uart->app->has_command_queue = false;
|
|
||||||
uart->app->command_queue[0] = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(uart->app->sent_reset == false) {
|
if(uart->app->sent_reset == false) {
|
||||||
furi_string_cat(uart->app->portal_logs, (char*)uart->rx_buf);
|
furi_string_cat(uart->app->portal_logs, (char*)uart->rx_buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
#include "../evil_portal_app_i.h"
|
#include "../evil_portal_app_i.h"
|
||||||
#include "../helpers/evil_portal_storage.h"
|
#include "../helpers/evil_portal_storage.h"
|
||||||
|
#include <m-string.h>
|
||||||
|
|
||||||
void evil_portal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
|
void evil_portal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Evil_PortalApp* app = context;
|
Evil_PortalApp* app = context;
|
||||||
|
|
||||||
|
if(app->capture_line) {
|
||||||
|
furi_string_cat_printf(app->captured_line, "%s", buf);
|
||||||
|
}
|
||||||
|
|
||||||
// If text box store gets too big, then truncate it
|
// If text box store gets too big, then truncate it
|
||||||
app->text_box_store_strlen += len;
|
app->text_box_store_strlen += len;
|
||||||
if(app->text_box_store_strlen >= EVIL_PORTAL_TEXT_BOX_STORE_SIZE - 1) {
|
if(app->text_box_store_strlen >= EVIL_PORTAL_TEXT_BOX_STORE_SIZE - 1) {
|
||||||
@@ -16,7 +21,11 @@ void evil_portal_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void
|
|||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
furi_string_cat_printf(app->text_box_store, "%s", buf);
|
furi_string_cat_printf(app->text_box_store, "%s", buf);
|
||||||
|
|
||||||
view_dispatcher_send_custom_event(app->view_dispatcher, Evil_PortalEventRefreshConsoleOutput);
|
text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool captured(Evil_PortalApp* app, const char* str) {
|
||||||
|
return furi_string_search_str(app->captured_line, str) != STRING_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void evil_portal_scene_console_output_on_enter(void* context) {
|
void evil_portal_scene_console_output_on_enter(void* context) {
|
||||||
@@ -73,11 +82,9 @@ void evil_portal_scene_console_output_on_enter(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(0 == strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
if(0 == strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
||||||
app->command_queue[0] = SET_AP_CMD;
|
|
||||||
app->has_command_queue = true;
|
|
||||||
app->command_index = 0;
|
|
||||||
if(app->show_stopscan_tip) {
|
if(app->show_stopscan_tip) {
|
||||||
const char* msg = "Starting portal\nIf no response press\nBACK to return\n";
|
const char* msg =
|
||||||
|
"Starting portal\nMarauder takes a few secs to start\nPress BACK to return\n";
|
||||||
furi_string_cat_str(app->text_box_store, msg);
|
furi_string_cat_str(app->text_box_store, msg);
|
||||||
app->text_box_store_strlen += strlen(msg);
|
app->text_box_store_strlen += strlen(msg);
|
||||||
}
|
}
|
||||||
@@ -104,28 +111,65 @@ void evil_portal_scene_console_output_on_enter(void* context) {
|
|||||||
|
|
||||||
if(app->is_command && app->selected_tx_string) {
|
if(app->is_command && app->selected_tx_string) {
|
||||||
if(0 == strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
if(0 == strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
|
||||||
evil_portal_read_index_html(context);
|
|
||||||
|
|
||||||
FuriString* data = furi_string_alloc();
|
FuriString* data = furi_string_alloc();
|
||||||
furi_string_cat(data, "sethtml=");
|
app->capture_line = true;
|
||||||
furi_string_cat(data, (char*)app->index_html);
|
|
||||||
|
|
||||||
evil_portal_uart_tx(
|
|
||||||
(uint8_t*)(furi_string_get_cstr(data)), strlen(furi_string_get_cstr(data)));
|
|
||||||
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
|
||||||
|
|
||||||
app->sent_html = true;
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
free(app->index_html);
|
|
||||||
|
|
||||||
evil_portal_read_ap_name(context);
|
evil_portal_read_ap_name(context);
|
||||||
|
// Test evil portal syntax and response, marauder ignores it
|
||||||
|
furi_string_printf(data, "setap=%s\n", (char*)app->ap_name);
|
||||||
|
furi_string_reset(app->captured_line);
|
||||||
|
evil_portal_uart_tx((uint8_t*)(furi_string_get_cstr(data)), furi_string_size(data));
|
||||||
|
for(uint8_t t = 0; t < 5 && !captured(app, "ap set"); t++) furi_delay_ms(100);
|
||||||
|
bool icanhazmarauder = !captured(app, "ap set"); // Evil portal didn't respond
|
||||||
|
// Not evil portal, set up marauder
|
||||||
|
if(icanhazmarauder) {
|
||||||
|
furi_string_printf(data, "ssid -a -n '%s'\n", app->ap_name);
|
||||||
|
furi_string_reset(app->captured_line);
|
||||||
|
evil_portal_uart_tx(
|
||||||
|
(uint8_t*)(furi_string_get_cstr(data)), furi_string_size(data));
|
||||||
|
// Marauder echoes the command, maybe still init so wait a while for echo
|
||||||
|
for(uint8_t t = 0; t < 69 && !captured(app, (char*)app->ap_name); t++)
|
||||||
|
furi_delay_ms(100);
|
||||||
|
}
|
||||||
|
free(app->ap_name);
|
||||||
|
|
||||||
|
evil_portal_read_index_html(context);
|
||||||
|
if(icanhazmarauder) {
|
||||||
|
furi_string_reset(app->captured_line);
|
||||||
|
evil_portal_uart_tx(
|
||||||
|
(uint8_t*)("evilportal -c sethtmlstr\n"),
|
||||||
|
strlen("evilportal -c sethtmlstr\n"));
|
||||||
|
for(uint8_t t = 0; t < 5 && !captured(app, "Setting HTML from serial..."); t++)
|
||||||
|
furi_delay_ms(100);
|
||||||
|
// Check for active attack
|
||||||
|
if(captured(app, ">") && !captured(app, "Setting HTML from serial...")) {
|
||||||
|
furi_string_reset(app->captured_line);
|
||||||
|
} else {
|
||||||
|
furi_string_reset(app->captured_line);
|
||||||
|
evil_portal_uart_tx(app->index_html, strlen((char*)app->index_html));
|
||||||
|
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
||||||
|
for(uint8_t t = 0; t < 10 && !captured(app, "html set"); t++)
|
||||||
|
furi_delay_ms(100);
|
||||||
|
evil_portal_uart_tx(
|
||||||
|
(uint8_t*)("evilportal -c start\n"), strlen("evilportal -c start\n"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
furi_string_set(data, "sethtml=");
|
||||||
|
furi_string_cat(data, (char*)app->index_html);
|
||||||
|
evil_portal_uart_tx(
|
||||||
|
(uint8_t*)(furi_string_get_cstr(data)), furi_string_size(data));
|
||||||
|
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(app->index_html);
|
||||||
|
app->capture_line = false;
|
||||||
|
furi_string_reset(app->captured_line);
|
||||||
|
furi_string_free(data);
|
||||||
} else if(0 == strncmp(RESET_CMD, app->selected_tx_string, strlen(RESET_CMD))) {
|
} else if(0 == strncmp(RESET_CMD, app->selected_tx_string, strlen(RESET_CMD))) {
|
||||||
app->sent_html = false;
|
|
||||||
app->sent_ap = false;
|
|
||||||
evil_portal_uart_tx(
|
evil_portal_uart_tx(
|
||||||
(uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
(uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
||||||
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
evil_portal_uart_tx((uint8_t*)("\n"), 1);
|
||||||
|
evil_portal_uart_tx((uint8_t*)("stopscan\n"), strlen("stopscan\n"));
|
||||||
} else if(1 == strncmp("help", app->selected_tx_string, strlen("help"))) {
|
} else if(1 == strncmp("help", app->selected_tx_string, strlen("help"))) {
|
||||||
evil_portal_uart_tx(
|
evil_portal_uart_tx(
|
||||||
(uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
(uint8_t*)(app->selected_tx_string), strlen(app->selected_tx_string));
|
||||||
@@ -135,14 +179,11 @@ void evil_portal_scene_console_output_on_enter(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool evil_portal_scene_console_output_on_event(void* context, SceneManagerEvent event) {
|
bool evil_portal_scene_console_output_on_event(void* context, SceneManagerEvent event) {
|
||||||
Evil_PortalApp* app = context;
|
UNUSED(context);
|
||||||
|
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
|
||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeTick) {
|
||||||
text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
|
|
||||||
consumed = true;
|
|
||||||
} else if(event.type == SceneManagerEventTypeTick) {
|
|
||||||
consumed = true;
|
consumed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user