This commit is contained in:
Aravind Madan Kumar 2026-11-25 04:09:27 +00:00 • committed by GitHub
commit 0f52ad2dce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 129 additions and 0 deletions

View 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

View 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