728x90
반응형
1. intro
2. code 및 분석
2.1. code
#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;
}
if(hashcode == check_password( argv[1] )){
system("/bin/cat flag");
return 0;
}
else
printf("wrong passcode.\n");
return 0;
}
2.2. 분석
뭐 특별히 분석할게... 없...
argv[1]의 크기가 20이어야하고, hashcode와 argv[1]의 합이 같으면 플래그를 준다.
왜냐면 ip[i] 가 argv[1]의 시작 주소부터 4 bytes의 offset 주소이기 때문.
3. 취약점 확인 및 공격 준비
3.1. 취약점
특별히 취약점은 없다.
3.2. 공격 준비
hashcode가 4 bytes고 argv[1]이 20 bytes이니 5번 더해서 hashcode 값이 되면 된다.
4. exploit
from pwn import *
s = ssh(user='col',host='pwnable.kr',port=2222,,port=2222,password='guest')
#0x21DD09EC
pay = p32(0x01111111)
pay += p32(0x01111111)
pay += p32(0x01111111)
pay += p32(0x01111111)
pay += p32(0x21DD09EC - 0x01111111*4 )
p = s.process(['./col',pay])
print(p.recvline().decode())
┌[WyV3rN]-(d/hack)-
└> python3 a.py
[+] Connecting to pwnable.kr on port 2222:
Done
[*] fd@pwnable.kr:
Distro Ubuntu 16.04
OS: linux
Arch: amd64
Version: 4.4.179
ASLR: Enabled
[+] Starting remote process bytearray(b'./col') on pwnable.kr: pid 454286
----------#플래그는 삭제
728x90
반응형
'Wargame > pwnable.kr' 카테고리의 다른 글
input (0) | 2022.12.28 |
---|---|
random (0) | 2022.12.28 |
passcode (0) | 2022.12.27 |
bof (0) | 2022.12.27 |
fd (0) | 2022.12.27 |