Skip to content

Commit 5244581

Browse files
committed
Created config to send sniffed packets over serial
1 parent 59a0379 commit 5244581

File tree

6 files changed

+113
-30
lines changed

6 files changed

+113
-30
lines changed

esp32_marauder/Buffer.cpp

+36-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ void Buffer::open(fs::FS* fs, String fn){
1818
file = fs->open(fileName, FILE_WRITE);
1919
file.close();
2020

21+
openPcap();
22+
}
23+
24+
void Buffer::openPcap(){
2125
bufSizeA = 0;
22-
bufSizeB = 0;
23-
26+
bufSizeB = 0;
2427
writing = true;
2528

2629
write(uint32_t(0xa1b2c3d4)); // magic number
@@ -30,10 +33,9 @@ void Buffer::open(fs::FS* fs, String fn){
3033
write(uint32_t(0)); // accuracy of timestamps
3134
write(uint32_t(SNAP_LEN)); // max length of captured packets, in octets
3235
write(uint32_t(105)); // data link type
33-
34-
//useSD = true;
3536
}
3637

38+
3739
void Buffer::close(fs::FS* fs){
3840
if(!writing) return;
3941
forceSave(fs);
@@ -201,3 +203,33 @@ void Buffer::forceSave(fs::FS* fs){
201203
saving = false;
202204
writing = true;
203205
}
206+
207+
void Buffer::forceSaveSerial() {
208+
uint32_t len = bufSizeA + bufSizeB;
209+
if(len == 0) return;
210+
211+
saving = true;
212+
writing = false;
213+
214+
if(useA){
215+
if(bufSizeB > 0){
216+
Serial.write(bufB, bufSizeB);
217+
bufSizeB = 0;
218+
}
219+
if(bufSizeA > 0){
220+
Serial.write(bufA, bufSizeA);
221+
bufSizeA = 0;
222+
}
223+
} else {
224+
if(bufSizeA > 0){
225+
Serial.write(bufA, bufSizeA);
226+
bufSizeA = 0;
227+
}
228+
if(bufSizeB > 0){
229+
Serial.write(bufB, bufSizeB);
230+
bufSizeB = 0;
231+
}
232+
}
233+
saving = false;
234+
writing = true;
235+
}

esp32_marauder/Buffer.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ class Buffer {
1717
public:
1818
Buffer();
1919
void open(fs::FS* fs, String fn = "");
20+
void openPcap();
2021
void close(fs::FS* fs);
2122
void addPacket(uint8_t* buf, uint32_t len);
2223
void save(fs::FS* fs);
2324
void forceSave(fs::FS* fs);
25+
void forceSaveSerial();
2426
private:
2527
void write(int32_t n);
2628
void write(uint32_t n);

esp32_marauder/CommandLine.cpp

+38-14
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ void CommandLine::main(uint32_t currentTime) {
3030

3131
this->runCommand(input);
3232

33-
if (input != "")
34-
Serial.print("> ");
33+
if (input != "") {
34+
#ifndef SNIFF_SERIAL
35+
Serial.print("> ");
36+
#endif
37+
}
3538
}
3639

3740
LinkedList<String> CommandLine::parseCommand(String input, char* delim) {
@@ -94,10 +97,13 @@ bool CommandLine::hasSSIDs() {
9497
}
9598

9699
void CommandLine::runCommand(String input) {
97-
if (input != "")
98-
Serial.println("#" + input);
99-
else
100+
if (input != "") {
101+
#ifndef SNIFF_SERIAL
102+
Serial.println("#" + input);
103+
#endif
104+
} else {
100105
return;
106+
}
101107

102108
LinkedList<String> cmd_args = this->parseCommand(input, " ");
103109

@@ -266,7 +272,9 @@ void CommandLine::runCommand(String input) {
266272
}
267273
// Raw sniff
268274
else if (cmd_args.get(0) == SNIFF_RAW_CMD) {
269-
Serial.println("Starting Raw sniff. Stop with " + (String)STOPSCAN_CMD);
275+
#ifndef SNIFF_SERIAL
276+
Serial.println("Starting Raw sniff. Stop with " + (String)STOPSCAN_CMD);
277+
#endif
270278
#ifdef HAS_SCREEN
271279
display_obj.clearScreen();
272280
menu_function_obj.drawStatusBar();
@@ -284,7 +292,9 @@ void CommandLine::runCommand(String input) {
284292
}
285293
// Beacon sniff
286294
else if (cmd_args.get(0) == SNIFF_BEACON_CMD) {
287-
Serial.println("Starting Beacon sniff. Stop with " + (String)STOPSCAN_CMD);
295+
#ifndef SNIFF_SERIAL
296+
Serial.println("Starting Beacon sniff. Stop with " + (String)STOPSCAN_CMD);
297+
#endif
288298
#ifdef HAS_SCREEN
289299
display_obj.clearScreen();
290300
menu_function_obj.drawStatusBar();
@@ -293,7 +303,9 @@ void CommandLine::runCommand(String input) {
293303
}
294304
// Probe sniff
295305
else if (cmd_args.get(0) == SNIFF_PROBE_CMD) {
296-
Serial.println("Starting Probe sniff. Stop with " + (String)STOPSCAN_CMD);
306+
#ifndef SNIFF_SERIAL
307+
Serial.println("Starting Probe sniff. Stop with " + (String)STOPSCAN_CMD);
308+
#endif
297309
#ifdef HAS_SCREEN
298310
display_obj.clearScreen();
299311
menu_function_obj.drawStatusBar();
@@ -302,7 +314,9 @@ void CommandLine::runCommand(String input) {
302314
}
303315
// Deauth sniff
304316
else if (cmd_args.get(0) == SNIFF_DEAUTH_CMD) {
305-
Serial.println("Starting Deauth sniff. Stop with " + (String)STOPSCAN_CMD);
317+
#ifndef SNIFF_SERIAL
318+
Serial.println("Starting Deauth sniff. Stop with " + (String)STOPSCAN_CMD);
319+
#endif
306320
#ifdef HAS_SCREEN
307321
display_obj.clearScreen();
308322
menu_function_obj.drawStatusBar();
@@ -311,7 +325,9 @@ void CommandLine::runCommand(String input) {
311325
}
312326
// Pwn sniff
313327
else if (cmd_args.get(0) == SNIFF_PWN_CMD) {
314-
Serial.println("Starting Pwnagotchi sniff. Stop with " + (String)STOPSCAN_CMD);
328+
#ifndef SNIFF_SERIAL
329+
Serial.println("Starting Pwnagotchi sniff. Stop with " + (String)STOPSCAN_CMD);
330+
#endif
315331
#ifdef HAS_SCREEN
316332
display_obj.clearScreen();
317333
menu_function_obj.drawStatusBar();
@@ -320,7 +336,9 @@ void CommandLine::runCommand(String input) {
320336
}
321337
// Espressif sniff
322338
else if (cmd_args.get(0) == SNIFF_ESP_CMD) {
323-
Serial.println("Starting Espressif device sniff. Stop with " + (String)STOPSCAN_CMD);
339+
#ifndef SNIFF_SERIAL
340+
Serial.println("Starting Espressif device sniff. Stop with " + (String)STOPSCAN_CMD);
341+
#endif
324342
#ifdef HAS_SCREEN
325343
display_obj.clearScreen();
326344
menu_function_obj.drawStatusBar();
@@ -335,16 +353,22 @@ void CommandLine::runCommand(String input) {
335353
if (ch_sw != -1) {
336354
wifi_scan_obj.set_channel = cmd_args.get(ch_sw + 1).toInt();
337355
wifi_scan_obj.changeChannel();
338-
Serial.println("Set channel: " + (String)wifi_scan_obj.set_channel);
356+
#ifndef SNIFF_SERIAL
357+
Serial.println("Set channel: " + (String)wifi_scan_obj.set_channel);
358+
#endif
339359

340360
}
341361

342362
if (d_sw == -1) {
343-
Serial.println("Starting PMKID sniff on channel " + (String)wifi_scan_obj.set_channel + ". Stop with " + (String)STOPSCAN_CMD);
363+
#ifndef SNIFF_SERIAL
364+
Serial.println("Starting PMKID sniff on channel " + (String)wifi_scan_obj.set_channel + ". Stop with " + (String)STOPSCAN_CMD);
365+
#endif
344366
wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
345367
}
346368
else {
347-
Serial.println("Starting PMKID sniff with deauthentication on channel " + (String)wifi_scan_obj.set_channel + ". Stop with " + (String)STOPSCAN_CMD);
369+
#ifndef SNIFF_SERIAL
370+
Serial.println("Starting PMKID sniff with deauthentication on channel " + (String)wifi_scan_obj.set_channel + ". Stop with " + (String)STOPSCAN_CMD);
371+
#endif
348372
wifi_scan_obj.StartScan(WIFI_SCAN_ACTIVE_EAPOL, TFT_VIOLET);
349373
}
350374
}

esp32_marauder/SDInterface.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,25 @@ bool SDInterface::initSD() {
7070
}
7171

7272
void SDInterface::addPacket(uint8_t* buf, uint32_t len) {
73-
if ((this->supported) && (this->do_save)) {
73+
if (!this->do_save)
74+
return;
75+
76+
#ifdef SNIFF_SERIAL
77+
buffer_obj.addPacket(buf, len);
78+
return;
79+
#endif
80+
81+
if ((this->supported)) {
7482
buffer_obj.addPacket(buf, len);
7583
}
7684
}
7785

7886
void SDInterface::openCapture(String file_name) {
87+
#ifdef SNIFF_SERIAL
88+
buffer_obj.openPcap();
89+
return;
90+
#endif
91+
7992
if (this->supported)
8093
buffer_obj.open(&SD, file_name);
8194
}
@@ -216,6 +229,11 @@ bool SDInterface::checkDetectPin() {
216229
}
217230

218231
void SDInterface::main() {
232+
#ifdef SNIFF_SERIAL
233+
buffer_obj.forceSaveSerial();
234+
return;
235+
#endif
236+
219237
if ((this->supported) && (this->do_save)) {
220238
//Serial.println("Saving packet...");
221239
buffer_obj.forceSave(&SD);

esp32_marauder/WiFiScan.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -2087,17 +2087,20 @@ void WiFiScan::rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
20872087
const WifiMgmtHdr *hdr = &ipkt->hdr;
20882088
}
20892089

2090-
Serial.print("RSSI: ");
2091-
Serial.print(snifferPacket->rx_ctrl.rssi);
2092-
Serial.print(" Ch: ");
2093-
Serial.print(snifferPacket->rx_ctrl.channel);
2094-
Serial.print(" BSSID: ");
20952090
char addr[] = "00:00:00:00:00:00";
20962091
getMAC(addr, snifferPacket->payload, 10);
2097-
Serial.print(addr);
2092+
2093+
#ifndef SNIFF_SERIAL
2094+
Serial.print("RSSI: ");
2095+
Serial.print(snifferPacket->rx_ctrl.rssi);
2096+
Serial.print(" Ch: ");
2097+
Serial.print(snifferPacket->rx_ctrl.channel);
2098+
Serial.print(" BSSID: ");
2099+
Serial.print(addr);
2100+
#endif
2101+
20982102
display_string.concat(text_table4[0]);
20992103
display_string.concat(snifferPacket->rx_ctrl.rssi);
2100-
21012104
display_string.concat(" ");
21022105
display_string.concat(addr);
21032106

@@ -2109,7 +2112,9 @@ void WiFiScan::rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
21092112
display_string.concat(" ");
21102113
}
21112114

2112-
Serial.print(" ");
2115+
#ifndef SNIFF_SERIAL
2116+
Serial.print(" ");
2117+
#endif
21132118

21142119
if (display_obj.display_buffer->size() == 0)
21152120
{
@@ -2119,9 +2124,9 @@ void WiFiScan::rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
21192124
}
21202125
#endif
21212126

2122-
2123-
2124-
Serial.println();
2127+
#ifndef SNIFF_SERIAL
2128+
Serial.println();
2129+
#endif
21252130

21262131
if (save_packet)
21272132
sd_obj.addPacket(snifferPacket->payload, len);

esp32_marauder/configs.h

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#define configs_h
44

55
#define POLISH_POTATO
6+
7+
#define SNIFF_SERIAL
68

79
//#define MARAUDER_MINI
810
//#define MARAUDER_V4

0 commit comments

Comments
 (0)