Buffer Overflow
BÀI TẬP
Bài tập cá nhân
▪ simple-buffer: File thực thi Linux 32 bit
1
Buffer Overflow: Bài tập 1 (cá nhân)
simple-buffer
▪ File thực thi Linux 32 bit
Hàm smash_my_buffer: đọc 1 input lưu vào buf với gets
int student_id; # biến lưu giá trị số nguyên của student_id
void smash_my_buffer()
{
int var = 0x12345678;
int another_var = 0x0;
char buf[20];
gets(buf);
if ((var != 0x12345678) || (another_var != 0)){
printf("You changed my local variables.\n");
if (another_var == student_id)
printf("Nice works. You've changed my another_var to %d. That's
what I need :)\n", another_var);
else
printf("Almost there. My another_var is %d now. Try harder.\n",
another_var);
}
}
2
Buffer Overflow: Bài tập 1 (cá nhân)
▪ Mục tiêu: nhập input buf sao cho gây ra buffer overflow làm thay đổi biến
another_var thành giá trị số nguyên của MSSV
▪ Vẽ stack: xác định vị trí tương đối giữa buf và biến another_var trong stack.
→ Suy ra được độ dài buf cần nhập là bao nhiêu, vị trí của another_var tương
ứng với phần nào trong buf?
▪ Khi ghi đè giá trị vào 1 ô nhớ: lưu ý về byte ordering trong Linux là Little endian
▪ Cách truyền input cho file simple-buffer: soạn sẵn chuỗi chứa các byte trong file
.py. Ví dụ: truyền 44 ký tự ‘0’ và 4 byte của giá trị 0x0D0C0B0A
python2 python3
$ python <python file> | ./simple-buffer <MSSV>
Nộp hình ảnh minh chứng tại Assignment
3