Autopsy  4.8.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EamArtifactUtil.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-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.centralrepository.datamodel;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.logging.Level;
24 import org.openide.util.NbBundle.Messages;
28 import org.sleuthkit.datamodel.AbstractFile;
29 import org.sleuthkit.datamodel.BlackboardArtifact;
30 import org.sleuthkit.datamodel.BlackboardAttribute;
31 import org.sleuthkit.datamodel.Content;
32 import org.sleuthkit.datamodel.HashUtility;
33 import org.sleuthkit.datamodel.TskCoreException;
34 import org.sleuthkit.datamodel.TskData;
35 
39 public class EamArtifactUtil {
40 
41  private static final Logger logger = Logger.getLogger(EamArtifactUtil.class.getName());
42 
43  public EamArtifactUtil() {
44  }
45 
46  @Messages({"EamArtifactUtil.emailaddresses.text=Email Addresses"})
47  public static String getEmailAddressAttrString() {
48  return Bundle.EamArtifactUtil_emailaddresses_text();
49  }
50 
63  public static List<CorrelationAttributeInstance> makeInstancesFromBlackboardArtifact(BlackboardArtifact bbArtifact,
64  boolean checkEnabled) {
65 
66  List<CorrelationAttributeInstance> eamArtifacts = new ArrayList<>();
67 
68  try {
69  // Cycle through the types and see if there is a correlation attribute that works
70  // for the given blackboard artifact
71  //
72  // @@@ This seems ineffecient. Instead of cycling based on correlation type, we should just
73  // have switch based on artifact type
75  if ((checkEnabled && aType.isEnabled()) || !checkEnabled) {
76  // Now always adds the instance details associated with this occurance.
78  if (correlationAttribute != null) {
79  eamArtifacts.add(correlationAttribute);
80  }
81  }
82  }
83  } catch (EamDbException ex) {
84  logger.log(Level.SEVERE, "Error getting defined correlation types.", ex); // NON-NLS
85  return eamArtifacts;
86  }
87 
88  return eamArtifacts;
89  }
90 
102  BlackboardArtifact bbArtifact) throws EamDbException {
103  String value = null;
104  int artifactTypeID = bbArtifact.getArtifactTypeID();
105 
106  try {
107  if (BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID() == artifactTypeID) {
108  // Get the associated artifact
109  BlackboardAttribute attribute = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
110  if (attribute != null) {
111  BlackboardArtifact associatedArtifact = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboardArtifact(attribute.getValueLong());
112  return EamArtifactUtil.makeInstanceFromBlackboardArtifact(correlationType, associatedArtifact);
113  }
114 
115  } else if (correlationType.getId() == CorrelationAttributeInstance.EMAIL_TYPE_ID
116  && BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID() == artifactTypeID) {
117 
118  BlackboardAttribute setNameAttr = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME));
119  if (setNameAttr != null
120  && EamArtifactUtil.getEmailAddressAttrString().equals(setNameAttr.getValueString())) {
121  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD)).getValueString();
122  }
123  } else if (correlationType.getId() == CorrelationAttributeInstance.DOMAIN_TYPE_ID
124  && (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getTypeID() == artifactTypeID
125  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID() == artifactTypeID
126  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == artifactTypeID
127  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID() == artifactTypeID)) {
128 
129  // Lower-case this to normalize domains
130  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN)).getValueString();
131  } else if (correlationType.getId() == CorrelationAttributeInstance.PHONE_TYPE_ID
132  && (BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT.getTypeID() == artifactTypeID
133  || BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG.getTypeID() == artifactTypeID
134  || BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == artifactTypeID)) {
135 
136  if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER))) {
137  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER)).getValueString();
138  } else if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM))) {
139  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM)).getValueString();
140  } else if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO))) {
141  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO)).getValueString();
142  }
143 
144  // Remove all non-numeric symbols to semi-normalize phone numbers, preserving leading "+" character
145  if (value != null) {
146  String newValue = value.replaceAll("\\D", "");
147  if (value.startsWith("+")) {
148  newValue = "+" + newValue;
149  }
150 
151  value = newValue;
152 
153  // If the resulting phone number is too small to be of use, return null
154  // (these 3-5 digit numbers can be valid, but are not useful for correlation)
155  if (value.length() <= 5) {
156  return null;
157  }
158  }
159 
160  } else if (correlationType.getId() == CorrelationAttributeInstance.USBID_TYPE_ID
161  && BlackboardArtifact.ARTIFACT_TYPE.TSK_DEVICE_ATTACHED.getTypeID() == artifactTypeID) {
162 
163  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_ID)).getValueString();
164  }
165 
166  } catch (TskCoreException ex) {
167  logger.log(Level.SEVERE, "Error getting attribute while getting type from BlackboardArtifact.", ex); // NON-NLS
168  return null;
169  } catch (NoCurrentCaseException ex) {
170  logger.log(Level.SEVERE, "Exception while getting open case.", ex); // NON-NLS
171  return null;
172  }
173 
174  if (null != value) {
175  return makeCorrelationAttributeInstanceUsingTypeValue(bbArtifact, correlationType, value);
176  } else {
177  return null;
178  }
179  }
180 
190  private static CorrelationAttributeInstance makeCorrelationAttributeInstanceUsingTypeValue(BlackboardArtifact bbArtifact, CorrelationAttributeInstance.Type correlationType, String value) {
191  try {
192  Case currentCase = Case.getCurrentCaseThrows();
193  AbstractFile bbSourceFile = currentCase.getSleuthkitCase().getAbstractFileById(bbArtifact.getObjectID());
194  if (null == bbSourceFile) {
195  logger.log(Level.SEVERE, "Error creating artifact instance. Abstract File was null."); // NON-NLS
196  return null;
197  }
198 
199  // make an instance for the BB source file
201  if (null == correlationCase) {
202  correlationCase = EamDb.getInstance().newCase(Case.getCurrentCaseThrows());
203  }
204  return new CorrelationAttributeInstance(
205  value,
206  correlationType,
207  correlationCase,
208  CorrelationDataSource.fromTSKDataSource(correlationCase, bbSourceFile.getDataSource()),
209  bbSourceFile.getParentPath() + bbSourceFile.getName(),
210  "",
211  TskData.FileKnown.UNKNOWN
212  );
213 
214  } catch (TskCoreException | EamDbException | CorrelationAttributeNormalizationException ex) {
215  logger.log(Level.SEVERE, "Error creating artifact instance.", ex); // NON-NLS
216  return null;
217  } catch (NoCurrentCaseException ex) {
218  logger.log(Level.SEVERE, "Case is closed.", ex); // NON-NLS
219  return null;
220  }
221  }
222 
230  public static CorrelationAttributeInstance getInstanceFromContent(Content content) {
231 
232  if (!(content instanceof AbstractFile)) {
233  return null;
234  }
235 
236  final AbstractFile file = (AbstractFile) content;
237 
238  if (!isSupportedAbstractFileType(file)) {
239  return null;
240  }
241 
243  CorrelationCase correlationCase;
244  CorrelationDataSource correlationDataSource;
245  String value;
246  String filePath;
247 
248  try {
250  correlationCase = EamDb.getInstance().getCase(Case.getCurrentCaseThrows());
251  if (null == correlationCase) {
252  //if the correlationCase is not in the Central repo then attributes generated in relation to it will not be
253  return null;
254  }
255  correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource());
256  value = file.getMd5Hash();
257  filePath = (file.getParentPath() + file.getName()).toLowerCase();
258  } catch (TskCoreException | EamDbException ex) {
259  logger.log(Level.SEVERE, "Error retrieving correlation attribute.", ex);
260  return null;
261  } catch (NoCurrentCaseException ex) {
262  logger.log(Level.SEVERE, "Case is closed.", ex);
263  return null;
264  }
265 
266  CorrelationAttributeInstance correlationAttributeInstance;
267  try {
268  correlationAttributeInstance = EamDb.getInstance().getCorrelationAttributeInstance(type, correlationCase, correlationDataSource, value, filePath);
270  logger.log(Level.WARNING, String.format(
271  "Correlation attribute could not be retrieved for '%s' (id=%d): %s",
272  content.getName(), content.getId(), ex.getMessage()));
273  return null;
274  }
275 
276  return correlationAttributeInstance;
277  }
278 
292  public static CorrelationAttributeInstance makeInstanceFromContent(Content content) {
293 
294  if (!(content instanceof AbstractFile)) {
295  return null;
296  }
297 
298  final AbstractFile af = (AbstractFile) content;
299 
300  if (!isSupportedAbstractFileType(af)) {
301  return null;
302  }
303 
304  // We need a hash to make the artifact
305  String md5 = af.getMd5Hash();
306  if (md5 == null || md5.isEmpty() || HashUtility.isNoDataMd5(md5)) {
307  return null;
308  }
309 
310  try {
312 
314  if (null == correlationCase) {
315  correlationCase = EamDb.getInstance().newCase(Case.getCurrentCaseThrows());
316  }
317  return new CorrelationAttributeInstance(
318  filesType,
319  af.getMd5Hash(),
320  correlationCase,
321  CorrelationDataSource.fromTSKDataSource(correlationCase, af.getDataSource()),
322  af.getParentPath() + af.getName());
323 
324  } catch (TskCoreException | EamDbException | CorrelationAttributeNormalizationException ex) {
325  logger.log(Level.SEVERE, "Error making correlation attribute.", ex);
326  return null;
327  } catch (NoCurrentCaseException ex) {
328  logger.log(Level.SEVERE, "Case is closed.", ex);
329  return null;
330  }
331  }
332 
342  public static boolean isSupportedAbstractFileType(AbstractFile file) {
343  if (file == null) {
344  return false;
345  }
346 
347  switch (file.getType()) {
348  case UNALLOC_BLOCKS:
349  case UNUSED_BLOCKS:
350  case SLACK:
351  case VIRTUAL_DIR:
352  case LOCAL_DIR:
353  return false;
354  case CARVED:
355  case DERIVED:
356  case LOCAL:
357  return true;
358  case FS:
359  return file.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC);
360  default:
361  logger.log(Level.WARNING, "Unexpected file type {0}", file.getType().getName());
362  return false;
363  }
364  }
365 }
static CorrelationAttributeInstance makeInstanceFromBlackboardArtifact(CorrelationAttributeInstance.Type correlationType, BlackboardArtifact bbArtifact)
CorrelationCase newCase(CorrelationCase eamCase)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
List< CorrelationAttributeInstance.Type > getDefinedCorrelationTypes()
static List< CorrelationAttributeInstance > makeInstancesFromBlackboardArtifact(BlackboardArtifact bbArtifact, boolean checkEnabled)
CorrelationAttributeInstance getCorrelationAttributeInstance(CorrelationAttributeInstance.Type type, CorrelationCase correlationCase, CorrelationDataSource correlationDataSource, String value, String filePath)
static CorrelationAttributeInstance getInstanceFromContent(Content content)
CorrelationAttributeInstance.Type getCorrelationTypeById(int typeId)
static CorrelationAttributeInstance makeInstanceFromContent(Content content)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static CorrelationAttributeInstance makeCorrelationAttributeInstanceUsingTypeValue(BlackboardArtifact bbArtifact, CorrelationAttributeInstance.Type correlationType, String value)

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