Autopsy  4.13.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-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.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.BlackboardArtifact.ARTIFACT_TYPE;
31 import org.sleuthkit.datamodel.BlackboardAttribute;
32 import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
33 import org.sleuthkit.datamodel.Content;
34 import org.sleuthkit.datamodel.HashUtility;
35 import org.sleuthkit.datamodel.TskCoreException;
36 import org.sleuthkit.datamodel.TskData;
37 
41 public class EamArtifactUtil {
42 
43  private static final Logger logger = Logger.getLogger(EamArtifactUtil.class.getName());
44 
45  @Messages({"EamArtifactUtil.emailaddresses.text=Email Addresses"})
46  public static String getEmailAddressAttrString() {
47  return Bundle.EamArtifactUtil_emailaddresses_text();
48  }
49 
62  public static List<CorrelationAttributeInstance> makeInstancesFromBlackboardArtifact(BlackboardArtifact artifact,
63  boolean checkEnabled) {
64  List<CorrelationAttributeInstance> eamArtifacts = new ArrayList<>();
65  try {
66  BlackboardArtifact artifactForInstance = null;
67  if (BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID() == artifact.getArtifactTypeID()) {
68  // Get the associated artifactForInstance
69  BlackboardAttribute attribute = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
70  if (attribute != null) {
71  artifactForInstance = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboardArtifact(attribute.getValueLong());
72  }
73  } else {
74  artifactForInstance = artifact;
75  }
76  if (artifactForInstance != null) {
77  int artifactTypeID = artifactForInstance.getArtifactTypeID();
78  if (artifactTypeID == ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
79  BlackboardAttribute setNameAttr = artifactForInstance.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME));
80  if (setNameAttr != null
81  && EamArtifactUtil.getEmailAddressAttrString().equals(setNameAttr.getValueString())) {
82  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD, CorrelationAttributeInstance.EMAIL_TYPE_ID);
83  }
84  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getTypeID()
85  || artifactTypeID == ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID()
86  || artifactTypeID == ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID()
87  || artifactTypeID == ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID()) {
88  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, CorrelationAttributeInstance.DOMAIN_TYPE_ID);
89  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_CONTACT.getTypeID()
90  || artifactTypeID == ARTIFACT_TYPE.TSK_CALLLOG.getTypeID()
91  || artifactTypeID == ARTIFACT_TYPE.TSK_MESSAGE.getTypeID()) {
92 
93  String value = null;
94  if (null != artifactForInstance.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER))) {
95  value = artifactForInstance.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER)).getValueString();
96  } else if (null != artifactForInstance.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM))) {
97  value = artifactForInstance.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM)).getValueString();
98  } else if (null != artifactForInstance.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO))) {
99  value = artifactForInstance.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO)).getValueString();
100  }
101  // Remove all non-numeric symbols to semi-normalize phone numbers, preserving leading "+" character
102  if (value != null) {
103  String newValue = value.replaceAll("\\D", "");
104  if (value.startsWith("+")) {
105  newValue = "+" + newValue;
106  }
107  value = newValue;
108  // Only add the correlation attribute if the resulting phone number large enough to be of use
109  // (these 3-5 digit numbers can be valid, but are not useful for correlation)
110  if (value.length() > 5) {
112  if (inst != null) {
113  eamArtifacts.add(inst);
114  }
115  }
116  }
117  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_DEVICE_ATTACHED.getTypeID()) {
118  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_ID, CorrelationAttributeInstance.USBID_TYPE_ID);
119  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MAC_ADDRESS, CorrelationAttributeInstance.MAC_TYPE_ID);
120  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_WIFI_NETWORK.getTypeID()) {
121  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SSID, CorrelationAttributeInstance.SSID_TYPE_ID);
122  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_WIFI_NETWORK_ADAPTER.getTypeID()
123  || artifactTypeID == ARTIFACT_TYPE.TSK_BLUETOOTH_PAIRING.getTypeID()
124  || artifactTypeID == ARTIFACT_TYPE.TSK_BLUETOOTH_ADAPTER.getTypeID()) {
125  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MAC_ADDRESS, CorrelationAttributeInstance.MAC_TYPE_ID);
126  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_DEVICE_INFO.getTypeID()) {
127  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IMEI, CorrelationAttributeInstance.IMEI_TYPE_ID);
128  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IMSI, CorrelationAttributeInstance.IMSI_TYPE_ID);
129  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ICCID, CorrelationAttributeInstance.ICCID_TYPE_ID);
130  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_SIM_ATTACHED.getTypeID()) {
131  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IMSI, CorrelationAttributeInstance.IMSI_TYPE_ID);
132  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ICCID, CorrelationAttributeInstance.ICCID_TYPE_ID);
133  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_WEB_FORM_ADDRESS.getTypeID()) {
134  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER, CorrelationAttributeInstance.PHONE_TYPE_ID);
135  addCorrelationAttributeToList(eamArtifacts, artifactForInstance, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL, CorrelationAttributeInstance.EMAIL_TYPE_ID);
136  }
137  }
138  } catch (EamDbException ex) {
139  logger.log(Level.SEVERE, "Error getting defined correlation types.", ex); // NON-NLS
140  return eamArtifacts;
141  } catch (TskCoreException ex) {
142  logger.log(Level.SEVERE, "Error getting attribute while getting type from BlackboardArtifact.", ex); // NON-NLS
143  return null;
144  } catch (NoCurrentCaseException ex) {
145  logger.log(Level.SEVERE, "Exception while getting open case.", ex); // NON-NLS
146  return null;
147  }
148  return eamArtifacts;
149  }
150 
169  private static void addCorrelationAttributeToList(List<CorrelationAttributeInstance> eamArtifacts, BlackboardArtifact artifact, ATTRIBUTE_TYPE bbAttributeType, int typeId) throws EamDbException, TskCoreException {
170  BlackboardAttribute attribute = artifact.getAttribute(new BlackboardAttribute.Type(bbAttributeType));
171  if (attribute != null) {
172  String value = attribute.getValueString();
173  if ((null != value) && (value.isEmpty() == false)) {
175  if (inst != null) {
176  eamArtifacts.add(inst);
177  }
178  }
179  }
180  }
181 
193  private static CorrelationAttributeInstance makeCorrelationAttributeInstanceUsingTypeValue(BlackboardArtifact bbArtifact, CorrelationAttributeInstance.Type correlationType, String value) {
194  try {
195  Case currentCase = Case.getCurrentCaseThrows();
196  AbstractFile bbSourceFile = currentCase.getSleuthkitCase().getAbstractFileById(bbArtifact.getObjectID());
197  if (null == bbSourceFile) {
198  logger.log(Level.SEVERE, "Error creating artifact instance. Abstract File was null."); // NON-NLS
199  return null;
200  }
201 
202  // make an instance for the BB source file
204  return new CorrelationAttributeInstance(
205  correlationType,
206  value,
207  correlationCase,
208  CorrelationDataSource.fromTSKDataSource(correlationCase, bbSourceFile.getDataSource()),
209  bbSourceFile.getParentPath() + bbSourceFile.getName(),
210  "",
211  TskData.FileKnown.UNKNOWN,
212  bbSourceFile.getId());
213 
214  } catch (TskCoreException ex) {
215  logger.log(Level.SEVERE, "Error getting AbstractFile for artifact: " + bbArtifact.toString(), ex); // NON-NLS
216  return null;
217  } catch (EamDbException | CorrelationAttributeNormalizationException ex) {
218  logger.log(Level.WARNING, "Error creating artifact instance for artifact: " + bbArtifact.toString(), ex); // NON-NLS
219  return null;
220  } catch (NoCurrentCaseException ex) {
221  logger.log(Level.SEVERE, "Case is closed.", ex); // NON-NLS
222  return null;
223  }
224  }
225 
233  public static CorrelationAttributeInstance getInstanceFromContent(Content content) {
234 
235  if (!(content instanceof AbstractFile)) {
236  return null;
237  }
238 
239  final AbstractFile file = (AbstractFile) content;
240 
241  if (!isSupportedAbstractFileType(file)) {
242  return null;
243  }
244 
246  CorrelationCase correlationCase;
247  CorrelationDataSource correlationDataSource;
248 
249  try {
251  correlationCase = EamDb.getInstance().getCase(Case.getCurrentCaseThrows());
252  if (null == correlationCase) {
253  //if the correlationCase is not in the Central repo then attributes generated in relation to it will not be
254  return null;
255  }
256  correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource());
257  } catch (TskCoreException | EamDbException ex) {
258  logger.log(Level.SEVERE, "Error retrieving correlation attribute.", ex);
259  return null;
260  } catch (NoCurrentCaseException ex) {
261  logger.log(Level.SEVERE, "Case is closed.", ex);
262  return null;
263  }
264 
265  CorrelationAttributeInstance correlationAttributeInstance;
266  try {
267  correlationAttributeInstance = EamDb.getInstance().getCorrelationAttributeInstance(type, correlationCase, correlationDataSource, file.getId());
268  } catch (EamDbException | CorrelationAttributeNormalizationException ex) {
269  logger.log(Level.WARNING, String.format(
270  "Correlation attribute could not be retrieved for '%s' (id=%d): ",
271  content.getName(), content.getId()), ex);
272  return null;
273  }
274  //if there was no correlation attribute found for the item using object_id then check for attributes added with schema 1,1 which lack object_id
275  if (correlationAttributeInstance == null && file.getMd5Hash() != null) {
276  String filePath = (file.getParentPath() + file.getName()).toLowerCase();
277  try {
278  correlationAttributeInstance = EamDb.getInstance().getCorrelationAttributeInstance(type, correlationCase, correlationDataSource, file.getMd5Hash(), filePath);
279  } catch (EamDbException | CorrelationAttributeNormalizationException ex) {
280  logger.log(Level.WARNING, String.format(
281  "Correlation attribute could not be retrieved for '%s' (id=%d): ",
282  content.getName(), content.getId()), ex);
283  return null;
284  }
285  }
286 
287  return correlationAttributeInstance;
288  }
289 
303  public static CorrelationAttributeInstance makeInstanceFromContent(Content content) {
304 
305  if (!(content instanceof AbstractFile)) {
306  return null;
307  }
308 
309  final AbstractFile af = (AbstractFile) content;
310 
311  if (!isSupportedAbstractFileType(af)) {
312  return null;
313  }
314 
315  // We need a hash to make the artifactForInstance
316  String md5 = af.getMd5Hash();
317  if (md5 == null || md5.isEmpty() || HashUtility.isNoDataMd5(md5)) {
318  return null;
319  }
320 
321  try {
323 
325  return new CorrelationAttributeInstance(
326  filesType,
327  af.getMd5Hash(),
328  correlationCase,
329  CorrelationDataSource.fromTSKDataSource(correlationCase, af.getDataSource()),
330  af.getParentPath() + af.getName(),
331  "",
332  TskData.FileKnown.UNKNOWN,
333  af.getId());
334 
335  } catch (TskCoreException | EamDbException | CorrelationAttributeNormalizationException ex) {
336  logger.log(Level.SEVERE, "Error making correlation attribute.", ex);
337  return null;
338  } catch (NoCurrentCaseException ex) {
339  logger.log(Level.SEVERE, "Case is closed.", ex);
340  return null;
341  }
342  }
343 
353  public static boolean isSupportedAbstractFileType(AbstractFile file) {
354  if (file == null) {
355  return false;
356  }
357  switch (file.getType()) {
358  case UNALLOC_BLOCKS:
359  case UNUSED_BLOCKS:
360  case SLACK:
361  case VIRTUAL_DIR:
362  case LOCAL_DIR:
363  return false;
364  case CARVED:
365  case DERIVED:
366  case LOCAL:
367  case LAYOUT_FILE:
368  return true;
369  case FS:
370  return file.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC);
371  default:
372  logger.log(Level.WARNING, "Unexpected file type {0}", file.getType().getName());
373  return false;
374  }
375  }
376 
380  private EamArtifactUtil() {
381  //empty constructor
382  }
383 }
static List< CorrelationAttributeInstance > makeInstancesFromBlackboardArtifact(BlackboardArtifact artifact, boolean checkEnabled)
static void addCorrelationAttributeToList(List< CorrelationAttributeInstance > eamArtifacts, BlackboardArtifact artifact, ATTRIBUTE_TYPE bbAttributeType, int typeId)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
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-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.