PE file structure | PE file format | Portable Executable

What Is Malware?

Malware is any program or file that is harmful to a computer user. It can take the form of an executable, script, code, or any other software. (Mã độc là những phần mềm, file mà có hại cho máy tính người sử dụng. Nó có thể dưới dạng một chương trình, một đoạn mã, phần mềm...)
Malware can perform the following operations. (Phần mềm độc hại có thể thực hiện các thao tác sau)
  1. Disrupting computer operations. (Làm gián đoạn chương trình máy tính)
  2. Stealing sensitive information, including personal, business, and financial data. (Đánh cắp các thông tin nhạy cảm, gồm thông tin cá nhân, doanh nghiệp và tài chính)
  3. Unauthorized access to the victim's system. (Truy nhập trái phép vào hệ thống của nạn nhân) 
  4. Spying on the victims. (Gián điệp - theo dõi nạn nhân)
  5. Sending spam emails. Etc. (Gửi các emails rác)

Malware categorized based on behaviors. (Các loại mã độc dựa vào hành vi cư xử)

1. Ransomware.
Is software that uses encryption to disable a target’s access to its data until a ransom is paid. The victim organization is rendered partially or totally unable to operate until it pays, but there is no guarantee that payment will result in the necessary decryption key or that the decryption key provided will function properly. (Là phần mềm mà sử dụng mã hóa để vô hiệu hóa quyền truy cập của nạn nhân vào dữ liệu của họ cho đến khi đã trả tiền chuộc. Tổ chức nạn nhân không thể hoạt động một phần hoặc toàn bộ cho đến khi được thanh toán, nhưng không có gì đảm bảo khi thanh toán dẫn đến khóa giải mã  cần thiết hoặc mã giải hoạt động bình thường)
2. Fileless Malware.
Fileless malware doesn’t install anything initially, instead, it makes changes to files that are native to the operating system, such as PowerShell or WMI. Because the operating system recognizes the edited files as legitimate, a fileless attack is not caught by antivirus software — and because these attacks are stealthy, they are up to ten times more successful than traditional malware attacks. (Fileless không cài đặt bất kì thứ gì, nó làm thay đổi các files có nguồn gốc từ hệ thống, như là PowerShell hoặc WMI. Vì tổ chức hệ thống cho phép chỉnh sửa files hợp pháp, một tấn công fileless không bị lọc bởi phần mềm chống virus - và vì những tấn công này là lén nút nên hó hiệu quả hơn tấn công mã độc truyền thống 10 lần).
3. Spyware.
Spyware collects information about users’ activities without their knowledge or consent. This can include passwords, pins, payment information, and unstructured messages.
The use of spyware is not limited to the desktop browser: it can also operate in a critical app or on a mobile phone. (Phần mềm gián điệp thu thập thông tin về hoạt động của người dùng mà người dùng không biết, không có sự đồng ý của họ. Nó có thể là password, thông tin thanh toán, thông tin không có cấu trúc. Phần mềm gián điệp không bị giới hạn về trình duyệt, nó cũng có thể hoạt động trên các app hoặc trên điện thoại)
4. Adware.
Adware tracks a user’s surfing activity to determine which ads to serve them.
Although adware is similar to spyware, it does not install any software on a user’s computer, nor does it capture keystrokes. (Phần mềm quảng cáo theo dõi hoạt động lướt web để xác định dịch vụ cho họ. Mặc dù phần mềm quảng cáo giống như phần mềm gián điệp, nó không cài đặt bất cứ phần mềm nào trên máy tính người dùng và cũng không nắm bắt các thao tác gõ phím)
5. Trojan.
A Trojan disguises itself as desirable code or software.
Once downloaded by unsuspecting users, the Trojan can take control of victim's systems for malicious purposes. Trojans may hide in games, apps, or even software patches, or they may be embedded in attachments included in phishing emails. (Trojan ngụy trang bản thân nó thành các mã hoặc phần mềm. Sau khi được tải xuống bởi các người dùng không nghi ngờ, Trojan có thể kiểm soát được hệ thống của nạn nhân cho các mục đích xấu. Trojan có thể ẩn trong trò chơi, ứng dụng, thậm chí là trong bản vá phần mềm hoặc được nhúng trong các tệp đính kèm có trong mail lừa đảo.)
6. Worms.
Worms target vulnerabilities in operating systems to install themselves into networks.
They may gain access in several ways: through backdoors built into software, through unintentional software vulnerabilities, or through flash drives. Once in place, worms can be used by malicious actors to launch DDoS attacks, steal sensitive data, or conduct ransomware attacks. (Worms nhắm tới các lỗ hổng trong hệ thống để tự cài đặt vào mạng. Chúng có thể có nhiều cách truy cập khác nhau: Thông qua của hậu được xây dựng sẵn trong phần mềm, thông qua các lỗ hổng không cố ý hoặc thông qua ổ đĩa flash. Khi đã có mặt, worms có thể được sử dụng bởi các tác nhân độc hại thực thi tấn công DDoS, trộm các thông tin nhạy cảm hoặc thực thi tấn công ransomewere)
7. Virus.
Is a piece of code that inserts itself into an application and executes when the app is run.
Once inside a network, a virus may be used to steal sensitive data, launch DDoS attacks or conduct ransomware attacks.(Là một đoạn mã chèn vào bên trong các ứng dụng hoặc thực thi khi ứng dụng được chạy. Khi ở trong mạng. virus có thể trộm các thông tin nhạy cảm, tấn côn DDoS hoặc tấn công ransomeware)
8. Rootkits.
A rootkit is a software that gives malicious actors remote control of a victim’s computer with full administrative privileges.
Rootkits can be injected into applications, kernels, hypervisors, or firmware. They spread through phishing, malicious attachments, malicious downloads, and compromised shared drives.
Rootkits can also be used to conceal other malware, such as keyloggers. (Rootkit là một phần mềm cho những kẻ độc hại từ xa điều  khiển máy tính của nạn nhân với quyền truy cập của quản trị viên. Rootkit có thể được đưa vào các ứng dụng, hạt nhân, bộ giám sát hoặc firmware. Chúng lây lan qua lừa đảo, tệp độc hại, bộ nhớ dùng chung bọ tổn hại. Rootkit có thể che giấu mã độc, keyloggers)
9. Keyloggers.
A keylogger is a type of spyware that monitors user activity.
Keyloggers have legitimate uses; businesses can use them to monitor employee activity and families may use them to keep track of children’s online behaviors. (là một phần mềm gián điệp  dùng để theo dõi hoạt động của người dùng. Keyloggers có cách sử dụng hợp pháp, các doanh nghiệp có thể theo hoạt động của nhân viên, gia đình có thể dùng để theo dõi các hoạt động của trẻ)
10. Botnet.
A bot is a software application that performs automated tasks on command. They’re used for legitimate purposes, such as indexing search engines, but when used for malicious purposes, they take the form of self-propagating malware that can connect back to a central server.
Classifying malware based on their functionalities may not always be possible because a single malware can contain multiple functionalities, which may fall into a variety of categories mentioned just now. (Bot là một phần mềm ứng dụng, cho phép thực thi một cách tự động các tác vụ theo lệnh. Nó được sử dụng trong các mục đích hợp pháp, chẳng hạn các chỉ mục công cụ tìm kiếm, nhưng khi được dùng cho các mục đích xấu, chúng ở dạng phần mềm độc hại tự lan truyền, có thể tự kết nối lại với máy chủ trung tâm. Phân lại các mã độc dựa trên chức năng của nó không phải lúc nào cũng có thể  vì một mã độc có thể bao gồm nhiều chức năng, có thể thuộc nhiều loại được đề cập bên trên)

