Autopsy  4.7.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 long serialVersionUID = 1L;
42  private static final Logger logger = Logger.getLogger(EamArtifactUtil.class.getName());
43 
44  public EamArtifactUtil() {
45  }
46 
47  @Messages({"EamArtifactUtil.emailaddresses.text=Email Addresses"})
48  public static String getEmailAddressAttrString() {
49  return Bundle.EamArtifactUtil_emailaddresses_text();
50  }
51 
66  public static List<CorrelationAttribute> getCorrelationAttributeFromBlackboardArtifact(BlackboardArtifact bbArtifact,
67  boolean addInstanceDetails, boolean checkEnabled) {
68 
69  List<CorrelationAttribute> eamArtifacts = new ArrayList<>();
70 
71  try {
72  // Cycle through the types and see if there is a correlation attribute that works
73  // for the given blackboard artifact
74  //
75  // @@@ This seems ineffecient. Instead of cycling based on correlation type, we should just
76  // have switch based on artifact type
78  if ((checkEnabled && aType.isEnabled()) || !checkEnabled) {
80  if (correlationAttribute != null) {
81  eamArtifacts.add(correlationAttribute);
82  }
83  }
84  }
85  } catch (EamDbException ex) {
86  logger.log(Level.SEVERE, "Error getting defined correlation types.", ex); // NON-NLS
87  return eamArtifacts;
88  }
89 
90  // if they asked for it, add the instance details associated with this occurance.
91  if (!eamArtifacts.isEmpty() && addInstanceDetails) {
92  try {
93  Case currentCase = Case.getCurrentCaseThrows();
94  AbstractFile bbSourceFile = currentCase.getSleuthkitCase().getAbstractFileById(bbArtifact.getObjectID());
95  if (null == bbSourceFile) {
96  //@@@ Log this
97  return eamArtifacts;
98  }
99 
100  // make an instance for the BB source file
102  if (null == correlationCase) {
103  correlationCase = EamDb.getInstance().newCase(Case.getCurrentCaseThrows());
104  }
106  correlationCase,
107  CorrelationDataSource.fromTSKDataSource(correlationCase, bbSourceFile.getDataSource()),
108  bbSourceFile.getParentPath() + bbSourceFile.getName(),
109  "",
110  TskData.FileKnown.UNKNOWN
111  );
112 
113  // add the instance details
114  for (CorrelationAttribute eamArtifact : eamArtifacts) {
115  eamArtifact.addInstance(eamInstance);
116  }
117  } catch (TskCoreException | EamDbException ex) {
118  logger.log(Level.SEVERE, "Error creating artifact instance.", ex); // NON-NLS
119  return eamArtifacts;
120  } catch (NoCurrentCaseException ex) {
121  logger.log(Level.SEVERE, "Case is closed.", ex); // NON-NLS
122  return eamArtifacts;
123  }
124  }
125 
126  return eamArtifacts;
127  }
128 
140  BlackboardArtifact bbArtifact) throws EamDbException {
141  String value = null;
142  int artifactTypeID = bbArtifact.getArtifactTypeID();
143 
144  try {
145  if (BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID() == artifactTypeID) {
146  // Get the associated artifact
147  BlackboardAttribute attribute = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
148  if (attribute != null) {
149  BlackboardArtifact associatedArtifact = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboardArtifact(attribute.getValueLong());
150  return EamArtifactUtil.getCorrelationAttributeFromBlackboardArtifact(correlationType, associatedArtifact);
151  }
152 
153  } else if (correlationType.getId() == CorrelationAttribute.EMAIL_TYPE_ID
154  && BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID() == artifactTypeID) {
155 
156  BlackboardAttribute setNameAttr = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME));
157  if (setNameAttr != null
158  && EamArtifactUtil.getEmailAddressAttrString().equals(setNameAttr.getValueString())) {
159  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD)).getValueString();
160  }
161  } else if (correlationType.getId() == CorrelationAttribute.DOMAIN_TYPE_ID
162  && (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getTypeID() == artifactTypeID
163  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID() == artifactTypeID
164  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == artifactTypeID
165  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID() == artifactTypeID)) {
166 
167  // Lower-case this to normalize domains
168  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN)).getValueString();
169  } else if (correlationType.getId() == CorrelationAttribute.PHONE_TYPE_ID
170  && (BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT.getTypeID() == artifactTypeID
171  || BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG.getTypeID() == artifactTypeID
172  || BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == artifactTypeID)) {
173 
174  if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER))) {
175  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER)).getValueString();
176  } else if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM))) {
177  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM)).getValueString();
178  } else if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO))) {
179  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO)).getValueString();
180  }
181 
182  // Remove all non-numeric symbols to semi-normalize phone numbers, preserving leading "+" character
183  if (value != null) {
184  String newValue = value.replaceAll("\\D", "");
185  if (value.startsWith("+")) {
186  newValue = "+" + newValue;
187  }
188 
189  value = newValue;
190 
191  // If the resulting phone number is too small to be of use, return null
192  // (these 3-5 digit numbers can be valid, but are not useful for correlation)
193  if (value.length() <= 5) {
194  return null;
195  }
196  }
197 
198  } else if (correlationType.getId() == CorrelationAttribute.USBID_TYPE_ID
199  && BlackboardArtifact.ARTIFACT_TYPE.TSK_DEVICE_ATTACHED.getTypeID() == artifactTypeID) {
200 
201  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_ID)).getValueString();
202  }
203 
204  } catch (TskCoreException ex) {
205  logger.log(Level.SEVERE, "Error getting attribute while getting type from BlackboardArtifact.", ex); // NON-NLS
206  return null;
207  } catch (NoCurrentCaseException ex) {
208  logger.log(Level.SEVERE, "Exception while getting open case.", ex); // NON-NLS
209  return null;
210  }
211 
212  if (null != value) {
213  return new CorrelationAttribute(correlationType, value);
214  } else {
215  return null;
216  }
217  }
218 
227 
228  if (!(content instanceof AbstractFile)) {
229  return null;
230  }
231 
232  final AbstractFile file = (AbstractFile) content;
233 
234  if (!isSupportedAbstractFileType(file)) {
235  return null;
236  }
237 
238  CorrelationAttribute correlationAttribute = null;
239 
240  try {
243  if (null == correlationCase) {
244  correlationCase = EamDb.getInstance().newCase(Case.getCurrentCaseThrows());
245  }
246  CorrelationDataSource correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource());
247  String value = file.getMd5Hash();
248  String filePath = (file.getParentPath() + file.getName()).toLowerCase();
249 
250  correlationAttribute = EamDb.getInstance().getCorrelationAttribute(type, correlationCase, correlationDataSource, value, filePath);
251  } catch (TskCoreException | EamDbException | NoCurrentCaseException ex) {
252  logger.log(Level.SEVERE, "Error retrieving correlation attribute.", ex);
253  }
254 
255  return correlationAttribute;
256  }
257 
272 
273  if (!(content instanceof AbstractFile)) {
274  return null;
275  }
276 
277  final AbstractFile af = (AbstractFile) content;
278 
279  if (!isSupportedAbstractFileType(af)) {
280  return null;
281  }
282 
283  // We need a hash to make the artifact
284  String md5 = af.getMd5Hash();
285  if (md5 == null || md5.isEmpty() || HashUtility.isNoDataMd5(md5)) {
286  return null;
287  }
288 
289  CorrelationAttribute eamArtifact;
290  try {
292  eamArtifact = new CorrelationAttribute(filesType, af.getMd5Hash());
294  if (null == correlationCase) {
295  correlationCase = EamDb.getInstance().newCase(Case.getCurrentCaseThrows());
296  }
298  correlationCase,
299  CorrelationDataSource.fromTSKDataSource(correlationCase, af.getDataSource()),
300  af.getParentPath() + af.getName());
301  eamArtifact.addInstance(cei);
302  return eamArtifact;
303  } catch (TskCoreException | EamDbException | NoCurrentCaseException ex) {
304  logger.log(Level.SEVERE, "Error making correlation attribute.", ex);
305  return null;
306  }
307  }
308 
318  public static boolean isSupportedAbstractFileType(AbstractFile file) {
319  if (file == null) {
320  return false;
321  }
322 
323  switch (file.getType()) {
324  case UNALLOC_BLOCKS:
325  case UNUSED_BLOCKS:
326  case SLACK:
327  case VIRTUAL_DIR:
328  case LOCAL_DIR:
329  return false;
330  case CARVED:
331  case DERIVED:
332  case LOCAL:
333  return true;
334  case FS:
335  return file.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC);
336  default:
337  logger.log(Level.WARNING, "Unexpected file type {0}", file.getType().getName());
338  return false;
339  }
340  }
341 }
CorrelationAttribute.Type getCorrelationTypeById(int typeId)
static CorrelationAttribute getCorrelationAttributeFromBlackboardArtifact(CorrelationAttribute.Type correlationType, BlackboardArtifact bbArtifact)
CorrelationCase newCase(CorrelationCase eamCase)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
void addInstance(CorrelationAttributeInstance artifactInstance)
static CorrelationAttribute makeCorrelationAttributeFromContent(Content content)
CorrelationAttribute getCorrelationAttribute(CorrelationAttribute.Type type, CorrelationCase correlationCase, CorrelationDataSource correlationDataSource, String value, String filePath)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
List< CorrelationAttribute.Type > getDefinedCorrelationTypes()
static List< CorrelationAttribute > getCorrelationAttributeFromBlackboardArtifact(BlackboardArtifact bbArtifact, boolean addInstanceDetails, boolean checkEnabled)
static CorrelationAttribute getCorrelationAttributeFromContent(Content content)

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