NMAP CheatSheet
2020-08-03 00:09:00 Author: www.hahwul.com(查看原文) 阅读量:174 收藏

go-to nmap commands

$ nmap -sC 192.168.0.1   (same this, nmap 192.168.0.1 --script=default)
- 디폴트 스크립트로 대상 스캔
- scanning with default scripts

$ nmap -sn -sC 192.168.0.1
- 포트스캔 없이 스크립트 스캔만
- scanning default script without portscan

$ nmap -PN 192.168.0.1
- Host 스캔 없이 바로 포트 스캐닝
- Portscanning without host scan

$ nmap -PN 192.168.0.1 -p-
- Full port(1-65536) scanning

$ nmap -sS 192.168.0.1
- Syn 스캔
- Syn portscan

$ nmap -sS 192.168.0.1 --script=http* -oX test.xml
- Syn scanning with enable "http~~" scripts and xml output file

Default commands

Scan single IP/Port

$ nmap 192.168.0.1
$ nmap www.hahwul.com
$ nmap 192.168.0.1 -p 443

Scan range of ip/port

IP Range and Subnet

$ nmap 192.168.0.1-254
$ nmap 192.168.0.0/24

Port Range

$ nmap 192.168.0.1 -p 20-3000

Full port scan

$ nmap 192.168.0.1 -p-

100 most command port

$ nmap 192.168.0.1 -F

Scan with file

$ nmap -iL hosts.txt

Scan Types

TCP

$ nmap -sT 192.168.0.1

SYN

$ nmap -sS 192.168.0.1

UDP

$ nmap -sU 192.168.0.1

PING(Ping Sweep)

$ nmap -sP 192.168.0.1

Use NSE

Usage(Options patterns)

Same lines.
--script <NSE FILE>
--script=<NSE FILE>

Using NSE

$ nmap 192.168.0.1 --script <NSE FILE>
$ nmap 192.168.0.1 --script=<NSE FILE>

Use NSE with nse arguments

$ nmap 192.168.0.1 --script nse --script-args <ARGUMENTS>

Use NSE with nse arguments file

$ nmap 192.168.0.1 —-script nse --script-args-file <FILE>

Use NSE Arguments Script

$ nmap -sC --script-args 'user=foo,pass=",{}=bar",paths={/admin,/cgi-bin},xmpp-info.server_name=localhost’

=>

nmap.registry.args = {
  user = "foo",
  pass = ",{}=bar",
  paths = {
    "/admin",
    "/cgi-bin"
  },
  xmpp-info.server_name="localhost"
}

NSE List



Write NSE Script

NSE Information

description = [[
Attempts to find the owner of an open TCP port by querying an auth
(identd - port 113) daemon which must also be open on the target system.
]]

author = "Diman Todorov"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"default", "safe"}

portrule

portrule = function(host, port)
    local auth_port = { number=113, protocol="tcp" }
    local identd = nmap.get_port_state(host, auth_port)

    return identd ~= nil
        and identd.state == "open"
        and port.protocol == "tcp"
        and port.state == "open"
end

action

action = function(host, port)
        local owner = ""

        local client_ident = nmap.new_socket()
        local client_service = nmap.new_socket()

        local catch = function()
                client_ident:close()
                client_service:close()
        end

        local try = nmap.new_try(catch)

        try(client_ident:connect(host.ip, 113))
        try(client_service:connect(host.ip, port.number))

        local localip, localport, remoteip, remoteport =
                try(client_service:get_info())

        local request = port.number .. ", " .. localport .. "\r\n"

        try(client_ident:send(request))

        owner = try(client_ident:receive_lines(1))

        if string.match(owner, "ERROR") then 
                owner = nil
        else
                owner = string.match(owner,
                        "%d+%s*,%s*%d+%s*:%s*USERID%s*:%s*.+%s*:%s*(.+)\r?\n")
        end

        try(client_ident:close())
        try(client_service:close())

        return owner
end

(https://nmap.org/book/nse-tutorial.html)


文章来源: https://www.hahwul.com/2020/08/02/nmap-cheatsheet/
如有侵权请联系:admin#unsafe.sh