> 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/reconnaissance.md). Agents can also search and read this documentation through its [MCP server](https://rosemary-2.gitbook.io/rosemary-docs/~gitbook/mcp).

# Reconnaissance

*Beginner · 10 minutes*

Perform network reconnaissance through an agent using built-in ping and port scanning.

***

### Overview

Rosemary includes reconnaissance features that run directly through connected agents. No need to upload nmap or write scanning scripts. It's all built into the CLI and dashboard.

**In this tutorial:**

* Ping a single host through an agent
* Discover live hosts on a subnet using ICMP and TCP probes
* Run TCP/UDP port scans through an agent

***

### Scenario

You have an agent connected to an internal network. You want to find live hosts and open ports without uploading any tools to the pivot machine.

```
[Server] > Rosemary > [Agent] > scans > [Target Network]
```

***

### Step 1: Ping a Single Host

Verify if a specific host is alive:

```bash
rosemary> ping agent-24 192.168.1.104
```

**Output:**

```
[*] Sent ICMP ping to agent agent-24 > 192.168.1.104 (count=4)
[+] ICMP agent-24 > 192.168.1.104 seq=1 rtt=0.05ms err=
[+] ICMP agent-24 > 192.168.1.104 seq=2 rtt=0.06ms err=
[+] ICMP agent-24 > 192.168.1.104 seq=3 rtt=0.05ms err=
[+] ICMP agent-24 > 192.168.1.104 seq=4 rtt=0.05ms err=
```

Host is alive. 4 packets sent, 4 received, 0% loss.

***

### Step 2: Discover Live Hosts

Scan a subnet for live hosts using ICMP and TCP probes:

```bash
rosemary> discover agent-24 192.168.1.0/24
```

**Output:**

```
[*] Discovering hosts on 192.168.1.0/24 via agent-24 (timeout=300ms, workers=100)
[*] Discover 192.168.1.0/24  3 hosts up:
  192.168.1.1         35.0 ms
  192.168.1.104       0.0 ms
  192.168.1.106       23.0 ms
```

3 live hosts found with round-trip times.

#### Discover Options

```bash
rosemary> discover agent-24 10.10.0.0/16 500 200
```

| Option       | Default | Description                 |
| ------------ | ------- | --------------------------- |
| `timeout_ms` | 300     | Response wait time per host |
| `workers`    | 100     | Concurrent probes           |

***

### Step 3: TCP Port Scan

Scan for open ports on a discovered host:

```bash
rosemary> portscan agent-24 tcp 192.168.1.104
```

**Output:**

```
[*] Started tcp port scan via agent agent-24 on 192.168.1.104 ports 1-1024
[*] Port scan agent agent-24 on 192.168.1.104 (tcp)
  open            111
  open            143
  open            993
Scan finished in 2.0 seconds
```

***

### Step 4: Custom Port Range

```bash
rosemary> portscan agent-24 tcp 192.168.1.104 22,80,443,8080
```

***

### Step 5: UDP Port Scan

```bash
rosemary> portscan agent-24 udp 192.168.1.104 53,161,500
```

***

### Dashboard Equivalent

All reconnaissance features are available in the dashboard via modals:

* **Ping** - Select agent, click Ping, enter target IP
* **Discover** - Same syntax as terminal CLI. Use in web CLI panel or API.
* **Port Scan** - Select agent, click Port Scan, choose TCP/UDP and ports

***

### API Reference

#### Ping

| Field  | Type   | Required | Description                  |
| ------ | ------ | -------- | ---------------------------- |
| target | string | yes      | IP or hostname to ping       |
| count  | int    | no       | Ping count (1-20, default 4) |

```bash
curl -X POST http://localhost:1024/api/v1/agents/agent-1/ping \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"target":"192.168.1.1","count":4}'
```

#### Discover

| Field       | Type   | Required | Description                       |
| ----------- | ------ | -------- | --------------------------------- |
| subnet      | string | yes      | CIDR notation e.g. 192.168.1.0/24 |
| timeout\_ms | int    | no       | Per-host timeout ms (default 300) |
| workers     | int    | no       | Concurrent workers (default 100)  |

```bash
curl -X POST http://localhost:1024/api/v1/agents/agent-1/discover \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"subnet":"192.168.1.0/24","timeout_ms":300,"workers":50}'
```

#### Port Scan

| Field  | Type   | Required | Description                                          |
| ------ | ------ | -------- | ---------------------------------------------------- |
| target | string | yes      | Target IP or hostname                                |
| ports  | string | no       | Port range e.g. 1-1024 or 22,80,443 (default 1-1024) |
| proto  | string | no       | tcp (default) or udp                                 |

```bash
curl -X POST http://localhost:1024/api/v1/agents/agent-1/portscan \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"target":"10.10.10.5","ports":"1-1024","proto":"tcp"}'
```

***

### Commands Summary

| Command                                         | Description                          |
| ----------------------------------------------- | ------------------------------------ |
| `ping <agent> <target> [count]`                 | ICMP ping through an agent           |
| `discover <agent> <subnet> [timeout] [workers]` | Discover live hosts using ICMP + TCP |
| `portscan <agent> tcp\|udp <target> [ports]`    | Port scan through an agent           |

***

### Why Use Built-in Reconnaissance

* **No tool uploads** - Nothing to transfer to the pivot host
* **Faster** - ICMP and scanning run natively on the agent
* **Stealthier** - No additional processes on the compromised machine
* **Dashboard visibility** - All results appear in real-time

***
