Wednesday, January 18, 2012

Malware Analysis Tutorial 12: Debug the Debugger - Fix Module Information and UDD File

Learning Goals:
  1. Understand how debugger saves debugger information
  2. Know how to use binary editor to examine file contents
  3. Trouble shooting and fix issues of debuggers when necessary
Applicable to:
  1. Assembly Language.
  2. Computer Security.
  3. Programming Language Principles.
  4. Operating Systems.

1. Introduction
In Tutorial 11, we have shown you the trick played by Max++ to load its own malicious executable using the "corpse" of another DLL called "lz32.dll". The basic idea is to cut in the LdrLoadDll call and reset the base address and other relevant information of the module, without loading the executable of lz32.dll from its file (while the malicious PE has been copied into that memory area). This is achieved by setting up a hardware breakpoint inside LdrLoadDll and the "surgery" is performed by the vectored exception handler configured by Max++ in advance.

Now, one side-effect of Max++'s "surgery" on Lz32.dll is that, we are no longer able to make comments in that particular area of "lz32.dll". When you try to place comments on the code (starting from 0x003C24FB, the starting addr of "lz32.dll"), they will not be properly saved by IMM. The next time you load Max++ in IMM, all comments related to lz32 will be lost! The reason is that Max++'s surgery is incomplete -- it did not fix the entire kernel structure of lz32.dll and the mal-formated data structure fails the internal analysis of IMM. When IMM tries to create a UDD file (a file records the debugging information for each module in a binary executable), it fails.

Clearly, there are two ways to fix this:
  (1) make sure that all kernel data related to lz32.dll are properly reset [which can be a huge task],   and
  (2) debug into IMM and tweak its control flow so that it can work correctly given the malformed data.

We will take approach 2 and show you how to debug the IMM debugger and fix issues on the spot.



2. Lab Configuration
2.1 Software You need
You need the following software tools. They can be easily downloaded from Internet: (1) HxD binary editor and (2) NotePad++.

2.2 Lab Configuration
You can either continue from Tutorial 10, or follow the instructions below to set up the lab. Refer to Tutorial 1 and Tutorial 4 for setting up VBOX instances and WinDbg.  We now proceed to the steps that we need for this tutorial:

(0) -- IT IS IMPORTANT TO TAKE A SNAPSHOT after you've installed HxD and NotePad. At this moment, the system is still clean. After step (3), the system will be infected, later, whenever you restart the system, you have to restore the snapshot to start from a clean system!!!
--------------------------------------------------------------------------------------------------
(0.5) restore the snapshot as discussed in step (0)

(1) In IMM, clear all hardware breakpoints and software breakpoints.

(2) Go to 0x4012DC and set a hardware breakpoint there (the instruction at 0x4012DC should be CALL 0x413652). Press F9 to run to 0x4012DC.
       This is the point right before the tricks introduced in Tutorial 11 (which sets up hardware breakpoint inside zwMapViewSection and then calls LdrLoadDLL).
       At this point, you might want to straighten out the display of the assembly code of IMM (if there is a large gibberish section of DB instructions). Highlight and select one or two pages of DB instructions, right click and then select Analysis -> During Next Analysis Treat Selection As -> Command, and then right click and select Analysis -> Code Analysis.

(3) Now at 0x401419 (instruction is MOV [ESP-2E8]: ESI) set a SOFTWARE BREAKPOINT (by pressing F2), and then press Shift+F9 (at least twice) until you hit 0x401419.
  Shift+F9 is to RUN (but passing all exceptions to user code). This way we allow the vectored exception handler set by Max++ to be effective. Hence, the malicious code will be layed in the "body" of lz32.dll. Notice that when you hit the 0x401419, the code of the fake lz32.dll has already been executed (which infects a number of driver files and modifies system registry etc.). We will introduce the analysis of this code in future tutorials. At this moment, we are interested in making comments working in IMM.

(4) At this point, if you click IMM View->Executable Modules (as shown in Figure 1, the first row), you can find a new module is loaded for "lz32.dll". Its base address is 0x3C0000 (could vary depending on the run-time behavior of the system). Using the trick introduced in Tutorial 9, we can find the entry point of the module to be 0x3C24FB.

