You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+254-22
Original file line number
Diff line number
Diff line change
@@ -1,42 +1,188 @@
1
1
# AWS ImdsPacketAnalyzer
2
2
3
-
The AWS ImdsPacketAnalyzer is a tool that traces TCP interactions with the EC2 Instance Metadata Service (IMDS). This can assist in identifying the processes making IMDSv1 calls on a host. Traces contain the `pid`, the `argv` used to launch the process, and the parent `pids` up to four levels deep. This information allow you to identify a Process making IMDSv1 calls for further investigation.
- [Amazon Linux 1, 2018.03](#amazon-linux-1-201803)
7
+
- [Debian 11](#debian-11)
8
+
- [Debian 10](#debian-10)
9
+
- [Ubuntu 20 / 22](#ubuntu-20--22)
10
+
- [RHEL 8 / 9](#rhel-8--9)
11
+
- [SLES 15](#sles-15)
12
+
- [Windows](#windows)
13
+
-[Usage](#usage)
14
+
-[Amazon Linux 2023](#amazon-linux-2023-1)
15
+
- [Amazon Linux 2](#amazon-linux-2-1)
16
+
- [Amazon Linux 1](#amazon-linux-1)
17
+
- [Debian 11](#debian-11-1)
18
+
- [Debian 10](#debian-10-1)
19
+
- [Ubuntu 20 / 22](#ubuntu-20--22-1)
20
+
- [RHEL 8 / 9](#rhel-8--9-1)
21
+
- [SLES 15](#sles-15-1)
22
+
- [Windows](#windows-1)
23
+
-[Logging](#logging)
24
+
-[Running the tool as a service](#running-the-tool-as-a-service)
25
+
- [Activating the tool as a service](#activating-the-tool-as-a-service)
26
+
- [Deactivating the tool as a service](#deactivating-the-tool-as-a-service)
27
+
-[Limitations](#limitations)
4
28
5
29
6
-
## Installation
7
-
The ImdsPacketAnalyzer leverages the [BCC (BPF Compiler Collection)](https://github.com/iovisor/bcc). In order to successfully run the analyzer the BCC pre-requisites need to be installed.
30
+
# Introduction
31
+
32
+
The AWS ImdsPacketAnalyzer is a tool that traces TCP interactions with the EC2 Instance Metadata Service (IMDS). This can assist in identifying the processes making IMDSv1 calls on a host. Traces contain the `pid`, the `argv` used to launch the process, and the parent `pids` up to four levels deep. This information allow you to identify a Process making IMDSv1 calls for further investigation.
33
+
34
+
The ImdsPacketAnalyzer leverages the [BCC (BPF Compiler Collection)](https://github.com/iovisor/bcc/blob/master/INSTALL.md#Amazon-Linux-2---Binary). In order to successfully run the analyzer the BCC pre-requisites need to be installed.
35
+
36
+
# Packages - Installing BCC
37
+
For hosts with internet access, the install script can be used. It is advised that this script only be run on non-production instances. Installation will update dependancies and may affect other functionality.
38
+
For instances without internet access you will need to share the files on an S3 folder.
39
+
```
40
+
sudo bash install-deps.sh
41
+
```
42
+
---
43
+
44
+
**OR** run the following commands per OS
45
+
46
+
47
+
## Amazon Linux 2023
48
+
49
+
Install BCC
8
50
9
-
### Amazon Linux 2 (AL2)
10
-
For AL2 hosts with internet access, either a installation script,
11
51
```
12
-
sudo ./install-deps.sh
52
+
sudo dnf install bcc-tools
13
53
```
14
-
or, the steps detailed in the [BCC documentation](https://github.com/iovisor/bcc/blob/master/INSTALL.md#Amazon-Linux-2---Binary)
Note : During the Dependency installation, the ["libcrypt1"](https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1818037.html) related error occurs so the execution has step to fix and continue with the installation process further, also the OS libraries can cause the restart of the system releated services like sshd and crond.
91
+
92
+
```
93
+
echo deb http://cloudfront.debian.net/debian sid main | sudo tee -a /etc/apt/sources.list
94
+
sudo -i # Need to switch as root user in the CLI before running below command
95
+
apt-get update
96
+
#Set the environment variable DEBIAN_FRONTEND to 'noninteractive' to avoid the prompts and accept the default answers
- Go to working directory ```cd C:\<Users>\<Administrator>\AppData\Roaming\Python\Python311\scripts```
173
+
174
+
---
34
175
35
176
**Note:** Troubleshooting + Installation on other distros please see: [BCC (BPF Compiler Collection)](https://github.com/iovisor/bcc/blob/master/INSTALL.md)
36
177
178
+
---
37
179
38
180
## Usage
39
-
BCC require that the analyze is run with root permissions. Typically you can execute the following script `sudo python3 src/imds_snoop.py`. IMDS calls will be logged to the console and to a log file by default (see [logging.conf](logging.conf)).
181
+
BCC require that the analyze is run with root permissions. Typically, you can execute the following script and IMDS calls will be logged to the console and to a log file by default (see [logging.conf](logging.conf)).
182
+
```
183
+
sudo python3 src/imds_snoop.py
184
+
```
185
+
40
186
41
187
#### Example v1 call:
42
188
The following IMDSv1 curl command
@@ -47,8 +193,77 @@ will result the following analyzer output
47
193
```
48
194
IMDSv1(!) (pid:6028:curl argv:curl http://169.254.169.254/latest/meta-data/) called by -> (pid:6027:makeCalls.sh argv:/bin/bash ./makeCalls.sh) -> (pid:4081:zsh argv:-zsh) -> (pid:4081:sshd argv:sshd: kianred@pts/0)
- From the Working directory E.g ```cd C:\<Users>\<Administrator>\AppData\Roaming\Python\Python311\scripts```
248
+
- Run to view IMDSv1 calls: ```metabadger cloudwatch-metrics --region us-east-1```
249
+
250
+
The output table will highlight if the instance has made IMDSv1 calls
251
+
252
+
To find the specific app that was making the IMDSv1 calls, use the inbuilt Windows Resource Monitor Network monitor to find the Image and PID of the application making calls.
253
+
254
+
To do this open Resource Monitor (Start->Search ->Resource Monitor) and click on the Network tab.
255
+
Then look for calls in the Network Activity section made to either the IP or DNS entries listed:
Network Analyzer will show the calls and you should proceed to update the software/application
260
+
261
+
More details and thanks to https://github.com/salesforce/metabadger and https://www.greystone.co.uk/2022/03/24/how-greystone-upgraded-its-aws-ec2-instances-to-use-instance-meta-data-service-version-2-imdsv2/
262
+
263
+
264
+
---
265
+
266
+
# Logging
52
267
The ImdsPacketAnalyzer will also capture IMDS calls to log files. Log entries follow the format: `[Time] [Level] [message]` where:
53
268
-**Time:** the time at which the IMDS call was made in the format: `%Y-%m-%dT%H:%M:%S` eg.) [2022-12-20T12:57:51]
54
269
-**Level:** the level of the log entry, where IMDSv2 calls are logged at `INFO` level and IMDSv1 calls are logged at `WARNING` level
@@ -80,35 +295,52 @@ By default:
80
295
### Analyzing log files
81
296
**Assuming default logging setup:**
82
297
- Running the command `cat /var/log/imds-trace.* | grep WARNING` will output all IMDSv1 calls to the terminal.
83
-
- Note that this grep will only identify the call, sometimes the calls leading up to the V1 call can provide additional context.
298
+
- Note that this grep will only identify the call, sometimes the calls leading up to the V1 call can provide additional context.
84
299
85
-
##Running the tool as a service
300
+
# Running the tool as a service
86
301
87
-
###Activating the tool as a service
302
+
## Activating the tool as a service
88
303
Configuring the analyzer to run as a service will ensure that the tool will run as soon as possible even upon the boot up of an instance. This will increase the chances of identifying services making IMDSv1 calls even as early as the instance is inited onto a network.
89
304
90
305
A shell script has been provided in the package that will automate the process of setting up the analyzer tool as a service. **Note:** the script/service will only work if the structure of the package is left unchanged.
91
306
92
307
Run the script from the command line as follows:
308
+
93
309
```
94
310
sudo ./activate-tracer-service.sh
95
311
```
96
312
97
-
you might need to change the file permissions with:
313
+
or
314
+
315
+
```
316
+
sudo bash activate-tracer-service.sh
317
+
```
318
+
319
+
The permissions for the shell script may need to be changed using:
98
320
```
99
-
chmod 777 activate-tracer-service.sh
321
+
chmod +x activate-tracer-service.sh
100
322
```
101
323
102
-
###Deactivating the tool as a service
324
+
## Deactivating the tool as a service
103
325
When the tool is configured as a service using the previous script a service file is added into the OS. In order to restore the system run the script from the command line:
326
+
104
327
```
105
328
sudo ./deactivate-tracer-service.sh
106
329
```
330
+
331
+
or
332
+
333
+
```
334
+
sudo bash deactivate-tracer-service.sh
335
+
```
336
+
107
337
Permissions for the script may need to be changed:
108
338
```
109
-
chmod 777 deactivate-tracer-service.sh
339
+
chmod +x deactivate-tracer-service.sh
110
340
```
111
341
342
+
---
343
+
112
344
## Limitations
113
345
We are aware of some limitations with the current version of the ImdsPacketAnalyzer. Contributions are welcomed.
114
346
- The `install-deps.sh` script assumes AL2 and internet connectivity
0 commit comments