Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Buffer Overflow
    primarykey
    data
    text
    <p>I'm trying to teach myself about buffer overflows and exploitation in C++. I'm an intermediate C++ guy, at best, so bear with me. I've followed a few tutorials, but here's some example code to illustrate my question:</p> <pre><code>#include &lt;string&gt; #include &lt;iostream&gt; using namespace std; int main() { begin: int authentication = 0; char cUsername[10], cPassword[10]; char cUser[10], cPass[10]; cout &lt;&lt; "Username: "; cin &gt;&gt; cUser; cout &lt;&lt; "Pass: "; cin &gt;&gt; cPass; strcpy(cUsername, cUser); strcpy(cPassword, cPass); if(strcmp(cUsername, "admin") == 0 &amp;&amp; strcmp(cPassword, "adminpass") == 0) { authentication = 1; } if(authentication) { cout &lt;&lt; "Access granted\n"; cout &lt;&lt; (char)authentication; } else { cout &lt;&lt; "Wrong username and password\n"; } system("pause"); goto begin; } </code></pre> <p>I know there's all kinds of bad juju in here with <code>cin &lt;&lt; String</code>, etc... Anyhow, when I enter too many letters (a ton of <code>A</code>'s for instance) into <code>cUser</code> and <code>cPass</code>, I just get an Access Violation from Visual Studio. If, however, I type 20ish <code>A</code>'s, then a space, then another <code>A</code> into <code>cUser</code>, it skips asking me for <code>cPass</code> (assuming because it's been filled after the space character caused the previous call to <code>cin</code> to return) and just grants me access.</p> <p>At what point, and why, is data overflowing into "authentication" and why does it only happen when I have the space and not when I have a million <code>A</code>'s... I never get the "Access Violation" when I use a space in the input for <code>cUser</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload