> 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)` - Create a submenu item in the context menu. This item can contain a submenu, an action, or a separator.

`AxItem create_separator()` - Create a separator.

`AxItem create_action(string text, handler(){})` - Creates an action that the `handler` will execute when this menu item is selected.

To add an `AxItem` object to any use the function.

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

* `item` - AxItem object
* `agents` - an array of strings containing the names of agents for which the menu item will be displayed. Available options are "beacon", "gopher", etc.
* `os` - an array of strings with the names of the operating systems for which the menu item will be displayed. The following options are available: "windows", "linux", "macos". If an empty array `[]` is specified, the command group will be registered for all operating systems.
* `listeners` - An array of strings with the names of registered listeners for which the menu item will be displayed. The following options are available: "BeaconHTTP", "BeaconSMB", etc. If an empty array \[] is specified, the command group will be registered for all listeners.

***

## Main Menu

* `menu.add_main` - Add `menu` to the *Main* menu.
* `menu.add_main_project` - Add `item` to the *Main* menu Projects.
* `menu.add_main_axscript` - Add `item` to the *Main* menu Ax Script.
* `menu.add_main_settings` - Add `item` to the *Main* menu Settings.

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

```javascript
function handler()
```

**Example**

This code adds a *Sub 1* action to the *Main* menu Projects, which show message.

```javascript
let act = menu.create_action("Sub 1", function() {
       ax.show_message("TEST", "New project submenu");
});
menu.add_main_projects(act);
```

***

## 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(string[] 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:
string 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:
string 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:
string file["agent_id"]
string file["file_id"]
string file["path"]
string file["state"]          // "finished", "running" or "stopped"
```

**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:
string file["agent_id"]
string file["task_id"]
string file["state"]         // "Hosted", "Running", "Success", "Error" or "Canceled"
string file["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(menu_item* item, string pos);
```

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&#x20;

**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_targets(menu_item* 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&#x20;

**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);
```

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://adaptix-framework.gitbook.io/adaptix-framework/development/axscript/axmenu-type.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
