zoukankan      html  css  js  c++  java
  • shellcode

    /*  
     *  作者: 冷却  
     *  时间: 2009年2月21日  
     *  E-mail: leng_que@yahoo.com.cn  
     *  描述: 演示几种用C语言来执行shellcode(其实也就是机器码)的方式
     *  备注:在WindowsXP SP3下测试成功
     */
    
    //一段打开Windows计算器(calc.exe)的shellcode
    unsigned char shellcode[] =
    "/xb8/x82/x0a/x8d/x38/xd9/xc6/xd9/x74/x24/xf4/x5a/x29/xc9/xb1/x23"
    "/x31/x42/x12/x83/xea/xfc/x03/xc0/x04/x6f/xcd/x38/xf0/x2b/x2e/xc0"
    "/x01/x3f/x6b/xfc/x8a/x43/x71/x84/x8d/x54/xf2/x3b/x96/x21/x5a/xe3"
    "/xa7/xde/x2c/x68/x93/xab/xae/x80/xed/x6b/x29/xf0/x8a/xac/x3e/x0f"
    "/x52/xe6/xb2/x0e/x96/x1c/x38/x2b/x42/xc7/xc5/x3e/x8f/x8c/x99/xe4"
    "/x4e/x78/x43/x6f/x5c/x35/x07/x30/x41/xc8/xfc/x45/x65/x41/x03/xb2"
    "/x1f/x09/x20/x40/xe3/x83/xe8/x2c/x68/xa3/xd8/x29/xae/x5c/x15/xba"
    "/x6f/x91/xae/xcc/x73/x04/x3b/x44/x84/xbd/x35/x1f/x14/xf1/x46/x1f"
    "/x15/x79/x2e/x23/x4a/x4c/x59/x3b/x22/x27/x5d/x38/x0a/x4c/xce/x56"
    "/xf5/x6b/x0c/xd5/x61/x14/x2f/x93/x7c/x73/x2f/x44/xe3/x1a/xa3/xe9"
    "/xe4";
    
    //第一种执行方式
    void exe_1()
    {
        void (*code)(void);
        code = (void*)shellcode;
        code();
    }
    
    //第二种执行方式
    void exe_2()
    {
        ( (void (*)(void))shellcode )();
    }
    
    //第三种执行方式
    void exe_3()
    {
        __asm
        {
            lea eax,shellcode;
            jmp eax;
        }
    }
    
    //第四种执行方式
    void exe_4()
    {
        __asm
        {
            mov eax,offset shellcode;
            jmp eax;
        }
    }
    
    //第五种执行方式
    void exe_5()
    {
        __asm
        {
            mov eax,offset shellcode;
            _emit 0xFF;
            _emit 0xE0;
        }
    }
    
    //主函数入口
    void main()
    {
        exe_5();
    }







    ---------------------------------------------------------------------

    ##void后面的shellcode是unsigned char 后面的参数
    方法一:强制类型转换成函数指针
    void ShellCode()
    {
            ((void(*)(void))&shellcode)();
    }
    方法二:嵌入式汇编呼叫shellcode
    void ShellCode()
    {
            __asm
            {
                    mov eax, offset shellcode;
                    jmp eax;
            }
    }
    
    void ShellCode()
    {
            __asm
            {
                    mov eax, offset shellcode;
                    call eax;
            }
    }
    
    void ShellCode()
    {
            __asm
            {
                    lea eax, shellcode;
                    jmp eax;
            }
    }
    方法三:利用动态申请内存
    void ShellCode()
    {
            PVOID p = NULL;
            if ((p = VirtualAlloc(NULL, sizeof(shellcode), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE)) == NULL)
                    MessageBoxA(NULL, "申请内存失败", "提醒", MB_OK);
            if (!(memcpy(p, shellcode, sizeof(shellcode))))
                    MessageBoxA(NULL, "写内存失败", "提醒", MB_OK);
     
            CODE code =(CODE)p;
     
            code();
    
    }  #该方法vc6.0编译失败,建议使用vs编译
    方法四:伪指定
    void ShellCode() { __asm { mov eax, offset shellcode; _emit 0xFF; _emit 0xE0; }
    

      

  • 相关阅读:
    【LeetCode】13. 罗马数字转整数
    【LeetCode】9. 回文数
    【LeetCode】7. 整数反转python3
    【LeetCode】7. 整数反转
    【LeetCode】1. 两数之和
    拖拽选择区域日历组件
    gitlab之gitlab-ci自动部署
    GitLab 安装和配置
    移动端键盘弹起导致底部按钮上浮解决方案
    JS判断滚动条是否停止滚动
  • 原文地址:https://www.cnblogs.com/ruingking/p/13307569.html
Copyright © 2011-2022 走看看