加入收藏 | 设为首页 | 会员中心 | 我要投稿 惠州站长网 (https://www.0752zz.com.cn/)- 办公协同、云通信、物联设备、操作系统、高性能计算!
当前位置: 首页 > 业界 > 正文

技术讨论 | 自动化Web渗透Payload提取技术

发布时间:2018-10-10 05:49:35 所属栏目:业界 来源:zhanghaoyil
导读:副标题#e# 【新品产上线啦】51CTO播客,随时随地,碎片化学习 一、写在前面 做Web安全已经三四年了,从最初的小白到今天的初探门路,小鲜肉已经熬成了油腻大叔。Web安全是一个日新月异的朝阳领域,每天的互联网上都在发生着从未暴露的0 Day和N Day攻击。这

熟悉TF-IDF的同学一定有疑问了,你这TF-IDF的字典也会很大呀,如果样本量很大而且有各式各样的参数value,你的特征向量岂不是稀疏得不行了?对于这个问题,我有一个解决方案,也就是将所有的TF-IDF进一步加以处理,对参数key相同的TF-IDF项进行求和。设参数key集合为K={k1, k2, …, kn},TF-IDF字典为集合x={x1, x2, …, xm}。则每个参数key的特征值为:

  1. vn = ∑TF-IDFxn   xn∈{x | x startswith ‘kn=’} 

具体代码在vectorize/vectorizer.py中:

  1. for path, strs in path_buckets.items(): 
  2.         if not strs: 
  3.             continue 
  4.         vectorizer = TfidfVectorizer(analyzer='word', token_pattern=r"(?u)bSS+b") 
  5.         try: 
  6.             tfidf = vectorizer.fit_transform(strs) 
  7.             #putting same key's indices together 
  8.             paramindex = {} 
  9.             for kv, index in vectorizer.vocabulary.items(): 
  10.                 k = kv.split('=')[0] 
  11.                 if k in param_index.keys(): 
  12.                     param_index[k].append(index) 
  13.                 else: 
  14.                     param_index[k] = [index] 
  15.             #shrinking tfidf vectors 
  16.             tfidf_vectors = [] 
  17.             for vector in tfidf.toarray(): 
  18.                 v = [] 
  19.                 for param, index in param_index.items(): 
  20.                     v.append(np.sum(vector[index])) 
  21.                 tfidf_vectors.append(v) 
  22.             #other features 
  23.             other_vectors = [] 
  24.             for str in strs: 
  25.                 ov = [] 
  26.                 kvs = str.split(' ')[:-1] 
  27.                 lengths = np.array(list(map(lambda x: len(x), kvs))) 
  28.                 #param count 
  29.                 ov.append(len(kvs)) 
  30.                 #mean kv length 
  31.                 ov.append(np.mean(lengths)) 
  32.                 #max kv length 
  33.                 ov.append(np.max(lengths)) 
  34.                 #min kv length 
  35.                 ov.append(np.min(lengths)) 
  36.                 #kv length std 
  37.                 ov.append(np.std(lengths)) 
  38.                 other_vectors.append(ov) 
  39.             tfidf_vectors = np.array(tfidf_vectors) 
  40.             other_vectors = np.array(other_vectors) 
  41.             vectors = np.concatenate((tfidf_vectors, other_vectors), axis=1) 

(编辑:惠州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读