Thursday, June 1, 2023

Automating REST Security Part 3: Practical Tests For Real-World APIs

Automating REST Security Part 3: Practical Tests for Real-World APIs

If you have read our two previous blogposts, you should now have a good grasp on the structural components used in REST APIs and where there are automation potentials for security analysis. You've also learned about REST-Attacker, the analysis tool we implemented as a framework for automated analysis.

In our final blogpost, we will dive deeper into practical testing by looking at some of the automated analysis tests implemented in REST-Attacker. Particularly, we will focus on three test categories that are well-suited for automation. Additionally, we will look at test results we acquired, when we ran these tests on the real-world API implementation of the services GitHub, Gitlab, Microsoft, Spotify, YouTube, and Zoom.

Author

Christoph Heine

Overview

Undocumented Operations

The first test that we are going to look at is the search for undocumented operations. These encompass all operations that accessible to API clients despite not being listed in the API documentation. For public-facing APIs, undocumented operations are a security risk because they can expose functionality of the service that clients are not supposed to access. Consequences can range from information leakage to extensive modification or even destruction of the resources managed by the underlying service.

A good example for an operation that should not be available is write access to the product information of a webshop API. While read operations on stock amounts, prices, etc. of a product are perfectly fine, you probably don't want to give clients the ability to change said information.

In HTTP-based REST, operations are represented by the HTTP methods used in the API request (as explained in Part 1 of the blog series). Remember that API requests are essentially HTTP requests which consist of HTTP method (operation), URI path (resource address) and optional header or body data.

GET /api/shop/items 

We can use the fact that REST operations are components from the HTTP standard to our advantage. First of all, we know that the set of possible operations is the same for all HTTP-based REST APIs (no matter their service-specific context) since each operation should map to a standardized HTTP method. As a result, we also have a rough idea what each operation does when it's applied to a resource, since it's based on the assigned purpose of the HTTP method. For example, we can infer that the DELETE method performs a destructive action a resource or that GET provides a form of read access. It also helps that in practice most APIs only use the same 4 or 5 HTTP methods representing the CRUD operations: GET, POST, PUT, PATCH, and DELETE.

If we know a URI path to a resource in the API, we can thus enumerate all possible API requests, simply by combining the URI with all possible HTTP methods:

GET    /api/shop/items POST   /api/shop/items PUT    /api/shop/items PATCH  /api/shop/items DELETE /api/shop/items 

REST-Attacker's test case undocumented.TestAllowedHTTPMethod uses the same approach to find undocumented operations. With an OpenAPI description, the generation of API requests is extremely to automate as the description lists all defined URI paths. Since the API description also documents the officially supported operations, we can slightly optimize the search by only generating API requests for operations not documented for a path (which basically are the candicates for undocumented operations).

To find out whether an undocumented operation exist, we have to determine if the generated API requests are successful. Here, we can again rely on a standard HTTP components that are used across REST APIs. By checking the HTTP response code of the API, we can see whether the API request was rejected or accepted. Since the response codes are standardized like the HTTP methods, we can also make general assumptions based on the response code received. If the operation in the API request is not available, we would expect to get the dedicated response code 405 - Method Not Allowed in the response. Other 4XX response codes can also indicate that the API request was unsuccessful for other reasons. If the operation is accepted, we would expect the API response to contain a 2XX response code.

Using the same approach, we let REST-Attacker search for undocumented operations in all 6 APIs we tested. None of them exposed undocumented operations that could be identified by the tool, which means they would be considered safe in regards to this test. However, it's interesting to see that the APIs could responded very differently to the API requests sent by the tool, especially when considering the response codes.

API Response Codes
GitHub 401, 404
Gitlab 400, 404
MS Graph 400, 401, 403, 404
Spotify 405
YouTube 404
Zoom 400, 401, 403, 404, 405

Spotify's API was the only one that used the 405 response code consistently. Other APIs returned 400, 401, 403, or 404, sometimes depending on the path used in the the API request. It should be noted that the APIs returned 401 - Unauthorized or 403 - Forbidden response codes even when supplying credentials with the highest possible level of authorization. An explanation for this behaviour could be that the internal access checks of the APIs work differently. Instead of checking whether an operation on a resource is allowed, they may check whether the client sending the request is authorized to access the resource.

