본문 바로가기
OffSec

[Blue Teams Academy] 모듈 19 - 메모리 분석 수행 방법

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

메모리 분석 수행 방법

출처: 멀웨어 분석-virtual-box-사이버-forensicator.jpg

추상

맬웨어 위협은 오늘날 정보 보안에서 매우 심각한 문제다. 위험한 해커들은 보안 계층을 우회하고 탐지를 피하기 위해 매일 새로운 기술을 발명하고 있다. 따라서, 기억력 결핍증을 어떻게 분석해야 하는지를 알아내야 할 때다.

하지만 이번에는 모든 포렌식 전문가와 멀웨어 분석가에게 필요한 기술이기 때문에 더 많은 메모리 분석을 더 자세히 하고자 한다.

본 기사에서는 다음 내용을 알아보십시오.

  • 기억 해부
  • 메모리 관리
  • 컴퓨터 포렌식 분석 단계
  • 디지털 증거 획득
  • 메모리 수집
  • 메모리 분석
  • 변동성 Framework
  • 메모리 분석 최선의 안정성 구현 방법

메모리 분석

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

메모리 악성 프로그램 분석은 디지털 조사와 악성 프로그램 분석에 널리 사용된다. 악성코드를 실행한 후 대상 시스템에서 덤핑된 메모리 이미지를 분석하여 네트워크 정보, 실행 프로세스, API 후크, 커널 로딩 모듈, Bash history 등 여러 가지 전문적 자료를 획득하는 행위를 말한다... 멀웨어 기능을 보다 명확하게 이해하는 것이 항상 좋은 생각이기 때문에 이 단계는 매우 중요하다.

  • 프로세스 목록 및 관련 스레드
  • 네트워킹 정보 및 인터페이스(TCP/UDP) • 숨겨진 모듈을 포함한 커널 모듈
  • 커널에서 열린 파일
  • 바쉬와 역사를 지휘한다.
  • 시스템 호출 • 커널 후크

기억 해부

우리가 메모리 덤프를 분석하는 방법을 배우려면 먼저 메모리가 무엇인지, 어떻게 작동하는지 탐구해야 한다.

기억은 컴퓨터 구조에서 필수적인 요소다. 컴퓨터는 다음과 같이 구성된다.

  • CPU
  • 관제사
  • 메모리

전체 아키텍처는 다음 그래프에 설명된다.

source overnor.properties

메모리 분석에서 우리는 RAM s를 다루고 있다.

__RAM(pronled ramm)은 임의로 액세스할 수 있는 컴퓨터 메모리의 일종인 랜덤 액세스 메모리의 약자다. 즉, 메모리의 어떤 바이트도 이전 바이트를 건드리지 않고 접근할 수 있다. RAM__은 서버, PC, 태블릿, 스마트폰, 그리고 프린터와 같은 다른 장치들에서 발견된다. RAM은 휘발성이 있다.

출처: RAM061711.jpg

메모리는 4,096바이트의 메모리 청크로 구분되어 내부 처리가 용이하다. 12개의 최하위 비트는 오프셋이고 나머지는 페이지 번호다. 예를 들어 최근의 x86 아키텍처에서 Linux 커널 가상 공간(일반적으로 4GB)을 UserLand 전용 3GB, 커널랜드 전용 1GB로 나눈다. 이 작업을 분할이라고 한다. 커널은 물리적 주소와 가상 주소 간의 통신에 페이지 테이블을 사용한다. 다양한 메모리 영역을 관리하려면 VMA(가상 메모리 영역)를 사용하십시오.

스택은 특별한 기억 공간이다. 프로그래밍에서 푸시(push)와 팝(pop)이라는 두 가지 연산을 사용하여 요소를 수집하는 데 사용되는 추상 데이터 유형이다. 이 구간은 자동으로 커지지만, 다른 메모리 구간과 가까워지면 문제가 발생하고 시스템이 혼란스러워진다. 공격자가 이 기법을 이용해 시스템을 다른 메모리 영역과 혼동하는 이유다.

은 동적 메모리 할당에 사용된다. 스택처럼 RAM에 상주하지만 속도가 더 느리다. 커널 힙은 다음과 같은 세 가지 유형의 할당자를 사용하고 있다.

  • SLAB: 이것은 캐시 친화적인 할당자 입니다.
  • 단순 블록 목록(SLOB): 이것은 작은 시스템에 사용되는 할당자 입니다. 퍼스트핏 알고리즘을 사용한다.
  • SLUB : 기본 Linux 할당자 입니다.

