IDA foundation

1. IDA Use

(1) Search, download and execute IDA Pro, executable program lab05-01.dll loading, respectively disassembly view the results of the program in a graphical and text mode

  • Running IDA Pro, open Lab05-01.dll, displayed in a graphical interface:

  • DLLMain directly to the location of the start. You can use the spacebar to switch to text mode to view:

(2) Check the program for all functions

程序中的所有函数包括:导入函数、导出函数、在中间过程中使用的函数。
  • We can see from the Import window to import function, Export window to view export functions, Function Window view all program functions:

(3) Check the program for all strings:

  • Open View string strings:

  • Here you can see all the strings:

(4) view a function call other functions

  • Just find a function in the left function bar, double-reach location of the function .text section 10011F40:

  • Use graphical tools to view:

    • Function calls Show all function calls;
    • Xrefs to See which function calls this function:

    • Xrefs from Check the function call those functions:

    • User Xrefs chart Allows the user to choose to display content:

      • Cross references to: display those functions is called, the equivalent of Xrefs to
      • Cross references from: display call those functions, the equivalent of Xrefs from
      • Recursive: (recursive), if only to cancel the display up and down direct call function
      • Follow only current direction: only the current function, if it becomes a canceled show all function calls
      • Recursion depth: Depth call display
      • Externals: whether to ignore external Windows API function
      • Data: whether to ignore data
      • From Library Functions: whether to ignore the internal cross-reference library functions
      • To Library functions: whether to ignore external CROSS-REFERENCE
      • Print Comment: whether to print annotations to external functions

2. Use the IDA to analyze lab05-01.dll

(1) DLLMain address?

  • Lab05-01.dll program opened, automatically stops the entry address DLLMain position:

  • We can see DLLMain address is the location in the .text section 1000D02E

(2) calls the function gethostbyname there?

  • Open the import table:

  • 通过ALT+T调出查找gethostbyname:

  • 然后被定位到:

  • 双击该项,跳转到其定位的地址100163CC的位置上:

  • 使用IDAPro的交叉引用功能,在上述位置用快捷键Ctrl+X打开交叉引用窗口:

  • p是gethostbyname被调用的引用,经过观察可得,在5个不同的位置调用了gethostbyname。

(3)分析地址为0x10001757处对gethostbyname的调用,确定DNS请求的目标。

  • 使用快捷键G快速定位到0x10001757:

  • 这里是一段汇编代码,call指令调用gethostbyname:

  • 这一段里面,首先在eax中压入偏移,双击off_10019040可以查看:

  • 这里可以通过IDA的自动注释功能看到部分内容,双击aThisIsRdoPics查看完整的内容:

    • 这里就是这个偏移指向的字符串“[This is RDO]pics.praticalmalwareanalysis.com”。
  • 接着,eax加上了0Dh,我们通过hex界面可能看得更直观,右击aThisIsRdoPics选择在新的十六进制视图打开:

  • 光标放在网址最前位置,可以在下方看到相对偏移,除去中括号中内容的网址部分开始位置的偏移就是0Dh:

  • 然后将这个指向这个URL的eax压入栈,调用gethostbyname函数。

(4)字符串“\cmd.exe /c”出现在内存中的什么位置?分析引用“\cmd.exe /c”的代码所在区域可能完成的作用。

  • 在字符串视图查找字符串“\cmd.exe /c”:

  • 双击打开:

  • 可以看到位置是xdoors_d:10095B34。通过双击字符串后面注释中的上箭头或Ctrl+C查看交叉引用找到其引用:

  • 定位到:

  • 汇编学的不好,在这里看汇编代码也实在是费劲,为了大体判断这一部分的功能,我采用图形化界面,直接双击蓝色无条件跳转指向线、绿色条件跳转指向线查看代码的流程。
  • 可以看到一些有用的信息:

      call ds:GetCurrentDirectoryA:是一个系统参数,在一个缓冲区中装载当前目录。
      call ds:GetLocalTime:获取本地时间。
  • 字符串位置:

  • 双击查看:

    • 获得关键信息:“Shell Session”会话

        call ds:CreatePipe:创建匿名管道的同时返回两个句柄:管道读句柄和管道写句柄。
        call ds:GetStartupInfoA:获取进程起始信息。 call ds:recv:套接字接收函数 call ds:closesocket:关闭套接字。
  • 综合来看,这一部分可能完成的作用是使用套接字的一个远程会话。

(5)函数sub_10004E79调用了哪些函数?其中的API函数有哪些?根据API函数信息猜测该函数的作用,并尝试对该函数进行重命名。

  • 在左侧函数栏查找到sub_10004E79,双击查看:

  • 使用图形化工具查看这个函数调用了那些函数:

  • 函数sub_10004E79调用了直接调用了四个函数,间接调用了四个函数。
    • API函数有:

        GetSystemDefaultLangID:取得系统的默认语言ID 
        Sprintf:把格式化的数据写入某个字符串中
    • C语言库函数有:

        Send:向一个已经连接的socket发送数据
        Strlen:检测字符串实际长度
        Malloc:向系统申请分配指定个字节的内存空间
        Free:释放指向的存储空间
  • 猜测这个函数应该是获取了系统语言并打印出来,可以在左侧函数栏右击函数编辑:

  • 重命名函数,方便进一步研究:

  • 更改后可以看到函数名都已经被修改了:

(6)在0x10001701处是一个对socket的调用,它的三个参数分别是什么?结合MSDN中socket帮助和IDA中的命名符号常量,你认为这三个参数实际分别是什么?

  • 首先到达0x10001701处,看到其三个参数分别为:2,1,6:

  • 可以使用hex-ray反汇编C语言伪代码看得更清楚:

  • MSDN中查找socket function

  • 可以找到我们需要的参数:

    • AF

    • Type

    • protocol

  • Socket函数中的三个参数分别为:

      2:AF_INET使用IPv4协议
      1:SOCK_STREAM使用流式Socket
      6:IPPROTO_TCP使用tcp协议
  • 可以右击更改为对应的名称方便理解:

  • 这个标志实际上是一个枚举型变量:

  • 更改后效果:

4. 实践小结

  • 有同学遇到了这样一个问题来问我:在Function window中搜索后面某一题中调用的函数没有找到,在Import中搜索到了,这个Function Window不应该包含这个程序里所有的函数吗,为什么会找不到一个确实被调用了的函数呢?
  • 我看了一下,确实是这样,打开其它程序,同样不显示导入函数:

  • 查看Function Window中的标志F,因为标志F表示可能是导入函数,也可能是自己写的函数,没有看到有该标志的,可能是因为IDA版本问题或者是本身导入函数就不算在程序中写的函数?

  • IDA Pro功能实在是太强大了,在这么短的时间内只做到了根据问题粗略的使用,《恶意代码分析实战》用了一章的篇幅讲这个强大的反汇编器,读完了之后感觉有很多可拓展的使用方法(有些插件需要付费才能下载,免费版的功能和上面说的不大一样),还需要一定时间的学习。

  • 在做这次实践的过程中,我一直在想如何在没有这些问题的提示下使用IDAPro对一个恶意代码进行高级静态分析。汇编和反汇编很重要,对程序及工具交互能力的利用也很重要。在接下来的学习过程中需要逐步解决这个问题。


参考资料:《恶意代码分析实战》读书笔记 静态分析高级技术一

Guess you like

Origin www.cnblogs.com/ltyandy/p/11240847.html