Post

[MalwareTechLabs]Strings (3 Labs)

Text strings can provide valuable insight into what a piece of code is doing. For this reason, malware will often attempt to conceal or encrypt them. These challenges focus around extracting strings, and are great for beginners.

[MalwareTechLabs]Strings (3 Labs)

3Labs

Strings 1

Lab Type: Static AnalystLanguages: x86_64Platform: Windows 64-bitDifficulty: Tools: Ghidra,DiE

Mô tả của bài

In the .data segment of the portable executable you’ll find several thousand text strings which look like flags, but only one of these is real. The correct flag is actually used by the executable, whereas the rest are not. Your job is to find the real flag by performing static analysis of the executable code.

Description

Trong bài này ta được cung cấp 1 file PE có tên là Strings1.exe_. Quy tắc của thử thách này là dùng Static Analyst. Tác giả cố tình thêm dấu ‘_’ ở cuối tên file để ngăn ta vô tình thực thi nó.

Phân tích

Ném file này vào Ghidra và phân tích: entry

Đây là 1 hàm khá đơn giản, chương trình sẽ băm 1 chuỗi bằng cách gọi hàm md5_hash() và kết quả được hiển thị ra màn hình thông qua hàm MessageBoxA. Từ đó có thể chắc chắn được rằng chuỗi trở thành tham số cho hàm băm chính là flag cần tìm. flag

Như vậy flag của bài này là : FLAG{NEEDLE-IN-A-HAYSTACK-FOUND}.

Đem đi nộp bài. result

Strings 2

Lab Type: Static AnalystLanguages: x86_64Platform: Windows 64-bitDifficulty: Tools: Ghidra,DiE

Mô tả của bài

This challenge introduces a common technique used by malware to concealing text strings inside code. You’ll need to perform static analysis and figure out how the flag is concealed. Description

Phân tích

Tương tự như bài trước, vẫn dùng static analyst để làm. Ném file Strings2.exe_ vào Ghidra và tìm đến hàm entry().

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
void entry(void)
{
  LPCSTR lpText;
  undefined1 local_30;
  undefined1 local_2f;
  undefined1 local_2e;
  undefined1 local_2d;
  undefined1 local_2c;
  undefined1 local_2b;
  undefined1 local_2a;
  undefined1 local_29;
  undefined1 local_28;
  undefined1 local_27;
  undefined1 local_26;
  undefined1 local_25;
  undefined1 local_24;
  undefined1 local_23;
  undefined1 local_22;
  undefined1 local_21;
  undefined1 local_20;
  undefined1 local_1f;
  undefined1 local_1e;
  undefined1 local_1d;
  undefined1 local_1c;
  undefined1 local_1b;
  undefined1 local_1a;
  undefined1 local_19;
  undefined1 local_18;
  undefined1 local_17;
  undefined1 local_16;
  undefined1 local_15;
  undefined1 local_14;
  undefined1 local_13;
  undefined1 local_12;
  undefined1 local_11;
  undefined1 local_10;
  undefined1 local_f;
  undefined1 local_e;
  undefined1 local_d;
  undefined1 local_c;
  undefined1 local_b;
  undefined1 local_a;
  undefined1 local_9;
  
  local_30 = 0x46;
  local_2f = 0x4c;
  local_2e = 0x41;
  local_2d = 0x47;
  local_2c = 0x7b;
  local_2b = 0x53;
  local_2a = 0x54;
  local_29 = 0x41;
  local_28 = 0x43;
  local_27 = 0x4b;
  local_26 = 0x2d;
  local_25 = 0x53;
  local_24 = 0x54;
  local_23 = 0x52;
  local_22 = 0x49;
  local_21 = 0x4e;
  local_20 = 0x47;
  local_1f = 0x53;
  local_1e = 0x2d;
  local_1d = 0x41;
  local_1c = 0x52;
  local_1b = 0x45;
  local_1a = 0x2d;
  local_19 = 0x42;
  local_18 = 0x55;
  local_17 = 0x49;
  local_16 = 0x4c;
  local_15 = 0x54;
  local_14 = 0x2d;
  local_13 = 0x41;
  local_12 = 0x54;
  local_11 = 0x2d;
  local_10 = 0x52;
  local_f = 0x55;
  local_e = 0x4e;
  local_d = 0x54;
  local_c = 0x49;
  local_b = 0x4d;
  local_a = 0x45;
  local_9 = 0x7d;
  lpText = md5_hash((longlong)&local_30);
  MessageBoxA((HWND)0x0,lpText,s_MalwareTech_Labs_140003480,0x30);
                    /* WARNING: Subroutine does not return */
  ExitProcess(0);
}

Tương tự như bài trước, tác giả gọi hàm md5_hash() để băm flag rồi hiển thị ra ngoài màn hình thông qua hàm MessageBoxA(). Dễ dàng thấy local_30 chính là 1 mảng 40 ký tự, từ local_9 đến local_30. Thay vì lưu trữ flag trong data section có thể xác định rõ ngay trong Ghidra thì ở đây, chương trình khởi tạo nó trong stack, vì vậy Ghidra sẽ xác định nó là undefined chứ không phải char.

Để đọc được flag, ta cần Retype lại từ undefined sang chuỗi ký tự. Retype local_30 từ undefined sang char[40].

Retype

Flag thu được là: FLAG{STACK-STRINGS-ARE-BUILT-AT-RUNTIME}

Flag

Strings 3

Lab Type: Static AnalystLanguages: x86_64Platform: Windows 64-bitDifficulty: Tools: Ghidra,DiE

Mô tả bài

There’s a very common place that both malicious and legitimate executables like to store arbitrary data. In this instance, you’ll find the flag string stored there. Reverse engineering the code will point you to where you can find the flag, as well as tell you which one is correct.

Description

Phân tích

Ném file exe vào Ghidra, tìm đến hàm entry().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void entry(void)
{
  LPCSTR lpText;
  longlong lVar1;
  CHAR *pCVar2;
  CHAR local_408 [1024];
  
  pCVar2 = local_408;
  for (lVar1 = 0x400; lVar1 != 0; lVar1 = lVar1 + -1) {
    *pCVar2 = '\0';
    pCVar2 = pCVar2 + 1;
  }
  LoadStringA((HINSTANCE)0x0,0x110,local_408,0x3ff);
  lpText = md5_hash((longlong)local_408);
  MessageBoxA((HWND)0x0,lpText,s_MalwareTech_Labs_140003480,0x30);
                    /* WARNING: Subroutine does not return */
  ExitProcess(0);
}

Ở vòng lặp đầu tiên, chương trình đang khởi tạo 1 mảng local_408 với kích thước 1024 bytes (0x400). Sau đó chương trình gọi hàm LoadStringA. Theo như tôi tìm hiểu ở đây MSDN LoadStringA thì hàm LoadStringA nhận vào 4 tham số:

1
2
3
4
5
6
int LoadStringA(
  [in, optional] HINSTANCE hInstance,
  [in]           UINT      uID,
  [out]          LPSTR     lpBuffer,
  [in]           int       cchBufferMax
);

Đây là 1 hàm Windows API, dùng để tải chuỗi văn bản được cất giấu trong phần Resource của file .exe vào vùng nhớ.

1
LoadStringA((HINSTANCE)0x0,0x110,local_408,0x3ff)
hInstance = 0x0Chỉ định lấy Resource từ chính file đang chạy
uID = 0x110String ID (Mã định danh chuỗi), chuyển sang dec là 272
lpBuffer = local_408Mảng 1024 bytes vừa khởi tạo
cchBufferMax = 0x3ffĐọc tối đa 0x3ff(1023) ký tự

Bây giờ sẽ đi tìm chuỗi có ID = 272 nằm ở đâu trong file exe. Ném file đó vào Resource Hacker để tìm.

src

Như vậy flag của bài này là: FLAG{RESOURCES-ARE-POPULAR-FOR-MALWARE}

flag

This post is licensed under CC BY 4.0 by the author.

Trending Tags