forked from Ne0nd0g/merlin
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Makefile
195 lines (158 loc) · 7.15 KB
/
Makefile
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# !!!MAKE SURE YOUR GOPATH ENVIRONMENT VARIABLE IS SET FIRST!!!
# Quick start:
# make
# After it finish, it will created files in data/temp/<version>/<id>/
# Then you can package it by running: "make package-agent-linux" or "make package-all"
# Merlin Server & Agent version number
VERSION=$(shell cat pkg/merlin.go |grep "const Version ="|cut -d"\"" -f2)
MSERVER=kubesploitServer
MAGENT=kubesploitAgent
PASSWORD=kubesploit
BUILD=$(shell git rev-parse HEAD)
DIR=data/temp/v${VERSION}/${BUILD}
BIN=data/bin/
XBUILD=-X main.build=${BUILD} -X github.com/cyberark/kubesploit/pkg/agent.build=${BUILD}
URL ?= https://127.0.0.1:443
XURL=-X main.url=${URL}
PSK ?= kubesploit
XPSK=-X main.psk=${PSK}
PROXY ?=
XPROXY =-X main.proxy=$(PROXY)
HOST ?=
XHOST =-X main.host=$(HOST)
PROTO ?= h2
XPROTO =-X main.protocol=$(PROTO)
JA3 ?=
XJA3 =-X main.ja3=$(JA3)
LDFLAGS=-ldflags "-s -w ${XBUILD} ${XPROTO} ${XURL} ${XHOST} ${XPSK} ${XPROXY} -buildid="
WINAGENTLDFLAGS=-ldflags "-s -w ${XBUILD} ${XPROTO} ${XURL} ${XHOST} ${XPSK} ${XPROXY} -H=windowsgui -buildid="
# TODO Update when Go1.13 is released https://stackoverflow.com/questions/45279385/remove-file-paths-from-text-directives-in-go-binaries
GCFLAGS=-gcflags=all=-trimpath=$(GOPATH)
ASMFLAGS=-asmflags=all=-trimpath=$(GOPATH)# -asmflags=-trimpath=$(GOPATH)
PACKAGE=7za a -p${PASSWORD} #-mhe -mx=9
F=README.MD LICENSE NOTICES.txt config.yaml kubesploit.yara data/bin data/html data/modules
F2=LICENSE NOTICES.txt
W=Windows-x64
L=Linux-x64
A=Linux-arm
M=Linux-mips
D=Darwin-x64
export GO111MODULE=on
# Make Directory to store executables
$(shell mkdir -p ${DIR})
# Change default to just make for the host OS and add MAKE ALL to do this
#default: server-windows agent-windows server-linux agent-linux server-darwin agent-darwin agent-dll agent-javascript prism-windows prism-linux prism-darwin
default: server-linux agent-linux server-darwin agent-darwin agent-javascript prism-linux prism-darwin
all: default
# Compile Windows binaries
windows: server-windows agent-windows agent-dll
# Compile Linux binaries
linux: server-linux agent-linux
# Compile Arm binaries
arm: agent-arm
# Compile mips binaries
mips: agent-mips
# Compile Darwin binaries
darwin: server-darwin agent-darwin
# Compile Server - Windows x64
server-windows:
export GOOS=windows;export GOARCH=amd64;go build ${LDFLAGS} -o ${DIR}/${MSERVER}-${W}.exe cmd/merlinserver/main.go
# Compile Agent - Windows x64
agent-windows:
export GOOS=windows GOARCH=amd64;go build ${WINAGENTLDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${W}.exe cmd/merlinagent/main.go
# Compile Agent - Windows x64 DLL - main() - Console
agent-dll:
export GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_ENABLED=1; \
go build ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -buildmode=c-archive -o ${DIR}/main.a cmd/merlinagentdll/main.go; \
cp data/bin/dll/merlin.c ${DIR}; \
x86_64-w64-mingw32-gcc -shared -pthread -o ${DIR}/merlin.dll ${DIR}/merlin.c ${DIR}/main.a -lwinmm -lntdll -lws2_32
# Compile PRISM - Windows x64
prism-windows:
export GOOS=windows GOARCH=amd64;go build ${LDFLAGS} -o ${DIR}/PRISM-${W}.exe cmd/prism/main.go
# Compile Server - Linux x64
server-linux:
export GOOS=linux;export GOARCH=amd64;go build ${LDFLAGS} -o ${DIR}/${MSERVER}-${L} cmd/merlinserver/main.go
# Compile Agent - Linux mips
agent-mips:
export GOOS=linux;export GOARCH=mips;go build ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${M} cmd/merlinagent/main.go
# Compile Agent - Linux arm
agent-arm:
export GOOS=linux;export GOARCH=arm;export GOARM=7;go build ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${A} cmd/merlinagent/main.go
# Compile Agent - Linux x64
agent-linux:
export GOOS=linux;export GOARCH=amd64;go build ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${L} cmd/merlinagent/main.go
# Compile PRISM - Linux x64
prism-linux:
export GOOS=linux;export GOARCH=amd64;go build ${LDFLAGS} -o ${DIR}/PRISM-${L} cmd/prism/main.go
# Compile Server - Darwin x64
server-darwin:
export GOOS=darwin;export GOARCH=amd64;go build ${LDFLAGS} -o ${DIR}/${MSERVER}-${D} cmd/merlinserver/main.go
# Compile Agent - Darwin x64
agent-darwin:
export GOOS=darwin;export GOARCH=amd64;go build ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${D} cmd/merlinagent/main.go
# Compile PRISM - Darwin x64
prism-darwin:
export GOOS=darwin;export GOARCH=amd64;go build ${LDFLAGS} -o ${DIR}/PRISM-${D} cmd/prism/main.go
# Update JavaScript Information
agent-javascript:
sed -i 's/var build = ".*"/var build = "${BUILD}"/' data/html/scripts/merlin.js
sed -i 's/var version = ".*"/var version = "${VERSION}"/' data/html/scripts/merlin.js
sed -i 's|var url = ".*"|var url = "${URL}"|' data/html/scripts/merlin.js
# Make directory 'data' and then agents, db, log, x509; Copy src folder, README, and requirements
package-server-windows:
${PACKAGE} ${DIR}/${MSERVER}-${W}.7z ${F}
cd ${DIR};${PACKAGE} ${MSERVER}-${W}.7z ${MSERVER}-${W}.exe
package-server-linux:
${PACKAGE} ${DIR}/${MSERVER}-${L}.7z ${F}
cd ${DIR};${PACKAGE} ${MSERVER}-${L}.7z ${MSERVER}-${L}
package-server-darwin:
${PACKAGE} ${DIR}/${MSERVER}-${D}.7z ${F}
cd ${DIR};${PACKAGE} ${MSERVER}-${D}.7z ${MSERVER}-${D}
package-agent-windows:
${PACKAGE} ${DIR}/${MAGENT}-${W}.7z ${F2}
cd ${DIR};${PACKAGE} ${MAGENT}-${W}.7z ${MAGENT}-${W}.exe
mkdir -p ${BIN}windows
cp ${DIR}/${MAGENT}-${W}.exe ${BIN}windows/
package-agent-linux:
${PACKAGE} ${DIR}/${MAGENT}-${L}.7z ${F2}
cd ${DIR};${PACKAGE} ${MAGENT}-${L}.7z ${MAGENT}-${L}
mkdir -p ${BIN}linux
cp ${DIR}/${MAGENT}-${L} ${BIN}linux/
package-agent-darwin:
${PACKAGE} ${DIR}/${MAGENT}-${D}.7z ${F2}
cd ${DIR};${PACKAGE} ${MAGENT}-${D}.7z ${MAGENT}-${D}
mkdir -p ${BIN}darwin/
cp ${DIR}/${MAGENT}-${D} ${BIN}darwin/
package-agent-dll:
${PACKAGE} ${DIR}/${MAGENT}-DLL.7z ${F2}
cd ${DIR};${PACKAGE} ${MAGENT}-DLL.7z merlin.dll
cp ${DIR}/merlin.dll ${BIN}dll
package-prism-windows:
${PACKAGE} ${DIR}/PRISM-${W}.7z ${F2}
cd ${DIR};${PACKAGE} PRISM-${W}.7z PRISM-${W}.exe
cp ${DIR}/PRISM-${W}.exe ${BIN}windows/
package-prism-linux:
${PACKAGE} ${DIR}/PRISM-${L}.7z ${F2}
cd ${DIR};${PACKAGE} PRISM-${L}.7z PRISM-${L}
cp ${DIR}/PRISM-${L} ${BIN}linux/
package-prism-darwin:
${PACKAGE} ${DIR}/PRISM-${D}.7z ${F2}
cd ${DIR};${PACKAGE} PRISM-${D}.7z PRISM-${D}
cp ${DIR}/PRISM-${D} ${BIN}darwin/
# Package agents and PRISM first so that they can be included in the Server distro
#package-all: package-agent-windows package-agent-dll package-agent-linux package-agent-darwin package-prism-windows package-prism-linux package-prism-darwin package-server-linux package-server-windows package-server-darwin
package-all: package-agent-linux package-agent-darwin package-prism-linux package-prism-darwin package-server-linux package-server-darwin
clean:
rm -rf ${DIR}*
#Build all files for release distribution
distro: clean all package-all
#Create all agents and move them to Merlin's data/bin directory; Used with Docker container
generate-agents: agent-windows agent-dll agent-linux agent-darwin
mkdir -p ${BIN}windows/
cp ${DIR}/${MAGENT}-${W}.exe ${BIN}windows/
mkdir -p ${BIN}dll
cp ${DIR}/merlin.dll ${BIN}dll
mkdir -p ${BIN}linux/
cp ${DIR}/${MAGENT}-${L} ${BIN}linux/
mkdir -p ${BIN}darwin/
cp ${DIR}/${MAGENT}-${D} ${BIN}darwin/