목록Hack (231)
CIDY
*sandbox 샌드박스는 외부의 공격으로부터 시스템을 보호하기 위해 설계된 보호 기법이다. -> Allow List와 Deny list 두 가지를 선택 적용할 수 있다. -> 프로그램의 기능 수행에 있어 꼭 필요한 시스템 콜 실행과 필수적인 파일에 대한 접근만을 허용함. -> 외부 공격 최소화 프로그램마다 목적과 기능이 제각기 다르기 떄문에 샌드박스는 개발자가 직접 명시해야 함 -> 오용할 경우 서비스 접근성을 과하게 해치거나 목적한 기능의 정상적 작동이 이루어지지 않을 수 있음. *SECCOMP secure computing mode -> 리눅스 커널에서 프로그램의 샌드박싱 매커니즘을 제공하는 컴퓨터 보안 기능. -> 불필요한 시스템 콜의 호출을 방지할 수 있다. 예를 들어 어플에서 외부의 시스템 명..

시스템 해킹 로드맵의 마지막 문제이다. C코드가 주어지지 않아서 아이다로 까 봐야 했다. int __cdecl main(int argc, const char **argv, const char **envp) { char s[128]; // [rsp+0h] [rbp-80h] BYREF memset(s, 0, 16uLL); read(0, s, 0x400uLL); validate(s, 128LL); return 0; } 일단 버퍼에 read하고 validate하는 간단한 코드인데.. 말 그대로 검증하는거다. validate함수에 전달되는 인자는 배열과 128이라는 숫자이다. 그럼 저 검증조건을 까 보자. __int64 __fastcall validate(__int64 a1, unsigned __int64 a2)..

#include #include #include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } int main() { char cmd_ip[256] = "ifconfig"; int dummy; char center_name[24]; init(); printf("Center name: "); read(0, center_name, 100); if( !strncmp(cmd_ip, "ifconfig", 8)) { system(cmd_ip); } else { printf("Something is wrong!\n"); } exit(0); } 메타문자를 잘 쓰면 되는 부분이다. from pwn import * #p = proce..

// 32-bit, nx, partial relro #include #include #include #include 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); } void get_shell() { system("/bin/sh"); } int main() { char buf[256]; int size; initialize(); signal(SIGSEGV, get_shell); printf("Size: "); scanf("%d"..

#include #include #include #include char *ptr[7]; void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); } void create_heap(int idx) { size_t size; if( idx >= 7 ) exit(0); printf("Size: "); scanf("%ld", &size); ptr[idx] = malloc(size); if(!ptr[idx]) exit(0); printf("Data: "); read(0, ptr[idx], size-1); } void modify_heap() { size_t size, idx; printf("idx: "); scan..

// gcc -o tcache_dup tcache_dup.c -no-pie // 64-bit, canary, nx, partial relro #include #include #include #include char *ptr[10]; void alarm_handler() { exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(60); } int create(int cnt) { int size; if(cnt > 10) { return -1; } printf("Size: "); scanf("%d", &size); ptr..

이전 글에서 double free를 통해 duplication list를 형성할 수 있다고 했었다. 그런데 만약 청크를 중복으로 연결해두고, 한 번 재할당하면 어떻게 될까? -> 그 청크는 해제된 청크인 동시에 할당된 청크이다. -> 임의 주소에 청크를 할당하거나, 그 청크를 이용해 임의 주소 데이터를 읽기 및 조작할 수 있다. 이를 Tcache Poisoning이라고 한다. 해제된 청크와 할당된 청크 구조의 가장 큰 차이점은 청크 헤더이다. 청크 구조에 대해서는 아래 글에서 설명했었다. ↓ https://orcinus-orca.tistory.com/55 중첩된 상태의 청크에 임의의 값을 써 fd, bk를 조작할 수 있다. -> free list는 fd와 .bk로 연결되므로, ptmalloc2의 free..
*Double free 이전 글에서 free함수로 할당 해제된 청크는 tcache나 bin에 보관되며, 비슷한 크기의 재할당 요청이 들어올 경우 이 연결 리스트들을 탐색해 청크를 재할당하는 과정을 설명했었다. 근데 이전 uaf문제를 풀 때도 설명했지만, free함수 자체는 메모리 공간이나 포인터를 초기화시키는 기능이 없다. 예를 들어 A = malloc(0x80); 이렇게 할당 후 free(A); 를 해줘도 A가 널포인터가 된 것은 아니므로(Dangling pointer) 다시 free(A)해줄수도 있는 부분이다. -> 청크를 tcache나 bin에 여러 번 중복 추가 가능함. 청크가 tcache나 bin에 중복으로 존재하는 것을 "청크가 duplicated됐다" 라고 말한다. 이 duplicated f..