Credentials Exposure

Excessive Data Exposure from OWASP's Top 10 API Security Issues is concerned with harmful "verbosity" of APIs. In other words, it describes a problem where API responses contain more information than they should return (hence excessive exposure). Examples for excessive data exposure include leaks of private user data, confidential data about the underlying service, or security parameters of the API. What counts as excessive exposure can also depend on the application context of the underlying service.

Since the definition of excessive data exposure is very broad, we will focus on a particular type of data for our practical test: Credentials. Not only do credentials exist in some form for almost any service, their exposure would also have a significant impact on the security of the API and its underlying service. Exposed credentials may be used to gain higher privileges or even account takeovers. Therefore, they are a lucrative target for attacks.

There are several credential types that can be interesting for attackers. Generally, they fit into these categories:

  • long-term credentials (e.g., passwords)
  • short-term credentials (e.g., session IDs, OAuth2 tokens)
  • service-specific credentials for user content (e.g., passwords for files on a file-hosting service)

Long- and short-term credentials should probably never be returned under any circumstances. Service-specific credentials may be less problematic in some specific circumstances, but should still be handled with care as they could be used to access resources that would otherwise be inaccessible to an API client.

The question is: Where can we start looking for exposed credentials? Since they would be part of the API responses, we could scrape the parameters in the response content. However, we may not actually need to look at any response values. Instead, we can examine the parameter names and check for association with credentials. For example, a parameter names "password" would likely contain a type of credential. The reason this can work is that parameter names in APIs are generally descriptive and human-readable, a side effect of APIs often being intended to be used by (third-party) developers.

In REST-Attacker, credentials parameter search is implemented by the resources.FindSecurityParameters test case. The test case actually only implements an offline search using the OpenAPI description, as the response parameter names can also be found there. The implementation iterates through the response parameter names of each API endpoint and matches them to keywords associated with credentials such as "pass", "auth" or "token". This naive approach is not very accurate and can produce a number of false-positives, so the resulting list of parameters has to be manually checked. However, the number of candidates is usually small enough to be searched in a small amount of time, even if the API defines thousands of unique response parameters.

API Parameter Count Candidates long-term short-term service-specific
GitHub 2110 39 0 0 0
Gitlab 1291 0 0 0 0
MS Graph 32199 117 0 0 0
Spotify 290 6 0 0 0
YouTube 703 6 0 0 0
Zoom 800 96 0 0 2

5 out of 6 APIs we tested had no problems with exposed credentials.

Zoom's API was the only one which showed signs of problematic exposure of service-specific credentials by returning the default meeting password for meetings created via the API at an endpoint. It should be noted that this information was only available to approved clients and an required authorized API request. However, the credentials could be requested with few priviledges. Another problem was that Zoom did not notify users that this type of information was accessible to third-party clients.

Default Access Priviledges

The last test category that we are going to look at addresses the access control mechanisms of REST APIs. Modern access control methods such as OAuth2 allow APIs to decide what minimum priviledges they require for each endpoint, operation, or resource. In the same way, it gives them fine-grained control on what priviledges are assigned to API clients. However, for fine-grained control to be impactful, APIs need to carefully decide which priviledges they delegate to clients by default.

But why is it important that APIs assigned do not grant too many priviledges by default? The best practice for authorization is to operate on the so-called least priviledge principle. Basically, this means that a client or user should only get the minimum necessary priviledges required for the respective task they want to do. For default priviledges, the task is usually unspecified, so there are no necessary priviledges. In that case, we would expect an API to grant either no priviledges or the overall lowest functional priviledge level.

If the API uses OAuth2 as its access control method, we can easily test what the API considers default priviledges. In OAuth2, clients can request a specific level of priviledge via the scope parameter in the initial authorization request.

Including the scope parameter in the request is optional. If it's omitted, the API can deny the authorization request or - and that's what we are interested in - decide which scope it assigns to the authorization token returned to the client. By analyzing the default scope value, we can see whether the API adheres to the least priviledge principle.

