Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExtractZoneIdentifier.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2019 Basis Technology Corp.
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.io.FileNotFoundException;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Properties;
29 import java.util.Set;
30 import java.util.logging.Level;
31 import org.apache.commons.lang3.StringUtils;
32 import org.openide.util.NbBundle.Messages;
37 import org.sleuthkit.datamodel.AbstractFile;
38 import org.sleuthkit.datamodel.BlackboardArtifact;
39 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_DOWNLOAD_SOURCE;
40 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD;
41 import org.sleuthkit.datamodel.BlackboardAttribute;
42 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN;
43 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION;
44 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID;
45 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL;
46 import org.sleuthkit.datamodel.Content;
47 import org.sleuthkit.datamodel.ReadContentInputStream;
48 import org.sleuthkit.datamodel.TskCoreException;
49 
55 final class ExtractZoneIdentifier extends Extract {
56 
57  private static final Logger LOG = Logger.getLogger(ExtractEdge.class.getName());
58 
59  private static final String ZONE_IDENTIFIER_FILE = "%:Zone.Identifier"; //NON-NLS
60  private static final String ZONE_IDENTIFIER = ":Zone.Identifier"; //NON-NLS
61 
62  @Messages({
63  "ExtractZone_process_errMsg_find=A failure occured while searching for :Zone.Indentifier files.",
64  "ExtractZone_process_errMsg=An error occured processing ':Zone.Indentifier' files.",
65  "ExtractZone_progress_Msg=Extracting :Zone.Identifer files"
66  })
67 
68  @Override
69  void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) {
70 
71  progressBar.progress(Bundle.ExtractZone_progress_Msg());
72 
73  List<AbstractFile> zoneFiles = null;
74  try {
75  zoneFiles = currentCase.getServices().getFileManager().findFiles(dataSource, ZONE_IDENTIFIER_FILE);
76  } catch (TskCoreException ex) {
77  addErrorMessage(Bundle.ExtractZone_process_errMsg_find());
78  LOG.log(Level.SEVERE, "Unable to find zone identifier files, exception thrown. ", ex); // NON-NLS
79  }
80 
81  if (zoneFiles == null || zoneFiles.isEmpty()) {
82  return;
83  }
84 
85  Set<Long> knownPathIDs = null;
86  try {
87  knownPathIDs = getPathIDsForType(TSK_WEB_DOWNLOAD);
88  } catch (TskCoreException ex) {
89  addErrorMessage(Bundle.ExtractZone_process_errMsg());
90  LOG.log(Level.SEVERE, "Failed to build PathIDs List for TSK_WEB_DOWNLOAD", ex); // NON-NLS
91  }
92 
93  if (knownPathIDs == null) {
94  return;
95  }
96 
97  Collection<BlackboardArtifact> sourceArtifacts = new ArrayList<>();
98  Collection<BlackboardArtifact> downloadArtifacts = new ArrayList<>();
99 
100  for (AbstractFile zoneFile : zoneFiles) {
101 
102  if (context.dataSourceIngestIsCancelled()) {
103  return;
104  }
105 
106  try {
107  processZoneFile(context, dataSource, zoneFile, sourceArtifacts, downloadArtifacts, knownPathIDs);
108  } catch (TskCoreException ex) {
109  addErrorMessage(Bundle.ExtractZone_process_errMsg());
110  String message = String.format("Failed to process zone identifier file %s", zoneFile.getName()); //NON-NLS
111  LOG.log(Level.WARNING, message, ex);
112  }
113  }
114 
115  postArtifacts(sourceArtifacts);
116  postArtifacts(downloadArtifacts);
117  }
118 
130  private void processZoneFile(IngestJobContext context, Content dataSource,
131  AbstractFile zoneFile, Collection<BlackboardArtifact> sourceArtifacts,
132  Collection<BlackboardArtifact> downloadArtifacts,
133  Set<Long> knownPathIDs) throws TskCoreException {
134 
135  ZoneIdentifierInfo zoneInfo = null;
136 
137  try {
138  zoneInfo = new ZoneIdentifierInfo(zoneFile);
139  } catch (IOException ex) {
140  String message = String.format("Unable to parse temporary File for %s", zoneFile.getName()); //NON-NLS
141  LOG.log(Level.WARNING, message, ex);
142  }
143 
144  if (zoneInfo == null) {
145  return;
146  }
147 
148  AbstractFile downloadFile = getDownloadFile(dataSource, zoneFile);
149 
150  if (downloadFile != null) {
151  // Only create a new TSK_WEB_DOWNLOAD artifact if one does not exist for downloadFile
152  if (!knownPathIDs.contains(downloadFile.getDataSourceObjectId())) {
153  // The zone identifier file is the parent of this artifact
154  // because it is the file we parsed to get the data
155  BlackboardArtifact downloadBba = createDownloadArtifact(zoneFile, zoneInfo);
156  if (downloadBba != null) {
157  downloadArtifacts.add(downloadBba);
158  }
159  }
160 
161  // check if download has a child TSK_DOWNLOAD_SOURCE artifact, if not create one
162  if (downloadFile.getArtifactsCount(TSK_DOWNLOAD_SOURCE) == 0) {
163  BlackboardArtifact sourceBba = createDownloadSourceArtifact(downloadFile, zoneInfo);
164  if (sourceBba != null) {
165  sourceArtifacts.add(sourceBba);
166  }
167  }
168  }
169  }
170 
181  private AbstractFile getDownloadFile(Content dataSource, AbstractFile zoneFile) throws TskCoreException {
182  AbstractFile downloadFile = null;
183 
185  = currentCase.getServices().getFileManager();
186 
187  String downloadFileName = zoneFile.getName().replace(ZONE_IDENTIFIER, ""); //NON-NLS
188 
189  List<AbstractFile> fileList = fileManager.findFiles(dataSource, downloadFileName, zoneFile.getParentPath());
190 
191  if (fileList.size() == 1) {
192  downloadFile = fileList.get(0);
193 
194  // Check that the download file and the zone file came from the same dir
195  if (!downloadFile.getParentPath().equals(zoneFile.getParentPath())) {
196  downloadFile = null;
197  } else if (zoneFile.getMetaAddr() != downloadFile.getMetaAddr()) {
198  downloadFile = null;
199  }
200  }
201 
202  return downloadFile;
203  }
204 
215  private BlackboardArtifact createDownloadSourceArtifact(AbstractFile downloadFile, ZoneIdentifierInfo zoneInfo) {
216 
217  Collection<BlackboardAttribute> bbattributes = new ArrayList<>();
218 
219  bbattributes.addAll(Arrays.asList(
220  new BlackboardAttribute(TSK_URL,
221  RecentActivityExtracterModuleFactory.getModuleName(),
222  StringUtils.defaultString(zoneInfo.getURL(), "")),
223 
224  new BlackboardAttribute(TSK_DOMAIN,
225  RecentActivityExtracterModuleFactory.getModuleName(),
226  (zoneInfo.getURL() != null) ? NetworkUtils.extractDomain(zoneInfo.getURL()) : ""),
227 
228  new BlackboardAttribute(TSK_LOCATION,
229  RecentActivityExtracterModuleFactory.getModuleName(),
230  StringUtils.defaultString(zoneInfo.getZoneIdAsString(), "")))); //NON-NLS
231 
232  return createArtifactWithAttributes(TSK_DOWNLOAD_SOURCE, downloadFile, bbattributes);
233  }
234 
243  private BlackboardArtifact createDownloadArtifact(AbstractFile zoneFile, ZoneIdentifierInfo zoneInfo) {
244 
245  Collection<BlackboardAttribute> bbattributes = createDownloadAttributes(
246  null, null,
247  zoneInfo.getURL(), null,
248  (zoneInfo.getURL() != null ? NetworkUtils.extractDomain(zoneInfo.getURL()) : ""),
249  null);
250  return createArtifactWithAttributes(TSK_WEB_DOWNLOAD, zoneFile, bbattributes);
251  }
252 
262  private Set<Long> getPathIDsForType(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
263  Set<Long> idList = new HashSet<>();
264  for (BlackboardArtifact artifact : currentCase.getSleuthkitCase().getBlackboardArtifacts(type)) {
265  BlackboardAttribute pathIDAttribute = artifact.getAttribute(new BlackboardAttribute.Type(TSK_PATH_ID));
266 
267  if (pathIDAttribute != null) {
268  long contentID = pathIDAttribute.getValueLong();
269  if (contentID != -1) {
270  idList.add(contentID);
271  }
272  }
273  }
274  return idList;
275  }
276 
277  @Messages({
278  "ExtractZone_Local_Machine=Local Machine Zone",
279  "ExtractZone_Local_Intranet=Local Intranet Zone",
280  "ExtractZone_Trusted=Trusted Sites Zone",
281  "ExtractZone_Internet=Internet Zone",
282  "ExtractZone_Restricted=Restricted Sites Zone"
283  })
284 
293  private final static class ZoneIdentifierInfo {
294 
295  private static final String ZONE_ID = "ZoneId"; //NON-NLS
296  private static final String REFERRER_URL = "ReferrerUrl"; //NON-NLS
297  private static final String HOST_URL = "HostUrl"; //NON-NLS
298  private static final String FAMILY_NAME = "LastWriterPackageFamilyName"; //NON-NLS
299 
300  private final Properties properties = new Properties(null);
301 
311  ZoneIdentifierInfo(AbstractFile zoneFile) throws IOException {
312  properties.load(new ReadContentInputStream(zoneFile));
313  }
314 
320  private int getZoneId() {
321  int zoneValue = -1;
322  String value = properties.getProperty(ZONE_ID);
323  if (value != null) {
324  zoneValue = Integer.parseInt(value);
325  }
326 
327  return zoneValue;
328  }
329 
335  private String getZoneIdAsString() {
336  switch (getZoneId()) {
337  case 0:
338  return Bundle.ExtractZone_Local_Machine();
339  case 1:
340  return Bundle.ExtractZone_Local_Intranet();
341  case 2:
342  return Bundle.ExtractZone_Trusted();
343  case 3:
344  return Bundle.ExtractZone_Internet();
345  case 4:
346  return Bundle.ExtractZone_Restricted();
347  default:
348  return null;
349  }
350  }
351 
357  private String getURL() {
358  return properties.getProperty(HOST_URL);
359  }
360 
366  private String getReferrer() {
367  return properties.getProperty(REFERRER_URL);
368  }
369 
375  private String getFamilyName() {
376  return properties.getProperty(FAMILY_NAME);
377  }
378  }
379 
380 }
synchronized List< AbstractFile > findFiles(String fileName)

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