mirror of
https://github.com/nmap/nmap.git
synced 2025-12-17 05:09:00 +00:00
Update epmd-info
Added structured output Simplified building of probe (now just a string) Added a timeout
This commit is contained in:
@@ -3,7 +3,6 @@ local nmap = require "nmap"
|
|||||||
local shortport = require "shortport"
|
local shortport = require "shortport"
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
local table = require "table"
|
|
||||||
|
|
||||||
description = [[
|
description = [[
|
||||||
Connects to Erlang Port Mapper Daemon (epmd) and retrieves a list of nodes with their respective port numbers.
|
Connects to Erlang Port Mapper Daemon (epmd) and retrieves a list of nodes with their respective port numbers.
|
||||||
@@ -17,9 +16,16 @@ Connects to Erlang Port Mapper Daemon (epmd) and retrieves a list of nodes with
|
|||||||
-- PORT STATE SERVICE
|
-- PORT STATE SERVICE
|
||||||
-- 4369/tcp open epmd
|
-- 4369/tcp open epmd
|
||||||
-- | epmd-info.nse:
|
-- | epmd-info.nse:
|
||||||
-- | epmd running on port 4369
|
-- | epmd_port: 4369
|
||||||
-- | name rabbit at port 36804
|
-- | nodes:
|
||||||
-- |_ name ejabberd at port 46540
|
-- | rabbit: 36804
|
||||||
|
-- |_ ejabberd: 46540
|
||||||
|
-- @xmloutput
|
||||||
|
-- <elem key="epmd_port">4369</elem>
|
||||||
|
-- <table key="nodes">
|
||||||
|
-- <elem key="rabbit">36804</elem>
|
||||||
|
-- <elem key="ejabberd">46540</elem>
|
||||||
|
-- </table>
|
||||||
|
|
||||||
author = "Toni Ruottu"
|
author = "Toni Ruottu"
|
||||||
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
||||||
@@ -27,31 +33,38 @@ categories = {"default", "discovery", "safe"}
|
|||||||
|
|
||||||
portrule = shortport.port_or_service (4369, "epmd")
|
portrule = shortport.port_or_service (4369, "epmd")
|
||||||
|
|
||||||
local NAMESREQ = 110
|
|
||||||
|
|
||||||
action = function(host, port)
|
action = function(host, port)
|
||||||
local socket = nmap.new_socket()
|
local socket = nmap.new_socket()
|
||||||
local status, err = socket:connect(host.ip, port.number)
|
socket:set_timeout(stdnse.get_timeout(host))
|
||||||
if not status then
|
local try = nmap.new_try(function () socket:close() end)
|
||||||
return {}
|
try(socket:connect(host, port))
|
||||||
end
|
|
||||||
local payload = bin.pack("C", NAMESREQ)
|
try(socket:send("\x00\x01n")) -- NAMESREQ = 110
|
||||||
local probe = bin.pack(">SA", #payload, payload)
|
|
||||||
socket:send(probe)
|
local getline = stdnse.make_buffer(socket, "\n")
|
||||||
local status = true
|
|
||||||
local data = ""
|
local data, err = getline()
|
||||||
local tmp = ""
|
if data == nil then
|
||||||
while status do
|
stdnse.debug2("Error on receive: %s", err)
|
||||||
data = data .. tmp
|
socket:close()
|
||||||
status, tmp = socket:receive()
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos, realport = bin.unpack(">I", data)
|
local pos, realport = bin.unpack(">I", data)
|
||||||
local nodestring = string.sub(data, pos, -2)
|
data = string.sub(data, pos)
|
||||||
local nodes = stdnse.strsplit("\n", nodestring)
|
|
||||||
local response = {}
|
local nodes = stdnse.output_table()
|
||||||
table.insert(response, 'epmd running on port ' .. realport)
|
local name, port
|
||||||
for _, node in ipairs(nodes) do
|
while data and data ~= "" do
|
||||||
table.insert(response, node)
|
name, port = data:match("^name (.*) at port (%d+)")
|
||||||
|
if name then
|
||||||
|
nodes[name] = port
|
||||||
end
|
end
|
||||||
return stdnse.format_output(true, response)
|
data = getline()
|
||||||
|
end
|
||||||
|
|
||||||
|
local response = stdnse.output_table()
|
||||||
|
response.epmd_port = realport
|
||||||
|
response.nodes = nodes
|
||||||
|
return response
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user