Tag: RCE

de4dotShell – Integrate de4dot to Context Menu

Just a basic application, nothing special here

The idea is simple. This small tool adds an entry named “de4dotShell” to context menus of .exe and dll files. From there you can interact with de4dot easily. It also has textboxes to input specific parameters to control de4dot’s works as you want.

To use it, first copy the de4dotShell.exe to de4dot’s root folder (which contains de4dot.exe), and then run de4dotShell.exe, check the box “Register Shell Extension” and voila!

Thanks for Yashar Mahmoudnia for his great idea about de4dotUI. Let make this de4dotShell as a modification of de4dotUI, so nothing special, feel free to use it and all credits go to Yashar Mahmoudnia.

Any bug reports are welcome

de4dotShell

Requires .NET 2.0 and a working de4dot

Download:

DOWNLOAD MEGA.CO.NZ LINK

 

Enjoy and best Regards

Levis

Customizing and sharing Windbg’s Theme: How to? Here’s a quick note

these days i spent some hours to play around with windbg to see how it works, and getting bored because i’m missing Ollydbg’s style. So I made a new look for windbg to make it become more friendly to me. You can take a look in the picture below:
ibcLcQqET5HkY7.png
Pretty nice, eh? Yeah, just a little bit modification. And everything is now okay. But before sharing this theme, let me talk a bit about the way to create a theme in windbg.
Windbg has a great and modern, highly configurable interface with docking, tabbed and floating-windows, so you can work in very comportable and flexible enviroment, as you wish to. For me, it’s very interesting, and i liked it a lot.
By default, the default workspace of windbg is really “empty” -> this means that the first time you ran the windbg, you will see a blank windows with no child-windows inside (for e,g disassembler, register, memory dump, stack, etc…). So, you should bring them out by clicking on the “View” menu. Then you can change display color and font style by going to menu “View” -> “Option”.
After get the thing done, you MUST save the setting by going to “File” menu and choose “Save workspace”. But, the point is, how to export the theme and share to others?
Here’s how i did it. Just follow these steps:
1. Fire up Windbg, then make changes to its interface as i said before
2. After step 1, click the “File” Menu and then choose the “Save Workspace to file”. A SaveFileDialog comes out, set the name for you file and click “Save” button. Remember the location where you saved the file
3. Locate the file which you just created in step 2, this is your saved settings (includes windows positions, color schemes and font style…) with extension “.wew”.
Everytime windbg executed, it will reads the information about workspace setting in a registry key value. The value is stored at HKCU\Software\Microsoft\Windbg\Workspace with name “Default” (means default workspace), so we should modify the value stored in this registry key, to load our theme. But why we need the *.wew file? I opened that file (.wew) in a hex editor to see the content inside, then i compared it with the value stored in “Default” registry key, and found that they all have the same format. So, to apply the theme, simply copy all the data in .wew file then paste in to “Default” registry key. I wrote a small python snippet to convert .wew file to a .reg file. Then we just apply the .reg file to overwrite data in “Default” registry key automatically. And if we want to share the theme to other, just send them the reg file and they will apply it.
4. Copy these code, save and run it with argument:
import binascii
import sys
fileName = sys.argv[1]
f = open(fileName,'rb')
content = f.read()
data = binascii.hexlify(content)
fileOut = open(fileName+'.reg','w')
fileOut.write('Windows Registry Editor Version 5.00\n\n')
fileOut.write('[HKEY_CURRENT_USER\\Software\\Microsoft\\Windbg]\n\n')
fileOut.write('[HKEY_CURRENT_USER\\Software\\Microsoft\\Windbg\\Workspaces]\n\n')
fileOut.write('\"Default\"=hex:'+data[0]+data[1])
x=2
while x < len(data):
  fileOut.write(','+data[x]+data[x+1])
  x+=2
f.close()
fileOut.close()
for example, my saved workspace file has the name “Cool_theme.wew”, and i saved the code above to a file named wtl.py (windbg_theme_loader), so the command is :
python wtl.py Cool_theme.wew
a new file named Cool_theme.wew.reg will be created. Now the time for you to start applying and sharing your creations.
And here is the reg file of my theme, jsut save and activate:
Windows Registry Editor Version 5.00
 
[HKEY_CURRENT_USER\Software\Microsoft\Windbg]
 
[HKEY_CURRENT_USER\Software\Microsoft\Windbg\Workspaces]
 
