Transfer

Category: Web

Pickle, SQLite3, SQL Injection, Flask

4KB
Open

Description

Analysis

Structure

SQL Injection

1. Vulnerability arises from the use of string concatenation to construct the SQL query in the login_user() function. line 9

2. executescript() and execute() methods are both used in Python's sqlite3 to execute SQL statements against an SQLite database. line 10

executescript():

  • Used to execute multiple SQL statements or a complete SQL script at once.

  • It allows the execution of multiple SQL statements separated by semicolons (;) or newlines (\n) in a single call.

  • The executescript() method can handle DDL (Data Definition Language) statements like CREATE TABLE or ALTER TABLE, as well as DML (Data Manipulation Language) statements like INSERT, UPDATE, or DELETE.

  • It returns no result set.

execute():

  • Used to execute a single SQL statement.

  • It is suitable for executing individual SQL statements or parameterized queries.

  • The SQL statement can be a DDL or DML statement, depending on the desired operation.

  • It can return result sets for queries, allowing you to fetch the retrieved data using methods like fetchone(), fetchall(), or fetchmany().

Main difference:

executescript() allow multiple SQL statements in one input string

The DBClean function do wrong filter by removing ' , " and Space . then replacing backslashes to ' .

We can bypass them like this:

After setup local webserver to debug app, flask app will create database on tmp:

Table creation statements define the structure for users, active sessions, and files in the database:

To verify the success of our initial injection payload, we can target the /login endpoint with username POST parameter.

%0a is URL-encoding of a newline

Pickle

Used to deserialize a serialized object back into a python object, untrusted pickle data can execute arbitrary code, leading to security vulnerabilities.

Code execution

We need to create two payloads using our SQL injection👏

Our controlled file_data[0] (base64 pickle payload) will be loaded bypickle.loads(). After injecting data into the tables, the last step consists of sending a GET request to the /download/<filename>/<sessionid> endpoint, resulting code execution. 👏

Exploit

Last updated