Types Of Malware Analysis.

1. Static analysis.
Static analysis is a process of analyzing a malware binary without actually running the code. Static analysis is generally performed by determining the signature of the binary file which is a unique identification for the binary file and can be done by calculating the cryptographic hash of the file and understanding each component.
2. Dynamic analysis.
Dynamic analysis is involves running the malware sample and observing its behavior on the system in order to remove the infection or stop it from spreading into other systems. The system is setup in a closed, isolated virtual environment so that the malware sample can be studied thoroughly without the risk of damage to your system.
3. Code analysis.
Code analysis is an advanced technique that focuses on analyzing the code to understand the inner workings of the binary. This technique reveals information that is not possible to determine just from static and dynamic analysis. Code analysis is further divided into Static code analysis and Dynamic code analysis.
PE File Structure
PE format is actually a data structure that tells Windows OS loader what information is required in order to manage the wrapped executable code.
This includes dynamic library references for linking, API export, and import tables, resource management data, and TLS data. The data structures on disk are the same data structures used in the memory and if you know how to find something in a PE file, it will help while analyzing any Windows malware samples.

DOS Header.

DOS Header occupies the first 64 bytes of the file. DOS Header there because DOS can recognize it as a valid executable and can run it in the DOS stub mode.


As we can see we have a list of structures that came under the DOS header. We will not discuss everything as it is beyond our scope; we will discuss important ones that are required, such as e_magic and e_lfanew structure.
e_magic: Determine whether a file is a PE file. A list of file signatures can be found Here
e_lfanew: Offset relative to the beginning of the file, used to find the PE header.

