Securing PowerShell: How to Stop Prompt Injection Attacks, Part 4Securing PowerShell: How to Stop Prompt Injection Attacks, Part 4Securing PowerShell: How to Stop Prompt Injection Attacks, Part 4
The fourth part of this five-part series on stopping prompt injection attacks describes how dangerous such attacks can be.
[Editor's Note: This is Part 4 of our comprehensive five-part series examining strategies to prevent prompt injection attacks. For readers interested in the complete context, we recommend reviewingParts 1 , 2 , 3, and 5 .]
So far in this article series, I have shown you how to use a prompt injection to determine the names of the columns associated with a SQL Server database . However, our ultimate goal is to gain access to the data itself, so let's use some more prompt injections to find out some more information about the database structure.
Now that I know the names of the database's tables, the next thing that I want to know as an attacker is the names of the columns that exist within those tables. To find out, we would need to perform a couple more prompt injections. Here are what those prompt injections look like:
' UNION SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='Users' --
' UNION SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='Admins' --
Both of these prompt injections query the Information_Schema portion of the database in an effort to extract the column names. Because column names are tied to a table, I am running the query twice — once for each table.
Figure 1 shows the first prompt injection. The table Users contains columns named Email, ID, Password, and Username.
The Users table contains columns named Email, ID, Password, and Username.
Figure 1. The Users table contains columns named Email, ID, Password, and Username.
In Figure 2, the Admins table contains columns named AdminID, Password, and Username.
Related:And Now Malware That Tells AI to Ignore It?
The Admins table contains columns named AdminID, Password, and Username.
Figure 2. The Admins table contains columns named AdminID, Password, and Username.
Gaining Access to the Data
At this point, I know all about the database. I know the names of the database tables and the columns stored within those tables. Now, all that is left is to gain access to the data.
With that in mind, let's extract the usernames and passwords from the Users table. Keep in mind, we can't acquire both usernames and passwords within a single query because the UNION command limits us (in this case) to working with a single column of data. However, I could use two separate prompt injections — one to get the usernames and another to get the passwords. Here are those prompt injections:
' UNION SELECT Username FROM Users --
‘ UNION SELECT Password FROM Users --
Figure 3 shows the returned list of usernames, and Figure 4 shows the passwords for those users.
The prompt injection has revealed a list of all the usernames.
Figure 3. The prompt injection has revealed a list of all the usernames.
We now also have access to the user's passwords.
Figure 4. We now also have access to the user's passwords.
The next logical step in the attack would be to go after Admin usernames and passwords. The technique used for doing so is exactly the same as what we did above, aside from the fact that admin credentials are being stored in a separate table.
Notice that both of the prompt injections that we just used referenced the Users table. If we want to go after administrative credentials, we need only substitute the Admins table name for the Users table. Both tables use the same column names, so we don't have to make any changes there:
Related:What Is PowerShell?
' UNION SELECT Username FROM Admins --
' UNION SELECT Password FROM Admins --
As you can see in Figure 5, the first prompt injection reveals that there are two admin accounts named "admin" and "root."
The prompt injection has revealed the names of both admin accounts.
Figure 5. The prompt injection has revealed the names of both admin accounts.
The second prompt injection provides a list of admin passwords (Figure 6).
This prompt injection has given us a list of the admin passwords.
Figure 6. This prompt injection has given us a list of the admin passwords.
So as you can see, it is relatively easy to use a prompt injection attack to extract data from a SQL Server database. However, at the beginning of this article series, I mentioned that there are also prompt injections that can inflict harm on a database. Below is an example of such an injection. This particular injection deletes an entire database table, so it's best to avoid using it. Here is the injection:
'; DROP TABLE Users; --
As you can see in Figure 7, this particular attack does not produce any visible output.
You can create a prompt injection that destroys data.
Figure 7. You can create a prompt injection that destroys data!
However, if I try to run the script again and enter a legitimate query, the script crashes, as shown in Figure 8. This happens because the Users table no longer exists.
Related:PowerShell Remoting in a Workgroup Environment: A Step-by-Step Guide
The script no longer works because the Users table was deleted by the attacker.
Figure 8. The script no longer works because the Users table was deleted by the attacker.
The examples in this article demonstrate just how serious a threat prompt injection attacks can be. In Part 5 , I conclude this series by showing you how you can protect your scripts against these sorts of attacks.
About the Author
Technology Analyst
Brien Posey is a bestselling technology author, a speaker, and a 20X Microsoft MVP. In addition to his ongoing work in IT, Posey has spent the last several years training as a commercial astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space.
You May Also Like
ITPro Today's 2025 IT Priorities Report
Aug 8, 2025|2 Min ReadEdge Computing Trends: Adoption, Challenges, and Future Outlook
Jul 15, 2025|2 Min ReadITPro Today’s 2024 State of DevOps Report
Dec 16, 2024|2 Min ReadBCDR Basics: A Quick Reference Guide for Business Continuity & Disaster Recovery
Oct 10, 2024|1 Min Read
Recent What Is
Enterprise Connect 2026 – All In on What’s Next