[과제] /bin/level7 파일을 disassemble 하여 의사코드(가상코드)를 만들어 보자.
(주의) root 사용자로 분석한다.
처음에 만들어지는 부분
0x08048454 <main+0>: push %ebp
0x08048455 <main+1>: mov %esp,%ebp
0x08048457 <main+3>: sub $0x8,%esp
0x0804845a <main+6>: and $0xfffffff0,%esp
0x0804845d <main+9>: mov $0x0,%eax eax에 0을 집어넣음.
0x08048462 <main+14>: sub %eax,%esp eax를 esp에 집어 넣는다.
malloc 함수 부분
0x08048464 <main+16>: sub $0xc,%esp
0x08048467 <main+19>: push $0x64 16진수 d(문자), 100(10진수)
0x08048469 <main+21>: call 0x8048344 <malloc> #include <stdlib.h> 메모리를 동적할당 하는 0x0804846e <main+26>: add $0x10,%esp 데 쓰임. 메모리는 0x64(100)
0x08048471 <main+29>: mov %eax,0xfffffffc(%ebp) 변수 설정
0x08048474 <main+32>: sub $0xc,%esp
0x08048477 <main+35>: push $0x80485c0 "Insert The Password : "
0x0804847c <main+40>: call 0x8048384 <printf>
0x08048481 <main+45>: add $0x10,%esp
0x08048484 <main+48>: sub $0x4,%esp
0x08048487 <main+51>: pushl 0x8049744 “” stdin
0x0804848d <main+57>: push $0x64
0x0804848f <main+59>: pushl 0xfffffffc(%ebp) push3개니 인자값 3개 넣어줘야함, 변수, ,stdin
0x08048492 <main+62>: call 0x8048354 <fgets> #include <stdio.h> 문자를 읽어 들임.키보드
0x08048497 <main+67>: add $0x10,%esp 입력 받는다.
0x0804849a <main+70>: sub $0x4,%esp
0x0804849d <main+73>: push $0x4
0x0804849f <main+75>: push $0x80485d7 "mate" 인자 3개 넣어줘야함. 변수, mate, $0x4
0x080484a4 <main+80>: pushl 0xfffffffc(%ebp)
0x080484a7 <main+83>: call 0x8048364 <strncmp> #include <string.h> 입력받은 문자와 비교
0x080484ac <main+88>: add $0x10,%esp mate를 비교한다
0x080484af <main+91>: test %eax,%eax
0x080484b1 <main+93>: jne 0x80484cd <main+121>
참이면 여기부터 실행
0x080484b3 <main+95>: sub $0xc,%esp
0x080484b6 <main+98>: push $0x80485e0 "\nCongratulation! next password is \"break..
0x080484bb <main+103>: call 0x8048384 <printf>
0x080484c0 <main+108>: add $0x10,%esp
0x080484c3 <main+111>: sub $0xc,%esp
0x080484c6 <main+114>: push $0x0
0x080484c8 <main+116>: call 0x8048394 <exit>
system 함수 거짓이면 이부분을 실행
0x080484cd <main+121>: sub $0xc,%esp
0x080484d0 <main+124>: push $0x8048617 "cat /bin/wrong.txt"
0x080484d5 <main+129>: call 0x8048334 <system>
0x080484da <main+134>: add $0x10,%esp
0x080484dd <main+137>: leave
0x080484de <main+138>: ret
0x080484df <main+139>: nop
-복원 코드-
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main()
{
char *input;
input = (char *)malloc(0x64);
printf("Insert The Password : ");
fgets(input, 0x64, stdin);
if(strncmp(input, "mate", 4) == 0) {
printf ("\nCongratulation! next password is \"break the world\".\n\n");
exit (0);
}
else {
system("cat /bin/wrong.txt");
}
return 0;
}
'정보보안공부 > 정보보안전문과정' 카테고리의 다른 글
정보보안 과정 Day 67 : 리버싱 5 (공유 메모리) (0) | 2020.12.10 |
---|---|
정보보안 과정 Day 66-1 : 리버싱 4 (0) | 2020.12.09 |
정보보안 과정 Day65 : Reverse Engineering 3 (0) | 2020.12.08 |
정보보안 과정 Day64 : Reverse Engineering 2 (0) | 2020.12.07 |
정보보안 과정 Day63 : Reverse Engineering 1 (0) | 2020.12.04 |