REST-Attacker can automatically retrieve this information for configured OAuth2 clients with the scopes.TestTokenRequestScopeOmit test case. For every configured OAuth2 client, an authorization request without the scope parameter is sent to the OAuth2 authorzation endpoints of the API. The tool then extracts the scope that is assigned to the returned OAuth2 token. This scope value then has to be manually analyzed.

Out of the 6 APIs we tested, 2 (MS Graph and YouTube) denied requests without a scope parameter. The other 4 APIs (GitHub, Gitlab, Spotify, and Zoom) allowed omitting the scope parameter. Therefore, only the latter 4 APIs assigned default prviledges that could be analyzed.

API Assigned Scope Least Priviledge?
GitHub (none) Yes
Gitlab api No
Spotify (default) Yes*
Zoom all approved No

* OAuth2 scope with least priviledges

Interestingly, the extent to which a least priviledge principle was followed varied between APIs.

GitHub's API assigned the overall lowest possible priviledges by default via the (none) scope. With this scope, a client could only access API endpoints that were already publicly accessible (without providing authorization). While the scope does not grant more priviledges than a public client would get, the (none) scope had other benefits such as an increased rate limit.

In comparison, the Spotify API had no publicly accessible API endpoints and required authorization for every request. By default, tokens were assigned a "default" scope which was the OAuth2 scope with the lowest available priviledges and allowed clients to access several basic API endpoints.

Gitlab's and Zoom's API went into the opposite direction and assigned the highest priviledge to their clients by default. In Gitlab's case, this was the api scope which allowed read and write access to all API endpoints. Zoom required a pre-approval of scopes that the client wants to access during client registration. After registration, Zoom returned all approved scopes by default.

Conclusion

We've seen that while REST is not a clarly defined standard, this does not result in REST APIs being too complex for a generalized automated analysis. The usage of standardized HTTP components allows the design of simple yet effective tests that work across APIs. This also applies to other components that are used across APIs such as access control mechanisms like OAuth2. The practical tests we discussed worked on all APIs we tested, even if their underlying application contexts were different. However, we've also seen that most of the APIs were generally safe against these tests.

Tool-based automation could certainly play a much larger role in REST security, not only for finding security issues but also for filtering results and streamlining otherwise manual tasks. In the long run, this will hopefully also result in an increase in security.

Acknowledgement

The REST-Attacker project was developed as part of a master's thesis at the Chair of Network & Data Security of the Ruhr University Bochum. I would like to thank my supervisors Louis Jannett, Christian Mainka, Vladislav Mladenov, and Jörg Schwenk for their continued support during the development and review of the project.

More information


How Do I Get Started With Bug Bounty ?

How do I get started with bug bounty hunting? How do I improve my skills?



These are some simple steps that every bug bounty hunter can use to get started and improve their skills:

Learn to make it; then break it!
A major chunk of the hacker's mindset consists of wanting to learn more. In order to really exploit issues and discover further potential vulnerabilities, hackers are encouraged to learn to build what they are targeting. By doing this, there is a greater likelihood that hacker will understand the component being targeted and where most issues appear. For example, when people ask me how to take over a sub-domain, I make sure they understand the Domain Name System (DNS) first and let them set up their own website to play around attempting to "claim" that domain.

Read books. Lots of books.
One way to get better is by reading fellow hunters' and hackers' write-ups. Follow /r/netsec and Twitter for fantastic write-ups ranging from a variety of security-related topics that will not only motivate you but help you improve. For a list of good books to read, please refer to "What books should I read?".

Join discussions and ask questions.
As you may be aware, the information security community is full of interesting discussions ranging from breaches to surveillance, and further. The bug bounty community consists of hunters, security analysts, and platform staff helping one and another get better at what they do. There are two very popular bug bounty forums: Bug Bounty Forum and Bug Bounty World.

Participate in open source projects; learn to code.
Go to https://github.com/explore or https://gitlab.com/explore/projects and pick a project to contribute to. By doing so you will improve your general coding and communication skills. On top of that, read https://learnpythonthehardway.org/ and https://linuxjourney.com/.

Help others. If you can teach it, you have mastered it.
Once you discover something new and believe others would benefit from learning about your discovery, publish a write-up about it. Not only will you help others, you will learn to really master the topic because you can actually explain it properly.

