LD_PRELOAD 参考使用
以下是一个简单的试用,主要是学习下
参考示例
一个进行用户输入确认的,通过LD_PRELOAD 实现一个拦截
- 默认代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char inputpassword[20];
printf("Enter the password?\n");
scanf("%19s",inputpassword);
if(strcmp(inputpassword,"dalong")==0){
printf("Correct password\n");
}
else{
printf("Incorrect password\n");
}
return 0;
}
简单说明: 需要输入dalong 之后才是正确的
- 通过改写strcmp 结合LD_PRELOAD 拦截
int strcmp(char *s1, char *s2) {
return 0;
}
构建共享库
gcc -shared -fPIC mystr.c -o mystr.so
进行拦截
LD_PRELOAD=./mystr.so ./demoapp
效果
说明
通过LD_PRELOAD 或者/etc/ld.so.preload
在linux 日常中还是比较常见的玩法,比如我们可以通过配置来替换glibc 默认的内存分配函数,同时还有一些
基于此模式的性能分析,当然还有一些日常的攻击(拦截系统调用,实现一些攻击破解)
参考资料
https://github.com/microsoft/mimalloc
https://github.com/jemalloc/jemalloc
https://github.com/koute/bytehound
https://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2022-05-05 graalvm typescript types 编写定义参考说明
2022-05-05 iasql-engine 基础设施即数据
2021-05-05 cube.js 预聚合检查
2021-05-05 cube.js 集成cubestore 时间格式问题的一些说明
2021-05-05 cube.js 集成cubestore 时间格式问题
2019-05-05 PostGraphile 4.4 发布,支持real time 查询
2014-05-05 SQL Server中如何实现遍历表的记录