해킹 공격의 예술 실습(5)
-
간단한 서버 소스 코드 분석
#include #include #include #include #include #include #include "hacking.h" #define PORT 7890 int main(void) { int sockfd, new_sockfd; struct sockaddr_in host_addr, client_addr; socklen_t sin_size; int recv_length = 1, yes = 1; char buffer[1024]; // int socket(int domain, int type, int protocol) // socket(IPv4, TCP, 0) // 소켓을 생성하는 함수, PF_INET 어떤 영역에서 통신을 할 것인 지 설정, TYPE 어떤 프로토콜로 통신 할 것인 지 설정(TCP,..
2022.03.19 -
소멸자를 이용한 우회법
GNU C 컴파일러를 이용해 컴파일된 이진 프로그램에서는 소멸자와 생성자를 위한 특수 테이블 섹션인 .dtors와 .ctors를 생성합니다. 생성자 함수는 main 함수 실행되기 전에 호출되고 소멸자 함수는 main 함수가 exit 시스템 콜로 끝나기 바로 전에 실행됩니다. 관련 코드와 실행 결과는 다음과 같습니다. #include #include static void cleanup(void) __attribute__ ((destructor)); main() { printf("Some actions happen in the main() function..\n"); printf("and then when main() exits, the destructor is called..\n"); exit(0); } ..
2022.03.10 -
힙 기반 오버 플로우
이번 실습은 힙 오버 플로우 공격입니다. 취약한 소스 코드는 아래와 같습니다. 더보기 #include #include #include #include #include #include "hacking.h" void usage(char *prog_name, char *filename) { printf("Usage: %s \n", prog_name, filename); exit(0); } void fatal(char *); // a function for fatal errors void *ec_malloc(unsigned int); // an errorchecked malloc() wrapper int main(int argc, char *argv[]) { int userid, fd; // file descr..
2022.03.06 -
환경 변수를 이용한 공격
두 번째 실습으로 환경 변수를 이용한 공격이다. 리눅스에서 프로그램을 실행하면 환경 변수도 같이 스택에 올라갑니다. 만약 환경 변수에 shellcode를 삽입하고 Return Address 주소를 shellcode의 위치로 변조한다면 셸을 실행시킬 수 있을 것입니다. 먼저 셸 스크립트를 사용하여 exploit_notesearch.c에 있는 shellcode를 추출해서 shellcode.bin에 추출한 후 NOP Sled를 추가해서 환경 변수를 선언합니다. gdb를 통해 확인해보면 SHELLCODE가 스택에 위치한 것을 확인할 수 있습니다. 이제 버퍼 오버 플로우 공격을 통해 RET를 주소를 NOP 위치로 변조하면 셸을 실행시킬 수 있습니다. 충분히 큰 NOP Sled는 셸을 실행시키기 쉽게 합니다. 하지..
2022.03.04 -
NOP Sled
해킹 공격의 예술 첫 번째 실습입니다. 더보기 #include #include #include #include #include "hacking.h" #define FILENAME "/var/notes" int print_notes(int, int, char *); // note printing function int find_user_note(int, int); // seek in file for a note for user int search_note(char *, char *); // search for keyword function void fatal(char *); // fatal error handler int main(int argc, char *argv[]) { int userid, prin..
2022.03.04