日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
怎么劫持printf函數(shù)的Demo

本篇內(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

#include 
	main()
	{
	        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 前加 #define _GNU_SOURCE,因?yàn)镽TLD_NEXTposix標(biāo)準(zhǔn)中包含的。

[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