Module: Msf::Auxiliary::Cisco

Includes:
Report
Defined in:
lib/msf/core/auxiliary/cisco.rb

Overview

This module provides methods for working with Cisco equipment

Instance Method Summary collapse

Methods included from Report

#active_db?, #create_cracked_credential, #create_credential, #create_credential_and_login, #create_credential_login, #db, #db_warning_given?, #get_client, #get_host, #inside_workspace_boundary?, #invalidate_login, #mytask, #myworkspace, #myworkspace_id, #report_auth_info, #report_client, #report_exploit, #report_host, #report_loot, #report_note, #report_service, #report_vuln, #report_web_form, #report_web_page, #report_web_site, #report_web_vuln, #store_cred, #store_local, #store_loot

Methods included from Metasploit::Framework::Require

optionally, optionally_active_record_railtie, optionally_include_metasploit_credential_creation, #optionally_include_metasploit_credential_creation, optionally_require_metasploit_db_gem_engines

Instance Method Details

#cisco_ios_config_eater(thost, tport, config) ⇒ Object



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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/msf/core/auxiliary/cisco.rb', line 36

def cisco_ios_config_eater(thost, tport, config)

  if framework.db.active
    credential_data = {
      address: thost,
      port: tport,
      protocol: 'tcp',
      workspace_id: myworkspace_id,
      origin_type: :service,
      private_type: :password,
      service_name: '',
      module_fullname: fullname,
      status: Metasploit::Model::Login::Status::UNTRIED
    }
  end

  # Default SNMP to UDP
  if tport == 161
    credential_data[:protocol] = 'udp'
  end

  store_loot('cisco.ios.config', 'text/plain', thost, config.strip, 'config.txt', 'Cisco IOS Configuration')

  tuniface = nil

  host_info = {
    host: thost,
    os_name: 'Cisco IOS'
  }
  report_host(host_info)

  config.each_line do |line|
    case line
      #
      # Cover host details
      #
    when /^version (\d\d\.\d)/i
      host_info[:os_flavor] = Regexp.last_match(1).to_s
      report_host(host_info)
    when /^hostname (\S+)/i
      host_info[:name] = Regexp.last_match(1).to_s
      report_host(host_info)
      #
      # Enable passwords
      #
    when /^\s*enable (password|secret) (\d+) (.*)/i
      stype = Regexp.last_match(2).to_i
      shash = Regexp.last_match(3).strip

      if framework.db.active
        cred = credential_data.dup
        cred[:private_data] = shash
      else
        cred = {} # throw away
      end

      case stype
      when 5
        print_good("#{thost}:#{tport} MD5 Encrypted Enable Password: #{shash}")
        cred[:jtr_format] = 'md5'
        cred[:private_type] = :nonreplayable_hash
        (cred) if framework.db.active
      when 0 # unencrypted
        print_good("#{thost}:#{tport} Enable Password: #{shash}")
        (cred) if framework.db.active
      when 7
        shash = begin
                cisco_ios_decrypt7(shash)
                rescue StandardError
                  shash
              end
        print_good("#{thost}:#{tport} Decrypted Enable Password: #{shash}")
        cred[:private_data] = shash
        (cred) if framework.db.active
      end

    when /^\s*enable password (.*)/i
      spass = Regexp.last_match(1).strip
      print_good("#{thost}:#{tport} Unencrypted Enable Password: #{spass}")

      if framework.db.active
        cred = credential_data.dup
        cred[:private_data] = spass
        (cred)
      end

      #
      # SNMP
      #
    when /^\s*snmp-server community ([^\s]+) (RO|RW)/i
      stype = Regexp.last_match(2).strip
      scomm = Regexp.last_match(1).strip
      print_good("#{thost}:#{tport} SNMP Community (#{stype}): #{scomm}")

      cred = credential_data.dup
      cred[:access_level] = stype.upcase
      cred[:protocol] = "udp"
      cred[:port] = 161
      cred[:private_data] = scomm
      (cred)
#
# VTY Passwords
#
    when /^\s*password 7 ([^\s]+)/i
      spass = Regexp.last_match(1).strip
      spass = begin
              cisco_ios_decrypt7(spass)
              rescue StandardError
                spass
            end

      print_good("#{thost}:#{tport} Decrypted VTY Password: #{spass}")

      if framework.db.active
        cred = credential_data.dup
        cred[:private_data] = spass
        (cred)
      end

    when /^\s*(password|secret) 5 (.*)/i
      shash = Regexp.last_match(2).strip
      print_good("#{thost}:#{tport} MD5 Encrypted VTY Password: #{shash}")
      if framework.db.active
        cred = credential_data.dup
        cred[:jtr_format] = 'md5'
        cred[:private_data] = shash
        cred[:private_type] = :nonreplayable_hash
        (cred)
      end

    when /^\s*password (0 |)([^\s]+)/i
      spass = Regexp.last_match(2).strip
      print_good("#{thost}:#{tport} Unencrypted VTY Password: #{spass}")

      if framework.db.active
        cred = credential_data.dup
        cred[:private_data] = spass
        (cred)
      end

      #
      # WiFi Passwords
      #
    when /^\s*encryption key \d+ size \d+bit (\d+) ([^\s]+)/
      spass = Regexp.last_match(2).strip
      print_good("#{thost}:#{tport} Wireless WEP Key: #{spass}")

    when /^\s*wpa-psk (ascii|hex) (\d+) ([^\s]+)/i

      stype = Regexp.last_match(2).to_i
      spass = Regexp.last_match(3).strip

      if framework.db.active
        cred = credential_data.dup
        cred[:private_data] = spass
      else
        cred = {} # throw away
      end

      case stype
      when 5
        print_good("#{thost}:#{tport} Wireless WPA-PSK MD5 Password Hash: #{spass}")
        cred[:jtr_format] = 'md5'
        cred[:private_type] = :nonreplayable_hash
        (cred) if framework.db.active
      when 0
        print_good("#{thost}:#{tport} Wireless WPA-PSK Password: #{spass}")
        (cred) if framework.db.active
      when 7
        spass = begin
                cisco_ios_decrypt7(spass)
                rescue StandardError
                  spass
              end
        print_good("#{thost}:#{tport} Wireless WPA-PSK Decrypted Password: #{spass}")
        cred[:private_data] = spass
        (cred) if framework.db.active
      end

      #
      # VPN Passwords
      #
    when /^\s*crypto isakmp key ([^\s]+) address ([^\s]+)/i
      spass = Regexp.last_match(1)
      shost = Regexp.last_match(2)

      print_good("#{thost}:#{tport} VPN IPSEC ISAKMP Key '#{spass}' Host '#{shost}'")
      if framework.db.active
        cred = credential_data.dup
        cred[:private_data] = spass
        cred[:private_type] = :nonreplayable_hash
        (cred)
      end

    when /^\s*interface tunnel(\d+)/i
      tuniface = Regexp.last_match(1)

    when /^\s*tunnel key ([^\s]+)/i
      spass = Regexp.last_match(1)
      siface = tuniface

      print_good("#{thost}:#{tport} GRE Tunnel Key #{spass} for Interface Tunnel #{siface}")
      if framework.db.active
        cred = credential_data.dup
        cred[:private_data] = spass
        cred[:private_type] = :nonreplayable_hash
        (cred)
      end

    when /^\s*ip nhrp authentication ([^\s]+)/i
      spass = Regexp.last_match(1)
      siface = tuniface

      print_good("#{thost}:#{tport} NHRP Authentication Key #{spass} for Interface Tunnel #{siface}")
      if framework.db.active
        cred = credential_data.dup
        cred[:private_data] = spass
        cred[:private_type] = :nonreplayable_hash
        (cred)
      end

      #
      # Various authentication secrets
      #
    when /^\s*username ([^\s]+) privilege (\d+) (secret|password) (\d+) ([^\s]+)/i
      user = Regexp.last_match(1)
      priv = Regexp.last_match(2)
      stype = Regexp.last_match(4).to_i
      spass = Regexp.last_match(5)

      if framework.db.active
        cred = credential_data.dup
        cred[:username] = user.to_s
        cred[:private_data] = spass
      else
        cred = {} # throw away
      end

      case stype
      when 5
        print_good("#{thost}:#{tport} Username '#{user}' with MD5 Encrypted Password: #{spass}")
        cred[:jtr_format] = 'md5'
        cred[:private_type] = :nonreplayable_hash
        (cred) if framework.db.active
      when 0
        print_good("#{thost}:#{tport} Username '#{user}' with Password: #{spass}")
        (cred) if framework.db.active
      when 7
        spass = begin
                cisco_ios_decrypt7(spass)
                rescue StandardError
                  spass
              end
        print_good("#{thost}:#{tport} Username '#{user}' with Decrypted Password: #{spass}")
        cred[:private_data] = spass
        (cred) if framework.db.active
      end

      # This regex captures ephones from Cisco Unified Communications Manager Express (CUE) which come in forms like:
      # username "phonefour" password 444444
      # username test password test
      # This is used for the voicemail system
    when /^\s*username "?([\da-z]+)"? password ([^\s]+)/i
      user = Regexp.last_match(1)
      spass = Regexp.last_match(2)
      print_good("#{thost}:#{tport} ePhone Username '#{user}' with Password: #{spass}")
      if framework.db.active
        cred = credential_data.dup
        cred[:username] = user.to_s
        cred[:private_data] = spass
        (cred)
      end

    when /^\s*username ([^\s]+) (secret|password) (\d+) ([^\s]+)/i
      user = Regexp.last_match(1)
      stype = Regexp.last_match(3).to_i
      spass = Regexp.last_match(4)

      if framework.db.active
        cred = credential_data.dup
        cred[:username] = user.to_s
        cred[:private_data] = spass
      else
        cred = {}
      end

      case stype
      when 5
        print_good("#{thost}:#{tport} Username '#{user}' with MD5 Encrypted Password: #{spass}")
        cred[:jtr_format] = 'md5'
        cred[:private_type] = :nonreplayable_hash
        (cred) if framework.db.active
      when 0
        print_good("#{thost}:#{tport} Username '#{user}' with Password: #{spass}")
        (cred) if framework.db.active
      when 7
        spass = begin
                cisco_ios_decrypt7(spass)
                rescue StandardError
                  spass
              end
        print_good("#{thost}:#{tport} Username '#{user}' with Decrypted Password: #{spass}")
        cred[:private_data] = spass
        (cred) if framework.db.active
      end

      # https://www.cisco.com/c/en/us/td/docs/voice_ip_comm/cucme/command/reference/cme_cr/cme_cr_chapter_010101.html#wp3722577363
    when /^\s*web admin (customer|system) name ([^\s]+) (secret [0|5]|password) ([^\s]+)/i
       = Regexp.last_match(1)
      suser = Regexp.last_match(2)
      stype = Regexp.last_match(3)
      spass = Regexp.last_match(4)

      if framework.db.active
        cred = credential_data.dup
        cred[:username] = suser.to_s
        cred[:private_data] = spass
      else
        cred = {}
      end

      case stype
      when 'secret 5'
        print_good("#{thost}:#{tport} Web Admin Username: #{suser} Type: #{} MD5 Encrypted Password: #{spass}")
        cred[:jtr_format] = 'md5'
        cred[:private_type] = :nonreplayable_hash
        (cred) if framework.db.active
      when 'secret 0', 'password'
        print_good("#{thost}:#{tport} Web Username: #{suser} Type: #{} Password: #{spass}")
        (cred) if framework.db.active
      end

    when /^\s*ppp.*username ([^\s]+) (secret|password) (\d+) ([^\s]+)/i

      suser = Regexp.last_match(1)
      stype = Regexp.last_match(3).to_i
      spass = Regexp.last_match(4)

      if framework.db.active
        cred = credential_data.dup
        cred[:username] = suser.to_s
        cred[:private_data] = spass
      else
        cred = {}
      end

      case stype
      when 5
        print_good("#{thost}:#{tport} PPP Username #{suser} MD5 Encrypted Password: #{spass}")
        cred[:jtr_format] = 'md5'
        cred[:private_type] = :nonreplayable_hash
        (cred) if framework.db.active
      when 0
        print_good("#{thost}:#{tport} PPP Username: #{suser} Password: #{spass}")
        (cred) if framework.db.active
      when 7
        spass = begin
                cisco_ios_decrypt7(spass)
                rescue StandardError
                  spass
              end
        print_good("#{thost}:#{tport} PPP Username: #{suser} Decrypted Password: #{spass}")
        cred[:private_data] = spass
        (cred) if framework.db.active
      end

    when /^\s*ppp chap (secret|password) (\d+) ([^\s]+)/i
      stype = Regexp.last_match(2).to_i
      spass = Regexp.last_match(3)

      if framework.db.active
        cred = credential_data.dup
        cred[:private_data] = spass
      else
        cred = {}
      end

      case stype
      when 5
        print_good("#{thost}:#{tport} PPP CHAP MD5 Encrypted Password: #{spass}")
        cred[:jtr_format] = 'md5'
        cred[:private_type] = :nonreplayable_hash
        (cred) if framework.db.active
      when 0
        print_good("#{thost}:#{tport} Password: #{spass}")
        (cred) if framework.db.active
      when 7
        spass = begin
                cisco_ios_decrypt7(spass)
                rescue StandardError
                  spass
              end
        print_good("#{thost}:#{tport} PPP Decrypted Password: #{spass}")
        cred[:private_data] = spass
        (cred) if framework.db.active
      end
    end
  end
end

#cisco_ios_decrypt7(inp) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/msf/core/auxiliary/cisco.rb', line 12

def cisco_ios_decrypt7(inp)
  xlat = [
    0x64, 0x73, 0x66, 0x64, 0x3b, 0x6b, 0x66, 0x6f,
    0x41, 0x2c, 0x2e, 0x69, 0x79, 0x65, 0x77, 0x72,
    0x6b, 0x6c, 0x64, 0x4a, 0x4b, 0x44, 0x48, 0x53,
    0x55, 0x42
  ]

  return nil if !(inp[0, 2] =~ /\d\d/)

  seed = nil
  clear = ''
  inp.scan(/../).each do |byte|
    if !seed
      seed = byte.to_i
      next
    end
    byte = byte.to_i(16)
    clear << [ byte ^ xlat[seed]].pack('C')
    seed += 1
  end
  clear
end