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

posted on   荣锋亮  阅读(218)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用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中如何实现遍历表的记录

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示