简体   繁体   English

如何测试我的简单mysql登录表单以进行sql注入?

[英]How to test my simple mysql login form for sql injection?

I have created a simple login form for a project in PHP and mySQL. 我已经使用PHP和mySQL为项目创建了一个简单的登录表单。 I read about security and info about SQL Injections and XSS. 我阅读了有关SQL注入和XSS的安全性和信息。 How can I test my form with these stuff ? 我如何用这些东西测试我的表格? I mean where I put it? 我的意思是我放在哪里? I found something like this ' or 1=1– and SQL queries like 我发现了类似这样的' or 1=1–和类似SQL查询

SELECT fieldlist
  FROM table
 WHERE field = '$EMAIL';

I know it's a silly question, but I don't know the answer! 我知道这是一个愚蠢的问题,但我不知道答案!

You'd submit suspicious strings into your login form. 您需要在登录表单中提交可疑字符串。

From there that string ' or 1=1- (or whatever you want to test) will be sent to your server, and PHP, if not set up properly, will send that string straight into your MySQL database, where if it's valid SQL, it will be executed. 从那里,该字符串' or 1=1- (或您要测试的任何内容)将被发送到您的服务器,而PHP(如果未正确设置)会将该字符串直接发送到您的MySQL数据库(如果它是有效的SQL),它会被执行。

for input input = $EMAIL the value asdf' or '1'='1 in the input and submit and see if you get true result or not. 对于输入input = $EMAIL ,输入中的值asdf' or '1'='1并提交,然后查看是否得到正确的结果。

So the query generated is 所以生成的查询是

SELECT fieldlist
  FROM table
 WHERE field = 'asdf' or '1'='1';

To check if password is not empty or not. 检查密码是否为空。

if(!isset($_POST['password'])) 

Also doing this would be more better if 如果这样做也会更好

$username = trim($_POST['username']); //also turn magic quotes
            //or add slashes to prevent sql injection

$password = md5(trim($_POST['username'])); //encrypt the password


SELECT *
FROM user
WHERE username = `$username` AND
password = `$password` LIMIT 1;

if(mysql_num_rows($result)) //if the count is 1, then, the the user exists
//do the login

You would enter in the malicious code through the form itself, so that it gets sent to PHP, and then to MySQL. 您将通过表单本身输入恶意代码,以便将其发送到PHP,然后发送到MySQL。 If the malicious code alters your query, then your code would be vulnerable to SQL injection. 如果恶意代码更改了您的查询,则您的代码将容易受到SQL注入的攻击。 Take a look at mysql_real_escape_string() . 看一下mysql_real_escape_string() Also, give this a read, to help you get started: 另外,请阅读以下内容,以帮助您入门:

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

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