mirror of
https://github.com/nmap/nmap.git
synced 2026-11-28 10:30:14 +00:00
Merge 229b4c106a into 4568fbc1b8
This commit is contained in:
commit
0f52ad2dce
2 changed files with 129 additions and 0 deletions
67
scripts/smtp-command-timing.nse
Normal file
67
scripts/smtp-command-timing.nse
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
local shortport = require "shortport"
|
||||
local smtp = require "smtp"
|
||||
local nmap = require "nmap"
|
||||
|
||||
description = [[
|
||||
Measures response times for selected SMTP commands
|
||||
to characterize server response behavior.
|
||||
]]
|
||||
|
||||
author = "Aravind M"
|
||||
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
|
||||
categories = {"discovery", "safe"}
|
||||
|
||||
portrule = shortport.port_or_service(
|
||||
{25, 587},
|
||||
{"smtp", "submission"}
|
||||
)
|
||||
|
||||
action = function(host, port)
|
||||
local options = {
|
||||
timeout = 10000,
|
||||
recv_before = true,
|
||||
ssl = false
|
||||
}
|
||||
|
||||
local socket, err = smtp.connect(host, port, options)
|
||||
|
||||
if not socket then
|
||||
return "Connection failed: " .. tostring(err)
|
||||
end
|
||||
|
||||
local status, response = smtp.ehlo(
|
||||
socket,
|
||||
smtp.get_domain(host)
|
||||
)
|
||||
|
||||
if not status then
|
||||
return "EHLO failed: " .. tostring(response)
|
||||
end
|
||||
|
||||
local results = {}
|
||||
|
||||
for _, command in ipairs({"NOOP", "RSET"}) do
|
||||
local start_time = nmap.clock_ms()
|
||||
local ok, reply = smtp.query(socket, command)
|
||||
local elapsed = nmap.clock_ms() - start_time
|
||||
|
||||
if ok then
|
||||
table.insert(results, string.format(
|
||||
"%s: %d ms; response: %s",
|
||||
command,
|
||||
elapsed,
|
||||
(reply or ""):gsub("[\r\n]+", " ")
|
||||
))
|
||||
else
|
||||
table.insert(results, string.format(
|
||||
"%s failed: %s",
|
||||
command,
|
||||
tostring(reply)
|
||||
))
|
||||
end
|
||||
end
|
||||
|
||||
smtp.quit(socket)
|
||||
|
||||
return table.concat(results, "\n")
|
||||
end
|
||||
62
scripts/smtp-response-scanner.nse
Normal file
62
scripts/smtp-response-scanner.nse
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
local nmap = require "nmap"
|
||||
local shortport = require "shortport"
|
||||
|
||||
description = [[
|
||||
Scans an SMTP service and records the response codes returned
|
||||
for selected standard SMTP commands.
|
||||
]]
|
||||
|
||||
author = "Aravind M"
|
||||
license = "Same as Nmap"
|
||||
categories = {"discovery", "safe"}
|
||||
|
||||
portrule = shortport.port_or_service({25, 587}, "smtp")
|
||||
|
||||
action = function(host, port)
|
||||
|
||||
local socket = nmap.new_socket()
|
||||
socket:set_timeout(5000)
|
||||
|
||||
local status = socket:connect(host.ip, port.number)
|
||||
|
||||
if not status then
|
||||
return "Could not connect to SMTP service"
|
||||
end
|
||||
|
||||
local output = {}
|
||||
|
||||
-- Read SMTP banner
|
||||
local _, banner = socket:receive_lines(1)
|
||||
if banner then
|
||||
table.insert(output, "Banner: " .. banner:gsub("\r?\n", ""))
|
||||
end
|
||||
|
||||
-- Commands to scan
|
||||
local commands = {
|
||||
"EHLO localhost",
|
||||
"NOOP",
|
||||
"HELP",
|
||||
"VRFY test"
|
||||
}
|
||||
|
||||
for _, command in ipairs(commands) do
|
||||
|
||||
socket:send(command .. "\r\n")
|
||||
|
||||
local _, response = socket:receive_lines(1)
|
||||
|
||||
if response then
|
||||
local code = response:match("^(%d%d%d)")
|
||||
|
||||
table.insert(output,
|
||||
command .. ": " .. (code or "Response received"))
|
||||
else
|
||||
table.insert(output, command .. ": No response")
|
||||
end
|
||||
end
|
||||
|
||||
socket:send("QUIT\r\n")
|
||||
socket:close()
|
||||
|
||||
return table.concat(output, "\n")
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue