Security_RNRF

리버스 엔지니어링 참고 블로그 정리 본문

Reversing

리버스 엔지니어링 참고 블로그 정리

RNRF 2022. 8. 31. 10:44

Compiler Explorer
> 웹 상에서 코드를 빌드, 컴파일도 가능하지만 해당 코드를 실시간으로 어셈블리어로 보여주며, 파일을 저장하고 공유할 수 있는 기능까지 포함된 도구(=사이트)이다.

https://godbolt.org/

 

Compiler Explorer

 

godbolt.org

https://dogbolt.org/

 

Decompiler Explorer

Decompiler Explorer is an interactive online decompiler which shows equivalent C-like output of decompiled programs from many popular decompilers.

dogbolt.org

 

Ex.) 라이센스 체크 예시 코드

#include <string.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
        if(argc==2) {
		printf("Checking License: %s\n", argv[1]);
		if(strcmp(argv[1], "AAAA-Z10N-42-OK")==0) {
			printf("Access Granted!\n");
		} else {
			printf("WRONG!\n");
		}
	} else {
		printf("Usage: <key>\n");
	}
	return 0;
}

> x86-64 gcc 12.1 - Intel Assembly

.LC0:
        .string "Checking License: %s\n"
.LC1:
        .string "AAAA-Z10N-42-OK"
.LC2:
        .string "Access Granted!"
.LC3:
        .string "WRONG!"
.LC4:
        .string "Usage: <key>"
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], edi
        mov     QWORD PTR [rbp-16], rsi
        cmp     DWORD PTR [rbp-4], 2
        jne     .L2
        mov     rax, QWORD PTR [rbp-16]
        add     rax, 8
        mov     rax, QWORD PTR [rax]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:.LC0
        mov     eax, 0
        call    printf
        mov     rax, QWORD PTR [rbp-16]
        add     rax, 8
        mov     rax, QWORD PTR [rax]
        mov     esi, OFFSET FLAT:.LC1
        mov     rdi, rax
        call    strcmp
        test    eax, eax
        jne     .L3
        mov     edi, OFFSET FLAT:.LC2
        call    puts
        jmp     .L4
.L3:
        mov     edi, OFFSET FLAT:.LC3
        call    puts
        jmp     .L4
.L2:
        mov     edi, OFFSET FLAT:.LC4
        call    puts
.L4:
        mov     eax, 0
        leave
        ret

 

> ARM gcc 12.1(linux) - ARM (ex. MAC)

.LC0:
        .ascii  "Checking License: %s\012\000"
.LC1:
        .ascii  "AAAA-Z10N-42-OK\000"
.LC2:
        .ascii  "Access Granted!\000"
.LC3:
        .ascii  "WRONG!\000"
.LC4:
        .ascii  "Usage: <key>\000"
main:
        push    {r7, lr}
        sub     sp, sp, #8
        add     r7, sp, #0
        str     r0, [r7, #4]
        str     r1, [r7]
        ldr     r3, [r7, #4]
        cmp     r3, #2
        bne     .L2
        ldr     r3, [r7]
        adds    r3, r3, #4
        ldr     r3, [r3]
        mov     r1, r3
        movw    r0, #:lower16:.LC0
        movt    r0, #:upper16:.LC0
        bl      printf
        ldr     r3, [r7]
        adds    r3, r3, #4
        ldr     r3, [r3]
        movw    r1, #:lower16:.LC1
        movt    r1, #:upper16:.LC1
        mov     r0, r3
        bl      strcmp
        mov     r3, r0
        cmp     r3, #0
        bne     .L3
        movw    r0, #:lower16:.LC2
        movt    r0, #:upper16:.LC2
        bl      puts
        b       .L4
.L3:
        movw    r0, #:lower16:.LC3
        movt    r0, #:upper16:.LC3
        bl      puts
        b       .L4
.L2:
        movw    r0, #:lower16:.LC4
        movt    r0, #:upper16:.LC4
        bl      puts
.L4:
        movs    r3, #0
        mov     r0, r3
        adds    r7, r7, #8
        mov     sp, r7
        pop     {r7, pc}

> https://godbolt.org/ 사이트 이미지 - 버전에 따라 어셈블리어를 비교하기 편한 사이트이다.

> https://dogbolt.org/ 사이트 이미지 - 디컴파일러에 따라 구문을 비교하기 편한 사이트이다.

 

 

* 참조 사이트
> https://www.youtube.com/watch?v=gPsYkV7-yJk
> https://binary.ninja/2022/07/13/introducing-decompiler-explorer.html

'Reversing' 카테고리의 다른 글

IDA 단축키 정리  (0) 2022.10.27
리버싱 기본 IDA Pro 활용법  (0) 2022.10.27
Comments