-
Notifications
You must be signed in to change notification settings - Fork 77
/
Makefile.in
292 lines (253 loc) · 14.5 KB
/
Makefile.in
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# SPADE - Support for Provenance Auditing in Distributed Environments.
# Copyright (C) 2015 SRI International.
JAVAC=@JAVAC@
CC=@CC@
JAR=@JAR@
JAVAC_CP = $(shell ./bin/classpath.sh)
JAVAC_OPTIONS =$(EXTRA_JAVAC_OPTIONS) -Xlint:none -proc:none
ANDROID_BUILD_TOOLS = @ANDROID_BUILD_TOOLS@
ANDROID_SDK_TOOLS = @ANDROID_SDK_TOOLS@
AUDIT_KERNEL_MODULES_MAKEFILE = src/spade/reporter/audit/kernel-modules/Makefile
#
# In Ubuntu, when you install llvm headers, it puts llvm and llvm-c inside version folder.
# sudo ln -s llvm-3.6/llvm/ llvm
# sudo ln -s llvm-c-3.6/llvm-c/ llvm-c
#
LLVM_INCLUDE_PATH=/usr/include/llvm-3.6/
LLVM_PATH = /var/clang+llvm-3.0-x86_64-apple-darwin11
# LLVM_TARGET = nweb
# System and architecture-specific configuration
OS_NAME = $(shell uname)
OS_ARCH = $(shell uname -m)
OS_KERNEL_RELEASE = $(shell uname -r)
OS_KERNEL_MAJOR = $(shell uname -r | cut -d '.' -f 1)
OS_KERNEL_MINOR = $(shell uname -r | cut -d '.' -f 2 | xargs printf "%02d")
OS_KERNEL_NUMBER = $(OS_KERNEL_MAJOR)$(OS_KERNEL_MINOR)
MAX_OS_KERNEL_NUMBER = 507
ifeq ($(OS_NAME), Darwin)
OS_BUILD = build-openbsm
NO_FUSE = $(shell pkg-config fuse; echo $$?)
ifeq (0, $(NO_FUSE))
OS_BUILD += build-macfuse
endif
OS_CONFIG_PATH = /usr/local/lib/pkgconfig
REPLIB_OSFLAG = -D_LLVMREPORTER_MACOSX
LLVM_RULE = build-mac-llvm
endif
ifeq ($(OS_NAME), Linux)
OS_BUILD = build-linuxaudit
NO_FUSE = $(shell pkg-config fuse; echo $$?)
ifeq (0, $(NO_FUSE))
OS_BUILD += build-linuxfuse
endif
OS_CONFIG_PATH = /usr/lib/pkgconfig
REPLIB_OSFLAG = -D_LLVMREPORTER_LINUX
LLVM_RULE = build-linux-llvm
endif
# kernel modules build default = false
ifndef KERNEL_MODULES
KERNEL_MODULES = false
endif
# -------- Default Build Configuration -----
REPORTERS = Graphviz DSL Network LLVM Facebook Bitcoin StraceLinux JSON CDM CamFlow ProcMon
# -------------------------------------------
.PHONY: build prepare-dirs core reporters filters query analyzers clients utilities storages screens android-build
all: build
./bin/keys/generatekeys.sh
help:
@echo 'Usage:'
@echo ' make - to compile the code'
@echo ' make clean - to remove the compiled code'
@echo ' '
# ---------- Building SPADE ----------
.SECONDEXPANSION:
build: | prepare-dirs
build: build-java $$(OS_BUILD) lib/spade.jar
# No sketches at the moment available
#build-java: download-neo4j core clients utilities storages filters query analyzers sketches transformers reporters
build-java: download-neo4j core clients utilities storages screens filters query analyzers transformers reporters
download-neo4j:
@bin/downloadNeo4j
.SUFFIXES : .class .java
prepare-dirs:
mkdir -p build
mkdir -p db/scaffold
mkdir -p tmp
build/%.class : src/%.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build $<
core:
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/core/*.java
@echo "--- Built Core ---"
clients:
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/client/*.java
@echo "--- Built Clients ---"
reporters: $$(foreach f,$$(REPORTERS), build/spade/reporter/$$(f).class )
@echo "--- Built Reporters ---"
query:
mkdir -p tmp
find src/spade/query -name "*.java" > tmp/query.classes
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build @tmp/query.classes
rm tmp/query.classes
@echo "--- Built Queries ---"
analyzers:
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/analyzer/*.java
@echo "--- Built Analyzers ---"
storages:
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/storage/*.java
@echo "--- Built Storages ---"
screens:
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/screen/*.java
@echo "--- Built Screens ---"
utilities:
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/profile/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/map/external/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/map/external/cache/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/map/external/screen/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/map/external/store/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/map/external/store/db/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/map/external/store/db/berkeleydb/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/map/external/store/db/leveldb/*.java
@echo "--- Built Utilities ---"
filters:
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/filter/*.java
@echo "--- Built Filters ---"
sketches:
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/sketch/*.java
@echo "--- Built Sketches ---"
transformers:
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/transformer/*.java
@echo "--- Built Transformers ---"
lib/spade.jar: build-java $$(OS_BUILD)
$(JAR) cvf lib/spade.jar -C build .
# Build the LinuxAudit reporter.
build-linuxaudit: build/spade/reporter/Audit.class bin/spadeAuditBridge audit-kernel-module
@echo '-----> IMPORTANT: To use the LinuxAudit reporter, please run the following commands to allow SPADE access to the audit stream:'
@echo '-----> sudo chown root bin/spadeAuditBridge'
@echo '-----> sudo chmod ug+s bin/spadeAuditBridge'
@echo ''
bin/spadeAuditBridge: src/spade/reporter/spadeAuditBridge.c
gcc -o bin/spadeAuditBridge src/spade/reporter/spadeAuditBridge.c
audit-kernel-module:
@if [ "$(findstring Microsoft, $(OS_KERNEL_RELEASE))" = "" ]; then \
if [ "$(KERNEL_MODULES)" = "true" ]; then \
if [ -z "$(OS_KERNEL_NUMBER)" ]; then \
echo 'ERROR: Kernel modules build failed. Failed to get current kernel release number.'; \
exit 1; \
else \
if [ $(OS_KERNEL_NUMBER) -ge $(MAX_OS_KERNEL_NUMBER) ]; then \
echo 'Warning: Kernel version > 5.7 uses workaround from https://github.com/xcellerator/linux_kernel_hacking/issues/3#issue-782815541 by hkerma'; \
else \
echo 'Building kernel modules normally'; \
fi; \
$(MAKE) --no-print-directory -f $(AUDIT_KERNEL_MODULES_MAKEFILE); \
fi \
else \
$(MAKE) --no-print-directory -f $(AUDIT_KERNEL_MODULES_MAKEFILE) clean; \
fi \
else \
echo 'Skipped kernel modules. OS Kernel not supported'; \
fi
# Build the LinuxFUSE reporter.
build-linuxfuse: src/spade/reporter/spade_reporter_LinuxFUSE.h lib/libLinuxFUSE.so
@echo ''
@echo '-----> IMPORTANT: To use the LinuxFUSE reporter, please enable "user_allow_other" in /etc/fuse.conf'
@echo ''
src/spade/reporter/spade_reporter_LinuxFUSE.h: build/spade/reporter/LinuxFUSE.class
$(JAVAC) -classpath 'build:lib/*' -h src/spade/reporter src/spade/reporter/LinuxFUSE.java
lib/libLinuxFUSE.so: src/spade/reporter/libLinuxFUSE.c utilities
export PKG_CONFIG_PATH=$(OS_CONFIG_PATH);\
gcc -fPIC -shared -Wl,-soname,libLinuxFUSE.so -I$(shell java -classpath build spade.utility.JavaHome) -I$(shell java -classpath build spade.utility.JavaHome)/linux -Wall src/spade/reporter/libLinuxFUSE.c `pkg-config fuse --cflags --libs` -o lib/libLinuxFUSE.so
# Build the OpenBSM reporter.
build-openbsm: build/spade/reporter/OpenBSM.class src/spade/reporter/spadeOpenBSM.c lib/spadeOpenBSM
@echo '-----> IMPORTANT: To use the OpenBSM reporter, please run the following commands to allow SPADE access to the audit stream:'
@echo '-----> sudo chown root lib/spadeOpenBSM'
@echo '-----> sudo chmod ug+s lib/spadeOpenBSM'
@echo ''
lib/spadeOpenBSM: src/spade/reporter/spadeOpenBSM.c
gcc -o lib/spadeOpenBSM -lbsm src/spade/reporter/spadeOpenBSM.c
# Build the MacFUSE reporter.
build-macfuse: build/spade/reporter/MacFUSE.class src/spade/reporter/MacFUSE.java src/spade/reporter/libMacFUSE.c
$(JAVAC) -classpath 'build:lib/*' -h src/spade/reporter src/spade/reporter/MacFUSE.java
gcc -dynamiclib -I$(shell java -classpath build spade.utility.JavaHome) -I$(shell java -classpath build spade.utility.JavaHome)/darwin src/spade/reporter/libMacFUSE.c `pkg-config fuse --cflags --libs` -o lib/libMacFUSE.jnilib
llvm:
@make $(LLVM_RULE)
build-mac-llvm:
$(eval CXX_FLAGS = $(shell $(LLVM_PATH)/bin/llvm-config --cxxflags))
$(eval C_FLAGS = $(shell $(LLVM_PATH)/bin/llvm-config --cflags))
$(eval CLANG_FLAGS = -cc1 -triple x86_64-apple-macosx10.6.8 -emit-obj -mrelax-all -disable-free ${C_FLAGS})
$(eval CLANG++_FLAGS = ${CXX_FLAGS} -m64 -Wl,-flat_namespace -Wl,-undefined,suppress -dynamiclib -mmacosx-version-min=10.6)
$(LLVM_PATH)/bin/clang ${CLANG_FLAGS} -g -o src/spade/reporter/llvmTracer.o -x c++ src/spade/reporter/llvmTracer.cpp
$(LLVM_PATH)/bin/clang ${CLANG++_FLAGS} -o lib/llvmTracer.dylib src/spade/reporter/llvmTracer.o
$(LLVM_PATH)/bin/clang -static ${REPLIB_OSFLAG} src/spade/reporter/llvmBridge.c -c -o src/spade/reporter/llvmBridge.o
$(LLVM_PATH)/bin/clang -c -emit-llvm ${TARGET}.c -o ${LLVM_TARGET}.bc
$(LLVM_PATH)/bin/opt -load lib/llvmTracer.dylib -provenance ${LLVM_TARGET}.bc -o ${LLVM_TARGET}.bc
$(LLVM_PATH)/bin/llc ${LLVM_TARGET}.bc -o ${LLVM_TARGET}.s
$(LLVM_PATH)/bin/clang src/spade/reporter/llvmClose.c -c -o src/spade/reporter/llvmClose.o
$(LLVM_PATH)/bin/clang ${LLVM_TARGET}.s src/spade/reporter/llvmClose.o -dynamiclib -Wl,-flat_namespace -Wl,-undefined,suppress -o ${LLVM_TARGET}.dylib
$(LLVM_PATH)/bin/clang src/spade/reporter/llvmBridge.o ${LLVM_TARGET}.dylib -o ${LLVM_TARGET}
build-linux-llvm:
echo llvm[0]: "Compiling llvmTracer.cpp for Release+Asserts build" "(PIC)"
clang++ -I$(LLVM_INCLUDE_PATH) -I./ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -fomit-frame-pointer -std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC -ffunction-sections -fdata-sections -Wcast-qual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcovered-switch-default -Wno-uninitialized -Wno-missing-field-initializers -Wno-comment -c -MMD -MP -MF "llvmTracer.d.tmp" -MT "llvmTracer.o" -MT "llvmTracer.d" src/spade/reporter/llvm/llvmTracer.cpp -o src/spade/reporter/llvm/llvmTracer.o ; \
echo llvm[0]: Linking "Loadable Module" \
LLVMTrace.so
clang++ -O3 -Wl,-R -Wl,'$ORIGIN' -Wl,--gc-sections -rdynamic -L./ -L./ -shared -o bin/llvm/LLVMTrace.so src/spade/reporter/llvm/llvmTracer.o -lpthread -ltinfo -ldl -lm
clang -emit-llvm -c src/spade/reporter/llvm/flushModule.c -o bin/llvm/flush.bc
echo llvm[0]: "Compiling WrapperPass.cpp for Release+Asserts build" "(PIC)"
clang++ -I$(LLVM_INCLUDE_PATH) -I./ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -fomit-frame-pointer -std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC -ffunction-sections -fdata-sections -Wcast-qual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcovered-switch-default -Wno-uninitialized -Wno-missing-field-initializers -Wno-comment -c -MMD -MP -MT "WrapperPass.o" src/spade/reporter/llvm/LibcWrapper.cpp -o src/spade/reporter/llvm/LibcWrapper.o ;
echo llvm[0]: Linking "Loadable Module build/WrapperPass.so"
clang++ -O3 -Wl,-R -Wl,'$ORIGIN' -Wl,--gc-sections -rdynamic -L./ -Lm./ -shared -o bin/llvm/LibcWrapper.so \
src/spade/reporter/llvm/LibcWrapper.o -lpthread -ltinfo -ldl -lm
# Build for Android
android-build:
@mkdir -p build;
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/client/Android.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/core/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/utility/*.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/filter/IORuns.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/storage/Graphviz.java
$(JAVAC) $(JAVAC_OPTIONS) -cp '$(JAVAC_CP)' -sourcepath src -d build src/spade/reporter/Strace.java
# @mkdir -p android-lib;
# $(ANDROID_BUILD_TOOLS)/dx --dex --output=android-lib/lucene-core-3.5.0.jar lib/lucene-core-3.5.0.jar
@mkdir -p android-build;
echo "dalvikvm -cp android-spade.jar spade.client.Android" > android-build/control.sh
@cd build; \
$(ANDROID_BUILD_TOOLS)/dx --dex --verbose --no-strict --output=../android-build/android-spade.jar spade;
# Deploy to Android
android-start:
$(ANDROID_SDK_TOOLS)/adb shell start
$(ANDROID_SDK_TOOLS)/adb shell "rm -r /sdcard/spade"
$(ANDROID_SDK_TOOLS)/adb shell "mkdir /sdcard/spade"
$(ANDROID_SDK_TOOLS)/adb shell "mkdir /sdcard/spade/log"
$(ANDROID_SDK_TOOLS)/adb shell "mkdir /sdcard/spade/conf"
# $(ANDROID_SDK_TOOLS)/adb shell "mkdir /sdcard/spade/android-lib"
# $(ANDROID_SDK_TOOLS)/adb shell "mkdir /sdcard/spade/android-build"
$(ANDROID_SDK_TOOLS)/adb shell "echo -e \"filter IORuns 0\\nstorage Graphviz /sdcard/spade/audit.dot\\nreporter Strace name=zygote user=radio user=system !name=/system/bin/surfaceflinger\" > /sdcard/spade/conf/spade.config"
# @for f in "android-build" "android-lib"; do $(ANDROID_SDK_TOOLS)/adb push $$f /sdcard/spade/$$f; done;
$(ANDROID_SDK_TOOLS)/adb push android-build/android-spade.jar /sdcard/spade/android-spade.jar;
$(ANDROID_SDK_TOOLS)/adb push android-build/control.sh /sdcard/spade/control.sh;
# $(ANDROID_SDK_TOOLS)/adb shell "cd /sdcard/spade/android-build; dalvikvm -Xmx512M -cp android-spade.jar spade.core.Kernel android"
$(ANDROID_SDK_TOOLS)/adb shell "cd /sdcard/spade; dalvikvm -Xmx512M -cp android-spade.jar spade.core.Kernel android"
android-stop:
# $(ANDROID_SDK_TOOLS)/adb shell "cd /sdcard/spade/android-build; dalvikvm -cp android-spade.jar spade.client.Android shutdown"
$(ANDROID_SDK_TOOLS)/adb shell "cd /sdcard/spade; dalvikvm -cp android-spade.jar spade.client.Android shutdown"
graph-utility:
java -cp 'build:lib/*' spade.utility.GraphUtility
# ---------- Removing files ----------
# Remove Java classes and native libraries, executables that we compiled.
clean:
@echo 'Removing Java classes, native libraries, executables...'
@rm -rf build android-build android-lib
@rm -rf src/spade/reporter/spade_reporter_LinuxFUSE.h lib/libLinuxFUSE.* lib/libMacFUSE.*
@rm -rf lib/spade.jar
@rm -rf lib/spadeOpenBSM lib/spadeAuditBridge
@rm -rf cfg/ssl
@rm -rf log
@rm -rf tmp
@$(MAKE) --no-print-directory -f $(AUDIT_KERNEL_MODULES_MAKEFILE) clean
DESTDIR = @prefix@
install:
test -d $(DESTDIR) || mkdir $(DESTDIR)
cp -R bin $(DESTDIR)
cp -R lib $(DESTDIR)
cp -R cfg $(DESTDIR)