19 package org.sleuthkit.autopsy.centralrepository.ingestmodule;
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.stream.Collectors;
26 import org.openide.util.NbBundle.Messages;
51 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT;
53 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT;
54 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME;
63 @Messages({
"CentralRepoIngestModule.prevTaggedSet.text=Previously Tagged As Notable (Central Repository)",
64 "CentralRepoIngestModule.prevCaseComment.text=Previous Case: "})
69 static final boolean DEFAULT_FLAG_TAGGED_NOTABLE_ITEMS =
true;
70 static final boolean DEFAULT_FLAG_PREVIOUS_DEVICES =
true;
71 static final boolean DEFAULT_CREATE_CR_PROPERTIES =
true;
81 private final boolean flagTaggedNotableItems;
82 private final boolean flagPreviouslySeenDevices;
83 private Blackboard blackboard;
84 private final boolean createCorrelationProperties;
91 CentralRepoIngestModule(IngestSettings settings) {
92 flagTaggedNotableItems = settings.isFlagTaggedNotableItems();
93 flagPreviouslySeenDevices = settings.isFlagPreviousDevices();
94 createCorrelationProperties = settings.shouldCreateCorrelationProperties();
98 public ProcessResult process(AbstractFile abstractFile) {
106 return ProcessResult.OK;
112 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
113 return ProcessResult.ERROR;
117 return ProcessResult.OK;
120 if (abstractFile.getKnown() == TskData.FileKnown.KNOWN) {
121 return ProcessResult.OK;
128 logger.log(Level.SEVERE,
"Error connecting to Central Repository database.", ex);
129 return ProcessResult.ERROR;
133 if (!filesType.isEnabled()) {
134 return ProcessResult.OK;
138 String md5 = abstractFile.getMd5Hash();
139 if ((md5 == null) || (HashUtility.isNoDataMd5(md5))) {
140 return ProcessResult.OK;
147 if (abstractFile.getKnown() != TskData.FileKnown.KNOWN && flagTaggedNotableItems) {
152 if (!caseDisplayNamesList.isEmpty()) {
153 postCorrelatedBadFileToBlackboard(abstractFile, caseDisplayNamesList);
156 logger.log(Level.SEVERE,
"Error searching database for artifact.", ex);
157 return ProcessResult.ERROR;
159 logger.log(Level.INFO,
"Error searching database for artifact.", ex);
160 return ProcessResult.ERROR;
165 if (createCorrelationProperties) {
172 abstractFile.getParentPath() + abstractFile.
getName(),
174 TskData.FileKnown.UNKNOWN
176 abstractFile.getId());
179 logger.log(Level.SEVERE,
"Error adding artifact to bulk artifacts.", ex);
180 return ProcessResult.ERROR;
182 logger.log(Level.INFO,
"Error adding artifact to bulk artifacts.", ex);
183 return ProcessResult.ERROR;
186 return ProcessResult.OK;
190 public void shutDown() {
193 if ((
EamDb.
isEnabled() ==
false) || (eamCase == null) || (eamDataSource == null)) {
200 logger.log(Level.SEVERE,
"Error connecting to Central Repository database.", ex);
206 logger.log(Level.SEVERE,
"Error doing bulk insert of artifacts.", ex);
210 logger.log(Level.INFO,
"{0} artifacts in db for case: {1} ds:{2}",
new Object[]{count, eamCase.getDisplayName(), eamDataSource.getName()});
212 logger.log(Level.SEVERE,
"Error counting artifacts.", ex);
221 "CentralRepoIngestModule.notfyBubble.title=Central Repository Not Initialized",
222 "CentralRepoIngestModule.errorMessage.isNotEnabled=Central repository settings are not initialized, cannot run Correlation Engine ingest module."
225 public void startUp(
IngestJobContext context)
throws IngestModuleException {
262 MessageNotifyUtil.
Notify.
warn(Bundle.CentralRepoIngestModule_notfyBubble_title(), Bundle.CentralRepoIngestModule_errorMessage_isNotEnabled());
271 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
272 throw new IngestModuleException(
"Exception while getting open case.", ex);
278 logger.log(Level.SEVERE,
"Cannot run correlation engine on a multi-user case with a SQLite central repository.");
279 throw new IngestModuleException(
"Cannot run on a multi-user case with a SQLite central repository.");
287 logger.log(Level.SEVERE,
"Error connecting to central repository database.", ex);
288 throw new IngestModuleException(
"Error connecting to central repository database.", ex);
294 logger.log(Level.SEVERE,
"Error getting correlation type FILES in ingest module start up.", ex);
295 throw new IngestModuleException(
"Error getting correlation type FILES in ingest module start up.", ex);
299 eamCase = centralRepoDb.
getCase(autopsyCase);
301 throw new IngestModuleException(
"Unable to get case from central repository database ", ex);
307 logger.log(Level.SEVERE,
"Error getting data source info.", ex);
308 throw new IngestModuleException(
"Error getting data source info.", ex);
321 logger.log(Level.SEVERE,
"Error adding data source to Central Repository.", ex);
322 throw new IngestModuleException(
"Error adding data source to Central Repository.", ex);
334 private void postCorrelatedBadFileToBlackboard(AbstractFile abstractFile, List<String> caseDisplayNames) {
336 Collection<BlackboardAttribute> attributes = Arrays.asList(
337 new BlackboardAttribute(
338 TSK_SET_NAME, MODULE_NAME,
339 Bundle.CentralRepoIngestModule_prevTaggedSet_text()),
340 new BlackboardAttribute(
341 TSK_COMMENT, MODULE_NAME,
342 Bundle.CentralRepoIngestModule_prevCaseComment_text() + caseDisplayNames.stream().distinct().collect(Collectors.joining(
","))));
346 if (!blackboard.artifactExists(abstractFile, TSK_INTERESTING_FILE_HIT, attributes)) {
347 BlackboardArtifact tifArtifact = abstractFile.newArtifact(TSK_INTERESTING_FILE_HIT);
348 tifArtifact.addAttributes(attributes);
351 blackboard.postArtifact(tifArtifact, MODULE_NAME);
352 }
catch (Blackboard.BlackboardException ex) {
353 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + tifArtifact.getArtifactID(), ex);
356 sendBadFileInboxMessage(tifArtifact, abstractFile.getName(), abstractFile.getMd5Hash(), caseDisplayNames);
358 }
catch (TskCoreException ex) {
359 logger.log(Level.SEVERE,
"Failed to create BlackboardArtifact.", ex);
360 }
catch (IllegalStateException ex) {
361 logger.log(Level.SEVERE,
"Failed to create BlackboardAttribute.", ex);
366 "CentralRepoIngestModule_notable_message_header=<html>A file in this data source was previously seen and tagged as Notable.<br>",
367 "CentralRepoIngestModel_name_header=Name:<br>",
368 "CentralRepoIngestModel_previous_case_header=<br>Previous Cases:<br>",
369 "# {0} - Name of file that is Notable",
370 "CentralRepoIngestModule_postToBB_knownBadMsg=Notable: {0}"
382 private void sendBadFileInboxMessage(BlackboardArtifact artifact, String name, String md5Hash, List<String> caseDisplayNames) {
383 StringBuilder detailsSb =
new StringBuilder(1024);
385 detailsSb.append(Bundle.CentralRepoIngestModule_notable_message_header()).append(Bundle.CentralRepoIngestModel_name_header());
386 detailsSb.append(name).append(Bundle.CentralRepoIngestModel_previous_case_header());
387 for (String str : caseDisplayNames) {
388 detailsSb.append(str).append(
"<br>");
390 detailsSb.append(
"</html>");
392 Bundle.CentralRepoIngestModule_postToBB_knownBadMsg(name),
393 detailsSb.toString(),
synchronized long decrementAndGet(long jobId)
CorrelationDataSource newDataSource(CorrelationDataSource eamDataSource)
static synchronized int getCeModuleInstanceCount()
static IngestMessage createDataMessage(String source, String subject, String detailsHtml, String uniqueKey, BlackboardArtifact data)
static boolean runningWithGUI
static synchronized boolean isFlagSeenDevices()
List< String > getListCasesHavingArtifactInstancesKnownBad(CorrelationAttributeInstance.Type aType, String value)
static synchronized void setCreateCrProperties(boolean value)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
static boolean isSupportedAbstractFileType(AbstractFile file)
synchronized long incrementAndGet(long jobId)
static TimingMetric getTimingMetric(String name)
static synchronized boolean isFlagNotableItems()
void addAttributeInstanceBulk(CorrelationAttributeInstance eamArtifact)
static EamDb getInstance()
CorrelationDataSource getDataSource(CorrelationCase correlationCase, Long caseDbDataSourceId)
void commitAttributeInstancesBulk()
CorrelationAttributeInstance.Type getCorrelationTypeById(int typeId)
static synchronized void setFlagSeenDevices(boolean value)
void postMessage(final IngestMessage message)
static String getModuleName()
Long getCountArtifactInstancesByCaseDataSource(CorrelationDataSource correlationDataSource)
static boolean isEnabled()
SleuthkitCase getSleuthkitCase()
static synchronized void setFlagNotableItems(boolean value)
Long getDataSourceObjectID()
static void submitTimingMetric(TimingMetric metric)
CorrelationCase getCase(Case autopsyCase)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static synchronized boolean shouldCreateCrProperties()
static synchronized void incrementCorrelationEngineModuleCount()
static synchronized void decrementCorrelationEngineModuleCount()
static void warn(String title, String message)
static final int FILES_TYPE_ID
static synchronized IngestServices getInstance()