19 package org.sleuthkit.autopsy.modules.encryptiondetection;
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.logging.Level;
24 import org.openide.util.NbBundle.Messages;
46 final class EncryptionDetectionDataSourceIngestModule
implements DataSourceIngestModule {
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;
62 EncryptionDetectionDataSourceIngestModule(EncryptionDetectionIngestJobSettings settings) {
63 minimumEntropy = settings.getMinimumEntropy();
67 public void startUp(IngestJobContext context)
throws IngestModule.IngestModuleException {
69 blackboard = Case.getCurrentCase().getSleuthkitCase().getBlackboard();
70 this.context = context;
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."
79 public ProcessResult process(Content dataSource, DataSourceIngestModuleProgress progressBar) {
82 if (dataSource instanceof Image) {
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;
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) {
95 if (context.dataSourceIngestIsCancelled()) {
96 return ProcessResult.OK;
99 for (Volume volume : volumeSystem.getVolumes()) {
101 if (context.dataSourceIngestIsCancelled()) {
102 return ProcessResult.OK;
104 if (BitlockerDetection.isBitlockerVolume(volume)) {
105 return flagVolume(volume, BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED, Bundle.EncryptionDetectionDataSourceIngestModule_artifactComment_bitlocker());
108 if (context.dataSourceIngestIsCancelled()) {
109 return ProcessResult.OK;
111 if (isVolumeEncrypted(volume)) {
112 return flagVolume(volume, BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED, String.format(Bundle.EncryptionDetectionDataSourceIngestModule_artifactComment_suspected(), calculatedEntropy));
116 numVolSystemsChecked++;
117 progressBar.progress(Bundle.EncryptionDetectionDataSourceIngestModule_processing_message(), numVolSystemsChecked);
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;
128 return IngestModule.ProcessResult.OK;
139 private void validateSettings() throws IngestModule.IngestModuleException {
140 EncryptionDetectionTools.validateMinEntropyValue(minimumEntropy);
153 private IngestModule.ProcessResult flagVolume(Volume volume, BlackboardArtifact.ARTIFACT_TYPE artifactType, String comment) {
155 if (context.dataSourceIngestIsCancelled()) {
156 return ProcessResult.OK;
160 BlackboardArtifact artifact = volume.newArtifact(artifactType);
161 artifact.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, EncryptionDetectionModuleFactory.getModuleName(), comment));
168 blackboard.postArtifact(artifact, EncryptionDetectionModuleFactory.getModuleName());
169 }
catch (Blackboard.BlackboardException ex) {
170 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + artifact.getArtifactID(), ex);
176 StringBuilder detailsSb =
new StringBuilder(
"");
177 detailsSb.append(
"File: ");
178 Content parentFile = volume.getParent();
179 if (parentFile != null) {
180 detailsSb.append(volume.getParent().getUniquePath());
182 detailsSb.append(volume.getName());
183 if (artifactType.equals(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_SUSPECTED)) {
184 detailsSb.append(
"<br/>\nEntropy: ").append(calculatedEntropy);
187 services.postMessage(IngestMessage.createDataMessage(EncryptionDetectionModuleFactory.getModuleName(),
188 artifactType.getDisplayName() +
" Match: " + volume.getName(),
189 detailsSb.toString(),
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);
196 return IngestModule.ProcessResult.ERROR;
208 private boolean isVolumeEncrypted(Volume volume)
throws ReadContentInputStream.ReadContentInputStreamException, IOException, TskCoreException {
213 if (volume.getFileSystems().isEmpty()) {
214 calculatedEntropy = EncryptionDetectionTools.calculateEntropy(volume, context);
215 if (calculatedEntropy >= minimumEntropy) {