新聞中心
本篇內(nèi)容主要講解“怎么劫持printf函數(shù)的Demo”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“怎么劫持printf函數(shù)的Demo”吧!

成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括富縣網(wǎng)站建設(shè)、富縣網(wǎng)站制作、富縣網(wǎng)頁制作以及富縣網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,富縣網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到富縣省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
##劫持printf函數(shù)的Demo
[root@garnett-vm-1-3nskg test_ld]# ls hijack_printf.c printf_hello.c
root@garnett-vm-1-3nskg test_ld]# cat printf_hello.c
#includemain() { printf("hello garnett.wang!"); }
[root@garnett-vm-1-3nskg test_ld]# cat hijack_printf.c
#define _GNU_SOURCE #include#include #include #include int printf(const char *format, ...) { va_list list; char *parg; typeof(printf) *old_printf; // format variable arguments va_start(list, format); vasprintf(&parg, format, list); va_end(list); //DO HERE SOMETHING VERY EVIL // get a pointer to the function "printf" old_printf = dlsym(RTLD_NEXT, "printf"); (*old_printf)("I have hijacked printf : %s", parg); // and we call the function with previous arguments free(parg); }
注意:在 #include
[root@garnett-vm-1-3nskg test_ld]# gcc printf_hello.c -o printf_hello [root@garnett-vm-1-3nskg test_ld]# ls hijack_printf.c printf_hello printf_hello.c
###劫持之前: [root@garnett-vm-1-3nskg test_ld]# ./printf_hello hello garnett.wang!
編譯源代碼生成劫持so文件: [root@garnett-vm-1-3nskg test_ld]# gcc -shared -fPIC hijack_printf.c -o libhijack_printf.so -ldl [root@garnett-vm-1-3nskg test_ld]# ls hijack_printf.c libhijack_printf.so printf_hello printf_hello.c
###配置LD_PRELOAD: [root@garnett-vm-1-3nskg test_ld]# export LD_PRELOAD=pwd/libhijack_printf.so [root@garnett-vm-1-3nskg test_ld]# echo $LD_PRELOAD /root/test_ld/libhijack_printf.so
###劫持之后: [root@garnett-vm-1-3nskg test_ld]# ./printf_hello I have hijacked printf : hello garnett.wang!
###查看ld dependency: [root@garnett-vm-1-3nskg test_ld]# ldd libhijack_printf.so linux-vdso.so.1 => (0x00007fff0fcfe000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fb30bd30000) libc.so.6 => /lib64/libc.so.6 (0x00007fb30b99b000) /lib64/ld-linux-x86-64.so.2 (0x00007fb30c13c000)
[root@garnett-vm-1-3nskg test_ld]# ldd printf_hello linux-vdso.so.1 => (0x00007fff0c5ff000) /root/test_ld/libhijack_printf.so (0x00007fc6329a8000) libc.so.6 => /lib64/libc.so.6 (0x00007fc63260d000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fc632409000) /lib64/ld-linux-x86-64.so.2 (0x00007fc632baa000)
到此,相信大家對“怎么劫持printf函數(shù)的Demo”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
本文標(biāo)題:怎么劫持printf函數(shù)的Demo
地址分享:http://www.dlmjj.cn/article/gjgogj.html


咨詢
建站咨詢
