-
Notifications
You must be signed in to change notification settings - Fork 57
/
Makefile
175 lines (144 loc) · 6.97 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
# !!!MAKE SURE YOUR GOPATH ENVIRONMENT VARIABLE IS SET FIRST!!!
# Agent file names
W=Windows-x64
L=Linux-x64
B=FreeBSD-x64
A=Linux-arm
M=Linux-mips
D=Darwin-x64
# Merlin version number
VERSION=$(shell cat ./core/core.go |grep "var Version ="|cut -d"\"" -f2)
MAGENT=merlinAgent
PASSWORD=merlin
BUILD=$(shell git rev-parse HEAD)
DIR=bin/v${VERSION}/${BUILD}
# http - Include the HTTP client (including HTTP/1.1, HTTP/2, and HTTP/3)
# http1 - Include the HTTP/1.1 client from Go's standard library
# http2 - Include the HTTP/2 client
# http3 - Include the HTTP/3 client
# smb - Include the peer-to-peer SMB client
# tcp - Include the peer-to-peer TCP client
# udp - Include the peer-to-peer UDP client
# winhttp - Include the Windows HTTP client
TAGS ?=
# Merlin Agent Variables
XBUILD=-X "github.com/Ne0nd0g/merlin-agent/v2/core.Build=${BUILD}"
URL ?= https://127.0.0.1:443
XURL=-X "main.url=${URL}"
PSK ?= merlin
XPSK=-X "main.psk=${PSK}"
PROXY ?=
XPROXY =-X "main.proxy=$(PROXY)"
SLEEP ?= 30s
XSLEEP =-X "main.sleep=$(SLEEP)"
HOST ?=
XHOST =-X "main.host=$(HOST)"
PROTO ?= h2
XPROTO =-X "main.protocol=$(PROTO)"
JA3 ?=
XJA3 =-X "main.ja3=$(JA3)"
USERAGENT = Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.85 Safari/537.36
XUSERAGENT =-X "main.useragent=$(USERAGENT)"
HEADERS =
XHEADERS =-X "main.headers=$(HEADERS)"
SECURE ?= false
HTTPCLIENT ?= go
XHTTPCLIENT =-X "main.httpClient=$(HTTPCLIENT)"
XSECURE =-X "main.secure=${SECURE}"
SKEW ?= 3000
XSKEW=-X "main.skew=${SKEW}"
PAD ?= 4096
XPAD=-X "main.padding=${PAD}"
KILLDATE ?= 0
XKILLDATE=-X "main.killdate=${KILLDATE}"
RETRY ?= 7
XRETRY=-X "main.maxretry=${RETRY}"
PARROT ?=
XPARROT=-X "main.parrot=${PARROT}"
AUTH ?= opaque
XAUTH=-X "main.auth=${AUTH}"
ADDR ?= 127.0.0.1:4444
XADDR=-X "main.addr=${ADDR}"
TRANSFORMS ?= jwe,gob-base
XTRANSFORMS=-X "main.transforms=${TRANSFORMS}"
LISTENER ?=
XLISTENER=-X "main.listener=${LISTENER}"
# Compile Flags
LDFLAGS=-ldflags '-s -w ${XADDR} ${XAUTH} ${XTRANSFORMS} ${XLISTENER} ${XBUILD} ${XPROTO} ${XURL} ${XHOST} ${XHTTPCLIENT} ${XPSK} ${XSECURE} ${XSLEEP} ${XPROXY} $(XUSERAGENT) $(XHEADERS) ${XSKEW} ${XPAD} ${XKILLDATE} ${XRETRY} ${XPARROT} -buildid='
WINAGENTLDFLAGS=-ldflags '-s -w ${XAUTH} ${XADDR} ${XTRANSFORMS} ${XLISTENER} ${XBUILD} ${XPROTO} ${XURL} ${XHOST} ${XHTTPCLIENT} ${XPSK} ${XSECURE} ${XSLEEP} ${XPROXY} $(XUSERAGENT) $(XHEADERS) ${XSKEW} ${XPAD} ${XKILLDATE} ${XRETRY} ${XPARROT} -H=windowsgui -buildid='
GCFLAGS=-gcflags=all=-trimpath=$(GOPATH)
ASMFLAGS=-asmflags=all=-trimpath=$(GOPATH)# -asmflags=-trimpath=$(GOPATH)
# Package Command
PACKAGE=7za a -p${PASSWORD} -mhe -mx=9
F=LICENSE
# Misc
# The Merlin server and agent MUST be built with the same seed value
# Set during build with "make linux-garble SEED=<insert seed>
SEED=d0d03a0ae4722535a0e1d5d0c8385ce42015511e68d960fadef4b4eaf5942feb
# 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:
go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT} ./main.go
all: windows windows-debug linux darwin
# Compile Agent - Windows x64
windows:
export GOOS=windows GOARCH=amd64;go build -tags ${TAGS} -trimpath ${WINAGENTLDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${W}.exe ./main.go
# Compile Agent - Windows x64 Debug (Can view STDOUT)
windows-debug:
export GOOS=windows GOARCH=amd64;go build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${W}-Debug.exe ./main.go
# Compile Agent - Windows x64 with Garble - The SEED must be the exact same that was used when compiling the server
# Garble version 0.5.2 or later must be installed and accessible in the PATH environment variable
windows-garble:
export GOGARBLE=${GOGARBLE};export GOOS=windows GOARCH=amd64;garble -tiny -literals -seed ${SEED} build -tags ${TAGS} -trimpath ${WINAGENTLDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${W}.exe ./main.go
windows-garble-debug:
export GOOS=windows GOARCH=amd64;garble -tiny -literals -seed ${SEED} build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${W}-Debug.exe ./main.go
# Compile Agent - Linux mips
mips:
export GOOS=linux;export GOARCH=mips;go build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${M} ./main.go
# Compile Agent - Linux arm
arm:
export GOOS=linux;export GOARCH=arm;export GOARM=7;go build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${A} ./main.go
# Compile Agent - Linux x64
linux:
export GOOS=linux;export GOARCH=amd64;go build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${L} ./main.go
# Compile Agent - Linux x64 with Garble - The SEED must be the exact same that was used when compiling the server
# Garble version 0.5.2 or later must be installed and accessible in the PATH environment variable
linux-garble:
export GOOS=linux GOARCH=amd64;garble -tiny -literals -seed ${SEED} build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${L} ./main.go
# Compile Agent - FreeBSD x64
freebsd:
export GOOS=freebsd;export GOARCH=amd64;go build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${B} ./main.go
# Compile Agent - FreeBSD x64 with Garble - The SEED must be the exact same that was used when compiling the server
# Garble version 0.5.2 or later must be installed and accessible in the PATH environment variable
freebsd-garble:
export GOOS=freebsd GOARCH=amd64;garble -tiny -literals -seed ${SEED} build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${B} ./main.go
# Compile Agent - Darwin x64
darwin:
export GOOS=darwin;export GOARCH=amd64;go build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${D} ./main.go
# Compile Agent - macOS (Darwin) x64 with Garble - The SEED must be the exact same that was used when compiling the server
# Garble version 0.5.2 or later must be installed and accessible in the PATH environment variable
darwin-garble:
export GOOS=darwin GOARCH=amd64;garble -tiny -literals -seed ${SEED} build -tags ${TAGS} -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/${MAGENT}-${D} ./main.go
package-windows:
${PACKAGE} ${DIR}/${MAGENT}-${W}.7z ${F}
cd ${DIR};${PACKAGE} ${MAGENT}-${W}.7z ${MAGENT}-${W}.exe
package-windows-debug:
${PACKAGE} ${DIR}/${MAGENT}-${W}-Debug.7z ${F}
cd ${DIR};${PACKAGE} ${MAGENT}-${W}-Debug.7z ${MAGENT}-${W}-Debug.exe
package-linux:
${PACKAGE} ${DIR}/${MAGENT}-${L}.7z ${F}
cd ${DIR};${PACKAGE} ${MAGENT}-${L}.7z ${MAGENT}-${L}
package-darwin:
${PACKAGE} ${DIR}/${MAGENT}-${D}.7z ${F}
cd ${DIR};${PACKAGE} ${MAGENT}-${D}.7z ${MAGENT}-${D}
package-freebsd:
${PACKAGE} ${DIR}/${MAGENT}-${B}.7z ${F}
cd ${DIR};${PACKAGE} ${MAGENT}-${B}.7z ${MAGENT}-${D}
package-move:
cp ${DIR}/${MAGENT}*.7z .
clean:
rm -rf ${DIR}*
package-all: package-windows package-windows-debug package-linux package-darwin
#Build all files for release distribution
distro: clean all package-all package-move