python shellcode 分析二
https://forum.90sec.com/t/topic/1587
![](https://upload-images.jianshu.io/upload_images/4664072-d8fa90a1286a2e49.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
分析shellcode
![](https://upload-images.jianshu.io/upload_images/4664072-e8ec149fa4ba756f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
将shellcode生成后,使用base64编码,放入buf。将代码写入内存,所以需要将代码解码并转为字节类型。在64位系统上运行,必须使用restype函数设置VirtualAlloc返回类型为ctypes.c_unit64,否则默认的是 32 位。
ctypes.windll.kernel32.VirtualAlloc.restype = ctypes.c_uint64
![](https://upload-images.jianshu.io/upload_images/4664072-bb75f0918a8fc979.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
申请内存,ctypes.windll.kernel32.VirtualAlloc函数。VirtualAlloc是Windows提供的API,通常用来分配大块的内存。跟上一篇的shellcode差不多。
放入内存,RtlMoveMemory从指定内存中复制内存至另一内存里
![](https://upload-images.jianshu.io/upload_images/4664072-8704b4d386888d32.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
调用CreateThread将在主线程的基础上创建一个新线程,WaitForSingleObject等待创建的线程,里两个参数,一个是创建的线程,一个是等待时间。正常的话我们创建的线程是需要一直运行的,所以将时间设为负数,等待时间将成为无限等待,程序就不会结束。
![](https://upload-images.jianshu.io/upload_images/4664072-e5ba61d2aa947a42.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
跟之前的分析的shellcode一样。
或者使用
![](https://upload-images.jianshu.io/upload_images/4664072-8d2c922087643fe4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
读取远程文件
分析第二个脚本
![](https://upload-images.jianshu.io/upload_images/4664072-ef956196865d93c3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
pickle 模块
python的pickle模块实现了基本的数据序列和反序列化。
pickle.dumps()将对象obj对象序列化并返回一个byte对象
pickle.loads(),从字节对象中读取被封装的对象
该脚本首先对加载器进行读取,使用base64进行解密,使用class对象进行执行sectr,在使用ret进行封装,进行base64加密解密,最后使用pickle.loads读取。