Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- ftz level1
- java
- 삼성 노트북 터치패드 먹통
- 자바로 엑셀만들기
- ftz level4
- vi editor shell
- ehart
- ftz level3
- python library
- c++ 출력문
- 터치노트북
- 안드로이드
- ListValuedMap
- 멀티터치노트북
- 터치패드 오류
- 안드로이드스튜디오
- 멀티터치노트북이란
- XSSF
- airbar
- rust #casting
- ftz
- 노트북 터치패드
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile
- c
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
- ftz level2
- Samsung Updates
- C++
- 터치패드 먹통
- for fun
Archives
- Today
- Total
ASCII
[과제] sum 파일 해결하기 본문
문제
제 과제는 아니지만 하는거 보고 재밌어 보여서 건들여 보았습니다.

- sum 프로그램의 main 함수의 어셈블리어를 분석하세요 (20점)
- 분석을 통해 확인한 로직을 프로그램으로 다시 개발해보세요 (10점)
- 바이너리 파일에서 프로그램을 변조하여 값이 10이 나오도록 해보세요 (10점)
풀이
1번
0x0000000000001149 <+0>: endbr64
0x000000000000114d <+4>: push rbp
0x000000000000114e <+5>: mov rbp,rsp
0x0000000000001151 <+8>: sub rsp,0x10
0x0000000000001155 <+12>: mov DWORD PTR [rbp-0xc],0x2
0x000000000000115c <+19>: mov DWORD PTR [rbp-0x8],0x3
0x0000000000001163 <+26>: mov edx,DWORD PTR [rbp-0xc]
0x0000000000001166 <+29>: mov eax,DWORD PTR [rbp-0x8]
0x0000000000001169 <+32>: add eax,edx
0x000000000000116b <+34>: mov DWORD PTR [rbp-0x4],eax
0x000000000000116e <+37>: mov eax,DWORD PTR [rbp-0x4]
0x0000000000001171 <+40>: mov esi,eax
0x0000000000001173 <+42>: lea rdi,[rip+0xe8a] # 0x2004
0x000000000000117a <+49>: mov eax,0x0
0x000000000000117f <+54>: call 0x1050 <printf@plt>
0x0000000000001184 <+59>: mov eax,0x0
0x0000000000001189 <+64>: leave
0x000000000000118a <+65>: ret
2번
위의 디스어셈블한 결과와 실행결과를 참고하여 볼 때, 변수에 2, 3을 대입하고, 이를 printf를 이용해서 출력하는 것 같습니다.
#include <stdio.h>
int main(int argc, char* argv[]){
int a = 2, b = 3;
int c = a + b;
printf("%d\n", c);
return 0;
}
3번
objdump -d sum | grep -A 10 "main>:"
objdump를 이용하여 어셈블 결과를 출력해 보겠습니다.
root@LAPTOP-OR7K2KFS:~/origin# objdump -d sum | grep -A 20 "main>:"
0000000000001149 <main>:
1149: f3 0f 1e fa endbr64
114d: 55 push %rbp
114e: 48 89 e5 mov %rsp,%rbp
1151: 48 83 ec 10 sub $0x10,%rsp
1155: c7 45 f4 02 00 00 00 movl $0x2,-0xc(%rbp)
115c: c7 45 f8 03 00 00 00 movl $0x3,-0x8(%rbp)
1163: 8b 55 f4 mov -0xc(%rbp),%edx
1166: 8b 45 f8 mov -0x8(%rbp),%eax
1169: 01 d0 add %edx,%eax
116b: 89 45 fc mov %eax,-0x4(%rbp)
116e: 8b 45 fc mov -0x4(%rbp),%eax
1171: 89 c6 mov %eax,%esi
1173: 48 8d 3d 8a 0e 00 00 lea 0xe8a(%rip),%rdi # 2004 <_IO_stdin_used+0x4>
117a: b8 00 00 00 00 mov $0x0,%eax
117f: e8 cc fe ff ff callq 1050 <printf@plt>
1184: b8 00 00 00 00 mov $0x0,%eax
1189: c9 leaveq
118a: c3 retq
118b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
hexdump를 이용하여 바이너리 파일을 hex로 출력하여 보겠습니다.
hexdump sum | grep -A 10 0001140
vi 에디터를 이용하여 값을 변경해주겠습니다.
변경후
root@LAPTOP-OR7K2KFS:~/origin# hexdump sum | grep -A 10 0001140
0001140 0ff3 fa1e 77e9 ffff f3ff 1e0f 55fa 8948
0001150 48e5 ec83 c710 f445 0003 0000 45c7 07f8
0001160 0000 8b00 f455 458b 01f8 89d0 fc45 458b
0001170 89fc 48c6 3d8d 0e8a 0000 00b8 0000 e800
0001180 fecc ffff 00b8 0000 c900 0fc3 441f 0000
0001190 0ff3 fa1e 5741 8d4c 1b3d 002c 4100 4956
00011a0 d689 5541 8949 41f5 4154 fc89 4855 2d8d
00011b0 2c0c 0000 4c53 fd29 8348 08ec 3fe8 fffe
00011c0 48ff fdc1 7403 311f 0fdb 801f 0000 0000
00011d0 894c 4cf2 ee89 8944 41e7 14ff 48df c383
00011e0 4801 dd39 ea75 8348 08c4 5d5b 5c41 5d41
root@LAPTOP-OR7K2KFS:~/origin# ./sum
10
'기타' 카테고리의 다른 글
vi 에디터에서 쉘코드 실행하기 (0) | 2022.02.06 |
---|---|
64비트 우분투에서 32비트 컴파일하기 (0) | 2021.12.21 |