feat : implment

This commit is contained in:
rinechran 2025-06-03 12:57:39 +09:00
parent bfbfc4ea29
commit d7753b7256
9 changed files with 40 additions and 0 deletions

6
CMakeLists.txt Normal file
View file

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(LDPathHackDemo)
add_subdirectory(real_lib)
add_subdirectory(fake_lib)
add_subdirectory(victim)

View file

@ -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

2
fake_lib/CMakeLists.txt Normal file
View file

@ -0,0 +1,2 @@
add_library(mylib_fake SHARED mylib.cpp)
set_target_properties(mylib_fake PROPERTIES OUTPUT_NAME mylib)

4
fake_lib/mylib.cpp Normal file
View file

@ -0,0 +1,4 @@
#include <iostream>
void greet() {
std::cout << "❌ HACKED: This is the fake library!" << std::endl;
}

2
real_lib/CMakeLists.txt Normal file
View file

@ -0,0 +1,2 @@
add_library(mylib SHARED mylib.cpp)
set_target_properties(mylib PROPERTIES OUTPUT_NAME mylib)

4
real_lib/mylib.cpp Normal file
View file

@ -0,0 +1,4 @@
#include <iostream>
void greet() {
std::cout << "✅ Hello from the real library!" << std::endl;
}

3
victim/CMakeLists.txt Normal file
View file

@ -0,0 +1,3 @@
add_executable(victim main.cpp)
target_include_directories(victim PRIVATE ${CMAKE_SOURCE_DIR}/victim)
target_link_libraries(victim PRIVATE mylib)

6
victim/main.cpp Normal file
View file

@ -0,0 +1,6 @@
#include "mylib.h"
int main() {
greet();
return 0;
}

2
victim/mylib.h Normal file
View file

@ -0,0 +1,2 @@
#pragma once
void greet();