![](/img/trans.png)
[英]Why do I get a segmentation fault in the exploit_notesearch program from “Hacking: The Art of Exploitation”?
[英]Why I can't crash the program even though I am following codes from book “Hacking-The art of exploitation”
我正在遵循“黑客 - 剝削藝術”一書中的代碼。 書中定義的源代碼附帶作者提供的CD。 我只是編譯預先編寫的代碼。根據本書,如果我提供正確的密碼,它應該授予我訪問權限,如果我給一個大字符串錯誤的密碼,它也應該授予我訪問權限,但它否認我。來源確實是如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int check_authentication(char *password) {
int auth_flag = 0;
char password_buffer[16];
strcpy(password_buffer, password);
if(strcmp(password_buffer, "brillig") == 0)
auth_flag = 1;
if(strcmp(password_buffer, "outgrabe") == 0)
auth_flag = 1;
return auth_flag;
}
int main(int argc, char *argv[]) {
if(argc < 2) {
printf("Usage: %s <password>\n", argv[0]);
exit(0);
}
if(check_authentication(argv[1])) {
printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
printf(" Access Granted.\n");
printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
} else {
printf("\nAccess Denied.\n");
}
}
加:
printf("delta: %td\n", (char *) &auth_flag - password_buffer);
在check_authentication
函數中。
如果delta
為負數,則無法利用您的程序。
否則,使用delta + 4
字符的參數來利用它。
如前所述,如果您可以下載的特定虛擬機可以隨書附帶,則可能需要使用它。 這個漏洞也給了我一個錯誤,而不是你希望溢出的結果。 例如,如果我嘗試使用我的系統上的代碼溢出緩沖區,它會給我一個*堆棧粉碎檢測到*錯誤。 我懷疑你的操作系統'內核正在防范這個預期的攻擊。
我還建議您使用以下代碼而不是strcpy(dest,src)來比較結果:
strncpy(password, password_buffer, 16);
這有助於防止創建緩沖區溢出情況。 閱讀手冊頁以比較strcpy和strncpy。
這是典型的緩沖區溢出攻擊。
在linux的c語言程序的教科書實現中,臨時變量存儲在堆棧中。 在你的情況下,它應該是:
-----------------
|int | char[16] |
-----------------
^
stack bottom
,地址從左到右。
當strcpy
將字符串復制到緩沖區時,它將溢出到int並使其不為0,因此它將為true。
但在現代操作系統中,這種攻擊可能無效。 有一些保護機制。
看看: http : //en.wikipedia.org/wiki/Buffer_overflow
http://en.wikipedia.org/wiki/Buffer_overflow_protection
最有可能的是,現代操作系統已經實施了canary
因此它並不像書中提供的那樣容易受到攻擊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.