Autopsy  4.17.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 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 java.util.TimeZone;
28 import org.apache.commons.lang3.StringUtils;
32 import org.sleuthkit.datamodel.BlackboardArtifact;
33 import org.sleuthkit.datamodel.BlackboardAttribute;
34 import org.sleuthkit.datamodel.SleuthkitCase;
35 import org.sleuthkit.datamodel.TimeUtilities;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
41 public class DomainSearch {
42 
43  private final DomainSearchCache searchCache;
46 
50  public DomainSearch() {
51  this(new DomainSearchCache(), new DomainSearchThumbnailCache(),
53  }
54 
63  DomainSearch(DomainSearchCache cache, DomainSearchThumbnailCache thumbnailCache,
64  DomainSearchArtifactsCache artifactsCache) {
65  this.searchCache = cache;
66  this.thumbnailCache = thumbnailCache;
67  this.artifactsCache = artifactsCache;
68  }
69 
88  public Map<GroupKey, Integer> getGroupSizes(String userName,
89  List<AbstractFilter> filters,
90  DiscoveryAttributes.AttributeType groupAttributeType,
91  Group.GroupSortingAlgorithm groupSortingType,
92  ResultsSorter.SortingMethod domainSortingMethod,
93  SleuthkitCase caseDb, CentralRepository centralRepoDb) throws DiscoveryException {
94 
95  final Map<GroupKey, List<Result>> searchResults = searchCache.get(
96  userName, filters, groupAttributeType, groupSortingType,
97  domainSortingMethod, caseDb, centralRepoDb);
98 
99  // Transform the cached results into a map of group key to group size.
100  final LinkedHashMap<GroupKey, Integer> groupSizes = new LinkedHashMap<>();
101  for (GroupKey groupKey : searchResults.keySet()) {
102  groupSizes.put(groupKey, searchResults.get(groupKey).size());
103  }
104 
105  return groupSizes;
106  }
107 
130  public List<Result> getDomainsInGroup(String userName,
131  List<AbstractFilter> filters,
132  DiscoveryAttributes.AttributeType groupAttributeType,
133  Group.GroupSortingAlgorithm groupSortingType,
134  ResultsSorter.SortingMethod domainSortingMethod,
135  GroupKey groupKey, int startingEntry, int numberOfEntries,
136  SleuthkitCase caseDb, CentralRepository centralRepoDb) throws DiscoveryException {
137 
138  final Map<GroupKey, List<Result>> searchResults = searchCache.get(
139  userName, filters, groupAttributeType, groupSortingType,
140  domainSortingMethod, caseDb, centralRepoDb);
141  final List<Result> domainsInGroup = searchResults.get(groupKey);
142 
143  final List<Result> page = new ArrayList<>();
144  for (int i = startingEntry; (i < startingEntry + numberOfEntries)
145  && (i < domainsInGroup.size()); i++) {
146  page.add(domainsInGroup.get(i));
147  }
148 
149  return page;
150  }
151 
169  public Image getThumbnail(DomainSearchThumbnailRequest thumbnailRequest) throws DiscoveryException {
170  return thumbnailCache.get(thumbnailRequest);
171  }
172 
188  public List<BlackboardArtifact> getArtifacts(DomainSearchArtifactsRequest artifactsRequest) throws DiscoveryException {
189  return artifactsCache.get(artifactsRequest);
190  }
191 
204  public List<MiniTimelineResult> getAllArtifactsForDomain(SleuthkitCase sleuthkitCase, String domain) throws DiscoveryException {
205  List<BlackboardArtifact> artifacts = new ArrayList<>();
206  Map<String, List<BlackboardArtifact>> dateMap = new HashMap<>();
207  if (!StringUtils.isBlank(domain)) {
208  for (BlackboardArtifact.ARTIFACT_TYPE type : SearchData.Type.DOMAIN.getArtifactTypes()) {
209 
210  artifacts.addAll(getArtifacts(new DomainSearchArtifactsRequest(sleuthkitCase, domain, type)));
211  }
212 
213  for (BlackboardArtifact artifact : artifacts) {
214  String date;
215  try {
216  date = getDate(artifact);
217  } catch (TskCoreException ex) {
218  throw new DiscoveryException("Unable to get date for artifact with ID: " + artifact.getArtifactID(), ex);
219  }
220  if (!StringUtils.isBlank(date)) {
221  List<BlackboardArtifact> artifactList = dateMap.get(date);
222  if (artifactList == null) {
223  artifactList = new ArrayList<>();
224  }
225  artifactList.add(artifact);
226  dateMap.put(date, artifactList);
227  }
228  }
229  }
230  List<MiniTimelineResult> dateArtifactList = new ArrayList<>();
231 
232  for (String date : dateMap.keySet()) {
233  dateArtifactList.add(new MiniTimelineResult(date, dateMap.get(date)));
234  }
235  return dateArtifactList;
236  }
237 
248  private String getDate(BlackboardArtifact artifact) throws TskCoreException {
249  for (BlackboardAttribute attribute : artifact.getAttributes()) {
250  if (attribute.getAttributeType().getTypeName().startsWith("TSK_DATETIME")) {
251  TimeZone timeZone = ContentUtils.getTimeZone(artifact);
252  String dateString = TimeUtilities.epochToTime(attribute.getValueLong(), timeZone);
253  if (dateString.length() >= 10) {
254  return dateString.substring(0, 10);
255  }
256  }
257  }
258  return "";
259  }
260 
261 }
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)
List< BlackboardArtifact > getArtifacts(DomainSearchArtifactsRequest artifactsRequest)
final DomainSearchArtifactsCache artifactsCache
final DomainSearchThumbnailCache thumbnailCache
static TimeZone getTimeZone(Content content)
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: Tue Jan 19 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.