summaryrefslogtreecommitdiffstats
path: root/scripts/iscsi-brute.nse
blob: 97a7312010aae61da65ac144625fa1bec732cdf4 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
local brute = require "brute"
local creds = require "creds"
local iscsi = require "iscsi"
local shortport = require "shortport"
local stdnse = require "stdnse"

description = [[
Performs brute force password auditing against iSCSI targets.
]]

---
-- @args iscsi-brute.target iSCSI target to brute-force.
-- @output
-- PORT     STATE SERVICE
-- 3260/tcp open  iscsi   syn-ack
-- | iscsi-brute:
-- |   Accounts
-- |     user:password123456 => Valid credentials
-- |   Statistics
-- |_    Perfomed 5000 guesses in 7 seconds, average tps: 714

-- Version 0.1
-- Created 2010/11/18 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
-- Revised 2010/11/27 - v0.2 - detect if no password is needed <patrik@cqure.net>


author = "Patrik Karlsson"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"intrusive", "brute"}

portrule = shortport.portnumber(3260, "tcp", {"open", "open|filtered"})

Driver = {

  new = function(self, host, port)
    local o = {}
    setmetatable(o, self)
    self.__index = self
    o.host = host
    o.port = port
    o.target = stdnse.get_script_args('iscsi-brute.target')
    return o
  end,

  connect = function( self )
    self.helper = iscsi.Helper:new( self.host, self.port )
    return self.helper:connect(brute.new_socket())
  end,

  login = function( self, username, password )
    local status = self.helper:login( self.target, username, password, "CHAP")

    if ( status ) then
      return true, creds.Account:new(username, password, creds.State.VALID)
    end

    return false, brute.Error:new( "Incorrect password" )
  end,

  disconnect = function( self )
    self.helper:close()
  end,
}


action = function( host, port )

  local target = stdnse.get_script_args('iscsi-brute.target')
  if ( not(target) ) then
    return stdnse.format_output(false, "No target specified (see iscsi-brute.target)")
  end

  local helper = iscsi.Helper:new( host, port )
  local status, err = helper:connect()
  if ( not(status) ) then return false, "Failed to connect" end

  local response
  status, response = helper:login( target )
  helper:logout()
  helper:close()

  if ( status ) then return "No authentication required" end

  local accounts

  local engine = brute.Engine:new(Driver, host, port)
  engine.options.script_name = SCRIPT_NAME
  status, accounts = engine:start()

  if ( status ) then return accounts end
end