๐ŸปELF x86 - Stack buffer overflow basic 3

Note : A JOURNEY TO GAIN KNOWLEDGE

#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
 
void shell(void);
 
int main()
{
 
  char buffer[64];
  int check;
  int i = 0;
  int count = 0;
 
  printf("Enter your name: ");
  fflush(stdout);
  while(1)
    {
      if(count >= 64)
        printf("Oh no...Sorry !\n");
      if(check == 0xbffffabc)
        shell();
      else
        {
            read(fileno(stdin),&i,1);
            switch(i)
            {
                case '\n':
                  printf("\a");
                  break;
                case 0x08:
                  count--;
                  printf("\b");
                  break;
                case 0x04:
                  printf("\t");
                  count++;
                  break;
                case 0x90:
                  printf("\a");
                  count++;
                  break;
                default:
                  buffer[count] = i;
                  count++;
                  break;
            }
        }
    }
}
 
void shell(void)
{
  setreuid(geteuid(), geteuid());
  system("/bin/bash");
}

Phรขn tรญch:

  • Dแปฑa vร o thแปฉ tแปฑ khai bรกo biแบฟn, ta cรณ thแปƒ phรกt thแบฃo thแปฉ tแปฑ trong stack nhฦฐ sau:

  • Nhฦฐ vแบญy khรกc vแป›i cรกc chall 1 vร  2, lรบc nร y biแบฟn check ฤ‘ฦฐแปฃc khai bรกo sau biแบฟn buffer ta khรดng thแปƒ nhแบญp trร n ฤ‘แปƒ ghi ฤ‘รจ giรก trแป‹ lรชn check

  • Lรบc nร y review lแบกi code ฤ‘แปƒ รฝ mแป™t hร m lแบก lแบซm read(fileno(stdin),&i,1);

  • Nhฦฐ vแบญy hร m nร y giรบp ta ฤ‘แปc tแปซng kรญ tแปฑ cแปงa chuแป—i nhแบญp vร o, nรชn nhแป› buff ฤ‘ฦฐแปฃc lฦฐu dฦฐแป›i dแบกng chuแป—i mรฌnh cรณ thแปƒ truy xuแบฅt tแปซng phแบงn tแปญ :

  • ฤแปƒ รฝ case sau:

case 0x08:
    count--;
    printf("\b");
  • Nhฦฐ vแบญy รฝ tฦฐแปŸng lรบc nร y ta cรณ thแปƒ ฤ‘แปc lแบกi tแปซng phแบงn tแปญ cแปงa check vร  thay ฤ‘แป•i giรก trแป‹ cแปงa chรบng bแบฑng viแป‡c giแบฃm giรก trแป‹ biแบฟn count vร  ghi ฤ‘รจ vร i tแปซng bytes tฦฐฦกng แปฉng vแป›i format little-endiant

default:
  buffer[count] = i;
  count++;

flag: Sm4shM3ify0uC4n

Last updated