Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EncryptionDetectionDataSourceIngestModule.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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.modules.encryptiondetection;
20 
21 import java.io.IOException;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.logging.Level;
25 import org.openide.util.NbBundle.Messages;
30 import org.sleuthkit.datamodel.Content;
31 import org.sleuthkit.datamodel.TskCoreException;
38 import org.sleuthkit.datamodel.BlackboardArtifact;
39 import org.sleuthkit.datamodel.BlackboardAttribute;
40 import org.sleuthkit.datamodel.Image;
41 import org.sleuthkit.datamodel.ReadContentInputStream;
42 import org.sleuthkit.datamodel.Volume;
43 import org.sleuthkit.datamodel.VolumeSystem;
44 
48 final class EncryptionDetectionDataSourceIngestModule implements DataSourceIngestModule {
49 
50  private final IngestServices services = IngestServices.getInstance();
51  private final Logger logger = services.getLogger(EncryptionDetectionModuleFactory.getModuleName());
52  private Blackboard blackboard;
53  private double calculatedEntropy;
54  private final double minimumEntropy;
55 
62  EncryptionDetectionDataSourceIngestModule(EncryptionDetectionIngestJobSettings settings) {
63  minimumEntropy = settings.getMinimumEntropy();
64  }
65 
66  @Override
67  public void startUp(IngestJobContext context) throws IngestModule.IngestModuleException {
68  validateSettings();
69  blackboard = Case.getCurrentCase().getServices().getBlackboard();
70  }
71 
72  @Messages({
73  "EncryptionDetectionDataSourceIngestModule.artifactComment.bitlocker=Bitlocker encryption detected.",
74  "EncryptionDetectionDataSourceIngestModule.artifactComment.suspected=Suspected encryption due to high entropy (%f).",
75  "EncryptionDetectionDataSourceIngestModule.processing.message=Checking image for encryption."
76  })
77  @Override
78  public ProcessResult process(Content dataSource, DataSourceIngestModuleProgress progressBar) {
79 
80 
81 
82  try {
83  if (dataSource instanceof Image) {
84 
85  if (((Image) dataSource).getPaths().length == 0) {
86  logger.log(Level.SEVERE, String.format("Unable to process data source '%s' - image has no paths", dataSource.getName()));
87  return IngestModule.ProcessResult.ERROR;
88  }
89 
90  List<VolumeSystem> volumeSystems = ((Image) dataSource).getVolumeSystems();
91  progressBar.switchToDeterminate(volumeSystems.size());
92  int numVolSystemsChecked = 0;
93  progressBar.progress(Bundle.EncryptionDetectionDataSourceIngestModule_processing_message(), 0);
94  for (VolumeSystem volumeSystem : volumeSystems) {
95  for (Volume volume : volumeSystem.getVolumes()) {
96  if (BitlockerDetection.isBitlockerVolume(volume)) {
97  return flagVolume(volume, BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED, Bundle.EncryptionDetectionDataSourceIngestModule_artifactComment_bitlocker());
98  }
99  if (isVolumeEncrypted(volume)) {
100  return flagVolume(volume, BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED, String.format(Bundle.EncryptionDetectionDataSourceIngestModule_artifactComment_suspected(), calculatedEntropy));
101  }
102  }
103  // Update progress bar
104  numVolSystemsChecked++;
105  progressBar.progress(Bundle.EncryptionDetectionDataSourceIngestModule_processing_message(), numVolSystemsChecked);
106  }
107  }
108  } catch (ReadContentInputStream.ReadContentInputStreamException ex) {
109  logger.log(Level.WARNING, String.format("Unable to read data source '%s'", dataSource.getName()), ex);
110  return IngestModule.ProcessResult.ERROR;
111  } catch (IOException | TskCoreException ex) {
112  logger.log(Level.SEVERE, String.format("Unable to process data source '%s'", dataSource.getName()), ex);
113  return IngestModule.ProcessResult.ERROR;
114  }
115 
116  return IngestModule.ProcessResult.OK;
117  }
118 
127  private void validateSettings() throws IngestModule.IngestModuleException {
128  EncryptionDetectionTools.validateMinEntropyValue(minimumEntropy);
129  }
130 
141  private IngestModule.ProcessResult flagVolume(Volume volume, BlackboardArtifact.ARTIFACT_TYPE artifactType, String comment) {
142  try {
143  BlackboardArtifact artifact = volume.newArtifact(artifactType);
144  artifact.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, EncryptionDetectionModuleFactory.getModuleName(), comment));
145 
146  try {
147  /*
148  * Index the artifact for keyword search.
149  */
150  blackboard.indexArtifact(artifact);
151  } catch (Blackboard.BlackboardException ex) {
152  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + artifact.getArtifactID(), ex); //NON-NLS
153  }
154 
155  /*
156  * Send an event to update the view with the new result.
157  */
158  services.fireModuleDataEvent(new ModuleDataEvent(EncryptionDetectionModuleFactory.getModuleName(), artifactType, Collections.singletonList(artifact)));
159 
160  /*
161  * Make an ingest inbox message.
162  */
163  StringBuilder detailsSb = new StringBuilder("");
164  detailsSb.append("File: ");
165  Content parentFile = volume.getParent();
166  if (parentFile != null) {
167  detailsSb.append(volume.getParent().getUniquePath());
168  }
169  detailsSb.append(volume.getName());
170  if (artifactType.equals(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED)) {
171  detailsSb.append("<br/>\nEntropy: ").append(calculatedEntropy);
172  }
173 
174  services.postMessage(IngestMessage.createDataMessage(EncryptionDetectionModuleFactory.getModuleName(),
175  artifactType.getDisplayName() + " Match: " + volume.getName(),
176  detailsSb.toString(),
177  volume.getName(),
178  artifact));
179 
180  return IngestModule.ProcessResult.OK;
181  } catch (TskCoreException ex) {
182  logger.log(Level.SEVERE, String.format("Failed to create blackboard artifact for '%s'.", volume.getName()), ex); //NON-NLS
183  return IngestModule.ProcessResult.ERROR;
184  }
185  }
186 
195  private boolean isVolumeEncrypted(Volume volume) throws ReadContentInputStream.ReadContentInputStreamException, IOException, TskCoreException {
196  /*
197  * Criteria for the checks in this method are partially based on
198  * http://www.forensicswiki.org/wiki/TrueCrypt#Detection
199  */
200  if (volume.getFileSystems().isEmpty()) {
201  calculatedEntropy = EncryptionDetectionTools.calculateEntropy(volume);
202  if (calculatedEntropy >= minimumEntropy) {
203  return true;
204  }
205  }
206  return false;
207  }
208 }

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.