코딩
#include <stdio.h>
void main()
{
char *name;
char *command;
name=(char *)malloc(10);
command=(char *)malloc(128);
printf("address of Name is : %d \n", name);
printf("address of Command is : %d \n", command);
printf("Difference between address is : %d \n", command-name);
printf("hey Enter your name: ");
gets(name);
printf("Hellow %s\n", name);
system(command);
}
MacBook-2:~ MGP$ gcc buffer.c -o buffer
실행
MacBook-2:~ MGP$ ./buffer
address of Name is : -1337968080
address of Command is : -1337968064
Difference between address is : 16
warning: this program uses gets(), which is unsafe.
hey Enter your name: www.keralacyberforces.in
Hellow www.keralacyberforces.in
sh: orces.in: command not found
MacBook-2:~ MGP$ ./buffer
address of Name is : 155204144
address of Command is : 155204160
Difference between address is : 16
warning: this program uses gets(), which is unsafe.
hey Enter your name: www.keralacyberfcat /etc/passwd
cat /etc/passwd가 실행된다.
This buffer overflow is caused because the gets() function doesn't limit's the length of the input.
To overrule this buffer overflow you can use frets(name, 10, stdin); where it will read a maximum of 10 characters from the input.
'컴퓨터 > 리눅스' 카테고리의 다른 글
backtrack에서 ssh 설치 및 설정 접속 (0) | 2013.08.17 |
---|---|
route (0) | 2013.08.12 |
ping, traceroute, netstat 명령어 (0) | 2013.08.12 |
리눅스 파일 압축하기 압축풀기 (1) | 2013.08.09 |
리눅스 실행 파일 (0) | 2013.07.12 |