Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AnalysisSummary.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.datasourcesummary.datamodel;
20 
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29 import java.util.function.Function;
30 import java.util.stream.Collectors;
31 import org.apache.commons.lang3.StringUtils;
32 import org.apache.commons.lang3.tuple.Pair;
34 import org.sleuthkit.datamodel.BlackboardArtifact;
35 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
36 import org.sleuthkit.datamodel.BlackboardAttribute;
37 import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
38 import org.sleuthkit.datamodel.DataSource;
39 import org.sleuthkit.datamodel.SleuthkitCase;
40 import org.sleuthkit.datamodel.TskCoreException;
41 
46 
47  private static final BlackboardAttribute.Type TYPE_SET_NAME = new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_SET_NAME);
48 
49  private static final Set<String> EXCLUDED_KEYWORD_SEARCH_ITEMS = new HashSet<>(Arrays.asList(
50  "PHONE NUMBERS",
51  "IP ADDRESSES",
52  "EMAIL ADDRESSES",
53  "URLS",
54  "CREDIT CARD NUMBERS"
55  ));
56 
57  private static final Set<Integer> ARTIFACT_UPDATE_TYPE_IDS = new HashSet<>(Arrays.asList(
58  ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID(),
59  ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID(),
60  ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID(),
61  ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()
62  ));
63 
65 
69  public AnalysisSummary() {
71  }
72 
79  this.provider = provider;
80  }
81 
82  @Override
83  public Set<Integer> getArtifactTypeIdsForRefresh() {
85  }
86 
97  public List<Pair<String, Long>> getHashsetCounts(DataSource dataSource) throws SleuthkitCaseProviderException, TskCoreException {
98  return getCountsData(dataSource, TYPE_SET_NAME, ARTIFACT_TYPE.TSK_HASHSET_HIT);
99  }
100 
111  public List<Pair<String, Long>> getKeywordCounts(DataSource dataSource) throws SleuthkitCaseProviderException, TskCoreException {
112  return getCountsData(dataSource, TYPE_SET_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT).stream()
113  // make sure we have a valid set and that that set does not belong to the set of excluded items
114  .filter((pair) -> pair != null && pair.getKey() != null && !EXCLUDED_KEYWORD_SEARCH_ITEMS.contains(pair.getKey().toUpperCase().trim()))
115  .collect(Collectors.toList());
116  }
117 
130  public List<Pair<String, Long>> getInterestingItemCounts(DataSource dataSource) throws SleuthkitCaseProviderException, TskCoreException {
131  return getCountsData(dataSource, TYPE_SET_NAME, ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT);
132  }
133 
148  private List<Pair<String, Long>> getCountsData(DataSource dataSource, BlackboardAttribute.Type keyType, ARTIFACT_TYPE... artifactTypes)
149  throws SleuthkitCaseProviderException, TskCoreException {
150 
151  if (dataSource == null) {
152  return Collections.emptyList();
153  }
154 
155  List<BlackboardArtifact> artifacts = new ArrayList<>();
156  SleuthkitCase skCase = provider.get();
157 
158  // get all artifacts in one list for each artifact type
159  for (ARTIFACT_TYPE type : artifactTypes) {
160  artifacts.addAll(skCase.getBlackboard().getArtifacts(type.getTypeID(), dataSource.getId()));
161  }
162 
163  // group those based on the value of the attribute type that should serve as a key
164  Map<String, Long> countedKeys = artifacts.stream()
165  .map((art) -> {
166  String key = DataSourceInfoUtilities.getStringOrNull(art, keyType);
167  return (StringUtils.isBlank(key)) ? null : key;
168  })
169  .filter((key) -> key != null)
170  .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
171 
172  // sort from max to min counts
173  return countedKeys.entrySet().stream()
174  .map((e) -> Pair.of(e.getKey(), e.getValue()))
175  .sorted((a, b) -> -a.getValue().compareTo(b.getValue()))
176  .collect(Collectors.toList());
177  }
178 }
List< Pair< String, Long > > getInterestingItemCounts(DataSource dataSource)
List< Pair< String, Long > > getCountsData(DataSource dataSource, BlackboardAttribute.Type keyType, ARTIFACT_TYPE...artifactTypes)
List< Pair< String, Long > > getHashsetCounts(DataSource dataSource)
List< Pair< String, Long > > getKeywordCounts(DataSource dataSource)

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