Autopsy  4.5.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-2017 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;
27 import org.sleuthkit.datamodel.AbstractFile;
28 import org.sleuthkit.datamodel.BlackboardArtifact;
29 import org.sleuthkit.datamodel.BlackboardAttribute;
30 import org.sleuthkit.datamodel.Content;
31 import org.sleuthkit.datamodel.HashUtility;
32 import org.sleuthkit.datamodel.TskCoreException;
33 import org.sleuthkit.datamodel.TskData;
34 
38 public class EamArtifactUtil {
39 
40  private static final long serialVersionUID = 1L;
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 
65  public static List<CorrelationAttribute> getCorrelationAttributeFromBlackboardArtifact(BlackboardArtifact bbArtifact,
66  boolean addInstanceDetails, boolean checkEnabled) {
67 
68  List<CorrelationAttribute> eamArtifacts = new ArrayList<>();
69 
70  try {
71  // Cycle through the types and see if there is a correlation attribute that works
72  // for the given blackboard artifact
73  //
74  // @@@ This seems ineffecient. Instead of cycling based on correlation type, we should just
75  // have switch based on artifact type
77  if ((checkEnabled && aType.isEnabled()) || !checkEnabled) {
79  if (eamArtifact != null) {
80  eamArtifacts.add(eamArtifact);
81  }
82  }
83  }
84  } catch (EamDbException ex) {
85  LOGGER.log(Level.SEVERE, "Error getting defined correlation types.", ex); // NON-NLS
86  return eamArtifacts;
87  }
88 
89  // if they asked for it, add the instance details associated with this occurance.
90  if (!eamArtifacts.isEmpty() && addInstanceDetails) {
91  try {
92  Case currentCase = Case.getCurrentCase();
93  AbstractFile bbSourceFile = currentCase.getSleuthkitCase().getAbstractFileById(bbArtifact.getObjectID());
94  if (null == bbSourceFile) {
95  //@@@ Log this
96  return eamArtifacts;
97  }
98 
99  // make an instance for the BB source file
101  if (null == correlationCase) {
102  correlationCase = EamDb.getInstance().newCase(Case.getCurrentCase());
103  }
105  correlationCase,
106  CorrelationDataSource.fromTSKDataSource(correlationCase, bbSourceFile.getDataSource()),
107  bbSourceFile.getParentPath() + bbSourceFile.getName(),
108  "",
109  TskData.FileKnown.UNKNOWN
110  );
111 
112  // add the instance details
113  for (CorrelationAttribute eamArtifact : eamArtifacts) {
114  eamArtifact.addInstance(eamInstance);
115  }
116  } catch (TskCoreException | EamDbException ex) {
117  LOGGER.log(Level.SEVERE, "Error creating artifact instance.", ex); // NON-NLS
118  return eamArtifacts;
119  } catch (IllegalStateException ex) {
120  LOGGER.log(Level.SEVERE, "Case is closed.", ex); // NON-NLS
121  return eamArtifacts;
122  }
123  }
124 
125  return eamArtifacts;
126  }
127 
139  BlackboardArtifact bbArtifact) throws EamDbException {
140  String value = null;
141  int artifactTypeID = bbArtifact.getArtifactTypeID();
142 
143  try {
144  if (BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID() == artifactTypeID) {
145  // Get the associated artifact
146  BlackboardAttribute attribute = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
147  if (attribute != null) {
148  BlackboardArtifact associatedArtifact = Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifact(attribute.getValueLong());
149  return EamArtifactUtil.getCorrelationAttributeFromBlackboardArtifact(correlationType, associatedArtifact);
150  }
151 
152  } else if (correlationType.getId() == CorrelationAttribute.EMAIL_TYPE_ID
153  && BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID() == artifactTypeID) {
154 
155  BlackboardAttribute setNameAttr = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME));
156  if (setNameAttr != null
157  && EamArtifactUtil.getEmailAddressAttrString().equals(setNameAttr.getValueString())) {
158  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD)).getValueString();
159  }
160  } else if (correlationType.getId() == CorrelationAttribute.DOMAIN_TYPE_ID
161  && (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getTypeID() == artifactTypeID
162  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID() == artifactTypeID
163  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == artifactTypeID
164  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID() == artifactTypeID)) {
165 
166  // Lower-case this to normalize domains
167  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN)).getValueString();
168  } else if (correlationType.getId() == CorrelationAttribute.PHONE_TYPE_ID
169  && (BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT.getTypeID() == artifactTypeID
170  || BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG.getTypeID() == artifactTypeID
171  || BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == artifactTypeID)) {
172 
173  if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER))) {
174  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER)).getValueString();
175  } else if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM))) {
176  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM)).getValueString();
177  } else if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO))) {
178  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO)).getValueString();
179  }
180 
181  // Remove all non-numeric symbols to semi-normalize phone numbers, preserving leading "+" character
182  if (value != null) {
183  String newValue = value.replaceAll("\\D", "");
184  if (value.startsWith("+")) {
185  newValue = "+" + newValue;
186  }
187 
188  value = newValue;
189 
190  // If the resulting phone number is too small to be of use, return null
191  // (these 3-5 digit numbers can be valid, but are not useful for correlation)
192  if (value.length() <= 5) {
193  return null;
194  }
195  }
196 
197  } else if (correlationType.getId() == CorrelationAttribute.USBID_TYPE_ID
198  && BlackboardArtifact.ARTIFACT_TYPE.TSK_DEVICE_ATTACHED.getTypeID() == artifactTypeID) {
199 
200  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_ID)).getValueString();
201  }
202 
203  } catch (TskCoreException ex) {
204  LOGGER.log(Level.SEVERE, "Error getting attribute while getting type from BlackboardArtifact.", ex); // NON-NLS
205  return null;
206  }
207 
208  if (null != value) {
209  return new CorrelationAttribute(correlationType, value);
210  } else {
211  return null;
212  }
213  }
214 
231  public static CorrelationAttribute getCorrelationAttributeFromContent(Content content, TskData.FileKnown knownStatus, String comment) {
232 
233  if (!(content instanceof AbstractFile)) {
234  return null;
235  }
236 
237  final AbstractFile af = (AbstractFile) content;
238 
239  if (!isValidCentralRepoFile(af)) {
240  return null;
241  }
242 
243  // We need a hash to make the artifact
244  String md5 = af.getMd5Hash();
245  if (md5 == null || md5.isEmpty() || HashUtility.isNoDataMd5(md5)) {
246  return null;
247  }
248 
249  CorrelationAttribute eamArtifact;
250  try {
252  eamArtifact = new CorrelationAttribute(filesType, af.getMd5Hash());
254  if (null == correlationCase) {
255  correlationCase = EamDb.getInstance().newCase(Case.getCurrentCase());
256  }
258  correlationCase,
259  CorrelationDataSource.fromTSKDataSource(correlationCase, af.getDataSource()),
260  af.getParentPath() + af.getName(),
261  comment,
262  knownStatus
263  );
264  eamArtifact.addInstance(cei);
265  return eamArtifact;
266  } catch (TskCoreException | EamDbException ex) {
267  LOGGER.log(Level.SEVERE, "Error making correlation attribute.", ex);
268  return null;
269  }
270  }
271 
281  public static boolean isValidCentralRepoFile(AbstractFile af) {
282  if (af == null) {
283  return false;
284  }
285 
286  if (af.getKnown() == TskData.FileKnown.KNOWN) {
287  return false;
288  }
289 
290  switch (af.getType()) {
291  case UNALLOC_BLOCKS:
292  case UNUSED_BLOCKS:
293  case SLACK:
294  case VIRTUAL_DIR:
295  case LOCAL_DIR:
296  return false;
297  case CARVED:
298  case DERIVED:
299  case LOCAL:
300  return true;
301  case FS:
302  return af.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC);
303  default:
304  LOGGER.log(Level.WARNING, "Unexpected file type {0}", af.getType().getName());
305  return false;
306  }
307  }
308 }
CorrelationAttribute.Type getCorrelationTypeById(int typeId)
static CorrelationAttribute getCorrelationAttributeFromContent(Content content, TskData.FileKnown knownStatus, String comment)
static CorrelationAttribute getCorrelationAttributeFromBlackboardArtifact(CorrelationAttribute.Type correlationType, BlackboardArtifact bbArtifact)
CorrelationCase newCase(CorrelationCase eamCase)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
void addInstance(CorrelationAttributeInstance artifactInstance)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
List< CorrelationAttribute.Type > getDefinedCorrelationTypes()
static List< CorrelationAttribute > getCorrelationAttributeFromBlackboardArtifact(BlackboardArtifact bbArtifact, boolean addInstanceDetails, boolean checkEnabled)

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