Autopsy  4.11.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 | 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 
246  try {
248  correlationCase = EamDb.getInstance().getCase(Case.getCurrentCaseThrows());
249  if (null == correlationCase) {
250  //if the correlationCase is not in the Central repo then attributes generated in relation to it will not be
251  return null;
252  }
253  correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource());
254  } catch (TskCoreException | EamDbException ex) {
255  logger.log(Level.SEVERE, "Error retrieving correlation attribute.", ex);
256  return null;
257  } catch (NoCurrentCaseException ex) {
258  logger.log(Level.SEVERE, "Case is closed.", ex);
259  return null;
260  }
261 
262  CorrelationAttributeInstance correlationAttributeInstance;
263  try {
264  correlationAttributeInstance = EamDb.getInstance().getCorrelationAttributeInstance(type, correlationCase, correlationDataSource, file.getId());
265  } catch (EamDbException | CorrelationAttributeNormalizationException ex) {
266  logger.log(Level.WARNING, String.format(
267  "Correlation attribute could not be retrieved for '%s' (id=%d): ",
268  content.getName(), content.getId()), ex);
269  return null;
270  }
271  //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
272  if (correlationAttributeInstance == null && file.getMd5Hash() != null) {
273  String filePath = (file.getParentPath() + file.getName()).toLowerCase();
274  try {
275  correlationAttributeInstance = EamDb.getInstance().getCorrelationAttributeInstance(type, correlationCase, correlationDataSource, file.getMd5Hash(), filePath);
276  } catch (EamDbException | CorrelationAttributeNormalizationException ex) {
277  logger.log(Level.WARNING, String.format(
278  "Correlation attribute could not be retrieved for '%s' (id=%d): ",
279  content.getName(), content.getId()), ex);
280  return null;
281  }
282  }
283 
284  return correlationAttributeInstance;
285  }
286 
300  public static CorrelationAttributeInstance makeInstanceFromContent(Content content) {
301 
302  if (!(content instanceof AbstractFile)) {
303  return null;
304  }
305 
306  final AbstractFile af = (AbstractFile) content;
307 
308  if (!isSupportedAbstractFileType(af)) {
309  return null;
310  }
311 
312  // We need a hash to make the artifactForInstance
313  String md5 = af.getMd5Hash();
314  if (md5 == null || md5.isEmpty() || HashUtility.isNoDataMd5(md5)) {
315  return null;
316  }
317 
318  try {
320 
322  return new CorrelationAttributeInstance(
323  filesType,
324  af.getMd5Hash(),
325  correlationCase,
326  CorrelationDataSource.fromTSKDataSource(correlationCase, af.getDataSource()),
327  af.getParentPath() + af.getName(),
328  "",
329  TskData.FileKnown.UNKNOWN,
330  af.getId());
331 
332  } catch (TskCoreException | EamDbException | CorrelationAttributeNormalizationException ex) {
333  logger.log(Level.SEVERE, "Error making correlation attribute.", ex);
334  return null;
335  } catch (NoCurrentCaseException ex) {
336  logger.log(Level.SEVERE, "Case is closed.", ex);
337  return null;
338  }
339  }
340 
350  public static boolean isSupportedAbstractFileType(AbstractFile file) {
351  if (file == null) {
352  return false;
353  }
354  switch (file.getType()) {
355  case UNALLOC_BLOCKS:
356  case UNUSED_BLOCKS:
357  case SLACK:
358  case VIRTUAL_DIR:
359  case LOCAL_DIR:
360  return false;
361  case CARVED:
362  case DERIVED:
363  case LOCAL:
364  case LAYOUT_FILE:
365  return true;
366  case FS:
367  return file.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC);
368  default:
369  logger.log(Level.WARNING, "Unexpected file type {0}", file.getType().getName());
370  return false;
371  }
372  }
373 
377  private EamArtifactUtil() {
378  //empty constructor
379  }
380 }
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-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.