Smile when you get feedback and use it to your advantage.
The bug bounty community is full of people wanting to help others so do not be surprised if someone gives you some constructive feedback about your work. Learn from your mistakes and in doing so use it to your advantage. I have a little physical notebook where I keep track of the little things that I learnt during the day and the feedback that people gave me.


Learn to approach a target.
The first step when approaching a target is always going to be reconnaissance — preliminary gathering of information about the target. If the target is a web application, start by browsing around like a normal user and get to know the website's purpose. Then you can start enumerating endpoints such as sub-domains, ports and web paths.

A woodsman was once asked, "What would you do if you had just five minutes to chop down a tree?" He answered, "I would spend the first two and a half minutes sharpening my axe."
As you progress, you will start to notice patterns and find yourself refining your hunting methodology. You will probably also start automating a lot of the repetitive tasks.

Read more
  1. Hacker Tools For Ios
  2. Hacker Tools Windows
  3. Hack Tools 2019
  4. Hacker Tools Windows
  5. Hack Apps
  6. How To Install Pentest Tools In Ubuntu
  7. Hacking Tools Mac
  8. Hacker Hardware Tools
  9. Ethical Hacker Tools
  10. How To Make Hacking Tools
  11. Hacking Tools Download
  12. How To Make Hacking Tools
  13. Hacking Tools
  14. Hacker Tools For Pc
  15. Hack Tools 2019
  16. Hacking Tools 2019
  17. Hacking Tools For Mac
  18. Beginner Hacker Tools
  19. Hacker Tool Kit
  20. Hacking Tools For Pc
  21. Hacking Tools 2019
  22. Hacking Tools Pc
  23. Hack Website Online Tool
  24. Pentest Tools Alternative
  25. Github Hacking Tools
  26. Hacker Tools For Ios
  27. Hacker Tools Github
  28. Hacking Tools Software
  29. Pentest Tools Free
  30. Hacker Tools Linux
  31. Hacking Tools
  32. Best Pentesting Tools 2018
  33. Hacker Tools For Ios
  34. Hacker Tools For Ios
  35. Hacker Tools Github
  36. Best Pentesting Tools 2018
  37. Hacking Tools For Windows
  38. Hack Tool Apk
  39. Tools 4 Hack
  40. Hacker
  41. Hack Tools For Pc
  42. Hackers Toolbox
  43. Pentest Tools Website Vulnerability
  44. Hacking Tools Name
  45. Pentest Tools Apk
  46. Hacker Tools Free
  47. Pentest Tools Url Fuzzer
  48. Hack Tools For Ubuntu
  49. Nsa Hack Tools Download
  50. Hack Tools 2019
  51. Physical Pentest Tools
  52. Hackers Toolbox
  53. Hacking Tools Github
  54. Hacking Tools Usb
  55. Hack Tools For Mac
  56. Hack Tools Mac
  57. Hacker Tools For Pc
  58. Pentest Tools Port Scanner
  59. Hackers Toolbox
  60. Pentest Tools Review
  61. Bluetooth Hacking Tools Kali
  62. Ethical Hacker Tools
  63. Hacking Tools Mac
  64. Hacker Tools 2020
  65. Hack Tools Online
  66. Hackers Toolbox
  67. What Are Hacking Tools
  68. How To Make Hacking Tools
  69. Pentest Tools Open Source
  70. Hacker Tools Software
  71. Hack Tools Mac
  72. Black Hat Hacker Tools
  73. Hack Tools For Ubuntu
  74. Nsa Hacker Tools
  75. Pentest Tools Website Vulnerability
  76. Underground Hacker Sites
  77. Underground Hacker Sites
  78. Pentest Tools Android
  79. Kik Hack Tools
  80. Hacking Tools And Software
  81. Ethical Hacker Tools
  82. How To Install Pentest Tools In Ubuntu
  83. Hacker Tools List
  84. Hacker Tool Kit
  85. Hack Tools Github
  86. Tools For Hacker
  87. Pentest Tools For Windows
  88. Android Hack Tools Github
  89. What Is Hacking Tools
  90. Hacking App
  91. Hacking Tools Github
  92. Hack Website Online Tool
  93. Physical Pentest Tools
  94. Pentest Tools
  95. Pentest Tools
  96. New Hack Tools
  97. Hacking Tools Mac
  98. Hack Tools
  99. Github Hacking Tools
  100. Hacker Search Tools
  101. Hacking Tools For Windows Free Download
  102. Hacking Tools 2020
  103. Best Hacking Tools 2019
  104. Best Pentesting Tools 2018
  105. Hack Tools For Ubuntu
  106. Pentest Tools Website
  107. How To Make Hacking Tools
  108. Game Hacking
  109. Hacker Tools
  110. Hack And Tools
  111. Hacking Tools For Pc
  112. Beginner Hacker Tools
  113. Pentest Tools Windows
  114. Pentest Tools Website
  115. Hacking Tools Pc
  116. Hacking Tools Pc
  117. Hacker Tools Apk
  118. Hacks And Tools
  119. Hack Tools Mac
  120. Hack Website Online Tool
  121. Hack Tools Pc
  122. Pentest Tools Android
  123. Best Pentesting Tools 2018
  124. Pentest Tools Subdomain
  125. Hacker Tools Mac
  126. Best Hacking Tools 2019
  127. Hack Tools Github
  128. Pentest Tools For Windows
  129. Hacking Tools Windows
  130. Hacking Tools Online
  131. Hack Tools For Pc
  132. Hackers Toolbox
  133. Physical Pentest Tools
  134. Hacker Tools Online

