Autopsy  4.4.1
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.Exceptions;
25 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.TskCoreException;
33 import org.sleuthkit.datamodel.TskData;
34 import org.sleuthkit.datamodel.TskDataException;
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 
64  public static List<CorrelationAttribute> getCorrelationAttributeFromBlackboardArtifact(BlackboardArtifact bbArtifact,
65  boolean addInstanceDetails, boolean checkEnabled) {
66 
67  List<CorrelationAttribute> eamArtifacts = new ArrayList<>();
68 
69  try {
70  // Cycle through the types and see if there is a correlation attribute that works
71  // for the given blackboard artifact
72  //
73  // @@@ This seems ineffecient. Instead of cycling based on correlation type, we should just
74  // have switch based on artifact type
76  if ((checkEnabled && aType.isEnabled()) || !checkEnabled) {
78  if (eamArtifact != null) {
79  eamArtifacts.add(eamArtifact);
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  // if they asked for it, add the instance details associated with this occurance.
89  if (!eamArtifacts.isEmpty() && addInstanceDetails) {
90  try {
91  Case currentCase = Case.getCurrentCase();
92  AbstractFile bbSourceFile = currentCase.getSleuthkitCase().getAbstractFileById(bbArtifact.getObjectID());
93  if (null == bbSourceFile) {
94  //@@@ Log this
95  return eamArtifacts;
96  }
97 
98  // make an instance for the BB source file
100  new CorrelationCase(currentCase.getName(), currentCase.getDisplayName()),
101  CorrelationDataSource.fromTSKDataSource(bbSourceFile.getDataSource()),
102  bbSourceFile.getParentPath() + bbSourceFile.getName(),
103  "",
104  TskData.FileKnown.UNKNOWN,
106  );
107 
108  // add the instance details
109  for (CorrelationAttribute eamArtifact : eamArtifacts) {
110  eamArtifact.addInstance(eamInstance);
111  }
112  } catch (TskCoreException | EamDbException ex) {
113  LOGGER.log(Level.SEVERE, "Error creating artifact instance.", ex); // NON-NLS
114  return eamArtifacts;
115  } catch (IllegalStateException ex) {
116  LOGGER.log(Level.SEVERE, "Case is closed.", ex); // NON-NLS
117  return eamArtifacts;
118  }
119  }
120 
121  return eamArtifacts;
122  }
123 
134  private static CorrelationAttribute getCorrelationAttributeFromBlackboardArtifact(CorrelationAttribute.Type correlationType, BlackboardArtifact bbArtifact) {
135  String value = null;
136  int artifactTypeID = bbArtifact.getArtifactTypeID();
137 
138  try {
139  if(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID() == artifactTypeID){
140  // Get the associated artifact
141  BlackboardAttribute attribute = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
142  if (attribute != null) {
143  BlackboardArtifact associatedArtifact = Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifact(attribute.getValueLong());
144  return EamArtifactUtil.getCorrelationAttributeFromBlackboardArtifact(correlationType, associatedArtifact);
145  }
146 
147  } else if (correlationType.getId() == CorrelationAttribute.EMAIL_TYPE_ID
148  && BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID() == artifactTypeID) {
149 
150  BlackboardAttribute setNameAttr = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME));
151  if (setNameAttr != null
152  && EamArtifactUtil.getEmailAddressAttrString().equals(setNameAttr.getValueString())) {
153  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD)).getValueString();
154  }
155  } else if (correlationType.getId() == CorrelationAttribute.DOMAIN_TYPE_ID
156  && (BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getTypeID() == artifactTypeID
157  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID() == artifactTypeID
158  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID() == artifactTypeID
159  || BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID() == artifactTypeID)) {
160 
161  // Lower-case this to normalize domains
162  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN)).getValueString();
163  } else if (correlationType.getId() == CorrelationAttribute.PHONE_TYPE_ID
164  && (BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT.getTypeID() == artifactTypeID
165  || BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG.getTypeID() == artifactTypeID
166  || BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE.getTypeID() == artifactTypeID)) {
167 
168  if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER))) {
169  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER)).getValueString();
170  } else if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM))) {
171  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM)).getValueString();
172  } else if (null != bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO))) {
173  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO)).getValueString();
174  }
175 
176  // Remove all non-numeric symbols to semi-normalize phone numbers, preserving leading "+" character
177  if (value != null) {
178  String newValue = value.replaceAll("\\D", "");
179  if (value.startsWith("+")) {
180  newValue = "+" + newValue;
181  }
182 
183  value = newValue;
184 
185  // If the resulting phone number is too small to be of use, return null
186  // (these 3-5 digit numbers can be valid, but are not useful for correlation)
187  if(value.length() <= 5){
188  return null;
189  }
190  }
191 
192  } else if (correlationType.getId() == CorrelationAttribute.USBID_TYPE_ID
193  && BlackboardArtifact.ARTIFACT_TYPE.TSK_DEVICE_ATTACHED.getTypeID() == artifactTypeID) {
194 
195  value = bbArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_ID)).getValueString();
196  }
197 
198  } catch (TskCoreException ex) {
199  LOGGER.log(Level.SEVERE, "Error getting attribute while getting type from BlackboardArtifact.", ex); // NON-NLS
200  return null;
201  }
202 
203  if (null != value) {
204  return new CorrelationAttribute(correlationType, value);
205  } else {
206  return null;
207  }
208  }
209 
224  public static CorrelationAttribute getEamArtifactFromContent(Content content, TskData.FileKnown knownStatus, String comment){
225 
226  if(! (content instanceof AbstractFile)){
227  return null;
228  }
229 
230  final AbstractFile af = (AbstractFile) content;
231 
232  if ((af.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)
233  || (af.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)
234  || (af.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)
235  || (af.getKnown() == TskData.FileKnown.KNOWN)
236  || (af.isDir() == true)
237  || (!af.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC))) {
238  return null;
239  }
240 
241  // We need a hash to make the artifact
242  String md5 = af.getMd5Hash();
243  if (md5 == null || md5.isEmpty()) {
244  return null;
245  }
246 
247  CorrelationAttribute eamArtifact;
248  try {
250  eamArtifact = new CorrelationAttribute(filesType, af.getMd5Hash());
253  CorrelationDataSource.fromTSKDataSource(af.getDataSource()),
254  af.getParentPath() + af.getName(),
255  comment,
256  TskData.FileKnown.BAD,
258  );
259  eamArtifact.addInstance(cei);
260  return eamArtifact;
261  } catch (TskCoreException | EamDbException ex) {
262  LOGGER.log(Level.SEVERE, "Error making correlation attribute.", ex);
263  return null;
264  }
265  }
266 }
CorrelationAttribute.Type getCorrelationTypeById(int typeId)
static CorrelationAttribute getCorrelationAttributeFromBlackboardArtifact(CorrelationAttribute.Type correlationType, BlackboardArtifact bbArtifact)
void addInstance(CorrelationAttributeInstance artifactInstance)
static CorrelationAttribute getEamArtifactFromContent(Content content, TskData.FileKnown knownStatus, String comment)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
List< CorrelationAttribute.Type > getDefinedCorrelationTypes()
static List< CorrelationAttribute > getCorrelationAttributeFromBlackboardArtifact(BlackboardArtifact bbArtifact, boolean addInstanceDetails, boolean checkEnabled)

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.