Day20-Stack 題目練習
Lab 網址 前言 今天大致來到 Stack 部分的尾聲,前面的內容我們討論了幾個經典的 Stack 漏洞,講解了如何進行攻擊並編寫 exploit,也介紹了不少實用的工具。今天,我們將實際練習一道程式碼量較大的題目,這是我在 HITCON 社團攤位時設計的練習題目。 Lab 查看以下原始碼: 1#include<stdio.h> 2#include<stdlib.h> 3#include<unistd.h> 4int choice,num; 5char *product[3] = { 6 "shirt\n", 7 "sticker\n", 8 "tissue\n" 9}; 10 11void buy(){ 12 printf("We have 3 products:\n"); 13 for(int i=0; i<3; i++){ 14 printf("%d. %s", i+1, product[i]); 15 } 16 printf("Which one do you want to buy? "); 17 scanf("%d", &choice); 18 printf("You have bought %s\n", product[choice-1]); 19 printf("How many do you want to buy? "); 20 scanf("%d", &num); 21 return; 22} 23 24char address[0x20]; 25int main(){ 26 setvbuf(stdout, 0, _IONBF, 0); 27 setvbuf(stdin, 0, _IONBF, 0); 28 printf("This is HackerSir!\n"); 29 printf("Welcome to the shop!\n"); 30 printf("1. Buy\n"); 31 printf("2. Exit\n"); 32 printf("Your choice: "); 33 scanf("%d", &choice); 34 if(choice==1){ 35 buy(); 36 printf("Please leave your address: "); 37 scanf("%s", address); 38 printf(address); 39 }else{ 40 printf("Goodbye!\n"); 41 exit(0); 42 } 43 char last[0x10]; 44 printf("\nleave your last message to our club: "); 45 read(0, last, 0x30); 46 return 0; 47} 使用以下指令進行編譯: ...