{"id":6513463,"date":"2015-09-05T08:34:17","date_gmt":"2015-09-05T08:34:17","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/sql-injection-vulnerability-9\/"},"modified":"2016-08-30T17:39:10","modified_gmt":"2016-08-30T17:39:10","slug":"sql-injection-vulnerability-9","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/sql-injection-vulnerability-9\/","title":{"rendered":"SQL Injection Vulnerability"},"content":{"rendered":"<p>So, you have this query here:<\/p>\n<pre><code>$tablerows = $wpdb-&gt;get_results( &quot;SELECT &lt;code&gt;login_id&lt;\/code&gt;, &lt;code&gt;login_ip&lt;\/code&gt;,&lt;code&gt;login_attempts&lt;\/code&gt;,&lt;code&gt;attempt_time&lt;\/code&gt;,&lt;code&gt;locked_time&lt;\/code&gt; FROM  &lt;code&gt;$tablename&lt;\/code&gt;   WHERE &lt;code&gt;login_ip&lt;\/code&gt; =  &#039;$ip&#039;  ORDER BY &lt;code&gt;login_id&lt;\/code&gt; DESC LIMIT 1 &quot; );<\/code><\/pre>\n<p>The variable $ip is populated by this function<\/p>\n<pre><code>function getip(){\n                   if (!empty($_SERVER[&#039;HTTP_CLIENT_IP&#039;])) {\n                    $ip = $_SERVER[&#039;HTTP_CLIENT_IP&#039;];\n                } elseif (!empty($_SERVER[&#039;HTTP_X_FORWARDED_FOR&#039;])) {\n                    $ip = $_SERVER[&#039;HTTP_X_FORWARDED_FOR&#039;];\n                } else {\n                    $ip = $_SERVER[&#039;REMOTE_ADDR&#039;];\n                     if($ip==&#039;::1&#039;){\n                         $ip = &#039;127.0.0.1&#039;;\n                     }\n                }\n                return $ip;\n            }<\/code><\/pre>\n<p>So if someone sends an X-Forwarded-For HTTP header with a malicious SQL injection payload, they could overwrite your query and hack your database.<\/p>\n<p>https:\/\/wordpress.org\/plugins\/wp-limit-login-attempts\/<\/p>\n","protected":false},"template":"","class_list":["post-6513463","topic","type-topic","status-closed","hentry","topic-tag-sql","topic-tag-sql-injection","topic-tag-sqli"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6513463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6513463\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=6513463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}