"Default"=hex:57,44,57,53,01,00,00,00,30,00,00,00,38,00,2e,00,43,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,5c,00,4c,00,65,00,76,00,69,00,73,00,5c,00,44,00,65,00,73,00,6b,00,74,00,6f,00,70,00,00,00,67,00,33,00,00,00,68,00,5c,00,f0,ff,ff,ff,00,00,00,00,00,00,00,00,00,00,00,00,90,01,00,00,00,00,00,00,03,02,01,31,43,00,6f,00,6e,00,73,00,6f,00,6c,00,61,00,73,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,6e,00,65,00,00,00,02,00,10,00,04,00,00,00,00,00,50,00,52,00,01,00,02,00,10,00,04,00,ff,ff,ff,00,00,00,00,6a,0a,00,00,00,10,00,04,00,20,00,00,00,00,6a,00,00,3d,00,00,00,10,00,04,00,00,00,00,00,00,03,00,00,0c,00,00,00,10,00,04,00,01,00,00,00,00,04,00,2e,3c,00,00,00,10,00,04,00,01,00,00,00,01,08,00,00,3f,00,00,00,10,00,04,00,01,00,00,00,00,03,00,00,12,00,00,00,10,00,04,00,01,00,00,00,00,08,00,30,24,00,00,00,50,00,42,00,44,00,3a,00,5c,00,43,00,72,00,61,00,63,00,6b,00,65,00,72,00,20,00,50,00,61,00,63,00,6b,00,61,00,67,00,65,00,5c,00,77,00,69,00,6e,00,64,00,62,00,67,00,5c,00,73,00,6f,00,75,00,72,00,63,00,65,00,00,00,00,03,00,01,04,2a,23,00,00,00,50,00,42,00,44,00,3a,00,5c,00,43,00,72,00,61,00,63,00,6b,00,65,00,72,00,20,00,50,00,61,00,63,00,6b,00,61,00,67,00,65,00,5c,00,77,00,69,00,6e,00,64,00,62,00,67,00,5c,00,69,00,6d,00,61,00,67,00,65,00,73,00,00,00,00,1e,0b,41,00,03,22,00,00,00,b0,00,a6,00,53,00,52,00,56,00,2a,00,44,00,3a,00,5c,00,43,00,72,00,61,00,63,00,6b,00,65,00,72,00,20,00,50,00,61,00,63,00,6b,00,61,00,67,00,65,00,5c,00,77,00,69,00,6e,00,64,00,62,00,67,00,5c,00,73,00,79,00,6d,00,62,00,6f,00,6c,00,73,00,72,00,2a,00,68,00,74,00,74,00,70,00,3a,00,2f,00,2f,00,6d,00,73,00,64,00,6c,00,2e,00,6d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,2e,00,63,00,6f,00,6d,00,2f,00,64,00,6f,00,77,00,6e,00,6c,00,6f,00,61,00,64,00,2f,00,73,00,79,00,6d,00,62,00,6f,00,6c,00,73,00,20,00,00,00,00,00,41,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,40,ff,02,00,10,00,04,00,ff,ff,ff,00,20,00,20,00,00,ff,02,00,10,00,04,00,ff,ff,ff,00,20,00,20,00,01,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,02,ff,02,00,10,00,04,00,ff,80,00,00,20,00,20,00,03,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,04,ff,02,00,10,00,04,00,ff,ff,00,00,20,00,20,00,05,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,06,ff,02,00,10,00,04,00,ff,ff,ff,00,20,00,20,00,07,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,08,ff,02,00,10,00,04,00,80,ff,00,00,20,00,20,00,09,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,0a,ff,02,00,10,00,04,00,ff,ff,ff,00,20,00,20,00,0b,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,0c,ff,02,00,10,00,04,00,ff,ff,80,00,20,00,20,00,0d,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,0e,ff,02,00,10,00,04,00,ff,ff,ff,00,20,00,20,00,0f,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,10,ff,02,00,10,00,04,00,00,ff,00,00,20,00,20,00,11,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,12,ff,02,00,10,00,04,00,ff,ff,ff,00,20,00,20,00,13,ff,02,00,10,00,04,00,00,00,00,00,20,00,20,00,38,ff,02,00,10,00,04,00,ff,ff,ff,00,20,00,20,00,39,ff,02,00,10,00,04,00,00,00,00,00,4e,00,4f,00,3a,ff,02,00,10,00,04,00,ff,ff,ff,00,43,00,48,00,3b,ff,02,00,10,00,04,00,00,00,00,00,00,00,48,00,3c,ff,02,00,10,00,04,00,ff,ff,ff,00,56,00,45,00,3d,ff,02,00,10,00,04,00,00,00,00,00,4d,00,45,00,3e,ff,02,00,10,00,04,00,ff,ff,ff,00,55,00,73,00,3f,ff,02,00,10,00,04,00,00,00,00,00,76,00,69,00,04,00,03,00,10,00,04,00,00,00,00,00,76,00,69,00,04,00,01,00,70,02,68,02,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,ff,ff,ff,0f,00,00,00,00,00,00,00,00,01,00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,05,00,00,00,ff,ff,ff,0f,01,00,00,00,00,00,00,00,02,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,ff,ff,ff,0f,00,00,00,00,00,00,00,00,03,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,ff,ff,ff,0f,00,00,00,00,00,00,00,00,04,00,00,00,01,00,00,00,01,00,00,00,20,00,00,00,4b,00,00,00,dc,02,00,00,db,01,00,00,03,00,00,00,00,00,00,00,05,00,00,00,00,00,00,00,05,00,00,00,01,00,00,00,01,00,00,00,fb,ff,ff,ff,eb,00,00,00,b7,02,00,00,7b,02,00,00,01,00,00,00,00,00,00,80,00,00,00,00,00,00,00,00,06,00,00,00,01,00,00,00,01,00,00,00,cb,01,00,00,44,00,00,00,9a,03,00,00,e1,01,00,00,05,00,00,00,00,00,00,00,05,00,00,00,00,00,00,00,07,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,ff,ff,ff,0f,00,00,00,00,00,00,00,00,08,00,00,00,01,00,00,00,01,00,00,00,30,00,00,00,5b,00,00,00,ec,02,00,00,eb,01,00,00,01,00,00,00,01,00,00,00,0a,00,00,00,00,00,00,00,09,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,ff,ff,ff,0f,00,00,00,00,00,00,00,00,0a,00,00,00,01,00,00,00,01,00,00,00,10,00,00,00,3b,00,00,00,cc,02,00,00,cb,01,00,00,04,00,00,00,00,00,00,00,05,00,00,00,00,00,00,00,0b,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,ff,ff,ff,0f,00,00,00,00,00,00,00,00,0c,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,ff,ff,ff,0f,00,00,00,00,00,00,00,00,0d,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,ff,ff,ff,0f,00,00,00,00,00,00,00,00,00,00,03,00,10,00,08,00,05,00,00,00,70,04,00,00,01,00,01,00,38,00,2c,00,2c,00,00,00,02,00,00,00,03,00,00,00,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,88,00,00,00,7a,00,00,00,cc,04,00,00,c8,02,00,00,56,00,45,00,03,00,03,00,78,00,6c,00,04,00,00,00,02,00,00,00,64,00,00,00,14,00,00,00,00,00,00,80,02,00,00,40,07,00,00,00,95,03,00,00,00,00,00,00,4e,05,00,00,93,01,00,00,04,00,00,00,01,00,00,00,01,00,00,00,20,00,00,00,4b,00,00,00,dc,02,00,00,db,01,00,00,03,00,00,00,00,00,00,00,05,00,00,00,00,00,00,00,00,00,00,80,01,00,00,40,04,00,00,40,02,00,00,00,01,00,00,00,44,00,00,00,03,00,03,00,80,00,74,00,0a,00,00,00,01,00,00,00,64,00,00,00,14,00,00,00,00,00,00,80,03,00,00,40,07,00,00,00,c7,02,00,00,93,01,00,00,4e,05,00,00,7c,02,00,00,0a,00,00,00,01,00,00,00,01,00,00,00,10,00,00,00,3b,00,00,00,cc,02,00,00,cb,01,00,00,04,00,00,00,00,00,00,00,05,00,00,00,00,00,00,00,00,00,00,80,ff,ff,ff,0f,02,00,00,40,03,00,00,40,02,00,00,00,00,00,00,00,14,00,00,00,10,00,04,00,03,00,03,00,98,00,90,00,08,00,00,00,03,00,00,00,64,00,00,00,14,00,00,00,00,00,00,80,03,00,00,40,07,00,00,00,00,00,00,00,93,01,00,00,c7,02,00,00,7c,02,00,00,08,00,00,00,01,00,00,00,01,00,00,00,30,00,00,00,5b,00,00,00,ec,02,00,00,eb,01,00,00,01,00,00,00,01,00,00,00,0a,00,00,00,00,00,00,00,00,00,00,80,01,00,00,40,03,00,00,00,01,00,00,00,01,00,00,00,00,00,00,00,03,00,00,00,01,00,00,00,10,00,00,00,40,00,24,00,73,00,63,00,6f,00,70,00,65,00,69,00,70,00,00,00,03,00,03,00,80,00,78,00,05,00,00,00,00,00,00,00,64,00,00,00,14,00,00,00,00,00,00,80,04,00,00,40,07,00,00,00,00,00,00,00,00,00,00,00,95,03,00,00,93,01,00,00,05,00,00,00,01,00,00,00,01,00,00,00,fb,ff,ff,ff,eb,00,00,00,b7,02,00,00,7b,02,00,00,01,00,00,00,00,00,00,80,00,00,00,00,00,00,00,00,ff,ff,ff,0f,ff,ff,ff,0f,ff,ff,ff,0f,ff,ff,ff,0f,00,00,00,00,01,00,00,00,00,00,00,00,01,00,00,00,03,00,03,00,80,00,74,00,06,00,00,00,04,00,00,00,64,00,00,00,14,00,00,00,00,00,00,80,04,00,00,40,06,00,00,00,00,00,00,00,00,00,00,00,95,03,00,00,93,01,00,00,06,00,00,00,01,00,00,00,01,00,00,00,cb,01,00,00,44,00,00,00,9a,03,00,00,e1,01,00,00,05,00,00,00,00,00,00,00,05,00,00,00,00,00,00,00,00,00,00,80,02,00,00,40,04,00,00,00,00,00,00,00,05,00,00,00,e2,ff,ff,ff,00,00,00,00,55,00,73,00,01,00,03,00,10,00,04,00,05,00,00,00,76,00,69,00

 

