Autopsy  4.10.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[] = // files expected in root folder of an Android media card
55  {".android_secure", "android", "audio",
56  "photos", "dcim", "music", "pictures", "videos"}; //NON-NLS
57  private Content dataSource;
58 
59  @Messages({
60  "# {0} - OS name",
61  "DataSourceUsageAnalyzer.customVolume.label=OS Drive ({0})",
62  "Progress_Message_Analyze_Usage=Data Sources Usage Analysis",
63  })
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  }
87  private void createOSInfoDataSourceUsageArtifacts() throws TskCoreException {
88  boolean windowsOsDetected = false;
89  List<BlackboardArtifact> osInfoArtifacts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO);
90  for (BlackboardArtifact osInfoArt : osInfoArtifacts) {
91  //if it is the current data source
92  if (osInfoArt.getDataSource().getId() == dataSource.getId()) {
93  BlackboardAttribute progNameAttr = osInfoArt.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME));
94  if (progNameAttr != null) {
95  if (progNameAttr.getValueString().isEmpty()) {
96  //skip empty Program Name text
97  } else if (progNameAttr.getDisplayString().toLowerCase().contains("windows")) { //non-nls
98  windowsOsDetected = true;
99  //use the program name when it appears to be windows
100  createDataSourceUsageArtifact(Bundle.DataSourceUsageAnalyzer_customVolume_label(progNameAttr.getDisplayString()));
101  } else {
102  ExtractOs.OS_TYPE osType = ExtractOs.OS_TYPE.fromOsInfoLabel(progNameAttr.getValueString());
103  if (osType != null) {
104  createDataSourceUsageArtifact(osType.getDsUsageLabel());
105  } else {
106  //unable to determine name for DATA_SOURCE_USAGE artifact using program name
107  createDataSourceUsageArtifact(Bundle.DataSourceUsageAnalyzer_customVolume_label(progNameAttr.getDisplayString()));
108  }
109  }
110  }
111  }
112  }
113  if (!windowsOsDetected) { //if we didn't find a windows OS_INFO artifact check if we still think it is a windows volume
114  checkIfOsSpecificVolume(ExtractOs.OS_TYPE.WINDOWS);
115  }
116  }
117 
127  private void createDataSourceUsageArtifact(String dataSourceUsageDescription) throws TskCoreException {
128  //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
129  List<BlackboardArtifact> artifacts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE, dataSource.getId());
130  for (BlackboardArtifact artifact : artifacts) {
131  if (artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION)).getValueString().equals(dataSourceUsageDescription)) {
132  return; //already exists don't create a duplicate
133  }
134  }
135  Collection<BlackboardAttribute> bbattributes = new ArrayList<>();
136  bbattributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION,
137  Bundle.DataSourceUsageAnalyzer_parentModuleName(),
138  dataSourceUsageDescription)); //NON-NLS
139  addArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE, dataSource, bbattributes);
140  }
141 
151  private void checkIfOsSpecificVolume(ExtractOs.OS_TYPE osType) throws TskCoreException {
152  FileManager fileManager = currentCase.getServices().getFileManager();
153  for (String filePath : osType.getFilePaths()) {
154  for (AbstractFile file : fileManager.findFiles(dataSource, FilenameUtils.getName(filePath), FilenameUtils.getPath(filePath))) {
155  if ((file.getParentPath() + file.getName()).equals(filePath)) {
156  createDataSourceUsageArtifact(osType.getDsUsageLabel());
157  return;
158  }
159  }
160  }
161  }
162 
171  @Messages({
172  "DataSourceUsage_AndroidMedia=Android Media Card",
173  "DataSourceUsage_FlashDrive=Flash Drive"
174  })
175  private void createAndroidMediaCardArtifacts() throws TskCoreException {
176 
177  if (dataSource instanceof Image) {
178  Image image = (Image) dataSource;
179  try {
180  if (image.getSize() > HUNDRED_GB) {
181  return;
182  }
183 
184  List<FileSystem> fileSystems = image.getFileSystems();
185  if (fileSystems.isEmpty() || fileSystems.size() > 1) {
186  return;
187  }
188 
189  FileSystem fileSystem = fileSystems.get(0);
190  if ( fileSystem == null || (fileSystem.getFsType().getValue() & FAT_EXFAT_FLAGS) == 0) {
191  return ;
192  }
193 
194  FileManager fileManager = currentCase.getServices().getFileManager();
195  for (String fileName : ANDROID_MEDIACARD_ROOT_FILENAMES ) {
196  for (AbstractFile file : fileManager.findFiles(dataSource, fileName, "/")) { // NON-NLS
197  if (file.getParentPath().equals("/") && file.getName().equalsIgnoreCase(fileName)) { // NON-NLS
198  createDataSourceUsageArtifact(Bundle.DataSourceUsage_AndroidMedia());
199  return;
200  }
201  }
202  }
203 
204  // If none of the Android paths is found but it meets other criteria, it might be just a flash drive
205  createDataSourceUsageArtifact(Bundle.DataSourceUsage_FlashDrive());
206 
207  } catch (TskCoreException ex) {
208  logger.log(Level.SEVERE, "Exception while checking image: {0} for Andriod media card", image.getName() + ex.getMessage()); //NON-NLS
209  }
210  }
211  }
212 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.