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

#db, #get_client, #get_host, #initialize, #inside_workspace_boundary?, #mytask, #myworkspace, #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

Instance Method Details

#cisco_ios_config_eater(thost, tport, config) ⇒ Object


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
# File 'lib/msf/core/auxiliary/cisco.rb', line 37

def cisco_ios_config_eater(thost, tport, config)

  #
  # Create a template hash for cred reporting
  #
  cred_info = {
    :host  => thost,
    :port  => tport,
    :user  => "",
    :pass  => "",
    :type  => "",
    :collect_type => "",
    :active => true
  }

  # Default SNMP to UDP
  if tport == 161
    cred_info[:proto] = 'udp'
  end

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

  tuniface = nil

  config.each_line do |line|
    case line
#
# Enable passwords
#
      when /^\s*enable (password|secret) (\d+) (.*)/i
        stype = $2.to_i
        shash = $3.strip

        if stype == 5
          print_good("#{thost}:#{tport} MD5 Encrypted Enable Password: #{shash}")
          store_loot("cisco.ios.enable_hash", "text/plain", thost, shash, "enable_password_hash.txt", "Cisco IOS Enable Password Hash (MD5)")
        end

        if stype == 0
          print_good("#{thost}:#{tport} Enable Password: #{shash}")
          store_loot("cisco.ios.enable_pass", "text/plain", thost, shash, "enable_password.txt", "Cisco IOS Enable Password")

          cred = cred_info.dup
          cred[:pass] = shash
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end

        if stype == 7
          shash = cisco_ios_decrypt7(shash) rescue shash
          print_good("#{thost}:#{tport} Decrypted Enable Password: #{shash}")
          store_loot("cisco.ios.enable_pass", "text/plain", thost, shash, "enable_password.txt", "Cisco IOS Enable Password")

          cred = cred_info.dup
          cred[:pass] = shash
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end

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

        cred = cred_info.dup
        cred[:pass] = spass
        cred[:type] = "password"
        cred[:collect_type] = "password"
        store_cred(cred)

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

        if stype.downcase == "ro"
          ptype = "password_ro"
        else
          ptype = "password"
        end

        cred = cred_info.dup
        cred[:sname] = "snmp"
        cred[:pass] = scomm
        cred[:type] = ptype
        cred[:collect_type] = ptype
        cred[:proto] = "udp"
        cred[:port]  = 161
        store_cred(cred)

#
# VTY Passwords
#
      when /^\s*password 7 ([^\s]+)/i
        spass = $1.strip
        spass = cisco_ios_decrypt7(spass) rescue spass

        print_good("#{thost}:#{tport} Decrypted VTY Password: #{spass}")
        cred = cred_info.dup

        cred[:pass] = spass
        cred[:type] = "password"
        cred[:collect_type] = "password"
        store_cred(cred)

      when /^\s*(password|secret) 5 (.*)/i
        shash = $1.strip
        print_good("#{thost}:#{tport} MD5 Encrypted VTY Password: #{shash}")
        store_loot("cisco.ios.vty_password", "text/plain", thost, shash, "vty_password_hash.txt", "Cisco IOS VTY Password Hash (MD5)")

      when /^\s*password (0 |)([^\s]+)/i
        spass = $2.strip
        print_good("#{thost}:#{tport} Unencrypted VTY Password: #{spass}")
        cred = cred_info.dup
        cred[:pass] = spass
        cred[:type] = "password"
        cred[:collect_type] = "password"
        store_cred(cred)

#
# WiFi Passwords
#
      when /^\s*encryption key \d+ size \d+bit (\d+) ([^\s]+)/
        spass = $2.strip
        print_good("#{thost}:#{tport} Wireless WEP Key: #{spass}")
        store_loot("cisco.ios.wireless_wep", "text/plain", thost, spass, "wireless_wep.txt", "Cisco IOS Wireless WEP Key")

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

        stype = $2.to_i
        spass = $3.strip

        if stype == 5
          print_good("#{thost}:#{tport} Wireless WPA-PSK MD5 Password Hash: #{spass}")
          store_loot("cisco.ios.wireless_wpapsk_hash", "text/plain", thost, spass, "wireless_wpapsk_hash.txt", "Cisco IOS Wireless WPA-PSK Password Hash (MD5)")
        end

        if stype == 0
          print_good("#{thost}:#{tport} Wireless WPA-PSK Password: #{spass}")
          cred = cred_info.dup
          cred[:pass] = spass
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)

          store_loot("cisco.ios.wireless_wpapsk", "text/plain", thost, spass, "wireless_wpapsk.txt", "Cisco IOS Wireless WPA-PSK Password")
        end

        if stype == 7
          spass = cisco_ios_decrypt7(spass) rescue spass
          print_good("#{thost}:#{tport} Wireless WPA-PSK Decrypted Password: #{spass}")
          cred = cred_info.dup
          cred[:pass] = spass
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)

          store_loot("cisco.ios.wireless_wpapsk", "text/plain", thost, spass, "wireless_wpapsk.txt", "Cisco IOS Wireless WPA-PSK Decrypted Password")
        end

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

        print_good("#{thost}:#{tport} VPN IPSEC ISAKMP Key '#{spass}' Host '#{shost}'")
        store_loot("cisco.ios.vpn_ipsec_key", "text/plain", thost, "#{spass}", "vpn_ipsec_key.txt", "Cisco VPN IPSEC Key")

        cred = cred_info.dup
        cred[:pass] = spass
        cred[:type] = "password"
        cred[:collect_type] = "password"
        store_cred(cred)
      when /^\s*interface tunnel(\d+)/i
        tuniface = $1

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

        print_good("#{thost}:#{tport} GRE Tunnel Key #{spass} for Interface Tunnel #{siface}")
        store_loot("cisco.ios.gre_tunnel_key", "text/plain", thost, "tunnel#{siface}_#{spass}", "gre_tunnel_key.txt", "Cisco GRE Tunnel Key")

        cred = cred_info.dup
        cred[:pass] = spass
        cred[:type] = "password"
        cred[:collect_type] = "password"
        store_cred(cred)

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

        print_good("#{thost}:#{tport} NHRP Authentication Key #{spass} for Interface Tunnel #{siface}")
        store_loot("cisco.ios.nhrp_tunnel_key", "text/plain", thost, "tunnel#{siface}_#{spass}", "nhrp_tunnel_key.txt", "Cisco NHRP Authentication Key")

        cred = cred_info.dup
        cred[:pass] = spass
        cred[:type] = "password"
        cred[:collect_type] = "password"
        store_cred(cred)

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

        if stype == 5
          print_good("#{thost}:#{tport} Username '#{user}' with MD5 Encrypted Password: #{shash}")
          store_loot("cisco.ios.username_password_hash", "text/plain", thost, "#{user}_level#{priv}:#{shash}", "username_password_hash.txt", "Cisco IOS Username and Password Hash (MD5)")
        end

        if stype == 0
          print_good("#{thost}:#{tport} Username '#{user}' with Password: #{shash}")
          store_loot("cisco.ios.username_password", "text/plain", thost, "#{user}_level#{priv}:#{shash}", "username_password.txt", "Cisco IOS Username and Password")

          cred = cred_info.dup
          cred[:user] = user
          cred[:pass] = shash
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end

        if stype == 7
          shash = cisco_ios_decrypt7(shash) rescue shash
          print_good("#{thost}:#{tport} Username '#{user}' with Decrypted Password: #{shash}")
          store_loot("cisco.ios.username_password", "text/plain", thost, "#{user}_level#{priv}:#{shash}", "username_password.txt", "Cisco IOS Username and Password")

          cred = cred_info.dup
          cred[:user] = user
          cred[:pass] = shash
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end

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

        if stype == 5
          print_good("#{thost}:#{tport} Username '#{user}' with MD5 Encrypted Password: #{shash}")
          store_loot("cisco.ios.username_password_hash", "text/plain", thost, "#{user}:#{shash}", "username_password_hash.txt", "Cisco IOS Username and Password Hash (MD5)")
        end

        if stype == 0
          print_good("#{thost}:#{tport} Username '#{user}' with Password: #{shash}")
          store_loot("cisco.ios.username_password", "text/plain", thost, "#{user}:#{shash}", "username_password.txt", "Cisco IOS Username and Password")

          cred = cred_info.dup
          cred[:user] = user
          cred[:pass] = shash
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end

        if stype == 7
          shash = cisco_ios_decrypt7(shash) rescue shash
          print_good("#{thost}:#{tport} Username '#{user}' with Decrypted Password: #{shash}")
          store_loot("cisco.ios.username_password", "text/plain", thost, "#{user}:#{shash}", "username_password.txt", "Cisco IOS Username and Password")

          cred = cred_info.dup
          cred[:user] = user
          cred[:pass] = shash
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end

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

        suser = $1
        stype = $3.to_i
        shash = $4

        if stype == 5
          print_good("#{thost}:#{tport} PPP Username #{suser} MD5 Encrypted Password: #{shash}")
          store_loot("cisco.ios.ppp_username_password_hash", "text/plain", thost, "#{suser}:#{shash}", "ppp_username_password_hash.txt", "Cisco IOS PPP Username and Password Hash (MD5)")
        end

        if stype == 0
          print_good("#{thost}:#{tport} PPP Username: #{suser} Password: #{shash}")
          store_loot("cisco.ios.ppp_username_password", "text/plain", thost, "#{suser}:#{shash}", "ppp_username_password.txt", "Cisco IOS PPP Username and Password")

          cred = cred_info.dup
          cred[:pass] = shash
          cred[:user] = suser
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end

        if stype == 7
          shash = cisco_ios_decrypt7(shash) rescue shash
          print_good("#{thost}:#{tport} PPP Username: #{suser} Decrypted Password: #{shash}")
          store_loot("cisco.ios.ppp_username_password", "text/plain", thost, "#{suser}:#{shash}", "ppp_username_password.txt", "Cisco IOS PPP Username and Password")

          cred = cred_info.dup
          cred[:pass] = shash
          cred[:user] = suser
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end

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

        if stype == 5
          print_good("#{thost}:#{tport} PPP CHAP MD5 Encrypted Password: #{shash}")
          store_loot("cisco.ios.ppp_password_hash", "text/plain", thost, shash, "ppp_password_hash.txt", "Cisco IOS PPP Password Hash (MD5)")
        end

        if stype == 0
          print_good("#{thost}:#{tport} Password: #{shash}")
          store_loot("cisco.ios.ppp_password", "text/plain", thost, shash, "ppp_password.txt", "Cisco IOS PPP Password")

          cred = cred_info.dup
          cred[:pass] = shash
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end

        if stype == 7
          shash = cisco_ios_decrypt7(shash) rescue shash
          print_good("#{thost}:#{tport} PPP Decrypted Password: #{shash}")
          store_loot("cisco.ios.ppp_password", "text/plain", thost, shash, "ppp_password.txt", "Cisco IOS PPP Password")

          cred = cred_info.dup
          cred[:pass] = shash
          cred[:type] = "password"
          cred[:collect_type] = "password"
          store_cred(cred)
        end
    end
  end
end

#cisco_ios_decrypt7(inp) ⇒ Object


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

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 not inp[0,2] =~ /\d\d/

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