pivoting.ts•6.43 kB
/**
* Pivoting and network operation-related MCP tools (SOCKS, port forwarding, linking)
*/
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { CobaltStrikeClient } from '../api/client.js';
export function createPivotingTools(client: CobaltStrikeClient): Tool[] {
return [
{
name: 'execute_socks4_start',
description: 'Start SOCKS4 proxy',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
port: {
type: 'number',
description: 'Local port for SOCKS4 proxy',
minimum: 1,
maximum: 65535,
},
},
required: ['beaconId', 'port'],
},
},
{
name: 'execute_socks5_start',
description: 'Start SOCKS5 proxy',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
port: {
type: 'number',
description: 'Local port for SOCKS5 proxy',
minimum: 1,
maximum: 65535,
},
},
required: ['beaconId', 'port'],
},
},
{
name: 'execute_socks_stop',
description: 'Stop SOCKS proxy',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
},
required: ['beaconId'],
},
},
{
name: 'execute_link_smb',
description: 'Link to SMB beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
target: {
type: 'string',
description: 'Target hostname or IP',
},
pipe: {
type: 'string',
description: 'Named pipe name (optional)',
},
},
required: ['beaconId', 'target'],
},
},
{
name: 'execute_link_tcp',
description: 'Link to TCP beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
target: {
type: 'string',
description: 'Target hostname or IP',
},
port: {
type: 'number',
description: 'Port number',
minimum: 1,
maximum: 65535,
},
},
required: ['beaconId', 'target', 'port'],
},
},
{
name: 'execute_unlink',
description: 'Unlink from beacon',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
},
required: ['beaconId'],
},
},
{
name: 'execute_rportfwd_start',
description: 'Start reverse port forward',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
bindPort: {
type: 'number',
description: 'Local port to bind',
minimum: 1,
maximum: 65535,
},
forwardHost: {
type: 'string',
description: 'Host to forward to',
},
forwardPort: {
type: 'number',
description: 'Port to forward to',
minimum: 1,
maximum: 65535,
},
},
required: ['beaconId', 'bindPort', 'forwardHost', 'forwardPort'],
},
},
{
name: 'execute_rportfwd_stop',
description: 'Stop reverse port forward',
inputSchema: {
type: 'object',
properties: {
beaconId: {
type: 'string',
description: 'The ID of the beacon',
},
bindPort: {
type: 'number',
description: 'Local port to stop',
minimum: 1,
maximum: 65535,
},
},
required: ['beaconId', 'bindPort'],
},
},
];
}
export async function handlePivotingTool(
name: string,
args: any,
client: CobaltStrikeClient
): Promise<string> {
switch (name) {
case 'execute_socks4_start':
const socks4Result = await client.executeSOCKS4Start(args.beaconId, args.port);
return JSON.stringify({ taskId: socks4Result, message: 'SOCKS4 proxy started' }, null, 2);
case 'execute_socks5_start':
const socks5Result = await client.executeSOCKS5Start(args.beaconId, args.port);
return JSON.stringify({ taskId: socks5Result, message: 'SOCKS5 proxy started' }, null, 2);
case 'execute_socks_stop':
const socksStopResult = await client.executeSOCKSStop(args.beaconId);
return JSON.stringify({ taskId: socksStopResult, message: 'SOCKS proxy stopped' }, null, 2);
case 'execute_link_smb':
const linkSmbResult = await client.executeLinkSMB(args.beaconId, args.target, args.pipe);
return JSON.stringify({ taskId: linkSmbResult, message: 'SMB link command submitted' }, null, 2);
case 'execute_link_tcp':
const linkTcpResult = await client.executeLinkTCP(args.beaconId, args.target, args.port);
return JSON.stringify({ taskId: linkTcpResult, message: 'TCP link command submitted' }, null, 2);
case 'execute_unlink':
const unlinkResult = await client.executeUnlink(args.beaconId);
return JSON.stringify({ taskId: unlinkResult, message: 'Unlink command submitted' }, null, 2);
case 'execute_rportfwd_start':
const rportfwdStartResult = await client.executeRPortFwdStart(args.beaconId, args.bindPort, args.forwardHost, args.forwardPort);
return JSON.stringify({ taskId: rportfwdStartResult, message: 'Reverse port forward started' }, null, 2);
case 'execute_rportfwd_stop':
const rportfwdStopResult = await client.executeRPortFwdStop(args.beaconId, args.bindPort);
return JSON.stringify({ taskId: rportfwdStopResult, message: 'Reverse port forward stopped' }, null, 2);
default:
throw new Error(`Unknown pivoting tool: ${name}`);
}
}