Figure 1. New "lz32.dll" Module
(5) Now in the code pane you can right click and goto 0x3C24FB. The first instruction should be "CMP [ESP+8], -2". You can set up some comments on any code below this instruction. To save your comments, goto to "View -> Executable Modules", right click on lz32.dll and select "Actualize" and then "save UDD files now". Stop the process being debugged and exit from IMM. Restart IMM again and repeat steps (1) to (5) again, you will notice that all your comments in the previous IMM session are gone!

3. Introduction of UDD Format
The missing comments problem is caused by IMM. When the module information structure is mal-formed, IMM will not behave correctly when analyzing its code section, and hence will not create a corresponding UDD file for lz32.dll (that's the reason all your comments are lost). IMM creates UDD files to record the debugging information (e.g., comments created by users). This section introduces some background information about the UDD file format.


Figure 2. UDD Files

There are several simple fact about UDD files:
(1) All UDD files are located in the Immunity Debugger folder (e.g., c:\Program files\Imm Inc\Immunity Debugger), as shown in Figure 2.
(2) For each module that is analyzed by IMM (i.e., its code is shown at least once in the IMM code pane), IMM will create a corresponding UDD file. For example, look at Figure 2 (to analyze Max++, we once stepped into ntdll, and there is a corresponding ntdll.udd). The ".bak" files are the temporary UDD files.

Figure 3. Snapshot of Max++_Downloader.udd (in Notepad)

A UDD file is a collection of records while each record occupies a line. Each record begins with some binary data, and then continued with the corresponding comment by the user. For example, in Figure 3, we displays a fragment of the Max++ download.udd. You can see that the file (opened by Notepad++) corresponds to the comments in the IMM debugger window.

Figure 4. Same UDD file in HxD binary editor


So far, there is no complete documentation on UDD format, however, it's easy to infer the meaning of the binary data at the beginning of each record. Look at the "ENTRY PC!" comment in Figure 4 and its subsequent comment "Standard stack protection for function call".

The binary data before "ENTRY PC!" is
  0x 55 73 36 13 00 00 00 C8 3B 01 00 .... 00 0A
Clearly the tag "55 73 36" indicates the type of the record (a user comment) - this is the same for the next comment "Standard stack protection". The next 4 bytes "13 00 00 00" indicates that the record length is 0x13 bytes, and then "C8 3B 01 00" indicate its relative location (beginning from the module base address) - you can verify this in Figure 3 (the location of the comment is 0x413BC8 - note the reversed byte sequence of integers). Clearly "00 0A" is used to end the record.

It is straightforward to infer how IMM works with a UDD file. For each module, IMM gets its base address and for each user comment, it calculates its offset and place the record in the UDD file. Clearly, if IMM's analysis fails somehow, the UDD file will not be created and thus all user comments will be lost.

4. Debug the Debugger
Now we show the tricks to debug into the IMM debugger and fix the issues. Our purpose is to redirect the control flow of IMM so that it would work normal. Follow the instructions below:
(1) Start IMM, and then open the executable of IMM (located in c:\Program Files\Imm Inc\Immunity Debugger). Press F9 to run it. In this case, we have two IMM instances, we call the first one IMM1 and the second one IMM2.
Figure 5. Set Breakpoint on IMM
(2) In IMM2, open the Max++ binary executable.
(3) Now in IMM1, View -> Executable Modules and then right click on IMM (the first one) and then right click and select View -> Names. Basically, this shows the list of exported functions. You might immediately notice that there is something that we are interested in: the function Analyzecode at 0x00411020(see Figure 5).
Figure 6. Python Script to Trigger Analyzecode

(4) We would like to trigger the Analyzecode() of IMM2 and then analyze its logic in IMM1. In IMM2, repeat Steps (1) to (3) in Section 2.2 until you hit 0x401419.

(5) Now in IMM2, click to open the python script window (it's the second button in the toolbar, right after the "open file" button). Type the first two commands: mod = getModule('ntdll.dll'); mod.Analyse() (see Figure 6). You will then hit the breakpoint in IMM1!
   Step through the instructions in IMM1 and make a good memory of it. When the function Analyzecode() returns, press F9 to let it run and you will go back to IMM2.
  Now do the same thing for lz32.dll. Did you notice there is something different? 


5. Challenge of the Day
(1) The control flow of two analyzecode() sessions depart from a CMP EDX, 7 instruction. Find out where it is.
(2) The value contained in EDX is an important attribute of a DLL module. Can you find out its meaning? [hint: codeSize. Prove it]
(3) Can you modify the control flow so that analyzecode() is successfully completed? After that, you can repeat steps (4) and (5) in section 2.2 and make comments. In the c:\program...\immunity debugger\ folder, you can verify that the lz32.udd file is created and your comments will be recorded.

30 comments:

  1. e will take approach 2 and show you how to debug the IMM debugger and fix issues on the spote will take approach 2 and show you how to debug the IMM debugger and fix issues on the spot

    ReplyDelete
    Replies
    1. Dr. Fu'S Security Blog: Malware Analysis Tutorial 12: Debug The Debugger - Fix Module Information And Udd File >>>>> Download Now

      >>>>> Download Full

      Dr. Fu'S Security Blog: Malware Analysis Tutorial 12: Debug The Debugger - Fix Module Information And Udd File >>>>> Download LINK

      >>>>> Download Now

      Dr. Fu'S Security Blog: Malware Analysis Tutorial 12: Debug The Debugger - Fix Module Information And Udd File >>>>> Download Full

      >>>>> Download LINK Wc

      Delete
  2. That is really cool. Thanks for finding it. Some really good ideas there, this is going to be a real time sink.I am a china tour lover,You can learn more: China travel packages | Asia tour packages | China city tour packages

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. What makes this kind of infection troublesome is that it diverts you to some different pages containing irrelevant data. What?s more awful is that this sort of infection is not identified effectively.navigate here

    ReplyDelete


  5. Please keep updating this blog, it's been too long. Great post! We adore this blog and This information is very good.

    SCR888th

    ACE333

    ReplyDelete
  6. • กำจัดขน
    • กระตุ้นการผลิตคอลลาเจนชูกระชับผิวหน้า (Tightening) เลือนหายไปริ้วรอยช่วยทำให้ผิวเรียบเนียน
    • รอยหลุมสิวตื้นขึ้นและก็รูขุมขนกระชับขึ้นผิวหน้าละเอียดและก็เรียบเนียน
    • รักษาสิวอักเสบรอยแดงจากสิวหรือเส้นเลือดฝอยที่ไม่ปกติ
    • ลดความหมองคล้ำผิวกระจ่างขาวสวยใสมองดูอ่อนกว่าวัย
    • กำจัดเส้นโลหิตขอดและก็เส้นเลือดฝอย
    • รักษาเส้นโลหิตขอดเล็กๆได้โดยไม่ต้องเสียเวล่ำเวลาผ่าตัด ไม่ต้องนอนพัก แต่ว่าบางทีอาจจำต้องทำต่อเนื่องกันบ่อยครั้งก็เลยจะได้ผลลัพธ์ที่ดี

    เลเซอร์ขนขา
    เลเซอร์รักแร้
    เลเซอร์บิกินี
    เลเซอร์ กำจัดขนหน้า
    เลเซอร์ กำจัดขน รักแร้

    ReplyDelete
  7. cool ! I am really impressed with your blog

    Gclub

    ReplyDelete
  8. Excellent Post as always. thank for good sharing

    Gclub Royal1688

    ReplyDelete
  9. I like all the points shared by you. Thanks for this informative post!
    แทงรูเล็ต

    ReplyDelete
  10. ทำไมต้องเทรด Forex?

    ในสนามของการลงทุน เงินฝากออมทรัพย์, พันธบัตรรัฐบาล เป็นการลงทุนที่ให้ผลตอบแทนเลวร้ายที่สุด พันธบัตรรัฐบาลให้ดอกเบี้ยเฉลี่ยปีละ 3% หรือแปลว่า หากคุณต้องการรายได้เดือนละ 25,000 บาท คุณจะต้องมีเงินลงทุนไปซื้อพันธบัตรมากถึง 10 ล้านบาท เพื่อแลกกับรายได้เพียงเดือนละ 25,000 บาท

    ความไม่คุ้มค่าในเชิงเวลา ทำให้คนรุ่นใหม่จากทุกๆ อาชีพ เลือกที่มองหาการลงทุนที่ให้ผลตอบแทนที่สูงกว่า นั่นก็คือ "การเทรดออนไลน์" โดยระบบของ ZFX เปิดโอกาสให้คุณสามารถเข้าไปซื้อขายได้ด้วยตัวเอง ทั้งตลาดหุ้น ทองคำ น้ำมัน ค่าเงิน สกุลเงินดิจิตอล ฯลฯ รวมถึงการคัดลอกสัญญาณการเทรดจากมืออาชีพ หรือเลือกใช้หุ่นยนต์เทรดอัตโนมัติที่มีให้ทดลองใช้จากทั่วโลก

    ReplyDelete
  11. Pretty detailed tutorial. Never thought someone would to this.

    ReplyDelete
  12. pussy888 คาสิโนออนไลน์เต็มแบบ สนุกสนานและก็ดีเยี่ยมที่สุดในปี 2020
    pussy888 แหล่งพนันออนไลน์ที่ครบวงจรสูงที่สุดรวมทั้งเหมาะสมที่สุดตอนนี้ ยินดีให้การอำนวยความสะดวกตลอดการใช้งาน โดยมีแบบการเล่นพนันที่เป็นเอกลักษณ์ซึ่งไม่ซ้ำใคร มีช้อยส์ตัวเลือกความรื่นเริงใจให้บริการครบถ้วน
    เหนือชั้นทุกการพนัน เกมส์พนันสูงที่สุดจำเป็นต้องที่ pussy888 แค่นั้น
    การเลือกใช้งานบริการพนันออนไลน์ผ่าน pussy888 ถือได้ว่าอีกหนึ่งปากทางเข้าสู่ความเบิกบานใจอย่างเต็มรูปแบบ กับการใช้แรงงานพนันเกมส์หลายชิ้นมากที่สุด แม้ว่าจะเป็นเว็บไซต์พนันสมาชิกใหม่ให้บริการได้ไม่นานแต่ว่าเรื่องความตระการตาของเกมพนันในลักษณะต่างๆมีให้ใช้งานครบวงจรเต็มๆทุกต้นแบบ จากการพัฒนาขึ้นมาเพื่ออยากที่จะให้นักการพนันทุกคนเลือกใช้งานร่วมบันเทิงใจได้ไม่ซ้ำ ทำให้เมมเบอร์ทุกคนสามารถร่วมเปิดประสบการณ์พนันออนไลน์ที่ล้ำสมัยได้จากโทรศัพท์มือถือของคุณ และก็ยังเป็นหนทางของการเล่นพนันที่พร้อมใช้งานได้ตามสไตล์ความอยากเท่าที่คุณอยากได้ เป็นเสมือนแหล่งพนันที่มีความนำสมัยเพียงแค่เลือกใช้งานผ่านมือถือสมาร์ทโฟน แท็บเล็ตหรือคอมพิวเตอร์ โน้ตบุค ขอเพียงมีสัญญาณเน็ตก็สามารถช่วยทำให้เข้าถึงการพนันและก็ลุ้นเงินรางวัลได้บ่อยมากเท่าที่คุณอยากแล้ว
    จุดเด่นสำหรับในการใช้บริการเกมคาสิโนออนไลน์ pussy888
    ในการใช้บริการเกมคาสิโนออนไลน์ pussy888 ต้นแบบการเล่นพนันออนไลน์ที่เปิดให้บริการเพื่อความเบิกบานใจอย่างเต็มรูปแบบแล้วก็มีจุดเด่นชอบใจนักเสี่ยงดวงทุกคนดังต่อไปนี้
    สามารถเริ่มของการเล่นพนันได้ด้วยเงินลงทุนอย่างน้อยเพียงแค่ 100 บาทแค่นั้น ก็เลยเป็นแหล่งพนันออนไลน์ที่เปิดกว้างให้บริการทุกคนได้อย่างยอดเยี่ยม
    ผู้คนนักเสี่ยงโชคมีอิสระของการใช้แรงงานเลือกเล่นพนันได้แบบไม่จำกัด คัดสรรยอดเยี่ยมเกมพนันประสิทธิภาพให้เลือกใช้งานเยอะแยะ
    ความสบาย คล่องแคล่วตลอดการใช้งานที่ตอบปัญหาได้อย่างยอดเยี่ยม ทำให้การพนันผ่านเว็บไซต์ใช้งานง่ายเพียงแค่มีโทรศัพท์มือถือหรือคอมได้ง่ายดายกว่าเมื่อก่อนอย่างชัดเจน
    มีโปรโมชั่น โบนัส ของขวัญ มอบให้กับสมาชิกทุกท่านไม่จำกัดว่าสมาชิกใหม่หรือสมาชิกเริ่มแรก
    วิถีทางการติดต่อ การใช้แรงงาน ลิงค์ปากทางเข้าอัพเดทให้บริการตลอดในทุกช่วง
    เข้ามาร่วมเปิดโลกกว้างที่การเล่นพนันออนไลน์ล้ำสมัยที่สุดที่
    pussy888 เป็นแหล่งพนันออนไลน์ที่เปิดให้บริการเพื่อร่วมสนุกสนานกับเกมพนันนานาประการการใช้บริการที่มีแบบอย่างนำสมัย ใครๆก็เลือกร่วมเล่นพนันได้ง่ายไม่ว่าจะเป็นคนใหม่หรือจะอ่อนประสบการณ์หรือคนเล่นพนันต่างก็เลือกใช้บริการได้ในทันที เมื่อเลือกใช้บริการกับเว็บไซต์มาตรฐานเชื่อมั่นได้ว่าไม่มีปัญหาประเด็นการพนันเพราะเหตุว่าคณะทำงานพร้อมดูแลความเรียบร้อยและก็ปรับปรุงอย่างไม่อยู่กับที่เพื่อสมาชิกทุกคนเชื่อใจตลอดการใช้งานเยอะที่สุด

    ReplyDelete
  13. Hi everyone the piece of writing is truly fruitful in support of me, keep up posting these articles or reviews.
    Here is the link of Latest Designer:
    https://softserialskey.com/mastercam-crack-free/
    Download it Free And Enjoy!

    ReplyDelete
  14. It is an interesting intelligent system like our automatic deposit-withdrawal system.
    สมัครpussy888

    ReplyDelete
  15. Your post contains interesting content. Your posts can be published. Read and feel enjoyment and can easily understand the content posted by the poster.
    Thank you and wish you good luck. บาคาร่า

    ReplyDelete
  16. Great Article
    Cyber Security Projects


    Networking Security Projects

    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete
  17. Dr. Fu'S Security Blog: Malware Analysis Tutorial 12: Debug The Debugger - Fix Module Information And Udd File >>>>> Download Now

    >>>>> Download Full

    Dr. Fu'S Security Blog: Malware Analysis Tutorial 12: Debug The Debugger - Fix Module Information And Udd File >>>>> Download LINK

    >>>>> Download Now

    Dr. Fu'S Security Blog: Malware Analysis Tutorial 12: Debug The Debugger - Fix Module Information And Udd File >>>>> Download Full

    >>>>> Download LINK rI

    ReplyDelete
  18. Thank you very much for writing such an interesting article
    SBO222.bet
    SBOBET

    ReplyDelete
  19. sbobet เป็นลู่ทางโดยมากที่คนเล่นการพนันเลือกใช้บริการกัน เพราะว่าเป็นเว็บไซต์ที่ไม่ต้องเล่นผ่านเอเย่นต์ ให้บริการเล่นเกมพนันอย่างครบวงจร มีเกมส์ให้เลือกเล่นมากมายค่ายมีชื่อเสียง แถวยังวางเดิมพันได้อย่างมีความสุข pic5678 ไม่มีความเสี่ยงต่อการถูกโกง ด้วยการให้บริการที่มีความโล่งใส มีระบบระเบียบพนันแบบมาตรฐานได้รับการยินยอมรับจากสากล เรื่องทางด้านกระบวนการทำธุรกรรมไม่ต้องกล่าวถึงสามารถไว้ใจได้ว่าเงินทุกบาทุกสตาร์ของคุณจะได้รับคืนรวมทั้งมากขึ้นจากการเล่นอย่างแน่แท้ แม้เข้ามาเป็นสมาชิกกับเว็บไซต์ตรงไม่ผ่านผู้แทนจะได้รับเงินรางวัลแบบเต็มๆไม่โดนหักเลย

    ReplyDelete
  20. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.

    Mastercam  Crack

    KeyShot Pro Crack

    BlueStacks Crack

    DVDFab  Crack

    ReplyDelete