Encoding payloads

One method of halting SQL Injection is filtering through either server side text manipulation or Web App Firewalls (WAFs). These systems target specific phrases commonly associated with attacks such as SELECT, AND, OR, and spaces. These can be easily evaded by replacing these values with less obvious ones, thus highlighting the issue with blacklists in general.

We will create a script that takes attack strings, looks for potentially escaped strings, and provides alternative attack strings.

How to do it…

The following is our script:

subs = [] values = {“ “: “%50”, “SELECT”: “HAVING”, “AND”: “&&”, “OR”: “||”} originalstring = “' UNION SELECT * FROM Users WHERE username = 'admin' OR 1=1 AND username = 'admin';#” secondoriginalstring ...

Get Python: Penetration Testing for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.