본문 바로가기
OffSec

[Blue Teams Academy] 모듈 15 - Radare2로 정적 멀웨어 분석을 수행하는 방법

by 10th doctrine 2021. 3. 19.
728x90

이 기사에서는 Radare2로 정적 멀웨어 분석을 수행하는 방법을 살펴보기로 한다.

소스

기술적 세부사항을 살펴보기 전에 먼저 멀웨어 분석이란 무엇이며 이를 수행하기 위한 다양한 접근방식은 무엇인지를 살펴봅시다.

멀웨어 분석은 바이러스, 웜, 트로이 목마, 루트킷 또는 백도어와 같은 특정 멀웨어 샘플의 기능, 출처 및 잠재적 영향을 결정하는 기술이다. 악성 소프트웨어 분석가로서 우리의 주된 역할은 악성 소프트웨어에 대한 모든 정보를 수집하고 감염된 기계에 무슨 일이 일어났는지 잘 이해하는 것이다. 다른 프로세스와 마찬가지로 악성 프로그램 분석을 수행하려면 일반적으로 특정 방법론과 여러 단계를 따라야 한다. 멀웨어 분석을 수행하려면 다음 세 단계를 수행하십시오.

  • 정적 멀웨어 분석
  • 동적 멀웨어 분석
  • 메모리 멀웨어 분석

정적 멀웨어 분석

정적 멀웨어 분석이란 멀웨어 샘플을 실행하지 않고 검사하는 것을 말한다. 악성 바이너리에 대한 모든 정보를 제공하는 것으로 구성된다. 정적 분석의 첫 번째 단계는 MD5 또는 SHA1과 같은 암호 해시가 샘플 파일의 고유 식별자 역할을 할 수 있기 때문에 해싱 값을 결정하는 것 외에 대상 시스템에 대해 명확한 비전을 갖는 멀웨어 크기와 파일 유형을 아는 것이다. 더 깊이 잠수하려면 문자열을 찾고, 이진 파일을 해부하고, IDA와 같은 분해기를 사용하여 악성코드의 코드를 역설계하는 것이 프로그램 지침을 연구함으로써 악성코드가 어떻게 작동하는지 알아보는 좋은 단계가 될 수 있다. 맬웨어 작성자는 종종 다음과 같은 작업을 수행하려고 한다.

맬웨어 분석가들의 작업은 더 어려워지기 때문에 그들은 항상 포커와 암호기를 사용하여 탐지를 회피한다. 그렇기 때문에 정적 분석 중에는 PEiD와 같은 도구를 사용하여 검출할 필요가 있다.

동적 멀웨어 분석

정적 분석을 수행하는 것만으로는 멀웨어의 실제 기능을 완전히 이해할 수 없다. 그렇기 때문에 격리된 환경에서 멀웨어를 실행하는 것이 멀웨어 분석 프로세스의 다음 단계다. 이 단계에서 분석가는 악의적인 이진의 모든 행동을 관찰한다. 동적 분석 기법은 DNS 요약, TCP 연결, 네트워크 활동, syscall 등을 포함한 모든 멀웨어 활동을 추적한다.

메모리 멀웨어 분석

메모리 악성 프로그램 분석은 디지털 조사와 악성 프로그램 분석에 널리 사용된다. 악성코드를 실행한 후 대상 시스템에서 덤핑된 메모리 이미지를 분석하여 네트워크 정보, 실행 프로세스, API 후크, 커널 로딩 모듈, Bash history 등 여러 가지 전문적 자료를 획득하는 행위를 말한다... 멀웨어 기능을 보다 명확하게 이해하는 것이 항상 좋은 생각이기 때문에 이 단계가 매우 중요하다. 메모리 분석의 첫 번째 단계는 다양한 수의 유틸리티를 사용하여 기계의 메모리를 덤핑함으로써 메모리를 획득하는 것이다. 이러한 도구 중 하나는 fmem인데, 이것은 /dev/fmem이라는 새로운 장치를 만들어 전체 메모리에 직접 액세스할 수 있도록 하는 커널 모듈이다.

