Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CorrelationAttributeUtil.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2017-2021 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.Arrays;
23 import java.util.Collections;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Optional;
27 import java.util.Set;
28 import java.util.logging.Level;
29 import org.openide.util.NbBundle.Messages;
34 import org.sleuthkit.datamodel.AbstractFile;
35 import org.sleuthkit.datamodel.Account;
36 import org.sleuthkit.datamodel.AnalysisResult;
37 import org.sleuthkit.datamodel.BlackboardArtifact;
38 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
39 import org.sleuthkit.datamodel.BlackboardAttribute;
40 import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
41 import org.sleuthkit.datamodel.Content;
42 import org.sleuthkit.datamodel.DataArtifact;
43 import org.sleuthkit.datamodel.DataSource;
44 import org.sleuthkit.datamodel.HashUtility;
45 import org.sleuthkit.datamodel.InvalidAccountIDException;
46 import org.sleuthkit.datamodel.OsAccount;
47 import org.sleuthkit.datamodel.OsAccountInstance;
48 import org.sleuthkit.datamodel.TskCoreException;
49 import org.sleuthkit.datamodel.TskData;
50 
56 
57  private static final Logger logger = Logger.getLogger(CorrelationAttributeUtil.class.getName());
58  private static final List<String> domainsToSkip = Arrays.asList("localhost", "127.0.0.1");
59 
60  // artifact ids that specifically have a TSK_DOMAIN attribute that should be handled by CR
61  private static final Set<Integer> DOMAIN_ARTIFACT_TYPE_IDS = new HashSet<>(Arrays.asList(
62  ARTIFACT_TYPE.TSK_WEB_BOOKMARK.getTypeID(),
63  ARTIFACT_TYPE.TSK_WEB_COOKIE.getTypeID(),
64  ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID(),
65  ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID(),
66  ARTIFACT_TYPE.TSK_WEB_CACHE.getTypeID()
67  ));
68 
79  @Messages({"CorrelationAttributeUtil.emailaddresses.text=Email Addresses"})
80  private static String getEmailAddressAttrDisplayName() {
81  return Bundle.CorrelationAttributeUtil_emailaddresses_text();
82  }
83 
84  public static List<CorrelationAttributeInstance> makeCorrAttrsToSave(DataArtifact artifact) {
85  int artifactTypeID = artifact.getArtifactTypeID();
86  //The account fields in these types are expected to be saved in a TSK_ACCOUNT artifact, which will be processed
87  if (artifactTypeID == ARTIFACT_TYPE.TSK_CALLLOG.getTypeID()
88  || artifactTypeID == ARTIFACT_TYPE.TSK_MESSAGE.getTypeID()
89  || artifactTypeID == ARTIFACT_TYPE.TSK_CONTACT.getTypeID()) {
90  return Collections.emptyList();
91  }
93  }
94 
108  public static List<CorrelationAttributeInstance> makeCorrAttrsToSave(AbstractFile file) {
109  return makeCorrAttrsForSearch(file);
110  }
111 
112  public static List<CorrelationAttributeInstance> makeCorrAttrsToSave(AnalysisResult file) {
113  return Collections.emptyList();
114  }
115 
116  public static List<CorrelationAttributeInstance> makeCorrAttrsToSave(OsAccountInstance osAccountInstance) {
117  return makeCorrAttrsForSearch(osAccountInstance);
118  }
119 
138  public static List<CorrelationAttributeInstance> makeCorrAttrsForSearch(AnalysisResult analysisResult) {
139  List<CorrelationAttributeInstance> correlationAttrs = new ArrayList<>();
140  try {
141  int artifactTypeID = analysisResult.getArtifactTypeID();
142  if (artifactTypeID == ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID()) {
143  BlackboardAttribute assocArtifactAttr = analysisResult.getAttribute(BlackboardAttribute.Type.TSK_ASSOCIATED_ARTIFACT);
144  if (assocArtifactAttr != null) {
145  BlackboardArtifact sourceArtifact = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboardArtifact(assocArtifactAttr.getValueLong());
146  if (sourceArtifact instanceof DataArtifact) {
147  correlationAttrs.addAll((CorrelationAttributeUtil.makeCorrAttrsForSearch((DataArtifact) sourceArtifact)));
148  } else if (sourceArtifact instanceof AnalysisResult) {
149  correlationAttrs.addAll((CorrelationAttributeUtil.makeCorrAttrsForSearch((AnalysisResult) sourceArtifact)));
150  } else {
151  String sourceName = sourceArtifact != null ? "SourceArtifact display name: " + sourceArtifact.getDisplayName() : "SourceArtifact was null";
152  logger.log(Level.WARNING, "Source artifact found through TSK_ASSOCIATED_ARTIFACT attribute was not a DataArtifact or "
153  + "an Analysis Result. AssociateArtifactAttr Value: {0} {1}",
154  new Object[]{assocArtifactAttr.getValueString(), sourceName});
155  }
156 
157  }
158  } else {
159  if (artifactTypeID == ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
160  BlackboardAttribute setNameAttr = analysisResult.getAttribute(BlackboardAttribute.Type.TSK_SET_NAME);
161  if (setNameAttr != null && CorrelationAttributeUtil.getEmailAddressAttrDisplayName().equals(setNameAttr.getValueString())) {
162  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(analysisResult, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD, CorrelationAttributeInstance.EMAIL_TYPE_ID, analysisResult.getAttributes()));
163  }
164  }
165  Content parent = analysisResult.getParent();
166  if (parent instanceof AbstractFile) {
167  correlationAttrs.addAll(CorrelationAttributeUtil.makeCorrAttrsForSearch((AbstractFile) parent));
168  } else if (parent instanceof AnalysisResult) {
169  correlationAttrs.addAll(CorrelationAttributeUtil.makeCorrAttrsForSearch((AnalysisResult) parent));
170  } else if (parent instanceof DataArtifact) {
171  correlationAttrs.addAll(CorrelationAttributeUtil.makeCorrAttrsForSearch((DataArtifact) parent));
172  } else if (parent instanceof OsAccount) {
173  for (OsAccountInstance osAccountInst : ((OsAccount) parent).getOsAccountInstances()) {
174  if (osAccountInst.getDataSource().equals(analysisResult.getDataSource())) {
175  correlationAttrs.addAll(CorrelationAttributeUtil.makeCorrAttrsForSearch(osAccountInst));
176  break;
177  }
178  }
179  }
180  }
181 
182  } catch (TskCoreException ex) {
183  logger.log(Level.SEVERE, "Failed to get information regarding correlation attributes from AnalysisResult", ex);
184  } catch (NoCurrentCaseException ex) {
185  logger.log(Level.SEVERE, "Attempted to retrieve correlation attributes for search with no currently open case.", ex);
186  } catch (CentralRepoException ex) {
187  logger.log(Level.SEVERE, "Failed to get correlation type from central repository.", ex);
188  }
189  return correlationAttrs;
190  }
191 
210  public static List<CorrelationAttributeInstance> makeCorrAttrsForSearch(DataArtifact artifact) {
211  List<CorrelationAttributeInstance> correlationAttrs = new ArrayList<>();
212  try {
213 
214  List<BlackboardAttribute> attributes = artifact.getAttributes();
215 
216  int artifactTypeID = artifact.getArtifactTypeID();
217  if (DOMAIN_ARTIFACT_TYPE_IDS.contains(artifactTypeID)) {
218  BlackboardAttribute domainAttr = getAttribute(attributes, new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_DOMAIN));
219  if ((domainAttr != null)
220  && !domainsToSkip.contains(domainAttr.getValueString())) {
221  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN, CorrelationAttributeInstance.DOMAIN_TYPE_ID, attributes));
222  }
223  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_DEVICE_ATTACHED.getTypeID()) {
224  // prefetch all the information as we will be calling makeCorrAttrFromArtifactAttr() multiple times
225  Content sourceContent = Case.getCurrentCaseThrows().getSleuthkitCase().getContentById(artifact.getObjectID());
226  Content dataSource = sourceContent.getDataSource();
227  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_ID, CorrelationAttributeInstance.USBID_TYPE_ID,
228  attributes, sourceContent, dataSource));
229  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MAC_ADDRESS, CorrelationAttributeInstance.MAC_TYPE_ID,
230  attributes, sourceContent, dataSource));
231  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_WIFI_NETWORK.getTypeID()) {
232  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SSID, CorrelationAttributeInstance.SSID_TYPE_ID, attributes));
233  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_WIFI_NETWORK_ADAPTER.getTypeID()
234  || artifactTypeID == ARTIFACT_TYPE.TSK_BLUETOOTH_PAIRING.getTypeID()
235  || artifactTypeID == ARTIFACT_TYPE.TSK_BLUETOOTH_ADAPTER.getTypeID()) {
236  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_MAC_ADDRESS, CorrelationAttributeInstance.MAC_TYPE_ID, attributes));
237  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_DEVICE_INFO.getTypeID()) {
238  // prefetch all the information as we will be calling makeCorrAttrFromArtifactAttr() multiple times
239  Content sourceContent = Case.getCurrentCaseThrows().getSleuthkitCase().getContentById(artifact.getObjectID());
240  Content dataSource = sourceContent.getDataSource();
241  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IMEI, CorrelationAttributeInstance.IMEI_TYPE_ID,
242  attributes, sourceContent, dataSource));
243  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IMSI, CorrelationAttributeInstance.IMSI_TYPE_ID,
244  attributes, sourceContent, dataSource));
245  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ICCID, CorrelationAttributeInstance.ICCID_TYPE_ID,
246  attributes, sourceContent, dataSource));
247 
248  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_SIM_ATTACHED.getTypeID()) {
249  // prefetch all the information as we will be calling makeCorrAttrFromArtifactAttr() multiple times
250  Content sourceContent = Case.getCurrentCaseThrows().getSleuthkitCase().getContentById(artifact.getObjectID());
251  Content dataSource = sourceContent.getDataSource();
252  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_IMSI, CorrelationAttributeInstance.IMSI_TYPE_ID,
253  attributes, sourceContent, dataSource));
254  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ICCID, CorrelationAttributeInstance.ICCID_TYPE_ID,
255  attributes, sourceContent, dataSource));
256 
257  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_WEB_FORM_ADDRESS.getTypeID()) {
258  // prefetch all the information as we will be calling makeCorrAttrFromArtifactAttr() multiple times
259  Content sourceContent = Case.getCurrentCaseThrows().getSleuthkitCase().getContentById(artifact.getObjectID());
260  Content dataSource = sourceContent.getDataSource();
261  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER, CorrelationAttributeInstance.PHONE_TYPE_ID,
262  attributes, sourceContent, dataSource));
263  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL, CorrelationAttributeInstance.EMAIL_TYPE_ID,
264  attributes, sourceContent, dataSource));
265 
266  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
267  makeCorrAttrFromAcctArtifact(correlationAttrs, artifact);
268 
269  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_INSTALLED_PROG.getTypeID()) {
270  BlackboardAttribute setNameAttr = getAttribute(attributes, new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH));
271  String pathAttrString = null;
272  if (setNameAttr != null) {
273  pathAttrString = setNameAttr.getValueString();
274  }
275  if (pathAttrString != null && !pathAttrString.isEmpty()) {
276  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH, CorrelationAttributeInstance.INSTALLED_PROGS_TYPE_ID, attributes));
277  } else {
278  correlationAttrs.addAll(makeCorrAttrFromArtifactAttr(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, CorrelationAttributeInstance.INSTALLED_PROGS_TYPE_ID, attributes));
279  }
280  } else if (artifactTypeID == ARTIFACT_TYPE.TSK_CONTACT.getTypeID()
281  || artifactTypeID == ARTIFACT_TYPE.TSK_CALLLOG.getTypeID()
282  || artifactTypeID == ARTIFACT_TYPE.TSK_MESSAGE.getTypeID()) {
283  correlationAttrs.addAll(makeCorrAttrsFromCommunicationArtifact(artifact, attributes));
284  }
286  logger.log(Level.WARNING, String.format("Error normalizing correlation attribute (%s)", artifact), ex); // NON-NLS
287  return correlationAttrs;
288  } catch (InvalidAccountIDException ex) {
289  logger.log(Level.WARNING, String.format("Invalid account identifier (artifactID: %d)", artifact.getId())); // NON-NLS
290  return correlationAttrs;
291  } catch (CentralRepoException ex) {
292  logger.log(Level.SEVERE, String.format("Error querying central repository (%s)", artifact), ex); // NON-NLS
293  return correlationAttrs;
294  } catch (TskCoreException ex) {
295  logger.log(Level.SEVERE, String.format("Error getting querying case database (%s)", artifact), ex); // NON-NLS
296  return correlationAttrs;
297  } catch (NoCurrentCaseException ex) {
298  logger.log(Level.SEVERE, "Error getting current case", ex); // NON-NLS
299  return correlationAttrs;
300  }
301  return correlationAttrs;
302  }
303 
314  private static BlackboardAttribute getAttribute(List<BlackboardAttribute> attributes, BlackboardAttribute.Type attributeType) throws TskCoreException {
315  for (BlackboardAttribute attribute : attributes) {
316  if (attribute.getAttributeType().equals(attributeType)) {
317  return attribute;
318  }
319  }
320  return null;
321  }
322 
340  private static List<CorrelationAttributeInstance> makeCorrAttrsFromCommunicationArtifact(BlackboardArtifact artifact,
341  List<BlackboardAttribute> attributes) throws TskCoreException, CentralRepoException, CorrelationAttributeNormalizationException {
342 
343  /*
344  * Extract the phone number from the artifact attribute.
345  */
346  String value = null;
347  if (null != getAttribute(attributes, new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER))) {
348  value = getAttribute(attributes, new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER)).getValueString();
349  } else if (null != getAttribute(attributes, new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM))) {
350  value = getAttribute(attributes, new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM)).getValueString();
351  } else if (null != getAttribute(attributes, new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO))) {
352  value = getAttribute(attributes, new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO)).getValueString();
353  }
354  /*
355  * Normalize the phone number.
356  */
357  List<CorrelationAttributeInstance> corrAttrInstances = Collections.emptyList();
358  if (value != null
359  && CorrelationAttributeNormalizer.isValidPhoneNumber(value)) {
360  value = CorrelationAttributeNormalizer.normalizePhone(value);
362  if (corrAttr != null) {
363  corrAttrInstances.add(corrAttr);
364  }
365  }
366  return corrAttrInstances;
367  }
368 
382  private static void makeCorrAttrFromAcctArtifact(List<CorrelationAttributeInstance> corrAttrInstances, BlackboardArtifact acctArtifact) throws InvalidAccountIDException, TskCoreException, CentralRepoException {
383 
384  // Get the account type from the artifact
385  BlackboardAttribute accountTypeAttribute = acctArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ACCOUNT_TYPE));
386  String accountTypeStr = accountTypeAttribute.getValueString();
387 
388  // @@TODO Vik-6136: CR currently does not know of custom account types.
389  // Ensure there is a predefined account type for this account.
390  Account.Type predefinedAccountType = Account.Type.PREDEFINED_ACCOUNT_TYPES.stream().filter(type -> type.getTypeName().equalsIgnoreCase(accountTypeStr)).findAny().orElse(null);
391 
392  // do not create any correlation attribute instance for a Device account
393  if (Account.Type.DEVICE.getTypeName().equalsIgnoreCase(accountTypeStr) == false && predefinedAccountType != null) {
394 
395  // Get the corresponding CentralRepoAccountType from the database.
396  Optional<CentralRepoAccountType> optCrAccountType = CentralRepository.getInstance().getAccountTypeByName(accountTypeStr);
397  if (!optCrAccountType.isPresent()) {
398  return;
399  }
400  CentralRepoAccountType crAccountType = optCrAccountType.get();
401 
402  int corrTypeId = crAccountType.getCorrelationTypeId();
404 
405  // Get the account identifier
406  BlackboardAttribute accountIdAttribute = acctArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ID));
407  String accountIdStr = accountIdAttribute.getValueString();
408 
409  // add/get the account and get its accountId.
410  CentralRepoAccount crAccount = CentralRepository.getInstance().getOrCreateAccount(crAccountType, accountIdStr);
411 
412  CorrelationAttributeInstance corrAttr = makeCorrAttr(acctArtifact, corrType, accountIdStr);
413  if (corrAttr != null) {
414  // set the account_id in correlation attribute
415  corrAttr.setAccountId(crAccount.getId());
416  corrAttrInstances.add(corrAttr);
417  }
418  }
419  }
420 
440  private static List<CorrelationAttributeInstance> makeCorrAttrFromArtifactAttr(BlackboardArtifact artifact, ATTRIBUTE_TYPE artAttrType, int typeId,
441  List<BlackboardAttribute> attributes, Content sourceContent, Content dataSource) throws CentralRepoException, TskCoreException {
442  List<CorrelationAttributeInstance> corrAttrInstances = new ArrayList<>();
443  BlackboardAttribute attribute = getAttribute(attributes, new BlackboardAttribute.Type(artAttrType));
444  if (attribute != null) {
445  String value = attribute.getValueString();
446  if ((null != value) && (value.isEmpty() == false)) {
447  CorrelationAttributeInstance inst = makeCorrAttr(artifact, CentralRepository.getInstance().getCorrelationTypeById(typeId), value, sourceContent, dataSource);
448  if (inst != null) {
449  corrAttrInstances.add(inst);
450  }
451  }
452  }
453  return corrAttrInstances;
454  }
455 
473  private static List<CorrelationAttributeInstance> makeCorrAttrFromArtifactAttr(BlackboardArtifact artifact, ATTRIBUTE_TYPE artAttrType, int typeId,
474  List<BlackboardAttribute> attributes) throws CentralRepoException, TskCoreException {
475 
476  return makeCorrAttrFromArtifactAttr(artifact, artAttrType, typeId, attributes, null, null);
477  }
478 
496  private static CorrelationAttributeInstance makeCorrAttr(BlackboardArtifact artifact, CorrelationAttributeInstance.Type correlationType, String value) {
497  return makeCorrAttr(artifact, correlationType, value, null, null);
498  }
499 
519  private static CorrelationAttributeInstance makeCorrAttr(BlackboardArtifact artifact, CorrelationAttributeInstance.Type correlationType, String value,
520  Content sourceContent, Content dataSource) {
521  Content srcContent = sourceContent;
522  Content dataSrc = dataSource;
523  try {
524  if (srcContent == null) {
525  srcContent = Case.getCurrentCaseThrows().getSleuthkitCase().getContentById(artifact.getObjectID());
526  }
527  if (null == srcContent) {
528  logger.log(Level.SEVERE, "Error creating artifact instance of type {0}. Failed to load content with ID: {1} associated with artifact with ID: {2}",
529  new Object[]{correlationType.getDisplayName(), artifact.getObjectID(), artifact.getId()}); // NON-NLS
530  return null;
531  }
532  if (dataSrc == null) {
533  dataSrc = srcContent.getDataSource();
534  }
535  if (dataSrc == null) {
536  logger.log(Level.SEVERE, "Error creating artifact instance of type {0}. Failed to load data source for content with ID: {1}",
537  new Object[]{correlationType.getDisplayName(), artifact.getObjectID()}); // NON-NLS
538  return null;
539  }
540 
542  if (artifact.getArtifactTypeID() == ARTIFACT_TYPE.TSK_INSTALLED_PROG.getTypeID()
543  || ! (srcContent instanceof AbstractFile)) {
544  return new CorrelationAttributeInstance(
545  correlationType,
546  value,
547  correlationCase,
548  CorrelationDataSource.fromTSKDataSource(correlationCase, dataSrc),
549  "",
550  "",
551  TskData.FileKnown.UNKNOWN,
552  srcContent.getId());
553  } else {
554  AbstractFile bbSourceFile = (AbstractFile) srcContent;
555 
556  return new CorrelationAttributeInstance(
557  correlationType,
558  value,
559  correlationCase,
560  CorrelationDataSource.fromTSKDataSource(correlationCase, dataSrc),
561  bbSourceFile.getParentPath() + bbSourceFile.getName(),
562  "",
563  TskData.FileKnown.UNKNOWN,
564  bbSourceFile.getId());
565  }
566  } catch (TskCoreException ex) {
567  logger.log(Level.SEVERE, String.format("Error getting querying case database (%s)", artifact), ex); // NON-NLS
568  return null;
569  } catch (CentralRepoException ex) {
570  logger.log(Level.SEVERE, String.format("Error querying central repository (%s)", artifact), ex); // NON-NLS
571  return null;
573  logger.log(Level.WARNING, String.format("Error creating correlation attribute instance (%s)", artifact), ex); // NON-NLS
574  return null;
575  } catch (NoCurrentCaseException ex) {
576  logger.log(Level.SEVERE, "Error getting current case", ex); // NON-NLS
577  return null;
578  }
579  }
580 
581  // @@@ BC: This seems like it should go into a DB-specific class because it is
582  // much different from the other methods in this class. It is going to the DB for data.
601  public static CorrelationAttributeInstance getCorrAttrForFile(AbstractFile file) {
602 
604  return null;
605  }
606 
608  CorrelationCase correlationCase;
609  CorrelationDataSource correlationDataSource;
610 
611  try {
614  if (null == correlationCase) {
615  //if the correlationCase is not in the Central repo then attributes generated in relation to it will not be
616  return null;
617  }
618  correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource());
619  } catch (TskCoreException ex) {
620  logger.log(Level.SEVERE, String.format("Error getting querying case database (%s)", file), ex); // NON-NLS
621  return null;
622  } catch (CentralRepoException ex) {
623  logger.log(Level.SEVERE, String.format("Error querying central repository (%s)", file), ex); // NON-NLS
624  return null;
625  } catch (NoCurrentCaseException ex) {
626  logger.log(Level.SEVERE, "Error getting current case", ex); // NON-NLS
627  return null;
628  }
629 
630  CorrelationAttributeInstance correlationAttributeInstance;
631  try {
632  correlationAttributeInstance = CentralRepository.getInstance().getCorrelationAttributeInstance(type, correlationCase, correlationDataSource, file.getId());
633  } catch (CentralRepoException ex) {
634  logger.log(Level.SEVERE, String.format("Error querying central repository (%s)", file), ex); // NON-NLS
635  return null;
637  logger.log(Level.WARNING, String.format("Error creating correlation attribute instance (%s)", file), ex); // NON-NLS
638  return null;
639  }
640 
641  /*
642  * If no correlation attribute instance was found when querying by file
643  * object ID, try searching by file path instead. This is necessary
644  * because file object IDs were not stored in the central repository in
645  * early versions of its schema.
646  */
647  if (correlationAttributeInstance == null && file.getMd5Hash() != null) {
648  String filePath = (file.getParentPath() + file.getName()).toLowerCase();
649  try {
650  correlationAttributeInstance = CentralRepository.getInstance().getCorrelationAttributeInstance(type, correlationCase, correlationDataSource, file.getMd5Hash(), filePath);
651  } catch (CentralRepoException ex) {
652  logger.log(Level.SEVERE, String.format("Error querying central repository (%s)", file), ex); // NON-NLS
653  return null;
655  logger.log(Level.WARNING, String.format("Error creating correlation attribute instance (%s)", file), ex); // NON-NLS
656  return null;
657  }
658  }
659 
660  return correlationAttributeInstance;
661  }
662 
683  public static List<CorrelationAttributeInstance> makeCorrAttrsForSearch(AbstractFile file) {
684  List<CorrelationAttributeInstance> fileTypeList = new ArrayList<>(); // will be an empty or single element list as was decided in 7852
685  if (!isSupportedAbstractFileType(file)) {
686  return fileTypeList;
687  }
688 
689  // We need a hash to make the correlation artifact instance.
690  String md5 = file.getMd5Hash();
691  if (md5 == null || md5.isEmpty() || HashUtility.isNoDataMd5(md5)) {
692  return fileTypeList;
693  }
694 
695  try {
697 
699  fileTypeList.add(new CorrelationAttributeInstance(
700  filesType,
701  file.getMd5Hash(),
702  correlationCase,
703  CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource()),
704  file.getParentPath() + file.getName(),
705  "",
706  TskData.FileKnown.UNKNOWN,
707  file.getId()));
708  } catch (TskCoreException ex) {
709  logger.log(Level.SEVERE, String.format("Error querying case database (%s)", file), ex); // NON-NLS
710  } catch (CentralRepoException ex) {
711  logger.log(Level.SEVERE, String.format("Error querying central repository (%s)", file), ex); // NON-NLS
713  logger.log(Level.WARNING, String.format("Error creating correlation attribute instance (%s)", file), ex); // NON-NLS
714  } catch (NoCurrentCaseException ex) {
715  logger.log(Level.SEVERE, "Error getting current case", ex); // NON-NLS
716  }
717  return fileTypeList;
718  }
719 
728  public static boolean isSupportedAbstractFileType(AbstractFile file) {
729  if (file == null) {
730  return false;
731  }
732  switch (file.getType()) {
733  case UNALLOC_BLOCKS:
734  case UNUSED_BLOCKS:
735  case SLACK:
736  case VIRTUAL_DIR:
737  case LOCAL_DIR:
738  return false;
739  case CARVED:
740  case DERIVED:
741  case LOCAL:
742  case LAYOUT_FILE:
743  return true;
744  case FS:
745  return file.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC);
746  default:
747  logger.log(Level.WARNING, "Unexpected file type {0}", file.getType().getName());
748  return false;
749  }
750  }
751 
752  public static List<CorrelationAttributeInstance> makeCorrAttrsForSearch(OsAccountInstance osAccountInst) {
753  List<CorrelationAttributeInstance> correlationAttrs = new ArrayList<>();
754  OsAccount account = null;
755  DataSource dataSource = null;
756  if (osAccountInst != null) {
757  try {
758  account = osAccountInst.getOsAccount();
759  dataSource = osAccountInst.getDataSource();
760  } catch (TskCoreException ex) {
761  logger.log(Level.SEVERE, "Error getting information from OsAccountInstance.", ex);
762  }
763  }
764  if (account != null && dataSource != null) {
765  Optional<String> accountAddr = account.getAddr();
766  // Check address if it is null or one of the ones below we want to ignore it since they will always be one a windows system
767  // and they are not unique
768  if (accountAddr.isPresent() && !accountAddr.get().equals("S-1-5-18") && !accountAddr.get().equals("S-1-5-19") && !accountAddr.get().equals("S-1-5-20")) {
769  try {
770 
772  CorrelationAttributeInstance correlationAttributeInstance = new CorrelationAttributeInstance(
774  accountAddr.get(),
775  correlationCase,
776  CorrelationDataSource.fromTSKDataSource(correlationCase, dataSource),
777  "",
778  "",
779  TskData.FileKnown.KNOWN,
780  account.getId());
781  correlationAttrs.add(correlationAttributeInstance);
782  } catch (CentralRepoException ex) {
783  logger.log(Level.SEVERE, String.format("Cannot get central repository for OsAccount: %s.", accountAddr.get()), ex); //NON-NLS
784  } catch (NoCurrentCaseException ex) {
785  logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
787  logger.log(Level.SEVERE, "Exception with Correlation Attribute Normalization.", ex); //NON-NLS
788  }
789  }
790  }
791  return correlationAttrs;
792  }
793 
798  }
799 
800 }
static List< CorrelationAttributeInstance > makeCorrAttrsToSave(OsAccountInstance osAccountInstance)
static CorrelationAttributeInstance makeCorrAttr(BlackboardArtifact artifact, CorrelationAttributeInstance.Type correlationType, String value, Content sourceContent, Content dataSource)
static List< CorrelationAttributeInstance > makeCorrAttrsFromCommunicationArtifact(BlackboardArtifact artifact, List< BlackboardAttribute > attributes)
static List< CorrelationAttributeInstance > makeCorrAttrsForSearch(OsAccountInstance osAccountInst)
static CorrelationAttributeInstance makeCorrAttr(BlackboardArtifact artifact, CorrelationAttributeInstance.Type correlationType, String value)
static List< CorrelationAttributeInstance > makeCorrAttrsForSearch(AbstractFile file)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
static List< CorrelationAttributeInstance > makeCorrAttrFromArtifactAttr(BlackboardArtifact artifact, ATTRIBUTE_TYPE artAttrType, int typeId, List< BlackboardAttribute > attributes, Content sourceContent, Content dataSource)
Optional< CentralRepoAccountType > getAccountTypeByName(String accountTypeName)
static List< CorrelationAttributeInstance > makeCorrAttrsForSearch(DataArtifact artifact)
static List< CorrelationAttributeInstance > makeCorrAttrsToSave(AbstractFile file)
static List< CorrelationAttributeInstance > makeCorrAttrsForSearch(AnalysisResult analysisResult)
static BlackboardAttribute getAttribute(List< BlackboardAttribute > attributes, BlackboardAttribute.Type attributeType)
static CorrelationAttributeInstance getCorrAttrForFile(AbstractFile file)
static List< CorrelationAttributeInstance > makeCorrAttrsToSave(AnalysisResult file)
static List< CorrelationAttributeInstance > makeCorrAttrFromArtifactAttr(BlackboardArtifact artifact, ATTRIBUTE_TYPE artAttrType, int typeId, List< BlackboardAttribute > attributes)
CorrelationAttributeInstance getCorrelationAttributeInstance(CorrelationAttributeInstance.Type type, CorrelationCase correlationCase, CorrelationDataSource correlationDataSource, String value, String filePath)
static List< CorrelationAttributeInstance > makeCorrAttrsToSave(DataArtifact artifact)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void makeCorrAttrFromAcctArtifact(List< CorrelationAttributeInstance > corrAttrInstances, BlackboardArtifact acctArtifact)
CorrelationAttributeInstance.Type getCorrelationTypeById(int typeId)
CentralRepoAccount getOrCreateAccount(CentralRepoAccount.CentralRepoAccountType crAccountType, String accountUniqueID)

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.