Files
hacktricks-cloud/src/pentesting-cloud/aws-security/aws-services/aws-efs-enum.md

9.8 KiB

AWS - EFS Enum

{{#include ../../../banners/hacktricks-training.md}}

EFS

Basiese Inligting

Amazon Elastic File System (EFS) word aangebied as 'n volledig bestuurde, skaalbare, en elastiese netwerk lêerstelsel deur AWS. Die diens fasiliteer die skepping en konfigurasie van lêerstelsels wat gelyktydig deur verskeie EC2-instanties en ander AWS-dienste benader kan word. Die sleutelkenmerke van EFS sluit in sy vermoë om outomaties te skaal sonder handmatige ingryping, lae-latensie toegang te voorsien, hoë-deurvoer werklas te ondersteun, data-duursaamheid te waarborg, en naatloos te integreer met verskeie AWS-sekuriteitsmeganismes.

Deur standaard sal die EFS-gids om te monteer / wees, maar dit kan 'n ander naam hê.

Netwerk Toegang

'n EFS word in 'n VPC geskep en sal standaard toeganklik wees in al die VPC-subnetwerke. Die EFS sal egter 'n Sekuriteitsgroep hê. Om toegang te gee aan 'n EC2 (of enige ander AWS-diens) om die EFS te monteer, is dit nodig om in die EFS-sekuriteitsgroep 'n inkomende NFS (poort 2049) reël van die EC2-sekuriteitsgroep toe te laat.

Sonder dit, sal jy nie in staat wees om die NFS-diens te kontak nie.

Vir meer inligting oor hoe om dit te doen, kyk: https://stackoverflow.com/questions/38632222/aws-efs-connection-timeout-at-mount

Enumerasie

# 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

Dit mag wees dat die EFS-mountpunt binne dieselfde VPC is, maar in 'n ander subnet. As jy seker wil wees dat jy al die EFS-punte vind, sal dit beter wees om die /16 netmask te skandeer.

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 Toegang

Deur standaard sal enigeen met netwerktoegang tot die EFS in staat wees om te monteer, te lees en te skryf selfs as die wortelgebruiker. egter, File System-beleide kan in plek wees wat slegs prinsipes met spesifieke toestemmings toelaat om toegang te verkry.
Byvoorbeeld, hierdie File System-beleid sal nie eens toelaat om die lêerstelsel te monteer as jy nie die IAM-toestemming het:

{
"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"
}
}
}
]
}

Of dit sal anonieme toegang voorkom:

Let daarop dat jy die tipe "efs" in die monteeropdrag MOET gebruik om lêerstelsels wat deur IAM beskerm word, te monteer:

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

Toegangspunte

Toegangspunte is aansoek-spesifieke toegangspunte tot 'n EFS-lêerstelsel wat dit makliker maak om aansoektoegang tot gedeelde datastelle te bestuur.

Wanneer jy 'n toegangspunt skep, kan jy die eienaar en POSIX-toestemmings vir die lêers en gidse wat deur die toegangspunt geskep word, specifiseer. Jy kan ook 'n pasgemaakte wortelgidse vir die toegangspunt definieer, hetsy deur 'n bestaande gidse te spesifiseer of deur 'n nuwe een met die gewenste toestemmings te skep. Dit stel jou in staat om toegang tot jou EFS-lêerstelsel op 'n per-aansoek of per-gebruiker basis te beheer, wat dit makliker maak om jou gedeelde lêerdata te bestuur en te beveilig.

Jy kan die Lêerstelsel vanaf 'n toegangspunt monteer met iets soos:

# 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

Let daarop dat selfs al probeer om 'n toegangspunt te monteer, jy steeds in staat moet wees om die NFS-diens via netwerk te kontak, en as die EFS 'n lêerstelsel beleid het, het jy voldoende IAM-toestemmings nodig om dit te monteer.

Toegangspunte kan vir die volgende doeleindes gebruik word:

  • Simplifiseer toestemmingsbestuur: Deur 'n POSIX-gebruiker en -groep vir elke toegangspunt te definieer, kan jy maklik toegangstoestemmings vir verskillende toepassings of gebruikers bestuur sonder om die onderliggende lêerstelsel se toestemmings te wysig.
  • Handhaaf 'n worteldirektories: Toegangspunte kan toegang tot 'n spesifieke direktorie binne die EFS-lêerstelsel beperk, wat verseker dat elke toepassing of gebruiker binne sy aangewese vouer werk. Dit help om toevallige data-blootstelling of -wysigings te voorkom.
  • Makliker lêerstelseltoegang: Toegangspunte kan geassosieer word met 'n AWS Lambda-funksie of 'n AWS Fargate-taak, wat lêerstelseltoegang vir serverless en gekontaineriseerde toepassings vereenvoudig.

EFS IP-adres

Deur die inligting rakende die EFS IP-adres te gebruik, kan die volgende Python-skrip help om besonderhede oor die EFS-stelsel te verkry. Hierdie inligting is nuttig om die monteer-sisteemopdrag te bou of verdere enumerasie uit te voer met kennis van die subnet-ID. Boonop toon die skrip toegangspunte, wat waardevol kan wees wanneer die worteldirektorie of primêre monteerpunt beperk is. In sulke gevalle bied die toegangspunte alternatiewe paaie om toegang tot sensitiewe inligting te verkry.

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)

Privesc

{{#ref}} ../aws-privilege-escalation/aws-efs-privesc.md {{#endref}}

Post Exploitation

{{#ref}} ../aws-post-exploitation/aws-efs-post-exploitation.md {{#endref}}

Persistensie

{{#ref}} ../aws-persistence/aws-efs-persistence.md {{#endref}}

{{#include ../../../banners/hacktricks-training.md}}