본문 바로가기

공부/보안

[pwnable.kr] - collision

반응형

collision - 3pt [writeup]

 

 

 

 

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
#include <stdio.h>
#include <string.h>
 
unsigned long hashcode = 0x21DD09EC;
 
unsigned long check_password(const char* p){
    int* ip = (int*)p;
    int i;
    int res=0;
    for(i=0; i<5; i++){
        res += ip[i];
    return res;
 
int main(int argc, char* argv[]){
    if(argc<2){
        printf("usage : %s [passcode]\n", argv[0]);
        return 0;
    // 인자가 없으면 안된다.
    if(strlen(argv[1]) != 20){
        printf("passcode length should be 20 bytes\n");
        return 0;
    // 아규먼트 벡터로 입력받은 첫번째 인자인 argv[1]의 길이가 20이여야 한다.
    if(hashcode == check_password( argv[1] )){
        system("/bin/cat flag");
        return 0;
    // hashcode가 argv[1]를 인자로 넣어서 리턴된 값과 같으면 셸이 따진다.
    else
        printf("wrong passcode.\n");
    return 0;
cs

 

그렇다면 20바이트의 길이의 첫번째 인자가 check_password() 함수로의 리턴값이 hashcode와 같아야 한다.

 

int 형 포인터로 형 변환을 했기에 4 바이트씩 읽어들인다.

 

첫번째 인자인 20바이트의 문자열을 int 형 포인터로 접근한 뒤 4바이트씩 5번 접근한다.

 

0x21DD09EC / 5 = 0x06C5CEC8

검산을 해보면 0x06C5CEC8 * 5 = 0x21DD09E8

0x21DD09EC - 0x21DD09E8 = 4

 

그럼 0x06C5CEC8 을 하나 보내주고, 0x06C5CEC9(0x06C5CEC8 + 1) 을 네개 보내준다.

 

반응형

'공부 > 보안' 카테고리의 다른 글

[dreamhack] System Exploitation 3강  (0) 2021.03.07
나 보려고 정리해두는 gdb 명령어  (0) 2021.03.07
[dreamhack] System Exploitation 2강  (0) 2021.03.06
[dreamhack] System Exploitation 1강  (0) 2021.03.04
[pwnable.kr] fd  (0) 2021.02.26