Google漏洞过滤规则研究

1、通过Protobuf的代码发现了过滤逻辑

goog.string.AMP_RE_ = /&/g;
goog.string.LT_RE_ = /</g;
goog.string.GT_RE_ = />/g;
goog.string.QUOT_RE_ = /"/g;
goog.string.SINGLE_QUOTE_RE_ = /'/g;
goog.string.NULL_RE_ = /\x00/g;
goog.string.E_RE_ = /e/g;
goog.string.ALL_RE_ = goog.string.DETECT_DOUBLE_ESCAPING ? /[\x00&<>"'e]/ : /[\x00&<>"']/;
goog.string.htmlEscape = function(str, opt_isLikelyToContainHtmlChars) {
  if (opt_isLikelyToContainHtmlChars) {
    str = str.replace(goog.string.AMP_RE_, "&amp;").replace(goog.string.LT_RE_, "&lt;").replace(goog.string.GT_RE_, "&gt;").replace(goog.string.QUOT_RE_, "&quot;").replace(goog.string.SINGLE_QUOTE_RE_, "&#39;").replace(goog.string.NULL_RE_, "&#0;"), goog.string.DETECT_DOUBLE_ESCAPING && (str = str.replace(goog.string.E_RE_, "&#101;"));
  } else {
    if (!goog.string.ALL_RE_.test(str)) {
      return str;
    }
    -1 != str.indexOf("&") && (str = str.replace(goog.string.AMP_RE_, "&amp;"));
    -1 != str.indexOf("<") && (str = str.replace(goog.string.LT_RE_, "&lt;"));
    -1 != str.indexOf(">") && (str = str.replace(goog.string.GT_RE_, "&gt;"));
    -1 != str.indexOf('"') && (str = str.replace(goog.string.QUOT_RE_, "&quot;"));
    -1 != str.indexOf("'") && (str = str.replace(goog.string.SINGLE_QUOTE_RE_, "&#39;"));
    -1 != str.indexOf("\x00") && (str = str.replace(goog.string.NULL_RE_, "&#0;"));
    goog.string.DETECT_DOUBLE_ESCAPING && -1 != str.indexOf("e") && (str = str.replace(goog.string.E_RE_, "&#101;"));
  }
  return str;
};

2、过滤一些特殊字符

oog.string.specialEscapeChars_ = {"\x00":"\\0", "\b":"\\b", "\f":"\\f", "\n":"\\n", "\r":"\\r", "\t":"\\t", "\x0B":"\\x0B", '"':'\\"', "\\":"\\\\", "<":"<"};
goog.string.jsEscapeCache_ = {"'":"\\'"};
" >>>>>> \"

3、 URLENCODE

对URL中一些请求进行服务端URLENCODE后输出;


4、HTML过滤


    f.string.Sj = function(a, c) {
        if (c) a = a.replace(f.string.IG, "&amp;").replace(f.string.GH, "&lt;").replace(f.string.DH, "&gt;").replace(f.string.ZH, "&quot;").replace(f.string.cI, "&#39;").replace(f.string.NH, "&#0;"), f.string.Gy && (a = a.replace(f.string.AH, "&#101;"));
        else {
            if (!f.string.SU.test(a)) return a; - 1 != a.indexOf("&") && (a = a.replace(f.string.IG, "&amp;")); - 1 != a.indexOf("<") && (a = a.replace(f.string.GH, "&lt;")); - 1 != a.indexOf(">") && (a = a.replace(f.string.DH, "&gt;")); - 1 != a.indexOf('"') && (a = a.replace(f.string.ZH,
                "&quot;")); - 1 != a.indexOf("'") && (a = a.replace(f.string.cI, "&#39;")); - 1 != a.indexOf("\x00") && (a = a.replace(f.string.NH, "&#0;"));
            f.string.Gy && -1 != a.indexOf("e") && (a = a.replace(f.string.AH, "&#101;"))
        }
        return a
    };
    f.string.IG = /&/g;
    f.string.GH = /</g;
    f.string.DH = />/g;
    f.string.ZH = /"/g;
    f.string.cI = /'/g;
    f.string.NH = /\x00/g;
    f.string.AH = /e/g;
    f.string.SU = f.string.Gy ? /[\x00&<>"'e]/ : /[\x00&<>"']/;
    f.string.nG = function(a) {
        return f.string.contains(a, "&") ? !f.string.n0 && "document" in f.global ? f.string.gU(a) : f.string.Jka(a) : a
    };

5. 默认输出过滤

针对所有的输出进行过滤;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值