<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vinicius Aragão</title>
    <description>The latest articles on DEV Community by Vinicius Aragão (@bsqqq).</description>
    <link>https://dev.to/bsqqq</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F926376%2F040d5f06-2b69-4e89-9114-aa971623a1a0.jpeg</url>
      <title>DEV Community: Vinicius Aragão</title>
      <link>https://dev.to/bsqqq</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bsqqq"/>
    <language>en</language>
    <item>
      <title>Case of Study: Buffer Overflow and arbitrary code execution in C.</title>
      <dc:creator>Vinicius Aragão</dc:creator>
      <pubDate>Fri, 21 Oct 2022 13:05:33 +0000</pubDate>
      <link>https://dev.to/bsqqq/case-of-study-buffer-overflow-and-arbitrary-code-execution-in-c-2208</link>
      <guid>https://dev.to/bsqqq/case-of-study-buffer-overflow-and-arbitrary-code-execution-in-c-2208</guid>
      <description>&lt;p&gt;Hi everyone, first of all, sorry for my poor english.&lt;/p&gt;

&lt;p&gt;It's a simple concept with a more simple case but it can start some spark in some people who are not aware of security implementation of their codes and programs, this is more directed to new programmers who are starting their studies and carrers. (But of course, even the experienced can have some new knowledge today 😁, this is what a community is made for).&lt;/p&gt;

&lt;p&gt;Ok, to be more specific about this case, the versions of the...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C -&amp;gt; 201112L (C11),
GCC -&amp;gt; 6.3.0,
x32dbg -&amp;gt; Jan 1 2022 20:06:58,
Python -&amp;gt; 3.10.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, to start this...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmk7v4tzfibxmunar591l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmk7v4tzfibxmunar591l.png" alt="vuln.c"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is this simple code in C that has only 4 lines inside the main() function and another function declared above called vitoria(), ok! very simple...&lt;/p&gt;

&lt;p&gt;As you can see, the function called &lt;code&gt;vitoria()&lt;/code&gt; is not being summoned into &lt;code&gt;main()&lt;/code&gt; function, so how we can get access to this function without calling it inside in main function?&lt;/p&gt;

&lt;p&gt;When the program is running in our RAM, all the content is loaded in memory without any exception, even the function vitoria() is somewhere in memory, even if won't be accessed throw ordinary ways, somewhere in some memory address..., &lt;/p&gt;

&lt;p&gt;To locate it, we need to use the debugger and search for the string in it, but beware, that's the address of the string in memory, not the entry point of the function that usually starts with &lt;code&gt;push ebp&lt;/code&gt; if compiled with GCC, it should be somewhere near the string address.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fme7evev05657gof9udpd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fme7evev05657gof9udpd.png" alt="Image description"&gt;&lt;/a&gt; (this is where the string inside the function in interest is located, but we should look for the &lt;code&gt;push ebp&lt;/code&gt; of it, wich is the start of th function vitoria())&lt;/p&gt;

&lt;p&gt;When we hit the part of the program that waits for our input, expressed with &lt;code&gt;call &amp;lt;JMP.&amp;amp;gets&amp;gt;&lt;/code&gt; inside the debugger, here is the part that we enter the exploit to overwrite the return address to enter the new one that should be the address of the entry point of the vitoria() function, so what we need to do now is enter a big enough input to overwrite the return address with "special characters" that, in hexadecimal, will now make the top of the stack point to the address of the vitoria() function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftndiegy5hlv22ub685ll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftndiegy5hlv22ub685ll.png" alt="Image description"&gt;&lt;/a&gt; (here i "inputed" 66 bytes of 'a' to reach the exact region of the return address, to leave the gets() function...)&lt;/p&gt;

&lt;p&gt;Depending if your system is 32 or 64 bits, the "payload" will have different sizes and other characters in order to do the correct buffer overflow... just count how many bytes will be necessary to overwrite the return address and what should be the last caracters to access the desired address.&lt;/p&gt;

&lt;p&gt;After that input, we should see a bunch of "61" inside of our stack... wich means the bunch of 'a' that i've inputed...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8figld6gy0b7t98equor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8figld6gy0b7t98equor.png" alt="Image description"&gt;&lt;/a&gt; (this sausage of "61 bytes" runs all the way down to the return address...)&lt;/p&gt;

&lt;p&gt;Now check this highlighted address in the picture below, see this little red thing on the left? this indicates the return address, i overwrited with the huge input that i've sent and if the program proceeds with this new information, it should get the "Segmentation fault" or Exception Access Violation, or simply it has returned to some address that wasn't supposed to return, resulting in crash...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1c5ve275igctrxdmjkd7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1c5ve275igctrxdmjkd7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, by far we know how many bytes we have to send to overwrite the return address, but with what bytes should we send to get the correct address and display the desired message?&lt;/p&gt;

&lt;p&gt;Going back to where we find the desired string, we can see with just some few addresses above the &lt;code&gt;push ebp&lt;/code&gt; instruction, now if we look at the address that this instuction is placed, this are the bytes that we need to send in the input, just within the last 3 bytes, we need to change it to be exact the same address, in hexadecimal of course.&lt;/p&gt;

&lt;p&gt;In order to get this correctly done, if we replace the last 3 'a' in the input with the same corresponding bytes in ASCII table (which is \x10\x14\x40) we should get the right address to return, so lets give it a try... (notice that i've putted the bytes from back to front, this is because of the little endian organization of bytes, almost everything is organized like this in little endian, wich means, that the most valuable bytes are in the most right position)&lt;/p&gt;

&lt;p&gt;If you are familiar with &lt;a href="https://condor.depaul.edu/sjost/lsp121/documents/ascii-npr.htm" rel="noopener noreferrer"&gt;ASCII table&lt;/a&gt;, you will know that both \x10 and \x14 bytes are not printable characters, so we will need to input with ^P and ^T, that translates to \x10 and \x14 (the ^ simbol is "control", so ctrl + shift + P and ctrl + shift + T), the \x40 is printable, is the '@' simbol, now lets get everything together...&lt;/p&gt;

&lt;p&gt;Running the program again but sending the correct input to overwrite the return address to where i desire to be...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwomd1rw7z351cb4qljnp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwomd1rw7z351cb4qljnp.png" alt="prompted the payload"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we got it!! Now if i do some steps we should get the message from vitoria() function without calling it inside the main() function...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1a8qad7e5fdevqdrg7hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1a8qad7e5fdevqdrg7hw.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, nice... but how do we fix this vulnerability? Well, using safety input functions such as fgets or fscanf, the syntax is a little bit different but not really complicated, google a little bit and it should do. That's it for today, hope you learned something new today! please feel free to comment below. &lt;/p&gt;

</description>
      <category>programming</category>
      <category>security</category>
      <category>testing</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Modern React Tutorials online for free!</title>
      <dc:creator>Vinicius Aragão</dc:creator>
      <pubDate>Tue, 27 Sep 2022 20:21:39 +0000</pubDate>
      <link>https://dev.to/bsqqq/modern-react-tutorials-online-for-free-3cbi</link>
      <guid>https://dev.to/bsqqq/modern-react-tutorials-online-for-free-3cbi</guid>
      <description>&lt;p&gt;Hi, is my first official post into dev.to community and i'd like to share this parctical free course that i found... it looks really intuitive and easy to learn, the same creator has the JavaScript course that is teached in the same way as this one, also CSS.&lt;/p&gt;

&lt;p&gt;Check the links below 👇👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://react-tutorial.app/"&gt;https://react-tutorial.app/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://jadjoubran.io/"&gt;https://jadjoubran.io/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
