Autopsy  4.11.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  private IngestJobContext context;
56 
63  EncryptionDetectionDataSourceIngestModule(EncryptionDetectionIngestJobSettings settings) {
64  minimumEntropy = settings.getMinimumEntropy();
65  }
66 
67  @Override
68  public void startUp(IngestJobContext context) throws IngestModule.IngestModuleException {
69  validateSettings();
70  blackboard = Case.getCurrentCase().getServices().getBlackboard();
71  this.context = context;
72  }
73 
74  @Messages({
75  "EncryptionDetectionDataSourceIngestModule.artifactComment.bitlocker=Bitlocker encryption detected.",
76  "EncryptionDetectionDataSourceIngestModule.artifactComment.suspected=Suspected encryption due to high entropy (%f).",
77  "EncryptionDetectionDataSourceIngestModule.processing.message=Checking image for encryption."
78  })
79  @Override
80  public ProcessResult process(Content dataSource, DataSourceIngestModuleProgress progressBar) {
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 
96  if (context.dataSourceIngestIsCancelled()) {
97  return ProcessResult.OK;
98  }
99 
100  for (Volume volume : volumeSystem.getVolumes()) {
101 
102  if (context.dataSourceIngestIsCancelled()) {
103  return ProcessResult.OK;
104  }
105  if (BitlockerDetection.isBitlockerVolume(volume)) {
106  return flagVolume(volume, BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED, Bundle.EncryptionDetectionDataSourceIngestModule_artifactComment_bitlocker());
107  }
108 
109  if (context.dataSourceIngestIsCancelled()) {
110  return ProcessResult.OK;
111  }
112  if (isVolumeEncrypted(volume)) {
113  return flagVolume(volume, BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED, String.format(Bundle.EncryptionDetectionDataSourceIngestModule_artifactComment_suspected(), calculatedEntropy));
114  }
115  }
116  // Update progress bar
117  numVolSystemsChecked++;
118  progressBar.progress(Bundle.EncryptionDetectionDataSourceIngestModule_processing_message(), numVolSystemsChecked);
119  }
120  }
121  } catch (ReadContentInputStream.ReadContentInputStreamException ex) {
122  logger.log(Level.WARNING, String.format("Unable to read data source '%s'", dataSource.getName()), ex);
123  return IngestModule.ProcessResult.ERROR;
124  } catch (IOException | TskCoreException ex) {
125  logger.log(Level.SEVERE, String.format("Unable to process data source '%s'", dataSource.getName()), ex);
126  return IngestModule.ProcessResult.ERROR;
127  }
128 
129  return IngestModule.ProcessResult.OK;
130  }
131 
140  private void validateSettings() throws IngestModule.IngestModuleException {
141  EncryptionDetectionTools.validateMinEntropyValue(minimumEntropy);
142  }
143 
154  private IngestModule.ProcessResult flagVolume(Volume volume, BlackboardArtifact.ARTIFACT_TYPE artifactType, String comment) {
155 
156  if (context.dataSourceIngestIsCancelled()) {
157  return ProcessResult.OK;
158  }
159 
160  try {
161  BlackboardArtifact artifact = volume.newArtifact(artifactType);
162  artifact.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, EncryptionDetectionModuleFactory.getModuleName(), comment));
163 
164  try {
165  /*
166  * Index the artifact for keyword search.
167  */
168  blackboard.indexArtifact(artifact);
169  } catch (Blackboard.BlackboardException ex) {
170  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + artifact.getArtifactID(), ex); //NON-NLS
171  }
172 
173  /*
174  * Send an event to update the view with the new result.
175  */
176  services.fireModuleDataEvent(new ModuleDataEvent(EncryptionDetectionModuleFactory.getModuleName(), artifactType, Collections.singletonList(artifact)));
177 
178  /*
179  * Make an ingest inbox message.
180  */
181  StringBuilder detailsSb = new StringBuilder("");
182  detailsSb.append("File: ");
183  Content parentFile = volume.getParent();
184  if (parentFile != null) {
185  detailsSb.append(volume.getParent().getUniquePath());
186  }
187  detailsSb.append(volume.getName());
188  if (artifactType.equals(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED)) {
189  detailsSb.append("<br/>\nEntropy: ").append(calculatedEntropy);
190  }
191 
192  services.postMessage(IngestMessage.createDataMessage(EncryptionDetectionModuleFactory.getModuleName(),
193  artifactType.getDisplayName() + " Match: " + volume.getName(),
194  detailsSb.toString(),
195  volume.getName(),
196  artifact));
197 
198  return IngestModule.ProcessResult.OK;
199  } catch (TskCoreException ex) {
200  logger.log(Level.SEVERE, String.format("Failed to create blackboard artifact for '%s'.", volume.getName()), ex); //NON-NLS
201  return IngestModule.ProcessResult.ERROR;
202  }
203  }
204 
213  private boolean isVolumeEncrypted(Volume volume) throws ReadContentInputStream.ReadContentInputStreamException, IOException, TskCoreException {
214  /*
215  * Criteria for the checks in this method are partially based on
216  * http://www.forensicswiki.org/wiki/TrueCrypt#Detection
217  */
218  if (volume.getFileSystems().isEmpty()) {
219  calculatedEntropy = EncryptionDetectionTools.calculateEntropy(volume, context);
220  if (calculatedEntropy >= minimumEntropy) {
221  return true;
222  }
223  }
224  return false;
225  }
226 }

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