diff --git a/common/src/lua_api.cpp b/common/src/lua_api.cpp index 1ca60fd..8fcaa48 100644 --- a/common/src/lua_api.cpp +++ b/common/src/lua_api.cpp @@ -98,11 +98,20 @@ std::string ssh(Session& context, const std::string& ip) { } std::string nmap(Session& context, const std::string& ip) { - long long machine_id = context.get_machine_manager()->get_machine_id_by_ip(ip); - if(machine_id == 0) { + INetworkBridge* bridge = context.get_network_bridge(); + Machine* target_machine = bridge->get_machine_by_ip(ip); + + if(!target_machine) { return "nmap: Could not resolve host: " + ip; } - auto services = context.get_db_manager()->services().get_for_machine(machine_id); + + /* Read services from the cached machine object, not the DB. */ + auto services = target_machine->services; + + /* Release the machine from the cache if it's a remote machine. */ + if(target_machine != context.get_session_machine()) { + bridge->release_machine(target_machine->id); + } if(services.empty()) { return "No open ports for " + ip;