AWS - EFS Enum
Tip
学んで実践する AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks をサポートする
- subscription plans を確認してください!
- 参加する 💬 Discord group または telegram group に参加するか、Twitter 🐦 @hacktricks_live をフォローしてください。
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
EFS
基本情報
Amazon Elastic File System (EFS) は、AWS によって 完全に管理された、スケーラブルで弾力性のあるネットワークファイルシステム として提供されています。このサービスは、複数の EC2 インスタンスや他の AWS サービスによって同時にアクセスできる ファイルシステム の作成と構成を容易にします。EFS の主な機能には、手動介入なしで自動的にスケールする能力、低遅延アクセスの提供、高スループットワークロードのサポート、データの耐久性の保証、さまざまな AWS セキュリティメカニズムとのシームレスな統合が含まれます。
デフォルトでは、マウントする EFS フォルダーは / ですが、異なる名前を持つこともあります。
ネットワークアクセス
EFS は VPC 内に作成され、デフォルトではすべての VPC サブネットワークでアクセス可能です。ただし、EFS にはセキュリティグループがあります。EFS をマウントするために EC2(または他の AWS サービス)にアクセスを許可するには、EFS セキュリティグループに EC2 セキュリティグループからのインバウンド NFS**(ポート 2049)**ルールを 許可する必要があります。
これがないと、NFS サービスに接続できません。
この方法についての詳細は、次を確認してください: https://stackoverflow.com/questions/38632222/aws-efs-connection-timeout-at-mount
列挙
# Get filesystems and access policies (if any)
aws efs describe-file-systems
aws efs describe-file-system-policy --file-system-id <id>
# Get subnetworks and IP addresses where you can find the file system
aws efs describe-mount-targets --file-system-id <id>
aws efs describe-mount-target-security-groups --mount-target-id <id>
aws ec2 describe-security-groups --group-ids <sg_id>
# Get other access points
aws efs describe-access-points
# Get replication configurations
aws efs describe-replication-configurations
# Search for NFS in EC2 networks
sudo nmap -T4 -Pn -p 2049 --open 10.10.10.0/20 # or /16 to be sure
Caution
EFSマウントポイントが同じVPC内の異なるサブネットにある可能性があります。すべてのEFSポイントを見つけるためには、
/16ネットマスクをスキャンする方が良いでしょう。
Mount EFS
sudo mkdir /efs
## Mount found
sudo apt install nfs-common
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport <IP>:/ /efs
## Mount with efs type
## You need to have installed the package amazon-efs-utils
sudo yum install amazon-efs-utils # If centos
sudo apt-get install amazon-efs-utils # If ubuntu
sudo mount -t efs <file-system-id/EFS DNS name>:/ /efs/
IAM アクセス
デフォルトでは、EFSへのネットワークアクセスを持つ誰でもマウントし、ルートユーザーとして読み書きすることができます。ただし、ファイルシステムポリシーが設定されている場合、特定の権限を持つプリンシパルのみがアクセスできるようになります。
例えば、このファイルシステムポリシーは、IAM権限を持っていない場合、ファイルシステムをマウントすることすら許可しません:
{
"Version": "2012-10-17",
"Id": "efs-policy-wizard-2ca2ba76-5d83-40be-8557-8f6c19eaa797",
"Statement": [
{
"Sid": "efs-statement-e7f4b04c-ad75-4a7f-a316-4e5d12f0dbf5",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "",
"Resource": "arn:aws:elasticfilesystem:us-east-1:318142138553:file-system/fs-0ab66ad201b58a018",
"Condition": {
"Bool": {
"elasticfilesystem:AccessedViaMountTarget": "true"
}
}
}
]
}
これにより匿名アクセスが防止されます:
.png)
IAMによって保護されたファイルシステムをマウントするには、マウントコマンドでタイプ「efs」を使用する必要があります:
sudo mkdir /efs
sudo mount -t efs -o tls,iam <file-system-id/EFS DNS name>:/ /efs/
# To use a different pforile from ~/.aws/credentials
# You can use: -o tls,iam,awsprofile=namedprofile
アクセスポイント
アクセスポイントは、EFSファイルシステムへのアプリケーション特有のエントリーポイントであり、共有データセットへのアプリケーションアクセスを管理しやすくします。
アクセスポイントを作成する際には、アクセスポイントを通じて作成されるファイルやディレクトリの所有者とPOSIX権限を指定できます。また、既存のディレクトリを指定するか、希望する権限で新しいディレクトリを作成することで、アクセスポイントのカスタムルートディレクトリを定義することもできます。これにより、アプリケーションまたはユーザーごとにEFSファイルシステムへのアクセスを制御でき、共有ファイルデータの管理とセキュリティが容易になります。
次のようにアクセスポイントからファイルシステムをマウントできます:
# Use IAM if you need to use iam permissions
sudo mount -t efs -o tls,[iam],accesspoint=<access-point-id> \
<file-system-id/EFS DNS> /efs/
Warning
注意してください。アクセス・ポイントをマウントしようとする場合でも、ネットワーク経由でNFSサービスに連絡できる必要があり、EFSにファイルシステムのポリシーがある場合は、マウントするために十分なIAM権限が必要です。
アクセス・ポイントは以下の目的で使用できます:
- 権限管理の簡素化:各アクセス・ポイントにPOSIXユーザーとグループを定義することで、基盤となるファイルシステムの権限を変更することなく、異なるアプリケーションやユーザーのアクセス権を簡単に管理できます。
- ルートディレクトリの強制:アクセス・ポイントはEFSファイルシステム内の特定のディレクトリへのアクセスを制限でき、各アプリケーションやユーザーが指定されたフォルダ内で操作することを保証します。これにより、偶発的なデータの露出や変更を防ぐことができます。
- ファイルシステムアクセスの簡素化:アクセス・ポイントはAWS Lambda関数やAWS Fargateタスクに関連付けることができ、サーバーレスおよびコンテナ化されたアプリケーションのためのファイルシステムアクセスを簡素化します。
EFS IPアドレス
EFS IPアドレスに関連する情報を使用して、以下のPythonスクリプトはEFSシステムに関する詳細を取得するのに役立ちます。この情報は、マウントシステムコマンドを構築したり、サブネットIDの知識を持ってさらに列挙を行ったりするのに役立ちます。さらに、スクリプトはアクセス・ポイントを表示し、ルートディレクトリや主要なマウントパスが制限されている場合に価値があります。そのような場合、アクセス・ポイントは機密情報にアクセスするための代替パスを提供します。
Usage: python efs_ip_enum.py <IP_ADDRESS>
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 <IP_ADDRESS>")
sys.exit(1)
ip_address = sys.argv[1]
get_efs_info(ip_address)
プライバシー昇格
ポストエクスプロイト
永続性
Tip
学んで実践する AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks をサポートする
- subscription plans を確認してください!
- 参加する 💬 Discord group または telegram group に参加するか、Twitter 🐦 @hacktricks_live をフォローしてください。
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
HackTricks Cloud

