第九章 web安全性入门 实训九

SampleServlet.java

package com.demo;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class SampleServlet
 */
@WebServlet("/sample-servlet")
public class SampleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SampleServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		RequestDispatcher rd = request.getRequestDispatcher("/jsp/demo.jsp");
		rd.forward(request, response);
		
	}

}

demo.jsp

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>security-demo</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>JSP pages</web-resource-name>
      <url-pattern>*.jsp</url-pattern>
    </web-resource-collection>
  </security-constraint>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>sample servlet</web-resource-name>
      <url-pattern>/sample-servlet</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>manager</role-name>
      <role-name>member</role-name>
    </auth-constraint>
    <user-data-constraint>
      <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
  </security-constraint>
  <login-config>
    <auth-method>FORM</auth-method>
    <realm-name>Security Test</realm-name>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/error.jsp</form-error-page>
    </form-login-config>
  </login-config>
</web-app>

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录页面</title>
</head>
<body bgcolor = "white">
<p>请输入用户名和口令:</p>
<form method = "POST" action="j_security_check">
	<table>
		<tr>
			<td>用户名:</td>
			<td><input type = "text" name="j_username"></td>
		</tr>
		<tr>
			<td>密&nbsp;&nbsp;码:</td>
			<td><input type = "password" name="j_password"></td>
		</tr>
		<tr>
			<td><input type = "submit" value="登录"></td>
			<td><input type = "reset" value="重置"></td>
	</table>
</form>

</body>
</html>

error.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<p style = "color:red">对不起,你的用户名和口令不正确!</p>
</body>
</html>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Web安全学习大纲 一、Web安全系列之基础 1、Web安全基础概念(1天) 互联网本来是安全的,自从有了研究安全的人之后,互联网就变的不安全了。 2、web面临的主要安全问题(2天) 客户端:移动APP漏洞、浏览器劫持、篡改 服务器:DDos攻击、CC攻击、黑客入侵、业务欺诈、恶意内容 3、常用渗透手段(3天) 信息搜集:域名、IP、服务器信息、CDN、子域名、GOOGLE HACKING 扫描器扫描:Nmap、AWVS、Burp Suite、在线扫描器 权限提升 权限维持 二、Web安全系列之漏洞 1、漏洞产生原因(1天) 漏洞就是软件设计时存在的缺陷,安全漏洞就是软件缺陷具有安全攻击应用方面的价值。软件系统越复杂,存在漏洞的可能性越大。 2、漏洞出现哪些地方?(2天) 前端静态页面 脚本 数据 服务:主机、网络 系统逻辑 移动APP 3、常见漏洞(3天) SQL注入:布尔型注入、报错型注入、可联合查询注入、基于时间延迟注入。 XSS(跨站脚本攻击):反射型XSS、存储型XSS、DOM XSS CSRF(跨站请求伪造) SSRF(服务器端请求伪造) 文件上传下载:富文本编辑器 弱口令: X-Scan、Brutus、Hydra、溯雪等工具 其它漏洞: 4、逻辑漏洞(3天) 平行越权 垂直越权 任意密码重置 支付漏洞:0元购 接口权限配置不当: 验证码功能缺陷: 5、框架漏洞(2天) struts2漏洞、Spring远程代码执行漏洞、Java反序列化漏洞 6、建站程序漏洞(1天) Discuz漏洞、CMS漏洞等 三、Web安全系列之防御 1、常见防御方案(1天) 2、安全开发(2天) 开发自检、测试自检、部署自检 开发工具:安全框架Spring security、 shiro、Spring boot 3、安全工具和设备(2天) DDos防护、WAF、主机入侵防护等等 4、网站安全工具(1天) 阿里云、云狗、云盾 网站在线检测:http://webscan.360.cn/ https://guanjia.qq.com/online_server/webindex.html http://www.51testing.com/zhuanti/selenium.html Selenium是一个用于Web应用程序测试的工具
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值