Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Alt Command Toggle #2790

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/objects/secondclass/c_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ class ExecutorSchema(ma.Schema):
name = ma.fields.String(missing=None)
platform = ma.fields.String(missing=None)
command = ma.fields.String(missing=None)
alt_command = ma.fields.String(missing=None)
code = ma.fields.String(missing=None)
language = ma.fields.String(missing=None)
build_target = ma.fields.String(missing=None)
labels = ma.fields.List(ma.fields.String())
payloads = ma.fields.List(ma.fields.String())
uploads = ma.fields.List(ma.fields.String())
timeout = ma.fields.Int(missing=60)
Expand Down Expand Up @@ -46,16 +48,20 @@ def test(self):

def __init__(self, name, platform, command=None, code=None, language=None, build_target=None,
payloads=None, uploads=None, timeout=60, parsers=None, cleanup=None, variations=None,
additional_info=None, **kwargs):
additional_info=None, alt_command=None, labels=None, **kwargs):
super().__init__()
self.name = name
self.platform = platform.lower()

self.command = command
self.alt_command = alt_command
self.code = code
self.language = language
self.build_target = build_target

self.labels = labels if labels else ["Command1", "Command2"]
if len(self.labels) < 2:
self.labels.append("Command2")
self.payloads = payloads if payloads else []
self.uploads = uploads if uploads else []

Expand Down
8 changes: 3 additions & 5 deletions app/service/data_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ async def load_ability_file(self, filename, access):
ab.pop('access', None)
plugin = self._get_plugin_name(filename)
ab.pop('plugin', plugin)

if tactic and tactic not in filename:
self.log.error('Ability=%s has wrong tactic' % ability_id)

await self._create_ability(ability_id=ability_id, name=name, description=description, tactic=tactic,
technique_id=technique_id, technique_name=technique_name,
executors=executors, requirements=requirements, privilege=privilege,
Expand Down Expand Up @@ -207,10 +205,9 @@ async def load_executors_from_platform_dict(self, platforms):
executors = []
for platform_names, platform_executors in platforms.items():
for executor_names, executor in platform_executors.items():

command = executor['command'].strip() if executor.get('command') else None
alt_command = executor['alt_command'].strip() if executor.get('alt_command') else None
cleanup = executor['cleanup'].strip() if executor.get('cleanup') else None

code = executor['code'].strip() if executor.get('code') else None
if code:
_, code_path = await self.get_service('file_svc').find_file_path(code)
Expand All @@ -221,6 +218,7 @@ async def load_executors_from_platform_dict(self, platforms):
language = executor.get('language')
build_target = executor.get('build_target')
payloads = executor.get('payloads')
labels = executor.get('labels')
uploads = executor.get('uploads')
timeout = executor.get('timeout', 60)
variations = executor.get('variations', [])
Expand All @@ -232,7 +230,7 @@ async def load_executors_from_platform_dict(self, platforms):
executors.append(Executor(name=executor_name, platform=platform_name, command=command,
code=code, language=language, build_target=build_target,
payloads=payloads, uploads=uploads, timeout=timeout,
parsers=parsers, cleanup=cleanup, variations=variations))
parsers=parsers, cleanup=cleanup, variations=variations, alt_command=alt_command, labels=labels))
return executors

async def load_executors_from_list(self, executors: list):
Expand Down
64 changes: 59 additions & 5 deletions templates/operations.html
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,11 @@ <h2>Operations</h2>
</tr>
<tr>
<td>
<label class="label">altcommand</label>
</td>
</tr>
<tr>
<td>selectedOperation.autonomous
<label class="label">Parser</label>
</td>
<td>
Expand Down Expand Up @@ -997,11 +1002,30 @@ <h2>Operations</h2>
</template>
<em x-show="showNotRepeatableText" class="has-text-grey-light is-pulled-right is-size-7">Note: Repeated links are not available for this operation</em>
</section>
<section class="modal-card-body " x-show="selectedPotentialLink.ability_id">
<section class="modal-card-body " x-show="selectedPotentialLink.ability_id">
<strong x-text="selectedPotentialLink.name" class="mb-2 is-size-4"></strong>
<span x-text="`(${selectedPotentialLink.technique_id})`"></span>
<p x-text="selectedPotentialLink.description" style="white-space: pre-line;"></p>
<hr>
<div class="toggleContainer flex is-flex-direction-column is-align-items-left">

