-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbuild_convert2shellcode.bat
More file actions
156 lines (131 loc) · 5.28 KB
/
Copy pathbuild_convert2shellcode.bat
File metadata and controls
156 lines (131 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
@echo off
setlocal EnableExtensions
for %%I in ("%~dp0..") do set "ROOT=%%~fI"
set "BIN=%ROOT%\bin"
set "GO_ASSETS=%ROOT%\internal\rdi"
set "ASM_DIR=%ROOT%\SRDI_Asm"
set "SCRIPTS=%ROOT%\tools\scripts"
set "SRC=%ROOT%\tools\src"
set "TARGET=%ROOT%\beacon.exe"
set "OBJDIR=%TEMP%\Convert2Shellcode_%RANDOM%%RANDOM%"
if /i "%~1"=="-h" goto usage
if /i "%~1"=="--help" goto usage
if not "%~1"=="" set "TARGET=%~1"
if not exist "%BIN%" mkdir "%BIN%"
mkdir "%OBJDIR%" >nul 2>nul
if errorlevel 1 (
echo [-] failed to create temp build directory:
echo %OBJDIR%
exit /b 1
)
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if exist "%VSWHERE%" goto have_vswhere
echo [-] vswhere.exe not found:
echo %VSWHERE%
goto fail
:have_vswhere
for /f "tokens=*" %%i in ('"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath') do set "VSINSTALL=%%i"
if not "%VSINSTALL%"=="" goto have_vs
echo [-] Visual Studio with VC tools not found
goto fail
:have_vs
set "VCVARSALL=%VSINSTALL%\VC\Auxiliary\Build\vcvarsall.bat"
if exist "%VCVARSALL%" goto have_vcvars
echo [-] vcvarsall.bat not found:
echo %VCVARSALL%
goto fail
:have_vcvars
call "%VCVARSALL%" x64 >nul
if errorlevel 1 goto fail
echo [*] assembling RDI_front_v2_x64.asm
ml64 /nologo /c /Fo"%OBJDIR%\srdi_front_v2_x64.obj" "%ASM_DIR%\RDI_front_v2_x64.asm"
if errorlevel 1 goto fail
python "%SCRIPTS%\extract_rdi_text.py" "%OBJDIR%\srdi_front_v2_x64.obj" -o "%BIN%\srdi_front_v2_x64.bin"
if errorlevel 1 goto fail
echo [*] assembling RDI_post_v2_x64.asm
ml64 /nologo /c /Fo"%OBJDIR%\srdi_post_v2_x64.obj" "%ASM_DIR%\RDI_post_v2_x64.asm"
if errorlevel 1 goto fail
python "%SCRIPTS%\extract_rdi_text.py" "%OBJDIR%\srdi_post_v2_x64.obj" -o "%BIN%\srdi_post_v2_x64.bin"
if errorlevel 1 goto fail
call "%VCVARSALL%" x86 >nul
if errorlevel 1 goto fail
echo [*] assembling RDI_front_v2_x86.asm
ml /nologo /c /Fo"%OBJDIR%\srdi_front_v2_x86.obj" "%ASM_DIR%\RDI_front_v2_x86.asm"
if errorlevel 1 goto fail
python "%SCRIPTS%\extract_rdi_text.py" "%OBJDIR%\srdi_front_v2_x86.obj" -o "%BIN%\srdi_front_v2_x86.bin"
if errorlevel 1 goto fail
echo [*] assembling RDI_post_v2_x86.asm
ml /nologo /c /Fo"%OBJDIR%\srdi_post_v2_x86.obj" "%ASM_DIR%\RDI_post_v2_x86.asm"
if errorlevel 1 goto fail
python "%SCRIPTS%\extract_rdi_text.py" "%OBJDIR%\srdi_post_v2_x86.obj" -o "%BIN%\srdi_post_v2_x86.bin"
if errorlevel 1 goto fail
echo [*] compiling shellcode_loader_x86.exe
cl /nologo /W4 /O2 /Fo"%OBJDIR%\shellcode_loader_x86.obj" /Fe"%BIN%\shellcode_loader_x86.exe" "%SRC%\shellcode_loader.c"
if errorlevel 1 goto fail
call "%VCVARSALL%" x64 >nul
if errorlevel 1 goto fail
echo [*] embedding public RDI blobs into Convert2Shellcode
python "%SCRIPTS%\embed_rdi_blobs.py" ^
--front "%BIN%\srdi_front_v2_x64.bin" ^
--post "%BIN%\srdi_post_v2_x64.bin" ^
--front-x86 "%BIN%\srdi_front_v2_x86.bin" ^
--post-x86 "%BIN%\srdi_post_v2_x86.bin" ^
-o "%BIN%\rdi_blobs.h"
if errorlevel 1 goto fail
echo [*] syncing RDI blobs into the Go module
copy /y "%BIN%\srdi_front_v2_x64.bin" "%GO_ASSETS%\srdi_front_v2_x64.bin" >nul
if errorlevel 1 goto fail
copy /y "%BIN%\srdi_post_v2_x64.bin" "%GO_ASSETS%\srdi_post_v2_x64.bin" >nul
if errorlevel 1 goto fail
copy /y "%BIN%\srdi_front_v2_x86.bin" "%GO_ASSETS%\srdi_front_v2_x86.bin" >nul
if errorlevel 1 goto fail
copy /y "%BIN%\srdi_post_v2_x86.bin" "%GO_ASSETS%\srdi_post_v2_x86.bin" >nul
if errorlevel 1 goto fail
if errorlevel 1 goto fail
echo [*] compiling Go Convert2Shellcode.exe
go build -o "%BIN%\Convert2Shellcode.exe" "%ROOT%\cmd\convert2shellcode"
if errorlevel 1 goto fail
echo [*] compiling shellcode_loader.exe
cl /nologo /W4 /O2 /Fo"%OBJDIR%\shellcode_loader.obj" /Fe"%BIN%\shellcode_loader.exe" "%SRC%\shellcode_loader.c"
if errorlevel 1 goto fail
if not exist "%TARGET%" goto skip_samples
echo [*] generating sample front shellcode
"%BIN%\Convert2Shellcode.exe" --type front --input "%TARGET%" --output "%BIN%\beacon_front_v2.bin"
if errorlevel 1 goto fail
echo [*] generating sample post shellcode
"%BIN%\Convert2Shellcode.exe" --type post --input "%TARGET%" --output "%BIN%\beacon_post_v2.bin"
if errorlevel 1 goto fail
:skip_samples
rmdir /s /q "%OBJDIR%" >nul 2>nul
echo.
echo Build complete:
echo %BIN%\Convert2Shellcode.exe
echo %BIN%\shellcode_loader.exe
echo %BIN%\shellcode_loader_x86.exe
echo %BIN%\srdi_front_v2_x64.bin
echo %BIN%\srdi_post_v2_x64.bin
echo %BIN%\srdi_front_v2_x86.bin
echo %BIN%\srdi_post_v2_x86.bin
echo.
echo Usage:
echo "%BIN%\Convert2Shellcode.exe" --arch x64 --type front --input "%TARGET%" --output "%BIN%\out_front.bin"
echo "%BIN%\Convert2Shellcode.exe" --arch x64 --type post --input "%TARGET%" --output "%BIN%\out_post.bin"
echo "%BIN%\Convert2Shellcode.exe" --arch x86 --type front --input "path\to\x86.exe" --output "%BIN%\out_x86_front.bin"
echo "%BIN%\Convert2Shellcode.exe" --arch x86 --type post --input "path\to\x86.exe" --output "%BIN%\out_x86_post.bin"
echo.
echo Test:
echo "%BIN%\shellcode_loader.exe" "%BIN%\beacon_front_v2.bin" 15000
echo "%BIN%\shellcode_loader.exe" "%BIN%\beacon_post_v2.bin" 15000
exit /b 0
:fail
set "ERR=%ERRORLEVEL%"
if "%ERR%"=="0" set "ERR=1"
rmdir /s /q "%OBJDIR%" >nul 2>nul
exit /b %ERR%
:usage
echo Usage:
echo %~nx0 [target_pe]
echo.
echo Default target:
echo %ROOT%\beacon.exe
exit /b 0