> For the complete documentation index, see [llms.txt](https://rosemary-2.gitbook.io/rosemary-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rosemary-2.gitbook.io/rosemary-docs/tutorials/egress.md). Agents can also search and read this documentation through its [MCP server](https://rosemary-2.gitbook.io/rosemary-docs/~gitbook/mcp).

# Egress

***

*Intermediate · 10 minutes*

Route all internet traffic through an agent when your server is isolated from the internet.

***

### Overview

Egress mode routes all traffic destined for the internet through a chosen agent. This is useful when your attacking server is on an isolated network without direct internet access, but one of your pivoted agents has connectivity.

**In this tutorial:**

* Identify which agent has internet access
* Set the default egress agent
* Access the internet from an isolated server

***

### Scenario

```
[Isolated Server] ──→ [Windows Agent] ──→ [macOS Agent] ──→ [Linux Agent] ──→ [Linux Agent 12] ──→ INTERNET
  No internet                                                                         172.16.19.136
                                                                                     Has internet ✅
```

Your FreeBSD server is on an isolated network. Agent 12 (the second Linux machine) has internet access. You want to browse the web, download tools, and clone repositories from the server through Agent 12.

***

### Before Egress: Server Has No Internet

The FreeBSD server is on an isolated network. Verify it cannot reach the internet.

#### Command Line Test

```bash
curl -I https://google.com
```

**Output:**

```
curl: (7) Failed to connect to google.com port 443: No route to host
```

#### Browser Test

Open a browser and navigate to `https://google.com`:

```
Unable to connect
The browser can't establish a connection to the server at google.com
```

<figure><img src="https://3327027809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXtbgQqKrmN1ymqKZFFPU%2Fuploads%2F7nDeZGouHQjuPtf3naCG%2Fimage.png?alt=media&#x26;token=dbec1f1b-efdf-4c0d-a87b-98883d185e72" alt=""><figcaption></figcaption></figure>

#### Ping Test

```bash
ping -c 3 8.8.8.8
```

**Output:**

```
ping: sendto: No route to host
```

The server is completely isolated from the internet.

### Step 1: Verify Which Agent Has Internet

List agents and check the `HasInternet` field in the dashboard or API:

```bash
rosemary> agents
```

**Output:**

```
ID         OS       Hostname      Subnets                    Internet
agent-2    windows  win-box       172.16.126.0/24            No
agent-6    darwin   mac-user      172.14.1.0/24              No
agent-8    linux    parrot-1      172.16.19.0/24             No
agent-12   linux    parrot-2      Multiple subnets           Yes ✅
agent-14   linux    airtouch      192.168.3.0/24             No
```

Agent 12 has internet access.

***

### Step 2: Set Default Egress Agent

```bash
rosemary> egress agent-12
```

<figure><img src="https://3327027809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXtbgQqKrmN1ymqKZFFPU%2Fuploads%2FVygZHWfA4adRLa1BcYq1%2Fimage.png?alt=media&#x26;token=054f18ca-e1a8-4e86-a87b-7af7e8d058f2" alt=""><figcaption></figcaption></figure>

All traffic to IPs outside known agent subnets now flows through Agent 12.

***

### Step 3: Verify Egress is Working

From the isolated server, test internet access:

```bash
curl -I https://google.com
```

<figure><img src="https://3327027809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXtbgQqKrmN1ymqKZFFPU%2Fuploads%2FSF9DnmrA6dCHjNRWmTH7%2Fimage.png?alt=media&#x26;token=2bed2c82-a870-43d7-8f8d-8725ea20a5b0" alt=""><figcaption></figcaption></figure>

The server can now reach the internet through 4 hops.

***

### Step 4: Use Internet Normally

Accessing any website with the browser

<figure><img src="https://3327027809-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXtbgQqKrmN1ymqKZFFPU%2Fuploads%2FISay5TmXMoPDHB7dcUW1%2Fimage.png?alt=media&#x26;token=c95663f5-745f-45b8-870d-1ca6e876d207" alt=""><figcaption></figcaption></figure>

```bash
# Clone a repository
git clone https://github.com/blue0x1/rosemary.git

# Download a file
wget https://example.com/tool.tar.gz

# Resolve external domains
nslookup github.com
```

All traffic routes automatically through Agent 12.

***

### Step 5: Clear Egress

```bash
rosemary> egress none
```

**Output:**

```
[-] Default egress cleared.
```

Internet access is restored to direct connection (if available) or blocked.

***

### How It Works

1. **Subnets are checked first:** Traffic to `192.168.3.0/24` goes through Agent 14, not egress
2. **Unknown IPs go to egress:** Traffic to `8.8.8.8` has no matching subnet, so it goes through Agent 12
3. **DNS still resolves:** Internal domains resolve via agents; public domains resolve via egress agent
4. **Kernel-level routing:** No application proxy settings needed

***

### API Equivalent

```bash
# Set egress
curl -X POST http://server:1024/api/v1/cli \
  -H "Authorization: Bearer tun_xxx" \
  -d '{"command":"egress agent-12"}'

# Clear egress
curl -X POST http://server:1024/api/v1/cli \
  -H "Authorization: Bearer tun_xxx" \
  -d '{"command":"egress none"}'
```

***

### Troubleshooting

| Issue                    | Solution                                                    |
| ------------------------ | ----------------------------------------------------------- |
| No internet after egress | Verify agent has internet: check `HasInternet` in dashboard |
| Egress agent not found   | Agent may have disconnected; check `agents`                 |
| DNS not resolving        | DNS automatically routes through egress agent               |
| Slow connection          | Each hop adds latency; minimize chain length                |

***
