File: sshv1.nse

package info (click to toggle)
nmap 7.93%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 44,552 kB
  • sloc: cpp: 60,990; ansic: 30,785; python: 17,679; xml: 11,558; sh: 11,320; perl: 2,679; makefile: 1,000; java: 45; objc: 43
file content (74 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
local nmap = require "nmap"
local shortport = require "shortport"
local string = require "string"

description = [[
Checks if an SSH server supports the obsolete and less secure SSH Protocol Version 1.
]]
author = "Brandon Enright"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"default", "safe"}

---
-- @output
-- PORT   STATE SERVICE
-- 22/tcp open  ssh
-- |_sshv1: Server supports SSHv1
--
-- @xmloutput
-- true


portrule = shortport.ssh

action = function(host, port)
  local socket = nmap.new_socket()
  local result;
  local status = true;

  socket:connect(host, port)
  status, result = socket:receive_lines(1);

  if (not status) then
    socket:close()
    return
  end

  if (result == "TIMEOUT") then
    socket:close()
    return
  end

  if  not string.match(result, "^SSH%-.+\n$") then
    socket:close()
    return
  end

  socket:send("SSH-1.5-NmapNSE_1.0\n")

  -- should be able to consume at least 13 bytes
  -- key length is a 4 byte integer
  -- padding is between 1 and 8 bytes
  -- type is one byte
  -- key is at least several bytes
  status, result = socket:receive_bytes(13);

  if (not status) then
    socket:close()
    return
  end

  if (result == "TIMEOUT") then
    socket:close()
    return
  end

  if  not string.match(result, "^....[\0]+\002") then
    socket:close()
    return
  end

  socket:close();

  return true, "Server supports SSHv1"
end