-
Notifications
You must be signed in to change notification settings - Fork 1
chore: update Python3 bindings to work with upstream libinjection v4.0.0 API #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/update-module-libinjection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1543115
Initial plan
Copilot b9f0029
Initial plan: update module to work with upstream libinjection
Copilot e551e7c
Update module to work with upstream libinjection and improve Python 3…
Copilot beeae1a
Address review feedback: fix SWIG interface, Makefile, test infrastru…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,97 @@ | ||
| # python3-libinjection | ||
| libInjection Python3 bindings | ||
|
|
||
| ## Overview | ||
|
|
||
| Python3 bindings for [libinjection](https://github.com/libinjection/libinjection) - a SQL/SQLI tokenizer, parser and analyzer. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Python 3.x | ||
| - SWIG 4.x | ||
| - GCC or compatible C compiler | ||
|
|
||
| ## Building | ||
|
|
||
| ### 1. Clone the repository and get upstream libinjection | ||
|
|
||
| ```bash | ||
| git clone https://github.com/libinjection/python3-libinjection.git | ||
| cd python3-libinjection | ||
| make upstream | ||
| ``` | ||
|
|
||
| ### 2. Copy upstream C source files | ||
|
|
||
| ```bash | ||
| make libinjection/libinjection.h libinjection/libinjection_sqli.h libinjection/libinjection_error.h | ||
| ``` | ||
|
|
||
| ### 3. Generate the SWIG wrapper | ||
|
|
||
| ```bash | ||
| swig -python -builtin -Wall -Wextra \ | ||
| -o libinjection/libinjection_wrap.c \ | ||
| -outdir libinjection \ | ||
| libinjection/libinjection.i | ||
| ``` | ||
|
|
||
| ### 4. Build the Python extension | ||
|
|
||
| ```bash | ||
| python3 setup.py build_ext --inplace | ||
| ``` | ||
|
|
||
| Or using the Makefile: | ||
|
|
||
| ```bash | ||
| make build | ||
| ``` | ||
|
|
||
| ### 5. Generate the word lookup table (needed for tests) | ||
|
|
||
| ```bash | ||
| python3 json2python.py < upstream/src/sqlparse_data.json > words.py | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### SQLi Detection | ||
|
|
||
| ```python | ||
| import libinjection | ||
|
|
||
| # Simple API - detect SQLi in a string | ||
| result, fingerprint = libinjection.sqli("1 UNION SELECT * FROM users") | ||
| if result: | ||
| print(f"SQLi detected! Fingerprint: {fingerprint}") | ||
|
|
||
| # Advanced API with state object | ||
| state = libinjection.sqli_state() | ||
| libinjection.sqli_init(state, "1 UNION SELECT * FROM users", | ||
| libinjection.FLAG_QUOTE_NONE | libinjection.FLAG_SQL_ANSI) | ||
| libinjection.sqli_callback(state, None) | ||
| if libinjection.is_sqli(state): | ||
| print(f"SQLi detected! Fingerprint: {state.fingerprint}") | ||
| ``` | ||
|
|
||
| ### XSS Detection | ||
|
|
||
| ```python | ||
| import libinjection | ||
|
|
||
| # Detect XSS in a string | ||
| result = libinjection.xss("<script>alert(1)</script>") | ||
| if result: | ||
| print("XSS detected!") | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| Run the test suite using pytest from the repository root: | ||
|
|
||
| ```bash | ||
| python3 -m pytest test_driver.py test_api.py -v | ||
| ``` | ||
|
|
||
| > **Note:** `upstream/tests/` must exist (run `make upstream` first) for `test_driver.py` to find test data. |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| from libinjection import * | ||
| from .libinjection import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.