chg: [object] Set fs/ls on all attributes when an object got its fs/ls

sets
pull/4743/head
mokaddem 2019-07-04 13:52:29 +02:00
parent 344f322a7d
commit 59d815b716
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 50 additions and 3 deletions

View File

@ -650,6 +650,7 @@ class ObjectsController extends AppController
throw new MethodNotAllowedException('Invalid input.');
}
}
$seen_changed = false;
foreach ($this->request->data['Object'] as $changedKey => $changedField) {
if (!in_array($changedKey, $validFields)) {
throw new MethodNotAllowedException('Invalid field.');
@ -658,6 +659,7 @@ class ObjectsController extends AppController
$this->autoRender = false;
return $this->RestResponse->saveSuccessResponse('Objects', 'edit', $id, false, 'nochange');
}
$seen_changed = $changedKey == 'first_seen' || $changedKey == 'last_seen';
$object['Object'][$changedKey] = $changedField;
$changed = true;
}
@ -666,7 +668,7 @@ class ObjectsController extends AppController
}
$date = new DateTime();
$object['Object']['timestamp'] = $date->getTimestamp();
$this->MispObject->setObjectSeenMetaFromAttribute($object, true);
$this->MispObject->setObjectSeenMetaFromAttribute($object, false);
if ($this->MispObject->save($object)) {
$event = $this->MispObject->Event->find('first', array(
'recursive' => -1,
@ -676,6 +678,22 @@ class ObjectsController extends AppController
)));
$event['Event']['timestamp'] = $date->getTimestamp();
$event['Event']['published'] = 0;
if ($seen_changed) {
// Set seen of object at attribute level
$attributes = $this->MispObject->find('first', array(
'conditions' => array('id' => $object['Object']['id']),
'contain' => array('Attribute')
))['Attribute'];
foreach ($attributes as $k => $attribute) {
if (is_null($attribute['first_seen']) && !is_null($object['Object']['first_seen'])) {
$attributes[$k]['first_seen'] = $object['Object']['first_seen'];
}
if (is_null($attribute['last_seen']) && !is_null($object['Object']['last_seen'])) {
$attributes[$k]['last_seen'] = $object['Object']['last_seen'];
}
}
$this->MispObject->Attribute->saveAttributes($attributes);
}
$this->MispObject->Event->save($event, array('fieldList' => array('published', 'timestamp', 'info')));
$this->autoRender = false;
return $this->RestResponse->saveSuccessResponse('Objects', 'edit', $id, false, 'Field updated');

View File

@ -239,6 +239,12 @@ class MispObject extends AppModel
$result = $this->id;
foreach ($object['Attribute'] as $k => $attribute) {
$object['Attribute'][$k]['object_id'] = $this->id;
if (is_null($object['Attribute'][$k]['first_seen']) && !is_null($object['first_seen'])) {
$object['Attribute'][$k]['first_seen'] = $object['first_seen'];
}
if (is_null($object['Attribute'][$k]['last_seen']) && !is_null($object['last_seen'])) {
$object['Attribute'][$k]['last_seen'] = $object['last_seen'];
}
}
$this->Attribute->saveAttributes($object['Attribute']);
} else {
@ -635,13 +641,13 @@ class MispObject extends AppModel
}
$date = new DateTime();
$object['Object']['timestamp'] = $date->getTimestamp();
$this->setObjectSeenMetaFromAttribute($object, false);
if (isset($objectToSave['Object']['first_seen'])) {
$object['Object']['first_seen'] = $objectToSave['Object']['first_seen'];
}
if (isset($objectToSave['Object']['last_seen'])) {
$object['Object']['last_seen'] = $objectToSave['Object']['last_seen'];
}
$this->setObjectSeenMetaFromAttribute($object, false);
$this->save($object);
if (!$onlyAddNewAttribute) {
@ -658,6 +664,15 @@ class MispObject extends AppModel
if ($newAttribute[$f] != $originalAttribute[$f]) {
$different = true;
}
// Set seen of object at attribute level
if (is_null($newAttribute['first_seen']) && !is_null($object['first_seen'])) {
$newAttribute['first_seen'] = $object['first_seen'];
$different = true;
}
if (is_null($newAttribute['last_seen']) && !is_null($object['last_seen'])) {
$newAttribute['last_seen'] = $object['last_seen'];
$different = true;
}
}
if ($different) {
$newAttribute['id'] = $originalAttribute['id'];
@ -685,6 +700,13 @@ class MispObject extends AppModel
$this->Event->Attribute->create();
$newAttribute['event_id'] = $object['Object']['event_id'];
$newAttribute['object_id'] = $object['Object']['id'];
// Set seen of object at attribute level
if (is_null($newAttribute['first_seen']) && !is_null($object['first_seen'])) {
$newAttribute['first_seen'] = $object['first_seen'];
}
if (is_null($newAttribute['last_seen']) && !is_null($object['last_seen'])) {
$newAttribute['last_seen'] = $object['last_seen'];
}
if (!isset($newAttribute['timestamp'])) {
$newAttribute['distribution'] = Configure::read('MISP.default_attribute_distribution');
if ($newAttribute['distribution'] == 'event') {
@ -701,10 +723,17 @@ class MispObject extends AppModel
}
} else { // we only add the new attribute
$newAttribute = $objectToSave['Attribute'][0];
if ($newAttribute != 'last-seen' && $newAttribute != 'first-seen') { // fs/ls should be added in the object's meta
if ($newAttribute['object_relation'] != 'last-seen' && $newAttribute['object_relation'] != 'first-seen') { // fs/ls should be added in the object's meta
$this->Event->Attribute->create();
$newAttribute['event_id'] = $object['Object']['event_id'];
$newAttribute['object_id'] = $object['Object']['id'];
// Set seen of object at attribute level
if (is_null($newAttribute['first_seen']) && !is_null($object['first_seen'])) {
$newAttribute['first_seen'] = $object['first_seen'];
}
if (is_null($newAttribute['last_seen']) && !is_null($object['last_seen'])) {
$newAttribute['last_seen'] = $object['last_seen'];
}
if (!isset($newAttribute['timestamp'])) {
$newAttribute['distribution'] = Configure::read('MISP.default_attribute_distribution');
if ($newAttribute['distribution'] == 'event') {