简体   繁体   中英

Exploiting Buffer Overflow

I have come across a C program which has a buffer overflow flaw. We need to make the program work in our way. As per my understanding overflowing the buffer would overwrite the next memory location. If we consider the following code, the program grants access if the password is goodpassword.I would like to exploit the buffer overflow flaw and giving the input as aaaaaaaaaaaaaaaaaaaaaaaa (24 a's) to overwrite the next memory location so that the program accepts the input for granting the access.

However its, not working as I think the program is getting crashed and I am not able to exploit the flaw. Could you please let me know what went wrong in my approach?

#include <stdio.h>
#include <string.h>

int IsPasswordOk( ) { 
    char password[13]; 
    gets(password); 
    if(!strcmp(password,"goodpassword"))
        return 1; 
    else
        return 0; 
} 

int main(int argc, char* argv[]) { 
    int pwdStatus; 
    puts("Enter password"); 
    pwdStatus = IsPasswordOk(); 
    if(!pwdStatus) { 
        puts("Access denied!"); 
        return -1; 
    } 
    else puts("Access granted!"); 

    return 0; 
}

An overflow need not always be pointing to a valid location. Assume a scenario where the next location may be located in the next page and you don't have access to it. It depends on how your OS distro can handle the situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM