Lets try new changes for marauder companion

https://github.com/tcpassos/flipperzero-firmware-with-wifi-marauder-companion
This commit is contained in:
MX 2023-03-16 00:00:10 +03:00
parent 2a040f245f
commit 2046ac6604
No known key found for this signature in database
GPG Key ID: 7CCC66B7DBDD1C83
9 changed files with 147 additions and 19 deletions

View File

@ -135,7 +135,7 @@ You can support us by using links or addresses below:
- WAV Player [(OFW: DrZlo13)](https://github.com/flipperdevices/flipperzero-firmware/tree/zlo/wav-player) - Fixed and improved by [LTVA1](https://github.com/LTVA1/wav_player)
- Barcode generator plugin [(original by McAzzaMan)](https://github.com/McAzzaMan/flipperzero-firmware/tree/UPC-A_Barcode_Generator/applications/barcode_generator) - [EAN-8 and refactoring](https://github.com/DarkFlippers/unleashed-firmware/pull/154) by @msvsergey
- GPIO: Sentry Safe plugin [(by H4ckd4ddy)](https://github.com/H4ckd4ddy/flipperzero-sentry-safe-plugin)
- ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion)
- ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion) - Saving pcap on flipper microSD [by tcpassos](https://github.com/tcpassos/flipperzero-firmware-with-wifi-marauder-companion)
- NRF24: Sniffer & MouseJacker (with changes) [(by mothball187)](https://github.com/mothball187/flipperzero-nrf24/tree/main/mousejacker)
- Simple Clock (timer by GMMan) [(original by CompaqDisc)](https://gist.github.com/CompaqDisc/4e329c501bd03c1e801849b81f48ea61)
- **Sub-GHz Remote** (UniversalRF Remix) [(by @darmiel & @xMasterX)](https://github.com/darmiel/flipper-playlist/tree/feat/unirf-protocols) (original by @ESurge)

View File

@ -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
buf[len] = '\0';
furi_string_cat_printf(app->text_box_store, "%s", buf);
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) {
WifiMarauderApp* app = context;
@ -33,8 +49,8 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
furi_string_reset(app->text_box_store);
app->text_box_store_strlen = 0;
if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
const char* help_msg =
"Marauder companion v0.3.0\nFor app support/feedback,\nreach out to me:\n@cococode#6011 (discord)\n0xchocolate (github)\n";
const char* help_msg = "Marauder companion " WIFI_MARAUDER_APP_VERSION
"\nby @0xchocolate\nmodified by @tcpassos\n";
furi_string_cat_str(app->text_box_store, help_msg);
app->text_box_store_strlen += strlen(help_msg);
}
@ -54,7 +70,11 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
// Register callback to receive data
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'
if(app->is_command && app->selected_tx_string) {
@ -84,9 +104,15 @@ void wifi_marauder_scene_console_output_on_exit(void* context) {
// Unregister rx callback
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
if(app->is_command) {
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);
}
}

View File

@ -25,6 +25,9 @@ WifiMarauderApp* wifi_marauder_app_alloc() {
WifiMarauderApp* app = malloc(sizeof(WifiMarauderApp));
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->scene_manager = scene_manager_alloc(&wifi_marauder_scene_handlers, app);
@ -67,6 +70,14 @@ WifiMarauderApp* wifi_marauder_app_alloc() {
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) {
furi_assert(app);
@ -77,33 +88,47 @@ void wifi_marauder_app_free(WifiMarauderApp* app) {
text_box_free(app->text_box);
furi_string_free(app->text_box_store);
text_input_free(app->text_input);
storage_file_free(app->capture_file);
// View dispatcher
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
wifi_marauder_uart_free(app->uart);
wifi_marauder_uart_free(app->lp_uart);
// Close records
furi_record_close(RECORD_GUI);
furi_record_close(RECORD_STORAGE);
furi_record_close(RECORD_DIALOGS);
free(app);
}
int32_t wifi_marauder_app(void* p) {
UNUSED(p);
furi_hal_power_enable_otg();
furi_delay_ms(300);
uint8_t attempts = 0;
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
furi_delay_ms(200);
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);
wifi_marauder_app_free(wifi_marauder_app);
furi_hal_power_disable_otg();
if(furi_hal_power_is_otg_enabled()) {
furi_hal_power_disable_otg();
}
return 0;
}

View File

@ -4,6 +4,8 @@
extern "C" {
#endif
#define WIFI_MARAUDER_APP_VERSION "v0.3.1"
typedef struct WifiMarauderApp WifiMarauderApp;
#ifdef __cplusplus

View File

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

View File

@ -0,0 +1,33 @@
#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");
}
}

View File

@ -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);

View File

@ -2,10 +2,12 @@
#include "wifi_marauder_uart.h"
#define UART_CH (FuriHalUartIdUSART1)
#define LP_UART_CH (FuriHalUartIdLPUART1)
#define BAUDRATE (115200)
struct WifiMarauderUart {
WifiMarauderApp* app;
FuriHalUartId channel;
FuriThread* rx_thread;
FuriStreamBuffer* rx_stream;
uint8_t rx_buf[RX_BUF_SIZE + 1];
@ -60,25 +62,42 @@ void wifi_marauder_uart_tx(uint8_t* data, size_t 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));
uart->app = app;
uart->channel = channel;
uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
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_context(uart->rx_thread, uart);
furi_thread_set_callback(uart->rx_thread, uart_worker);
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;
}
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) {
furi_assert(uart);
@ -86,7 +105,7 @@ void wifi_marauder_uart_free(WifiMarauderUart* uart) {
furi_thread_join(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();
free(uart);

View File

@ -10,5 +10,7 @@ void wifi_marauder_uart_set_handle_rx_data_cb(
WifiMarauderUart* uart,
void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context));
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);