Buffer overflow Attack: Sample Authorization

void A( ) {
  int authorized;
  char name [128];
  authorized = check credentials (...); /* the attacker is not authorized, so returns 0 */
  printf ("What is your name?\n");
  gets (name);
  if (authorized != 0) {
      printf ("Welcome %s, here is all our secret data\n", name)
      /* ... show secret data ... */
  } else
      printf ("Sorry %s, but you are not authorized.\n");

The code is meant to do an authorization check. Only users with the right credentials are allowed to see the top secret data. The function check credentials is not a function from the C library, but we assume that it exists somewhere in the program and does not contain any errors. Now suppose the attacker types in 129 characters. As in the previous case, the buffer will overflow, but it will not modify the return address. Instead, the attacker has modified the value of the authorized variable, giving it a value that is not 0. The program does not crash and does not execute any attacker code, but it leaks the secret information to an unauthorized user.

=> Can the sandboxing technique prevent attack? How?

1 Answer 1


Can the sandboxing technique prevent attack? How?

No, sandboxing will not prevent attacks designed to take advantage of this buffer overflow.

To quote Wikipedia,

In computer security, a sandbox is a security mechanism for separating running programs, usually in an effort to mitigate system failures and/or software vulnerabilities from spreading. It is often used to execute untested or untrusted programs or code, possibly from unverified or untrusted third parties, suppliers, users or websites, without risking harm to the host machine or operating system.

In your case, the program is wholly contained. The authentication is within the program, the authentication bypass is within the program, and the putative secret information is within the program. All the harm that is done is within the program; it does not touch other programs or the operating system.

Therefore, a sandbox, which separates programs, cannot impact the security of this one program. Sandboxes address sets of programs; they do not protect individual programs.

  • Thank you for your answer Please explain why it does not prevent?
    – Love
    Jan 14, 2021 at 21:37
  • @Love: Sandboxing will not prevent the attack here the same as a seat belt will not prevent an accident. Seat belts can mitigate some impact of an accident (like harm to the person but not harm to the car) and the same a sandbox can mitigate some impact of an attack but not everything. And it does not prevent the attack itself, at most some impact. Jan 14, 2021 at 21:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .