> For the complete documentation index, see [llms.txt](https://adaptix-framework.gitbook.io/adaptix-framework/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adaptix-framework.gitbook.io/adaptix-framework/development/teamserver-interface/ts-api.md).

# TS API

## Agent Functions

### TsAgentIsExists

Checks if an agent exists by ID.

```go
TsAgentIsExists(agentId string) bool
```

<table><thead><tr><th width="140">Parameter</th><th width="118">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentId</code></td><td><code>string</code></td><td>Unique agent identifier</td></tr></tbody></table>

**Returns:** `bool` — `true` if agent exists

***

### TsAgentCreate

Creates a new agent on first connection.

```go
TsAgentCreate(agentCrc string, agentId string, beat []byte, listenerName string, ExternalIP string, Async bool) (adaptix.AgentData, error)
```

<table><thead><tr><th width="144">Parameter</th><th width="130">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentCrc</code></td><td><code>string</code></td><td>CRC/watermark of agent type</td></tr><tr><td><code>agentId</code></td><td><code>string</code></td><td>Unique agent ID</td></tr><tr><td><code>beat</code></td><td><code>[]byte</code></td><td>Initial data from agent (heartbeat)</td></tr><tr><td><code>listenerName</code></td><td><code>string</code></td><td>Listener name</td></tr><tr><td><code>ExternalIP</code></td><td><code>string</code></td><td>Agent's external IP</td></tr><tr><td><code>Async</code></td><td><code>bool</code></td><td>Async mode</td></tr></tbody></table>

**Returns:** `adaptix.AgentData`, `error`

**Events:**

* `agent.new` (Pre/Post hooks)

***

### TsAgentProcessData

Processes data received from the agent.

```go
TsAgentProcessData(agentId string, bodyData []byte) error
```

<table><thead><tr><th width="137">Parameter</th><th width="112">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>bodyData</code></td><td><code>[]byte</code></td><td>Data from agent</td></tr></tbody></table>

**Note:** If the agent has `Mark="Inactive"`, it is automatically activated and the `agent.activate` event is called.

***

### TsAgentUpdateData

Updates agent data (sleep, jitter, killdate, workingtime).

```go
TsAgentUpdateData(newAgentData adaptix.AgentData) error
```

***

### TsAgentUpdateDataPartial

Partial update of agent data.

```go
TsAgentUpdateDataPartial(agentId string, updateData interface{}) error
```

**Supported fields:**

* `InternalIP`, `ExternalIP`, `GmtOffset`, `ACP`, `OemCP`
* `Pid`, `Tid`, `Arch`, `Elevated`, `Process`
* `Os`, `OsDesc`, `Domain`, `Computer`, `Username`
* `Impersonated`, `Tags`, `Mark`, `Color`

***

### TsAgentTerminate

Terminates the agent.

```go
TsAgentTerminate(agentId string, terminateTaskId string) error
```

**Actions on call:**

1. Cancels all active downloads
2. Stops all tunnels
3. Closes terminals
4. Clears task queues
5. Removes pivot connections

**Events:**

* `agent.terminate` (Pre/Post hooks)

***

### TsAgentSetTick

Updates the agent's last response time and current listener.

```go
TsAgentSetTick(agentId string, listenerName string) error
```

***

### TsAgentConsoleOutput

Outputs a message to the agent console.

```go
TsAgentConsoleOutput(agentId string, messageType int, message string, clearText string, store bool)
```

<table><thead><tr><th width="143">Parameter</th><th width="110">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>messageType</code></td><td><code>int</code></td><td>Message type (5=INFO, 6=ERROR, 7=SUCCESS)</td></tr><tr><td><code>message</code></td><td><code>string</code></td><td>Message title</td></tr><tr><td><code>clearText</code></td><td><code>string</code></td><td>Message text</td></tr><tr><td><code>store</code></td><td><code>bool</code></td><td>Store in DB</td></tr></tbody></table>

***

### TsAgentBuildExecute

Executes an external command during agent build with output redirected to the WebSocket build channel.

```go
TsAgentBuildExecute(builderId string, workingDir string, program string, args ...string) error
```

<table><thead><tr><th width="141">Parameter</th><th width="145">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>builderId</code></td><td><code>string</code></td><td>Builder ID (empty string for synchronous execution)</td></tr><tr><td><code>workingDir</code></td><td><code>string</code></td><td>Working directory for the command</td></tr><tr><td><code>program</code></td><td><code>string</code></td><td>Executable</td></tr><tr><td><code>args</code></td><td><code>...string</code></td><td>Command-line arguments</td></tr></tbody></table>

**Note:** If `builderId` is empty, the command executes synchronously without WebSocket output. Otherwise, stdout/stderr are redirected to the build channel.

***

### TsAgentBuildLog

Sends a log message to the agent's WebSocket build channel.

```go
TsAgentBuildLog(builderId string, status int, message string) error
```

<table><thead><tr><th width="124">Parameter</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>builderId</code></td><td><code>string</code></td><td>Builder ID</td></tr><tr><td><code>status</code></td><td><code>int</code></td><td>Status: BUILD_LOG_NONE=0, INFO=1, ERROR=2, SUCCESS=3</td></tr><tr><td><code>message</code></td><td><code>string</code></td><td>Message text</td></tr></tbody></table>

***

### TsAgentGetHosted\* Functions

Gets tasks for sending to the agent. All functions pack tasks considering size limitations.

#### **TsAgentGetHostedAll**

Gets all available tasks: regular tasks, tunnel tasks, tunnel data, and pivot tasks.

```go
TsAgentGetHostedAll(agentId string, maxDataSize int) ([]byte, error)
```

<table><thead><tr><th width="144">Parameter</th><th width="107">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>maxDataSize</code></td><td><code>int</code></td><td>Maximum data size (bytes)</td></tr></tbody></table>

**Returns:** Packed task data for sending to the agent.

#### **TsAgentGetHostedTasks**

Gets only regular tasks and tunnel tasks (without pivot).

```go
TsAgentGetHostedTasks(agentId string, maxDataSize int) ([]byte, error)
```

#### **TsAgentGetHostedTasksCount**

Gets the specified number of tasks.

```go
TsAgentGetHostedTasksCount(agentId string, count int, maxDataSize int) ([]byte, error)
```

<table><thead><tr><th width="150">Parameter</th><th width="121">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>count</code></td><td><code>int</code></td><td>Maximum number of tasks</td></tr><tr><td><code>maxDataSize</code></td><td><code>int</code></td><td>Maximum data size (bytes)</td></tr></tbody></table>

***

## Task Functions

### TsTaskRunningExists

Checks if a task is running.

```go
TsTaskRunningExists(agentId string, taskId string) bool
```

***

### TsTaskCreate

Creates a new task.

```go
TsTaskCreate(agentId string, cmdline string, client string, taskData adaptix.TaskData)
```

**Events:**

* `task.create` (Pre/Post hooks)

***

### TsTaskUpdate

Updates the task with execution results.

```go
TsTaskUpdate(agentId string, updateData adaptix.TaskData)
```

**Events:**

* `task.complete` (Post hook) — when task is completed

***

### TsTaskCancel

Cancels a task that is in the queue (not yet sent to the agent).

```go
TsTaskCancel(agentId string, taskId string) error
```

<table><thead><tr><th width="142">Parameter</th><th width="141">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>taskId</code></td><td><code>string</code></td><td>Task ID</td></tr></tbody></table>

**Note:** Cancels only tasks in the queue. Already running tasks cannot be cancelled.

***

## Client GUI Functions

Functions for synchronizing data with GUI clients (File Browser, Process Manager). These functions send results only to the client that initiated the request.

### TsClientGuiDisksWindows

Sends the list of Windows drives to the client.

```go
TsClientGuiDisksWindows(taskData adaptix.TaskData, drives []adaptix.ListingDrivesDataWin)
```

<table><thead><tr><th width="139">Parameter</th><th width="303">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>taskData</code></td><td><code>adaptix.TaskData</code></td><td>Task data</td></tr><tr><td><code>drives</code></td><td><code>[]adaptix.ListingDrivesDataWin</code></td><td>Drive list</td></tr></tbody></table>

***

### TsClientGuiFilesWindows

Sends the list of Windows files to the client.

```go
TsClientGuiFilesWindows(taskData adaptix.TaskData, path string, files []adaptix.ListingFileDataWin)
```

<table><thead><tr><th width="135">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>taskData</code></td><td><code>adaptix.TaskData</code></td><td>Task data</td></tr><tr><td><code>path</code></td><td><code>string</code></td><td>Directory path</td></tr><tr><td><code>files</code></td><td><code>[]adaptix.ListingFileDataWin</code></td><td>File list</td></tr></tbody></table>

***

### TsClientGuiFilesUnix

Sends the list of Unix/Linux files to the client.

```go
TsClientGuiFilesUnix(taskData adaptix.TaskData, path string, files []adaptix.ListingFileDataUnix)
```

<table><thead><tr><th width="141">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>taskData</code></td><td><code>adaptix.TaskData</code></td><td>Task data</td></tr><tr><td><code>path</code></td><td><code>string</code></td><td>Directory path</td></tr><tr><td><code>files</code></td><td><code>[]adaptix.ListingFileDataUnix</code></td><td>File list</td></tr></tbody></table>

***

### TsClientGuiFilesStatus

Sends the file operation status (delete, rename, etc.) to the client.

```go
TsClientGuiFilesStatus(taskData adaptix.TaskData)
```

<table><thead><tr><th width="128">Parameter</th><th width="187">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>taskData</code></td><td><code>adaptix.TaskData</code></td><td>Task data with MessageType and Message for status</td></tr></tbody></table>

***

### TsClientGuiProcessWindows

Sends the list of Windows processes to the client.

```go
TsClientGuiProcessWindows(taskData adaptix.TaskData, process []adaptix.ListingProcessDataWin)
```

<table><thead><tr><th width="137">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>taskData</code></td><td><code>adaptix.TaskData</code></td><td>Task data</td></tr><tr><td><code>process</code></td><td><code>[]adaptix.ListingProcessDataWin</code></td><td>Process list</td></tr></tbody></table>

***

### TsClientGuiProcessUnix

Sends the list of Unix/Linux processes to the client.

```go
TsClientGuiProcessUnix(taskData adaptix.TaskData, process []adaptix.ListingProcessDataUnix)
```

<table><thead><tr><th width="141">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>taskData</code></td><td><code>adaptix.TaskData</code></td><td>Task data</td></tr><tr><td><code>process</code></td><td><code>[]adaptix.ListingProcessDataUnix</code></td><td>Process list</td></tr></tbody></table>

***

## Credentials Functions

### TsCredentilsAdd

Adds credentials.

```go
TsCredentilsAdd(creds []map[string]interface{}) error
```

**Credential structure:**

```go
map[string]interface{}{
    "username": "admin",
    "password": "hash_or_password",
    "realm":    "DOMAIN",
    "type":     "NTLM",
    "tag":      "DC01",
    "storage":  "LSASS",
    "agent_id": "abc123",
    "host":     "192.168.1.1",
}
```

**Events:**

* `credentials.add` (Pre/Post hooks)

***

### TsCredentilsEdit

```go
TsCredentilsEdit(credId string, username string, password string, realm string, credType string, tag string, storage string, host string) error
```

**Events:**

* `credentials.edit` (Pre/Post hooks)

***

### TsCredentialsSetTag

```go
TsCredentialsSetTag(credsId []string, tag string) error
```

***

### TsCredentilsDelete

```go
TsCredentilsDelete(credsId []string) error
```

**Events:**

* `credentials.remove` (Pre/Post hooks)

***

## Download/Upload Functions

### TsDownloadAdd

Initializes a file download.

```go
TsDownloadAdd(agentId string, fileId string, fileName string, fileSize int64) error
```

**Events:**

* `download.start` (Pre/Post hooks)

***

### TsDownloadUpdate

Updates download state.

```go
TsDownloadUpdate(fileId string, state int, data []byte) error
```

<table><thead><tr><th width="110">State</th><th width="142">Value</th><th>Description</th></tr></thead><tbody><tr><td>1</td><td>RUNNING</td><td>Download in progress</td></tr><tr><td>2</td><td>STOPPED</td><td>Paused</td></tr><tr><td>3</td><td>FINISHED</td><td>Completed</td></tr><tr><td>4</td><td>CANCELED</td><td>Cancelled</td></tr></tbody></table>

***

### TsDownloadClose

Finishes a download.

```go
TsDownloadClose(fileId string, reason int) error
```

**Events:**

* `download.finish` (Pre/Post hooks)

***

### TsDownloadSave

Saves a file directly (from memory).

```go
TsDownloadSave(agentId string, fileId string, filename string, content []byte) error
```

***

### TsDownloadGetFilepath

Returns the local path to the downloaded file.

```go
TsDownloadGetFilepath(fileId string) (string, error)
```

<table><thead><tr><th width="137">Parameter</th><th width="135">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>fileId</code></td><td><code>string</code></td><td>File ID</td></tr></tbody></table>

**Returns:** Full path to the file on the server.

**Note:** Works only for completed downloads (state=FINISHED).

***

### TsDownloadDelete

Deletes downloaded files.

```go
TsDownloadDelete(fileId []string) error
```

<table><thead><tr><th width="147">Parameter</th><th width="167">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>fileId</code></td><td><code>[]string</code></td><td>List of file IDs</td></tr></tbody></table>

**Actions:**

1. Deletes files from disk
2. Removes records from DB
3. Synchronizes with clients

**Events:**

* `download.remove` (Pre/Post hooks)

***

## Listener Functions

### TsListenerGetProfile

Gets a profile for agent generation.

```go
TsListenerGetProfile(listenerName string, listenerType string) (string, []byte, error)
```

**Returns:** watermark, profile bytes, error

***

### TsListenerInteralHandler

Handles internal requests (pivot agents).

```go
TsListenerInteralHandler(watermark string, data []byte) (string, error)
```

***

## Pivot Functions

### TsPivotCreate

Creates a pivot connection.

```go
TsPivotCreate(pivotId string, pAgentId string, chAgentId string, pivotName string, isRestore bool) error
```

**Events:**

* `pivot.create` (Pre/Post hooks)

***

### TsPivotDelete

```go
TsPivotDelete(pivotId string) error
```

**Events:**

* `pivot.remove` (Pre/Post hooks)

***

### TsGetPivotInfoByName / TsGetPivotInfoById

```go
TsGetPivotInfoByName(pivotName string) (string, string, string)  // pivotId, parentAgentId, childAgentId
TsGetPivotInfoById(pivotId string) (string, string, string)      // pivotName, parentAgentId, childAgentId
```

***

### TsGetPivotByName / TsGetPivotById

```go
TsGetPivotByName(pivotName string) *adaptix.PivotData
TsGetPivotById(pivotId string) *adaptix.PivotData
```

***

## Screenshot Functions

### TsScreenshotAdd

Adds a screenshot.

```go
TsScreenshotAdd(agentId string, Note string, Content []byte) error
```

**Events:**

* `screenshot.add` (Pre/Post hooks)

***

### TsScreenshotNote

Updates the note for a screenshot.

```go
TsScreenshotNote(screenId string, note string) error
```

<table><thead><tr><th width="150">Parameter</th><th width="141">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>screenId</code></td><td><code>string</code></td><td>Screenshot ID</td></tr><tr><td><code>note</code></td><td><code>string</code></td><td>Note text</td></tr></tbody></table>

***

### TsScreenshotDelete

Deletes a screenshot.

```go
TsScreenshotDelete(screenId string) error
```

<table><thead><tr><th width="147">Parameter</th><th width="149">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>screenId</code></td><td><code>string</code></td><td>Screenshot ID</td></tr></tbody></table>

**Actions:**

1. Deletes the file from disk
2. Removes the record from the DB
3. Synchronizes with clients

**Events:**

* `screenshot.remove` (Pre/Post hooks)

***

## Target Functions

### TsTargetsAdd

Adds new targets (hosts). Duplicates are automatically ignored.

```go
TsTargetsAdd(targets []map[string]interface{}) error
```

**Target structure:**

```go
map[string]interface{}{
    "computer": "DC01",           // Computer name
    "domain":   "CORP.LOCAL",     // Domain
    "address":  "192.168.1.10",   // IP address
    "os":       1,                // 1=Windows, 2=Linux, 3=macOS
    "os_desk":  "Windows Server 2019",
    "tag":      "Domain Controller",
    "info":     "Additional information",
    "alive":    true,             // Is target alive
}
```

**Events:**

* `target.add` (Pre/Post hooks)

***

### TsTargetsEdit

Edits an existing target.

```go
TsTargetsEdit(targetId string, computer string, domain string, address string, os int, osDesk string, tag string, info string, alive bool) error
```

<table><thead><tr><th width="168">Parameter</th><th width="155">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>targetId</code></td><td><code>string</code></td><td>Target ID</td></tr><tr><td><code>computer</code></td><td><code>string</code></td><td>Computer name</td></tr><tr><td><code>domain</code></td><td><code>string</code></td><td>Domain</td></tr><tr><td><code>address</code></td><td><code>string</code></td><td>IP address</td></tr><tr><td><code>os</code></td><td><code>int</code></td><td>OS type (1/2/3)</td></tr><tr><td><code>osDesk</code></td><td><code>string</code></td><td>OS description</td></tr><tr><td><code>tag</code></td><td><code>string</code></td><td>Tag</td></tr><tr><td><code>info</code></td><td><code>string</code></td><td>Additional info</td></tr><tr><td><code>alive</code></td><td><code>bool</code></td><td>Alive</td></tr></tbody></table>

**Events:**

* `target.edit` (Pre/Post hooks)

***

### TsTargetSetTag

Sets a tag for a group of targets.

```go
TsTargetSetTag(targetsId []string, tag string) error
```

<table><thead><tr><th width="164">Parameter</th><th width="170">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>targetsId</code></td><td><code>[]string</code></td><td>List of target IDs</td></tr><tr><td><code>tag</code></td><td><code>string</code></td><td>New tag</td></tr></tbody></table>

***

### TsTargetDelete

Deletes targets.

```go
TsTargetDelete(targetsId []string) error
```

<table><thead><tr><th width="173">Parameter</th><th width="170">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>targetsId</code></td><td><code>[]string</code></td><td>List of target IDs</td></tr></tbody></table>

**Events:**

* `target.remove` (Pre/Post hooks)

***

## Tunnel Functions

### TsTunnelStart

Starts the created tunnel.

```go
TsTunnelStart(TunnelId string) (string, error)
```

<table><thead><tr><th width="152">Parameter</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>TunnelId</code></td><td><code>string</code></td><td>Tunnel ID</td></tr></tbody></table>

**Returns:** TaskId for tracking

**Events:**

* `tunnel.start` (Pre/Post hooks)

***

### TsTunnelCreate\* Functions

Functions for creating tunnels of different types. Return TunnelId.

#### TsTunnelCreateSocks4

Creates a SOCKS4 proxy.

```go
TsTunnelCreateSocks4(AgentId string, Info string, Lhost string, Lport int) (string, error)
```

<table><thead><tr><th width="144">Parameter</th><th width="126">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>AgentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>Info</code></td><td><code>string</code></td><td>Tunnel description</td></tr><tr><td><code>Lhost</code></td><td><code>string</code></td><td>Bind address</td></tr><tr><td><code>Lport</code></td><td><code>int</code></td><td>Bind port</td></tr></tbody></table>

#### TsTunnelCreateSocks5

Creates a SOCKS5 proxy with optional authentication.

```go
TsTunnelCreateSocks5(AgentId string, Info string, Lhost string, Lport int, UseAuth bool, Username string, Password string) (string, error)
```

<table><thead><tr><th width="150">Parameter</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>AgentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>Info</code></td><td><code>string</code></td><td>Tunnel description</td></tr><tr><td><code>Lhost</code></td><td><code>string</code></td><td>Bind address</td></tr><tr><td><code>Lport</code></td><td><code>int</code></td><td>Bind port</td></tr><tr><td><code>UseAuth</code></td><td><code>bool</code></td><td>Use authentication</td></tr><tr><td><code>Username</code></td><td><code>string</code></td><td>Username (if UseAuth)</td></tr><tr><td><code>Password</code></td><td><code>string</code></td><td>Password (if UseAuth)</td></tr></tbody></table>

#### TsTunnelCreateLportfwd

Creates a local port forward.

```go
TsTunnelCreateLportfwd(AgentId string, Info string, Lhost string, Lport int, Thost string, Tport int) (string, error)
```

<table><thead><tr><th width="140">Parameter</th><th width="143">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>AgentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>Info</code></td><td><code>string</code></td><td>Tunnel description</td></tr><tr><td><code>Lhost</code></td><td><code>string</code></td><td>Local address</td></tr><tr><td><code>Lport</code></td><td><code>int</code></td><td>Local port</td></tr><tr><td><code>Thost</code></td><td><code>string</code></td><td>Target address (on agent)</td></tr><tr><td><code>Tport</code></td><td><code>int</code></td><td>Target port</td></tr></tbody></table>

#### TsTunnelCreateRportfwd

Creates a reverse port forward.

```go
TsTunnelCreateRportfwd(AgentId string, Info string, Lport int, Thost string, Tport int) (string, error)
```

<table><thead><tr><th width="136">Parameter</th><th width="152">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>AgentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>Info</code></td><td><code>string</code></td><td>Tunnel description</td></tr><tr><td><code>Lport</code></td><td><code>int</code></td><td>Port on agent</td></tr><tr><td><code>Thost</code></td><td><code>string</code></td><td>Target address (on server)</td></tr><tr><td><code>Tport</code></td><td><code>int</code></td><td>Target port</td></tr></tbody></table>

***

### TsTunnelUpdateRportfwd

Updates reverse port forward status after the agent response.

```go
TsTunnelUpdateRportfwd(tunnelId int, result bool) (string, string, error)
```

<table><thead><tr><th width="138">Parameter</th><th width="153">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>tunnelId</code></td><td><code>int</code></td><td>Tunnel ID (numeric)</td></tr><tr><td><code>result</code></td><td><code>bool</code></td><td>Whether the tunnel was created on the agent</td></tr></tbody></table>

**Returns:** TaskId, message, error

***

### TsTunnelStop\* Functions

Functions for stopping tunnels.

#### TsTunnelStop

Stops a tunnel by ID.

```go
TsTunnelStop(tunnelId string) error
```

**Events:**

* `tunnel.stop` (Pre/Post hooks)

#### TsTunnelStopSocks

Stops a SOCKS proxy by agent and port.

```go
TsTunnelStopSocks(AgentId string, Port int)
```

#### TsTunnelStopLportfwd

Stops a local port forward.

```go
TsTunnelStopLportfwd(AgentId string, Port int)
```

#### TsTunnelStopRportfwd

Stops a reverse port forward. Sends a close command to the agent.

```go
TsTunnelStopRportfwd(AgentId string, Port int)
```

***

### TsTunnelChannelExists

Checks whether the tunnel channel exists.

```go
TsTunnelChannelExists(channelId int) bool
```

***

### TsTunnelGetPipe

Gets pipes for reading/writing tunnel data.

```go
TsTunnelGetPipe(AgentId string, channelId int) (*io.PipeReader, *io.PipeWriter, error)
```

<table><thead><tr><th width="145">Parameter</th><th width="111">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>AgentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>channelId</code></td><td><code>int</code></td><td>Channel ID</td></tr></tbody></table>

**Returns:** PipeReader for reading data from the server, PipeWriter for writing data to the tunnel.

***

### TsTunnelConnection\* Functions

Functions for managing tunnel connections.

#### TsTunnelConnectionData

Sends data to the tunnel channel.

```go
TsTunnelConnectionData(channelId int, data []byte)
```

#### TsTunnelConnectionResume

Resumes the connection after a successful connection on the agent side.

```go
TsTunnelConnectionResume(AgentId string, channelId int, ioDirect bool)
```

<table><thead><tr><th width="147">Parameter</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>AgentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>channelId</code></td><td><code>int</code></td><td>Channel ID</td></tr><tr><td><code>ioDirect</code></td><td><code>bool</code></td><td>true = direct transfer without buffering</td></tr></tbody></table>

#### TsTunnelConnectionClose

Closes the channel connection.

```go
TsTunnelConnectionClose(channelId int, writeOnly bool)
```

<table><thead><tr><th width="147">Parameter</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>channelId</code></td><td><code>string</code></td><td>ChannelId ID</td></tr><tr><td><code>writeOnly</code></td><td><code>bool</code></td><td>To ensure sufficient time for reading and sending data over a socket. Used in async payloads such as HTTP.</td></tr></tbody></table>

#### TsTunnelConnectionHalt

Closes the connection with a SOCKS error.

```go
TsTunnelConnectionHalt(channelId int, errorCode byte)
```

<table><thead><tr><th width="147">Parameter</th><th width="118">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>channelId</code></td><td><code>int</code></td><td>Channel ID</td></tr><tr><td><code>errorCode</code></td><td><code>byte</code></td><td>SOCKS5 error code (1-8)</td></tr></tbody></table>

#### TsTunnelConnectionAccept

Accepts an incoming connection for reverse port forward.

```go
TsTunnelConnectionAccept(tunnelId int, channelId int)
```

***

### TsTunnelPause

Pause tunnels connection to client

```go
TsTunnelPause(channelId int)
```

***

### TsTunnelResume

Recume tunnels connection to client

```go
TsTunnelResume(channelId int)
```

***

## Terminal Functions

Functions for managing interactive terminal sessions via the agent.

### TsAgentTerminalCloseChannel

Closes the terminal channel and notifies the client.

```go
TsAgentTerminalCloseChannel(terminalId string, status string) error
```

<table><thead><tr><th width="167">Parameter</th><th width="134">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>terminalId</code></td><td><code>string</code></td><td>Terminal session ID</td></tr><tr><td><code>status</code></td><td><code>string</code></td><td>Close status/reason</td></tr></tbody></table>

***

### TsTerminalConnExists

Checks whether a terminal connection exists.

```go
TsTerminalConnExists(terminalId string) bool
```

<table><thead><tr><th width="155">Parameter</th><th width="114">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>terminalId</code></td><td><code>string</code></td><td>Terminal session ID</td></tr></tbody></table>

**Returns:** `true` if the session exists

***

### TsTerminalConnResume

Resumes the terminal connection after a successful start on the agent.

```go
TsTerminalConnResume(agentId string, terminalId string, ioDirect bool)
```

<table><thead><tr><th width="150">Parameter</th><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>terminalId</code></td><td><code>string</code></td><td>Terminal session ID</td></tr><tr><td><code>ioDirect</code></td><td><code>bool</code></td><td>true = direct transfer without buffering</td></tr></tbody></table>

***

### TsTerminalConnData

Sends data to the terminal session (output from the agent).

```go
TsTerminalConnData(terminalId string, data []byte)
```

<table><thead><tr><th width="151">Parameter</th><th width="118">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>terminalId</code></td><td><code>string</code></td><td>Terminal session ID</td></tr><tr><td><code>data</code></td><td><code>[]byte</code></td><td>Data to send</td></tr></tbody></table>

***

### TsTerminalConnClose

Closes the terminal session.

```go
TsTerminalConnClose(terminalId string, reason string) error
```

<table><thead><tr><th width="149">Parameter</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>terminalId</code></td><td><code>string</code></td><td>Terminal session ID</td></tr><tr><td><code>reason</code></td><td><code>string</code></td><td>Close reason</td></tr></tbody></table>

***

### TsTerminalGetPipe

Gets pipes for terminal input/output.

```go
TsTerminalGetPipe(AgentId string, terminalId string) (*io.PipeReader, *io.PipeWriter, error)
```

<table><thead><tr><th width="156">Parameter</th><th width="130">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>AgentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>terminalId</code></td><td><code>string</code></td><td>Terminal session ID</td></tr></tbody></table>

**Returns:** PipeReader for reading input from the client, PipeWriter for writing agent output.

***

## Service Functions

### TsServiceSendDataAll

Sends data to all clients on behalf of the service.

```go
TsServiceSendDataAll(service string, data string)
```

***

### TsServiceSendDataClient

Sends data to a specific client on behalf of the service.

```go
TsServiceSendDataClient(operator string, service string, data string)
```

***

## AxScript Server Functions

Server-side AxScript engine functions. Allow loading and executing scripts on the server side, defining commands and hooks without client participation.

### TsAxScriptLoadUser

Loads a user AxScript on the server.

```go
TsAxScriptLoadUser(name string, script string) error
```

<table><thead><tr><th width="131.66668701171875">Parameter</th><th width="107.3333740234375">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code></td><td>Script name</td></tr><tr><td><code>script</code></td><td><code>string</code></td><td>Script content</td></tr></tbody></table>

***

### TsAxScriptUnloadUser

Unloads a user AxScript from the server.

```go
TsAxScriptUnloadUser(name string) error
```

***

### TsAxScriptList

Returns a JSON list of loaded scripts.

```go
TsAxScriptList() (string, error)
```

***

### TsAxScriptCommands

Returns a JSON list of registered server-side commands.

```go
TsAxScriptCommands() (string, error)
```

***

### TsAxScriptResolveHooks

Resolves server-side hooks for an agent command. Used when processing commands where the client did not provide a hook/handler.

```go
TsAxScriptResolveHooks(agentName string, agentId string, listenerRegName string, os int, cmdline string, args map[string]interface{}) (string, string, bool, error)
```

<table><thead><tr><th width="165">Parameter</th><th width="229.6666259765625">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentName</code></td><td><code>string</code></td><td>Agent type name</td></tr><tr><td><code>agentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>listenerRegName</code></td><td><code>string</code></td><td>Registered listener name</td></tr><tr><td><code>os</code></td><td><code>int</code></td><td>Agent OS type</td></tr><tr><td><code>cmdline</code></td><td><code>string</code></td><td>Command line</td></tr><tr><td><code>args</code></td><td><code>map[string]interface{}</code></td><td>Command arguments</td></tr></tbody></table>

**Returns:** `hookId`, `handlerId`, `preHookHandled` (true if Pre hook fully handled the command), `error`

***

### TsAxScriptParseAndExecute

Parses and executes a raw command via the server-side AxScript engine.

```go
TsAxScriptParseAndExecute(agentId string, username string, cmdline string) error
```

<table><thead><tr><th width="129">Parameter</th><th width="133.66668701171875">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>agentId</code></td><td><code>string</code></td><td>Agent ID</td></tr><tr><td><code>username</code></td><td><code>string</code></td><td>Operator name</td></tr><tr><td><code>cmdline</code></td><td><code>string</code></td><td>Command line</td></tr></tbody></table>

***

### AxGetAgentContext

Returns agent context for the server-side AxScript.

```go
AxGetAgentContext(agentId string) (agentName string, listenerRegName string, osType int, err error)
```

***

## Extender Data Functions

Functions for storing extender data in the database.

### TsExtenderDataSave

Saves extender data to the database.

```go
TsExtenderDataSave(extenderName string, key string, value []byte) error
```

***

### TsExtenderDataLoad

Loads extender data from the database.

```go
TsExtenderDataLoad(extenderName string, key string) ([]byte, error)
```

***

### TsExtenderDataDelete

Deletes data by key from the database.

```go
TsExtenderDataDelete(extenderName string, key string) error
```

***

### TsExtenderDataKeys

Returns a list of saved extender keys.

```go
TsExtenderDataKeys(extenderName string) ([]string, error)
```

***

### TsExtenderDataDeleteAll

Deletes all extender data from the database.

```go
TsExtenderDataDeleteAll(extenderName string) error
```

***

## Endpoint Functions

Functions for registering HTTP endpoints.

### TsEndpointRegister

Registers a protected endpoint (uses the teamserver's shared JWT authentication).

```go
TsEndpointRegister(method string, path string, handler func(username string, body []byte) (int, []byte)) error
```

<table><thead><tr><th width="117">Parameter</th><th width="440">Type</th><th width="186">Description</th></tr></thead><tbody><tr><td><code>method</code></td><td><code>string</code></td><td>HTTP method (GET, POST...)</td></tr><tr><td><code>path</code></td><td><code>string</code></td><td>Endpoint path</td></tr><tr><td><code>handler</code></td><td><code>func(username string, body []byte) (int, []byte)</code></td><td>Handler</td></tr></tbody></table>

**Handler parameters:**

* `username` — authenticated username
* `body` — request body

**Handler returns:**

* `int` — HTTP status code
* `[]byte` — response body

***

### TsEndpointUnregister

Unregisters an endpoint.

```go
TsEndpointUnregister(method string, path string) error
```

***

### TsEndpointExists

Checks whether an endpoint exists.

```go
TsEndpointExists(method string, path string) bool
```

***

### TsEndpointRegisterPublic

Registers a public endpoint (no authentication).

```go
TsEndpointRegisterPublic(method string, path string, handler func(body []byte) (int, []byte)) error
```

<table><thead><tr><th width="123">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>method</code></td><td><code>string</code></td><td>HTTP method (GET, POST...)</td></tr><tr><td><code>path</code></td><td><code>string</code></td><td>Endpoint path</td></tr><tr><td><code>handler</code></td><td><code>func(body []byte) (int, []byte)</code></td><td>Handler</td></tr></tbody></table>

***

### TsEndpointUnregisterPublic

Unregisters a public endpoint.

```go
TsEndpointUnregisterPublic(method string, path string) error
```

***

### TsEndpointExistsPublic

Checks whether a public endpoint exists.

```go
TsEndpointExistsPublic(method string, path string) bool
```

***

## Utility Functions

### TsConvertCpToUTF8

Converts a string from a code page to UTF-8.

```go
TsConvertCpToUTF8(input string, codePage int) string
```

**Supported code pages:**

* 866 (Russian DOS)
* 1251 (Cyrillic Windows)
* 1252 (Western European Windows)
* 936 (Chinese GBK)
* 65001 (UTF-8)
* and many others...

***

### TsConvertUTF8toCp

Converts UTF-8 to the agent's code page.

```go
TsConvertUTF8toCp(input string, codePage int) string
```

***

### TsWin32Error

Returns a description of a Windows error code.

```go
TsWin32Error(errorCode uint) string
```

***

## Data Types

### adaptix.AgentData

```go
type AgentData struct {
    Crc          string   // CRC/watermark of the agent type
    Id           string   // Unique agent ID
    Name         string   // Agent type name
    SessionKey   []byte   // Session key for encryption
    Listener     string   // Listener name
    Async        bool     // Asynchronous mode
    ExternalIP   string   // External IP address
    InternalIP   string   // Internal IP address
    GmtOffset    int      // Time zone offset
    Sleep        uint     // Sleep interval (seconds)
    Jitter       uint     // Jitter (percentage)
    Pid          string   // Process ID
    Tid          string   // Thread ID
    Arch         string   // Architecture (x86, x64)
    Elevated     bool     // Elevated privileges
    Process      string   // Process name
    Os           int      // OS type (0=Windows, 1=Linux, 2=macOS)
    OsDesc       string   // OS description
    Domain       string   // Domain
    Computer     string   // Computer name
    Username     string   // Username
    Impersonated string   // Impersonated user
    OemCP        int      // OEM code page
    ACP          int      // ANSI code page
    CreateTime   int64    // Creation time (Unix timestamp)
    LastTick     int      // Last tick
    KillDate     int      // Kill date
    WorkingTime  int      // Working time
    Tags         string   // Tags
    Mark         string   // Mark (Inactive, Terminated, etc.)
    Color        string   // Color in GUI
    TargetId     string   // ID of the associated target
}
```

***

### adaptix.TaskData

```go
type TaskData struct {
    Type        int      // Type: TASK_TYPE_TASK=1, TASK_TYPE_BROWSER=2, TASK_TYPE_JOB=3, TASK_TYPE_TUNNEL=4
    TaskId      string   // Unique task ID
    AgentId     string   // Agent ID
    Client      string   // Client (operator) name
    HookId      string   // Hook ID for callback
    HandlerId   string   // Handler ID for callback
    User        string   // User on the target machine
    Computer    string   // Computer name
    StartDate   int64    // Start time
    FinishDate  int64    // Finish time
    Data        []byte   // Task binary data
    CommandLine string   // Command line
    MessageType int      // Message type: INFO=5, ERROR=6, SUCCESS=7
    Message     string   // Message title
    ClearText   string   // Message text
    Completed   bool     // Completion flag
    Sync        bool     // Synchronize with GUI
}
```

***

### adaptix.ListenerData

```go
type ListenerData struct {
    Name       string   // Unique listener name
    RegName    string   // Registered type
    Protocol   string   // Protocol
    Type       string   // Listener type
    BindHost   string   // Bind address
    BindPort   string   // Bind port
    AgentAddr  string   // Address for the agent
    CreateTime int64    // Creation date
    Status     string   // Status (running, stopped, paused)
    Data       string   // Additional data (JSON)
    Watermark  string   // Watermark
}
```

***

### adaptix.DownloadData

```go
type DownloadData struct {
    FileId     string   // Unique file ID
    AgentId    string   // Agent ID
    AgentName  string   // Agent type name
    User       string   // User
    Computer   string   // Computer
    RemotePath string   // Path on the target machine
    LocalPath  string   // Local path on the server
    TotalSize  int      // Total file size
    RecvSize   int      // Received size
    Date       int64    // Start date
    State      int      // State: RUNNING=1, STOPPED=2, FINISHED=3, CANCELED=4
}
```

***

### adaptix.TunnelData

```go
type TunnelData struct {
    TunnelId  string   // Unique tunnel ID
    AgentId   string   // Agent ID
    Computer  string   // Computer
    Username  string   // User
    Process   string   // Process
    Type      string   // Type (socks4, socks5, lportfwd, rportfwd)
    Info      string   // Additional information
    Interface string   // Bind interface
    Port      string   // Port
    Client    string   // Client that created the tunnel
    Fhost     string   // Forward host
    Fport     string   // Forward port
    AuthUser  string   // Authentication user
    AuthPass  string   // Authentication password
}
```

***

### adaptix.PivotData

```go
type PivotData struct {
    PivotId       string   // Unique pivot ID
    PivotName     string   // Pivot name
    ParentAgentId string   // Parent agent ID
    ChildAgentId  string   // Child agent ID
}
```

***

### adaptix.CredsData

```go
type CredsData struct {
    CredId   string   // Unique ID
    Username string   // Username
    Password string   // Password or hash
    Realm    string   // Domain/realm
    Type     string   // Type (NTLM, Plaintext, Kerberos)
    Tag      string   // Tag
    Date     int64    // Date added
    Storage  string   // Source (LSASS, SAM, DCSync)
    AgentId  string   // Agent ID (source)
    Host     string   // Host (source)
}
```

***

### adaptix.TargetData

```go
type TargetData struct {
    TargetId string     // Unique target ID
    Computer string     // Computer name
    Domain   string     // Domain
    Address  string     // IP address
    Os       int        // OS type
    OsDesk   string     // OS description
    Tag      string     // Tag
    Info     string     // Additional information
    Date     int64      // Date added
    Alive    bool       // Active
    Agents   []string   // List of agent IDs
}
```

***

### Constants

```go
// Task types
const (
    TASK_TYPE_TASK    = 1   // Regular task
    TASK_TYPE_BROWSER = 2   // File/Process Browser
    TASK_TYPE_JOB     = 3   // Background job
    TASK_TYPE_TUNNEL  = 4   // Tunnel
)

// Console message types
const (
    CONSOLE_OUT_LOCAL         = 1
    CONSOLE_OUT_LOCAL_INFO    = 2
    CONSOLE_OUT_LOCAL_ERROR   = 3
    CONSOLE_OUT_LOCAL_SUCCESS = 4
    CONSOLE_OUT_INFO          = 5   // INFO
    CONSOLE_OUT_ERROR         = 6   // ERROR
    CONSOLE_OUT_SUCCESS       = 7   // SUCCESS
    CONSOLE_OUT               = 10
)

// Download states
const (
    DOWNLOAD_STATE_RUNNING  = 1
    DOWNLOAD_STATE_STOPPED  = 2
    DOWNLOAD_STATE_FINISHED = 3
    DOWNLOAD_STATE_CANCELED = 4
)
```
