更改exit()某一结构体,再调用exit()可以实现程序流程的劫持。
原理分析
首先查看exit()源代码,我的libc=2.27
调用__run_exit_handlers
函数,查看源代码,
exit.c 77行。
while (cur->idx > 0)
{
struct exit_function *const f = &cur->fns[--cur->idx];
const uint64_t new_exitfn_called = __new_exitfn_called;
/* Unlock the list while we call a foreign function. */
__libc_lock_unlock (__exit_funcs_lock);
switch (f->flavor)
{
void (*atfct) (void);
void (*onfct) (int status, void *arg);
void (*cxafct) (void *arg, int status);
case ef_free:
case ef_us:
break;
case ef_on:
onfct = f->func.on.fn;
发现三个关键call,