Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DomainSearch.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020-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.discovery.search;
20 
21 import java.awt.Image;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.LinkedHashMap;
25 import java.util.List;
26 import java.util.Map;
27 import org.apache.commons.lang3.StringUtils;
31 import org.sleuthkit.datamodel.BlackboardArtifact;
32 import org.sleuthkit.datamodel.BlackboardAttribute;
33 import org.sleuthkit.datamodel.SleuthkitCase;
34 import org.sleuthkit.datamodel.TskCoreException;
35 
39 public class DomainSearch {
40 
41  private final DomainSearchCache searchCache;
44 
48  public DomainSearch() {
49  this(new DomainSearchCache(), new DomainSearchThumbnailCache(),
51  }
52 
61  DomainSearch(DomainSearchCache cache, DomainSearchThumbnailCache thumbnailCache,
62  DomainSearchArtifactsCache artifactsCache) {
63  this.searchCache = cache;
64  this.thumbnailCache = thumbnailCache;
65  this.artifactsCache = artifactsCache;
66  }
67 
86  public Map<GroupKey, Integer> getGroupSizes(String userName,
87  List<AbstractFilter> filters,
88  DiscoveryAttributes.AttributeType groupAttributeType,
89  Group.GroupSortingAlgorithm groupSortingType,
90  ResultsSorter.SortingMethod domainSortingMethod,
91  SleuthkitCase caseDb, CentralRepository centralRepoDb) throws DiscoveryException {
92 
93  final Map<GroupKey, List<Result>> searchResults = searchCache.get(
94  userName, filters, groupAttributeType, groupSortingType,
95  domainSortingMethod, caseDb, centralRepoDb);
96  // Transform the cached results into a map of group key to group size.
97  final LinkedHashMap<GroupKey, Integer> groupSizes = new LinkedHashMap<>();
98  for (GroupKey groupKey : searchResults.keySet()) {
99  groupSizes.put(groupKey, searchResults.get(groupKey).size());
100  }
101 
102  return groupSizes;
103  }
104 
127  public List<Result> getDomainsInGroup(String userName,
128  List<AbstractFilter> filters,
129  DiscoveryAttributes.AttributeType groupAttributeType,
130  Group.GroupSortingAlgorithm groupSortingType,
131  ResultsSorter.SortingMethod domainSortingMethod,
132  GroupKey groupKey, int startingEntry, int numberOfEntries,
133  SleuthkitCase caseDb, CentralRepository centralRepoDb) throws DiscoveryException {
134 
135  final Map<GroupKey, List<Result>> searchResults = searchCache.get(
136  userName, filters, groupAttributeType, groupSortingType,
137  domainSortingMethod, caseDb, centralRepoDb);
138  final List<Result> domainsInGroup = searchResults.get(groupKey);
139  final List<Result> page = new ArrayList<>();
140  for (int i = startingEntry; (i < startingEntry + numberOfEntries)
141  && (i < domainsInGroup.size()); i++) {
142  page.add(domainsInGroup.get(i));
143  }
144 
145  return page;
146  }
147 
165  public Image getThumbnail(DomainSearchThumbnailRequest thumbnailRequest) throws DiscoveryException {
166  return thumbnailCache.get(thumbnailRequest);
167  }
168 
184  public List<BlackboardArtifact> getArtifacts(DomainSearchArtifactsRequest artifactsRequest) throws DiscoveryException {
185  return artifactsCache.get(artifactsRequest);
186  }
187 
200  public List<MiniTimelineResult> getAllArtifactsForDomain(SleuthkitCase sleuthkitCase, String domain) throws DiscoveryException {
201  List<BlackboardArtifact> artifacts = new ArrayList<>();
202  Map<String, List<BlackboardArtifact>> dateMap = new HashMap<>();
203  if (!StringUtils.isBlank(domain)) {
204  for (BlackboardArtifact.ARTIFACT_TYPE type : SearchData.Type.DOMAIN.getArtifactTypes()) {
205 
206  artifacts.addAll(getArtifacts(new DomainSearchArtifactsRequest(sleuthkitCase, domain, type)));
207  }
208 
209  for (BlackboardArtifact artifact : artifacts) {
210  String date;
211  try {
212  date = getDate(artifact);
213  } catch (TskCoreException ex) {
214  throw new DiscoveryException("Unable to get date for artifact with ID: " + artifact.getArtifactID(), ex);
215  }
216  if (!StringUtils.isBlank(date)) {
217  List<BlackboardArtifact> artifactList = dateMap.get(date);
218  if (artifactList == null) {
219  artifactList = new ArrayList<>();
220  }
221  artifactList.add(artifact);
222  dateMap.put(date, artifactList);
223  }
224  }
225  }
226  List<MiniTimelineResult> dateArtifactList = new ArrayList<>();
227 
228  for (String date : dateMap.keySet()) {
229  dateArtifactList.add(new MiniTimelineResult(date, dateMap.get(date)));
230  }
231  return dateArtifactList;
232  }
233 
244  private String getDate(BlackboardArtifact artifact) throws TskCoreException {
245  for (BlackboardAttribute attribute : artifact.getAttributes()) {
246  if (attribute.getAttributeType().getTypeName().startsWith("TSK_DATETIME")) {
247  String dateString = TimeZoneUtils.getFormattedTime(attribute.getValueLong());
248  if (dateString.length() >= 10) {
249  return dateString.substring(0, 10);
250  }
251  }
252  }
253  return "";
254  }
255 
256 }
List< BlackboardArtifact > get(DomainSearchArtifactsRequest request)
List< Result > getDomainsInGroup(String userName, List< AbstractFilter > filters, DiscoveryAttributes.AttributeType groupAttributeType, Group.GroupSortingAlgorithm groupSortingType, ResultsSorter.SortingMethod domainSortingMethod, GroupKey groupKey, int startingEntry, int numberOfEntries, SleuthkitCase caseDb, CentralRepository centralRepoDb)
static String getFormattedTime(long epochTime)
List< BlackboardArtifact > getArtifacts(DomainSearchArtifactsRequest artifactsRequest)
final DomainSearchArtifactsCache artifactsCache
final DomainSearchThumbnailCache thumbnailCache
Map< GroupKey, Integer > getGroupSizes(String userName, List< AbstractFilter > filters, DiscoveryAttributes.AttributeType groupAttributeType, Group.GroupSortingAlgorithm groupSortingType, ResultsSorter.SortingMethod domainSortingMethod, SleuthkitCase caseDb, CentralRepository centralRepoDb)
List< MiniTimelineResult > getAllArtifactsForDomain(SleuthkitCase sleuthkitCase, String domain)
String getDate(BlackboardArtifact artifact)
Image getThumbnail(DomainSearchThumbnailRequest thumbnailRequest)

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