19 package org.sleuthkit.autopsy.centralrepository.ingestmodule;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.logging.Level;
26 import java.util.stream.Collectors;
27 import org.openide.util.NbBundle.Messages;
52 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT;
54 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT;
55 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME;
65 @Messages({
"CentralRepoIngestModule.prevTaggedSet.text=Previously Tagged As Notable (Central Repository)",
66 "CentralRepoIngestModule.prevCaseComment.text=Previous Case: "})
71 static final boolean DEFAULT_FLAG_TAGGED_NOTABLE_ITEMS =
true;
72 static final boolean DEFAULT_FLAG_PREVIOUS_DEVICES =
true;
73 static final boolean DEFAULT_CREATE_CR_PROPERTIES =
true;
83 private final boolean flagTaggedNotableItems;
84 private final boolean flagPreviouslySeenDevices;
85 private Blackboard blackboard;
86 private final boolean createCorrelationProperties;
93 CentralRepoIngestModule(IngestSettings settings) {
94 flagTaggedNotableItems = settings.isFlagTaggedNotableItems();
95 flagPreviouslySeenDevices = settings.isFlagPreviousDevices();
96 createCorrelationProperties = settings.shouldCreateCorrelationProperties();
100 public ProcessResult process(AbstractFile abstractFile) {
108 return ProcessResult.OK;
114 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
115 return ProcessResult.ERROR;
119 return ProcessResult.OK;
122 if (abstractFile.getKnown() == TskData.FileKnown.KNOWN) {
123 return ProcessResult.OK;
130 logger.log(Level.SEVERE,
"Error connecting to Central Repository database.", ex);
131 return ProcessResult.ERROR;
135 if (!filesType.isEnabled()) {
136 return ProcessResult.OK;
140 String md5 = abstractFile.getMd5Hash();
141 if ((md5 == null) || (HashUtility.isNoDataMd5(md5))) {
142 return ProcessResult.OK;
149 if (abstractFile.getKnown() != TskData.FileKnown.KNOWN && flagTaggedNotableItems) {
154 if (!caseDisplayNamesList.isEmpty()) {
155 postCorrelatedBadFileToBlackboard(abstractFile, caseDisplayNamesList);
158 logger.log(Level.SEVERE,
"Error searching database for artifact.", ex);
159 return ProcessResult.ERROR;
161 logger.log(Level.INFO,
"Error searching database for artifact.", ex);
162 return ProcessResult.ERROR;
167 if (createCorrelationProperties) {
174 abstractFile.getParentPath() + abstractFile.
getName(),
176 TskData.FileKnown.UNKNOWN
178 abstractFile.getId());
181 logger.log(Level.SEVERE,
"Error adding artifact to bulk artifacts.", ex);
182 return ProcessResult.ERROR;
184 logger.log(Level.INFO,
"Error adding artifact to bulk artifacts.", ex);
185 return ProcessResult.ERROR;
188 return ProcessResult.OK;
192 public void shutDown() {
195 if ((
EamDb.
isEnabled() ==
false) || (eamCase == null) || (eamDataSource == null)) {
202 logger.log(Level.SEVERE,
"Error connecting to Central Repository database.", ex);
208 logger.log(Level.SEVERE,
"Error doing bulk insert of artifacts.", ex);
212 logger.log(Level.INFO,
"{0} artifacts in db for case: {1} ds:{2}",
new Object[]{count, eamCase.getDisplayName(), eamDataSource.getName()});
214 logger.log(Level.SEVERE,
"Error counting artifacts.", ex);
223 "CentralRepoIngestModule.notfyBubble.title=Central Repository Not Initialized",
224 "CentralRepoIngestModule.errorMessage.isNotEnabled=Central repository settings are not initialized, cannot run Correlation Engine ingest module."
227 public void startUp(
IngestJobContext context)
throws IngestModuleException {
264 MessageNotifyUtil.
Notify.
warn(Bundle.CentralRepoIngestModule_notfyBubble_title(), Bundle.CentralRepoIngestModule_errorMessage_isNotEnabled());
273 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
274 throw new IngestModuleException(
"Exception while getting open case.", ex);
280 logger.log(Level.SEVERE,
"Cannot run correlation engine on a multi-user case with a SQLite central repository.");
281 throw new IngestModuleException(
"Cannot run on a multi-user case with a SQLite central repository.");
289 logger.log(Level.SEVERE,
"Error connecting to central repository database.", ex);
290 throw new IngestModuleException(
"Error connecting to central repository database.", ex);
296 logger.log(Level.SEVERE,
"Error getting correlation type FILES in ingest module start up.", ex);
297 throw new IngestModuleException(
"Error getting correlation type FILES in ingest module start up.", ex);
301 eamCase = centralRepoDb.
getCase(autopsyCase);
303 throw new IngestModuleException(
"Unable to get case from central repository database ", ex);
309 logger.log(Level.SEVERE,
"Error getting data source info.", ex);
310 throw new IngestModuleException(
"Error getting data source info.", ex);
323 logger.log(Level.SEVERE,
"Error adding data source to Central Repository.", ex);
324 throw new IngestModuleException(
"Error adding data source to Central Repository.", ex);
336 private void postCorrelatedBadFileToBlackboard(AbstractFile abstractFile, List<String> caseDisplayNames) {
338 Collection<BlackboardAttribute> attributes = Arrays.asList(
339 new BlackboardAttribute(
340 TSK_SET_NAME, MODULE_NAME,
341 Bundle.CentralRepoIngestModule_prevTaggedSet_text()),
342 new BlackboardAttribute(
343 TSK_COMMENT, MODULE_NAME,
344 Bundle.CentralRepoIngestModule_prevCaseComment_text() + caseDisplayNames.stream().distinct().collect(Collectors.joining(
","))));
348 if (!blackboard.artifactExists(abstractFile, TSK_INTERESTING_FILE_HIT, attributes)) {
349 BlackboardArtifact tifArtifact = abstractFile.newArtifact(TSK_INTERESTING_FILE_HIT);
350 tifArtifact.addAttributes(attributes);
353 blackboard.postArtifact(tifArtifact, MODULE_NAME);
354 }
catch (Blackboard.BlackboardException ex) {
355 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + tifArtifact.getArtifactID(), ex);
358 sendBadFileInboxMessage(tifArtifact, abstractFile.getName(), abstractFile.getMd5Hash());
360 }
catch (TskCoreException ex) {
361 logger.log(Level.SEVERE,
"Failed to create BlackboardArtifact.", ex);
362 }
catch (IllegalStateException ex) {
363 logger.log(Level.SEVERE,
"Failed to create BlackboardAttribute.", ex);
375 @Messages({
"CentralRepoIngestModule.postToBB.fileName=File Name",
376 "CentralRepoIngestModule.postToBB.md5Hash=MD5 Hash",
377 "CentralRepoIngestModule.postToBB.hashSetSource=Source of Hash",
378 "CentralRepoIngestModule.postToBB.eamHit=Central Repository",
379 "# {0} - Name of file that is Notable",
380 "CentralRepoIngestModule.postToBB.knownBadMsg=Notable: {0}"})
381 public void sendBadFileInboxMessage(BlackboardArtifact artifact, String name, String md5Hash) {
382 StringBuilder detailsSb =
new StringBuilder();
384 detailsSb.append(
"<table border='0' cellpadding='4' width='280'>");
386 detailsSb.append(
"<tr>");
387 detailsSb.append(
"<th>")
388 .append(Bundle.CentralRepoIngestModule_postToBB_fileName())
390 detailsSb.append(
"<td>")
393 detailsSb.append(
"</tr>");
395 detailsSb.append(
"<tr>");
396 detailsSb.append(
"<th>")
397 .append(Bundle.CentralRepoIngestModule_postToBB_md5Hash())
399 detailsSb.append(
"<td>").append(md5Hash).append(
"</td>");
400 detailsSb.append(
"</tr>");
402 detailsSb.append(
"<tr>");
403 detailsSb.append(
"<th>")
404 .append(Bundle.CentralRepoIngestModule_postToBB_hashSetSource())
406 detailsSb.append(
"<td>").append(Bundle.CentralRepoIngestModule_postToBB_eamHit()).append(
"</td>");
407 detailsSb.append(
"</tr>");
409 detailsSb.append(
"</table>");
412 Bundle.CentralRepoIngestModule_postToBB_knownBadMsg(name),
413 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()