需要帮助编写 NMAP NSE 脚本来检测主机上的开放端口并发送命令

问题描述 投票:0回答:1

大家好。 我有一个非常具体的问题,需要解决为 Nmap 编写 NSE 脚本的问题。 基本上这就是我想要脚本执行的操作:

  1. 连接到主机并检查提供的开放端口:E.G. 18000.
  2. 如果端口开放:通过开放端口连接主机,向主机发送以下命令:“hello ”。 注:“ “在命令中很重要。
  3. 如果发送命令的输出以字符串“SeedLink”开头,则应打印出响应,否则应将响应静音。

这是我迄今为止尝试过的:

-- HEAD --

description = [[
This is a simple script example that determines if a port has a seedlink server running.
]]

author = "Me"

-- RULE --

portrule = function(host, port)
        return port.protocol == "tcp"
                 and port.state == "open"
 end

-- ACTION --

action = function(host, port)
        local sock = nmap.new_socket()
        local status, err = sock:connect(host, port)
        if not status then
                return "Failed to connect"
        end

        local data = "hello\n"
        status, err = sock:send(data)
        if not status then
                return "Failed to send data"
        end

        local response = sock:receive()
        if string.sub(response, 1, 8) == "SeedLink" then
                return "Seedlink server is running"
        else
                return "SeedLink server is not running."
        end
end

我使用以下命令来运行脚本:

nmap --script=seedlink.nse localhost -p 18000

预期输出将是:

SeedLink v3.3 (2022.096) EQM

这个脚本可以工作,但它告诉我没有 Seedlink 服务器正在运行,尽管我可以通过运行来验证是否有一个:

telnet localhost:18000

如有任何帮助,我们将不胜感激。

scripting nmap
1个回答
0
投票

您是否尝试过使用Slinktool,而不是使用Telnet?

© www.soinside.com 2019 - 2024. All rights reserved.