Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

adapt new features to be able to build on m5stick without iram overflow

Geo2a4032f9fee2
diff --git a/src/Abstracts/ANetworkController.cpp b/src/Abstracts/ANetworkController.cpp
index b8e93436..dd65e047 100644
--- a/src/Abstracts/ANetworkController.cpp
+++ b/src/Abstracts/ANetworkController.cpp
@@ -47,6 +47,8 @@ void ANetworkController::handlePing(const TerminalCommand &cmd)
return;
}
+ #ifndef DEVICE_M5STICK
+
auto args = argTransformer.splitArgs(cmd.getArgs());
int pingCount = 5, pingTimeout = 1000, pingInterval = 200;
@@ -85,6 +87,20 @@ void ANetworkController::handlePing(const TerminalCommand &cmd)
vTaskDelay(pdMS_TO_TICKS(50));
terminalView.print(icmpService.getReport());
+
+
+ #else
+
+ const unsigned long t0 = millis();
+ const bool ok = Ping.ping(host.c_str(), 1);
+ const unsigned long t1 = millis();
+ if (ok) {
+ terminalView.println("Ping: " + host + " successful, " + std::to_string(t1 - t0) + " ms");
+ } else {
+ terminalView.println("Ping: " + host + " failed.");
+ }
+
+ #endif
}
void ANetworkController::handleDiscovery(const TerminalCommand &cmd)
diff --git a/src/Abstracts/ANetworkController.h b/src/Abstracts/ANetworkController.h
index 59e8560a..4b832ea8 100644
--- a/src/Abstracts/ANetworkController.h
+++ b/src/Abstracts/ANetworkController.h
@@ -2,6 +2,7 @@
#include <Arduino.h>
#include <string>
+#include <ESP32Ping.h>
#include "Interfaces/ITerminalView.h"
#include "Interfaces/IInput.h"
#include "Services/WifiService.h"
diff --git a/src/Controllers/TwoWireController.cpp b/src/Controllers/TwoWireController.cpp
index 39b9dcb2..b3502da7 100644
--- a/src/Controllers/TwoWireController.cpp
+++ b/src/Controllers/TwoWireController.cpp
@@ -39,6 +39,10 @@ void TwoWireController::handleInstruction(const std::vector<ByteCode>& bytecodes
Sniff
*/
void TwoWireController::handleSniff() {
+
+ // IRAM overflow for M5tick, not enough space left in IRAM
+ #ifndef DEVICE_M5STICK
+
ensureConfigured();
terminalView.println("2WIRE Sniffer: Running on CLK/IO... Press [ENTER] to stop\r\n");
@@ -108,6 +112,12 @@ void TwoWireController::handleSniff() {
twoWireService.stopSniffer();
terminalView.println("\r\n2WIRE Sniffer: Stopped by user.");
+
+ #else
+
+ terminalView.println("\r\n2WIRE Sniffer: M5Stick not supported.");
+
+ #endif
}
/*
diff --git a/src/Services/ICMPService.cpp b/src/Services/ICMPService.cpp
index 2bb2d5bd..c7582724 100644
--- a/src/Services/ICMPService.cpp
+++ b/src/Services/ICMPService.cpp
@@ -4,6 +4,7 @@
#include <freertos/task.h>
#include <vector>
#include <algorithm>
+#include <ESP32Ping.h>
#include "lwip/inet.h"
#include "lwip/netdb.h"
@@ -99,7 +100,7 @@ void ICMPService::discoveryTask(void* params){
ip4_addr_t targetIP;
uint32_t targetsResponded = 0;
- pushICMPLog("Discovery: Scanning network for devices...");
+ pushICMPLog("Discovery: Scanning network for devices... Press [ENTER] to stop.");
if (!ip4addr_aton(deviceIP.c_str(), &targetIP))
{
@@ -138,6 +139,9 @@ void ICMPService::discoveryTask(void* params){
service->cleanupICMPService();
auto *params = new ICMPTaskParams{targetIPStr, 2, 150, 100, service};
+
+ #ifndef DEVICE_M5STICK
+
xTaskCreatePinnedToCore(pingAPI, "ICMPPing", 4096, params, 1, nullptr, 1);
while (!service->pingReady)
@@ -148,6 +152,23 @@ void ICMPService::discoveryTask(void* params){
pushICMPLog("Device found: " + targetIPStr);
targetsResponded++;
}
+
+ #else
+ // Using ESP32Ping library to avoid IRAM overflow
+ // Can't set timeout response for ping with the Ping lib
+ // This is quite unusable since it takes 5sec per ping
+ // TODO: find a better way
+ const unsigned long t0 = millis();
+ const bool ok = Ping.ping(targetIPStr.c_str());
+ const unsigned long t1 = millis();
+ if (ok) {
+ pushICMPLog("Device found: " + targetIPStr);
+ targetsResponded++;
+ } else {
+ pushICMPLog("Device not found: " + targetIPStr);
+ }
+
+ #endif
}
pushICMPLog(std::to_string(targetsResponded) + " devices up, pinged " +
diff --git a/src/Services/NmapService.cpp b/src/Services/NmapService.cpp
index 6350d79b..50bb6684 100644
--- a/src/Services/NmapService.cpp
+++ b/src/Services/NmapService.cpp
@@ -9,6 +9,7 @@
#include <freertos/task.h>
#include <Data/NmapUtils.h>
#include <unordered_set>
+#include <ESP32Ping.h>
extern "C" {
#include <getopt.h> // provides getopt_long
@@ -334,16 +335,32 @@ void NmapService::scanTarget(const std::string &host, const std::vector<uint16_t
this->report.append("Nmap scan report for ").append(host).append(" (").append(ipStr).append(")\r\n");
// TODO show if host is up + latency?
if (icmpService != nullptr){
+
+ #ifndef DEVICE_M5STICK
+
icmpService->startPingTask(host, 1, 1000, 200);
- while (!icmpService->isPingReady())
+ while (!icmpService->isReady())
vTaskDelay(pdMS_TO_TICKS(50));
- if (icmpService->lastRc() == ping_rc_t::ping_ok) {
+ if (icmpService->lastPingUp()) {
this->report.append("Host is up (").append(std::to_string(icmpService->lastMedianMs())).append("ms latency).\r\n");
}
else {
this->report.append("Host is down.\r\n");
return; // No point in scanning if host is down
}
+ #else
+
+ // Using ESP32Ping library to avoid IRAM overflow
+ const unsigned long t0 = millis();
+ const bool ok = Ping.ping(host.c_str(), 1);
+ const unsigned long t1 = millis();
+ if (ok) {
+ this->report.append("Host is up (").append(std::to_string(t1 - t0)).append("ms latency).\r\n");
+ } else {
+ this->report.append("Host is down.\r\n");
+ }
+
+ #endif
}
else {
// TODO what to do?