Files Download Information




After 7 years of Contagio existence, Google Safe Browsing services notified Mediafire (hoster of Contagio and Contagiominidump files) that "harmful" content is hosted on my Mediafire account.

It is harmful only if you harm your own pc and but not suitable for distribution or infecting unsuspecting users but I have not been able to resolve this with Google and Mediafire.

Mediafire suspended public access to Contagio account.

The file hosting will be moved.

If you need any files now, email me the posted Mediafire links (address in profile) and I will pull out the files and share via other methods.

P.S. I have not been able to resolve "yet" because it just happened today, not because they refuse to help.  I don't want to affect Mediafire safety reputation and most likely will have to move out this time.

The main challenge is not to find hosting, it is not difficult and I can pay for it, but the effort move all files and fix the existing links on the Blogpost, and there are many. I planned to move out long time ago but did not have time for it. If anyone can suggest how to change all Blogspot links in bulk, I will be happy.


P.P.S. Feb. 24 - The files will be moved to a Dropbox Business account and shared from there (Dropbox team confirmed they can host it )  


The transition will take some time, so email me links to what you need. 

Thank you all
M

Continue reading


  1. Hacking Tools
  2. Hacking Tools For Windows 7
  3. Hacker Techniques Tools And Incident Handling
  4. Hack App
  5. Best Hacking Tools 2019
  6. Hacker Tools 2020
  7. Usb Pentest Tools
  8. Hacking Tools Online
  9. Pentest Reporting Tools
  10. Pentest Tools Bluekeep
  11. Hacking Tools 2020
  12. Underground Hacker Sites
  13. Kik Hack Tools
  14. Pentest Tools Apk
  15. Hacking Tools For Windows
  16. Hacking Tools For Windows Free Download
  17. Github Hacking Tools
  18. Nsa Hack Tools Download
  19. Hacking Tools For Games
  20. Hack Apps
  21. Hacker Security Tools
  22. Pentest Tools Tcp Port Scanner
  23. Hack Tools Online
  24. Hacker Search Tools
  25. Pentest Tools Website Vulnerability
  26. Hacker Tools Free Download
  27. Pentest Tools Alternative
  28. New Hack Tools
  29. Hacker Tool Kit
  30. Hacking Tools Kit
  31. Pentest Tools Online
  32. Hacking Tools 2019
  33. How To Hack
  34. Hacking Tools Pc
  35. Pentest Tools Website
  36. Pentest Tools Website Vulnerability
  37. Hack Tools
  38. Tools 4 Hack
  39. Computer Hacker
  40. Nsa Hack Tools Download
  41. Pentest Tools Tcp Port Scanner
  42. Hacking Tools 2019
  43. Pentest Tools Open Source
  44. Android Hack Tools Github
  45. Hack Tool Apk No Root
  46. Hack Tools Github
  47. Hacker Tools Software
  48. Wifi Hacker Tools For Windows
  49. Hacking Tools Usb
  50. Pentest Box Tools Download
  51. World No 1 Hacker Software
  52. Hacking Tools Github
  53. Hacking Tools Pc
  54. Pentest Tools Github
  55. Hacker Tools Apk
  56. Ethical Hacker Tools
  57. Nsa Hack Tools Download
  58. Black Hat Hacker Tools
  59. Pentest Tools Find Subdomains
  60. How To Make Hacking Tools
  61. Hacking Tools For Beginners
  62. Hack Tools For Windows
  63. Pentest Reporting Tools
  64. Hack Tools For Ubuntu
  65. Pentest Tools Online
  66. How To Install Pentest Tools In Ubuntu
  67. Pentest Tools Linux
  68. Hacker Tools For Mac
  69. Hacker Tool Kit
  70. How To Hack
  71. Hack Apps
  72. Computer Hacker
  73. Hacker Tools Mac
  74. Top Pentest Tools
  75. Hacking Tools 2020
  76. Hacking Tools For Games
  77. Hacking Tools Github
  78. Blackhat Hacker Tools
  79. Pentest Box Tools Download
  80. Pentest Tools Framework
  81. Hacker Tools Windows
  82. Pentest Reporting Tools
  83. Hacker Techniques Tools And Incident Handling
  84. Github Hacking Tools
  85. Hacker Tools For Mac
  86. Pentest Tools For Android
  87. Blackhat Hacker Tools
  88. Hack App
  89. Nsa Hack Tools Download
  90. Hacker Tools Mac
  91. Hacker
  92. How To Make Hacking Tools
  93. Nsa Hack Tools Download
  94. Hacking Tools Online
  95. Hack Tools 2019
  96. Pentest Tools Apk
  97. Hacker Tools Online
  98. Termux Hacking Tools 2019
  99. Hacking Tools Name
  100. Easy Hack Tools
  101. Blackhat Hacker Tools
  102. Pentest Box Tools Download
  103. Tools For Hacker
  104. Hacking Apps
  105. Hacker Tools Hardware
  106. New Hacker Tools
  107. Pentest Tools Open Source
  108. Install Pentest Tools Ubuntu
  109. Wifi Hacker Tools For Windows
  110. Hack App
  111. Pentest Tools Github
  112. Best Hacking Tools 2020
  113. Hacker Tools Free
  114. Hacking App
  115. Hacker Tools For Pc
  116. New Hacker Tools
  117. New Hacker Tools
  118. How To Make Hacking Tools
  119. Pentest Tools Apk
  120. Nsa Hack Tools
  121. Hacker Techniques Tools And Incident Handling
  122. Hacker Search Tools
  123. Hack Tools Download
  124. Hacking Tools For Games
  125. Hackers Toolbox
  126. Hacking Tools Name
  127. Hacker Tools For Pc
  128. Hacking Tools 2019
  129. Hacking Tools Online
  130. Pentest Tools Android
  131. Hack Tools
  132. Hacker Hardware Tools
  133. Hacking Tools Usb
  134. Pentest Tools Android
  135. Hacker Tools Hardware
  136. Hacking Tools Download
  137. What Is Hacking Tools
  138. Hacker Tools 2020
  139. Hacking Tools For Windows 7
  140. Growth Hacker Tools
  141. Pentest Tools For Ubuntu
  142. Hacking Tools Pc
  143. Pentest Tools Windows
  144. Hack Tools Download
  145. Github Hacking Tools
  146. Tools 4 Hack
  147. Top Pentest Tools
  148. Pentest Tools Free
  149. Hacker Tools Free Download
  150. Tools Used For Hacking
  151. Hacker Tools
  152. Hacker Tools Github
  153. Tools For Hacker
  154. Hack Tools Github
  155. Physical Pentest Tools
  156. Hacking Tools Github
  157. Hacker Hardware Tools
  158. Hacker Tools Github
  159. Hacker Tools For Mac
  160. Hacking Tools For Windows Free Download
  161. Pentest Tools For Ubuntu
  162. Hacker Tools Github
  163. Android Hack Tools Github
  164. Pentest Tools Review
  165. Hacker Tools For Pc