Skip to content

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

Added scan skeleton

Andrei Vladescu4718aa3000e5
diff --git a/src/Controllers/WifiController.cpp b/src/Controllers/WifiController.cpp
index 842dda3a..9bf8526a 100644
--- a/src/Controllers/WifiController.cpp
+++ b/src/Controllers/WifiController.cpp
@@ -513,11 +513,27 @@ void WifiController::handleNmap(const TerminalCommand &cmd)
return;
}
+ auto args = argTransformer.splitArgs(cmd.getArgs());
+
// Parse args
+ // Parse hosts first
auto hosts_arg = cmd.getSubcommand();
- nmapService.parseHosts(hosts_arg);
+ if(!nmapService.parseHosts(hosts_arg)) {
+ terminalView.println("Nmap: Invalid host.");
+ return;
+ }
+
+ // Not yet implemented - getopt
+
+ if (args[0] == "-p" && args.size() > 1) {
+ // Parse ports
+ if(!nmapService.parsePorts(args[1])) {
+ terminalView.println("Nmap: Invalid port.");
+ return;
+ }
+ }
- nmapService.startTask("127.0.0.1", 0);
+ nmapService.startTask(0);
terminalView.println("\r\n\nNmap: Session closed.");
}
diff --git a/src/Services/NmapService.cpp b/src/Services/NmapService.cpp
index fc27b6c9..2c04e0a9 100644
--- a/src/Services/NmapService.cpp
+++ b/src/Services/NmapService.cpp
@@ -8,33 +8,68 @@
struct NmapTaskParams
{
- std::string host;
+ std::vector<std::string> target_hosts;
+ std::vector<uint16_t> target_ports;
int verbosity;
NmapService *service;
};
-void NmapService::startTask(const std::string &host, int verbosity)
+void NmapService::scanTarget(const std::string &host, const std::vector<uint16_t> &ports)
{
- auto *params = new NmapTaskParams{host, verbosity, this};
- //xTaskCreatePinnedToCore(connectTask, "NmapConnect", 20000, params, 1, nullptr, 1);
- delay(500); // start task delay
+
+}
+
+void NmapService::connectTask(void *pvParams)
+{
+ auto *params = static_cast<NmapTaskParams *>(pvParams);
+ //params->service->connect(params->target_hosts, params->verbosity, params->target_ports);
+ //delete params;
+ vTaskDelete(nullptr);
+}
+
+void NmapService::startTask(int verbosity)
+{
+ auto *params = new NmapTaskParams{this->target_hosts, this->target_ports, verbosity, this};
+ xTaskCreatePinnedToCore(connectTask, "NmapConnect", 20000, params, 1, nullptr, 1);
+ delay(100); // start task delay
}
-void NmapService::parseHosts(const std::string& hosts_arg)
+bool NmapService::parseHosts(const std::string& hosts_arg)
{
- // Check if hosts_arg contains at least one letter (domain name)
- bool hasLetter = false;
- for (char c : hosts_arg) {
- if (isalpha(static_cast<unsigned char>(c))) {
- hasLetter = true;
- break;
+ this->target_hosts = std::vector<std::string>();
+
+ // If we find ',' or '-' or '/network_mask' there are multiple hosts
+ if (hosts_arg.find(',') == std::string::npos && hosts_arg.find('-') == std::string::npos && hosts_arg.find('/') == std::string::npos) {
+ // Single host
+ if (isIpv4(hosts_arg)) {
+ this->target_hosts.push_back(hosts_arg);
+ }
+ else {
+ return false;
}
}
- if (!hasLetter && !isIpv4(hosts_arg)) {
- // TODO: Handle invalid host
+ else {
+ // Not yet implemented
+ return false;
}
+ return true;
+}
- // TODO: Handle valid hosts
+bool NmapService::parsePorts(const std::string& ports_arg)
+{
+ this->target_ports = std::vector<uint16_t>();
+
+ // If we find ',' or '-' there are multiple ports
+ if (ports_arg.find(',') != std::string::npos || ports_arg.find('-') != std::string::npos) {
+ // Not yet implemented
+ return false;
+ }
+ else {
+ // Single port
+ uint16_t port = static_cast<uint16_t>(std::stoi(ports_arg));
+ this->target_ports.push_back(port);
+ }
+ return true;
}
bool NmapService::isIpv4(const std::string& address)
diff --git a/src/Services/NmapService.h b/src/Services/NmapService.h
index 9ef80260..0ee74edd 100644
--- a/src/Services/NmapService.h
+++ b/src/Services/NmapService.h
@@ -5,13 +5,19 @@
class NmapService {
public:
- void startTask(const std::string& host, int verbosity);
- void parseHosts(const std::string& hosts_arg);
-
+ void startTask(int verbosity);
+ bool parseHosts(const std::string& hosts_arg);
+ bool parsePorts(const std::string& ports_arg);
+
private:
// Nmap Task, cause overflow if it runs in the main loop, so it must run in a dedicated FreeRTOS task with a larger stack
+ static void connectTask(void *pvParams);
bool isIpv4(const std::string& address);
- bool NmapService::isIpv4(const std::string& address);
+ void scanTarget(const std::string &host, const std::vector<uint16_t> &ports);
+
+ std::vector<std::string> target_hosts;
+ std::vector<uint16_t> target_ports;
+
static std::vector<uint16_t> selected_ports;
};