2017. 7. 7. 00:42ㆍ0x02 Reverse Engineer/0x03. Etc
gdb에 적응하기 위해 간단한 코드를 만들어서 실습을 해보았다.
소스코드는 다음과 같다.
#include <stdio.h> #include <stdlib.h> #include <string.h> int check_authentication(char *password) { int auth_flag = 0; char password_buffer[16];
strcpy(password_buffer, password); if(strcmp(password_buffer,"constant") == 0) auth_flag = 1; if(strcmp(password_buffer,"love hack") == 0) auth_flag = 0; return auth_flag; } int main(int argc, char *argv[]) { if(argc<2) { printf(" usage : %s (password)\n",argv[0]); exit(-1); } if(check_authentication(argv[1])) { printf(" welcome admin! \n"); } else { printf(" Sorry you don't permit! \n"); } return 0; } |
check_authentication에 strcpy 함수가 있어 이를 확인하기 위해 bp를 걸었다.
eax의 값에 따라 분기하는 위치가 달라진다.
eax의 값에 따라 분기하는 위치가 달라진다.
main 함수에서 성공/실패를 정하는 구간이다.
입력한 argv[1]='hello' 이므로 함수 check_authentication에서의 반환값은 0이다.
반환 값이 0이면 if문 만족하지 못하므로 실패에 관련 된 출력문이 출력된다.
이번에는 올바른 인증 값 'constant'를 입력한다.
main함수에서 argv[1] = password
check_authentication(*password==constant)
즉, password인 constant를 password_buffer에 복사한다.
'0x02 Reverse Engineer > 0x03. Etc' 카테고리의 다른 글
[H4C CTF] Let's Bingo ! (0) | 2017.09.09 |
---|---|
[Basic] Tutorial Reversing - Controlled to printf (0) | 2017.08.25 |
[피카츄 시연] (0) | 2017.07.03 |
피카츄 리버싱 5부... (0) | 2017.06.05 |
피카츄 리버싱 4부... (0) | 2017.06.05 |