# T1040 - Network Sniffing

## Description from ATT&CK

> Adversaries may passively sniff network traffic to capture information about an environment, including authentication material passed over the network. Network sniffing refers to using the network interface on a system to monitor or capture information sent over a wired or wireless connection. An adversary may place a network interface into promiscuous mode to passively access data in transit over the network, or use span ports to capture a larger amount of data.
> 
> Data captured via this technique may include user credentials, especially those sent over an insecure, unencrypted protocol. Techniques for name service resolution poisoning, such as [Name Resolution Poisoning and SMB Relay](https://attack.mitre.org/techniques/T1557/001), can also be used to capture credentials to websites, proxies, and internal systems by redirecting traffic to an adversary.
> 
> Network sniffing may reveal configuration details, such as running services, version numbers, and other network characteristics (e.g. IP addresses, hostnames, VLAN IDs) necessary for subsequent [Lateral Movement](https://attack.mitre.org/tactics/TA0008) and/or [Stealth](https://attack.mitre.org/tactics/TA0005) activities. Adversaries may likely also utilize network sniffing during [Adversary-in-the-Middle](https://attack.mitre.org/techniques/T1557) (AiTM) to passively gain additional knowledge about the environment.
> 
> In cloud-based environments, adversaries may still be able to use traffic mirroring services to sniff network traffic from virtual machines. For example, AWS Traffic Mirroring, GCP Packet Mirroring, and Azure vTap allow users to define specified instances to collect traffic from and specified targets to send collected traffic to.(Citation: AWS Traffic Mirroring)(Citation: GCP Packet Mirroring)(Citation: Azure Virtual Network TAP) Often, much of this traffic will be in cleartext due to the use of TLS termination at the load balancer level to reduce the strain of encrypting and decrypting traffic.(Citation: Rhino Security Labs AWS VPC Traffic Mirroring)(Citation: SpecterOps AWS Traffic Mirroring) The adversary can then use exfiltration techniques such as Transfer Data to Cloud Account in order to access the sniffed traffic.(Citation: Rhino Security Labs AWS VPC Traffic Mirroring)
> 
> On network devices, adversaries may perform network captures using [Network Device CLI](https://attack.mitre.org/techniques/T1059/008) commands such as `monitor capture`.(Citation: US-CERT-TA18-106A)(Citation: capture_embedded_packet_on_software)

[Source](https://attack.mitre.org/techniques/T1040)

## Atomic Tests

- [Atomic Test #1: Packet Capture Linux using tshark or tcpdump](#atomic-test-1-packet-capture-linux-using-tshark-or-tcpdump)
- [Atomic Test #2: Packet Capture FreeBSD using tshark or tcpdump](#atomic-test-2-packet-capture-freebsd-using-tshark-or-tcpdump)
- [Atomic Test #3: Packet Capture macOS using tcpdump or tshark](#atomic-test-3-packet-capture-macos-using-tcpdump-or-tshark)
- [Atomic Test #4: Packet Capture Windows Command Prompt](#atomic-test-4-packet-capture-windows-command-prompt)
- [Atomic Test #5: Windows Internal Packet Capture](#atomic-test-5-windows-internal-packet-capture)
- [Atomic Test #6: Windows Internal pktmon capture](#atomic-test-6-windows-internal-pktmon-capture)
- [Atomic Test #7: Windows Internal pktmon set filter](#atomic-test-7-windows-internal-pktmon-set-filter)
- [Atomic Test #8: Packet Capture macOS using /dev/bpfN with sudo](#atomic-test-8-packet-capture-macos-using-devbpfn-with-sudo)
- [Atomic Test #9: Filtered Packet Capture macOS using /dev/bpfN with sudo](#atomic-test-9-filtered-packet-capture-macos-using-devbpfn-with-sudo)
- [Atomic Test #10: Packet Capture FreeBSD using /dev/bpfN with sudo](#atomic-test-10-packet-capture-freebsd-using-devbpfn-with-sudo)
- [Atomic Test #11: Filtered Packet Capture FreeBSD using /dev/bpfN with sudo](#atomic-test-11-filtered-packet-capture-freebsd-using-devbpfn-with-sudo)
- [Atomic Test #12: Packet Capture Linux socket AF_PACKET,SOCK_RAW with sudo](#atomic-test-12-packet-capture-linux-socket-af_packetsock_raw-with-sudo)
- [Atomic Test #13: Packet Capture Linux socket AF_INET,SOCK_RAW,TCP with sudo](#atomic-test-13-packet-capture-linux-socket-af_inetsock_rawtcp-with-sudo)
- [Atomic Test #14: Packet Capture Linux socket AF_INET,SOCK_PACKET,UDP with sudo](#atomic-test-14-packet-capture-linux-socket-af_inetsock_packetudp-with-sudo)
- [Atomic Test #15: Packet Capture Linux socket AF_PACKET,SOCK_RAW with BPF filter for UDP with sudo](#atomic-test-15-packet-capture-linux-socket-af_packetsock_raw-with-bpf-filter-for-udp-with-sudo)
- [Atomic Test #16: PowerShell Network Sniffing](#atomic-test-16-powershell-network-sniffing)

### Atomic Test #1: Packet Capture Linux using tshark or tcpdump

Perform a PCAP. Wireshark will be required for tshark. TCPdump may already be installed.

Upon successful execution, tshark or tcpdump will execute and capture 5 packets on interface ens33.

**Supported Platforms:** Linux

**auto_generated_guid:** `7fe741f7-b265-4951-a7c7-320889083b3e`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| interface | Specify interface to perform PCAP on. | string | ens33|

#### Attack Commands: Run with `bash`! Elevation Required (e.g. root or admin)

```bash
tcpdump -c 5 -nnni #{interface}
tshark -c 5 -i #{interface}
```


#### Dependencies: Run with `bash`!

##### Description: Check if at least one of tcpdump or tshark is installed.

###### Check Prereq Commands

```bash
if [ ! -x "$(command -v tcpdump)" ] && [ ! -x "$(command -v tshark)" ]; then exit 1; else exit 0; fi;
```

###### Get Prereq Commands

```bash
(which yum && yum -y install epel-release tcpdump tshark)||(which apt-get && DEBIAN_FRONTEND=noninteractive apt-get install -y tcpdump tshark)
```

### Atomic Test #2: Packet Capture FreeBSD using tshark or tcpdump

Perform a PCAP. Wireshark will be required for tshark. TCPdump may already be installed.

Upon successful execution, tshark or tcpdump will execute and capture 5 packets on interface ens33.

**Supported Platforms:** Linux

**auto_generated_guid:** `c93f2492-9ebe-44b5-8b45-36574cccfe67`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| interface | Specify interface to perform PCAP on. | string | em0|

#### Attack Commands: Run with `sh`! Elevation Required (e.g. root or admin)

```sh
tcpdump -c 5 -nnni #{interface}
tshark -c 5 -i #{interface}
```


#### Dependencies: Run with `sh`!

##### Description: Check if at least one of tcpdump or tshark is installed.

###### Check Prereq Commands

```sh
if [ ! -x "$(command -v tcpdump)" ] && [ ! -x "$(command -v tshark)" ]; then exit 1; else exit 0; fi;
```

###### Get Prereq Commands

```sh
(which pkg && pkg install -y wireshark-nox11)
```

### Atomic Test #3: Packet Capture macOS using tcpdump or tsh