自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Unix操作系統(tǒng)LD_PRELOAD簡介

系統(tǒng) 其他OS
Unix操作系統(tǒng)的動態(tài)鏈接庫的知識中,這個功能主要就是用來有選擇性的載入Unix操作系統(tǒng)不同動態(tài)鏈接庫中的相同函數(shù)。

在Unix操作系統(tǒng)的動態(tài)鏈接庫的世界中,LD_PRELOAD就是這樣一個環(huán)境變量,它可以影響程序的運(yùn)行時的鏈接(Runtime linker),它允許你定義在程序運(yùn)行前優(yōu)先加載的動態(tài)鏈接庫。

這個功能主要就是用來有選擇性的載入Unix操作系統(tǒng)不同動態(tài)鏈接庫中的相同函數(shù)。通過這個環(huán)境變量,我們可以在主程序和其動態(tài)鏈接庫的中間加載別的動態(tài)鏈接庫,甚至覆蓋正常的函數(shù)庫。一方面,我們可以以此功能來使用自己的或是更好的函數(shù)(無需別人的源碼),而另一方面,我們也可以以向別人的程序注入惡意程序,從而達(dá)到那不可告人的罪惡的目的。

我們知道,Linux的用的都是glibc,有一個叫l(wèi)ibc.so.6的文件,這是幾乎所有Linux下命令的動態(tài)鏈接中,其中有標(biāo)準(zhǔn)C的各種函數(shù)。Unix操作系統(tǒng)中對于GCC而言,默認(rèn)情況下,所編譯的程序中對標(biāo)準(zhǔn)C函數(shù)的鏈接,都是通過動態(tài)鏈接方式來鏈接libc.so.6這個函數(shù)庫的。

OK。還是讓我用一個例子來看一下用LD_PRELOAD來hack別人的程序。

Unix操作系統(tǒng)LD_PRELOAD示例一

我們寫下面一段例程:
/* 文件名:verifypasswd.c */
/* 這是一段判斷用戶口令的程序,其中使用到了標(biāo)準(zhǔn)C函數(shù)strcmp*/
 

  1. #include <stdio.h> 
  2. #include <string.h> 
  3. int main(int argc, char **argv)   
  4. {  
  5. char passwd[] = "password";  
  6. if (argc < 2) {  
  7. printf("usage: %s <password>\n", argv[0]);  
  8. return;  
  9. }  
  10. if (!strcmp(passwd, argv[1])) {  
  11. printf("Correct Password!\n");  
  12. return;  
  13. }  
  14. printf("Invalid Password!\n");  

在上面這段Unix操作系統(tǒng)程序中,我們使用了strcmp函數(shù)來判斷兩個字符串是否相等。下面,我們使用一個動態(tài)函數(shù)庫來重載strcmp函數(shù):
 

  1. /* 文件名:hack.c */  
  2. #include <stdio.h> 
  3. #include <string.h> 
  4. int strcmp(const char *s1, const char *s2)  
  5. {  
  6. printf("hack function invoked. s1=<%s> s2=<%s>\n", s1, s2);  
  7. /* 永遠(yuǎn)返回0,表示兩個字符串相等 */  
  8. return 0;  

編譯程序:
 

  1. $ gcc -o verifypasswd verifypasswd.c  
  2. $ gcc -shared -o hack.so hack.c 


測試一下程序:(得到正確結(jié)果)
 

  1. $ ./verifypasswd asdf  
  2. Invalid Password! 

設(shè)置LD_PRELOAD變量:(使我們重寫過的strcmp函數(shù)的hack.so成為優(yōu)先載入鏈接庫)
 $ export LD_PRELOAD="./hack.so"

再次運(yùn)行程序:
 

  1. $ ./verifypasswd  asdf  
  2. hack function invoked. s1=<password> s2=<asdf> 
  3. Correct Password! 

1)我們的hack.so中的strcmp被調(diào)用了。
2)主程序中運(yùn)行結(jié)果被影響了。

如果這是一個Unix操作系統(tǒng)登錄程序,那么這也就意味著我們用任意口令都可以進(jìn)入Unix操作系統(tǒng)了。

【編輯推薦】

  1. 淺析Unix操作系統(tǒng)set命令
  2. 實際運(yùn)用Unix操作系統(tǒng)set命令
  3. Unix操作系統(tǒng)TCP/UDP知識
  4. 利用Unix操作系統(tǒng)重定向
  5. Unix操作系統(tǒng)與農(nóng)村信用社
責(zé)任編輯:小霞
相關(guān)推薦

2010-04-20 16:09:18

Unix操作系統(tǒng)

2010-04-26 17:24:56

Unix操作系統(tǒng)

2010-04-13 12:27:44

Unix操作系統(tǒng)

2010-04-15 14:40:26

Unix操作系統(tǒng)

2010-04-08 16:18:22

Unix操作系統(tǒng)工具

2010-04-19 18:18:30

Unix操作系統(tǒng)

2010-04-09 11:24:38

Unix操作系統(tǒng)

2010-04-19 16:57:09

Unix操作系統(tǒng)

2010-04-19 10:54:33

Unix操作系統(tǒng)

2010-04-14 13:59:45

Unix操作系統(tǒng)

2010-04-08 17:56:42

Unix操作系統(tǒng)

2010-04-16 17:49:28

Unix操作系統(tǒng)

2010-04-08 15:21:39

Unix操作系統(tǒng)

2010-04-16 17:19:58

Unix操作系統(tǒng)

2010-04-08 10:42:28

Unix操作系統(tǒng)

2010-04-19 17:39:50

Unix操作系統(tǒng)

2010-04-19 18:31:16

Unix操作系統(tǒng)

2010-05-04 10:16:11

Unix操作系統(tǒng)

2010-04-09 16:45:42

Unix操作系統(tǒng)

2010-04-20 17:11:33

Unix操作系統(tǒng)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號