멀웨어 분석을 수행하려면 멀웨어 랩을 구축하십시오. 이 방법을 배우려면 내 글을 읽어보길 강력히 추천한다.

Radare2를 사용하여 정적 멀웨어 분석을 수행하는 방법

관계자에 따르면

Github 계정:

Radare2 __는 유닉스 같은 __ 역 엔지니어링 __ 프레임워크 __ 및 __ 명령줄__ 도구다.

출처: https://rada.re/r/img/webui.png

그것은 역공학적인 도구 그 이상이다. R2는 다른 많은 작업을 수행할 수 있다. 보통은 라다레2를 배우기가 힘들겠지만 잠시 후 대부분의 특징을 잘 이해하게 된다.

소스

이 훌륭한 도구를 탐구하는 것으로 시작합시다. 시범적으로, 우리는 그것을 가지고 정적 악성 프로그램 분석을 수행하는 방법을 배울 것이다. 일반적으로 정적 분석에서는 이러한 작업을 수행하고 다음을 포함한 많은 정보를 수집해야 한다.

  • 파일 형식 및 아키텍처
  • 파일 지문 및 해시
  • 줄들
  • 난독화 해독
  • 패커 및 암호화 결정
  • 헤더정보
  • 분류 및 야라 규칙
  • 온라인 AV 검색(자세한 내용은 내장된 문서 확인)

Radare2 설치:

R2를 사용하기 전에 먼저 설치해야 한다.

$ \<a class="data-id="TMLH8gEnq2rpQjkH" 데이터 유형="Tag" href="/ref/git"\>git 클론 \

cd radare2

설치:

$ sys/install.sh

라다레2는 라빈2, 라디프2, 락스2, rasm2 등과 같은 많은 도구를 포함하고 있다...

Kali Linux를 사용하는 경우 다음을 입력하여 직접 사용할 수 있다.

r2

시연을 위해 "멀티 플랫폼 리눅스 라우터 DDoS ELF"를 다운로드했다.

앞서 논의한 바와 같이 먼저 이진에 대한 정보를 얻어야 한다.

rabin2 -I halfnint

데이터 섹션에서 문자열을 추출하려면 다음을 입력하십시오.

rabin2 -z halfnint

이진법 로드

radare2 halfnint

정보를 얻으려면 " i " 옵션을 사용하십시오. 다음을 입력하여 사용 가능한 모든 수집 정보를 확인하십시오.

i?

예를 들어 내보내기 유형에 대한 정보를 수집하는 방법:

iE

수입:

ii

머리 글:

ih

해시 유형을 계산하려면:

rahash2 -a all halfnint

To determine the packers usually, we use PEiD

source

But it is a bit outdated, thus, There is Yara support in r2 and PEiD signatures are available in Yara format.

리비아라를 설치하다

r2pm init

r2pm -i yara3-lib

요약

이 모듈에서는 멀웨어 분석을 수행하기 위한 다양한 기법을 살펴보았다. 나중에 우리는 "Radare2"라는 놀라운 도구를 설치하는 방법과 정적 멀웨어 분석 작업을 수행하는 데 사용하는 방법을 배웠다.

참조:

  1. Chiheeb Cebbi "Malware Analysis a Machine Learning Access" eForensics Magazine 발행/2017
  2. 치헵 체비: 생성 상대 네트워크를 통해 머신러닝 멀웨어 탐지기를 바이패스하는 방법
  3. https://github.com/radare/radare2/blob/master/doc/yara.md

 

더보기

How to Perform Static Malware Analysis with Radare2

In this article, we are going to explore how to perform static malware analysis with Radare2.

source

Before diving into technical details let's explore first what is malware analysis and what are the different approaches to perform it.

Malware analysis is the art of determining the functionality, origin and potential impact of a given malware sample, such as a virus, worm, trojan horse, rootkit, or backdoor. As a malware analyst, our main role is to collect all the information about malicious software and have a good understanding of what happened to the infected machines. Like any process, to perform a malware analysis we typically need to follow a certain methodology and a number of steps. To perform Malware Analysis we can go through three phases:

  • Static Malware Analysis
  • Dynamic Malware Analysis
  • Memory Malware Analysis

