فهرست منبع

Merge pull request #7 from tcpassos/feature_wifi_marauder_app

Prepared to receive packets via serial and write them to the internal SD card
0xchocolate 2 سال پیش
والد
کامیت
b5e00cb97a

+ 29 - 4
applications/plugins/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c

@@ -3,7 +3,7 @@
 void wifi_marauder_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
 void wifi_marauder_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
     furi_assert(context);
     furi_assert(context);
     WifiMarauderApp* app = context;
     WifiMarauderApp* app = context;
-
+    
     // 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 >= WIFI_MARAUDER_TEXT_BOX_STORE_SIZE - 1) {
     if(app->text_box_store_strlen >= WIFI_MARAUDER_TEXT_BOX_STORE_SIZE - 1) {
@@ -14,10 +14,26 @@ void wifi_marauder_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, vo
     // Null-terminate buf and append to text box store
     // Null-terminate buf and append to text box store
     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, WifiMarauderEventRefreshConsoleOutput);
     view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshConsoleOutput);
 }
 }
 
 
+void wifi_marauder_console_output_handle_rx_packets_cb(uint8_t* buf, size_t len, void* context) {
+    furi_assert(context);
+    WifiMarauderApp* app = context;
+
+    // If it is a sniff function, open the pcap file for recording
+    if (strncmp("sniff", app->selected_tx_string, strlen("sniff")) == 0 && !app->is_writing) {
+        app->is_writing = true;
+        if (!app->capture_file || !storage_file_is_open(app->capture_file)) {
+            wifi_marauder_create_pcap_file(app);
+        }
+    }
+
+    if (app->is_writing) {
+        storage_file_write(app->capture_file, buf, len);
+    }
+}
+
 void wifi_marauder_scene_console_output_on_enter(void* context) {
 void wifi_marauder_scene_console_output_on_enter(void* context) {
     WifiMarauderApp* app = context;
     WifiMarauderApp* app = context;
 
 
@@ -34,7 +50,7 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
         app->text_box_store_strlen = 0;
         app->text_box_store_strlen = 0;
         if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
         if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
             const char* help_msg =
             const char* help_msg =
-                "Marauder companion " WIFI_MARAUDER_APP_VERSION "\nFor app support/feedback,\nreach out to me:\n@cococode#6011 (discord)\n0xchocolate (github)\n";
+                "Marauder companion " WIFI_MARAUDER_APP_VERSION "\n";
             furi_string_cat_str(app->text_box_store, help_msg);
             furi_string_cat_str(app->text_box_store, help_msg);
             app->text_box_store_strlen += strlen(help_msg);
             app->text_box_store_strlen += strlen(help_msg);
         }
         }
