Skip to content

Instantly share code, notes, and snippets.

@d33tah
Last active August 29, 2015 14:07
Show Gist options
  • Save d33tah/b902eb4e10c1e2b8e095 to your computer and use it in GitHub Desktop.
Save d33tah/b902eb4e10c1e2b8e095 to your computer and use it in GitHub Desktop.
Detects whether the given server is running a WebSocket service on its root directory.
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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment