Autopsy  4.14.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 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();
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() throws TskCoreException {
77 
78  createOSInfoDataSourceUsageArtifacts();
79  createAndroidMediaCardArtifacts();
80  createDJIDroneDATArtitifacts();
81  }
82 
89  private void createOSInfoDataSourceUsageArtifacts() throws TskCoreException {
90  boolean windowsOsDetected = false;
91  List<BlackboardArtifact> osInfoArtifacts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO);
92  for (BlackboardArtifact osInfoArt : osInfoArtifacts) {
93  //if it is the current data source
94  if (osInfoArt.getDataSource().getId() == dataSource.getId()) {
95  BlackboardAttribute progNameAttr = osInfoArt.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME));
96  if (progNameAttr != null) {
97  if (progNameAttr.getValueString().isEmpty()) {
98  //skip empty Program Name text
99  } else if (progNameAttr.getDisplayString().toLowerCase().contains("windows")) { //non-nls
100  windowsOsDetected = true;
101  //use the program name when it appears to be windows
102  createDataSourceUsageArtifact(Bundle.DataSourceUsageAnalyzer_customVolume_label(progNameAttr.getDisplayString()));
103  } else {
104  ExtractOs.OS_TYPE osType = ExtractOs.OS_TYPE.fromOsInfoLabel(progNameAttr.getValueString());
105  if (osType != null) {
106  createDataSourceUsageArtifact(osType.getDsUsageLabel());
107  } else {
108  //unable to determine name for DATA_SOURCE_USAGE artifact using program name
109  createDataSourceUsageArtifact(Bundle.DataSourceUsageAnalyzer_customVolume_label(progNameAttr.getDisplayString()));
110  }
111  }
112  }
113  }
114  }
115  if (!windowsOsDetected) { //if we didn't find a windows OS_INFO artifact check if we still think it is a windows volume
116  checkIfOsSpecificVolume(ExtractOs.OS_TYPE.WINDOWS);
117  }
118  }
119 
129  private void createDataSourceUsageArtifact(String dataSourceUsageDescription) throws TskCoreException {
130  //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
131  List<BlackboardArtifact> artifacts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE, dataSource.getId());
132  for (BlackboardArtifact artifact : artifacts) {
133  if (artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION)).getValueString().equals(dataSourceUsageDescription)) {
134  return; //already exists don't create a duplicate
135  }
136  }
137  Collection<BlackboardAttribute> bbattributes = new ArrayList<>();
138  bbattributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION,
139  Bundle.DataSourceUsageAnalyzer_parentModuleName(),
140  dataSourceUsageDescription)); //NON-NLS
141  BlackboardArtifact bba = createArtifactWithAttributes(BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE, dataSource, bbattributes);
142  if (bba != null) {
143  postArtifact(bba);
144  }
145  }
146 
156  private void checkIfOsSpecificVolume(ExtractOs.OS_TYPE osType) throws TskCoreException {
157  FileManager fileManager = currentCase.getServices().getFileManager();
158  for (String filePath : osType.getFilePaths()) {
159  for (AbstractFile file : fileManager.findFiles(dataSource, FilenameUtils.getName(filePath), FilenameUtils.getPath(filePath))) {
160  if ((file.getParentPath() + file.getName()).equals(filePath)) {
161  createDataSourceUsageArtifact(osType.getDsUsageLabel());
162  return;
163  }
164  }
165  }
166  }
167 
176  @Messages({
177  "DataSourceUsage_AndroidMedia=Android Media Card",
178  "DataSourceUsage_FlashDrive=Flash Drive"
179  })
180  private void createAndroidMediaCardArtifacts() {
181 
182  if (dataSource instanceof Image) {
183  Image image = (Image) dataSource;
184  try {
185  if (image.getSize() > HUNDRED_GB) {
186  return;
187  }
188 
189  List<FileSystem> fileSystems = image.getFileSystems();
190  if (fileSystems.isEmpty() || fileSystems.size() > 1) {
191  return;
192  }
193 
194  FileSystem fileSystem = fileSystems.get(0);
195  if (fileSystem == null || (fileSystem.getFsType().getValue() & FAT_EXFAT_FLAGS) == 0) {
196  return;
197  }
198 
199  if(hasAndroidMediaCardRootNames()) {
200  return;
201  }
202 
203  // If none of the Android paths is found but it meets other criteria, it might be just a flash drive
204  createDataSourceUsageArtifact(Bundle.DataSourceUsage_FlashDrive());
205 
206  } catch (TskCoreException ex) {
207  logger.log(Level.SEVERE, "Exception while checking image: {0} for Andriod media card", image.getName() + ex.getMessage()); //NON-NLS
208  }
209  }
210  }
211 
219  private boolean hasAndroidMediaCardRootNames() throws TskCoreException{
220  FileManager fileManager = currentCase.getServices().getFileManager();
221  for (String fileName : ANDROID_MEDIACARD_ROOT_FILENAMES) {
222  for (AbstractFile file : fileManager.findFiles(dataSource, fileName, "/")) { // NON-NLS
223  if (file.getParentPath().equals("/") && file.getName().equalsIgnoreCase(fileName)) { // NON-NLS
224  createDataSourceUsageArtifact(Bundle.DataSourceUsage_AndroidMedia());
225  return true;
226  }
227  }
228  }
229 
230  return false;
231  }
232 
241  @Messages({
242  "DataSourceUsage_DJU_Drone_DAT=DJI Internal SD Card"
243  })
244  private void createDJIDroneDATArtitifacts() throws TskCoreException {
245  FileManager fileManager = currentCase.getServices().getFileManager();
246  // The underscores are SQL wild cards.
247  List<AbstractFile> files = fileManager.findFiles(dataSource, "FLY___.DAT");
248  if (files != null && !files.isEmpty()) {
249  createDataSourceUsageArtifact(Bundle.DataSourceUsage_DJU_Drone_DAT());
250  }
251  }
252 }

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