-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
270 lines (234 loc) · 8.38 KB
/
CMakeLists.txt
File metadata and controls
270 lines (234 loc) · 8.38 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
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
cmake_minimum_required(VERSION 3.16)
project(C2Core LANGUAGES CXX)
# --- Use the static MSVC runtime (/MT, /MTd) everywhere on Windows ---
if(MSVC)
# Make CMAKE_MSVC_RUNTIME_LIBRARY authoritative
cmake_policy(SET CMP0091 NEW)
# Use /MT for Release-like configs and /MTd for Debug
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "" FORCE)
# (Optional) clean any /MD that third-parties might have injected into global flags
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_MINSIZEREL)
if(DEFINED ${flag_var})
string(REGEX REPLACE "/MDd" "" ${flag_var} "${${flag_var}}")
string(REGEX REPLACE "/MD" "" ${flag_var} "${${flag_var}}")
endif()
endforeach()
add_compile_definitions(
NOMINMAX # <-- disables Windows min/max macros
)
endif()
# --------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(FetchContent)
# External libraries
FetchContent_Declare(
Dnscommunication
GIT_REPOSITORY https://github.com/maxDcb/Dnscommunication.git
GIT_TAG develop
)
FetchContent_MakeAvailable(Dnscommunication)
set_target_properties(Dnscommunication PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${dnscommunication_SOURCE_DIR}/src>;$<INSTALL_INTERFACE:include>")
FetchContent_Declare(
SocketHandler
GIT_REPOSITORY https://github.com/maxDcb/libSocketHandler.git
GIT_TAG master
)
FetchContent_MakeAvailable(SocketHandler)
set_target_properties(SocketHandler PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${sockethandler_SOURCE_DIR}/src>;$<INSTALL_INTERFACE:include>")
# PipeHandler and MemoryModule have platform-specific sources
if(WIN32)
FetchContent_Declare(
PipeHandler
GIT_REPOSITORY https://github.com/maxDcb/libPipeHandler.git
GIT_TAG master
)
FetchContent_Declare(
MemoryModule
GIT_REPOSITORY https://github.com/maxDcb/MemoryModule.git
GIT_TAG develop
)
else()
FetchContent_Declare(
PipeHandler
GIT_REPOSITORY https://github.com/maxDcb/C2TeamServer.git
GIT_TAG master
SOURCE_SUBDIR libs/libPipeHandlerDumy
)
FetchContent_Declare(
MemoryModule
GIT_REPOSITORY https://github.com/maxDcb/C2TeamServer.git
GIT_TAG master
SOURCE_SUBDIR libs/libMemoryModuleDumy
)
endif()
FetchContent_MakeAvailable(PipeHandler)
FetchContent_MakeAvailable(MemoryModule)
if(WIN32)
set(_pipe_inc ${pipehandler_SOURCE_DIR}/src)
set(_mm_inc ${memorymodule_SOURCE_DIR}/)
else()
set(_pipe_inc ${pipehandler_SOURCE_DIR}/libs/libPipeHandlerDumy/src)
set(_mm_inc ${memorymodule_SOURCE_DIR}/libs/libMemoryModuleDumy/src)
endif()
set_target_properties(PipeHandler PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${_pipe_inc}>;$<INSTALL_INTERFACE:include>")
set_target_properties(MemoryModule PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${_mm_inc}>;$<INSTALL_INTERFACE:include>")
FetchContent_Declare(
SocksServer
GIT_REPOSITORY https://github.com/maxDcb/libSocks5.git
GIT_TAG master
)
FetchContent_MakeAvailable(SocksServer)
set_target_properties(SocksServer PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${socksserver_SOURCE_DIR}/src>;$<INSTALL_INTERFACE:include>")
if(WIN32)
FetchContent_Declare(
CoffPacker
GIT_REPOSITORY https://github.com/maxDcb/COFFPacker.git
GIT_TAG master
)
FetchContent_Declare(
CoffLoader
GIT_REPOSITORY https://github.com/maxDcb/COFFLoader.git
GIT_TAG dev
)
FetchContent_MakeAvailable(CoffPacker CoffLoader)
endif()
# Header-only / source dependencies placed in thirdParty for relative includes
set(BASE64_SRC_DIR ${CMAKE_SOURCE_DIR}/thirdParty/base64)
FetchContent_Declare(
base64
GIT_REPOSITORY https://github.com/ReneNyffenegger/cpp-base64.git
GIT_TAG 82147d6d89636217b870f54ec07ddd3e544d5f69
SOURCE_DIR ${BASE64_SRC_DIR}
)
FetchContent_MakeAvailable(base64)
include_directories(${BASE64_SRC_DIR})
set(DONUT_SRC_DIR ${CMAKE_SOURCE_DIR}/thirdParty/donut)
FetchContent_Declare(
Donut
GIT_REPOSITORY https://github.com/maxDcb/donut.git
GIT_TAG master
SOURCE_DIR ${DONUT_SRC_DIR}
)
FetchContent_MakeAvailable(Donut)
include_directories(${DONUT_SRC_DIR}/include)
if (WIN32)
add_custom_target(donut_build ALL
COMMAND nmake -f Makefile.msvc
WORKING_DIRECTORY ${DONUT_SRC_DIR}
COMMENT "Building donut with nmake / Makefile.msvc"
)
# ---- Import the produced lib / exe ----
add_library(Donut SHARED IMPORTED)
set_target_properties(Donut PROPERTIES
IMPORTED_IMPLIB "${DONUT_SRC_DIR}/lib/donut.lib" # linker uses this
IMPORTED_LOCATION "${DONUT_SRC_DIR}/lib/donut.dll" # runtime DLL
)
set(DONUT_DLL "${DONUT_SRC_DIR}/lib/donut.dll")
set(TEST_DIR "${CMAKE_SOURCE_DIR}/Tests")
add_custom_target(copy_donut ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${DONUT_DLL}"
"${TEST_DIR}/donut.dll"
COMMENT "Copying donut.dll to ${TEST_DIR}"
)
add_dependencies(copy_donut donut_build)
endif (WIN32)
if (UNIX)
add_custom_target(donut_build ALL
COMMAND make -f Makefile
WORKING_DIRECTORY ${DONUT_SRC_DIR}
COMMENT "Building donut with make / Makefile"
)
set(aplib64 "${DONUT_SRC_DIR}/lib/aplib64.a")
add_library(Donut STATIC IMPORTED)
set_target_properties(Donut PROPERTIES
IMPORTED_LOCATION "${DONUT_SRC_DIR}/lib/libdonut.a"
)
endif (UNIX)
# Additional third party libraries
FetchContent_Declare(
httplib
GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
GIT_TAG v0.14.1
)
FetchContent_MakeAvailable(httplib)
FetchContent_Declare(
crow
GIT_REPOSITORY https://github.com/CrowCpp/crow.git
GIT_TAG v1.1.1
)
FetchContent_MakeAvailable(crow)
include_directories(${crow_SOURCE_DIR}/include)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE)
set(BUILD_STATIC_LIBS ON CACHE BOOL "Build static libraries" FORCE)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
add_compile_definitions(LIBSSH2_LIBRARY) # needed for full static lib
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
FetchContent_Declare(
libssh2
GIT_REPOSITORY https://github.com/libssh2/libssh2.git
GIT_TAG libssh2-1.11.1
)
FetchContent_MakeAvailable(libssh2)
find_package(OpenSSL REQUIRED)
add_library(openssl::openssl INTERFACE IMPORTED)
target_link_libraries(openssl::openssl INTERFACE OpenSSL::SSL OpenSSL::Crypto)
add_compile_definitions(CROW_ENABLE_SSL)
# Build tests only when explicitly enabled. Default to ON when C2Core is the
# top-level project and OFF when included from another build.
option(C2CORE_BUILD_TESTS "Build C2Core unit tests" OFF)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(C2CORE_BUILD_TESTS ON CACHE BOOL "Build C2Core unit tests" FORCE)
endif()
if(C2CORE_BUILD_TESTS)
add_definitions(-DBUILD_TESTS)
enable_testing()
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.12.0
)
FetchContent_MakeAvailable(Catch2 nlohmann_json)
include_directories(${nlohmann_json_SOURCE_DIR}/include)
add_subdirectory(beacon/tests)
add_subdirectory(listener/tests)
endif()
add_subdirectory(beacon)
add_subdirectory(modules)
install(
DIRECTORY beacon/ listener/ modules/ModuleCmd/ ${socksserver_SOURCE_DIR}/src/
DESTINATION include
FILES_MATCHING PATTERN "Beacon*.hpp"
PATTERN "Listener*.hpp"
PATTERN "CommonCommand.hpp"
PATTERN "ModuleCmd.hpp"
PATTERN "C2Message.hpp"
PATTERN "Session.hpp"
PATTERN "Common.hpp"
PATTERN "nlohmann/json.hpp"
PATTERN "SocksDef.hpp"
PATTERN "SocksTunnelClient.hpp"
)
include(CMakePackageConfigHelpers)
install(EXPORT C2CoreTargets FILE C2CoreTargets.cmake NAMESPACE "" DESTINATION lib/cmake/C2Core)
configure_package_config_file(
cmake/C2CoreConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/C2CoreConfig.cmake
INSTALL_DESTINATION lib/cmake/C2Core
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/C2CoreConfig.cmake DESTINATION lib/cmake/C2Core)