From a8627abe501da701b7a600415e667ae7f5c84100 Mon Sep 17 00:00:00 2001 From: Translator Date: Sun, 2 Feb 2025 18:22:50 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/aws-security/aws-services/aws-efs-enum --- .../aws-security/aws-services/aws-efs-enum.md | 118 ++++++++++++++++-- 1 file changed, 108 insertions(+), 10 deletions(-) diff --git a/src/pentesting-cloud/aws-security/aws-services/aws-efs-enum.md b/src/pentesting-cloud/aws-security/aws-services/aws-efs-enum.md index 8255793d7..573dd63e7 100644 --- a/src/pentesting-cloud/aws-security/aws-services/aws-efs-enum.md +++ b/src/pentesting-cloud/aws-security/aws-services/aws-efs-enum.md @@ -12,11 +12,11 @@ Amazon Elastic File System (EFS) 被 AWS 视为一个 **完全托管、可扩展 ### 网络访问 -EFS 在 VPC 中创建,**默认情况下在所有 VPC 子网中可访问**。然而,EFS 将具有一个安全组。为了 **允许 EC2**(或任何其他 AWS 服务)挂载 EFS,需要 **在 EFS 安全组中允许来自 EC2 安全组的入站 NFS**(2049 端口)**规则**。 +EFS 创建在 VPC 中,**默认情况下在所有 VPC 子网中可访问**。然而,EFS 将具有一个安全组。为了 **允许 EC2**(或任何其他 AWS 服务)挂载 EFS,需要在 EFS 安全组中 **允许来自 EC2 安全组的入站 NFS**(2049 端口) **规则**。 没有这个,您 **将无法联系 NFS 服务**。 -有关如何做到这一点的更多信息,请查看:[https://stackoverflow.com/questions/38632222/aws-efs-connection-timeout-at-mount](https://stackoverflow.com/questions/38632222/aws-efs-connection-timeout-at-mount) +有关如何执行此操作的更多信息,请查看: [https://stackoverflow.com/questions/38632222/aws-efs-connection-timeout-at-mount](https://stackoverflow.com/questions/38632222/aws-efs-connection-timeout-at-mount) ### 枚举 ```bash @@ -41,7 +41,7 @@ sudo nmap -T4 -Pn -p 2049 --open 10.10.10.0/20 # or /16 to be sure > [!CAUTION] > EFS挂载点可能在同一个VPC内,但在不同的子网中。如果你想确保找到所有**EFS点,最好扫描`/16`子网掩码**。 -### 挂载EFS +### Mount EFS ```bash sudo mkdir /efs @@ -57,7 +57,7 @@ sudo mount -t efs :/ /efs/ ``` ### IAM 访问 -默认情况下,任何具有对 EFS 的网络访问权限的人都能够挂载、读取和写入它,即使是根用户。然而,文件系统策略可能会限制仅允许具有特定权限的主体访问它。\ +默认情况下,任何具有对 EFS 的网络访问的人都能够挂载、读取和写入,即使是根用户。然而,文件系统策略可能会限制仅允许具有特定权限的主体访问它。\ 例如,如果您没有 IAM 权限,这个文件系统策略将**不允许挂载**文件系统: ```json { @@ -92,9 +92,9 @@ sudo mount -t efs -o tls,iam :/ /efs/ # To use a different pforile from ~/.aws/credentials # You can use: -o tls,iam,awsprofile=namedprofile ``` -### 访问点 +### Access Points -**访问点**是**特定于应用程序**的入口点**进入EFS文件系统**,使管理应用程序对共享数据集的访问变得更加容易。 +**访问点**是**特定于应用程序**的入口点**进入EFS文件系统**,使管理应用程序对共享数据集的访问变得更容易。 当您创建访问点时,您可以**指定通过访问点创建的文件和目录的所有者和POSIX权限**。您还可以**为访问点定义自定义根目录**,可以通过指定现有目录或创建一个具有所需权限的新目录来实现。这使您能够**按应用程序或用户控制对EFS文件系统的访问**,从而更容易管理和保护您的共享文件数据。 @@ -109,23 +109,121 @@ sudo mount -t efs -o tls,[iam],accesspoint= \ 访问点可以用于以下目的: -- **简化权限管理**:通过为每个访问点定义一个POSIX用户和组,您可以轻松管理不同应用程序或用户的访问权限,而无需修改底层文件系统的权限。 +- **简化权限管理**:通过为每个访问点定义POSIX用户和组,您可以轻松管理不同应用程序或用户的访问权限,而无需修改底层文件系统的权限。 - **强制根目录**:访问点可以限制对EFS文件系统中特定目录的访问,确保每个应用程序或用户在其指定的文件夹内操作。这有助于防止意外的数据泄露或修改。 - **更容易的文件系统访问**:访问点可以与AWS Lambda函数或AWS Fargate任务关联,简化无服务器和容器化应用程序的文件系统访问。 -## Privesc +## EFS IP地址 + +使用与EFS IP地址相关的信息,以下Python脚本可以帮助检索有关EFS系统的详细信息。这些信息对于构建挂载系统命令或在了解子网ID的情况下进行进一步枚举非常有用。此外,脚本显示访问点,当根目录或主要挂载路径受到限制时,这些访问点提供访问敏感信息的替代路径。 +```bash +Usage: python efs_ip_enum.py +``` + +```python +import boto3 +import sys + +def get_efs_info(ip_address): +try: +session = boto3.Session(profile_name="profile") +ec2_client = session.client('ec2') +efs_client = session.client('efs') + +print(f"[*] Enumerating EFS information for IP address: {ip_address}\n") + +try: +response = ec2_client.describe_network_interfaces(Filters=[ +{'Name': 'addresses.private-ip-address', 'Values': [ip_address]} +]) + +if not response['NetworkInterfaces']: +print(f"[!] No network interface found for IP address {ip_address}") +return + +network_interface = response['NetworkInterfaces'][0] +network_interface_id = network_interface['NetworkInterfaceId'] +print(f"[+] Found network interface: {network_interface_id}\n") +except Exception as e: +print(f"[!] Error retrieving network interface: {str(e)}") +return + +try: +efs_response = efs_client.describe_file_systems() +file_systems = efs_response['FileSystems'] +except Exception as e: +print(f"[!] Error retrieving EFS file systems: {str(e)}") +return + +for fs in file_systems: +fs_id = fs['FileSystemId'] + +try: +mount_targets = efs_client.describe_mount_targets(FileSystemId=fs_id)['MountTargets'] + +for mt in mount_targets: +if mt['NetworkInterfaceId'] == network_interface_id: +try: +policy = efs_client.describe_file_system_policy(FileSystemId=fs_id).get('Policy', 'No policy attached') +except Exception as e: +policy = f"Error retrieving policy: {str(e)}" + +print("[+] Found matching EFS File System:\n") +print(f" FileSystemId: {fs_id}") +print(f" MountTargetId: {mt['MountTargetId']}") +print(f" DNSName: {fs_id}.efs.{session.region_name}.amazonaws.com") +print(f" LifeCycleState: {mt['LifeCycleState']}") +print(f" SubnetId: {mt['SubnetId']}") +print(f" SecurityGroups: {', '.join(mt.get('SecurityGroups', [])) if mt.get('SecurityGroups') else 'None'}") +print(f" Policy: {policy}\n") + +try: +access_points = efs_client.describe_access_points(FileSystemId=fs_id)['AccessPoints'] + +if access_points: +print(f"[+] Access Points for FileSystemId {fs_id}:") +for ap in access_points: +print(f" AccessPointId: {ap['AccessPointId']}") +print(f" Name: {ap.get('Name', 'N/A')}") +print(f" OwnerId: {ap['OwnerId']}") +posix_user = ap.get('PosixUser', {}) +print(f" PosixUser: UID={posix_user.get('Uid', 'N/A')}, GID={posix_user.get('Gid', 'N/A')}") +root_dir = ap.get('RootDirectory', {}) +print(f" RootDirectory: Path={root_dir.get('Path', 'N/A')}") +creation_info = root_dir.get('CreationInfo', {}) +print(f" CreationInfo: OwnerUID={creation_info.get('OwnerUid', 'N/A')}, OwnerGID={creation_info.get('OwnerGid', 'N/A')}, Permissions={creation_info.get('Permissions', 'N/A')}\n") +else: +print(f"[!] No Access Points found for FileSystemId {fs_id}\n") +except Exception as e: +print(f"[!] Error retrieving access points for FileSystemId {fs_id}: {str(e)}\n") +except Exception as e: +print(f"[!] Error processing file system {fs_id}: {str(e)}\n") + +except Exception as e: +print(f"[!] General Error: {str(e)}\n") + +if __name__ == "__main__": +if len(sys.argv) != 2: +print("Usage: python efs_enum.py ") +sys.exit(1) + +ip_address = sys.argv[1] +get_efs_info(ip_address) + +``` +## 提权 {{#ref}} ../aws-privilege-escalation/aws-efs-privesc.md {{#endref}} -## Post Exploitation +## 后期利用 {{#ref}} ../aws-post-exploitation/aws-efs-post-exploitation.md {{#endref}} -## Persistence +## 持久性 {{#ref}} ../aws-persistence/aws-efs-persistence.md