lab1-4 PE结构

目录

一、实验环境

二、实验思路

三、实验步骤

1、使用网络扫描工具扫描

2、查看文件是否被加壳

 3、查看文件被编译的时间

4、查看导入函数

5、查看程序中可打印的字符

6、检查并查看资源

7、简单分析资源


一、实验环境

        操作系统:windows XP sp2

        软件:PEiD、Strings、VirSCAN.org、PETools、Resourse Hacker

二、实验思路

(1)利用网络扫描工具对目标程序进行扫描

(2)利用本地静态分析工具分析目标程序

(3)提取资源中的内容进行分析

三、实验步骤

1、使用网络扫描工具扫描

        将文件上传到virscan.org进行扫描;

         从结果可以看到27个引擎报毒,说明该程序非常危险。

2、查看文件是否被加壳

        将待测文件放入PEiD中,可以看到PEiD显示文件未加壳。

 3、查看文件被编译的时间

        将文件拖入PETools,查看"文件头"——"时间/日期标志"。

         可以看到文件的编译时间。但是这是个错误的时间,被修改过!!!

4、查看导入函数

        这一步的目的:通过导入函数,猜测函数的功能。

        将待测文件拖入PEiD,依次点击"子系统"——"输入表":

         可以看到程序一个导入了三个动态链接库,分别是:kernel32.dll、advapi32.dll、msvcrt.dll。

        在kernel32.dll中,创建了一个文件(CreateFile)并写入(WriteFile),winexec()函数能够运行一个程序,需要特别留意。

         在advapi32.dll中,出现了三个提权的API函数:OpenProcessToken()、LookupPrivilegeValueA()、AdjustTokenPrivileges().

5、查看程序中可打印的字符

        进行这一步的目的是:如果一个主机感染了该恶意代码,主机会出现哪些网络层面的特征和主机层面的特征。

         最后一条是一个网址,想到程序导入了一个winexec()函数,程序可能开启一个后门在这个网址进行下载并且执行下载的后门程序。

        "\system32\wupdmgad.exe"这一条可以猜测:程序可能将自身改名,并复制到该目录下。

        "URLDownloadToFileA"这是一个用于后台下载的API函数。

         "URLDownloadToFileA"结合"winexec"能够将下载的内容进行执行。

        "GetWindowsDirectoryA"用于获取本地系统的windows目录,一般来说,恶意程序调用该函数将自己复制到windows的目录里面。这样做的目的是让我们以为恶意程序是正常程序。

        总结:

        (1)网络特征:恶意程序会从网址下载后门程序;

        (2)主机特征:恶意程序会将自己改名并复制到"\system32\wupdmgad.exe"。

6、检查并查看资源

        用resource hacker打开待测文件,可以看到'MZ'标志,可以得到:资源里隐藏的是一个PE文件。

         但是PE文件主要有两种文件,分别是:dll文件和exe文件。首先将隐藏的PE文件导出来:

         将导出的文件用PETools打开,依次点击"文件头"——"特征值";

         可以看到特征值页面中的"dll"没有打勾,说明当前文件不是一个DLL文件,也就是该文件是一个exe文件。

