Codebase list hotpatch / 5bf4cb7
New upstream snapshot. Kali Janitor 2 years ago
7 changed file(s) with 54 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
0 *.swp
1 build
2 tags
3 TAGS
4 TODO
5 todo
6 Debug
7 Release
8 *.tgz
9 *.tar.gz
3030
3131 option(DEBUG "In Debug mode" ON)
3232 option(USE_ASM "Use Assembler" OFF)
33 option(BUILD_HOTPATCHER "Build hotpatcher" ON)
34 option(BUILD_TESTS "Build tests" ON)
3335 if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
3436 set(DEBUG OFF)
3537 endif (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
145147 include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
146148 add_subdirectory(include)
147149 add_subdirectory(src)
148 add_subdirectory(test)
150 if (BUILD_TESTS)
151 add_subdirectory(test)
152 endif (BUILD_TESTS)
2828 ###
2929 CMAKE=$(shell which cmake)
3030 CTEST=$(shell which ctest)
31 PREFIX?=/usr
31 PREFIX?=/usr/local
3232 ARCH=$(shell uname -m)
3333
3434 default: release
5353 Another limitation is that injection for a particular .so file can happen only
5454 once in the target process. Each library that is injected can be injected only
5555 once into the target process.
56
57
58 Ubuntu Ptrace()
59 ===============
60
61 On Ubuntu, `ptrace()` of non-child processes has been blocked as a security
62 feature. To get around it you will need to set
63 `/proc/sys/kernel/yama/ptrace_scope` to 0 as below
64
65
66 bash> echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
67
68
5669
5770 Usage: API
5871 ===========
127140 various options that are supported.
128141
129142 A sample execution of "hotpatcher" into the current running shell can be done as
130 below:
143 below.
131144
132 Let's say the library libhotpatchtest.so is in the current directory.
145 We can compile a fresh one to make sure we are picking up the correct library.
133146
134 bash> ./hotpatcher -l ./libhotpatchtest.so -s mysym -v1 $$
147
148 bash> make release
149 bash> cd Release
150 bash> ./src/hotpatcher -vvvv -l $PWD/test/libhotpatchtest.so -s mysym $$
151
135152
136153 On success the "/tmp/hotpatchtest.log" file can be checked if it has the
137154 timestamp of the injection.
0 hotpatch (0.2+git20200110.1.fd2baf1-0kali1) UNRELEASED; urgency=low
1
2 * New upstream snapshot.
3
4 -- Kali Janitor <[email protected]> Fri, 04 Jun 2021 17:20:21 -0000
5
06 hotpatch (0.2-1kali2) kali-dev; urgency=medium
17
28 [ Raphaƫl Hertzog ]
6565 install(TARGETS hotpatch LIBRARY DESTINATION lib)
6666 install(TARGETS hotpatch_s ARCHIVE DESTINATION lib)
6767
68 add_executable(hotpatcher main.c)
69 target_link_libraries(hotpatcher hotpatch_s)
70 install(TARGETS hotpatcher RUNTIME DESTINATION bin)
68 if (BUILD_HOTPATCHER)
69 add_executable(hotpatcher main.c)
70 target_link_libraries(hotpatcher hotpatch_s)
71 install(TARGETS hotpatcher RUNTIME DESTINATION bin)
72 endif (BUILD_HOTPATCHER)
668668 A.regs.rip = FN; \
669669 A.regs.rax = 0; \
670670 } while (0)
671 #define HP_REDZONE 128
672 /* David Yeager pointed this out. http://en.wikipedia.org/wiki/Red_zone_(computing) */
671673 #else /* __WORDSIZE == 64 */
672674 #define HP_PASS_ARGS2FUNC(A,FN,ARG1,ARG2) \
673675 do { \
686688 A.regs.eip = FN; \
687689 A.regs.eax = 0; \
688690 } while (0)
691 #define HP_REDZONE 0
689692 #endif /* __WORDSIZE == 64 */
690693 /* Prepare the child for injection */
691694 if (verbose > 1)
703706 if ((rc = hp_get_regs(hp->pid, &oregs)) < 0)
704707 break;
705708 memcpy(&iregs, &oregs, sizeof(oregs));
709 HP_REG_SP(iregs) -= HP_REDZONE;
706710 if (verbose > 1)
707711 fprintf(stderr, "[%s:%d] Copying stack out.\n", __func__, __LINE__);
708712 for (idx = 0; idx < sizeof(stack)/sizeof(uintptr_t); ++idx) {
795799 fprintf(stderr, "[%s:%d] Copying stack back.\n",
796800 __func__, __LINE__);
797801 for (idx = 0; idx < sizeof(stack)/sizeof(uintptr_t); ++idx) {
798 if ((rc = hp_pokedata(hp->pid, HP_REG_SP(oregs) +
799 idx * sizeof(size_t), stack[idx], verbose)) < 0)
802 if ((rc = hp_pokedata(hp->pid, HP_REG_SP(oregs) - HP_REDZONE
803 + idx * sizeof(size_t), stack[idx], verbose)) < 0)
800804 break;
801805 }
802806 if (rc < 0)
827831 #undef HP_REG_IP
828832 #undef HP_REG_SP
829833 #undef HP_REG_AX
834 #undef HP_REDZONE
830835 return rc;
831836 }