Autopsy  4.9.1
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-2018 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.modules.stix;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.logging.Level;
24 import org.openide.util.NbBundle.Messages;
30 import org.sleuthkit.datamodel.AbstractFile;
31 import org.sleuthkit.datamodel.BlackboardArtifact;
32 import org.sleuthkit.datamodel.BlackboardAttribute;
33 import org.sleuthkit.datamodel.SleuthkitCase;
34 import org.sleuthkit.datamodel.TskCoreException;
35 
39 class StixArtifactData {
40 
41  private AbstractFile file;
42  private final String observableId;
43  private final String objType;
44  private static final Logger logger = Logger.getLogger(StixArtifactData.class.getName());
45 
46  public StixArtifactData(AbstractFile a_file, String a_observableId, String a_objType) {
47  file = a_file;
48  observableId = a_observableId;
49  objType = a_objType;
50  }
51 
52  public StixArtifactData(long a_objId, String a_observableId, String a_objType) {
53  try {
54  Case case1 = Case.getCurrentCaseThrows();
55  SleuthkitCase sleuthkitCase = case1.getSleuthkitCase();
56  file = sleuthkitCase.getAbstractFileById(a_objId);
57  } catch (TskCoreException | NoCurrentCaseException ex) {
58  file = null;
59  }
60  observableId = a_observableId;
61  objType = a_objType;
62  }
63 
64  @Messages({"StixArtifactData.indexError.message=Failed to index STIX interesting file hit artifact for keyword search.",
65  "StixArtifactData.noOpenCase.errMsg=No open case available."})
66  public void createArtifact(String a_title) throws TskCoreException {
67  Case currentCase;
68  try {
69  currentCase = Case.getCurrentCaseThrows();
70  } catch (NoCurrentCaseException ex) {
71  logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
72  MessageNotifyUtil.Notify.error(Bundle.StixArtifactData_noOpenCase_errMsg(), ex.getLocalizedMessage());
73  return;
74  }
75 
76  String setName;
77  if (a_title != null) {
78  setName = "STIX Indicator - " + a_title; //NON-NLS
79  } else {
80  setName = "STIX Indicator - (no title)"; //NON-NLS
81  }
82 
83  Collection<BlackboardAttribute> attributes = new ArrayList<>();
84  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, "Stix", setName)); //NON-NLS
85  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE, "Stix", observableId)); //NON-NLS
86  attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, "Stix", objType)); //NON-NLS
87 
88  org.sleuthkit.datamodel.Blackboard tskBlackboard = currentCase.getSleuthkitCase().getBlackboard();
89  // Create artifact if it doesn't already exist.
90  if (!tskBlackboard.artifactExists(file, BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, attributes)) {
91  BlackboardArtifact bba = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
92  bba.addAttributes(attributes);
93 
94  try {
95  // index the artifact for keyword search
96  Blackboard blackboard = currentCase.getServices().getBlackboard();
97  blackboard.indexArtifact(bba);
98  } catch (Blackboard.BlackboardException ex) {
99  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS
100  MessageNotifyUtil.Notify.error(Bundle.StixArtifactData_indexError_message(), bba.getDisplayName());
101  }
102  }
103  }
104 
105  public void print() {
106  System.out.println(" " + observableId + " " + file.getName());
107  }
108 }

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.