Edited by Levis, Yesterday, 09:33 PM.

[Bài dịch] Phân tích Confuser 1.9.0.0 – Anti-tamper Protection

Xin chào các bạn,

Đây là bài dịch tiếp theo trong loạt bài dịch/bài viết tiếng Việt về Reverse Engineering .NET. Đây là bài viết của tác giả ubbelol lằm trong series “Dissecting Confuser” (Một bài dịch trước tôi đã đăng lên ở đây). Trong bài viết này tác giả sẽ nói đến cơ chế bảo vệ của Anti-tamper Protection trong Confuser và cách để vượt qua.

Các bạn có thể đọc bài dịch tại đây:

Enjoy and best regards,

Levis

[Bài viết] Các công cụ cần thiết cho quá trình Reverse Engineering .NET – Bản hoàn thiện

Xin chào các bạn,

Trong khoảng thời gian trước tôi có đăng tải một loạt bài viết với chủ đề “Các công cụ cần thiết cho quá trình Reverse Engineering .NET”. Hôm nay tôi đã tập hợp lại các bài viết (từ phần 1 đến phần 4) và bổ sung thêm phần 5, tạo thành một bài viết hoàn chỉnh, để tiện hơn trong việc lưu trữ và theo dõi. Các bạn có thể đọc bài viết tại đây:

Enjoy and best regards,

Levis

Các công cụ cần thiết cho quá trình Reverse Engineering .NET (phần 4)

Các công cụ cần thiết cho quá trình Reverse Engineering .NET (phần 3)

Các công cụ cần thiết cho quá trình Reverse Engineering .NET (phần 2)

Các công cụ cần thiết cho quá trình Reverse Engineering .NET (phần 1)

 

[Bài viết] Các thuật ngữ thường gặp trong .NET Reverse Engineering

Xin chào các bạn,

Đây là bài viết mới nhất của tôi trong loạt bài viết tiếng Việt về .NET Reverse Engineering. Trong bài viết này tôi đã tổng hợp và ghi chép lại các thuật ngữ thường gặp trong .NET Reverse Engineering, kèm theo lời giải thích và một số hình minh họa, để làm tài liệu tiện cho mọi người tra cứu. Vì được viết trong thời gian ngắn nên chưa tập hợp đủ các thông tin, thuật ngữ còn thiếu. Vậy nên, tôi rất hoan nghênh nếu các bạn có thể đóng góp những gì mình biết, bổ sung để bài viết trở nên hoàn thiện hơn. Xin cảm ơn!

Các bạn có thể đọc bài viết tại đây:

 

Enjoy and best regards,

Levis

