files.ts•7.89 kB
/**
* File operation-related MCP tools
*/
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { CobaltStrikeClient } from '../api/client.js';
export function createFileTools(client: CobaltStrikeClient): Tool[] {
return [
{
name: 'beacon_list_directory',
description: 'List directory contents on a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
path: {
type: 'string',
description: 'Directory path to list (optional, defaults to current directory)',
},
},
required: ['beaconId'],
},
},
{
name: 'beacon_change_directory',
description: 'Change current directory on a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
path: {
type: 'string',
description: 'Directory path to change to',
},
},
required: ['beaconId', 'path'],
},
},
{
name: 'beacon_get_current_directory',
description: 'Get current working directory on a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
},
required: ['beaconId'],
},
},
{
name: 'beacon_list_drives',
description: 'List available drives on a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
},
required: ['beaconId'],
},
},
{
name: 'beacon_upload_file',
description: 'Upload a file to a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
localPath: {
type: 'string',
description: 'Local file path to upload',
},
remotePath: {
type: 'string',
description: 'Remote path where file should be saved',
},
},
required: ['beaconId', 'localPath', 'remotePath'],
},
},
{
name: 'beacon_download_file',
description: 'Download a file from a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
remotePath: {
type: 'string',
description: 'Remote file path to download',
},
},
required: ['beaconId', 'remotePath'],
},
},
{
name: 'beacon_copy_file',
description: 'Copy a file on a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
source: {
type: 'string',
description: 'Source file path',
},
destination: {
type: 'string',
description: 'Destination file path',
},
},
required: ['beaconId', 'source', 'destination'],
},
},
{
name: 'beacon_move_file',
description: 'Move/rename a file on a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
source: {
type: 'string',
description: 'Source file path',
},
destination: {
type: 'string',
description: 'Destination file path',
},
},
required: ['beaconId', 'source', 'destination'],
},
},
{
name: 'beacon_delete_file',
description: 'Delete a file or directory on a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
path: {
type: 'string',
description: 'File or directory path to delete',
},
},
required: ['beaconId', 'path'],
},
},
{
name: 'beacon_create_directory',
description: 'Create a directory on a beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
path: {
type: 'string',
description: 'Directory path to create',
},
},
required: ['beaconId', 'path'],
},
},
];
}
export async function handleFileTool(
name: string,
args: any,
client: CobaltStrikeClient
): Promise<string> {
switch (name) {
case 'beacon_list_directory':
const listing = await client.executeBeaconCommand(args.beaconId, 'ls', args.path ? [args.path] : undefined);
return JSON.stringify({ taskId: listing, message: 'Directory listing command submitted. Use get_task to retrieve results.' }, null, 2);
case 'beacon_change_directory':
const cdResult = await client.executeBeaconCommand(args.beaconId, 'cd', [args.path]);
return JSON.stringify({ taskId: cdResult, message: 'Change directory command submitted. Use get_task to verify.' }, null, 2);
case 'beacon_get_current_directory':
const pwdResult = await client.executeBeaconCommand(args.beaconId, 'pwd');
return JSON.stringify({ taskId: pwdResult, message: 'Get current directory command submitted. Use get_task to retrieve result.' }, null, 2);
case 'beacon_list_drives':
const drivesResult = await client.executeBeaconCommand(args.beaconId, 'drives');
return JSON.stringify({ taskId: drivesResult, message: 'List drives command submitted. Use get_task to retrieve results.' }, null, 2);
case 'beacon_upload_file':
const uploadResult = await client.uploadFile(args.beaconId, args.localPath, args.remotePath);
return JSON.stringify({ taskId: uploadResult, message: 'File upload initiated' }, null, 2);
case 'beacon_download_file':
const downloadResult = await client.downloadFile(args.beaconId, args.remotePath);
return JSON.stringify({ taskId: downloadResult, message: 'File download initiated' }, null, 2);
case 'beacon_copy_file':
const copyResult = await client.executeBeaconCommand(args.beaconId, 'cp', [args.source, args.destination]);
return JSON.stringify({ taskId: copyResult, message: 'Copy file command submitted. Use get_task to verify completion.' }, null, 2);
case 'beacon_move_file':
const moveResult = await client.executeBeaconCommand(args.beaconId, 'mv', [args.source, args.destination]);
return JSON.stringify({ taskId: moveResult, message: 'Move file command submitted. Use get_task to verify completion.' }, null, 2);
case 'beacon_delete_file':
const deleteResult = await client.executeBeaconCommand(args.beaconId, 'rm', [args.path]);
return JSON.stringify({ taskId: deleteResult, message: 'Delete file command submitted. Use get_task to verify completion.' }, null, 2);
case 'beacon_create_directory':
const mkdirResult = await client.executeBeaconCommand(args.beaconId, 'mkdir', [args.path]);
return JSON.stringify({ taskId: mkdirResult, message: 'Create directory command submitted. Use get_task to verify completion.' }, null, 2);
default:
throw new Error(`Unknown file tool: ${name}`);
}
}