Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
StixArtifactData.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.report.modules.stix;
20 
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.logging.Level;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openide.util.NbBundle.Messages;
29 import org.sleuthkit.datamodel.AbstractFile;
30 import org.sleuthkit.datamodel.Blackboard;
31 import org.sleuthkit.datamodel.BlackboardArtifact;
32 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT;
33 import org.sleuthkit.datamodel.BlackboardAttribute;
34 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY;
35 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME;
36 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE;
37 import org.sleuthkit.datamodel.SleuthkitCase;
38 import org.sleuthkit.datamodel.TskCoreException;
39 
43 class StixArtifactData {
44 
45  private static final String MODULE_NAME = "Stix";
46 
47  private AbstractFile file;
48  private final String observableId;
49  private final String objType;
50  private static final Logger logger = Logger.getLogger(StixArtifactData.class.getName());
51 
52  StixArtifactData(AbstractFile a_file, String a_observableId, String a_objType) {
53  file = a_file;
54  observableId = a_observableId;
55  objType = a_objType;
56  }
57 
58  StixArtifactData(long a_objId, String a_observableId, String a_objType) {
59  try {
60  Case case1 = Case.getCurrentCaseThrows();
61  SleuthkitCase sleuthkitCase = case1.getSleuthkitCase();
62  file = sleuthkitCase.getAbstractFileById(a_objId);
63  } catch (TskCoreException | NoCurrentCaseException ex) {
64  file = null;
65  }
66  observableId = a_observableId;
67  objType = a_objType;
68  }
69 
70  @Messages({"StixArtifactData.indexError.message=Failed to index STIX interesting file hit artifact for keyword search.",
71  "StixArtifactData.noOpenCase.errMsg=No open case available."})
72  void createArtifact(String a_title) throws TskCoreException {
73  Blackboard blackboard;
74  try {
75  blackboard = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard();
76  } catch (NoCurrentCaseException ex) {
77  logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
78  return;
79  }
80 
81  String setName = "STIX Indicator - " + StringUtils.defaultIfBlank(a_title, "(no title)"); //NON-NLS
82 
83  Collection<BlackboardAttribute> attributes = Arrays.asList(
84  new BlackboardAttribute(TSK_SET_NAME, MODULE_NAME, setName),
85  new BlackboardAttribute(TSK_TITLE, MODULE_NAME, observableId),
86  new BlackboardAttribute(TSK_CATEGORY, MODULE_NAME, objType));
87 
88  // Create artifact if it doesn't already exist.
89  if (!blackboard.artifactExists(file, TSK_INTERESTING_FILE_HIT, attributes)) {
90  BlackboardArtifact bba = file.newArtifact(TSK_INTERESTING_FILE_HIT);
91  bba.addAttributes(attributes);
92 
93  try {
94  /*
95  * post the artifact which will index the artifact for keyword
96  * search, and fire an event to notify UI of this new artifact
97  */
98  blackboard.postArtifact(bba, MODULE_NAME);
99  } catch (Blackboard.BlackboardException ex) {
100  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS
101  }
102  }
103  }
104 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.