Malware analyzing – Hello world with IDM Silent Plus Malwares

These days i joined a small campain which its main goal is to find and clear out the malware embeded inside a Cracked IDM package released by some VNese guys with name “IDM Silent Plus vx.xx”. This is very interesting because it’s my first time dealing with malware analysis. Still not completed yet, but i create this note to show my result.

 

 

At the first time, a RCE Guru (TQN) warned that the malicious application is located in folder %windir%\System32\Microsoft .NET Framework v4.5.1\Application.exe. This folder is set to Hidden and System attribute, so we could remove these attribute to get the file. When i tried to extract the idm package which contains this file, in a xpsp3 vm, i could not grab it (later i discovered that it had some anti-VM code, so the file actually won’t run). So i asked some other guy who are also analyzing it, to give me that file, to start. After a while, they gave me an archive which has Application.exe inside. And then i start analyzing.

 

 

i Scanned it using some scanner, this file is written in dotNET (vb.net, i assume that) and was protected by DeepSea Obfuscator. So i quickly threw it into de4dot to have a clean file, which is easier to read the code. After de4dot finished its job, i got a cleaned file, and then i opened this file in .NET Reflector (because it’s .NET). The first thing i did is take a look at the entrypoint of that file:

 

in this picture, it’s trying to invoke some method in GClass7, the name of that method was changed by the obfuscator. It’s not a big deal, just follow the call:

 

Here you can see that there is a string, a warning message if debugger is detected. And we have an ‘if’ statement block above. Another call? yeah, it’s another call. Keep following the code inside that call. And what we got is a bunch of code, and these code are used for anti-debugging, you can see that they invoke some winapi like isDebuggerPresent, CheckRemoteDebuggerPresent, EnumWindows. These tricks are very very useless with a .NET Application,lol. so nothing interesting here, just come back to the code at its entrypoint.We have another one call to GClass0.u(). Follow it and we see some code. Seem that this malware is trying to create some threads and execute them. And the thread proc is GClass0.c(). One more time, follow the call.

 

The picture shows the code in GClass0.c(). The one interesting line at the bottom of the method body. It calls a method: Class1.p(). What does Class1.p() actually do? Follow it, again. but we got nothing. The body of p is blank. Don’t give up, we should analyze Class1. So i browse all the method inside Class1, and get a good news in constructor method .cctor():

static Class1()

{

p = (b) Delegate.CreateDelegate(typeof(b), Class4.O, "doua");

}

 

 

So p is a delegate of a method called “doua”, and the method is located in Class4.O(). but in Class4.O(), we see nothing. And again, take a look at .cctor() method of Class4:

static Class4()

{

O = ((Class3.D) Delegate.CreateDelegate(typeof(Class3.D), typeof(Assembly).GetMethod("Load", new Type[] { typeof(byte[]) })))(Class0.L()).GetType("simplu.una");

}

The code is a bit complicated, so i will describe what it does here:- Malware will try to use Assembly.Load() to load a data stream defined by Class0.L() with name “simplu.una”.- After assembly is loaded, it creates a delegate to invoke a method with name “doua” in that assembly.

 

 

