python系统安全工具软件汇编一线开发 [2021]余弦定理检测文件相似度 & 病毒样本基因检测 本余弦定理有如下应用场景: 1.相似度计算 2.信息推送 在网络安全领域,主要就是样本基因检测,或者叫做样本相似度计算,他的公式长这样: ![](https://key08.com/usr/uploads/2021/08/2243488000.png) 请注意,之所以叫做余弦定理,是因为,他就是求一个三角形的角,并且在N维这个定理也成立 ![](https://key08.com/usr/uploads/2021/08/3451125394.png) 样本相似度检测,以两个风灵月影为例,属于同一个家族: ![](https://key08.com/usr/uploads/2021/08/947620823.png) # 编码 通过pefile库,读入文件,然后逐个比对字节码,参数A为字节码相同的,参数B为字节码不同的: ```cpp def get_peinfo_by_cos(pSource,pTarget): source = pefile.PE(pSource) target = pefile.PE(pTarget) source_map,source_sizeof_code,source_base_of_code = get_pe_info(source) target_map,target_sizeof_code,target_base_of_code = get_pe_info(target) a1_dict = {} a2_dict = {} for iter in range(source_sizeof_code): v1 = iter + source_base_of_code v2 = iter + source_base_of_code + 1 if source_map[v1:v2] in a1_dict.keys(): a1_dict[source_map[v1:v2]] = a1_dict[source_map[v1:v2]] + 1 else: a1_dict[source_map[v1:v2]] = 0 for iter in range(target_sizeof_code): v1 = iter + target_base_of_code v2 = iter + target_base_of_code + 1 if target_map[v1:v2] in a2_dict.keys(): a2_dict[target_map[v1:v2]] = a2_dict[target_map[v1:v2]] + 1 else: a2_dict[target_map[v1:v2]] = 0 str1_vector=[] str2_vector=[] for key in a1_dict: str1_count = a1_dict[key] str1_vector.append(str1_count) for key in a2_dict: str2_count = a2_dict[key] str2_vector.append(str2_count) str1_map = map(lambda x: x*x,str1_vector) str2_map = map(lambda x: x*x,str2_vector) str1_mod = reduce(lambda x, y: x+y, str1_map) str2_mod = reduce(lambda x, y: x+y, str2_map) str1_mod = math.sqrt(str1_mod) str2_mod = math.sqrt(str2_mod) vector_multi = reduce(lambda x, y: x + y, map(lambda x, y: x * y, str1_vector, str2_vector)) # 计算余弦值 cos = float(vector_multi)/(str1_mod*str2_mod) return cos ``` 其中,两个是相似的,两个是不相似的,两个是恶意样本家族 来试试: ![](https://key08.com/usr/uploads/2021/08/1402924204.png) 简单粗暴,并且有效. 完整代码: 阅读全文 2021-08-19 huoji 1 条评论
python工具软件 [2021]python批量比较校验两个文件夹里面的文件md5 网上的东西都不怎么靠谱,这里发一个自己写的,用来快速确认有没有后门之类的东西 ```python import base64 import hashlib import os g_origin_path = "【目录】" g_target_path = "【目录】" def get_file_md5(filepath): f = open(filepath, 'rb') md5obj = hashlib.md5() md5obj.update(f.read()) hash = md5obj.hexdigest() f.close() return str(hash).upper() for root, dirs, files in os.walk(g_origin_path): for file in files: origin_file_path = os.path.join(root, file) strlist = origin_file_path.split('\\') target_file_path = g_origin_path + '\\'.join(strlist[5:]) if os.path.exists(target_file_path) == False: print("多出文件: {} ".format(target_file_path)) continue origin_file_md5 = get_file_md5(origin_file_path) target_file_md5 = get_file_md5(target_file_path) #print(origin_file_md5, target_file_md5) if origin_file_md5 != target_file_md5: print("md5不同 路径: {} src: {} target: {}".format( target_file_path, origin_file_md5, target_file_md5)) ``` 阅读全文 2021-08-02 huoji 0 条评论
系统安全工具软件二进制安全C/C++一线开发 [2021]检测Cobalt Strike只使用40行代码 无文件落地的木马主要是一段可以自定位的shellcode组成,特点是没有文件,可以附加到任何进程里面执行。一旦特征码被捕获甚至是只需要xor一次就能改变特征码.由于传统安全软件是基于文件检测的,对目前越来越多的无文件落地木马检查效果差. **基于内存行为特征的检测方式,可以通过检测执行代码是否在正常文件镜像区段内去识别是否是无文件木马.由于cobaltstrike等无文件木马区段所在的是private内存,所以在执行loadimage回调的时候可以通过堆栈回溯快速确认是否是无文件木马** 检测只需要40行代码: 1. 在loadimagecallback上做堆栈回溯 2. 发现是private区域的内存并且是excute权限的code在加载dll,极有可能,非常有可能是无文件木马或者是shellcode在运行 核心代码如下: 阅读全文 2021-07-25 huoji 0 条评论
系统安全工具软件二进制安全C/C++一线开发 [2021]让InfinityHook再次伟大 make InfinityHook great again ## 前言 在我折腾InfinityHook的时候我发现2004下系统没啥作用,原因是在2004系统上 WMI_LOGGER_CONTEXT->GetCpuClock已经不是rdtsc()函数了而是一个叫做 EtwpGetLoggerTimeStamp的函数 ![](https://key08.com/usr/uploads/2021/06/239927485.png) EtwpGetLoggerTimeStamp函数按照WMI_LOGGER_CONTEXT->GetCpuClock的值有如下操作: 大于3抛异常 等于3用rdtsc 等于2用off_140C00A30 等于1用KeQueryPerformanceCounter 等于0用RtlGetSystemTimePrecise 3,1,0都好说,但是这个2的off_140C00A30是什么鬼? 阅读全文 2021-06-23 huoji 5 条评论
工具软件二进制安全C/C++汇编一线开发 [2021]基于hypervisor的HIPS架构 从0到1 四 (SSDT hook) # 前言 还记我们系列的标题吗? HIPS,作为系统监控,我们需要监控所有的syscall调用。这个部分会由hypervisor完成. ssdt hook是一个古老古老的东西了,还记得我以前入门就是很多人把ssdt hook看做是核心机密,现在已经烂大街了.我们的ssdt hook不同于传统的"内联hook",我们准确的说叫做msr hook.回忆一下amd64里面syscall的方式,看看AMD手册的介绍: 在AMD64体系下,为了解决之前int调用方式的不足,从而推出了syscall指令作为进入内核入口的指令,syscall在AMD64体系下调用的方式 ![](https://key08.com/usr/uploads/2021/05/3936827292.png) 可以看到,最终RIP的值会等与MSR_LSTAR相等,而在微软体系里,MSR_LSTAR存放着kisystemcall64的函数地址 因此,我们需要hook这个msr_star 阅读全文 2021-05-25 huoji 1 条评论
python工具软件 [2021]MySQL蜜罐,读取攻击者任意文件 mysql客户端load data语句这块没有受到限制,服务端发什么信息就会读什么,而且没有校验,特别蠢 原理 > MySQL中 load data local infile '/etc/passwd' into table test fields terminated by '\n';语句可以读取客户端本地文件并插进表中,那么我们可以伪造一个恶意的服务器,向连接服务器的客户端发送读取文件的payload。这个技术并不新鲜,但是合理利用就能起到一些不错的成果。 脚本: https://github.com/ev0A/Mysqlist https://github.com/qigpig/MysqlHoneypot ```c chrome的login data,虽然无法解密出密码,但是还是可以获取到对方的一些账号的 'C:/Users/' + username + '/AppData/Local/Google/Chrome/User Data/Default/Login Data' chrome的历史记录 'C:/Users/' + username + '/AppData/Local/Google/Chrome/User Data/Default/History' 用户的NTLM Hash(Bettercap + responder) \\ip\test C:\Users\username\Documents\WeChat Files\All Users\config\config.data中含有微信ID C:\Windows\PFRO.log中较大几率能找到用户名 ``` 阅读全文 2021-04-11 huoji 0 条评论
python工具软件 [2021]SSH流量取证工具 在实战中我们经常遇到ssh被爆破登陆后搞这个搞那个 我们需要一个工具来解密ssh流量并且取证 packetStrider就是干这个的 使用: ```bash pip3 install pandas matplotlib pyshark git clone https://github.com/benjeems/packetStrider.git python3 packetStrider-ssh.py -h usage: packetStrider-ssh.py [-h] [-f FILE] [-n NSTREAM] [-m] [-k] [-p] [-z ZOOM] [-d DIRECTION] [-o OUTPUT_DIR] [-w WINDOW] [-s STRIDE] packetStrider-ssh is a packet forensics tool for SSH. It creates a rich feature set from packet metadata such SSH Protocol message content, direction, size, latency and sequencing. It performs pattern matching on these features, using statistical analysis, and sliding windows to predict session initiation, keystrokes, human/script behavior, password length, use of client certificates, context into the historic nature of client/server contact and exfil/infil data movement characteristics in both Forward and Reverse sessions optional arguments: -h, --help show this help message and exit -f FILE, --file FILE pcap file to analyze -n NSTREAM, --nstream NSTREAM Perform analysis only on stream n -m, --metaonly Display stream metadata only -k, --keystrokes Perform keystroke prediction -p, --predict_plot Plot data movement and keystrokes -z ZOOM, --zoom ZOOM Narrow down/zoom the analysis and plotting to only packets "x-y" -d DIRECTION, --direction DIRECTION Perform analysis on SSH direction : "forward", "reverse" OR "both" -o OUTPUT_DIR, --output_dir OUTPUT_DIR Directory to output plots -w WINDOW, --window WINDOW Sliding window size, # of packets to side of window center packet, default is 2 -s STRIDE, --stride STRIDE Stride between sliding windows, default is 1 ``` 解密ssh流量与时间会话: ```bash python3 packetStrider-ssh.py -f tcpdump.pcap -k -p -o out ``` 基本上全出来了 ![](https://key08.com/usr/uploads/2021/04/3355700718.png) github: https://github.com/benjeems/packetStrider 阅读全文 2021-04-11 huoji 0 条评论