> 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/axscript/axmenu-type.md).

# AxMenu type

AxScripts can also complement the AdaptixClient menu structure. The `menu` namespace allows you to create a menu structure with actions and separators.

## AxItem

`AxItem create_menu(string text, string icon = "")` - Create a submenu. `addItem` puts an action, another submenu, or a separator inside it. `setIcon(string resourcePath)` sets the icon.

`AxItem create_separator()` - Create a separator.

`AxItem create_action(string text, handler(){}, string icon = "")` - Creates an action that `handler` runs when the item is selected. `setIcon(string resourcePath)` sets the icon after creation.

Menu items are shown by the client. On the teamserver every `menu.*` call is a no-op.

```javascript
void menu.add_MENU_TYPE(AxItem item, string[] agents, string[] os = [], string[] listeners = []);
```

* `item` - AxItem object
* `agents` - a non-empty array of agent type names, such as `"beacon"` or `"gopher"`. An empty array is ignored and the item is not registered. Targets, credentials, and the payload store do not take this argument.
* `os` - `"windows"`, `"linux"`, `"macos"`. An empty array shows the item on every operating system.
* `listeners` - listener type names, such as `"BeaconHTTP"` or `"BeaconSMB"`. An empty array shows the item for every listener.

***

## Sessions Table and Graph menu

* `menu.add_session_main` - Adds `item` to the context menu after the *Access* item.
* `menu.add_session_agent` - Adds an `item` as a submenu to the *Agent* menu.
* `menu.add_session_browser` - Adds an `item` as a submenu to the *Browsers* menu.
* `menu.add_session_access` - Adds an `item` as a submenu to the *Access* menu.

For these context menu items, the action must have a `handler` in the following format.

```javascript
function handler(int[] ids)
```

* `ids` - array of selected agent ids

**Example**

This code adds a *Process Browser* action to the *Browser* menu, which opens Process Browser for all selected sessions.

```javascript
let process_browser_action = menu.create_action("Process Browser", function(value) { value.forEach(v => ax.open_browser_process(v)) });
menu.add_session_browser(process_browser_action, ["beacon"])
```

***

## File Browser menu

* `menu.add_filebrowser` - Adds `item` to the context menu

For these context menu items, the action must have a `handler` in the following format.

```javascript
function handler(FILE_INFO[] files)
```

* `files` - array of selected files

```javascript
// FILE_INFO STRUCTURE:
int    file["agent_id"]    // agent ID
string file["path"]        // file directory
string file["name"]        // filename
string file["type"]        // type: "file" or "dir"
```

**Example**

This code adds a *Download* action to the File Browser context menu, which executes a command to download a file.

```javascript
let download_action = menu.create_action("Download", function(files_list) {
    files_list.forEach((file) => {
        if(file.type == "file") {
            ax.execute_command(file.agent_id, "download " + file.path + file.name);
        }
    });
});
menu.add_filebrowser(download_action, ["beacon"])
```

***

## Process Browser menu

* `menu.add_processbrowser` - Adds `item` to the context menu

For these context menu items, the action must have a `handler` in the following format.

```javascript
function handler(PROC_INFO[] processes)
```

* `processes` - array of selected processes

```javascript
// PROC_INFO STRUCTURE:
int    proc["agent_id"]      // agent ID
string proc["pid"]
string proc["ppid"] 
string proc["arch"]          // if unix, then empty
string proc["session_id"]    // if unix, then TTY
string proc["context"]
string proc["process"]
```

**Example**

This code adds a "*Steal Token*" action to the Process Browser context menu that performs the `token steal` BOF.

```javascript
let token_steal_action = menu.create_action("Steal token", function(process_list) {
    if (process_list.length > 0 ) {
        let proc = process_list[0];
        ax.execute_command(proc.agent_id, "token steal " + proc.pid);
    }
});
menu.add_processbrowser(token_steal_action, ["beacon", "gopher"], ["windows"]);
```

***

## Downloads Table menu

* `menu.add_downloads_running` - Adds an `item` to the context menu if the file is in the download stage.
* `menu.add_downloads_finished` - Adds an `item` to the context menu if the file is already downloaded.

