일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 리버싱
- 토이프로젝트
- 듀얼테이블
- orcle
- leetcode
- Practicalmalwareanalysis
- 균형이진트리
- 코딩테스트
- 투빌리지
- N-ary Tree Preorder Traversal
- 다해요
- 대학생
- toVillage
- lab03-03.exe
- 마을짓기
- 가차시스템
- 악코분
- dualtable
- 투두리스트
- JavaScript
- 취업준비
- 악성코드분석
- JS
- gamification
- TODOLIST
- 릿코드
- to-do
- 자바스크립트
- 사이버보안
- 사이드프로젝트
- Today
- Total
이것저것
IAT 총정리 본문
진짜 아무것도 모르겠다. 막 찾아보니까 IAT를 알면 WINDOWS OS의 근간을 이해할 수 있다는데...
아무래도 이해를 못하는걸 보니 난 말하는 감자인게 분명하다.
이래나 저래나 어쨋거나 저쨋거나, 악성코드분석을 할려면 PE File Format 를 아는게 좋고, PE File Format에서 IAT는 중요한 역할을 하고 있다길래 정리했다.
IAT (Import Address Table)
프로그램이 어떤 라이브러리에서 어떤 함수를 사용하고 있는지를 기술한 테이블
IAT를 알기 전에 DLL에 대한 이해가 필요하다
DLL (Dynamic Linked Library)
둘 이상의 프로그램에서 사용할 수 있는 코드와 데이터를 포함하는 라이브러리 (동적 연결 라이브러리)
각 프로그램들은 이 DLL를 사용하여 프로그램을 별도의 구성 요소로 모듈화하여 코드 재사용과 효율적인 메모리 사용을 촉진할 수 있다.
이때 DLL 로딩 방식은 2가지가 존재한다.
Explicit Linking - LoadLibrary를 명시적으로 호출하여 DLL을 로드
Implicit Linking - 응용 프로그램은 컴파일 하는 동안 DLL을 지정하고, Windows 로더는 런타임에 로드
여기서 IAT는 두가지 DLL 로딩 방식 중 Implicit Linking(암시적 연결)을 지원한다.
DLL은 매번 동일한 메모리 공간에 매핑되지 않고 DLL 내 함수 주소 역시 매번 바뀐다. 그렇기 때문에 PE는 IAT에 프로그램에서 사용되고 있는 함수들의 주소를 기록해둔다.
그래서 IAT가 왜 필요한건데?
프로그램이 실행될 때, 함수는 스택 영역에서 스택 프레임으로 생성되어 메모리를 할당받는다.
이때 ESP, EBP (스택프레임에 관한 메모리 주소를 저장하는 레지스터)의 값이 필요하다.
그러나, DLL은 다른 메모리 공간에 매핑되기 때문에 IAT를 참조하여 함수의 주소 값을 받아와야 프로그램을 실행할 수 있다.
스택 프레임에 관한 내용은 이전에 작성했던 포스터를 참고
https://k-clutter.tistory.com/59?category=1090526
과제 1주차 abex crackme 1
나는 바보다. 아니 근데 진짜 좋은 아이디어라고 생각한다고! 지금부터 시작합니다. 이번에 받은 과제는, 아래처럼 뜨는 프로그램을 실행시켰을때 정상적인 출력을 보이라는 말 같았다. 그럼 정
k-clutter.tistory.com
이제 IAT를 제대로 이해했는지 확인하기 위해 IAT 값을 볼 수 있는 PE parser를 구현해야하는데..................
(((틀린 코드임)))
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
IMAGE_NT_HEADERS NH;
IMAGE_DATA_DIRECTORY *DD;
IMAGE_IMPORT_DESCRIPTOR *ID;
IMAGE_THUNK_DATA32 *TD;
IMAGE_IMPORT_BY_NAME *IBM;
FILE * file;
int main() {
int filesize;
char *filename;
int i;
int j;
filename = malloc(sizeof(char) * 500);
printf("Please enter a file name : ");
scanf("%s", filename);
fseek(file, 0, SEEK_END);
filesize = ftell(file);
DD = (IMAGE_DATA_DIRECTORY*)malloc(sizeof(IMAGE_DATA_DIRECTORY) * (NH.OptionalHeader.DataDirectory[1].Size / sizeof(IMAGE_IMPORT_DESCRIPTOR) - 1));
for (i = 0;i < NH.OptionalHeader.DataDirectory[1].Size / sizeof(IMAGE_DATA_DIRECTORY) - 1; i++)
{
fread(&ID[i], sizeof(IMAGE_DATA_DIRECTORY), 1, file);
}
printf("< IMPORT DATA DIRECTORY >\n");
for (j = 0; j < NH.OptionalHeader.DataDirectory[1].Size / sizeof(IMAGE_DATA_DIRECTORY) - 1; j++)
{
printf("RVA: 0x%x (raw: 0x%x) \n", DD[j]., RvaToRaw(DD[j].VirtualAddress.OriginalFirstThunk));
printf("Data: \n");
INTable(RvaToRaw(DD[j].VirtualAddress.OriginalFirstThunk));
printf("Name: 0x%x (raw: 0x%x) -> ", DD[j].VirtualAddress.OriginalFirstThunk.AddressOfData.Hint, RvaToRaw(ID[j].Name));
readName(RvaToRaw(DD[j].VirtualAddress.OriginalFirstThunk.AddressOfData.Hint));
printf("First Thunk: 0x%x (raw: 0x%x)\n\n", DD[j].VirtualAddress.FirstThunk, RvaToRaw(DD[j].VirtualAddress.FirstThunk));
}
printf("\n\n");
printf("\n");
free(filename);
fclose(file);
return 0;
}
틀린 이유는
- 구조체가 아닌데 (DWORD로 선언사진 참고) 구조체 접근하듯 선언했기 때문
- RvaToRaw를 시간관계상 작성하지 않음
출처 및 공부자료
https://reversecore.com/23?category=216978
PE(Portable Executable) File Format (6) - PE Header
IAT (Import Address Table) PE Header 를 처음 배울때 최대 장벽은 IAT(Import Address Table) 입니다. IAT 에는 Windows 운영체제의 핵심 개념인 process, memory, DLL 구조 등에 대한 내용이 함축되어 있습니..
reversecore.com
https://noirstar.tistory.com/273
IAT (Import Address Table) 함수주소 기록 과정
맨날 보고 보고 또 봐도 헷갈리는 IAT(Import Address Table) 에 함수주소를 기록하는 과정을 PEView 를 이용하여 하나하나 살펴보도록 하겠습니다. 진짜 어려운거 다 집어치우고 핵심 프로세스만 적도록
noirstar.tistory.com
http://sandsprite.com/CodeStuff/Understanding_imports.html
Understanding the Import Address Table
That graphic should explain the structure and nesting adequetly. If you need more of a reference search the msdn site for the full PE specification. They have a very comprehensive pdf on it although it is quite dry. If you are to write any kind of import r
sandsprite.com
https://learn.microsoft.com/en-us/troubleshoot/windows-client/deployment/dynamic-link-library
Dynamic link library (DLL) - Windows Client
Describes what a DLL is and the various issues that occur when you use a DLL.
learn.microsoft.com
https://en.wikipedia.org/wiki/Dynamic-link_library#Using_DLL_imports
Dynamic-link library - Wikipedia
From Wikipedia, the free encyclopedia Jump to navigation Jump to search Microsoft's implementation of the shared library concept in Windows and OS/2 This article is about the OS/2 and Windows implementation. For dynamic linking of libraries in general, see
en.wikipedia.org
When do these load DLLs : Implicit Linking VS Explicit Linking
I thought Implicit linking loads a DLL as soon as the application starts because it is also called "load-time dynamic linking". But I found some strange explanations below from the link here(https:...
stackoverflow.com
Linker support for delay-loaded DLLs
Learn more about: Linker support for delay-loaded DLLs
learn.microsoft.com
'전공 > 악성코드분석' 카테고리의 다른 글
기초정적분석하기, Lab 01-02.exe (0) | 2022.11.06 |
---|---|
오랜만에 쓰는, Lena tutorials 3! (0) | 2022.10.04 |
lena tutorials 2, JUMP로 해결하기 (0) | 2022.09.27 |
과제 1주차 abex crackme 2 (0) | 2022.09.18 |
과제 1주차 abex crackme 1 (0) | 2022.09.17 |