@@ -54,7 +70,9 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
 
 
     // Register callback to receive data
     // Register callback to receive data
     wifi_marauder_uart_set_handle_rx_data_cb(
     wifi_marauder_uart_set_handle_rx_data_cb(
-        app->uart, wifi_marauder_console_output_handle_rx_data_cb); // setup callback for rx thread
+        app->uart, wifi_marauder_console_output_handle_rx_data_cb); // setup callback for general log rx thread
+    wifi_marauder_uart_set_handle_rx_data_cb(
+        app->lp_uart, wifi_marauder_console_output_handle_rx_packets_cb); // setup callback for packets rx thread
 
 
     // Send command with newline '\n'
     // Send command with newline '\n'
     if(app->is_command && app->selected_tx_string) {
     if(app->is_command && app->selected_tx_string) {
@@ -84,9 +102,16 @@ void wifi_marauder_scene_console_output_on_exit(void* context) {
 
 
     // Unregister rx callback
     // Unregister rx callback
     wifi_marauder_uart_set_handle_rx_data_cb(app->uart, NULL);
     wifi_marauder_uart_set_handle_rx_data_cb(app->uart, NULL);
+    wifi_marauder_uart_set_handle_rx_data_cb(app->lp_uart, NULL);
 
 
     // Automatically stop the scan when exiting view
     // Automatically stop the scan when exiting view
     if(app->is_command) {
     if(app->is_command) {
         wifi_marauder_uart_tx((uint8_t*)("stopscan\n"), strlen("stopscan\n"));
         wifi_marauder_uart_tx((uint8_t*)("stopscan\n"), strlen("stopscan\n"));
     }
     }
+
+    app->is_writing = false;
+    if (app->capture_file && storage_file_is_open(app->capture_file)) {
+        storage_file_close(app->capture_file);
+    }
+
 }
 }

+ 19 - 1
applications/plugins/wifi_marauder_companion/wifi_marauder_app.c

@@ -25,6 +25,9 @@ WifiMarauderApp* wifi_marauder_app_alloc() {
     WifiMarauderApp* app = malloc(sizeof(WifiMarauderApp));
     WifiMarauderApp* app = malloc(sizeof(WifiMarauderApp));
 
 
     app->gui = furi_record_open(RECORD_GUI);
     app->gui = furi_record_open(RECORD_GUI);
+    app->dialogs = furi_record_open(RECORD_DIALOGS);
+    app->storage = furi_record_open(RECORD_STORAGE);
+    app->capture_file = storage_file_alloc(app->storage);
 
 
     app->view_dispatcher = view_dispatcher_alloc();
     app->view_dispatcher = view_dispatcher_alloc();
     app->scene_manager = scene_manager_alloc(&wifi_marauder_scene_handlers, app);
     app->scene_manager = scene_manager_alloc(&wifi_marauder_scene_handlers, app);
@@ -67,6 +70,14 @@ WifiMarauderApp* wifi_marauder_app_alloc() {
     return app;
     return app;
 }
 }
 
 
+void wifi_marauder_make_app_folder(WifiMarauderApp* app) {
+    furi_assert(app);
+
+    if (!storage_simply_mkdir(app->storage, MARAUDER_APP_FOLDER)) {
+        dialog_message_show_storage_error(app->dialogs, "Cannot create\napp folder");
+    }
+}
+
 void wifi_marauder_app_free(WifiMarauderApp* app) {
 void wifi_marauder_app_free(WifiMarauderApp* app) {
     furi_assert(app);
     furi_assert(app);
 
 
@@ -77,15 +88,19 @@ void wifi_marauder_app_free(WifiMarauderApp* app) {
     text_box_free(app->text_box);
     text_box_free(app->text_box);
     furi_string_free(app->text_box_store);
     furi_string_free(app->text_box_store);
     text_input_free(app->text_input);
     text_input_free(app->text_input);
+    storage_file_free(app->capture_file);
 
 
     // View dispatcher
     // View dispatcher
     view_dispatcher_free(app->view_dispatcher);
     view_dispatcher_free(app->view_dispatcher);
     scene_manager_free(app->scene_manager);
     scene_manager_free(app->scene_manager);
 
 
     wifi_marauder_uart_free(app->uart);
     wifi_marauder_uart_free(app->uart);
+    wifi_marauder_uart_free(app->lp_uart);
 
 
     // Close records
     // Close records
     furi_record_close(RECORD_GUI);
     furi_record_close(RECORD_GUI);
+    furi_record_close(RECORD_STORAGE);
+    furi_record_close(RECORD_DIALOGS);
 
 
     free(app);
     free(app);
 }
 }
@@ -94,7 +109,10 @@ int32_t wifi_marauder_app(void* p) {
     UNUSED(p);
     UNUSED(p);
     WifiMarauderApp* wifi_marauder_app = wifi_marauder_app_alloc();
     WifiMarauderApp* wifi_marauder_app = wifi_marauder_app_alloc();
 
 
-    wifi_marauder_app->uart = wifi_marauder_uart_init(wifi_marauder_app);
+    wifi_marauder_make_app_folder(wifi_marauder_app);
+
+    wifi_marauder_app->uart = wifi_marauder_usart_init(wifi_marauder_app);
+    wifi_marauder_app->lp_uart = wifi_marauder_lp_uart_init(wifi_marauder_app);
 
 
     view_dispatcher_run(wifi_marauder_app->view_dispatcher);
     view_dispatcher_run(wifi_marauder_app->view_dispatcher);
 
 

+ 11 - 1
applications/plugins/wifi_marauder_companion/wifi_marauder_app_i.h

@@ -6,6 +6,7 @@
 #include "scenes/wifi_marauder_scene.h"
 #include "scenes/wifi_marauder_scene.h"
 #include "wifi_marauder_custom_event.h"
 #include "wifi_marauder_custom_event.h"
 #include "wifi_marauder_uart.h"
 #include "wifi_marauder_uart.h"
+#include "wifi_marauder_pcap.h"
 
 
 #include <gui/gui.h>
 #include <gui/gui.h>
 #include <gui/view_dispatcher.h>
 #include <gui/view_dispatcher.h>
@@ -14,11 +15,16 @@
 #include <gui/modules/text_input.h>
 #include <gui/modules/text_input.h>
 #include <gui/modules/variable_item_list.h>
 #include <gui/modules/variable_item_list.h>
 
 
+#include <storage/storage.h>
+#include <dialogs/dialogs.h>
+
 #define NUM_MENU_ITEMS (16)
 #define NUM_MENU_ITEMS (16)
 
 
 #define WIFI_MARAUDER_TEXT_BOX_STORE_SIZE (4096)
 #define WIFI_MARAUDER_TEXT_BOX_STORE_SIZE (4096)
 #define WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE (512)
 #define WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE (512)
 
 
+#define MARAUDER_APP_FOLDER ANY_PATH("apps_data/marauder")
+
 struct WifiMarauderApp {
 struct WifiMarauderApp {
     Gui* gui;
     Gui* gui;
     ViewDispatcher* view_dispatcher;
     ViewDispatcher* view_dispatcher;
@@ -29,11 +35,14 @@ struct WifiMarauderApp {
     size_t text_box_store_strlen;
     size_t text_box_store_strlen;
     TextBox* text_box;
     TextBox* text_box;
     TextInput* text_input;
     TextInput* text_input;
-    //Widget* widget;
+    Storage* storage;
+    File* capture_file;
+    DialogsApp* dialogs;
 
 
     VariableItemList* var_item_list;
     VariableItemList* var_item_list;
 
 
     WifiMarauderUart* uart;
     WifiMarauderUart* uart;
+    WifiMarauderUart* lp_uart;
     int selected_menu_index;
     int selected_menu_index;
     int selected_option_index[NUM_MENU_ITEMS];
     int selected_option_index[NUM_MENU_ITEMS];
     const char* selected_tx_string;
     const char* selected_tx_string;
@@ -41,6 +50,7 @@ struct WifiMarauderApp {
     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 is_writing;
 
 
     // For input source and destination MAC in targeted deauth attack
     // For input source and destination MAC in targeted deauth attack
     int special_case_input_step;
     int special_case_input_step;

+ 27 - 0
applications/plugins/wifi_marauder_companion/wifi_marauder_pcap.c

@@ -0,0 +1,27 @@
+#include "wifi_marauder_app_i.h"
+#include "wifi_marauder_pcap.h"
+
+void wifi_marauder_get_prefix_from_cmd(char* dest, const char* command) {
+    int start, end, delta;
+    start = strlen("sniff");
+    end = strcspn(command, " ");
+    delta = end - start;
+    strncpy(dest, command + start, end - start);
+    dest[delta] = '\0';    
+}
+
+void wifi_marauder_create_pcap_file(WifiMarauderApp* app) {
+    char prefix[10];
+    char capture_file_path[100];
+    wifi_marauder_get_prefix_from_cmd(prefix, app->selected_tx_string);
+
+    int i=0;
+    do{
+        snprintf(capture_file_path, sizeof(capture_file_path), "%s/%s_%d.pcap", MARAUDER_APP_FOLDER, prefix, i);
+        i++;
+    } while(storage_file_exists(app->storage, capture_file_path));
+
+    if (!storage_file_open(app->capture_file, capture_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
+        dialog_message_show_storage_error(app->dialogs, "Cannot open pcap file");
+    }
+}

+ 11 - 0
applications/plugins/wifi_marauder_companion/wifi_marauder_pcap.h

@@ -0,0 +1,11 @@
+#pragma once
+
+#include "furi_hal.h"
+
+/**
+ * Creates a PCAP file to store incoming packets.
+ * The file name will have a prefix according to the type of scan being performed by the application (Eg: raw_0.pcap)
+ * 
+ * @param app Application context
+ */
+void wifi_marauder_create_pcap_file(WifiMarauderApp* app);

+ 25 - 7
applications/plugins/wifi_marauder_companion/wifi_marauder_uart.c

@@ -2,10 +2,12 @@
 #include "wifi_marauder_uart.h"
 #include "wifi_marauder_uart.h"
 
 
 #define UART_CH (FuriHalUartIdUSART1)
 #define UART_CH (FuriHalUartIdUSART1)
+#define LP_UART_CH (FuriHalUartIdLPUART1)
 #define BAUDRATE (115200)
 #define BAUDRATE (115200)
 
 
 struct WifiMarauderUart {
 struct WifiMarauderUart {
     WifiMarauderApp* app;
     WifiMarauderApp* app;
+    FuriHalUartId channel;
     FuriThread* rx_thread;
     FuriThread* rx_thread;
     FuriStreamBuffer* rx_stream;
     FuriStreamBuffer* rx_stream;
     uint8_t rx_buf[RX_BUF_SIZE + 1];
     uint8_t rx_buf[RX_BUF_SIZE + 1];
@@ -60,25 +62,41 @@ void wifi_marauder_uart_tx(uint8_t* data, size_t len) {
     furi_hal_uart_tx(UART_CH, data, len);
     furi_hal_uart_tx(UART_CH, data, len);
 }
 }
 
 
-WifiMarauderUart* wifi_marauder_uart_init(WifiMarauderApp* app) {
+void wifi_marauder_lp_uart_tx(uint8_t* data, size_t len) {
+    furi_hal_uart_tx(LP_UART_CH, data, len);
+}
+
+WifiMarauderUart* wifi_marauder_uart_init(WifiMarauderApp* app, FuriHalUartId channel, const char* thread_name) {
     WifiMarauderUart* uart = malloc(sizeof(WifiMarauderUart));
     WifiMarauderUart* uart = malloc(sizeof(WifiMarauderUart));
 
 
     uart->app = app;
     uart->app = app;
+    uart->channel = channel;
     uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
     uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
     uart->rx_thread = furi_thread_alloc();
     uart->rx_thread = furi_thread_alloc();
-    furi_thread_set_name(uart->rx_thread, "WifiMarauderUartRxThread");
+    furi_thread_set_name(uart->rx_thread, thread_name);
     furi_thread_set_stack_size(uart->rx_thread, 1024);
     furi_thread_set_stack_size(uart->rx_thread, 1024);
     furi_thread_set_context(uart->rx_thread, uart);
     furi_thread_set_context(uart->rx_thread, uart);
     furi_thread_set_callback(uart->rx_thread, uart_worker);
     furi_thread_set_callback(uart->rx_thread, uart_worker);
     furi_thread_start(uart->rx_thread);
     furi_thread_start(uart->rx_thread);
-
-    furi_hal_console_disable();
-    furi_hal_uart_set_br(UART_CH, BAUDRATE);
-    furi_hal_uart_set_irq_cb(UART_CH, wifi_marauder_uart_on_irq_cb, uart);
+    if(channel == FuriHalUartIdUSART1) {
+        furi_hal_console_disable();
+    } else if(channel == FuriHalUartIdLPUART1) {
+        furi_hal_uart_init(channel, BAUDRATE);
+    }
+    furi_hal_uart_set_br(channel, BAUDRATE);
+    furi_hal_uart_set_irq_cb(channel, wifi_marauder_uart_on_irq_cb, uart);
 
 
     return uart;
     return uart;
 }
 }
 
 
+WifiMarauderUart* wifi_marauder_usart_init(WifiMarauderApp* app) {
+    return wifi_marauder_uart_init(app, UART_CH,"WifiMarauderUartRxThread");
+}
+
+WifiMarauderUart* wifi_marauder_lp_uart_init(WifiMarauderApp* app) {
+    return wifi_marauder_uart_init(app, LP_UART_CH,"WifiMarauderLPUartRxThread");
+}
+
 void wifi_marauder_uart_free(WifiMarauderUart* uart) {
 void wifi_marauder_uart_free(WifiMarauderUart* uart) {
     furi_assert(uart);
     furi_assert(uart);
 
 
@@ -86,7 +104,7 @@ void wifi_marauder_uart_free(WifiMarauderUart* uart) {
     furi_thread_join(uart->rx_thread);
     furi_thread_join(uart->rx_thread);
     furi_thread_free(uart->rx_thread);
     furi_thread_free(uart->rx_thread);
 
 
-    furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
+    furi_hal_uart_set_irq_cb(uart->channel, NULL, NULL);
     furi_hal_console_enable();
     furi_hal_console_enable();
 
 
     free(uart);
     free(uart);

+ 3 - 1
applications/plugins/wifi_marauder_companion/wifi_marauder_uart.h

@@ -10,5 +10,7 @@ void wifi_marauder_uart_set_handle_rx_data_cb(
     WifiMarauderUart* uart,
     WifiMarauderUart* uart,
     void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context));
     void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context));
 void wifi_marauder_uart_tx(uint8_t* data, size_t len);
 void wifi_marauder_uart_tx(uint8_t* data, size_t len);
-WifiMarauderUart* wifi_marauder_uart_init(WifiMarauderApp* app);
+void wifi_marauder_lp_uart_tx(uint8_t* data, size_t len);
+WifiMarauderUart* wifi_marauder_usart_init(WifiMarauderApp* app);
+WifiMarauderUart* wifi_marauder_lp_uart_init(WifiMarauderApp* app);
 void wifi_marauder_uart_free(WifiMarauderUart* uart);
 void wifi_marauder_uart_free(WifiMarauderUart* uart);