This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
/
Makefile
159 lines (122 loc) · 5.12 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
# Used by 'install' target. Change this to wherever your framework checkout is.
# Doesn't have to be development. Should point to the base directory where
# msfconsole lives.
framework_dir = ../metasploit-framework/
# Change me if you want to build openssl and libpcap somewhere else
build_tmp = posix-meterp-build-tmp
cwd=$(shell pwd)
ROOT=$(basename $(CURDIR:%/=%))
BIONIC=$(ROOT)/source/bionic
LIBC=$(BIONIC)/libc
LIBM=$(BIONIC)/libm
COMPILED=$(BIONIC)/compiled
objects = $(COMPILED)/libc.so
objects += $(COMPILED)/libm.so
objects += $(COMPILED)/libdl.so
objects += $(COMPILED)/libcrypto.so
objects += $(COMPILED)/libssl.so
objects += $(COMPILED)/libsupport.so
objects += $(COMPILED)/libmetsrv_main.so
objects += $(COMPILED)/libpcap.so
outputs = data/meterpreter/msflinker_linux_x86.bin
outputs += data/meterpreter/ext_server_stdapi.lso
outputs += data/meterpreter/ext_server_sniffer.lso
outputs += data/meterpreter/ext_server_networkpug.lso
STD_CFLAGS = -Os -m32 -march=i386 -fno-stack-protector
STD_CFLAGS += -Wl,--hash-style=sysv
STD_CFLAGS += -lc -lm -nostdinc -nostdlib -fno-builtin -fPIC -DPIC
STD_CFLAGS += -Dwchar_t='char' -D_SIZE_T_DECLARED -DElf_Size='u_int32_t'
STD_CFLAGS += -D_BYTE_ORDER=_LITTLE_ENDIAN -D_UNIX -D__linux__ -lgcc
STD_CFLAGS += -I$(LIBC)/include
STD_CFLAGS += -I$(LIBC)/kernel/common/linux/
STD_CFLAGS += -I$(LIBC)/kernel/common/
STD_CFLAGS += -I$(LIBC)/arch-x86/include/
STD_CFLAGS += -I$(LIBC)/kernel/arch-x86/
STD_CFLAGS += -L$(COMPILED)
GCCGOLD = $(shell (echo "int main(){}" | gcc -fuse-ld=gold -o/dev/null -xc -); echo $$?)
ifeq "$(GCCGOLD)" "0"
STD_CFLAGS += -fuse-ld=gold
endif
PCAP_CFLAGS = $(STD_CFLAGS)
OSSL_CFLAGS = $(STD_CFLAGS) -I$(LIBC)/private -I$(LIBM)/include
workspace = workspace
all: $(objects) $(outputs)
include deps/libressl/Makefile
include deps/libpcap/Makefile
debug: DEBUG=true
# I'm 99% sure this is the wrong way to do this
debug: MAKE += debug
debug: all
$(COMPILED):
mkdir $(COMPILED)/
$(COMPILED)/libc.so: $(COMPILED)
@echo Building libc
@(cd source/bionic/libc && ARCH=x86 TOP=${ROOT} jam > build.log 2>&1 )
@(cd source/bionic/libc/out/x86/ && $(MAKE) -f Makefile.msf >> build.log 2>&1 && [ -f libbionic.so ])
@cp source/bionic/libc/out/x86/libbionic.so $(COMPILED)/libc.so
$(COMPILED)/libm.so:
@echo Building libm
@$(MAKE) -C $(LIBM) -f Makefile.msf > build.log 2>&1 && [ -f $(LIBM)/libm.so ]
@cp $(LIBM)/libm.so $(COMPILED)/libm.so
$(COMPILED)/libdl.so:
@echo Building libdl
@$(MAKE) -C $(BIONIC)/libdl > build.log && [ -f $(BIONIC)/libdl/libdl.so ]
@cp $(BIONIC)/libdl/libdl.so $(COMPILED)/libdl.so
data/meterpreter/msflinker_linux_x86.bin: source/server/rtld/msflinker.bin
cp source/server/rtld/msflinker.bin data/meterpreter/msflinker_linux_x86.bin
source/server/rtld/msflinker.bin: $(COMPILED)/libc.so \
$(wildcard source/server/*.h) \
$(wildcard source/server/*.c)
$(MAKE) -C source/server/rtld
$(workspace)/metsrv/libmetsrv_main.so: $(COMPILED)/libsupport.so \
$(wildcard source/server/*.h) \
$(wildcard source/server/*.c)
$(MAKE) -C $(workspace)/metsrv
$(COMPILED)/libmetsrv_main.so: $(workspace)/metsrv/libmetsrv_main.so
cp $(workspace)/metsrv/libmetsrv_main.so $(COMPILED)/libmetsrv_main.so
$(workspace)/common/libsupport.so: \
$(wildcard source/common/*.h) \
$(wildcard source/common/*.c)
$(MAKE) -C $(workspace)/common
$(COMPILED)/libsupport.so: $(workspace)/common/libsupport.so
cp $(workspace)/common/libsupport.so $(COMPILED)/libsupport.so
$(workspace)/ext_server_sniffer/ext_server_sniffer.so: \
$(wildcard source/extensions/sniffer/*.h) \
$(wildcard source/extensions/sniffer/*.c) \
$(COMPILED)/libpcap.so
$(MAKE) -C $(workspace)/ext_server_sniffer
data/meterpreter/ext_server_sniffer.lso: \
$(workspace)/ext_server_sniffer/ext_server_sniffer.so
cp $(workspace)/ext_server_sniffer/ext_server_sniffer.so \
data/meterpreter/ext_server_sniffer.lso
$(workspace)/ext_server_stdapi/ext_server_stdapi.so: \
$(wildcard source/extensions/stdapi/*.h) \
$(wildcard source/extensions/stdapi/*.c)
$(MAKE) -C $(workspace)/ext_server_stdapi
data/meterpreter/ext_server_stdapi.lso: \
$(workspace)/ext_server_stdapi/ext_server_stdapi.so
cp $(workspace)/ext_server_stdapi/ext_server_stdapi.so \
data/meterpreter/ext_server_stdapi.lso
$(workspace)/ext_server_networkpug/ext_server_networkpug.so: \
$(wildcard source/extensions/networkpug/*.h) \
$(wildcard source/extensions/networkpug/*.c)
$(MAKE) -C $(workspace)/ext_server_networkpug
data/meterpreter/ext_server_networkpug.lso: \
$(workspace)/ext_server_networkpug/ext_server_networkpug.so
cp $(workspace)/ext_server_networkpug/ext_server_networkpug.so \
data/meterpreter/ext_server_networkpug.lso
install: $(outputs)
cp $(outputs) $(framework_dir)/data/meterpreter/
clean:
rm -f $(objects)
make -C source/server/rtld/ clean
make -C $(workspace) clean
depclean:
rm -f source/bionic/lib*/*.o
find source/bionic/ -name '*.a' -print0 | xargs -0 rm -f 2>/dev/null
find source/bionic/ -name '*.so' -print0 | xargs -0 rm -f 2>/dev/null
find . -name 'build.log' | xargs rm -f
rm -f source/bionic/lib*/*.so
really-clean: clean clean-ssl clean-pcap depclean
distclean: really-clean
.PHONY: clean clean-ssl clean-pcap really-clean debug