{"id":18870,"date":"2024-06-25T11:19:00","date_gmt":"2024-06-25T10:19:00","guid":{"rendered":"https:\/\/staging2022.42crunch.com\/?p=18870"},"modified":"2024-06-25T11:20:07","modified_gmt":"2024-06-25T10:20:07","slug":"the-scourge-of-sql-injection-for-apis","status":"publish","type":"post","link":"https:\/\/staging2022.42crunch.com\/the-scourge-of-sql-injection-for-apis\/","title":{"rendered":"The Scourge of SQL Injection for APIs"},"content":{"rendered":"

In a <\/span>report<\/span><\/a> published in May 2024, cybersecurity firm Eclypsium outlined key vulnerabilities discovered in the F5 Big IP Next device. It’s another sobering reminder of the challenges faced in securing APIs when a highly regarded security company like F5 launches a new flagship product with all-too-familiar vulnerabilities like SQL injection and SSRF.<\/span><\/p>\n

Among the vulnerabilities reported by Eclypsum, unauthenticated SQL injection deserves special attention. Injection attacks are very common and this was arguably the most dangerous vulnerability in this case, because it provided the easiest entry point for an unauthorized user.<\/span><\/p>\n

Injection attacks are often successful when developers fail to define and enforce appropriate constraints on API input. This appears to be what happened in this case.<\/span><\/p>\n

 <\/p>\n

<\/h2>\n

Follow the API data<\/span><\/h2>\n

The F5 API endpoint in question is documented <\/span>here<\/span><\/a>. This is a user login operation. Both the username and the provider_name fields were found to be vulnerable to injection attacks, although the provider_name field is the one specifically vulnerable to SQL injection.<\/span><\/p>\n

Note the schema description for provider_name as \u201cnon-empty string\u201d. It’s quite vague!<\/span><\/p>\n

\"\"<\/p>\n

F5 BIG-IP Next Central Manager API Specifications<\/span><\/em><\/p>\n

 <\/p>\n

Jumping into F5\u2019s OpenAPI file for the same API data, the requirements set for the provider_name input are simply that <\/span>it must be a string with a minimum length of 1<\/b>.\u00a0<\/span><\/p>\n

\"\"<\/p>\n

F5 BIG-IP Next OpenAPI file<\/span><\/em><\/p>\n

 <\/p>\n

Again this is a <\/span>very<\/span><\/i> vague definition of the API\u2019s input. It gives hackers enough leeway to try different attack patterns on the API and see what works. In the case of the BIG IP Next device, this is the malicious pattern for provider_name that worked:<\/span><\/p>\n

"LDAPP'or' name = (select case when (password like concat({full_guess})) then chr(76)||chr(111)||chr(99)||chr(97)||chr(108) else chr(76) end from mbiq_system.users where username like concat({encoded_user}) limit 1)"<\/code><\/p>\n

That doesn’t look like a valid provider name! Why was this input allowed?\u00a0<\/span><\/p>\n

Because<\/span> it\u2019s a string and it\u2019s more than one character long. <\/b>Remember, this was the only requirement set for the provider_name input. The hacker\u2019s malicious input met that requirement. The API requirement <\/span>is<\/span><\/i> the vulnerability!<\/span><\/p>\n

To prevent injection vulnerabilities developers need to set precise requirements on API input fields. By documenting those requirements formally, using OpenAPI, it provides a common reference for developers to code to, and testers to verify against.\u00a0<\/span><\/p>\n

Documenting requirements is not a security solution in itself. But this <\/span>is<\/span><\/i> a well-established practice for producing reliable software. Poorly defined API requirements infiltrate the development and testing phases as vulnerabilities, and ultimately into production where, as evidenced by this case, they can be discovered and exploited.\u00a0<\/span><\/p>\n

 <\/p>\n

<\/h2>\n

<\/h2>\n

Prevent vulnerabilities at the source<\/span><\/h2>\n

Let’s take the F5 case as an example and think about how to define, implement and test API requirements to avoid SQL injection vulnerabilities during API development.<\/span><\/p>\n

 <\/p>\n

Locate missing requirements\u00a0<\/span><\/h4>\n

We start in the OpenAPI file. The F5 OpenAPI file has over 81,000 lines. How can a team find the missing API requirements?\u00a0<\/span><\/p>\n

42Crunch API Security Audit reveals missing or incomplete API requirements in OpenAPI files. In the case of F5, it immediately flags a vulnerability with the provider_name field, which lacks precise constraints on the data.\u00a0<\/span><\/p>\n

\"\"<\/p>\n

API Security Audit finds a vulnerability in the F5 OpenAPI file<\/span><\/em><\/p>\n

 <\/p>\n

Complete the API requirements<\/span><\/h4>\n

So now we know what’s missing. How can we help developers add API requirements consistently and correctly across the team?<\/span><\/p>\n

Data dictionaries are centralized repositories of formats and patterns for commonly used API data fields. Developers can refer to the data dictionary to ensure consistency in applying constraints on API data.<\/span><\/p>\n

For this example let\u2019s assume the requirement for the provider_name field is as follows:<\/span><\/p>\n

provider_name must be 1-64 characters long, and use lowercase letters, numbers and underscore characters only.<\/code><\/span><\/i><\/p>\n

This requirement could be stored in a data dictionary and shared with developers for reference or used for auto-completion of requirements:<\/span><\/p>\n

\"\"<\/p>\n

Auto-complete API requirements for the provider_name<\/span><\/em><\/p>\n

 <\/p>\n

Note that this simple requirement would have been enough to remove the SQL injection vulnerability. In fact, just setting an upper limit of 64 characters on the input would have blocked the SQL injection on the F5 device, since the attack pattern was longer than 64 characters.<\/span><\/p>\n

The more specific the requirement, the less room a hacker has to attack your API.<\/span><\/p>\n

 <\/p>\n

Test the API<\/span><\/h4>\n

Now that the provider_name requirement is complete and documented, has the API developer implemented the correct constraints in the API code?\u00a0<\/span><\/p>\n

It is the responsibility of the API testing team to verify whether the API runtime behavior conforms to the expected behavior. Does the API accept malicious SQL injection patterns or does it securely reject input that doesn’t match the requirements:<\/span><\/p>\n

provider_name must be 1-64 characters long, and use lowercase letters, numbers and underscore characters only.<\/code><\/span><\/p>\n

This test is simple to run manually. But if we are talking about checking the requirements on the entire OpenAPI file (all 81,000+ lines) then 42Crunch API Conformance Scan is the right tool for the job. Conformance Scan takes the OpenAPI file as input and tests whether the API enforces each of the requirements (although developers can also test API operations one by one).\u00a0<\/span><\/p>\n

In this example, using a simulation of the F5 API endpoint, Conformance Scan attempts to bypass the requirement by sending the API a provider_name that exceeds the 64 character maximum.<\/span><\/p>\n

\"\"<\/p>\n

API Conformance Scan finds the vulnerability in the API<\/span><\/em><\/p>\n

 <\/p>\n

The expected response from the API is HTTP 400 bad request, since the input data is invalid.<\/span><\/p>\n

However the actual response from the API is 404. Understanding the difference between 400 and 404 is important. The 404 response indicates that the API not only accepted the invalid provider name, but even tried to use it to search the database. This demonstrates that the API is vulnerable to injection attacks via malicious input.<\/span><\/p>\n

So, using API Conformance Scan, the team could have identified the vulnerability in the API code and prevented the breach in production.<\/span><\/p>\n

By leveraging OpenAPI as a requirements specification for your API, API teams can align your security goals with development and testing best practices.\u00a0<\/span><\/p>\n

 <\/p>\n

<\/h2>\n

<\/h2>\n

Tools for API Teams<\/span><\/h2>\n

API Security Audit and API Conformance Scan are both available as IDE plugins for VSCode, Intellij or Eclipse.\u00a0<\/span><\/p>\n

You can try both API tools <\/span>for free<\/b> today using the Freemium option. See the 42Crunch website for details: <\/span>https:\/\/42crunch.com\/freemium\/<\/span><\/a>\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

In a report published in May 2024, cybersecurity firm Eclypsium outlined key vulnerabilities discovered in the F5 Big IP Next device. It’s another sobering reminder of the challenges faced in securing APIs when a highly regarded security company like F5 launches a new flagship product with all-too-familiar vulnerabilities like SQL injection and SSRF. Among the […]<\/p>\n","protected":false},"author":20,"featured_media":18925,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"The Scourge Of SQL Injection For APIs","_seopress_titles_desc":"How the SQL injection vulnerability in the F5 Big IP Next device could have been discovered and remediated using 42Crunch API security testing tools","_seopress_robots_index":"","site-sidebar-layout":"default","site-content-layout":"disabled","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"disabled","ast-hfb-above-header-display":"disabled","ast-hfb-below-header-display":"disabled","ast-hfb-mobile-header-display":"disabled","site-post-title":"disabled","ast-breadcrumbs-content":"disabled","ast-featured-img":"disabled","footer-sml-layout":"disabled","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[6],"tags":[],"class_list":["post-18870","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/posts\/18870"}],"collection":[{"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/comments?post=18870"}],"version-history":[{"count":2,"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/posts\/18870\/revisions"}],"predecessor-version":[{"id":18927,"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/posts\/18870\/revisions\/18927"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/media\/18925"}],"wp:attachment":[{"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/media?parent=18870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/categories?post=18870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging2022.42crunch.com\/wp-json\/wp\/v2\/tags?post=18870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}