Fault Hunting or Finding

32 views Asked by At

I have this code, could someone suggest to me any input string that might make the code to crush, probably make the code to through a segmentation fault error

#define POLYNOMIAL 0x04c11db7L
uint32_t crc_table[256];

int win()
{
  printf("Great Job\n");
  exit(0);
}


void gen_crc_table()
{
 uint16_t i, j;
 uint32_t crc_accum;

 for (i=0; i<256; i++)
  {
    crc_accum = ((uint32_t)i << 24);
    for (j = 0;j < 8; j++)
    {
        if (crc_accum & 0x80000000L)
            crc_accum = (crc_accum << 1) ^ POLYNOMIAL;
        else
            crc_accum = (crc_accum << 1);
    }
    crc_table[i] = crc_accum;
   } 
}

uint32_t update_crc(uint32_t crc_accum, uint8_t *data_blk_ptr, uint32_t data_blk_size)
{
 uint32_t i, j;

for (j=0; j < data_blk_size; j++)
{
    i = ((int) (crc_accum >> 24) ^ *data_blk_ptr++) & 0xFF;
    crc_accum = (crc_accum << 8) ^ crc_table[i];
 }
  crc_accum = ~crc_accum;
  return crc_accum;
}


int main()
{
  char buffer[256];
  unsigned long long target;

  scanf("%256s", buffer);
  gen_crc_table();
  if (update_crc(-1, buffer, sizeof(buffer)) == 0x4920cbc3)
  {
    memcpy(buffer + 128, buffer, sizeof(buffer));
  }
  exit(1);
 }

I have tried to use this kind of input but am still not able to cause experience any fault within this code.

abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

1

There are 1 answers

0
Employed Russian On

I have tried to use this kind of input but am still not able to cause experience any fault within this code.

You need to prepare the input for which update_crc() will return a particular value 0x4920cbc3.

"Random" guessing "by hand" is unlikely to produce such output. You'll probably want to try random input in a program and check the result for expected value.

Since the CRC is not a cryptographically strong hash, you should be able to find such input without enumerating all possible (22048`) inputs.

You could probably start the search by using all possible ASCII inputs.