19 package org.sleuthkit.autopsy.centralrepository.ingestmodule;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.stream.Collectors;
26 import org.openide.util.Exceptions;
27 import org.openide.util.NbBundle.Messages;
58 @Messages({
"IngestModule.prevTaggedSet.text=Previously Tagged As Notable (Central Repository)",
59 "IngestModule.prevCaseComment.text=Previous Case: "})
73 public ProcessResult process(AbstractFile af) {
81 return ProcessResult.OK;
86 if ((af.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)
87 || (af.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)
88 || (af.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)
89 || (af.getKnown() == TskData.FileKnown.KNOWN)
90 || (af.isDir() ==
true)
91 || (!af.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC))) {
92 return ProcessResult.OK;
99 LOGGER.log(Level.SEVERE,
"Error connecting to Central Repository database.", ex);
100 return ProcessResult.ERROR;
104 if (!filesType.isEnabled()) {
105 return ProcessResult.OK;
109 String md5 = af.getMd5Hash();
110 if ((md5 == null) || (HashUtility.isNoDataMd5(md5))) {
111 return ProcessResult.OK;
115 if (af.getKnown() == TskData.FileKnown.UNKNOWN) {
121 if (!caseDisplayNames.isEmpty()) {
122 postCorrelatedBadFileToBlackboard(af, caseDisplayNames);
125 LOGGER.log(Level.SEVERE,
"Error counting notable artifacts.", ex);
126 return ProcessResult.ERROR;
133 postCorrelatedHashHitToBlackboard(af);
136 LOGGER.log(Level.SEVERE,
"Error retrieving global known status.", ex);
137 return ProcessResult.ERROR;
145 af.getParentPath() + af.
getName(),
147 TskData.FileKnown.UNKNOWN,
153 LOGGER.log(Level.SEVERE,
"Error adding artifact to bulk artifacts.", ex);
154 return ProcessResult.ERROR;
157 return ProcessResult.OK;
161 public void shutDown() {
163 if ((
EamDb.
isEnabled() ==
false) || (eamCase == null) || (eamDataSource == null)) {
170 LOGGER.log(Level.SEVERE,
"Error connecting to Central Repository database.", ex);
176 LOGGER.log(Level.SEVERE,
"Error doing bulk insert of artifacts.", ex);
180 LOGGER.log(Level.INFO,
"{0} artifacts in db for case: {1} ds:{2}",
new Object[]{count, eamCase.getDisplayName(), eamDataSource.getName()});
182 LOGGER.log(Level.SEVERE,
"Error counting artifacts.", ex);
191 "IngestModule.notfyBubble.title=Central Repository Not Initialized",
192 "IngestModule.errorMessage.isNotEnabled=Central repository settings are not initialized, cannot run Correlation Engine ingest module."
195 public void startUp(
IngestJobContext context)
throws IngestModuleException {
215 LOGGER.log(Level.SEVERE,
"Cannot run correlation engine on a multi-user case with a SQLite central repository.");
216 throw new IngestModuleException(
"Cannot run on a multi-user case with a SQLite central repository.");
224 LOGGER.log(Level.SEVERE,
"Error getting data source info.", ex);
225 throw new IngestModuleException(
"Error getting data source info.", ex);
232 LOGGER.log(Level.SEVERE,
"Error connecting to central repository database.", ex);
233 throw new IngestModuleException(
"Error connecting to central repository database.", ex);
239 LOGGER.log(Level.SEVERE,
"Error getting correlation type FILES in ingest module start up.", ex);
240 throw new IngestModuleException(
"Error getting correlation type FILES in ingest module start up.", ex);
254 LOGGER.log(Level.SEVERE,
"Error creating new data source in ingest module start up.", ex);
255 throw new IngestModuleException(
"Error creating new data source in ingest module start up.", ex);
274 if (existingCase == null) {
279 LOGGER.log(Level.SEVERE,
"Error creating new case in ingest module start up.", ex);
280 throw new IngestModuleException(
"Error creating new case in ingest module start up.", ex);
285 private void postCorrelatedBadFileToBlackboard(AbstractFile abstractFile, List<String> caseDisplayNames) {
289 BlackboardArtifact tifArtifact = abstractFile.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
290 BlackboardAttribute att =
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, MODULE_NAME,
291 Bundle.IngestModule_prevTaggedSet_text());
292 BlackboardAttribute att2 =
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT, MODULE_NAME,
293 Bundle.IngestModule_prevCaseComment_text() + caseDisplayNames.stream().distinct().collect(Collectors.joining(
",",
"",
"")));
294 tifArtifact.addAttribute(att);
295 tifArtifact.addAttribute(att2);
301 LOGGER.log(Level.SEVERE,
"Unable to index blackboard artifact " + tifArtifact.getArtifactID(), ex);
305 sendBadFileInboxMessage(tifArtifact, abstractFile.getName(), abstractFile.getMd5Hash());
309 }
catch (TskCoreException ex) {
310 LOGGER.log(Level.SEVERE,
"Failed to create BlackboardArtifact.", ex);
311 }
catch (IllegalStateException ex) {
312 LOGGER.log(Level.SEVERE,
"Failed to create BlackboardAttribute.", ex);
316 private void postCorrelatedHashHitToBlackboard(AbstractFile abstractFile) {
319 BlackboardArtifact tifArtifact = abstractFile.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT);
320 BlackboardAttribute att =
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, MODULE_NAME,
321 Bundle.IngestModule_prevCaseComment_text());
322 tifArtifact.addAttribute(att);
328 LOGGER.log(Level.SEVERE,
"Unable to index blackboard artifact " + tifArtifact.getArtifactID(), ex);
332 sendBadFileInboxMessage(tifArtifact, abstractFile.getName(), abstractFile.getMd5Hash());
336 }
catch (TskCoreException ex) {
337 LOGGER.log(Level.SEVERE,
"Failed to create BlackboardArtifact.", ex);
338 }
catch (IllegalStateException ex) {
339 LOGGER.log(Level.SEVERE,
"Failed to create BlackboardAttribute.", ex);
351 @Messages({
"IngestModule.postToBB.fileName=File Name",
352 "IngestModule.postToBB.md5Hash=MD5 Hash",
353 "IngestModule.postToBB.hashSetSource=Source of Hash",
354 "IngestModule.postToBB.eamHit=Central Repository",
355 "# {0} - Name of file that is Notable",
356 "IngestModule.postToBB.knownBadMsg=Notable: {0}"})
357 public void sendBadFileInboxMessage(BlackboardArtifact artifact, String name, String md5Hash) {
358 StringBuilder detailsSb =
new StringBuilder();
360 detailsSb.append(
"<table border='0' cellpadding='4' width='280'>");
362 detailsSb.append(
"<tr>");
363 detailsSb.append(
"<th>")
364 .append(Bundle.IngestModule_postToBB_fileName())
366 detailsSb.append(
"<td>")
369 detailsSb.append(
"</tr>");
371 detailsSb.append(
"<tr>");
372 detailsSb.append(
"<th>")
373 .append(Bundle.IngestModule_postToBB_md5Hash())
375 detailsSb.append(
"<td>").append(md5Hash).append(
"</td>");
376 detailsSb.append(
"</tr>");
378 detailsSb.append(
"<tr>");
379 detailsSb.append(
"<th>")
380 .append(Bundle.IngestModule_postToBB_hashSetSource())
382 detailsSb.append(
"<td>").append(Bundle.IngestModule_postToBB_eamHit()).append(
"</td>");
383 detailsSb.append(
"</tr>");
385 detailsSb.append(
"</table>");
388 Bundle.IngestModule_postToBB_knownBadMsg(name),
389 detailsSb.toString(),
CorrelationAttribute.Type getCorrelationTypeById(int typeId)
CorrelationCase getCaseByUUID(String caseUUID)
synchronized long decrementAndGet(long jobId)
static IngestMessage createDataMessage(String source, String subject, String detailsHtml, String uniqueKey, BlackboardArtifact data)
static boolean runningWithGUI
static final int FILES_TYPE_ID
void prepareBulkArtifact(CorrelationAttribute eamArtifact)
void newCase(CorrelationCase eamCase)
synchronized long incrementAndGet(long jobId)
void bulkInsertArtifacts()
List< String > getListCasesHavingArtifactInstancesKnownBad(CorrelationAttribute.Type aType, String value)
void addInstance(CorrelationAttributeInstance artifactInstance)
static EamDb getInstance()
CorrelationDataSource getDataSourceDetails(String dataSourceDeviceId)
void postMessage(final IngestMessage message)
void fireModuleDataEvent(ModuleDataEvent moduleDataEvent)
Long getCountArtifactInstancesByCaseDataSource(String caseUUID, String dataSourceID)
static boolean isEnabled()
static CorrelationDataSource fromTSKDataSource(Content dataSource)
boolean isArtifactlKnownBadByReference(CorrelationAttribute.Type aType, String value)
Blackboard getBlackboard()
synchronized void indexArtifact(BlackboardArtifact artifact)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
static EamOrganization getDefault()
static synchronized void incrementCorrelationEngineModuleCount()
static synchronized void decrementCorrelationEngineModuleCount()
static void warn(String title, String message)
void newDataSource(CorrelationDataSource eamDataSource)
static synchronized IngestServices getInstance()