<div id="altcommandToggle" style="display:none;">
<label id="command_label" for="toggleAltcommand">Command1</label>
<div class="toggleSwitch mx-2" >
<input type="checkbox"
id="altcommandToggle"
x-model="selectedCommand"
x-bind:checked="Boolean(selectedCommand) ? 'checked' : null"/>
<span class="toggleSlider toggleSliderRound"
title="Toggle chosen command for this ability"
x-on:click="switchAltcommand();"
x-bind:class="Boolean(selectedCommand) ? 'toggle-on' : 'toggle-off'">
<span x-bind:class="Boolean(selectedCommand) ? 'toggle-slider-on' : 'toggle-slider-off'"></span>
</span>
</div>
<label id="alt_command_label" for="toggleAltcommand">Command2</label>
</div>
</div>
<p class="has-text-centered has-text-weight-bold">Fact Templates</p>
<p class="help" x-show="Object.keys(selectedPotentialLinkFacts).length">
This link needs facts in order to run properly. Select one value for each fact to add one potential link, otherwise, select multiple
Expand Down Expand Up @@ -1238,6 +1262,7 @@ <h2>Operations</h2>
agentGroups: [],
selectedOperationID: '',
selectedOperation: null,
selectedCommand: 0,
selectedAgentIndex: 0,
isSelectedAdversaryRepeatable: false,
selectedLink: null,
Expand All @@ -1260,12 +1285,13 @@ <h2>Operations</h2>
operations: [],
operationToStart: {},

selectedPotentialLink: {},
selectedPotentialLink: {"alt_command":0},
selectedPotentialLinkFacts: {},
potentialLinksToAdd: [],
potentialLinkSearchQuery: '',
isAddingBlankPotentialLink: false,
potentialLinkCommand: '',
otherPotentialLinkCommand: '',
potentialLink: {
agent: '',
executor: '',
Expand Down Expand Up @@ -1619,13 +1645,31 @@ <h2>Operations</h2>
this.selectedPotentialLinkFacts = {};
this.setPotentialLinksToAdd();
if (!this.selectedPotentialLink.ability_id) return;

const executor = link.executors.find((e) => this.potentialLink.executor === e.name);
const fields = [...new Set([...executor.command.matchAll(/#{(.*?)}/gm)].map((field) => field[1]))];
//alt_command support
if (executor.alt_command)
{
document.getElementById("altcommandToggle").style.display="block";
document.getElementById("command_label").innerHTML = executor.labels[0];
document.getElementById("alt_command_label").innerHTML = executor.labels[1];
if (this.potentialLinkCommand != executor.command) {
this.selectedCommand = 0;
var chosen_command = executor.command;
}
else {
this.selectedCommand = 1;
var chosen_command = executor.alt_command;
}
}
else {
document.getElementById("altcommandToggle").style.display="none";
var chosen_command = executor.command;
}
const fields = [...new Set([...chosen_command.matchAll(/#{(.*?)}/gm)].map((field) => field[1]))];
const opSource = this.SOURCES.find((s) => s.id === this.selectedOperation.source.id);
const opSourceCollected = this.SOURCES.find((source) => source.name === this.selectedOperation.name);
const facts = (opSource.facts.concat(opSourceCollected ? opSourceCollected.facts : [])).concat(this.facts);
this.potentialLinkCommand = executor.command;
this.potentialLinkCommand = chosen_command;

fields.filter((field) => facts.find((fact) => fact.name === field)).forEach((field) => {
this.selectedPotentialLinkFacts[field] = []
Expand Down Expand Up @@ -1884,6 +1928,16 @@ <h2>Operations</h2>
return matchAgent && matchTactic && matchTechnique && matchQuery;
});
},

//
// Altcommand Support
//
switchAltcommand() {
// Return the other ability
//this.selectedPotentialLink.o
this.selectPotentialLink(this.selectedPotentialLink);

}
};
}
</script>
Expand Down