0% found this document useful (0 votes)
55 views3 pages

Buffer Overflow

Bài tập yêu cầu người làm thực hiện buffer overflow để thay đổi giá trị biến another_var thành mã sinh viên bằng cách nhập đúng số lượng ký tự vào biến buf. Cần vẽ biểu đồ stack để xác định vị trí các biến và độ dài cần nhập cho buf. Sử dụng little endian và gửi input qua ống dẫn từ file python.

Uploaded by

Tan Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views3 pages

Buffer Overflow

Bài tập yêu cầu người làm thực hiện buffer overflow để thay đổi giá trị biến another_var thành mã sinh viên bằng cách nhập đúng số lượng ký tự vào biến buf. Cần vẽ biểu đồ stack để xác định vị trí các biến và độ dài cần nhập cho buf. Sử dụng little endian và gửi input qua ống dẫn từ file python.

Uploaded by

Tan Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like