So, how we can take that assembly out to browse code of doua()? Follow Class0.L(). and you will see a extreme long string with the common schema. It’s a base64 encoded string! So we need to decode it to see the real data. Because the string is very long, so i copied to a file, named file.txt (http://pastebin.com/16iBzrtu), and made a small python script to decode and save to file:

 

 

Python code:

 


import base64

f = open("file.txt", "r")

string = f.read()

f.close()

f2 = open("newdll.dll", "wb")

f2.write(base64.b64decode(string))

f.close()

 

 

Save code and run, we got a new file named newdll.dll, and it’s the assembly which we’re looking for. This one is coded in .NET with no obfuscation, so we can easily browse the code when drop into .NET Reflector. After load that file in .NET Reflector, i start searching for method named “doua”. And it’s in a class named “una”. in doua(), you will see a lot of code, and some anti-VM and anti-sandboxies code, if detected, the malware would not run:

 

 

But those code is not as important as this one:


int timestamp = GetTimestamp();

Pack pack = new Pack();

byte[] data = ReadManagedResource(timestamp.ToString(CultureInfo.InvariantCulture));

object[] objArray = pack.Deserialize(Decrypt(data, timestamp.ToString(CultureInfo.InvariantCulture)));

FileData = (byte[]) objArray[0];

int num2 = (int) objArray[1];

int num3 = num2 * 5;

bool flag3 = (bool) objArray[2 + num3];

bool flag4 = (bool) objArray[3 + num3];

byte num4 = (byte) objArray[4 + num3];

bool flag5 = (bool) objArray[5 + num3];

string caption = objArray[6 + num3].ToString();

string text = objArray[7 + num3].ToString();

bool flag6 = (bool) objArray[8 + num3];

bool flag7 = (bool) objArray[9 + num3];

bool flag8 = (bool) objArray[10 + num3];

bool flag9 = (bool) objArray[11 + num3];

string uriString = (string) objArray[12 + num3];

string pass = (string) objArray[13 + num3];

bool flag10 = (bool) objArray[14 + num3];

bool flag11 = (bool) objArray[15 + num3];

int num5 = (int) objArray[0x10 + num3];

bool flag12 = (bool) objArray[0x11 + num3];

injectionPath = string.Empty;

Seem that it trying to get Resource in the file and decrypt the data, resource name is defined by Timestamp.ToString(CultureInfo.InvariantCulture). The GetTimeStamp() method is a type of checksum function which reads the value of specified memory address of program at runtime. But in .NET, it’s a bit harder to debug, so we can not get the value directly. So what will we do now?
Remember that doua() is used via a delegate of Application.exe. So it will takes resource of Application.exe instead of simplu.dll( the dll contains doua()) (although, the resource of simplu.dll also very supicious, i will talk later). The name is a constant and not changed in runtime, so maybe the name of resource in Application.exe is the value of timestamp. Browse the resource section of Application.exe, inside Reflector. There is only one resource with name 1406429313. So what i’ve thought above seem to be correct. let’s view the resource, we only see a very big (and complicated) data.

 

So this must be encrypted data, we have to find a way to decrypt it. go back to doua() and keep focus on the code i posted before (i copied it here to get a better look)

 


int timestamp = GetTimestamp();

Pack pack = new Pack();

byte[] data = ReadManagedResource(timestamp.ToString(CultureInfo.InvariantCulture));

object[] objArray = pack.Deserialize(Decrypt(data, timestamp.ToString(CultureInfo.InvariantCulture)));

FileData = (byte[]) objArray[0];

int num2 = (int) objArray[1];

int num3 = num2 * 5;

bool flag3 = (bool) objArray[2 + num3];

bool flag4 = (bool) objArray[3 + num3];

byte num4 = (byte) objArray[4 + num3];

bool flag5 = (bool) objArray[5 + num3];

string caption = objArray[6 + num3].ToString();

string text = objArray[7 + num3].ToString();

bool flag6 = (bool) objArray[8 + num3];

bool flag7 = (bool) objArray[9 + num3];

bool flag8 = (bool) objArray[10 + num3];

bool flag9 = (bool) objArray[11 + num3];

string uriString = (string) objArray[12 + num3];

string pass = (string) objArray[13 + num3];

bool flag10 = (bool) objArray[14 + num3];

bool flag11 = (bool) objArray[15 + num3];

int num5 = (int) objArray[0x10 + num3];

bool flag12 = (bool) objArray[0x11 + num3];

injectionPath = string.Empty;</blockquote>

 

These code:


Pack pack = new Pack();

byte[] data = ReadManagedResource(timestamp.ToString(CultureInfo.InvariantCulture));

object[] objArray = pack.Deserialize(Decrypt(data, timestamp.ToString(CultureInfo.InvariantCulture)));

 

 

The malware created a new object using class Pack. this object will be used to deserializethe decrypted data into an object array. I will re-build this class with my code to make it do the right job for me. Then the malware will read and take resource (encrypted data) out, then save it to a byte array. Call the Decrypt() method with 2 parameters: encrypted data and Timestamp (must be a key string for decryption method). we have value of timestamp – 1406429313, so the key is also “1406429313”. After decryption done, all the data will be splitted into array of object using method Deserialize() in class Pack.These code:

 

FileData = (byte[]) objArray[0];</pre>

int num2 = (int) objArray[1];

int num3 = num2 * 5;

bool flag3 = (bool) objArray[2 + num3];

bool flag4 = (bool) objArray[3 + num3];

byte num4 = (byte) objArray[4 + num3];

bool flag5 = (bool) objArray[5 + num3];

string caption = objArray[6 + num3].ToString();

string text = objArray[7 + num3].ToString();

bool flag6 = (bool) objArray[8 + num3];

bool flag7 = (bool) objArray[9 + num3];

bool flag8 = (bool) objArray[10 + num3];

bool flag9 = (bool) objArray[11 + num3];

string uriString = (string) objArray[12 + num3];

string pass = (string) objArray[13 + num3];

bool flag10 = (bool) objArray[14 + num3];

bool flag11 = (bool) objArray[15 + num3];

int num5 = (int) objArray[0x10 + num3];

bool flag12 = (bool) objArray[0x11 + num3];

injectionPath = string.Empty;
 

 

The decrypted data stored in object array before now will be assigned to each separate variables and will be used to control the malware activities. you will see that in code of doua() it will use these variable to define where to drop malware, which to drop, and how to execute newly dropped file. So we have to get all the value of these variables, to define what will actually do. And a small notice with the variable named “fileData”, it should be another malware which will be dropped onto the computer, with specified path. So, i will create a small decryptor in C# to make them automatically. Our decryptor will decrypts the resource and extracts the fileData, also shows the value of all variables.But before we get started with coding, there is one more thing to determine, that is the algorithm used to decrypt. Pretty simple, follow the call to Decrypt() to view code, and we know it’s DES.

 

 

now the time to build a decryptor. I ripped almost the code from this malware, and it’s pretty easy to understand. the code i pasted it here: http://pastebin.com/RhB9YPJ0

/*
 * Created by SharpDevelop.
 * User: Levis
 * Date: 13/08/14
 * Time: 8:21 AM
 * 
 * For further information or any question, contact me: levintaeyeon@live.com or Skype: levintaeyeon
 * My personal Blog: http://www.ltops9.wordpress.com
 ^ Team REPT Official Website: http://www.team-rept.com 
 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Security.Cryptography;

namespace get_decrypted_flag
{
    class Program
    {
        public static void Main(string[] args)
        {
            string Magic_value = "1406429313";
            Pack pack = new Pack();
            byte[] inputfile = File.ReadAllBytes(Magic_value);
            object[] objArray =pack.Deserialize(Decrypt(inputfile,Magic_value));
            byte[] FileData = (byte[]) objArray[0];
            int num2 = (int) objArray[1];
            int num3 = num2 * 5;
            bool flag3 = (bool) objArray[2 + num3];
            bool flag4 = (bool) objArray[3 + num3];
            byte num4 = (byte) objArray[4 + num3];
            bool flag5 = (bool) objArray[5 + num3];
            string caption = objArray[6 + num3].ToString();
            string text = objArray[7 + num3].ToString();
            bool flag6 = (bool) objArray[8 + num3];
            bool flag7 = (bool) objArray[9 + num3];
            bool flag8 = (bool) objArray[10 + num3];
            bool flag9 = (bool) objArray[11 + num3];
            string uriString = (string) objArray[12 + num3];
            string pass = (string) objArray[13 + num3];
            bool flag10 = (bool) objArray[14 + num3];
            bool flag11 = (bool) objArray[15 + num3];
            int num5 = (int) objArray[0x10 + num3];
            bool flag12 = (bool) objArray[0x11 + num3];
            File.WriteAllBytes("Decrypted-malware.bin",FileData);
            Console.WriteLine("num2: " +num2.ToString());
            Console.WriteLine("num3: " +num3.ToString());
            Console.WriteLine("flag3: " +flag3.ToString());
            Console.WriteLine("flag4: " + flag4.ToString());
            Console.WriteLine("num4: " +num4.ToString());
            Console.WriteLine("flag5: " +flag5.ToString());
            Console.WriteLine("Flag6: " +flag6.ToString());
            Console.WriteLine("flag7: " +flag7.ToString());
            Console.WriteLine("flag8: " +flag8.ToString());
            Console.WriteLine("flag9: " +flag9.ToString());
            Console.WriteLine("flag10: "+flag10.ToString());
            Console.WriteLine("flag11: "+flag11.ToString());
            Console.WriteLine("flag12: "+flag12.ToString());
            Console.WriteLine("num5: " +num5.ToString());
            Console.WriteLine("uriString: "+uriString);
            Console.WriteLine("Pass: "+pass);
            Console.WriteLine("Caption: "+caption);
            Console.WriteLine("Text: " +text);
            Console.ReadKey(true);
        }
        private static byte[] Decrypt(byte[] data, string pass)
        {
            byte[] src = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(pass));
            byte[] dst = new byte[8];
            Buffer.BlockCopy(src, 0, dst, 0, dst.Length);
            DESCryptoServiceProvider provider2 = new DESCryptoServiceProvider {
                Key = dst,
                IV = dst,
                Mode = CipherMode.CBC
            };
            return provider2.CreateDecryptor().TransformFinalBlock(data, 0, data.Length);
        }

    }
    
    
    public class Pack
    {
        public Pack()
        {
            Dictionary<Type, byte> dictionary = new Dictionary<Type, byte>();
            dictionary.Add(typeof(bool), 0);
            dictionary.Add(typeof(byte), 1);
            dictionary.Add(typeof(byte[]), 2);
            dictionary.Add(typeof(char), 3);
            dictionary.Add(typeof(char[]), 4);
            dictionary.Add(typeof(decimal), 5);
            dictionary.Add(typeof(double), 6);
            dictionary.Add(typeof(int), 7);
            dictionary.Add(typeof(long), 8);
            dictionary.Add(typeof(sbyte), 9);
            dictionary.Add(typeof(short), 10);
            dictionary.Add(typeof(float), 11);
            dictionary.Add(typeof(string), 12);
            dictionary.Add(typeof(uint), 13);
            dictionary.Add(typeof(ulong), 14);
            dictionary.Add(typeof(ushort), 15);
            dictionary.Add(typeof(DateTime), 0x10);
        }
        public object[] Deserialize(byte[] data)
        {
            MemoryStream input = new MemoryStream(data);
            BinaryReader reader = new BinaryReader(input, Encoding.UTF8);
            List<object> list = new List<object>();
            byte num = reader.ReadByte();
            for (int i = 0; i <= (num - 1); i++)
            {
                switch (reader.ReadByte())
                {
                    case 0:
                        list.Add(reader.ReadBoolean());
                        break;
        
                    case 1:
                        list.Add(reader.ReadByte());
                        break;
        
                    case 2:
                        list.Add(reader.ReadBytes(reader.ReadInt32()));
                        break;
        
                    case 3:
                        list.Add(reader.ReadChar());
                        break;
        
                    case 4:
                        list.Add(reader.ReadString().ToCharArray());
                        break;
        
                    case 5:
                        list.Add(reader.ReadDecimal());
                        break;
        
                    case 6:
                        list.Add(reader.ReadDouble());
                        break;
        
                    case 7:
                        list.Add(reader.ReadInt32());
                        break;
        
                    case 8:
                        list.Add(reader.ReadInt64());
                        break;
        
                    case 9:
                        list.Add(reader.ReadSByte());
                        break;
        
                    case 10:
                        list.Add(reader.ReadInt16());
                        break;
        
                    case 11:
                        list.Add(reader.ReadSingle());
                        break;
        
                    case 12:
                        list.Add(reader.ReadString());
                        break;
        
                    case 13:
                        list.Add(reader.ReadUInt32());
                        break;
        
                    case 14:
                        list.Add(reader.ReadUInt64());
                        break;
        
                    case 15:
                        list.Add(reader.ReadUInt16());
                        break;
        
                    case 0x10:
                        list.Add(DateTime.FromBinary(reader.ReadInt64()));
                        break;
                }
            }
            reader.Close();
            return list.ToArray();
        }


    }
}

 

After compiling code, then we have to extract the resource of Application.exe in Reflector and save with its name (1406429313). Copy that file to the same folder with our decryptor and run the decryptor, we will get a dumped file and all the value of variables will be shown in the console screen, like this:

 

 

We’re doing well. But right now i don’t have idea to dealing with the Decrypted-malware.bin (originally named hi.exe) which is just dumped by decryptor (another obfuscated .NET baby). Also take a look at resource section of the simplu.dll (which contains the doua() method), you will see another .NET file (named newfile.dll, no obfuscated). That’s all i’ve got so far, and i’m still analyzing that 2 files. I think this enough to stop this note. New information maybe added in another post, in future.

Here you can download the entire project which i did (malware sample + some extracted malware + decryptor source + IDM setup package):

CRITICAL CAUTION: BECAUSE THIS IS MALWARE ANALYSIS, SO YOU MUST HAVE BASIC KNOWLEDGE BEFORE DOWNLOAD THESE FILES AND USE THEM IN YOUR OWN RISK!!! I WILL NOT TAKE ANY RESPONSIBILITIES IF YOUR COMPUTER WAS INFECTED.

DOWNLOAD LINK (PASSWORD: silentisfake)

 

Regards,

Levis

[Bài dịch] Phân tích Confuser – Method proxy/Constructor proxy Confusion

Xin chào các bạn,

Confuser là một obfuscator rất nổi tiếng trong .NET, được viết bởi yck1509 (1 reverser và là 1 coder trẻ tuổi, thực sự rất giỏi). Confuser có mã nguồn mở, và hoàn toàn miễn phí, về mặt bảo mật thì có thể nói là tốt hơn so với các protector thương mại khác (một phần là do de4dot không hỗ trợ, phần còn lại thì nó thực sự khó với những ai muốn deobfuscate thủ công). Trong bài viết này, tác giả ubbelol sẽ hé lộ với các bạn về một phần trong cơ chế bảo vệ của Confuser là Method proxy / Constructor proxy confusion. Các bạn có thể dọc bản dịch tại đây:

Enjoy and best regards,

Levis

[Bài dịch] Hướng dẫn tạo Loader trong .NET

Xin chào các bạn,

Đây là bài viết tiếp theo trong loạt bài dịch .NET của tôi. Bản gốc tiếng Anh do tôi viết, cách đây không lâu , các bạn có thể tìm thấy ở đây. Còn trong topic này là bản dịch của bài viết đó. Các kiến thức tuy không mới, nhưng hi vọng sẽ hữu ích với các bạn.

Trong bài viết này, tôi sẽ hướng dẫn các bạn cách tạo 1 loader bằng C#, để patch một chương trình viết băng .NET mà không làm ảnh hưởng đến chương trình gốc.

Bài viết

Link tải crackme được sử dụng trong bài viết : DOWNLOAD MEDIAFIRE

Enjoy and best regards,

Levis

[Bài dịch] Hướng dẫn deobfuscate DotnetPatcher 3.1

Xin chào các bạn

Đây là bài tiếp theo trong loạt bài dịch về .NET Reverse Engineering của tôi.

Trong bài viết này, tác giả (ubbelol) sẽ hướng dẫn chúng ta các để deobfuscate file được bảo vệ bởi DotnetPatcher.

Các bước thực hiện chính:

– Dump file từ memory bằng Windbg để loại bỏ lớp packer

– Dùng de4dot để decrypt các string ở trong file bị obfuscate

Các bạn có thể đọc bài viết tại đây:

Enjoy and best regards,

Levis

[Tản mạn] Đạo Hacker

Nhiều bạn trẻ hiện nay rất là ham cái danh xưng “hacker”, thế rồi lao đầu vào internet, vào các forum để “tầm sư học đạo”. Mà thức ra những cái người dạy bạn ấy, chưa chắc họ có đủ kiến thức để truyền lại cho bạn 1 cách bài bản và chính xác. Họ có thể chỉ là những tay script kiddies ham cái danh hão huyền giống như bạn, nhưng họ hơn bạn vì họ có tool và biết đôi chút cách sử dụng tool. Tất nhiên thì kể cả cao thủ – các hacker xịn – cũng sử dụng tool, tuy nhiên họ sử dụng tool theo cái cách là “kiếm nhân hợp nhất” – tool và người gắn liền một thể, cùng hoạt động nhịp nhàng và hiểu rõ về nhau như những người bạn tri kỉ, tiến thoái tùy nghi không câu nệ, không gò bó. Còn các script kiddies chỉ giống như những tay võ biền cục súc, cứ có kiếm (tool) trong tay là giơ lên chém bất cứ thứ gì, không cần biết đó là kiếm gì và không cần biết mình chém cái gì, tại sao mình lại chém thứ đó.

Vì vậy tôi viết bài này, để chia sẻ với các bạn quan điểm của tôi về một cái gọi là “đạo hacker”, là những nguyên lý, những chân lý bạn cần làm theo và nên làm theo, nếu bạn muốn trở thành 1 hacker hay thứ gì đó đại loại như thế. Tôi cũng chẳng phải là 1 hacker, tôi chỉ sử dụng những nguyên lý này với chính bản thân mình vì tôi thấy nó giúp tôi rất nhiều trong việc nắm bắt kiến thức tốt hơn. “Đạo hacker” theo tôi nghĩ thì rất quan trọng, nhiều khi quan trọng hơn cả những kiến thức về mặt kí thuật

1. Phải kiên nhẫn: đây là yếu tố rất quan trọng, bởi vì nếu ta không kiên nhẫn thì không thể nào thành công được Cứ ví dụ như tôi muốn thâm nhập vào một hệ thống, tôi sẽ phải lần mò, xem xét cái hệ thống đó từng chút một để tìm ra đuợc lỗ hổng. Nếu tôi không kiên nhẫn, tôi sẽ không thể làm được việc đó bởi nó tốn nhiều thời gian và đòi hỏi sự tinh tế, nhanh nhạy của bản thân. Hầu hết những bạn trẻ thích hack hiện giờ đều chỉ quan tâm vào kết quả, chứ không chú ý đến quá trình. Thế là suy nghĩ sai lầm. Nếu bạn không có một khởi đầu tốt, và buớc những buớc đi vững vàng trong suốt cuộc hành trình, thì bạn sẽ chẳng bao giờ tới đích. Vì vậy, hãy kiên nhẫn và tỉ mỉ, ở bất cứ đâu, khi làm bất cứ việc gì.

2. Biết cách đặt những câu hỏi thông minh: Thế nào là một câu hỏi thông minh? Một câu hỏi đuợc coi là thông minh nếu như câu hỏi đó không … Ngu. Thế nào là 1 câu hỏi “ngu”? Câu hỏi ngu, theo tôi là những câu hỏi không nêu lên đuợc mục đích của người muốn hỏi, không cung cấp đuợc đủ thông tin cho người khác để họ có thể đưa ra câu trả lời, hoặc là những câu hỏi đã có quá nhiều người trả lời. Tất nhiên, không ai có thể biết tất cả mọi thứ, cách để tiếp cận kiễn thức nhanh nhất chính là việc đặt câu hỏi, hỏi chính mình, và hỏi những nguời khác. Tôi rất ngán ngẩm khi vào trong các group và thấy nhiều bạn học cntt, làm cntt đặt những câu hỏi rất chi là “trời ơi đất hỡi: ” có ai rành về abcxyz không cho mình hỏi phát”, “em muốn làm abcxyz, mọi người hãy tư vấn cho em nên bắt đầu từ đâu”,”cái này là cái gì vậy mọi người”, blah blah blah… Tất cả những câu hỏi kiểu đó tôi đều liệt vào cái dạng “hỏi ngu”. Vậy làm sao để đặt một câu hỏi thông minh? Có 1 bài viết trong HVA rất hay, nói về điều đó, hãy tìm và đọc nó.

3. Kĩ năng tìm kiếm, phân tích và suy luận: Theo tôi, “hacking is everything”, mọi thứ đều có thể dùng để hack. Nhưng cái “everything” đó, nó rộng lắm. Mà nhiều lúc bạn chỉ cần một ít trong cái “everything” đó thôi, là bạn đã đủ dùng rồi. Tài nguyên (công cụ, tư liệu, các bài thảo luận, huớng dẫn…) nhan nhản trên internet, đâu đâu cũng có. Thế nhưng, bạn cần phải biết tìm kiếm, phân tích để chọn lọc ra những gì bạn cần học, cần đọc, cần tìm hiểu trong cái mớ hỗn độn đó. Đừng hỏi tôi “làm thế nào để biết tài liệu nào mình cần?” vì tôi cho đó là một câu hỏi “ngu”. Nếu bạn không biết mình cần gì thì bạn nên dừng việc nghiên cứu lại, mà nếu biết mình cần gì rồi nhưng vẫn không tự tìm ra được những thứ đó trên internet mà phải đi hỏi người khác, thì bạn cũng nên dừng lại, bởi vì bạn chưa có đuợc cả 3 yếu tố tôi đã nói ở trên. Quan trọng nhất là bạn biết mình có những gì, mình cần làm gì để đạt đuợc những điều mình chưa có. Và khi có được thứ mình cần, thì phải biết suy luận áp dụng vào trường hợp của mình chứ đừng dập khuôn, bởi vì “hacking is everything”, là everything nên sẽ khó có hai vấn đề giống nhau y hệt được, “không ai tắm hai lần trên cùng 1 dòng sông”, vậy nên hãy biết suy luận và sáng tạo dựa trên những gì mình có

4. Chia sẻ những gì mình biết: biết nhiều hay biết ít, hãy cứ chia sẻ với mọi người. Không ai trách bạn, ngược lại họ còn ủng hộ bạn. Rồi sẽ nhận được những lời khen chê. Khen là để động viên bạn cố gắng, còn chê là để bạn biết mình còn thiếu gì, cần phải chỉnh sửa những gì để khá hơn. Chia sẻ và đón nhận phản hồi là biểu hiện cho sự cầu tiến và vì cộng đồng, những người như vậy, trong xã hội không ai là không quý.

5. Giữ vững quan điểm, không hành động vì lợi ích bản thân: Tôi nghĩ, một người chỉ biết đến riêng mình thì không bao giờ thành công. Sẽ có những lúc ta bị mờ mắt bởi những thú vui rẻ mạt. Nhiều cậu trẻ bây giờ thích thể hiện cái “tôi” và để lòe những người không biết thường đi hack site người khác rồi ghi tên mình vào đó, hay là rủ nhau đi phá Web của Tàu dạo gần đây. Tôi đặt câu hỏi: làm thế để làm gì? Không mang lại ích lợi cho cộng đồng, chỉ được mỗi cái là khoe mẽ, nhưng thực ra cũng chỉ là những script kiddies, tiêng bom thì to nhưng nhanh biến mất và để lại phía sau những vết thương nặng nề. Còn tiếng chuông, tiếng đàn thì nhẹ nhàng như vô hình, nhưng mang lại sự thảnh thơi và khoan khoái. Vậy nên, hãy học để rồi đánh đàn thay vì học để rồi đi đánh bom. Đó mới là gía trị thật sự của hack, bàn cần hiểu rõ và làm theo.

6. “Tầm sư học đạo”: đối với tôi, người thầy tốt là người đặt những câu hỏi “thông minh” cho chúng ta để giúp chúng ta khai mở đuợc tư duy, kích thích sự tìm hiểu và sáng tạo. Có một “ông thầy” bạn nên tìm học đầu tiên, đó chính là bản thân bạn. Hãy tự mình dạy mình, tự mình đặt ra những câu hỏi cho mình và tự tìm câu trả lời, Không ai hiểu bạn hơn chính bạn, cũng không ai kiên nhân với bạn hơn chính bạn. Khi bạn nhìn thấy “ông thầy” trong chính bạn rồi thì bạn đã đi đuợc một buớc rất dài trong con đuờng học tập của chính mình. “Ông thầy” thứ hai cần gặp là Google. Ông này có nhiều tài liệu, kiến thức lắm nhưng khá khó tinh, bạn phải biết đặt một câu hỏi thông minh với ông ta, thì ông ta sẽ đưa về cho bạn nhiều thứ gía trị hơn những gì bạn muốn.

Hacker là vậy, không chỉ có kiến thức sâu về công nghệ, mà cái cách họ rèn luyện bản thân, rèn luyện lối tư duy của họ mới chính là những thứ bạn cần phải học. Bây giờ internet là rộng mở, ai ai cũng tiếp cận đuợc, cho nên mọi người là bình đẳng. Xuất phát điểm như nhau, ai có quan điểm tốt, tư tưởng tốt và đúng đắn, có nghĩa là khả năng của họ tốt hơn, thì họ sẽ về đích truớc. Không ai ngu dốt yếu kém cả, chỉ là họ có chịu rèn luyện hay không thôi