| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- androidhacking
- sql injection
- time-based
- 취약점 진단
- Linux
- msfconsole #heartbleed #247ctf #misc #webhacking
- 안드로이드 모의해킹
- 리눅스
- 모의해킹
- 밴딧
- androGoat
- error-based
- bandit #밴딧 #웹해킹 #해킹 #화이트해커 #공부 #스터디 #IT #hacking #linux #openssl #nmap
- pentest
- Bandit
- 쿠키변조
Archives
- Today
- Total
d0r1
[dreamhack] set-int 본문

//Name: chall.c
//Compile: gcc chall.c -o chall -no-pie -fno-stack-protector
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
void alarm_handler() {
puts("TIME OUT");
exit(-1);
}
void initialize() {
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
signal(SIGALRM, alarm_handler);
alarm(30);
}
int main(int argc, char *argv[]){
unsigned int a = 0;
int b = 0;
initialize();
printf("Your input : \n");
scanf("%u", &a);
if(a > 0){
b = (int)a + 1;
if(b == 0){
printf("Success.\nYour second input : \n");
scanf("%d", &b);
if(b < 1){
b = b-1;
if(b > 0){
system("/bin/sh");
} else{
printf("fail!\n");
}
} else{
printf("Input is too large!\n");
}
} else{
printf("fail!\n");
}
} else{
printf("Input is too small!\n");
}
return 0;
}
숫자를 입력하고 조건에 맞으면 /bin/sh이 호출되어서, flag를 확인할 수 있다.
조건
1. a는 0보다 크고, a+1은 0이어야한다.
2. b는 1보다 작고, b-1은 0보다 커야한다.
조건에 맞는 자연수는 사실 존재하지 않는다
이는 컴퓨터의 자료형 표현 범위를 알면 해결할 수 있다.
| 자료형 | 키워드 |
메모리 크기 | 값의 범위 |
| 문자형 | char | 1 Bytes | -128~127 |
| 정수형 | short | 2 Bytes | -32,768~32,767 |
| int | 4 Bytes | -2,147,483,648 ~ 2,147,483,647 |
|
| long | 4 Bytes | -2,147,483,648 ~2.147.483.647 |
|
| 부호없는 문자형 | unsigned char | 1 Bytes | 0~255 |
| 부호없는 정수형 | unsigned short | 2 Bytes | 0~65,535 |
| unsigned int | 4 Bytes | 0~4,294,967,295 | |
| unsigned long | 4 Bytes | 0~4,294,967,295 | |
| 부동 소수형 | float | 4 Bytes | 1.2E-38~3.4E38 |
| double | 8 Bytes | 2.2E-308~1.8E308 | |
| void형 | void | 0 Bytes | 값 없음 |
해당 범위를 벗어나면, 최대값 최소값으로 돌아가게 됩니다.

예시를 들면, 다음과 같습니다.
위의 도형처럼 표현범위는 A-D입니다.
만약 D+1을 하게되면, A가 나오며
A-1을 하게되면, D가 나오게 됩니다.
이를 활용하면 해당 문제를 풀 수 있습니다.
우선 문제에서
a는 scanf를 통해 %u로 입력 값을 받는데
u 는 unsigned int, 즉 부호 없는 정수 입니다. 부호 없는 정수의 표현 범위는 다음과 같습니다.
0 ~ 4,294,967,295
1. a는 0보다 크고, a+1은 0이어야한다.
해당 조건을 만족하는 값을 생각해보면 4,294,967,295 일때,
1을 더하면 0이 되기에 1의 조건을 만족하는 값은 4294967295 입니다
b의 경우에는 %d 정수로 입력을 받고 있기 때문에
정수의 표현 범위는 다음과 같습니다.
-2,147,483,648 ~ 2,147,483,647
2. b는 1보다 작고, b-1은 0보다 커야한다.
해당 조건을 만족하는 값을 생각해보면, -2147483648에 1을 빼면, 2147483647이 되므로
2의 조건을 만족하는 값은 -2147483648 입니다

'dreamhack > misc' 카테고리의 다른 글
| [dreamhack] robocaptcha (0) | 2025.07.08 |
|---|---|
| [dreamhack] Batch Checker (1) | 2024.01.09 |
| [dreamhack] 산타 할아버지도 힘들어요 (0) | 2024.01.09 |
| [dreamhack] password in the box (0) | 2024.01.09 |
| [dreamhack] pathtraversal (0) | 2023.11.16 |