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;
64 @Messages({
"CentralRepoIngestModule.prevTaggedSet.text=Previously Tagged As Notable (Central Repository)",
65 "CentralRepoIngestModule.prevCaseComment.text=Previous Case: "})
70 static final boolean DEFAULT_FLAG_TAGGED_NOTABLE_ITEMS =
false;
71 static final boolean DEFAULT_FLAG_PREVIOUS_DEVICES =
false;
72 static final boolean DEFAULT_CREATE_CR_PROPERTIES =
true;
82 private final boolean flagTaggedNotableItems;
83 private final boolean flagPreviouslySeenDevices;
84 private Blackboard blackboard;
85 private final boolean createCorrelationProperties;
92 CentralRepoIngestModule(IngestSettings settings) {
93 flagTaggedNotableItems = settings.isFlagTaggedNotableItems();
94 flagPreviouslySeenDevices = settings.isFlagPreviousDevices();
95 createCorrelationProperties = settings.shouldCreateCorrelationProperties();
99 public ProcessResult process(AbstractFile abstractFile) {
107 return ProcessResult.OK;
113 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
114 return ProcessResult.ERROR;
118 return ProcessResult.OK;
121 if (abstractFile.getKnown() == TskData.FileKnown.KNOWN) {
122 return ProcessResult.OK;
129 logger.log(Level.SEVERE,
"Error connecting to Central Repository database.", ex);
130 return ProcessResult.ERROR;
134 if (!filesType.isEnabled()) {
135 return ProcessResult.OK;
139 String md5 = abstractFile.getMd5Hash();
140 if ((md5 == null) || (HashUtility.isNoDataMd5(md5))) {
141 return ProcessResult.OK;
148 if (abstractFile.getKnown() != TskData.FileKnown.KNOWN && flagTaggedNotableItems) {
153 if (!caseDisplayNamesList.isEmpty()) {
154 postCorrelatedBadFileToBlackboard(abstractFile, caseDisplayNamesList);
157 logger.log(Level.SEVERE,
"Error searching database for artifact.", ex);
158 return ProcessResult.ERROR;
160 logger.log(Level.INFO,
"Error searching database for artifact.", ex);
161 return ProcessResult.ERROR;
166 if (createCorrelationProperties) {
173 abstractFile.getParentPath() + abstractFile.
getName(),
175 TskData.FileKnown.UNKNOWN
177 abstractFile.getId());
180 logger.log(Level.SEVERE,
"Error adding artifact to bulk artifacts.", ex);
181 return ProcessResult.ERROR;
183 logger.log(Level.INFO,
"Error adding artifact to bulk artifacts.", ex);
184 return ProcessResult.ERROR;
187 return ProcessResult.OK;
191 public void shutDown() {
201 logger.log(Level.SEVERE,
"Error connecting to Central Repository database.", ex);
207 logger.log(Level.SEVERE,
"Error doing bulk insert of artifacts.", ex);
211 logger.log(Level.INFO,
"{0} artifacts in db for case: {1} ds:{2}",
new Object[]{count, eamCase.getDisplayName(), eamDataSource.getName()});
213 logger.log(Level.SEVERE,
"Error counting artifacts.", ex);
222 "CentralRepoIngestModule.notfyBubble.title=Central Repository Not Initialized",
223 "CentralRepoIngestModule.errorMessage.isNotEnabled=Central repository settings are not initialized, cannot run Central Repository ingest module."
226 public void startUp(
IngestJobContext context)
throws IngestModuleException {
263 MessageNotifyUtil.
Notify.
warn(Bundle.CentralRepoIngestModule_notfyBubble_title(), Bundle.CentralRepoIngestModule_errorMessage_isNotEnabled());
272 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
273 throw new IngestModuleException(
"Exception while getting open case.", ex);
279 logger.log(Level.SEVERE,
"Cannot run Central Repository ingest module on a multi-user case with a SQLite central repository.");
280 throw new IngestModuleException(
"Cannot run on a multi-user case with a SQLite central repository.");
288 logger.log(Level.SEVERE,
"Error connecting to central repository database.", ex);
289 throw new IngestModuleException(
"Error connecting to central repository database.", ex);
295 logger.log(Level.SEVERE,
"Error getting correlation type FILES in ingest module start up.", ex);
296 throw new IngestModuleException(
"Error getting correlation type FILES in ingest module start up.", ex);
300 eamCase = centralRepoDb.
getCase(autopsyCase);
302 throw new IngestModuleException(
"Unable to get case from central repository database ", ex);
308 logger.log(Level.SEVERE,
"Error getting data source info.", ex);
309 throw new IngestModuleException(
"Error getting data source info.", ex);
322 logger.log(Level.SEVERE,
"Error adding data source to Central Repository.", ex);
323 throw new IngestModuleException(
"Error adding data source to Central Repository.", ex);
335 private void postCorrelatedBadFileToBlackboard(AbstractFile abstractFile, List<String> caseDisplayNames) {
337 Collection<BlackboardAttribute> attributes = Arrays.asList(
338 new BlackboardAttribute(
339 TSK_SET_NAME, MODULE_NAME,
340 Bundle.CentralRepoIngestModule_prevTaggedSet_text()),
341 new BlackboardAttribute(
342 TSK_COMMENT, MODULE_NAME,
343 Bundle.CentralRepoIngestModule_prevCaseComment_text() + caseDisplayNames.stream().distinct().collect(Collectors.joining(
","))));
347 if (!blackboard.artifactExists(abstractFile, TSK_INTERESTING_FILE_HIT, attributes)) {
348 BlackboardArtifact tifArtifact = abstractFile.newArtifact(TSK_INTERESTING_FILE_HIT);
349 tifArtifact.addAttributes(attributes);
352 blackboard.postArtifact(tifArtifact, MODULE_NAME);
353 }
catch (Blackboard.BlackboardException ex) {
354 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + tifArtifact.getArtifactID(), ex);
357 sendBadFileInboxMessage(tifArtifact, abstractFile.getName(), abstractFile.getMd5Hash(), caseDisplayNames);
359 }
catch (TskCoreException ex) {
360 logger.log(Level.SEVERE,
"Failed to create BlackboardArtifact.", ex);
361 }
catch (IllegalStateException ex) {
362 logger.log(Level.SEVERE,
"Failed to create BlackboardAttribute.", ex);
367 "CentralRepoIngestModule_notable_message_header=<html>A file in this data source was previously seen and tagged as Notable.<br>",
368 "CentralRepoIngestModel_name_header=Name:<br>",
369 "CentralRepoIngestModel_previous_case_header=<br>Previous Cases:<br>",
370 "# {0} - Name of file that is Notable",
371 "CentralRepoIngestModule_postToBB_knownBadMsg=Notable: {0}"
383 private void sendBadFileInboxMessage(BlackboardArtifact artifact, String name, String md5Hash, List<String> caseDisplayNames) {
384 StringBuilder detailsSb =
new StringBuilder(1024);
386 detailsSb.append(Bundle.CentralRepoIngestModule_notable_message_header()).append(Bundle.CentralRepoIngestModel_name_header());
387 detailsSb.append(name).append(Bundle.CentralRepoIngestModel_previous_case_header());
388 for (String str : caseDisplayNames) {
389 detailsSb.append(str).append(
"<br>");
391 detailsSb.append(
"</html>");
393 Bundle.CentralRepoIngestModule_postToBB_knownBadMsg(name),
394 detailsSb.toString(),
CentralRepoPlatforms getDbPlatform()
void addAttributeInstanceBulk(CorrelationAttributeInstance eamArtifact)
synchronized long decrementAndGet(long jobId)
static synchronized int getCeModuleInstanceCount()
static IngestMessage createDataMessage(String source, String subject, String detailsHtml, String uniqueKey, BlackboardArtifact data)
static boolean runningWithGUI
static synchronized boolean isFlagSeenDevices()
static synchronized void setCreateCrProperties(boolean value)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
synchronized long incrementAndGet(long jobId)
CorrelationCase getCase(Case autopsyCase)
static CentralRepoDbChoice getSavedDbChoice()
List< String > getListCasesHavingArtifactInstancesKnownBad(CorrelationAttributeInstance.Type aType, String value)
static TimingMetric getTimingMetric(String name)
static synchronized boolean isFlagNotableItems()
static boolean isSupportedAbstractFileType(AbstractFile file)
static synchronized void setFlagSeenDevices(boolean value)
void postMessage(final IngestMessage message)
static String getModuleName()
SleuthkitCase getSleuthkitCase()
static synchronized void setFlagNotableItems(boolean value)
CorrelationDataSource newDataSource(CorrelationDataSource eamDataSource)
Long getDataSourceObjectID()
static void submitTimingMetric(TimingMetric metric)
void commitAttributeInstancesBulk()
CorrelationDataSource getDataSource(CorrelationCase correlationCase, Long caseDbDataSourceId)
synchronized static Logger getLogger(String name)
CorrelationAttributeInstance.Type getCorrelationTypeById(int typeId)
static Case getCurrentCaseThrows()
static synchronized boolean shouldCreateCrProperties()
Long getCountArtifactInstancesByCaseDataSource(CorrelationDataSource correlationDataSource)
static synchronized void incrementCorrelationEngineModuleCount()
static synchronized void decrementCorrelationEngineModuleCount()
static CentralRepository getInstance()
static void warn(String title, String message)
static final int FILES_TYPE_ID
static boolean isEnabled()
static synchronized IngestServices getInstance()