As shown in the above figure e_magic value is 4D 5A (MZ) and e_lfanew is 0x00000108 (PE File header address)

DOS Stub.

A stub is a tiny program or a piece of code that is run by default when the execution of an application starts. This stub prints out the message “This program cannot be run in DOS mode” when the program is not compatible with Windows.

PE File Header.

The PE header is located by looking at the e_lfanew field of the MS-DOS Header. The e_lfanew field gives the offset of the PE header location.
The main PE Header is a structure of type IMAGE_NT_HEADERS and mainly contains PE signature, IMAGE_FILE_HEADER, and IMAGE_OPTIONAL_HEADER.
The Standard PE header is the next 20 bytes of the PE file and contains only the most basic information about the layout of the file.
In the Example the first member (Magic, 2Byte): the magic number 020B, which means that the file is a 64-bit PE.
The optional PE header is followed by the standard PE header, and its size is 32-bit default E0H, 64-bit default F0H bytes. The optional header contains most of the meaningful information about the executable image, such as initial stack size, program entry point location, preferred base address, operating system version, section alignment information.

Data Directories (_IMAGE_DATA_DIRECTORY)

It is the last entry of the Optional Header. The data directory indicates where to find other important components of executable information in the file. It is really nothing more than an array of IMAGE_DATA_DIRECTORY structures that are located at the end of the optional header structure. The current PE file format defines 16 possible data directories, 11 of which are now being used.Then use the virtual address to determine which section the directory is in. Once you determine which section contains the directory, the section header for that section is then used to find the exact file offset location of the data directory.

Section Header Table

Section Header Table is an array of IMAGE_SECTION_HEADER structures and contains information related to the various sections available in the image of an executable file. The sections in the image are sorted by the RVAs rather than alphabetically.
Sections Headers Table contains the following important fields:
  • Name
  • Virtual Size
  • Virtual Address
  • Raw Size
  • Raw Address
  • Reloc Address
  • Linenumbers
  • Relocations Number
  • Linenumbers Number
  • Characteristics
Sections
PE section headers also specify the section name using using a simple character array field, called as Name. Below are the various common sections names available from an executable file:
  • .text: This is normally the first section and contains the executable code for the application. Inside this section is also an entry point of the application: the address of the first application instruction that will be executed. An application can have more than one section with the executable code.
  • .data: This section contains an initialized data of an application such as strings.
  • .rdata or .idata: Usually these section names are used for the sections where the import table is located. This is the table that lists the Windows API used by the application (along with the names of their associated DLLs). Using this, the Windows loader knows the API to find, in which system DLL, in order to retrieve its address.
  • .reloc: contains relocation information.
  • .rsrc: This is the common name for the resource-container section, which contains things like images used for the application’s UI.
  • .debug: contains debug information.


 

(https://malware.gitbook.io/malware-analysis/pe-file-structure)

Nhận xét