mirror of https://github.com/MISP/MISP
add: [stix2 import] Added `distribution` to the `upload_stix` form so we can pass its value to `misp-stix`
parent
6bb0168860
commit
334ddbc533
|
@ -2376,11 +2376,24 @@ class EventsController extends AppController
|
|||
|
||||
public function upload_stix($stix_version = '1', $publish = false, $galaxies_as_tags = true, $debug = false)
|
||||
{
|
||||
$sgs = $this->Event->SharingGroup->fetchAllAuthorised($this->Auth->user(), 'name', 1);
|
||||
$initialDistribution = 0;
|
||||
if (Configure::read('MISP.default_event_distribution') != null) {
|
||||
$initialDistribution = Configure::read('MISP.default_event_distribution');
|
||||
}
|
||||
$distributionLevels = $this->Event->distributionLevels;
|
||||
if ($this->request->is('post')) {
|
||||
if ($this->_isRest()) {
|
||||
if (isset($this->params['named']['publish'])) {
|
||||
$publish = $this->params['named']['publish'];
|
||||
}
|
||||
if (isset($this->params['named']['distribution'])) {
|
||||
if (in_array($this->params['named']['distribution'], $distributionLevels)) {
|
||||
$initialDistribution = $this->params['named']['distribution'];
|
||||
} else {
|
||||
throw new MethodNotAllowedException(__('Wrong distribution level'));
|
||||
}
|
||||
}
|
||||
if (isset($this->params['named']['galaxies_as_tags'])) {
|
||||
$galaxies_as_tags = $this->params['named']['galaxies_as_tags'];
|
||||
}
|
||||
|
@ -2394,6 +2407,7 @@ class EventsController extends AppController
|
|||
$stix_version,
|
||||
'uploaded_stix_file.' . ($stix_version == '1' ? 'xml' : 'json'),
|
||||
$publish,
|
||||
$initialDistribution,
|
||||
$galaxies_as_tags,
|
||||
$debug
|
||||
);
|
||||
|
@ -2423,6 +2437,7 @@ class EventsController extends AppController
|
|||
$stix_version,
|
||||
$original_file,
|
||||
$this->data['Event']['publish'],
|
||||
$this->data['Event']['distribution'],
|
||||
!boolval($this->data['Event']['galaxies_parsing']),
|
||||
$debug
|
||||
);
|
||||
|
@ -2442,6 +2457,20 @@ class EventsController extends AppController
|
|||
}
|
||||
}
|
||||
$this->set('stix_version', $stix_version == 2 ? '2.x JSON' : '1.x XML');
|
||||
$this->set('initialDistribution', $initialDistribution);
|
||||
$distributions = array_keys($this->Event->distributionDescriptions);
|
||||
$distributions = $this->_arrayToValuesIndexArray($distributions);
|
||||
$this->set('distributions', $distributions);
|
||||
$fieldDesc = array();
|
||||
if (empty($sgs)) {
|
||||
unset($distributionLevels[4]);
|
||||
}
|
||||
$this->set('distributionLevels', $distributionLevels);
|
||||
foreach ($distributionLevels as $key => $value) {
|
||||
$fieldDesc['distribution'][$key] = $this->Event->distributionDescriptions[$key]['formdesc'];
|
||||
}
|
||||
$this->set('sharingGroups', $sgs);
|
||||
$this->set('fieldDesc', $fieldDesc);
|
||||
}
|
||||
|
||||
public function merge($target_id=null, $source_id=null)
|
||||
|
|
|
@ -11,6 +11,34 @@
|
|||
));
|
||||
?>
|
||||
<div class="input clear"></div>
|
||||
<?php
|
||||
$distributionFormInfo = $this->element(
|
||||
'genericElements/Form/formInfo',
|
||||
[
|
||||
'field' => [
|
||||
'field' => 'distribution'
|
||||
],
|
||||
'modelForForm' => 'Event',
|
||||
'fieldDesc' => $fieldDesc['distribution'],
|
||||
]
|
||||
);
|
||||
echo $this->Form->input('distribution', array(
|
||||
'options' => $distributionLevels,
|
||||
'label' => __('Distribution ') . $distributionFormInfo,
|
||||
'selected' => $initialDistribution,
|
||||
));
|
||||
?>
|
||||
<div id="SGContainer" style="display:none;">
|
||||
<?php
|
||||
if (!empty($sharingGroups)) {
|
||||
echo $this->Form->input('sharing_group_id', array(
|
||||
'options' => array($sharingGroups),
|
||||
'label' => __('Sharing Group'),
|
||||
));
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="input clear"></div>
|
||||
<?php
|
||||
echo $this->Form->input('publish', array(
|
||||
'checked' => false,
|
||||
|
|
|
@ -41,7 +41,9 @@ def _process_stix_file(args: argparse.ArgumentParser):
|
|||
)
|
||||
stix_version = getattr(bundle, 'version', '2.1')
|
||||
to_call = 'Internal' if _from_misp(bundle.objects) else 'External'
|
||||
parser = globals()[f'{to_call}STIX2toMISPParser'](args.galaxies_as_tags)
|
||||
parser = globals()[f'{to_call}STIX2toMISPParser'](
|
||||
args.distribution, args.galaxies_as_tags
|
||||
)
|
||||
parser.load_stix_bundle(bundle)
|
||||
parser.parse_stix_bundle()
|
||||
with open(f'{args.input}.out', 'wt', encoding='utf-8') as f:
|
||||
|
@ -71,9 +73,22 @@ def _process_stix_file(args: argparse.ArgumentParser):
|
|||
|
||||
if __name__ == '__main__':
|
||||
argparser = argparse.ArgumentParser(description='Import STIX 2 content to MISP.')
|
||||
argparser.add_argument('-i', '--input', required=True, type=Path, help='Input file containing STIX 2 content.')
|
||||
argparser.add_argument('-d', '--debug', action='store_true', help='Display error and warning messages.')
|
||||
argparser.add_argument('--galaxies_as_tags', action='store_true', help='Import MISP Galaxies as tag names.')
|
||||
argparser.add_argument(
|
||||
'-i', '--input', required=True, type=Path,
|
||||
help='Input file containing STIX 2 content.'
|
||||
)
|
||||
argparser.add_argument(
|
||||
'--distribution', type=int, default=0,
|
||||
help='Distribution level for the resulting MISP Event.'
|
||||
)
|
||||
argparser.add_argument(
|
||||
'--debug', action='store_true',
|
||||
help='Display error and warning messages.'
|
||||
)
|
||||
argparser.add_argument(
|
||||
'--galaxies_as_tags', action='store_true',
|
||||
help='Import MISP Galaxies as tag names.'
|
||||
)
|
||||
try:
|
||||
args = argparser.parse_args()
|
||||
_process_stix_file(args)
|
||||
|
|
Loading…
Reference in New Issue