7、简单分析资源

        将导出的文件放到PEiD中,可以看到:

         该文件由VC6.0编写。

        查看导入表:

         可以看到该PE文件,一共导入了三个动态链接库:kernel32.dll、urlmon.dll、msvcrt.dll。

        在kernel32.dll中,程序调用了GetWindowsDirectoryA这个API函数,用于获取windows的系统目录;使用winexec()用于执行。

         在urlmon.dll中,URLDownloadToFileA函数用于开启后门进行下载,并且结合之前的winexec进行执行。

        总结:

        提取出来的资源文件,主要用于开启后门这一操作。

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PETools 源码 // ImportTable.cpp : implementation file // #include "stdafx.h" #include "PEinfo by saga.h" #include "ImportTable.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CImportTable dialog CImportTable::CImportTable(CWnd* pParent /*=NULL*/) : CDialog(CImportTable::IDD, pParent) { //{{AFX_DATA_INIT(CImportTable) //}}AFX_DATA_INIT } void CImportTable::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CImportTable) DDX_Control(pDX, IDC_LIST2, m_ListCtrl2); DDX_Control(pDX, IDC_LIST1, m_ListCtrl1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CImportTable, CDialog) //{{AFX_MSG_MAP(CImportTable) ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CImportTable message handlers BOOL CImportTable::OnInitDialog() { // TODO: Add extra initialization here CDialog::OnInitDialog(); CFile PEfile,PEfile2; WORD NumofSection; DWORD n,j,ImpRVA,ImpRaw,NameRaw; char cBuff[1024]; IMAGE_IMPORT_DESCRIPTOR ImpDescriptor; if (!PEfile.Open(CPEinfo::FilePathName.GetBuffer(CPEinfo::\ FilePathName.GetLength()),CFile::shareDenyNone)) { MessageBox("无法打开文件!"); return TRUE; } else{ PEfile.Seek(CPEinfo::DosHeader.e_lfanew,CFile::begin); PEfile.Seek(sizeof(CPEinfo::NtHeader),CFile::current); } if (!PEfile2.Open(CPEinfo::FilePathName.GetBuffer(CPEinfo::\ FilePathName.GetLength()),CFile::shareDenyNone)) { MessageBox("无法打开文件!"); return TRUE; } this->m_ListCtrl1.InsertColumn(0,"DLL Name",LVCFMT_LEFT,80); this->m_ListCtrl1.InsertColumn(1,"OriginalFirstThunk",LVCFMT_LEFT,98); this->m_ListCtrl1.InsertColumn(2,"TimeDateStamp",LVCFMT_LEFT,94); this->m_ListCtrl1.InsertColumn(3,"ForwarderChain",LVCFMT_LEFT,94); this->m_ListCtrl1.InsertColumn(4,"Name",LVCFMT_LEFT,90); this->m_ListCtrl1.InsertColumn(5,"FirstThunk",LVCFMT_LEFT,94); this->m_ListCtrl1.SetExtendedStyle(LVS_EX_FULLROWSELECT); this->m_ListCtrl2.InsertColumn(0,"ThunkRVA",LVCFMT_LEFT,90); this->m_ListCtrl2.InsertColumn(1,"ThunkValue",LVCFMT_LEFT,90); this->m_ListCtrl2.InsertColumn(2,"Hint",LVCFMT_LEFT,50); this->m_ListCtrl2.InsertColumn(3,"Function Name",LVCFMT_LEFT,300); this->m_ListCtrl2.SetExtendedStyle(LVS_EX_FULLROWSELECT); NumofSection=CPEinfo::NtHeader.FileHeader.NumberOfSections; ImpRVA=CPEinfo::NtHeader.OptionalHeader.DataDirectory[1].VirtualAddress; for(n=NumofSection;n>0;n--){ PEfile.Read(&CPEinfo;::SecHeader,sizeof(CPEinfo::SecHeader)); if (ImpRVA<(CPEinfo::SecHeader.VirtualAddress+\ CPEinfo::SecHeader.Misc.VirtualSize)) { ImpRaw=ImpRVA-CPEinfo::SecHeader.VirtualAddress\ +CPEinfo::SecHeader.PointerToRawData; break; } } PEfile.Seek(ImpRaw,CFile::begin); n=0; while (TRUE) { PEfile.Read(&ImpDescriptor;,20); if (ImpDescriptor.Name==NULL) { break; } else { NameRaw=ImpDescriptor.Name-ImpRVA+ImpRaw; PEfile2.Seek(NameRaw,CFile::begin); for(j=0;j<1024;j++){ PEfile2.Read(&cBuff;[j],1); if (cBuff[j]==NULL) { break; } } this->m_ListCtrl1.InsertItem(n,cBuff); wsprintf(cBuff,"lX",ImpDescriptor.OriginalFirstThunk); this->m_ListCtrl1.SetItemText(n,1,cBuff); wsprintf(cBuff,"lX",ImpDescriptor.TimeDateStamp); this->m_ListCtrl1.SetItemText(n,2,cBuff); wsprintf(cBuff,"lX",ImpDescriptor.ForwarderChain); this->m_ListCtrl1.SetItemText(n,3,cBuff); wsprintf(cBuff,"lX",ImpDescriptor.Name); this->m_ListCtrl1.SetItemText(n,4,cBuff); wsprintf(cBuff,"lX",ImpDescriptor.FirstThunk); this->m_ListCtrl1.SetItemText(n,5,cBuff); n++; } } PEfile.Close(); PEfile2.Close(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CImportTable::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here POSITION SelectItemNum; char cBuff[1024]; CFile PEfile,PEfile2; DWORD n,j,ImpRVA,ImpRaw,IATRaw,NameRaw; WORD NumofSection,Hint; IMAGE_IMPORT_DESCRIPTOR ImpDescriptor; IMAGE_THUNK_DATA ThunkData; if (!PEfile.Open(CPEinfo::FilePathName.GetBuffer(CPEinfo::\ FilePathName.GetLength()),CFile::shareDenyNone)) { MessageBox("无法打开文件!"); return; } else{ PEfile.Seek(CPEinfo::DosHeader.e_lfanew,CFile::begin); PEfile.Seek(sizeof(CPEinfo::NtHeader),CFile::current); } if (!PEfile2.Open(CPEinfo::FilePathName.GetBuffer(CPEinfo::\ FilePathName.GetLength()),CFile::shareDenyNone)) { MessageBox("无法打开文件!"); return; } NumofSection=CPEinfo::NtHeader.FileHeader.NumberOfSections; ImpRVA=CPEinfo::NtHeader.OptionalHeader.DataDirectory[1].VirtualAddress; for(n=NumofSection;n>0;n--){ PEfile.Read(&CPEinfo;::SecHeader,sizeof(CPEinfo::SecHeader)); if (ImpRVA<(CPEinfo::SecHeader.VirtualAddress+CPEinfo::SecHeader.Misc.VirtualSize)) { ImpRaw=ImpRVA-CPEinfo::SecHeader.VirtualAddress +CPEinfo::SecHeader.PointerToRawData; break; } } PEfile.Seek(ImpRaw,CFile::begin); if ((SelectItemNum=this->m_ListCtrl1.GetFirstSelectedItemPosition())==NULL) { return; } this->m_ListCtrl2.DeleteAllItems(); j=DWORD(SelectItemNum); for(n=0;n<j;n++){ PEfile.Read(&ImpDescriptor;,20); } //wsprintf(cBuff,"lX",ImpDescriptor.Name); //MessageBox(cBuff); IATRaw=ImpDescriptor.FirstThunk-ImpRVA+ImpRaw; PEfile.Seek(IATRaw,CFile::begin); n=0; while (TRUE){ PEfile.Read(&ThunkData;,4); if (ThunkData.u1.AddressOfData==NULL) { break; } wsprintf(cBuff,"lX",ImpDescriptor.FirstThunk); this->m_ListCtrl2.InsertItem(n,cBuff); wsprintf(cBuff,"lX",ThunkData); this->m_ListCtrl2.SetItemText(n,1,cBuff); if (((DWORD)ThunkData.u1.AddressOfData&0x80000000;)==0x80000000) { this->m_ListCtrl2.SetItemText(n,2,"--"); this->m_ListCtrl2.SetItemText(n,3,"--"); } else{ NameRaw=(DWORD)ThunkData.u1.AddressOfData-ImpRVA+ImpRaw; PEfile2.Seek(NameRaw,CFile::begin); PEfile2.Read(&Hint;,2); wsprintf(cBuff,"lX",Hint); this->m_ListCtrl2.SetItemText(n,2,cBuff); for(j=0;j<1024;j++){ PEfile2.Read(&cBuff;[j],1); if (cBuff[j]==NULL) { break; } } this->m_ListCtrl2.SetItemText(n,3,cBuff); } ImpDescriptor.FirstThunk+=4; n++; } PEfile.Close(); PEfile2.Close(); *pResult = 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值