Tổng hợp bài viết cho người bắt đầu phân tích mã độc
Bài viết này tổng hợp tất cả blogs, ghi chú...về quá trình bắt đầu học phân tích mã độc.
(This article is a summary of many blogs, notes...about starting malware analysis in both English and Vietnamese languages).
1. Source https://hshrzd.wordpress.com/how-to-start/
How to start RE/malware analysis?
Many people approach me asking more or less the same questions: how to start RE, how to become a malware analyst, how did I started, what materials I can recommend, etc. So, in this section I will collect some hints and useful links for the beginners.
//WARNING: this article is a work-in-progress
The topic of reverse engineering (RE) is very broad. You can reverse engineer all sort of software for all sort of platforms. You can even reverse engineer hardware. But in this article I will focus mostly on the subset of skills that you need for analyzing malware on Windows.
Tools & environment
In order to not infect yourself, you need to prepare an isolated virtual environment with all the tools installed, where you can deploy the malware sample and analyze it. More details:
- Malware analysis for N00bs – part 1: malware and the tools for its analysis (slides)
- Malware Analysis Virtual Machine – by OALabs
- Creating a Simple Free Malware Analysis Environment – by MalwareTech
- Reviews of various tools for reverse engineering
Learning tools
Among the tools that you will use on daily will be debuggers and disassembles, such as IDA, Ghidra, OllyDbg (or some of its derivatives such as ImmunityDbg), x64dbg. Very useful and advanced, but not as user-friendly is WinDbg – also worth to learn it, but I don’t recommend it to beginners. Below you will find some courses that will help you familiarize with those tools:
- Reversing with Lena151 – learn OllyDbg (old, but still very useful)
- TiGa’s course on IDA Pro
- Introduction to WinDbg by Anand George
How to get malware samples, intelligence etc.?
If you are a beginner and not a member of any community yet, you can find fresh, nicely cataloged samples for free here:
You can also download them from some of the free online sandboxes and open repositories, such as:
For a threat intelligence, information about outbreaks, hashes of fresh samples etc, I recommend you to join twitter and follow some of the researchers that you know.
As you will become more proficient, I recommend you to join also this community:
Check also some malware trackers, where you can find live links to the latest malware, and some more information about campaigns:
Exercises
Reversing is an art that you can learn only by doing, so I recommend you to start practicing directly. First try to practice by following step-by-step writeups.
- Beginner Malware Reversing Challenges (by Malware Tech)
- Malwarebytes CrackMe #1 + tutorial
- Malwarebytes CrackMe #2 + list of write-ups
- https://crackmes.one/ – various crackmes to help you exercise reversing
Check also writeups from an annual FlareOn Challenge. It contains variety of reverse engineering tasks with growing difficulty level.
Inside the compiled application
Reversing a native application requires you to understand some low-level concepts. If you want to focus on Windows malware (as I do), you will most of the time be dealing with PE files. When you watch an application under a debugger, you see it in a disassembled form – transformed to assembly language (assembler). So, the more about assembler, PE structure, and operating system you know, the easier will be for you to follow. Here and here you will find some gentle introduction to x86 assembly. To get a deeper understanding and a grasp on other platforms too, check this free book.
For learning the PE format, I recommend you to read [this] + the articles of Matt Pietrek (i.e. [1] [2] [3]), and Ange Albertini’s posters (PE101, PE102). Check also PE-bear and try to view various executables, compare it with what you read about the format.
Programming for RE/malware analysis
Not all malware analysts are proficient programmers, but you need to have some basic skills, and at least be able to understand the code. The more fluent programmer you are, the better for you – you will be able to experiment with the techniques and create some tools helping you in analysis.
The languages that I use on daily are C/C++, Python, and assembler, and I am mostly agree with [this] MalwareTech’s article.
Some people ask me from where I learned particular languages, so here are some of the sources:
- x86 Assembler:
- C/C++
- “The C Programming language” – by Kernighan & Ritchie
- “The C++ Programming language“
- “Linux Programming by example” – by Kurt Wall
“Windows System Programming” is a very solid book covering Windows API and the related topics.
Malware unpacking
Malware usually comes packed, and in order to analyze the core you will have to unpack it from the outer, protective layer. Malware distributors may use legitimate, well-known packers and protectors, as well as custom ones, prepared with a special focus on AV evasion. This article explains the concept.
To get familiar with manual unpacking, check the series of tutorials “Unpacking With Anthracene” [1][2][3][4], and other tutorials from Tuts4You.
My vidoetutorials about unpacking malware are available here.
Malware injection methods
Most of the malware injects code into other processes. The common purposes of injections are: impersonating other applications and hooking. Used methods are various. The most popular is Process Hollowing (aka RunPE) and Reflective DLL injection.
Hooking
Hooking is a technique that allows to intercept API calls. Malware uses this technique for various purposes, such as: being unnoticed by monitoring applications, intercepting the data being sent etc. From the other hand side, the same technique is also used by sandboxes, to monitor malware.
How the hooking works:
How a simple, userland rootkit utilizes hooking:
Kernel Mode malware
Most of the malware you will encounter works in userland. But from time to time you can come across some kernel mode malware modules. Reversing them is more difficult, and it will require different environment setup.
Setting up the environment for analyzing malware in kernel mode will follow the same steps as I described for Windows Kernel Exploitation practice, here:
Below, you can find a very nice tutorial about reversing a kernel more rootkit:
More about techniques used by kernel mode rootkits you will find, i.e. here:
- https://resources.infosecinstitute.com/hooking-idt/
- https://www.adlice.com/kernelmode-rootkits-part-1-ssdt-hooks/
- https://www.adlice.com/kernelmode-rootkits-part-2-irp-hooks/
- https://www.adlice.com/kernelmode-rootkits-part-3-kernel-filters/
Courses
- https://www.begin.re/ – Reverse Engineering for beginners
- Reverse Engineering Malware 101 and 102 – by MalwareUnicorn
- http://legend.octopuslabs.io/sample-page.html
- http://opensecuritytraining.info/Training.html
- https://samsclass.info/126/126_S17.shtml – Practical Malware Analysis
- Malware Analysis course (University of Cincinnati)
YouTube channels
Books
- Practical Malware Analysis: A Hands-On Guide to Dissecting Malicious Software
- The Art of Computer Virus Research and Defense – Peter Szor (old but very good book)
- Malware Analyst’s Cookbook and DVD: Tools and Techniques for Fighting Malicious Code
- Hacker Disassembling Uncovered – by Kris Kaspersky
- The Rootkit Arsenal: Escape and Evasion in the Dark Corners of the System
- Rootkits and Bootkits – by Alex Matrosov, Eugene Rodionov, and Sergey Bratus
- Windows System Programming (4th edition) – by Johnson M. Hart
- Gray Hat Python
Tips & ideas
- “How to Become (and Remain) a Malware Researcher” – by Todd Cullum
- “How to become the best Malware Analyst E-V-E-R” – by Hexacorn
- “So You Want To Be A Malware Analyst” – by Adam Kujawa
How to get a job as malware analyst?
From my experience, the best way is to contribute in the community. Be active, start researching on your own, show your passion, share what you learned. There is a big and very friendly community of researchers on twitter, it helped me a lot finding a job in this field. So, if you are not there yet, I strongly recommend you to join.
2. Tips in RE/Malware Analysis (Source: Link)
Yourself
- Don't be afraid about new stuff.
- There is no age limitation for learning RE/Malware analysis.
- Don't believe that new field like reverse engineering is extremely hard, it's in fact easier than you think
- When you have no idea about what the malware do, don't think at first that you are bad/rookie, it means that you will learn new stuff, it's the most important thing to notice.
- Mistake are part of the process, and it's important to make mistakes.
- Mistake/Failures are probably one of the best thing that could happen to you, it's incredibly worth for learning.
- You will learn during all your life, don't think that you have to know "everything" in the first days, it's impossible to know litterally everything in that field, just take your time.
- Papers, Work, Projects, Tools are proofs that you have done something, popular or not, it's a satisfaction to some work done.
- Don't hurry on something new, it's the best way to make irreversible mistakes.
- Frustration is part of the process, learn to deal with it.
- if you someone said to you that it's mandatory to have certifications or required diploma in IT for starting this field, this dude is ridiculous.
- It's stupid to say it's impossible whenever you didn't try it once.
- Don't hesitate to ask, we eat ASM code not people.
- Unable to do some tasks that others succeeded with no problem, doesn't mean that you sucks, it will just take more times for you.
Learning
- Notes are mandatory
- Practice, Practice, Practice...
- There is no fundamental path into RE/Malware Analysis, i could say that everyone path is different even if some branches are identicals.
- Write some programs and do some reverse on them (Also play with the compilers options to understand the differences).
- In my opinion, it's better that you take your time with a few analysis tools/software than a dozens.
- Read a lot of code, if you think it's decent to run it, compiled and do some RE again.
- Something that you don't understand one day, you will get it on another case and will blow your mind... this is some magic that i love when it comes.
- If english is not your main language, learn this one and put your notes/papers/comments in that language. It's easier to show your work to others.
- When people say it's expensive to learn RE i could say they are wrong, i've build my first lab setup with low-cost computers threw on streets and free softwares so...
- Some CTF/CrackMe challenges are fun ways to learn also some interesting things.
- Take breaks, especially when you have struggles in some analysis.
- 20/30 min dedicated everyday on reading/analyzing new stuff shared by the community is incredibly worth after weeks, months. (don't forget to make notes about it)
- Specialized websites
- Technical Papers
- Read In-Depth Malware Technical Analysis, reverse the malware with the paper nears you.
- Learn to recognize API kernel functions, this will help you to understand what the malware do.
- Reverse program that you like, to discover some exciting new contents
- Read Books, Tutorials (most of them are free)
- Watch Security Conferences, Security Tutorials (They are nowadays accessibles easily and free).
- Reversing old games are a really fun way to check your basics.
Malware Analysis
- If you want to verify something for a malware, don't look on the sandbox but read/eat the code, the code never lies (in sort of).
- Reverse everything that dig your curiosity, even if it's stupid, you will learn somewhat something, for further investigations.
- A specific POST/GET request pattern doesn't mean this is always the same malware, be careful about this.
- It's better to focus on one family than multiple, take your time, nobody will push you to do other things, it all up to you to decide. [Ransomware / Banker / Infostealers / Loaders...]
- Of course, when you considered that you have seen all the apsect of one, go to another one but always keep an eye on new species.
- Never trust tags, comments on sandboxes, VT, and others...
- Seriously, never trust tags, comments on sandboxes, VT, and others...
- Tags are for guidance, must be only used for search as first guidance not as final clue.
Updating...
What's Your Reaction?