Skip to content

Commit

Permalink
Deployed f86b14e with MkDocs version: 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchiii committed May 10, 2024
1 parent cc6a2e6 commit 264b580
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
5 changes: 3 additions & 2 deletions binary-exploitation/what-is-the-heap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3238,6 +3238,7 @@ <h2 id="using-the-heap">Using the heap</h2>
<p>Let's see how these could be used in a program:</p>
<div class="highlight"><pre><span></span><code><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;stdio.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;stdlib.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;string.h&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;unistd.h&gt;</span>

<span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
Expand All @@ -3248,7 +3249,7 @@ <h2 id="using-the-heap">Using the heap</h2>
<span class="w"> </span><span class="n">scanf</span><span class="p">(</span><span class="s">&quot;%u&quot;</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">alloc_size</span><span class="p">);</span>

<span class="w"> </span><span class="n">stuff</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="n">alloc_size</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
<span class="w"> </span><span class="n">memset</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">stuff</span><span class="p">,</span><span class="w"> </span><span class="n">alloc_size</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
<span class="w"> </span><span class="n">memset</span><span class="p">(</span><span class="n">stuff</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">alloc_size</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>

<span class="w"> </span><span class="n">read</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">stuff</span><span class="p">,</span><span class="w"> </span><span class="n">alloc_size</span><span class="p">);</span>

Expand Down Expand Up @@ -3282,7 +3283,7 @@ <h2 id="using-the-heap">Using the heap</h2>
<span class="md-icon" title="Last update">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg>
</span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">January 26, 2024</span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">April 30, 2024</span>
</span>


Expand Down
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

Binary file modified sitemap.xml.gz
Binary file not shown.
74 changes: 72 additions & 2 deletions web-exploitation/sql-injection/what-is-sql-injection/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,17 @@



<label class="md-nav__link md-nav__link--active" for="__toc">


<span class="md-ellipsis">
What is SQL Injection
</span>


<span class="md-nav__icon md-icon"></span>
</label>

<a href="./" class="md-nav__link md-nav__link--active">


Expand All @@ -1423,6 +1434,34 @@

</a>



<nav class="md-nav md-nav--secondary" aria-label="Table of contents">






<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>

<li class="md-nav__item">
<a href="#preventing-sql-injection" class="md-nav__link">
<span class="md-ellipsis">
Preventing SQL Injection
</span>
</a>

</li>

</ul>

</nav>

</li>


Expand Down Expand Up @@ -3146,6 +3185,23 @@



<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>

<li class="md-nav__item">
<a href="#preventing-sql-injection" class="md-nav__link">
<span class="md-ellipsis">
Preventing SQL Injection
</span>
</a>

</li>

</ul>

</nav>
</div>
</div>
Expand Down Expand Up @@ -3176,8 +3232,8 @@ <h1 id="sql-injection">SQL Injection</h1>
</code></pre></div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Notice the extra single quote at the end.</p>
</div>
<p>Notice the extra single quote at the end.</p>
<p>With the knowledge that a single quote will cause an error in the application we can expand a little more on SQL Injection.</p>
<p>What if our input was <code>' OR 1=1</code>?</p>
<div class="highlight"><pre><span></span><code><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">users</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">username</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="w"> </span><span class="k">OR</span><span class="w"> </span><span class="mi">1</span><span class="o">=</span><span class="mi">1</span>
Expand All @@ -3191,6 +3247,20 @@ <h1 id="sql-injection">SQL Injection</h1>
</code></pre></div>
<p>This payload sets the username parameter to an empty string to break out of the query and then adds a comment (<code>--</code>) that effectively hides the second single quote.</p>
<p>Using this technique of adding SQL statements to an existing query we can force databases to return data that it was not meant to return.</p>
<h2 id="preventing-sql-injection">Preventing SQL Injection</h2>
<p>The best way to prevent SQL Injection is to use prepared statements. Prepared statements are a way to execute SQL queries that separates the query logic from the data being passed into the query.</p>
<div class="highlight"><pre><span></span><code><span class="cp">&lt;?php</span>
<span class="nv">$stmt</span> <span class="o">=</span> <span class="nv">$pdo</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s1">&#39;SELECT * FROM users WHERE username = :username&#39;</span><span class="p">);</span>
<span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">execute</span><span class="p">([</span><span class="s1">&#39;username&#39;</span> <span class="o">=&gt;</span> <span class="nv">$username</span><span class="p">]);</span>
<span class="cp">?&gt;</span>
</code></pre></div>
<p>In this example, the <code>:username</code> is a placeholder that is replaced with the value of the <code>$username</code> variable. The database driver will automatically escape the value of <code>$username</code> to prevent SQL Injection.</p>
<p>Another way to prevent SQL Injection is to use an ORM (Object Relational Mapping) library. ORM libraries abstract the database layer and allow you to interact with the database using objects instead of raw SQL queries.</p>
<div class="highlight"><pre><span></span><code><span class="cp">&lt;?php</span>
<span class="nv">$user</span> <span class="o">=</span> <span class="nx">User</span><span class="o">::</span><span class="na">where</span><span class="p">(</span><span class="s1">&#39;username&#39;</span><span class="p">,</span> <span class="nv">$username</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">first</span><span class="p">();</span>
<span class="cp">?&gt;</span>
</code></pre></div>
<p>ORM libraries automatically escape user input to prevent SQL Injection.</p>



Expand All @@ -3213,7 +3283,7 @@ <h1 id="sql-injection">SQL Injection</h1>
<span class="md-icon" title="Last update">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg>
</span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">January 26, 2024</span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">April 30, 2024</span>
</span>


Expand Down

0 comments on commit 264b580

Please sign in to comment.