For these context menu items, the action must have a `handler` in the following format.

```javascript
function handler(DOWNLOAD[] files)
```

* `files` - array of selected downloads

```javascript
// DOWNLOAD STRUCTURE:
int    file["agent_id"]
int    file["file_id"]
string file["path"]
string file["state"]          // "running", "stopped", or "finished"
```

**Example**

This code adds the actions *Pause, Resume*, *Cancel* and a `separator` to the context menu of the Downloads Table.

```javascript
let download_stop_action = menu.create_action("Pause", function(files_list) { files_list.forEach( file => ax.execute_command(file.agent_id, "exfil stop " + file.file_id) ) });
let download_start_action = menu.create_action("Resume", function(files_list) { files_list.forEach( file => ax.execute_command(file.agent_id, "exfil start " + file.file_id) ) });
let download_separator1 = menu.create_separator()
let download_cancel_action = menu.create_action("Cancel", function(files_list) { files_list.forEach( file => ax.execute_command(file.agent_id, "exfil cancel " + file.file_id) ) });
menu.add_downloads_running(download_stop_action, ["beacon"])
menu.add_downloads_running(download_start_action, ["beacon"])
menu.add_downloads_running(download_separator1, ["beacon"])
menu.add_downloads_running(download_cancel_action, ["beacon"])
```

***

## Task Manager menu

* `menu.add_tasks` - Adds an `item` to the context menu for all tasks.
* `menu.add_tasks_job` - Adds an `item` to the context menu if the task is of type JOB and is in the running state.

For these context menu items, the action must have a `handler` in the following format.

```javascript
function handler(TASK[] tasks)
```

* `tasks` - array of selected tasks

```javascript
// TASK STRUCTURE:
int    task["agent_id"]
int    task["task_id"]
string task["state"]         // "", "Running", "Success", "Error", or "Canceled". An empty state is a task that has not been sent yet.
string task["type"]          // "TASK", "JOB", "TUNNEL", or "unknown"
```

**Example**

This code adds the action *Stop job* to the context menu of the Tasks Manager.

```javascript
let job_stop_action = menu.create_action("Stop job", function(tasks_list) {
    tasks_list.forEach((task) => {
        if(task.type == "JOB" && task.state == "Running") {
            ax.execute_command(task.agent_id, "jobs kill " + task.task_id);
        }
    });
});
menu.add_tasks_job(job_stop_action, ["beacon"])
```

***

## Targets Manager menu

Adds an `item` to a specific `position` (top, center, bottom) in the context menu for all targets.

```javascript
void menu.add_targets(AxItem item, string pos = "center");
```

`pos` is `"top"`, `"center"`, or `"bottom"`. Any other value is treated as `"center"`.

For these context menu items, the action must have a `handler` in the following format.

```javascript
function handler(string[] ids)
```

* `ids` - list of selected targets ids

**Example**

This code adds the action *Stop job* to the context menu of the Tasks Manager.

```javascript
let t_action = menu.create_action("Jump to ...", function(targets_id) {
   let targets = ax.targets()
   targets_id.forEach((id) => {
       let addr = targets[id].address;
       ax.show_message("Target", addr);
   });
});
menu.add_targets(t_action, "top");
```

***

## Credentials Manager menu

Adds an `item` to the context menu for all creds.

```javascript
void menu.add_credentials(AxItem item);
```

For these context menu items, the action must have a `handler` in the following format.

```javascript
function handler(string[] ids)
```

* `ids` - list of selected creds ids

**Example**

This code adds the action *Stop job* to the context menu of the Tasks Manager.

```javascript
let c_action = menu.create_action("Jump to ...", function(creds_id) {
   let creds = ax.credentials()
   creds_id.forEach((id) => {
       let passwd = creds[id].password;
       ax.show_message("Password", passwd);
   });
});
menu.add_credentials(c_action);
```

***

## Payload Store menu

Adds an item to the context menu of the payload store.

```javascript
void menu.add_payload_store(AxItem item);
```

```javascript
function handler(int[] ids)
```

* `ids` - selected payload ids

***
