diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e175e04 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.10) +project(LDPathHackDemo) + +add_subdirectory(real_lib) +add_subdirectory(fake_lib) +add_subdirectory(victim) diff --git a/README.md b/README.md index e69de29..90eedab 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,11 @@ +# 빌드 +mkdir build && cd build +cmake .. +cmake --build . + +# 정상 실행 +./victim/victim + +# 가짜 라이브러리 우선 경로 설정 +mv real_lib/libmylib.so real_lib/libmylib_ +LD_LIBRARY_PATH=./fake_lib ./victim/victim \ No newline at end of file diff --git a/fake_lib/CMakeLists.txt b/fake_lib/CMakeLists.txt new file mode 100644 index 0000000..c5b6d8a --- /dev/null +++ b/fake_lib/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(mylib_fake SHARED mylib.cpp) +set_target_properties(mylib_fake PROPERTIES OUTPUT_NAME mylib) diff --git a/fake_lib/mylib.cpp b/fake_lib/mylib.cpp new file mode 100644 index 0000000..94cbee2 --- /dev/null +++ b/fake_lib/mylib.cpp @@ -0,0 +1,4 @@ +#include +void greet() { + std::cout << "❌ HACKED: This is the fake library!" << std::endl; +} diff --git a/real_lib/CMakeLists.txt b/real_lib/CMakeLists.txt new file mode 100644 index 0000000..08be752 --- /dev/null +++ b/real_lib/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(mylib SHARED mylib.cpp) +set_target_properties(mylib PROPERTIES OUTPUT_NAME mylib) \ No newline at end of file diff --git a/real_lib/mylib.cpp b/real_lib/mylib.cpp new file mode 100644 index 0000000..4588ccc --- /dev/null +++ b/real_lib/mylib.cpp @@ -0,0 +1,4 @@ +#include +void greet() { + std::cout << "✅ Hello from the real library!" << std::endl; +} \ No newline at end of file diff --git a/victim/CMakeLists.txt b/victim/CMakeLists.txt new file mode 100644 index 0000000..a65c4b9 --- /dev/null +++ b/victim/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(victim main.cpp) +target_include_directories(victim PRIVATE ${CMAKE_SOURCE_DIR}/victim) +target_link_libraries(victim PRIVATE mylib) diff --git a/victim/main.cpp b/victim/main.cpp new file mode 100644 index 0000000..bc6f7d4 --- /dev/null +++ b/victim/main.cpp @@ -0,0 +1,6 @@ +#include "mylib.h" + +int main() { + greet(); + return 0; +} diff --git a/victim/mylib.h b/victim/mylib.h new file mode 100644 index 0000000..66f5e6e --- /dev/null +++ b/victim/mylib.h @@ -0,0 +1,2 @@ +#pragma once +void greet();