Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceUsageAnalyzer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-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.recentactivity;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.logging.Level;
25 import org.apache.commons.io.FilenameUtils;
26 import org.openide.util.NbBundle.Messages;
31 import org.sleuthkit.datamodel.AbstractFile;
32 import org.sleuthkit.datamodel.BlackboardArtifact;
33 import org.sleuthkit.datamodel.BlackboardAttribute;
34 import org.sleuthkit.datamodel.Content;
35 import org.sleuthkit.datamodel.FileSystem;
36 import org.sleuthkit.datamodel.Image;
37 import org.sleuthkit.datamodel.TskCoreException;
38 import org.sleuthkit.datamodel.TskData;
39 
45 @Messages({"DataSourceUsageAnalyzer.parentModuleName=Recent Activity"})
46 class DataSourceUsageAnalyzer extends Extract {
47 
48  private static final Logger logger = Logger.getLogger(DataSourceUsageAnalyzer.class.getName());
49  private static final int FAT_EXFAT_FLAGS = TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_FAT16.getValue()
50  | TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_FAT32.getValue()
51  | TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_EXFAT.getValue();
52  private static final long HUNDRED_GB = 100 * 1024 * 1024 * 1024l;
53 
54  private static final String ANDROID_MEDIACARD_ROOT_FILENAMES[]
55  = // files expected in root folder of an Android media card
56  {".android_secure", "android", "audio",
57  "photos", "dcim", "music", "pictures", "videos"}; //NON-NLS
58  private Content dataSource;
59 
60  @Messages({
61  "# {0} - OS name",
62  "DataSourceUsageAnalyzer.customVolume.label=OS Drive ({0})",
63  "Progress_Message_Analyze_Usage=Data Sources Usage Analysis",})
64  @Override
65  void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) {
66  this.dataSource = dataSource;
67  try {
68  progressBar.progress(Bundle.Progress_Message_Analyze_Usage());
69  createDataSourceUsageArtifacts(context);
70  } catch (TskCoreException ex) {
71  logger.log(Level.WARNING, "Failed to check if datasource contained a volume with operating system specific files", ex);
72  }
73 
74  }
75 
76  private void createDataSourceUsageArtifacts(IngestJobContext context) throws TskCoreException {
77 
78  createOSInfoDataSourceUsageArtifacts();
79 
80  if (context.dataSourceIngestIsCancelled()) {
81  return;
82  }
83 
84  createAndroidMediaCardArtifacts();
85 
86  if (context.dataSourceIngestIsCancelled()) {
87  return;
88  }
89 
90  createDJIDroneDATArtitifacts();
91  }
92 
99  private void createOSInfoDataSourceUsageArtifacts() throws TskCoreException {
100  boolean windowsOsDetected = false;
101  List<BlackboardArtifact> osInfoArtifacts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO);
102  for (BlackboardArtifact osInfoArt : osInfoArtifacts) {
103  //if it is the current data source
104  if (osInfoArt.getDataSource().getId() == dataSource.getId()) {
105  BlackboardAttribute progNameAttr = osInfoArt.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME));
106  if (progNameAttr != null) {
107  if (progNameAttr.getValueString().isEmpty()) {
108  //skip empty Program Name text
109  } else if (progNameAttr.getDisplayString().toLowerCase().contains("windows")) { //non-nls
110  windowsOsDetected = true;
111  //use the program name when it appears to be windows
112  createDataSourceUsageArtifact(Bundle.DataSourceUsageAnalyzer_customVolume_label(progNameAttr.getDisplayString()));
113  } else {
114  ExtractOs.OS_TYPE osType = ExtractOs.OS_TYPE.fromOsInfoLabel(progNameAttr.getValueString());
115  if (osType != null) {
116  createDataSourceUsageArtifact(osType.getDsUsageLabel());
117  } else {
118  //unable to determine name for DATA_SOURCE_USAGE artifact using program name
119  createDataSourceUsageArtifact(Bundle.DataSourceUsageAnalyzer_customVolume_label(progNameAttr.getDisplayString()));
120  }
121  }
122  }
123  }
124  }
125  if (!windowsOsDetected) { //if we didn't find a windows OS_INFO artifact check if we still think it is a windows volume
126  checkIfOsSpecificVolume(ExtractOs.OS_TYPE.WINDOWS);
127  }
128  }
129 
139  private void createDataSourceUsageArtifact(String dataSourceUsageDescription) throws TskCoreException {
140  //if the data source usage description is not empty create a data source usage artifact if an Usage artifact does not already exist with the same description
141  List<BlackboardArtifact> artifacts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE, dataSource.getId());
142  for (BlackboardArtifact artifact : artifacts) {
143  if (artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION)).getValueString().equals(dataSourceUsageDescription)) {
144  return; //already exists don't create a duplicate
145  }
146  }
147  Collection<BlackboardAttribute> bbattributes = new ArrayList<>();
148  bbattributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION,
149  Bundle.DataSourceUsageAnalyzer_parentModuleName(),
150  dataSourceUsageDescription)); //NON-NLS
151  postArtifact(createArtifactWithAttributes(BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE, dataSource, bbattributes));
152  }
153 
161  private void checkIfOsSpecificVolume(ExtractOs.OS_TYPE osType) throws TskCoreException {
162  for (String filePath : osType.getFilePaths()) {
163  for (AbstractFile file : currentCase.getSleuthkitCase().getFileManager().findFilesExactNameExactPath(dataSource,
164  FilenameUtils.getName(filePath), FilenameUtils.getPath(filePath))) {
165  createDataSourceUsageArtifact(osType.getDsUsageLabel());
166  return;
167  }
168  }
169  }
170 
179  @Messages({
180  "DataSourceUsage_AndroidMedia=Android Media Card",
181  "DataSourceUsage_FlashDrive=Flash Drive"
182  })
183  private void createAndroidMediaCardArtifacts() {
184 
185  if (dataSource instanceof Image) {
186  Image image = (Image) dataSource;
187  try {
188  if (image.getSize() > HUNDRED_GB) {
189  return;
190  }
191 
192  List<FileSystem> fileSystems = image.getFileSystems();
193  if (fileSystems.isEmpty() || fileSystems.size() > 1) {
194  return;
195  }
196 
197  FileSystem fileSystem = fileSystems.get(0);
198  if (fileSystem == null || (fileSystem.getFsType().getValue() & FAT_EXFAT_FLAGS) == 0) {
199  return;
200  }
201 
202  if(hasAndroidMediaCardRootNames()) {
203  return;
204  }
205 
206  // If none of the Android paths is found but it meets other criteria, it might be just a flash drive
207  createDataSourceUsageArtifact(Bundle.DataSourceUsage_FlashDrive());
208 
209  } catch (TskCoreException ex) {
210  logger.log(Level.SEVERE, "Exception while checking image: {0} for Andriod media card", image.getName() + ex.getMessage()); //NON-NLS
211  }
212  }
213  }
214 
222  private boolean hasAndroidMediaCardRootNames() throws TskCoreException{
223  FileManager fileManager = currentCase.getServices().getFileManager();
224  for (String fileName : ANDROID_MEDIACARD_ROOT_FILENAMES) {
225  for (AbstractFile file : fileManager.findFiles(dataSource, fileName, "/")) { // NON-NLS
226  if (file.getParentPath().equals("/") && file.getName().equalsIgnoreCase(fileName)) { // NON-NLS
227  createDataSourceUsageArtifact(Bundle.DataSourceUsage_AndroidMedia());
228  return true;
229  }
230  }
231  }
232 
233  return false;
234  }
235 
244  @Messages({
245  "DataSourceUsage_DJU_Drone_DAT=DJI Internal SD Card"
246  })
247  private void createDJIDroneDATArtitifacts() throws TskCoreException {
248  FileManager fileManager = currentCase.getServices().getFileManager();
249  // The underscores are SQL wild cards.
250  List<AbstractFile> files = fileManager.findFiles(dataSource, "FLY___.DAT");
251  if (files != null && !files.isEmpty()) {
252  createDataSourceUsageArtifact(Bundle.DataSourceUsage_DJU_Drone_DAT());
253  }
254  }
255 }

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