{"id":174,"date":"2021-11-14T15:28:48","date_gmt":"2021-11-14T15:28:48","guid":{"rendered":"https:\/\/www.davincivirus.com\/?p=174"},"modified":"2021-11-14T15:50:56","modified_gmt":"2021-11-14T15:50:56","slug":"sql-injection","status":"publish","type":"post","link":"https:\/\/www.davincivirus.com\/?p=174","title":{"rendered":"SQL Injection"},"content":{"rendered":"\n<p>A SQL injection (SQLi) occurs when an unfiltered user parameter is rendered as executable logic by a database management system (DBMS). The impact stemming from this vulnerability can range from disclosure of sensitive data to arbitrary code execution.<\/p>\n\n\n\n<p>As with most vulnerabilities, this deficiency is caused by improper input validation and\/or output encoding.  Concatenation of strings to create SQL statement is commonly associated with vulnerable code. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"547\" height=\"76\" src=\"https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/StringConcatenation.jpg\" alt=\"\" class=\"wp-image-175\" srcset=\"https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/StringConcatenation.jpg 547w, https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/StringConcatenation-300x42.jpg 300w, https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/StringConcatenation-540x76.jpg 540w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/figure>\n\n\n\n<h2>Exploitation<\/h2>\n\n\n\n<p>An attacker will append series of special characters to request parameters in search of SQLi.  System errors or abnormal responses help diagnose vulnerable segments of the application.  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"523\" src=\"https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/sqli_hunting-1024x523.jpg\" alt=\"\" class=\"wp-image-177\" srcset=\"https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/sqli_hunting-1024x523.jpg 1024w, https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/sqli_hunting-300x153.jpg 300w, https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/sqli_hunting-768x392.jpg 768w, https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/sqli_hunting.jpg 1030w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>A methodical process of tweaking the request parameter will then ensue to perfect the payload.  This process often necessitates setting up a test instance of the target DBMS.  Contrastingly, a more haphazard approach would employ automated exploitation frameworks; most notably SQLMap.  <\/p>\n\n\n\n<p>Technical hurdles will often accompany exploitation of a SQLi vulnerability.  Attackers will often need to utilize creative solutions to exfiltrate data and further their attack.  For example, appending exfiltrated data into a user retrievable value within the database.  The below image depicts a payload that stores data into a user&#8217;s profile image.  An attacker can subsequently retrieve the information by simply navigating the image URL.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"870\" height=\"99\" src=\"https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/imageExfiltration-1.jpg\" alt=\"\" class=\"wp-image-183\" srcset=\"https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/imageExfiltration-1.jpg 870w, https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/imageExfiltration-1-300x34.jpg 300w, https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/imageExfiltration-1-768x87.jpg 768w\" sizes=\"(max-width: 870px) 100vw, 870px\" \/><\/figure>\n\n\n\n<h2>Remediation<\/h2>\n\n\n\n<p>The utilization of parameterized statements will output encode any values being appended to a SQL command.  This will almost always prevent exploitation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"663\" height=\"131\" src=\"https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/parameterizedQueries.jpg\" alt=\"\" class=\"wp-image-176\" srcset=\"https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/parameterizedQueries.jpg 663w, https:\/\/www.davincivirus.com\/wp-content\/uploads\/2021\/11\/parameterizedQueries-300x59.jpg 300w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A SQL injection (SQLi) occurs when an unfiltered user parameter is rendered as executable logic by a database management system&hellip; <a class=\"read-more\" href=\"https:\/\/www.davincivirus.com\/?p=174\">Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/posts\/174"}],"collection":[{"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=174"}],"version-history":[{"count":3,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":184,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions\/184"}],"wp:attachment":[{"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}