[NOTE] SQL与sqlmap
SQL语法
order by
- 对查询结果排序
- ASC:升序(默认)、DESC:降序
- SQL注入中多在成功查询之后添加order by i来猜解回显的字段数
- 如
XXX/?id=1' order by 3 %23
limit
select * from tableName limit i,n
- tableName:表名
- i:查询结果的索引值(默认从0开始),当i=0时可省略i
- n:查询结果返回的数量
- i与n之间使用英文逗号","隔开
- 例
- 查询10条数据,索引从0到9,第1条记录到第10条记录
select * from t_user limit 10
select * from t_user limit 0,10
- 查询第6条数据
select * from t_user limit 5,1
union
- union操作符可以合并多个select结果作为一个查询结果返回
- union内部的每个select必须拥有相同的列
- 列也必须拥有相似的数据类型
- 可以用来查找显错的字段(让前一个select语句为false,后一个select 1,2,3等)
- 例如输入了
1’ union select 1,2 #
,回显:
information_schema(重要)
sys数据库
里面有一些视图可能会暴露敏感信息
- innodb_buffer_stats_by_schema
通过数据库统计innodb引擎的innodb缓存
有数据库名字段 - innodb_buffer_stats_by_table
通过每个表innodb引擎的innodb缓存
有数据库名和表名字段 - host_summary
主机概要
有host、unique_users(主机唯一用户数)等字段 - host_summary_by_statement_type
主机语句执行概要
有statement(最后的语句时间名称)字段 - latest_file_io
记录着最近的文件I/O操作
有文件路径名、操作类型等字段 - schema_auto_increment_columns
记录着数据库中自增的字段
有库名、表名、自增列的数据类型等 - user_summary
一些函数
直接获取信息
- database():当前数据库
- user():当前用户
- system_user():操作系统用户
- session_user():连接数据库的用户
- version():当前数据库版本
- @@basedir:当前数据库绝对路径
- @@version_compile_os:操作系统版本
辅助与计算
- length():计算字段长度
- count(*):计算返回结果的数量
- substr(string, start, length):返回string从位置start开始length长度的子字符串
- mid():与substr()类似
- ascii(char):计算char对应的ASCII码
整理输出
- concat_ws(separator,str1,str2,…):以第一个参数为分隔符,返回拼接后的字符串
- group_concat(column_name):对返回的特定分组(常为某一列的数据)的字符串进行拼接
sqlmap
目标与探测级别
-
-r:从文件中加载HTTP请求
-
-p XXX:选择注入参数
-
–level=LEVEL(1-5): 探测级别
-
–risk=RISK(1-3):探测风险
全局信息查询
- –current-user:查询当前数据库用户
- –current-db:查询当前数据库
- –hostname:查询目标主机名
- –users:枚举所有用户
- –is-dba:判断当前用户是否为DBA
- –passwords:枚举所有用户的密码(可能会结合爆破/hash爆破)
- –privileges:查询当前用户权限
- –roles:查询当前用户角色
具体数据查询
- -dbs:枚举所有数据库
- –dump-all:导出所有数据库的所有内容
- -D DATABASE:指定数据库
- –dump:导出数据库的所有内容
- –tables:枚举所有表
- -T TABLE:指定表
- –schema:查询表的结构
- –colums:枚举所有列
- -C COLUM:指定列
系统操作(需要挂马)