脱壳练习-手脱upx壳-ELF文件

首先用ida打开待脱壳的程序,函数很少,一个一个翻看。

发现

这个跳转比较怪,我们在这里下一个断点,设置debug调试程序

可以看到直接就断在了这里。

1.然后我们f8单步执行,往下找retn指令

2.在retn指令处下断点,然后f9跳过去,然后再按f8

3.再往下找retn指令重复2步骤

大概重复个两三次后,然后一直f8。最终来到这个位置

 这里是一个大跳转,也就是跳到OEP处,我们接着f8

可以看到来到了这里

我们继续执行到返回

 这里ida提示说返回的地方没有被定义为代码,问我们是否定义,我们选yes

可以看到我们已经到达OEP

然后使用ida脚本dump出来,脚本网上可以搜到。

脚本如下(如果运行报错,可以更改文件保存路径):

#include <idc.idc>

#define PT_LOAD              1

#define PT_DYNAMIC           2

static main(void)

{

         auto ImageBase,StartImg,EndImg;

         auto e_phoff;

         auto e_phnum,p_offset;

         auto i,dumpfile;

         ImageBase=0x400000;

         StartImg=0x400000;

         EndImg=0x0;

         if (Dword(ImageBase)==0x7f454c46 || Dword(ImageBase)==0x464c457f )

  {

    if(dumpfile=fopen("G:\\dumpfile","wb"))

    {

      e_phoff=ImageBase+Qword(ImageBase+0x20);

      Message("e_phoff = 0x%x\n", e_phoff);

      e_phnum=Word(ImageBase+0x38);

      Message("e_phnum = 0x%x\n", e_phnum);

      for(i=0;i<e_phnum;i++)

      {

         if (Dword(e_phoff)==PT_LOAD || Dword(e_phoff)==PT_DYNAMIC)

                         {

                                 p_offset=Qword(e_phoff+0x8);

                                 StartImg=Qword(e_phoff+0x10);

                                 EndImg=StartImg+Qword(e_phoff+0x28);

                                 Message("start = 0x%x, end = 0x%x, offset = 0x%x\n", StartImg, EndImg, p_offset);

                                 dump(dumpfile,StartImg,EndImg,p_offset);

                                 Message("dump segment %d ok.\n",i);

                         }   

         e_phoff=e_phoff+0x38;

      }

 

      fseek(dumpfile,0x3c,0);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

 

      fseek(dumpfile,0x28,0);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

      fputc(0x00,dumpfile);

 

      fclose(dumpfile);

        }else Message("dump err.");

 }

}

static dump(dumpfile,startimg,endimg,offset)

{

        auto i;

        auto size;

        size=endimg-startimg;

        fseek(dumpfile,offset,0);

        for ( i=0; i < size; i=i+1 )

        {

        fputc(Byte(startimg+i),dumpfile);

        }

}

dump出来的文件无壳且能正常运行。

posted @ 2023-02-08 11:35  r136a1  阅读(458)  评论(0编辑  收藏  举报