19 package org.sleuthkit.autopsy.centralrepository.eventlisteners;
21 import com.google.common.util.concurrent.ThreadFactoryBuilder;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import static java.lang.Boolean.FALSE;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.EnumSet;
29 import java.util.LinkedHashSet;
30 import java.util.List;
32 import java.util.concurrent.ExecutorService;
33 import java.util.concurrent.Executors;
34 import java.util.logging.Level;
35 import java.util.stream.Collectors;
36 import org.apache.commons.lang3.StringUtils;
37 import org.openide.util.NbBundle;
52 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT;
57 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT;
58 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT;
59 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME;
70 @NbBundle.Messages({
"IngestEventsListener.ingestmodule.name=Correlation Engine"})
76 private static final String MODULE_NAME = Bundle.IngestEventsListener_ingestmodule_name();
81 private static final String INGEST_EVENT_THREAD_NAME =
"Ingest-Event-Listener-%d";
85 final Collection<String> recentlyAddedCeArtifacts =
new LinkedHashSet<>();
88 jobProcessingExecutor = Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder().setNameFormat(INGEST_EVENT_THREAD_NAME).build());
116 correlationModuleInstanceCount++;
124 if (getCeModuleInstanceCount() > 0) {
125 correlationModuleInstanceCount--;
133 synchronized static void resetCeModuleInstanceCount() {
134 correlationModuleInstanceCount = 0;
144 return correlationModuleInstanceCount;
153 return flagNotableItems;
162 return flagSeenDevices;
171 return createCrProperties;
180 flagNotableItems = value;
189 flagSeenDevices = value;
198 createCrProperties = value;
206 @NbBundle.Messages({
"IngestEventsListener.prevTaggedSet.text=Previously Tagged As Notable (Central Repository)",
207 "IngestEventsListener.prevCaseComment.text=Previous Case: "})
210 Collection<BlackboardAttribute> attributesForNewArtifact = Arrays.asList(
new BlackboardAttribute(
211 TSK_SET_NAME, MODULE_NAME,
212 Bundle.IngestEventsListener_prevTaggedSet_text()),
213 new BlackboardAttribute(
214 TSK_COMMENT, MODULE_NAME,
215 Bundle.IngestEventsListener_prevCaseComment_text() + caseDisplayNames.stream().distinct().collect(Collectors.joining(
","))),
216 new BlackboardAttribute(
217 TSK_ASSOCIATED_ARTIFACT, MODULE_NAME,
218 originalArtifact.getArtifactID()));
219 makeAndPostInterestingArtifact(originalArtifact, attributesForNewArtifact);
228 @NbBundle.Messages({
"IngestEventsListener.prevExists.text=Previously Seen Devices (Central Repository)",
231 "IngestEventsListener.prevCount.text=Number of previous {0}: {1}"})
233 Collection<BlackboardAttribute> attributesForNewArtifact = Arrays.asList(
new BlackboardAttribute(
234 TSK_SET_NAME, MODULE_NAME,
235 Bundle.IngestEventsListener_prevExists_text()),
236 new BlackboardAttribute(
237 TSK_ASSOCIATED_ARTIFACT, MODULE_NAME,
238 originalArtifact.getArtifactID()));
239 makeAndPostInterestingArtifact(originalArtifact, attributesForNewArtifact);
249 SleuthkitCase tskCase = originalArtifact.getSleuthkitCase();
250 AbstractFile abstractFile = tskCase.getAbstractFileById(originalArtifact.getObjectID());
251 Blackboard blackboard = tskCase.getBlackboard();
253 if (!blackboard.artifactExists(abstractFile, TSK_INTERESTING_ARTIFACT_HIT, attributesForNewArtifact)) {
254 BlackboardArtifact newInterestingArtifact = abstractFile.newArtifact(TSK_INTERESTING_ARTIFACT_HIT);
255 newInterestingArtifact.addAttributes(attributesForNewArtifact);
259 blackboard.postArtifact(newInterestingArtifact, MODULE_NAME);
260 }
catch (Blackboard.BlackboardException ex) {
261 LOGGER.log(Level.SEVERE,
"Unable to index blackboard artifact " + newInterestingArtifact.getArtifactID(), ex);
264 }
catch (TskCoreException ex) {
265 LOGGER.log(Level.SEVERE,
"Failed to create BlackboardArtifact.", ex);
266 }
catch (IllegalStateException ex) {
267 LOGGER.log(Level.SEVERE,
"Failed to create BlackboardAttribute.", ex);
283 LOGGER.log(Level.SEVERE,
"Failed to connect to Central Repository database.", ex);
292 jobProcessingExecutor.submit(
new DataAddedTask(dbManager, evt, flagNotable, flagPrevious, createAttributes));
310 LOGGER.log(Level.SEVERE,
"Failed to connect to Central Repository database.", ex);
315 case DATA_SOURCE_ANALYSIS_COMPLETED: {
329 private final PropertyChangeEvent
event;
339 if (getCeModuleInstanceCount() == 0) {
340 recentlyAddedCeArtifacts.clear();
352 String dataSourceName =
"";
353 long dataSourceObjectId = -1;
360 if (!(dataSource instanceof Image)) {
364 dataSourceName = dataSource.getName();
365 dataSourceObjectId = dataSource.getId();
370 if (null == correlationCase) {
371 correlationCase = dbManager.
newCase(openCase);
375 if (correlationDataSource == null) {
380 if (dataSource instanceof Image) {
381 Image image = (Image) dataSource;
383 String imageMd5Hash = image.
getMd5();
384 if (imageMd5Hash == null) {
387 String crMd5Hash = correlationDataSource.
getMd5();
388 if (StringUtils.equals(imageMd5Hash, crMd5Hash) ==
false) {
389 correlationDataSource.
setMd5(imageMd5Hash);
392 String imageSha1Hash = image.getSha1();
393 if (imageSha1Hash == null) {
396 String crSha1Hash = correlationDataSource.
getSha1();
397 if (StringUtils.equals(imageSha1Hash, crSha1Hash) ==
false) {
398 correlationDataSource.
setSha1(imageSha1Hash);
401 String imageSha256Hash = image.getSha256();
402 if (imageSha256Hash == null) {
403 imageSha256Hash =
"";
405 String crSha256Hash = correlationDataSource.
getSha256();
406 if (StringUtils.equals(imageSha256Hash, crSha256Hash) ==
false) {
407 correlationDataSource.
setSha256(imageSha256Hash);
412 LOGGER.log(Level.SEVERE, String.format(
413 "Unable to fetch data from the Central Repository for data source '%s' (obj_id=%d)",
414 dataSourceName, dataSourceObjectId), ex);
416 LOGGER.log(Level.SEVERE,
"No current case opened.", ex);
417 }
catch (TskCoreException ex) {
418 LOGGER.log(Level.SEVERE, String.format(
419 "Unable to fetch data from the case database for data source '%s' (obj_id=%d)",
420 dataSourceName, dataSourceObjectId), ex);
428 private final PropertyChangeEvent
event;
433 private DataAddedTask(
EamDb db, PropertyChangeEvent evt,
boolean flagNotableItemsEnabled,
boolean flagPreviousItemsEnabled,
boolean createCorrelationAttributes) {
436 this.flagNotableItemsEnabled = flagNotableItemsEnabled;
437 this.flagPreviousItemsEnabled = flagPreviousItemsEnabled;
438 this.createCorrelationAttributes = createCorrelationAttributes;
447 Collection<BlackboardArtifact> bbArtifacts = mde.
getArtifacts();
448 if (null == bbArtifacts) {
451 List<CorrelationAttributeInstance> eamArtifacts =
new ArrayList<>();
453 for (BlackboardArtifact bbArtifact : bbArtifacts) {
459 if (recentlyAddedCeArtifacts.add(eamArtifact.toString())) {
464 if (flagNotableItemsEnabled) {
465 List<String> caseDisplayNames;
468 if (!caseDisplayNames.isEmpty()) {
469 makeAndPostPreviousNotableArtifact(bbArtifact,
473 LOGGER.log(Level.INFO, String.format(
"Unable to flag notable item: %s.", eamArtifact.toString()), ex);
476 if (flagPreviousItemsEnabled
484 List<CorrelationAttributeInstance> previousOccurences = dbManager.
getArtifactInstancesByTypeValue(eamArtifact.getCorrelationType(), eamArtifact.getCorrelationValue());
486 if (!instance.getCorrelationCase().getCaseUUID().equals(eamArtifact.getCorrelationCase().getCaseUUID())) {
487 makeAndPostPreviousSeenArtifact(bbArtifact);
492 LOGGER.log(Level.INFO, String.format(
"Unable to flag notable item: %s.", eamArtifact.toString()), ex);
495 if (createCorrelationAttributes) {
496 eamArtifacts.add(eamArtifact);
500 LOGGER.log(Level.SEVERE,
"Error counting notable artifacts.", ex);
504 if (FALSE == eamArtifacts.isEmpty()) {
509 LOGGER.log(Level.SEVERE,
"Error adding artifact to database.", ex);
Collection< BlackboardArtifact > getArtifacts()
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static List< CorrelationAttributeInstance > makeInstancesFromBlackboardArtifact(BlackboardArtifact artifact, boolean checkEnabled)
static boolean flagSeenDevices
final ExecutorService jobProcessingExecutor
static final int USBID_TYPE_ID
void setMd5(String md5Hash)
static synchronized IngestManager getInstance()
static synchronized int getCeModuleInstanceCount()
DataAddedTask(EamDb db, PropertyChangeEvent evt, boolean flagNotableItemsEnabled, boolean flagPreviousItemsEnabled, boolean createCorrelationAttributes)
static final int ICCID_TYPE_ID
static synchronized boolean isFlagSeenDevices()
List< String > getListCasesHavingArtifactInstancesKnownBad(CorrelationAttributeInstance.Type aType, String value)
static synchronized void setCreateCrProperties(boolean value)
CorrelationCase newCase(CorrelationCase eamCase)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
static void makeAndPostPreviousSeenArtifact(BlackboardArtifact originalArtifact)
boolean isIngestRunning()
DATA_SOURCE_ANALYSIS_COMPLETED
static final int IMEI_TYPE_ID
static void makeAndPostInterestingArtifact(BlackboardArtifact originalArtifact, Collection< BlackboardAttribute > attributesForNewArtifact)
List< CorrelationAttributeInstance > getArtifactInstancesByTypeValue(CorrelationAttributeInstance.Type aType, String value)
static boolean createCrProperties
static synchronized boolean isFlagNotableItems()
void removeIngestJobEventListener(final PropertyChangeListener listener)
final boolean createCorrelationAttributes
static void shutDownTaskExecutor(ExecutorService executor)
void uninstallListeners()
AnalysisCompleteTask(EamDb db, PropertyChangeEvent evt)
final PropertyChangeEvent event
static EamDb getInstance()
CorrelationDataSource getDataSource(CorrelationCase correlationCase, Long caseDbDataSourceId)
void addIngestJobEventListener(final PropertyChangeListener listener)
final boolean flagNotableItemsEnabled
void setSha256(String sha256Hash)
static synchronized void setFlagSeenDevices(boolean value)
void propertyChange(PropertyChangeEvent evt)
static boolean isEnabled()
void setSha1(String sha1Hash)
void propertyChange(PropertyChangeEvent evt)
static int correlationModuleInstanceCount
static synchronized void setFlagNotableItems(boolean value)
static final int MAC_TYPE_ID
static void makeAndPostPreviousNotableArtifact(BlackboardArtifact originalArtifact, List< String > caseDisplayNames)
static final int IMSI_TYPE_ID
CorrelationCase getCase(Case autopsyCase)
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static boolean flagNotableItems
static synchronized boolean shouldCreateCrProperties()
final boolean flagPreviousItemsEnabled
final PropertyChangeEvent event
static synchronized void incrementCorrelationEngineModuleCount()
static synchronized void decrementCorrelationEngineModuleCount()
void addArtifactInstance(CorrelationAttributeInstance eamArtifact)