作者sosokill (隨便殺)
看板PHP
標題Re: [請益] php網頁會員登入問題
時間Sun Aug 10 23:27:06 2008
這兩天 小弟參考了各位大大的建議 也自己去找了一些書籍來看
目前在登入的部分 似乎沒有什麼問題了 可以正常登入
但是還有一個問題 我試了很久還是搞不出來 是有關sql injection的部分
是希望能夠透過簡單的隱碼攻擊 (EX: 'or 1=1--)這種 來達到登入的目的
不知各位高手們 能賜教一下嗎??
感謝!!
--------------------以下為目前修改後的原始碼----------------------
<!--範例程式:>
<html>
<head><title>login</title></head>
<body>
<center>
<h2>ID&&PassWord</h2>
<hr><small><font color="red">
<?
session_start();
session_register("login_session");
$ID="";
$Password="";
if(isset($_POST["ID"]))
$ID=$_POST["ID"];
if(isset($_POST["Password"]))
$Password=$_POST["Password"];
if($ID!="")
{
$link=mysql_connect("localhost","sosokill","sosokill");
mysql_select_db("member");
$sql="SELECT *FROM membertest WHERE ID='".$ID."' AND
Password='".$Password."'";
$result=mysql_query($sql);
$Fields=mysql_fetch_array($result);
if($Fields["ID"]==$ID && $Fields["Password"]==$Password){
$_SESSION["login_session"]=true;
header("location:hello.php");
}else
echo "<br>Password error<br>";
mysql_close($link);
}
?>
</font></small></center>
<form action="check.php" method="post">
<table align="center" bgcolor="#FFCC99">
<tr><td>username:</td>
<td><input type="text" name="ID" size="15" maxlength="10"></td></tr>
<tr><td>password:</td>
<td><input type="password" name="Password" size="15" maxlength="10"></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" value="login"></td></tr>
</table>
</form>
</body>
</html>
-----------------------------------------------------------------------------
有試過將WHERE ID='".$ID."' AND Password='".$Password."'";
改成WHERE ID='".$ID."'";
但是沒用= =
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.129.39.100
※ 編輯: sosokill 來自: 140.129.39.100 (08/10 23:47)
※ 編輯: sosokill 來自: 140.129.39.100 (08/11 01:22)
推 rabbithenry :sql injection基本上只要表單輸入值沒有篩選就有可能 08/11 01:37
→ rabbithenry :被攻擊,像你最後的 WHERE ID='".$ID."'; 輸入值只要 08/11 01:38
→ rabbithenry :是 ; DROP DATABASE `dbname`; 就會把你的資料表刪除 08/11 01:39
→ rabbithenry :因為SQL會變成 WHERE ID='';DROP DATABASE `dbname`; 08/11 01:40
→ ybite :最後一段有告訴你要如何避免,注意看其中第四點 XD 08/11 02:47
→ ybite :這樣已經有點放水了 XD 08/11 02:47
我將IF($Fields["ID"]==$ID && $Fields["Password"]==$Password)這段
改成IF($result==true)
結果是 不論輸入啥 都可以成功登入 囧
※ 編輯: sosokill 來自: 140.129.39.100 (08/11 03:23)
推 weiyucsie :如果要SQL Injection的話 可能就是卡在你說的if 08/11 13:26
→ weiyucsie :因為這個作法把帳號密碼再檢查一遍 08/11 13:26
→ weiyucsie :一般可能只檢查是不是有回傳結果 所以容易有危險XD 08/11 13:29
→ sosokill :嗯啊 現在就是卡在if判斷那邊 不知道該怎麼寫= = 08/11 17:45
→ weiyucsie :判斷回傳結果的筆數 如果超過0筆的話 就是有查到 08/11 19:35
→ sosokill :我有試著使用mysql_num_rows($result)的方法 08/11 22:54
→ sosokill :但是卻是出現warning 然後連輸入正確的帳號密碼 08/11 22:55
→ sosokill :都無法登入= =" 08/11 22:55