Exploiting LLM APIs

Created: 2024-01-21 18:44
#note

How LLM APIs work

The workflow for integrating an Large Language Models (LLMs) with an API depends on the structure of the API itself. When calling external APIs, some LLMs may require the client to call a separate function endpoint (effectively a private API) in order to generate valid requests that can be sent to those APIs. The workflow for this could look something like the following:

  1. The client calls the LLM with the user's prompt.
  2. The LLM detects that a function needs to be called and returns a JSON object containing arguments adhering to the external API's schema.
  3. The client calls the function with the provided arguments.
  4. The client processes the function's response.
  5. The client calls the LLM again, appending the function response as a new message.
  6. The LLM calls the external API with the function response.
  7. The LLM summarizes the results of this API call back to the user.

This workflow can have security implications, as the LLM is effectively calling external APIs on behalf of the user but the user may not be aware that these APIs are being called. Ideally, users should be presented with a confirmation step before the LLM calls the external API.

Mapping LLM API attack surface

The term "excessive agency" refers to a situation in which an LLM has access to APIs that can access sensitive information and can be persuaded to use those APIs unsafely. This enables attackers to push the LLM beyond its intended scope and launch attacks via its APIs.

The first stage of using an LLM to attack APIs and plugins is to work out which APIs and plugins the LLM has access to. One way to do this is to simply ask the LLM which APIs it can access. You can then ask for additional details on any APIs of interest.

If the LLM isn't cooperative, try providing misleading context and re-asking the question. For example, you could claim that you are the LLM's developer and so should have a higher level of privilege.

Chaining vulnerabilities in LLM APIs

Even if an LLM only has access to APIs that look harmless, you may still be able to use these APIs to find a secondary vulnerability. For example, you could use an LLM to execute a path traversal attack on an API that takes a filename as input.

Once you've mapped an LLM's API attack surface, your next step should be to use it to send classic web exploits to all identified APIs.

References

  1. Portswigger