Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FilesIdentifierIngestModule.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2014-2021 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 */
19package org.sleuthkit.autopsy.modules.interestingitems;
20
21import java.util.ArrayList;
22import java.util.Arrays;
23import java.util.Collection;
24import java.util.List;
25import java.util.Map;
26import java.util.concurrent.ConcurrentHashMap;
27import java.util.logging.Level;
28import org.openide.util.NbBundle;
29import org.openide.util.NbBundle.Messages;
30import org.sleuthkit.autopsy.casemodule.Case;
31import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
32import org.sleuthkit.autopsy.coreutils.Logger;
33import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
34import org.sleuthkit.autopsy.ingest.FileIngestModule;
35import org.sleuthkit.autopsy.ingest.IngestJobContext;
36import org.sleuthkit.autopsy.ingest.IngestMessage;
37import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter;
38import org.sleuthkit.autopsy.ingest.IngestServices;
39import org.sleuthkit.datamodel.AbstractFile;
40import org.sleuthkit.datamodel.Blackboard;
41import org.sleuthkit.datamodel.BlackboardArtifact;
42import org.sleuthkit.datamodel.BlackboardAttribute;
43import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY;
44import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME;
45import org.sleuthkit.datamodel.Score;
46import org.sleuthkit.datamodel.TskCoreException;
47import org.sleuthkit.datamodel.TskData;
48
53@NbBundle.Messages({"FilesIdentifierIngestModule.getFilesError=Error getting interesting files sets from file."})
54final class FilesIdentifierIngestModule implements FileIngestModule {
55
56 private static final Object sharedResourcesLock = new Object();
57 private static final Logger logger = Logger.getLogger(FilesIdentifierIngestModule.class.getName());
58 private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
59 private static final Map<Long, List<FilesSet>> interestingFileSetsByJob = new ConcurrentHashMap<>();
60 private static final String MODULE_NAME = InterestingItemsIngestModuleFactory.getModuleName();
61
62 private final FilesIdentifierIngestJobSettings settings;
63 private final IngestServices services = IngestServices.getInstance();
64 private IngestJobContext context;
65 private Blackboard blackboard;
66
73 FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
74 this.settings = settings;
75 }
76
77 @Override
78 public void startUp(IngestJobContext context) throws IngestModuleException {
79 this.context = context;
80 synchronized (FilesIdentifierIngestModule.sharedResourcesLock) {
81 if (FilesIdentifierIngestModule.refCounter.incrementAndGet(context.getJobId()) == 1) {
82 // Starting up the first instance of this module for this ingest
83 // job, so get the interesting file sets definitions snapshot
84 // for the job. Note that getting this snapshot atomically via a
85 // synchronized definitions manager method eliminates the need
86 // to disable the interesting files set definition UI during ingest.
87 List<FilesSet> filesSets = new ArrayList<>();
88 try {
90 if (settings.interestingFilesSetIsEnabled(set.getName())) {
91 filesSets.add(set);
92 }
93 }
95 throw new IngestModuleException(Bundle.FilesIdentifierIngestModule_getFilesError(), ex);
96 }
97 FilesIdentifierIngestModule.interestingFileSetsByJob.put(context.getJobId(), filesSets);
98 }
99 }
100 }
101
102 @Override
103 @Messages({"FilesIdentifierIngestModule.indexError.message=Failed to index interesting file hit artifact for keyword search."})
104 public ProcessResult process(AbstractFile file) {
105 try {
106 blackboard = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard();
107 } catch (NoCurrentCaseException ex) {
108 logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
109 return ProcessResult.ERROR;
110 }
111
112 // Skip slack space files.
113 if (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
114 return ProcessResult.OK;
115 }
116
117 // See if the file belongs to any defined interesting files set.
118 List<FilesSet> filesSets = FilesIdentifierIngestModule.interestingFileSetsByJob.get(this.context.getJobId());
119 for (FilesSet filesSet : filesSets) {
120 String ruleSatisfied = filesSet.fileIsMemberOf(file);
121 if (ruleSatisfied != null) {
122 try {
123
124 Collection<BlackboardAttribute> attributes = Arrays.asList(
125 /*
126 * Add a set name attribute to the artifact. This
127 * adds a fair amount of redundant data to the
128 * attributes table (i.e., rows that differ only in
129 * artifact id), but doing otherwise would requires
130 * reworking the interesting files set hit artifact. */
131 new BlackboardAttribute(
132 TSK_SET_NAME, MODULE_NAME,
133 filesSet.getName()),
134 /*
135 * Add a category attribute to the artifact to
136 * record the interesting files set membership rule
137 * that was satisfied. */
138 new BlackboardAttribute(
139 TSK_CATEGORY, MODULE_NAME,
140 ruleSatisfied)
141 );
142
143 // Create artifact if it doesn't already exist.
144 if (!blackboard.artifactExists(file, BlackboardArtifact.Type.TSK_INTERESTING_ITEM, attributes)) {
145 BlackboardArtifact artifact = file.newAnalysisResult(
146 BlackboardArtifact.Type.TSK_INTERESTING_ITEM, Score.SCORE_LIKELY_NOTABLE,
147 null, filesSet.getName(), null,
148 attributes)
149 .getAnalysisResult();
150 try {
151
152 // Post thet artifact to the blackboard.
153 blackboard.postArtifact(artifact, MODULE_NAME, context.getJobId());
154 } catch (Blackboard.BlackboardException ex) {
155 logger.log(Level.SEVERE, "Unable to index blackboard artifact " + artifact.getArtifactID(), ex); //NON-NLS
156 MessageNotifyUtil.Notify.error(Bundle.FilesIdentifierIngestModule_indexError_message(), artifact.getDisplayName());
157 }
158
159 // make an ingest inbox message
160 StringBuilder detailsSb = new StringBuilder();
161 detailsSb.append("File: ").append(file.getParentPath()).append(file.getName()).append("<br/>\n");
162 detailsSb.append("Rule Set: ").append(filesSet.getName());
163
164 services.postMessage(IngestMessage.createDataMessage(InterestingItemsIngestModuleFactory.getModuleName(),
165 "Interesting File Match: " + filesSet.getName() + "(" + file.getName() + ")",
166 detailsSb.toString(),
167 file.getName(),
168 artifact));
169 }
170 } catch (TskCoreException ex) {
171 FilesIdentifierIngestModule.logger.log(Level.SEVERE, "Error posting to the blackboard", ex); //NOI18N NON-NLS
172 }
173 }
174 }
175 return ProcessResult.OK;
176 }
177
178 @Override
179 public void shutDown() {
180 if (context != null) {
181 if (refCounter.decrementAndGet(this.context.getJobId()) == 0) {
182 // Shutting down the last instance of this module for this ingest
183 // job, so discard the interesting file sets definitions snapshot
184 // for the job.
185 FilesIdentifierIngestModule.interestingFileSetsByJob.remove(this.context.getJobId());
186 }
187 }
188 }
189}
synchronized static Logger getLogger(String name)
Definition Logger.java:124
static IngestMessage createDataMessage(String source, String subject, String detailsHtml, String uniqueKey, BlackboardArtifact data)
static synchronized IngestServices getInstance()

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.