如果它是Tomcat的最新版本,则可能没有问题。但是,这取决于您检查与会话关联的SSL ID。使用以下代码可以使用
String sslId = (String) req.getAttribute("javax.servlet.request.ssl_session");(注意,将来
javax.servlet.request.ssl_session
_id作为Servlet
3.0规范的一部分,属性键可能会更改为-)。
我使用以下
doGet方法设置了servlet :
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); String sid = session.getId(); String sslId = (String) request.getAttribute( "javax.servlet.request.ssl_session"); String uri = request.getRequestURI(); OutputStream out = response.getOutputStream(); PrintWriter pw = new PrintWriter(out); HashMap<String, Object> secrets; Object secret = null; Object notSecret; Date d = new Date(); notSecret = session.getAttribute("unprotected"); if (notSecret == null) { notSecret = "unprotected: " + d.getTime(); session.setAttribute("unprotected", notSecret); } secrets = (HashMap<String, Object>) session.getAttribute("protected"); if (secrets == null) { secrets = new HashMap<String, Object>(); session.setAttribute("protected", secrets); } if (sslId != null) { if (secrets.containsKey(sslId)) secret = secrets.get(sslId); else { secret = "protected: " + d.getTime(); secrets.put(sslId, secret); } } response.setContentType("text/plain"); pw.println(MessageFormat.format("URI: {0}", new Object[] { uri })); pw.println(MessageFormat.format("SID: {0}", new Object[] { sid })); pw.println(MessageFormat.format("SSLID: {0}", new Object[] { sslId })); pw.println(MessageFormat.format("Info: {0}", new Object[] { notSecret })); pw.println(MessageFormat.format("Secret: {0}", new Object[] { secret })); pw.println(MessageFormat.format("Date: {0}", new Object[] { d })); pw.close();}然后,我使用Firefox和Live HTTP Headers扩展调用了一个合适的不受保护的URL,以获取会话cookie。这是我导航到时发送的响应
http://localhost:8080/EchoWeb/unprotected
(我的web.xml和您一样,仅保护/ user / 和/ personal / ):
URI:/ EchoWeb /不受保护SID:9ACCD06B69CA365EFD8C10816ADD8D71SSLID:null信息:未受保护:1254034761932秘密:空日期:2009年9月27日07:59
接下来,我尝试访问受保护的URL
http://localhost:8080/EchoWeb/personal/protected
和预期的一样,我被重定向到
https://localhost:8443/EchoWeb/personal/protected
回应是
URI:/ EchoWeb /个人/受保护SID:9ACCD06B69CA365EFD8C10816ADD8D71SSLID:4abf0d67549489648e7a3cd9292b671ddb9dd844b9dba682ab3f381b462d1ad1信息:未受保护:1254034761932秘密:受保护:1254034791333日期:2009年9月27日07:59
请注意,cookie /会话ID是相同的,但是我们现在有了一个新的SSLID。现在,让我们尝试使用会话cookie欺骗服务器。
我设置了一个Python脚本
spoof.py:
import urllib2url = "https://localhost:8443/EchoWeb/personal/protected"headers = { 'Host': 'localhost:8080', 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-gb,en;q=0.5', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'cookie' : 'JSESSIonID=9ACCD06B69CA365EFD8C10816ADD8D71'}req = urllib2.Request(url, None, headers)response = urllib2.urlopen(req)print response.read()现在,您不需要特别了解Python-我只是想将HTTP请求发送到cookie中具有相同会话ID的(不同的)受保护资源。这是我两次运行欺骗脚本时的响应:
C: temp>欺骗URI:/ EchoWeb /个人/受保护SID:9ACCD06B69CA365EFD8C10816ADD8D71SSLID:4abf0eafb4ffa30b6579cf189c402a8411294201e2df94b33a48ae7484f22854信息:未受保护:1254034761932秘密:受保护的:1254035119303日期:2009年9月27日08:05C: temp>欺骗URI:/ EchoWeb /个人/受保护SID:9ACCD06B69CA365EFD8C10816ADD8D71SSLID:4abf0eb184cb380ce69cce28beb01665724c016903650539d095c671d98f1de3信息:未受保护:1254034761932秘密:受保护的:1254035122004日期:2009年9月27日08:05
请注意,在上面的响应中,
1254034761932在第一个不受保护的请求中设置的会话数据(带有时间戳记的值)已被发送出去,因为Tomcat使用的是同一会话,因为会话ID相同。这当然是
不安全的 。但是,请注意, 每次 使用的SSL ID 都不相同 ,如果您使用 它们
来键入会话数据(例如,如图所示),则应该是安全的。如果刷新Firefox选项卡,则响应如下:
URI:/ EchoWeb /个人/受保护SID:9ACCD06B69CA365EFD8C10816ADD8D71SSLID:4abf0d67549489648e7a3cd9292b671ddb9dd844b9dba682ab3f381b462d1ad1信息:未受保护:1254034761932秘密:受保护:1254034791333日期:2009年9月27日08:05
请注意,SSLID是 相同的 ,作为较早的Firefox的请求。因此,服务器可以使用SSL
ID值区分会话。通知特别的是,“受保护的数据”是从Firefox的会议上提出的每个请求相同,但 不同的
每个欺骗性的会议,并从Firefox的会话也不同。