Static Malware analysis

Static malware analysis refers to the examination of the malware sample without executing it. It consists of providing all the information about the malicious binary. The first steps in the static analysis are knowing the malware size and file type to have a clear vision about the targeted machines, in addition to determining the hashing values, because cryptographic hashes like MD5 or SHA1 can serve as a unique identifier for the sample file. To dive deeper, finding strings, dissecting the binary and reverse-engineering the code of malware using a disassembler like IDA could be a great step to explore how the malware works by studying the program instructions. Malware authors often are trying to make

the work of malware analysts harder so they are always using packers and cryptors to evade detection. That is why, during static analysis, it is necessary to detect them using tools like PEiD.

Dynamic Malware analysis

Performing static analysis is not enough to fully understand malware's true functionality. That is why running the malware in an isolated environment is the next step for the malware analysis process. During this phase, the analyst observes all the behaviours of the malicious binary. Dynamic analysis techniques track all the malware activities, including DNS summary, TCP connections, network activities, syscalls and much more.

Memory Malware analysis

Memory malware analysis is widely used for digital investigation and malware analysis. It refers to the act of analysing a dumped memory image from a targeted machine after executing the malware to obtain multiple numbers of artefacts including network information, running processes, API hooks, kernel loaded modules, Bash history, etc. ... This phase is very important because it is always a good idea to have a clearer understanding of malware capabilities. The first step of memory analysis is memory acquisition by dumping the memory of a machine using a various number of utilities. One of these tools is fmem, which is a kernel module to create a new device called /dev/fmem to allow direct access to the whole memory

To perform malware analysis you need to build a malware lab. To learn how to do it, I highly recommend you to read my article:

How to perform static malware analysis with Radare2

According to its official

Github account:

Radare2 __ is unix-like __ reverse engineering __ __ framework __ and __ command line__ tools

Source: https://rada.re/r/img/webui.png

It is more than a reverse engineering tool. R2 is able to perform many other tasks. Usually, you will find it hard to learn Radare2 but after a while, you will acquire a good understanding of most of its features.

Source

Let's get started by exploring this great tool. As a demonstration, we are going to learn how to perform some static malware analysis with it. Usually, in the static analysis, we need to perform these tasks and to collect many pieces of information including:

  • File type and architecture
  • File fingerprinting and hashes
  • Strings
  • Decoding obfuscation
  • Determining Packers and Cryptors
  • Header information
  • Classification and Yara Rules
  • Online AV Scanning (Check the embedded article for more information)

Radare2 installation:

Before using R2 we need to install it first.

$ \git clone \https://github.com/radare/radare2.git\

cd radare2

and install it:

$ sys/install.sh

Radare2 contains many tools such as rabin2 , radiff2 , rax2 , rasm2 etc...

If you are using Kali Linux you can use it directly by typing:

r2

For the demonstration, I downloaded "Multi-Platform Linux Router DDoS ELF".

As discussed previously first we need to obtain information about the binary:

rabin2 -I halfnint

To extract the string from the data section type:

rabin2 -z halfnint

Load the binary

radare2 halfnint

To get information use the " i " option. Check all the available gathered information by typing:

i?

For example to collect information about Exports type:

iE

Imports:

ii

Headers:

ih

To calculate the hashes type:

rahash2 -a all halfnint

To determine the packers usually, we use PEiD

source

But it is a bit outdated, thus, There is Yara support in r2 and PEiD signatures are available in Yara format.

install libyara

r2pm init

r2pm -i yara3-lib

Summary

In this module, we explored the different techniques to perform malware analysis. Later we learned how to install an amazing tool called "Radare2" and how to use to perform some static malware analysis tasks.

References:

  1. Chiheb Chebbi "Malware Analysis a Machine Learning Approach" eForensics Magazine Issue 07/2017
  2. Chiheb Chebbi: How to bypass Machine Learning Malware Detectors with Generative adversarial Networks
  3. https://github.com/radare/radare2/blob/master/doc/yara.md

 

 

※ 출처 : Blue Teams Academy | www.blueteamsacademy.com/radare2/

반응형

댓글