Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExtractOs.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.Arrays;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.logging.Level;
27 import org.apache.commons.io.FilenameUtils;
28 import org.openide.util.NbBundle.Messages;
33 import org.sleuthkit.datamodel.AbstractFile;
34 import org.sleuthkit.datamodel.BlackboardArtifact;
35 import org.sleuthkit.datamodel.BlackboardAttribute;
36 import org.sleuthkit.datamodel.Content;
37 import org.sleuthkit.datamodel.TskCoreException;
38 
43 @Messages({"ExtractOs.parentModuleName=Recent Activity",
44  "ExtractOS_progressMessage=Checking for OS"})
45 class ExtractOs extends Extract {
46 
47  private static final Logger logger = Logger.getLogger(ExtractOs.class.getName());
48 
49  private static final String WINDOWS_VOLUME_PATH = "/windows/system32";
50  private static final String OSX_VOLUME_PATH = "/System/Library/CoreServices/SystemVersion.plist";
51  private static final String ANDROID_VOLUME_PATH = "/data/com.android.providers.settings/databases/settings.db";
52  //linux specific files reference https://www.novell.com/coolsolutions/feature/11251.html
53  private static final String LINUX_RED_HAT_PATHS[] = {"/etc/redhat-release", "/etc/redhat_version"};
54  private static final String LINUX_NOVELL_SUSE_PATH = "/etc/SUSE-release";
55  private static final String LINUX_FEDORA_PATH = "/etc/fedora-release";
56  private static final String LINUX_SLACKWARE_PATHS[] = {"/etc/slackware-release", "/etc/slackware-version"};
57  private static final String LINUX_DEBIAN_PATHS[] = {"/etc/debian_release", "/etc/debian_version"};
58  private static final String LINUX_MANDRAKE_PATH = "/etc/mandrake-release";
59  private static final String LINUX_YELLOW_DOG_PATH = "/etc/yellowdog-release";
60  private static final String LINUX_SUN_JDS_PATH = "/etc/sun-release";
61  private static final String LINUX_SOLARIS_SPARC_PATH = "/etc/release";
62  private static final String LINUX_GENTOO_PATH = "/etc/gentoo-release";
63  private static final String LINUX_UNITED_LINUX_PATH = "/etc/UnitedLinux-release";
64  private static final String LINUX_UBUNTU_PATH = "/etc/lsb-release";
65 
66  private Content dataSource;
67 
68  @Override
69  void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) {
70  this.dataSource = dataSource;
71  try {
72  progressBar.progress(Bundle.ExtractOS_progressMessage());
73  for (OS_TYPE value : OS_TYPE.values()) {
74  if (context.dataSourceIngestIsCancelled()) {
75  return;
76  }
77 
78  checkForOSFiles(value);
79  }
80  } catch (TskCoreException ex) {
81  logger.log(Level.WARNING, "Failed to check if datasource contained a volume with operating system specific files", ex);
82  }
83  }
84 
92  private void checkForOSFiles(OS_TYPE osType) throws TskCoreException {
93  if (osType.getOsInfoLabel().isEmpty()) {
94  //shortcut out if it was called with out a specified program name so no OS INFO artifacts are created
95  return;
96  }
97  AbstractFile file = getFirstFileFound(osType.getFilePaths());
98 
99  if (file != null && tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO, file.getId()).isEmpty()) {
100  //if the os info program name is not empty create an os info artifact on the first of the files found
101  Collection<BlackboardAttribute> bbattributes = new ArrayList<>();
102  bbattributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME,
103  Bundle.ExtractOs_parentModuleName(),
104  osType.getOsInfoLabel())); //NON-NLS
105  postArtifact(createArtifactWithAttributes(BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO, file, bbattributes));
106  }
107  }
108 
119  private AbstractFile getFirstFileFound(List<String> pathsToSearchFor) throws TskCoreException{
120  for (String filePath : pathsToSearchFor) {
121  List<AbstractFile> files = currentCase.getSleuthkitCase().getFileManager().findFilesExactNameExactPath(dataSource, FilenameUtils.getName(filePath), FilenameUtils.getPath(filePath));
122  if (!files.isEmpty()) {
123  return files.get(0);
124  }
125  }
126  return null;
127  }
128 
129  @Messages({
130  "ExtractOs.osx.label=Mac OS X",
131  "ExtractOs.androidOs.label=Android",
132  "ExtractOs.redhatLinuxOs.label=Linux (Redhat)",
133  "ExtractOs.novellSUSEOs.label=Linux (Novell SUSE)",
134  "ExtractOs.fedoraLinuxOs.label=Linux (Fedora)",
135  "ExtractOs.slackwareLinuxOs.label=Linux (Slackware)",
136  "ExtractOs.debianLinuxOs.label=Linux (Debian)",
137  "ExtractOs.mandrakeLinuxOs.label=Linux (Mandrake)",
138  "ExtractOs.yellowDogLinuxOs.label=Linux (Yellow Dog)",
139  "ExtractOs.sunJDSLinuxOs.label=Linux (Sun JDS)",
140  "ExtractOs.solarisSparcOs.label=Linux (Solaris/Sparc)",
141  "ExtractOs.gentooLinuxOs.label=Linux (Gentoo)",
142  "ExtractOs.unitedLinuxOs.label=Linux (United Linux)",
143  "ExtractOs.ubuntuLinuxOs.label=Linux (Ubuntu)",
144  "ExtractOs.windowsVolume.label=OS Drive (Windows)",
145  "ExtractOs.osxVolume.label=OS Drive (OS X)",
146  "ExtractOs.androidVolume.label=OS Drive (Android)",
147  "ExtractOs.redhatLinuxVolume.label=OS Drive (Linux Redhat)",
148  "ExtractOs.novellSUSEVolume.label=OS Drive (Linux Novell SUSE)",
149  "ExtractOs.fedoraLinuxVolume.label=OS Drive (Linux Fedora)",
150  "ExtractOs.slackwareLinuxVolume.label=OS Drive (Linux Slackware)",
151  "ExtractOs.debianLinuxVolume.label=OS Drive (Linux Debian)",
152  "ExtractOs.mandrakeLinuxVolume.label=OS Drive (Linux Mandrake)",
153  "ExtractOs.yellowDogLinuxVolume.label=OS Drive (Linux Yellow Dog)",
154  "ExtractOs.sunJDSLinuxVolume.label=OS Drive (Linux Sun JDS)",
155  "ExtractOs.solarisSparcVolume.label=OS Drive (Linux Solaris/Sparc)",
156  "ExtractOs.gentooLinuxVolume.label=OS Drive (Linux Gentoo)",
157  "ExtractOs.unitedLinuxVolume.label=OS Drive (Linux United Linux)",
158  "ExtractOs.ubuntuLinuxVolume.label=OS Drive (Linux Ubuntu)"})
163  enum OS_TYPE {
164  WINDOWS("", Bundle.ExtractOs_windowsVolume_label(), Arrays.asList(WINDOWS_VOLUME_PATH)), //windows doesn't get OS_INFO artifacts created for it here
165  MAC_OS_X(Bundle.ExtractOs_osx_label(), Bundle.ExtractOs_osxVolume_label(), Arrays.asList(OSX_VOLUME_PATH)),
166  ANDROID(Bundle.ExtractOs_androidOs_label(), Bundle.ExtractOs_androidVolume_label(), Arrays.asList(ANDROID_VOLUME_PATH)),
167  LINUX_REDHAT(Bundle.ExtractOs_redhatLinuxOs_label(), Bundle.ExtractOs_redhatLinuxVolume_label(), Arrays.asList(LINUX_RED_HAT_PATHS)),
168  LINUX_NOVELL_SUSE(Bundle.ExtractOs_novellSUSEOs_label(), Bundle.ExtractOs_novellSUSEVolume_label(), Arrays.asList(LINUX_NOVELL_SUSE_PATH)),
169  LINUX_FEDORA(Bundle.ExtractOs_fedoraLinuxOs_label(), Bundle.ExtractOs_fedoraLinuxVolume_label(), Arrays.asList(LINUX_FEDORA_PATH)),
170  LINUX_SLACKWARE(Bundle.ExtractOs_slackwareLinuxOs_label(), Bundle.ExtractOs_slackwareLinuxVolume_label(), Arrays.asList(LINUX_SLACKWARE_PATHS)),
171  LINUX_DEBIAN(Bundle.ExtractOs_debianLinuxOs_label(), Bundle.ExtractOs_debianLinuxVolume_label(), Arrays.asList(LINUX_DEBIAN_PATHS)),
172  LINUX_MANDRAKE(Bundle.ExtractOs_mandrakeLinuxOs_label(), Bundle.ExtractOs_mandrakeLinuxVolume_label(), Arrays.asList(LINUX_MANDRAKE_PATH)),
173  LINUX_YELLOW_DOG(Bundle.ExtractOs_yellowDogLinuxOs_label(), Bundle.ExtractOs_yellowDogLinuxVolume_label(), Arrays.asList(LINUX_YELLOW_DOG_PATH)),
174  LINUX_SUN_JDS(Bundle.ExtractOs_sunJDSLinuxOs_label(), Bundle.ExtractOs_sunJDSLinuxVolume_label(), Arrays.asList(LINUX_SUN_JDS_PATH)),
175  LINUX_SOLARIS_SPARC(Bundle.ExtractOs_solarisSparcOs_label(), Bundle.ExtractOs_solarisSparcVolume_label(), Arrays.asList(LINUX_SOLARIS_SPARC_PATH)),
176  LINUX_GENTOO(Bundle.ExtractOs_gentooLinuxOs_label(), Bundle.ExtractOs_gentooLinuxVolume_label(), Arrays.asList(LINUX_GENTOO_PATH)),
177  LINUX_UNITED_LINUX(Bundle.ExtractOs_unitedLinuxOs_label(), Bundle.ExtractOs_unitedLinuxVolume_label(), Arrays.asList(LINUX_UNITED_LINUX_PATH)),
178  LINUX_UBUNTU(Bundle.ExtractOs_ubuntuLinuxOs_label(), Bundle.ExtractOs_ubuntuLinuxVolume_label(), Arrays.asList(LINUX_UBUNTU_PATH));
179 
180  private final String osInfoLabel;
181  private final String dsUsageLabel;
182  private final List<String> filePaths;
183 
194  private OS_TYPE(String osInfoText, String dsUsageText, List<String> filePathList) {
195  this.osInfoLabel = osInfoText;
196  this.dsUsageLabel = dsUsageText;
197  this.filePaths = filePathList;
198  }
199 
206  String getOsInfoLabel() {
207  return osInfoLabel;
208  }
209 
216  String getDsUsageLabel() {
217  return dsUsageLabel;
218  }
219 
226  List<String> getFilePaths() {
227  return Collections.unmodifiableList(filePaths);
228  }
229 
240  static public OS_TYPE fromDsUsageLabel(String dsUsageLabel) {
241  for (OS_TYPE value : OS_TYPE.values()) {
242  if (value.getDsUsageLabel().equals(dsUsageLabel)) {
243  return value;
244  }
245  }
246  return null;
247  }
248 
258  static public OS_TYPE fromOsInfoLabel(String osInfoLabel) {
259  for (OS_TYPE value : OS_TYPE.values()) {
260  if (value.getOsInfoLabel().equals(osInfoLabel)) {
261  return value;
262  }
263  }
264  return null;
265  }
266  }
267 }

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