19package org.sleuthkit.autopsy.modules.fileextmismatch;
21import java.text.MessageFormat;
22import java.util.Collections;
23import java.util.HashMap;
25import java.util.logging.Level;
26import org.openide.util.NbBundle;
27import org.openide.util.NbBundle.Messages;
28import org.sleuthkit.autopsy.casemodule.Case;
29import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
30import org.sleuthkit.autopsy.coreutils.Logger;
31import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
32import org.sleuthkit.autopsy.ingest.FileIngestModule;
33import org.sleuthkit.autopsy.ingest.IngestJobContext;
34import org.sleuthkit.autopsy.ingest.IngestMessage;
35import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter;
36import org.sleuthkit.autopsy.ingest.IngestServices;
37import org.sleuthkit.autopsy.modules.fileextmismatch.FileExtMismatchDetectorModuleSettings.CHECK_TYPE;
38import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector;
39import org.sleuthkit.datamodel.AbstractFile;
40import org.sleuthkit.datamodel.Blackboard;
41import org.sleuthkit.datamodel.BlackboardArtifact;
42import org.sleuthkit.datamodel.Score;
43import org.sleuthkit.datamodel.TskData;
44import org.sleuthkit.datamodel.TskData.FileKnown;
45import org.sleuthkit.datamodel.TskException;
51 "CannotRunFileTypeDetection=Unable to run file type detection.",
52 "FileExtMismatchIngestModule.readError.message=Could not read settings."
58 private final FileExtMismatchDetectorModuleSettings
settings;
78 private static synchronized void addToTotals(
long ingestJobId,
long processTimeInc) {
80 if (ingestJobTotals ==
null) {
85 ingestJobTotals.processTime += processTimeInc;
91 this.settings = settings;
96 jobId = context.getJobId();
100 mimeTypeToExtsMap = FileExtMismatchSettings.readSettings().getMimeTypeToExtsMap();
102 }
catch (FileExtMismatchSettings.FileExtMismatchSettingsException ex) {
110 @Messages({
"FileExtMismatchIngestModule.indexError.message=Failed to index file extension mismatch artifact for keyword search."})
115 logger.log(Level.WARNING,
"Exception while getting open case.", ex);
118 if (this.settings.skipKnownFiles() && (abstractFile.getKnown() == FileKnown.KNOWN)) {
123 if ((abstractFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)
124 || (abstractFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)
125 || (abstractFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)
126 || (abstractFile.isFile() ==
false)) {
131 if ((abstractFile.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.UNALLOC))
132 || (abstractFile.isDirNameFlagSet(TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC))) {
137 long startTime = System.currentTimeMillis();
143 if (mismatchDetected) {
144 String justification = MessageFormat.format(
"File has MIME type of {0}",
detector.getMIMEType(abstractFile));
147 BlackboardArtifact bart = abstractFile.newAnalysisResult(
148 BlackboardArtifact.Type.TSK_EXT_MISMATCH_DETECTED, Score.SCORE_LIKELY_NOTABLE,
149 null,
null, justification, Collections.emptyList())
150 .getAnalysisResult();
159 }
catch (Blackboard.BlackboardException ex) {
160 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + bart.getArtifactID(), ex);
166 }
catch (TskException ex) {
167 logger.log(Level.WARNING,
"Error matching file signature", ex);
180 String currActualExt = abstractFile.getNameExtension();
183 if (
settings.skipFilesWithNoExtension() && currActualExt.isEmpty()) {
186 String currActualSigType =
detector.getMIMEType(abstractFile);
189 if (!currActualExt.isEmpty() && currActualSigType.equals(
"text/plain")) {
194 if (!FileExtMismatchDetectorModuleSettings.MEDIA_AND_EXE_MIME_TYPES.contains(currActualSigType)) {
202 if (allowedExtSet !=
null) {
204 for (String e : allowedExtSet) {
205 if (e.equals(currActualExt)) {
220 synchronized (
this) {
223 if (jobTotals !=
null) {
224 StringBuilder detailsSb =
new StringBuilder();
225 detailsSb.append(
"<table border='0' cellpadding='4' width='280'>");
227 detailsSb.append(
"<tr><td>").append(
228 NbBundle.getMessage(
this.getClass(),
"FileExtMismatchIngestModule.complete.totalProcTime"))
229 .append(
"</td><td>").append(jobTotals.
processTime).append(
"</td></tr>\n");
230 detailsSb.append(
"<tr><td>").append(
231 NbBundle.getMessage(
this.getClass(),
"FileExtMismatchIngestModule.complete.totalFiles"))
232 .append(
"</td><td>").append(jobTotals.
numFiles).append(
"</td></tr>\n");
233 detailsSb.append(
"</table>");
236 NbBundle.getMessage(
this.getClass(),
237 "FileExtMismatchIngestModule.complete.svcMsg.text"),
238 detailsSb.toString()));
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()
synchronized static Logger getLogger(String name)
static void error(String title, String message)
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
static synchronized IngestServices getInstance()
HashMap< String, Set< String > > mimeTypeToExtsMap
static Blackboard blackboard
boolean compareSigTypeToExt(AbstractFile abstractFile)
FileTypeDetector detector
static final Logger logger
ProcessResult process(AbstractFile abstractFile)
final FileExtMismatchDetectorModuleSettings settings
static final HashMap< Long, IngestJobTotals > totalsForIngestJobs
static final IngestModuleReferenceCounter refCounter
final IngestServices services
void startUp(IngestJobContext context)
static synchronized void addToTotals(long ingestJobId, long processTimeInc)