Jump to content

[C++] Basic Buffer Overflow Vulnerable Code


K1u

Recommended Posts

Something I wrote for a new section on my site, angablade might make some on vulns in php soon.

Vulnerable:

#include <iostream>

int main(void)
{
   char ownme[255] = { 0 };
   std::cin >> ownme;
   getchar();
}

Solution:

The code may be exploited by entering a value of 256 chars, causing just one form of a very basic Buffer Overflow.

This occurs logically due to more going in than meant to go in.

This concept may not be easy to all, so I will explain through a example, if I were to fill a balloon with more air than it could take it would explode, very simple example to understand.

More information: Buffer Overflow - http://en.wikipedia.org/wiki/Buffer_overflow

Writing a secure version of the code:

#include <iostream>

int main(void)
{
   char hahacantownme[256] = { 0 };
   std::cin.getline(hahacantownme, 255);
   getchar();
}

Notice that I use the max which is 256 and only permit to get 1 lower than this.

I hope you enjoyed and also learned something.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...