Skip to content

Commit 210ec7d

Browse files
committed
Format and remove 09.4.md spaces
1 parent dc80329 commit 210ec7d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

zh/09.4.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,44 @@ SQL注入攻击(SQL Injection),简称注入攻击,是Web开发中最常
1111
考虑以下简单的登录表单:
1212
```html
1313

14-
<form action="/login" method="POST">
15-
<p>Username: <input type="text" name="username" /></p>
16-
<p>Password: <input type="password" name="password" /></p>
17-
<p><input type="submit" value="登陆" /></p>
18-
</form>
14+
<form action="/login" method="POST">
15+
<p>Username: <input type="text" name="username" /></p>
16+
<p>Password: <input type="password" name="password" /></p>
17+
<p><input type="submit" value="登陆" /></p>
18+
</form>
1919

2020
```
2121
我们的处理里面的SQL可能是这样的:
2222
```Go
2323

24-
username:=r.Form.Get("username")
25-
password:=r.Form.Get("password")
26-
sql:="SELECT * FROM user WHERE username='"+username+"' AND password='"+password+"'"
24+
username:=r.Form.Get("username")
25+
password:=r.Form.Get("password")
26+
sql:="SELECT * FROM user WHERE username='"+username+"' AND password='"+password+"'"
2727

2828
```
2929
如果用户的输入的用户名如下,密码任意
3030
```Go
3131

32-
myuser' or 'foo' = 'foo' --
32+
myuser' or 'foo' = 'foo' --
3333
3434
```
3535
那么我们的SQL变成了如下所示:
3636
```Go
3737
38-
SELECT * FROM user WHERE username='myuser' or 'foo' = 'foo' --'' AND password='xxx'
38+
SELECT * FROM user WHERE username='myuser' or 'foo' = 'foo' --'' AND password='xxx'
3939
```
4040
在SQL里面`--`是注释标记,所以查询语句会在此中断。这就让攻击者在不知道任何合法用户名和密码的情况下成功登录了。
4141
4242
对于MSSQL还有更加危险的一种SQL注入,就是控制系统,下面这个可怕的例子将演示如何在某些版本的MSSQL数据库上执行系统命令。
4343
```Go
4444
45-
sql:="SELECT * FROM products WHERE name LIKE '%"+prod+"%'"
46-
Db.Exec(sql)
45+
sql:="SELECT * FROM products WHERE name LIKE '%"+prod+"%'"
46+
Db.Exec(sql)
4747
```
4848
如果攻击提交`a%' exec master..xp_cmdshell 'net user test testpass /ADD' --`作为变量 prod的值,那么sql将会变成
4949
```Go
5050

51-
sql:="SELECT * FROM products WHERE name LIKE '%a%' exec master..xp_cmdshell 'net user test testpass /ADD'--%'"
51+
sql:="SELECT * FROM products WHERE name LIKE '%a%' exec master..xp_cmdshell 'net user test testpass /ADD'--%'"
5252
```
5353
MSSQL服务器会执行这条SQL语句,包括它后面那个用于向系统添加新用户的命令。如果这个程序是以sa运行而 MSSQLSERVER服务又有足够的权限的话,攻击者就可以获得一个系统帐号来访问主机了。
5454

0 commit comments

Comments
 (0)