English 中文(简体)
我的登录脚本正在被黑入 [重复]
原标题:My login script is being hacked [duplicate]
  • 时间:2012-05-25 18:35:29
  •  标签:
  • php
  • mysql
  • sql
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
Best way to stop SQL Injection in PHP

我的登录脚本正被黑入(黑入可以绕过登录进入成员部分)。

以下是我的登录 :

<form action="<?php echo $_SERVER[ PHP_SELF ]?>" method="post"> 
<table width="450px"><tr><td>
<?php 
if(isset($_POST[ login ]))
{   

$user= mysql_real_escape_string($_POST[ username ]);
$user22 = strip_tags($user);
$pass= mysql_real_escape_string($_POST[ password ]);
$pass2 = strip_tags($pass);
$pass1 = md5($pass2);

$mod = 1 ;

$sql = "SELECT * FROM users WHERE username= ".$user22."  AND password =  ".$pass1." ";
$result = mysql_query($sql) or die(mysql_error());
$battle_get = mysql_fetch_array($result);

if ( $battle_get[ mod ] == 1 ) {
                $month = time() + 3600*24*30;
                $hour = time() + 3600*1*1;
                $LastLogin = date( l, M d, Y H:i:s );
                $_SESSION[ user ] = $_POST[ username ];
                setcookie("save_user", stripslashes(htmlentities($user22)), $hour); 
                setcookie("save_pass", stripslashes(htmlentities($user22)), $month);
                $username = stripslashes(htmlentities($user22));
                $result = mysql_query("UPDATE users SET LastLogin =  $LastLogin  WHERE username= $username ");
                header("location: home.php"); 
}

}
?></td></tr></table>
<ul><li class="topper" style="width:410px;"></li>
<table>
<tr><td>Username</td><td><input type="text" name="username" id="textfield"></td></tr>
<tr><td>Password</td><td><input type="password" name="password" id="textfield"></td></tr>
</table><li class="bottomer" style="width:410px;"></li></ul>
<table><tr><td><input type="submit" name="login" value="login" id="button"></td></tr></table>
</form>

在我的配置文件中,我有一个代码 阻止用户更改每个登录的IP等 。

if(isset($_SESSION[ last_ip ]) == false){
    $_SESSION[ last_ip ] = $_SERVER[ REMOTE_ADDR ];
    }

    if ($_SESSION[ last_ip ] !== $_SERVER[ REMOTE_ADDR ]){

    session_unset();
    session_destroy();

    }

if(empty($_SESSION[ user ])){
         echo"Please login into the rpg first" ;
         die;
}

我在每个页面上插入配置文件(上面的代码), 如果是空的话, 用户将无法在网站旁查看... 黑客告诉我他正在使用 Sql 进入......

我做错什么了?

问题回答

线条线

$sql = "SELECT * FROM users WHERE username= ".$user22."  AND password =  ".$pass1." ";

是危险的(SQL 注入),我建议您使用有 PdoMySQL 的预发语句。

http://www.php.net/manual/en/ref.pdo-mysql.php' rel=“no follow”>http://www.php.net/manual/en/ref.pdo-mysql.php

他正在使用 SQL 注射。 他正在将用户名的 $_POST 转换为

"username; OR 1=1"

并且因为 1=1 是“ 真实的 ”, 它允许他进去。 你不受“ ” 的保护;

有关SQL注射和如何保护自己的信息很多。

Look into Sql Injection, and view examples here: http://www.unixwiz.net/techtips/sql-injection.html

您的特殊 sql 看起来像 :

$sql = "SELECT * FROM users WHERE username= ".$user22."  AND password =  ".$pass1." ";

准备打针的时机已经成熟了

研究以下几个方面:

这些仅仅是在寻找如何防止在php中发生 sql 注射攻击时的几条顶端链接。

请查看"https://stackoverflow.com/ questions/574187/sql-inpition- that-gets-around-mysql-real-escape-string"。>此文章

他解释了 sql 注入和 mysql_real_escape_string (; smysql_real_escape_string (; ) 的原因





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签