Skip to content

Instantly share code, notes, and snippets.

@d33tah
Last active August 29, 2015 14:07

Revisions

  1. d33tah revised this gist Oct 5, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion http-websocket-test.nse
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,6 @@ categories = { "default", "discovery", "safe" }
    portrule = shortport.http

    action = function(host, port)
    local output = ""
    local status, err, response

    local socket = nmap.new_socket()
  2. d33tah revised this gist Oct 5, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions http-websocket-test.nse
    Original file line number Diff line number Diff line change
    @@ -11,9 +11,9 @@ directory.
    -- nmap -p 80 --script http-websocket-test <target>
    --
    -- @output
    --PORT STATE SERVICE
    --80/tcp open http
    --|_http-websocket-test: Websocket detected
    -- PORT STATE SERVICE
    -- 80/tcp open http
    -- |_http-websocket-test: Websocket detected

    author = "Jacek Wielemborek"

    @@ -40,4 +40,4 @@ action = function(host, port)
    if response:find("Web Socket Protocol Handshake") then
    return "Websocket detected"
    end
    end
    end
  3. d33tah created this gist Oct 5, 2014.
    43 changes: 43 additions & 0 deletions http-websocket-test.nse
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    local shortport = require "shortport"
    local stdnse = require "stdnse"

    description = [[
    Detects whether the given server is running a WebSocket service on its root
    directory.
    ]]

    ---
    -- @usage
    -- nmap -p 80 --script http-websocket-test <target>
    --
    -- @output
    --PORT STATE SERVICE
    --80/tcp open http
    --|_http-websocket-test: Websocket detected

    author = "Jacek Wielemborek"

    license = "Same as Nmap--See http://nmap.org/book/man-legal.html"

    categories = { "default", "discovery", "safe" }

    portrule = shortport.http

    action = function(host, port)
    local output = ""
    local status, err, response

    local socket = nmap.new_socket()
    socket:connect(host.ip, port)
    status, err = socket:send("GET / HTTP/1.1\r\n" ..
    "Upgrade: websocket\r\n" ..
    "Connection: Upgrade\r\n" ..
    "Host: " .. stdnse.get_hostname(host) .. "\r\n" ..
    "Sec-WebSocket-Key: AIRcKHNkSl6fYaPxjJgs+A==\r\n" ..
    "Sec-WebSocket-Version: 13\r\n\r\n")
    status, response = socket:receive_bytes(0)

    if response:find("Web Socket Protocol Handshake") then
    return "Websocket detected"
    end
    end