메모리 체크의 세부 섹션을 자세히 살펴보십시오.

여기에서 더 나은 해상도 메모리 세그먼트화 시트

메모리 관리

메모리 관리는 모든 운영 체제에서 중요한 기능이다. 리눅스 커널에도 통합되어 있다. 리눅스는 메모리를 가상으로 관리한다. 즉, 물리적 메모리 주소와 프로그램이 사용하고 보는 주소 사이에는 일치성이 없다. 이 기술은 사용자 개발자에게 유연성을 제공한다. 리눅스는 다음과 같은 5가지 유형의 주소를 처리하고 있다.

  1. 사용자 가상 주소
  2. 실제 주소
  3. 버스 주소
  4. 커널 논리 주소
  5. 커널 가상 주소

컴퓨터 포렌식 분석 단계

NIST는 포렌식을 다음과 같이 설명하고 있다.

포렌식 수행의 가장 일반적인 목표는 그 사건과 관련된 사실들을 찾아내고 분석함으로써 관심의 사건을 더 잘 이해하는 것이다. 법적 절차와 내부 징계를 위한 증거 수집, 멀웨어 사고 및 비정상적인 운영 문제 처리 등 여러 가지 상황에서 포렌식 조사가 필요할 수 있다. _

컴퓨터 포렌식 분석은 다른 방법론적 조작과 마찬가지로 수집, 검사, 분석 및 보고라는 잘 정의된 단계를 거친다. 다음 단계를 하나씩 살펴봅시다.

  1. 수집: 데이터 소스 식별 및 무결성 확인
  2. 검사: 수집된 데이터에서 관련 정보의 평가 및 추출
  3. 분석
  4. 보도

이 단계는 과학 수사 기법을 사고 대응 통합하는 NIST 가이드에 기초한다. 자세한 절차 탐색(과학 수사 절차 수행)을 적극 권장한다.

출처: 니스타+프로세스.jpg

디지털 증거 획득

디지털 증거를 분석하기 때문에 세심하게 다룰 필요가 있다. 또한, 우리는 나중에 법적 절차 내에서 그것들을 사용할 필요가 있다. Eliézer Pereira는 그의 논문 RAM 메모리 포렌식 분석에서 가장 휘발성이 강한 것부터 가장 덜 휘발적인 것까지 다음과 같이 우선순위를 매겼다.

메모리 수집

메모리 분석의 첫 번째 단계는 다수의 유틸리티를 사용하여 기계의 메모리를 덤핑함으로써 메모리를 획득하는 것이다. 이러한 도구들 중 하나는 fmem인데, 이것은 /dev/fmem이라는 새로운 장치를 만들어 전체 메모리에 직접 접근할 수 있도록 하기 위한 커널 모듈이다. 공식 리포지토리에서 다운로드하여 컴파일한 후 다음 명령을 사용하여 시스템 메모리를 획득할 수 있다.

# dd if=/dev/fmem of=... bs=1MB count=...

또 다른 도구는 리눅스 메모리 추출기 입니다. 라임은 안드로이드 등 리눅스 기반 기기에서 휘발성 메모리 획득을 허용하는 LKM(Loadable Kernel Module)이다.

다음은 사용 가능한 메모리 수집 도구:

유용한 도구의 전체 목록은 여기에서 확인할 수 있다. 도구: 메모리 이미징(https://www.forensicswiki.org/wiki/Tools:Memory_Imaging )

메모리 덤프를 만든 뒤 메모리 이미지를 분석할 때다.

변동성 프레임워크를 이용한 메모리 분석

메모리 분석 Python에서 작성된 오픈 소스 메모리 포렌식 도구인 변동성 프레임워크를 간단히 사용할 수 있다. 그것은 GPL로 이용할 수 있다. 변동성은 메모리 이미지 파일에 대한 기본적인 법의학적 정보를 쉽게 얻을 수 있도록 다양한 플러그인과 다수의 프로필과 함께 제공된다. 다운로드하려면 다음 웹 사이트를 방문하십시오. 변동성 기반 - 오픈 소스 메모리 포렌식 또는 GitHub - 변동성 기반/기능성

출처: 변동성-변동성-변동성.

악의적인 네트워크 활동을 식별하기 위해 많은 전문가가 다음 단계를 따를 것을 권고한다. 첫째, 네트워크 연결의 프로세스 ID를 식별할 수 있다.

source: pslist.png

나중에 당신은 그 ID를 Process Name에 매핑하고 나중에 메모, 스크린샷, 그리고 물론 타임 스탬프를 통해 실제적인 정보를 수집함으로써 모든 단계와 프로세스를 종료해야 한다.

출처: 그림2lg061711.jpg

참고: 이 섹션은 아직 완료되지 않았다. 그 과정은 상세하게 설명될 것이다. 채널을 고정해 주십시오

탐색해야 하는 메모리 분석에 대한 가장 강력한 문서

요약

이 기사에서는 멀웨어 메모리 분석을 수행하는 방법에 대해 살펴보았다.

업데이트 게시

도구 사용 가능 여부 확인(Ken Prier 덕분에

참조

  1. https://technical.nttsecurity.com/post/102egyy/hunting-malware-with-memory-analysis
  2. 고급 인프라 침투 테스트 치헵 체비
  3. https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-86.pdf
  4. https://www.cybrary.it/0p3n/ram-memory-forensic-analysis/
  5. https://resources.infosecinstitute.com/memory-forensics/#gref
  6. https://technical.nttsecurity.com/post/102egyy/hunting-malware-with-memory-analysis
  7. RAM이란? RAM - Random Access Memory? Webopedia 정의

 

더보기

How to Perform Memory Analysis

How to Perform Memory Analysis

Source: malware-analysis-virtual-box-cyber-forensicator.jpg

Abstract

Malware threats are a very serious problem in information security nowadays. Dangerous hackers are inventing new techniques on a daily basis to bypass security layers and avoid detection. Thus it is time to figure out how to analyse memorydumps as.

But this time I want to take this opportunity to elaborate more Memory analysis because it is a required skill to every Forensics expert and malware analyst.

In this Article we are going to learn:

  • Dissecting Memory
  • Memory Management
  • Computer Forensic analysis steps
  • Digital Evidence acquisition
  • Memory Acquisition
  • Memory Analysis
  • Volatility Framework
  • Memory Analysis Best Practices

Memory Analysis

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, your main role is to collect all the information about the malicious software and have a good understanding of what happened to the infected machines. Like any process, to perform a malware analysis you typically need to follow a certain methodology and a number of steps.

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 the malware capabilities.

  • Process list and the associated threads
  • networking information and interfaces (TCP/UDP) • Kernel modules including the hidden modules
  • Opened files in the kernel
  • Bash and commands history
  • System Calls • Kernel hooks

Dissecting Memory

If we are going to learn how to analyse memory dumps we need first to explore what memory is? and how it works.

Memory is a vital component in the computer architecture. Computers are composed by:

  • CPU
  • Controllers
  • Memory

The full architecture is described in the following graph:

source overall.gif

In memory analysis, we are dealing with RAM s.

A __RAM (pronounced ramm) is an acronym for random access memory, a type of computer memory that can be accessed randomly; that is, any byte of memory can be accessed without touching the preceding bytes. RAM__ is found in servers, PCs, tablets, smartphones and other devices_, such as printers. __ RAM is volatile _

source: RAM061711.jpg

The memory is divided into 4,096-byte memory chunks named pages, to facilitate internal handling. The 12 least significant bits are the offset; the rest is the page number. On the recent x86 architecture, For example, the Linux kernel divides the virtual space, usually 4 GB into 3 GB dedicated to UserLand, and 1 GB for kernel land. This operation is named segmentation. The kernel uses a page table for the correspondence between physical and virtual addresses. To manage the different regions of memory, it uses a virtual memory area (VMA)

The stack is a special memory space. In programming, it is an abstract data type used to collect elements using two operations: push and pop. This section grows automatically, but when it becomes closer to another memory section, it will cause a problem and a confusion to the system. That is why attackers are using this technique to confuse the system with other memory areas.

The heap is used for dynamic memory allocation. It resides in the RAM like the stack, but it is slower. The kernel heap is using the following three types of allocators:

  • SLAB: This is a cache-friendly allocator.
  • A simple list of blocks (SLOB): This is an allocator used in small systems. It uses a first-fit algorithm.
  • SLUB : It is the default Linux allocator.

You can explore the detailed sections of memory check this great cheat sheet:

Better resolution here Memory Segmentation sheet

Memory Management

Memory management is an important capability of every operating system. It is also integrated into Linux kernel. Linux manages memory in a virtual way. In other words, there is no correspondence between the physical memory addresses, and the addresses used and seen by the program. This technique gives the users and developers flexibility. Linux is dealing with the following five types of addresses:

  1. User virtual addresses
  2. Physical addresses
  3. Bus addresses
  4. Kernel logical addresses
  5. Kernel virtual addresses

Computer Forensic analysis steps

NIST is describing Forensics as the following:

The most common goal of performing forensics is to gain a better understanding of an event of interest by finding and analyzing the facts related to that event... Forensics may be needed in many different situations, such as evidence collection for legal_ proceedings and internal disciplinary actions, and handling of malware incidents and unusual operational problems. _

Like any methodological operation, Computer forensic analysis goes through well-defined steps: Collection; Examination, Analysis and reporting. let's explore these steps one by one:

  1. Collection: identifying data sources and verify the integrity of it
  2. Examination: assessing and extracting the relevant pieces of information from the collected data
  3. Analysis
  4. Reporting

The steps are based on the NIST Guide to Integrating Forensic Techniques into Incident Response. I highly recommend exploring the Process in details (Performing the Forensic Process)

source: nist+process.jpg

Digital Evidence acquisition

Digital evidence needs to be treated carefully because we are going to analyse them. Also, we need to use them later within the legal process. Eliézer Pereira prioritized them in his Article RAM Memory Forensic Analysis as the following from the most volatile to the least volatile:

  • Caches
  • Routing tables, process tables, memory
  • Temporary system files
  • Hard drive
  • Remote logs, monitoring data
  • Physical network configuration, network topology
  • Media files (CDs, DVDs)

Memory Acquisition

The first step of memory analysis is memory acquisition by dumping the memory of a machine using a 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. After downloading it from their official repository and compiling it you can acquire the machine memory using this command:

# dd if=/dev/fmem of=... bs=1MB count=...

Another tool is The Linux Memory Extractor. LIME is a Loadable Kernel Module (LKM) to allow volatile memory acquisition from Linux and Linux- based devices, such as Android.

These are some free Memory Acquisition tools:

A full list of useful tools can be found here: Tools: Memory Imaging (https://www.forensicswiki.org/wiki/Tools:Memory_Imaging )

After having a memory dump, it is time to analyze the memory image.

Memory Analysis with Volatility Framework

To analyse memory You can simply use volatility framework, which is an open source memory forensics tool written in Python. It is available under GPL. Volatility comes with various plugins and a number of profiles to ease obtaining basic forensic information about memory image files. To download it you can visit this website: The Volatility Foundation - Open Source Memory Forensics or GitHub - volatilityfoundation/volatility

source: volatility-sockets.gif

To identify malicious network activities many experts recommend following these steps. First, you can identify Process IDs of network connections.

source: pslist.png

Later you need to map that IDs to Process Names and later terminate every step and process by collecting the artefacts by taking notes, screenshots and of course time-stamps.

source: Fig2lg061711.jpg

Note: this section is not completed yet. The processes will be described in a detailed way. Stay tuned.

Peerlyst Articles about Memory Analysis you need to explore

Summary

In this article, we explored how to perform Malware memory analysis.

Post Updates

Checked the availability of tools (Thanks to Ken Pryor )

References

  1. https://technical.nttsecurity.com/post/102egyy/hunting-malware-with-memory-analysis
  2. Advanced Infrastructure Penetration Testing Chiheb Chebbi
  3. https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-86.pdf
  4. https://www.cybrary.it/0p3n/ram-memory-forensic-analysis/
  5. https://resources.infosecinstitute.com/memory-forensics/#gref
  6. https://technical.nttsecurity.com/post/102egyy/hunting-malware-with-memory-analysis
  7. What is RAM - Random Access Memory? Webopedia Definition

 

 

※ 출처 : Blue Teams Academy | www.blueteamsacademy.com/memory-analysis/

반응형

댓글