Autopsy  4.16.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.List;
23 import java.util.logging.Level;
24 import org.openide.util.NbBundle.Messages;
33 import org.sleuthkit.datamodel.Blackboard;
34 import org.sleuthkit.datamodel.BlackboardArtifact;
35 import org.sleuthkit.datamodel.BlackboardAttribute;
36 import org.sleuthkit.datamodel.Content;
37 import org.sleuthkit.datamodel.Image;
38 import org.sleuthkit.datamodel.ReadContentInputStream;
39 import org.sleuthkit.datamodel.TskCoreException;
40 import org.sleuthkit.datamodel.Volume;
41 import org.sleuthkit.datamodel.VolumeSystem;
42 
46 final class EncryptionDetectionDataSourceIngestModule implements DataSourceIngestModule {
47 
48  private final IngestServices services = IngestServices.getInstance();
49  private final Logger logger = services.getLogger(EncryptionDetectionModuleFactory.getModuleName());
50  private Blackboard blackboard;
51  private double calculatedEntropy;
52  private final double minimumEntropy;
53  private IngestJobContext context;
54 
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().getSleuthkitCase().getBlackboard();
70  this.context = context;
71  }
72 
73  @Messages({
74  "EncryptionDetectionDataSourceIngestModule.artifactComment.bitlocker=Bitlocker encryption detected.",
75  "EncryptionDetectionDataSourceIngestModule.artifactComment.suspected=Suspected encryption due to high entropy (%f).",
76  "EncryptionDetectionDataSourceIngestModule.processing.message=Checking image for encryption."
77  })
78  @Override
79  public ProcessResult process(Content dataSource, DataSourceIngestModuleProgress progressBar) {
80 
81  try {
82  if (dataSource instanceof Image) {
83 
84  if (((Image) dataSource).getPaths().length == 0) {
85  logger.log(Level.SEVERE, String.format("Unable to process data source '%s' - image has no paths", dataSource.getName()));
86  return IngestModule.ProcessResult.ERROR;
87  }
88 
89  List<VolumeSystem> volumeSystems = ((Image) dataSource).getVolumeSystems();
90  progressBar.switchToDeterminate(volumeSystems.size());
91  int numVolSystemsChecked = 0;
92  progressBar.progress(Bundle.EncryptionDetectionDataSourceIngestModule_processing_message(), 0);
93  for (VolumeSystem volumeSystem : volumeSystems) {
94 
95  if (context.dataSourceIngestIsCancelled()) {
96  return ProcessResult.OK;
97  }
98 
99  for (Volume volume : volumeSystem.getVolumes()) {
100 
101  if (context.dataSourceIngestIsCancelled()) {
102  return ProcessResult.OK;
103  }
104  if (BitlockerDetection.isBitlockerVolume(volume)) {
105  return flagVolume(volume, BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED, Bundle.EncryptionDetectionDataSourceIngestModule_artifactComment_bitlocker());
106  }
107 
108  if (context.dataSourceIngestIsCancelled()) {
109  return ProcessResult.OK;
110  }
111  if (isVolumeEncrypted(volume)) {
112  return flagVolume(volume, BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED, String.format(Bundle.EncryptionDetectionDataSourceIngestModule_artifactComment_suspected(), calculatedEntropy));
113  }
114  }
115  // Update progress bar
116  numVolSystemsChecked++;
117  progressBar.progress(Bundle.EncryptionDetectionDataSourceIngestModule_processing_message(), numVolSystemsChecked);
118  }
119  }
120  } catch (ReadContentInputStream.ReadContentInputStreamException ex) {
121  logger.log(Level.WARNING, String.format("Unable to read data source '%s'", dataSource.getName()), ex);
122  return IngestModule.ProcessResult.ERROR;
123  } catch (IOException | TskCoreException ex) {
124  logger.log(Level.SEVERE, String.format("Unable to process data source '%s'", dataSource.getName()), ex);
125  return IngestModule.ProcessResult.ERROR;
126  }
127 
128  return IngestModule.ProcessResult.OK;
129  }
130 
139  private void validateSettings() throws IngestModule.IngestModuleException {
140  EncryptionDetectionTools.validateMinEntropyValue(minimumEntropy);
141  }
142 
153  private IngestModule.ProcessResult flagVolume(Volume volume, BlackboardArtifact.ARTIFACT_TYPE artifactType, String comment) {
154 
155  if (context.dataSourceIngestIsCancelled()) {
156  return ProcessResult.OK;
157  }
158 
159  try {
160  BlackboardArtifact artifact = volume.newArtifact(artifactType);
161  artifact.addAttribute(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, EncryptionDetectionModuleFactory.getModuleName(), comment));
162 
163  try {
164  /*
165  * post the artifact which will index the artifact for keyword
166  * search, and fire an event to notify UI of this new artifact
167  */
168  blackboard.postArtifact(artifact, EncryptionDetectionModuleFactory.getModuleName());
169  } catch (Blackboard.BlackboardException ex) {
170  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + artifact.getArtifactID(), ex); //NON-NLS
171  }
172 
173  /*
174  * Make an ingest inbox message.
175  */
176  StringBuilder detailsSb = new StringBuilder("");
177  detailsSb.append("File: ");
178  Content parentFile = volume.getParent();
179  if (parentFile != null) {
180  detailsSb.append(volume.getParent().getUniquePath());
181  }
182  detailsSb.append(volume.getName());
183  if (artifactType.equals(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED)) {
184  detailsSb.append("<br/>\nEntropy: ").append(calculatedEntropy);
185  }
186 
187  services.postMessage(IngestMessage.createDataMessage(EncryptionDetectionModuleFactory.getModuleName(),
188  artifactType.getDisplayName() + " Match: " + volume.getName(),
189  detailsSb.toString(),
190  volume.getName(),
191  artifact));
192 
193  return IngestModule.ProcessResult.OK;
194  } catch (TskCoreException ex) {
195  logger.log(Level.SEVERE, String.format("Failed to create blackboard artifact for '%s'.", volume.getName()), ex); //NON-NLS
196  return IngestModule.ProcessResult.ERROR;
197  }
198  }
199 
208  private boolean isVolumeEncrypted(Volume volume) throws ReadContentInputStream.ReadContentInputStreamException, IOException, TskCoreException {
209  /*
210  * Criteria for the checks in this method are partially based on
211  * http://www.forensicswiki.org/wiki/TrueCrypt#Detection
212  */
213  if (volume.getFileSystems().isEmpty()) {
214  calculatedEntropy = EncryptionDetectionTools.calculateEntropy(volume, context);
215  if (calculatedEntropy >= minimumEntropy) {
216  return true;
217  }
218  }
219  return false;
220  }
221 }

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