简体   繁体   English

考虑到SQL注入,这种PHP登录技术是否安全?

[英]Is this PHP login technique safe considering SQL injection?

I'am investigating a site that was written long ago by some PHP developer, and I'd like to know if the login technique he used was safe or not. 我正在调查很久以前由一些PHP开发人员编写的网站,我想知道他使用的登录技术是否安全。

Here is the way he did it: 这是他做的方式:

$username='';
$username = escapeshellcmd($HTTP_POST_VARS['user']);
$pwd = escapeshellcmd($HTTP_POST_VARS['pw']);

$loginerror=false;

if ($logout=="1")
{
  closesession($s_id);
  $username='';
  $logged=false;
}

$logged=checksession(session_id(), $ipaddr);

if ((!$logged) && ($username!=''))
{
        //$username = escapeshellcmd($HTTP_POST_VARS['felhasznalo']);
        //$pwd = escapeshellcmd($HTTP_POST_VARS['jelszo']);
        if (checkuser($username, $pwd, DOM))
            {
            if (sessionstore(session_id(), $username, $pwd, $ipaddr, $datum, DOM))
                {
                $logged=true;
                }
            }
        else
            {
            $loginerror=true;
            ;
            }       
}
if ($logged)
    {
    $username=getsessionuser(session_id());
    $remember=getremember($username, DOM);
    }
?>

function checkuser($u, $p, $d )
{
$sql_ell='SELECT PWD FROM USERS WHERE ACTIVE=1 AND USERNAME="'.$u.'" AND DOMAIN="'.$d.'"';
$eredm_ell= mysql_query($sql_ell);
if ($eredm_ell)
    {
    $domainnumrows=mysql_num_rows($eredm_ell);
    if ($domainnumrows==1) 
        {
        $egy_sor = mysql_fetch_row( $eredm_ell ); 
        $pwd_in_table=$egy_sor[0];
        if ($pwd_in_table==md5($u.$p))
            {
            return true;
            }
        } // rows
    } // ered
return false;   
} // func

Is this safe? 这样安全吗?

If I see correctly, the only check done on username is escapeshellcmd . 如果我看得正确,对用户名进行的唯一检查就是escapeshellcmd That is NOT enough. 这还不够。 Again, if I see correctly, it gets put into this query: 再次,如果我看到正确,它将被放入此查询:

$sql_ell='SELECT PWD FROM USERS WHERE ACTIVE=1 AND USERNAME="'.$u.'" AND DOMAIN="'.$d.'"'

where you can do all sorts of nasties. 在哪里你可以做各种各样的恶作剧。

So no. 所以不行。 it's not safe. 这不安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM