19 package org.sleuthkit.autopsy.recentactivity;
 
   21 import java.io.FileNotFoundException;
 
   22 import java.io.IOException;
 
   23 import java.util.ArrayList;
 
   24 import java.util.Arrays;
 
   25 import java.util.Collection;
 
   26 import java.util.HashSet;
 
   27 import java.util.List;
 
   28 import java.util.Properties;
 
   30 import java.util.logging.Level;
 
   31 import org.apache.commons.lang3.StringUtils;
 
   32 import org.openide.util.NbBundle.Messages;
 
   41 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_DOWNLOAD_SOURCE;
 
   42 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD;
 
   44 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN;
 
   45 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION;
 
   46 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID;
 
   47 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL;
 
   57 final class ExtractZoneIdentifier 
extends Extract {
 
   59     private static final Logger LOG = Logger.getLogger(ExtractEdge.class.getName());
 
   61     private static final String ZONE_IDENTIFIER_FILE = 
"%:Zone.Identifier"; 
 
   62     private static final String ZONE_IDENTIFIER = 
":Zone.Identifier"; 
 
   65         "ExtractZone_process_errMsg_find=A failure occured while searching for :Zone.Indentifier files.",
 
   66         "ExtractZone_process_errMsg=An error occured processing ':Zone.Indentifier' files.",
 
   67         "ExtractZone_progress_Msg=Extracting :Zone.Identifer files" 
   71     void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) {
 
   73         progressBar.progress(Bundle.ExtractZone_progress_Msg());
 
   75         List<AbstractFile> zoneFiles = null;
 
   77             zoneFiles = currentCase.getServices().getFileManager().findFiles(dataSource, ZONE_IDENTIFIER_FILE);
 
   78         } 
catch (TskCoreException ex) {
 
   79             addErrorMessage(Bundle.ExtractZone_process_errMsg_find());
 
   80             LOG.log(Level.SEVERE, 
"Unable to find zone identifier files, exception thrown. ", ex); 
 
   83         if (zoneFiles == null || zoneFiles.isEmpty()) {
 
   87         Set<Long> knownPathIDs = null;
 
   89             knownPathIDs = getPathIDsForType(TSK_WEB_DOWNLOAD);
 
   90         } 
catch (TskCoreException ex) {
 
   91             addErrorMessage(Bundle.ExtractZone_process_errMsg());
 
   92             LOG.log(Level.SEVERE, 
"Failed to build PathIDs List for TSK_WEB_DOWNLOAD", ex); 
 
   95         if (knownPathIDs == null) {
 
   99         Collection<BlackboardArtifact> sourceArtifacts = 
new ArrayList<>();
 
  100         Collection<BlackboardArtifact> downloadArtifacts = 
new ArrayList<>();
 
  102         for (AbstractFile zoneFile : zoneFiles) {
 
  104                 processZoneFile(context, dataSource, zoneFile, sourceArtifacts, downloadArtifacts, knownPathIDs);
 
  105             } 
catch (TskCoreException ex) {
 
  106                 addErrorMessage(Bundle.ExtractZone_process_errMsg());
 
  107                 String message = String.format(
"Failed to process zone identifier file  %s", zoneFile.getName()); 
 
  108                 LOG.log(Level.WARNING, message, ex);
 
  112         IngestServices services = IngestServices.getInstance();
 
  114         if (!sourceArtifacts.isEmpty()) {
 
  115             services.fireModuleDataEvent(
new ModuleDataEvent(
 
  116                     RecentActivityExtracterModuleFactory.getModuleName(),
 
  117                     TSK_DOWNLOAD_SOURCE, sourceArtifacts));
 
  120         if (!downloadArtifacts.isEmpty()) {
 
  121             services.fireModuleDataEvent(
new ModuleDataEvent(
 
  122                     RecentActivityExtracterModuleFactory.getModuleName(),
 
  123                     TSK_WEB_DOWNLOAD, downloadArtifacts));
 
  138     private void processZoneFile(IngestJobContext context, Content dataSource,
 
  139             AbstractFile zoneFile, Collection<BlackboardArtifact> sourceArtifacts,
 
  140             Collection<BlackboardArtifact> downloadArtifacts,
 
  141             Set<Long> knownPathIDs) 
throws TskCoreException {
 
  143         ZoneIdentifierInfo zoneInfo = null;
 
  146             zoneInfo = 
new ZoneIdentifierInfo(zoneFile);
 
  147         } 
catch (IOException ex) {
 
  148             String message = String.format(
"Unable to parse temporary File for %s", zoneFile.getName()); 
 
  149             LOG.log(Level.WARNING, message, ex);
 
  152         if (zoneInfo == null) {
 
  156         AbstractFile downloadFile = getDownloadFile(dataSource, zoneFile);
 
  158         if (downloadFile != null) {
 
  160             if (!knownPathIDs.contains(downloadFile.getDataSourceObjectId())) {
 
  163                 BlackboardArtifact downloadBba = createDownloadArtifact(zoneFile, zoneInfo);
 
  164                 if (downloadBba != null) {
 
  165                     downloadArtifacts.add(downloadBba);
 
  170             if (downloadFile.getArtifactsCount(TSK_DOWNLOAD_SOURCE) == 0) {
 
  171                 BlackboardArtifact sourceBba = createDownloadSourceArtifact(downloadFile, zoneInfo);
 
  172                 if (sourceBba != null) {
 
  173                     sourceArtifacts.add(sourceBba);
 
  189     private AbstractFile getDownloadFile(Content dataSource, AbstractFile zoneFile) 
throws TskCoreException {
 
  190         AbstractFile downloadFile = null;
 
  193                 = currentCase.getServices().getFileManager();
 
  195         String downloadFileName = zoneFile.getName().replace(ZONE_IDENTIFIER, 
""); 
 
  197         List<AbstractFile> fileList = fileManager.
findFiles(dataSource, downloadFileName, zoneFile.getParentPath());
 
  199         if (fileList.size() == 1) {
 
  200             downloadFile = fileList.get(0);
 
  203             if (!downloadFile.getParentPath().equals(zoneFile.getParentPath())) {
 
  205             } 
else if (zoneFile.getMetaAddr() != downloadFile.getMetaAddr()) {
 
  223     private BlackboardArtifact createDownloadSourceArtifact(AbstractFile downloadFile, ZoneIdentifierInfo zoneInfo) {
 
  225         Collection<BlackboardAttribute> bbattributes = 
new ArrayList<>();
 
  227         bbattributes.addAll(Arrays.asList(
 
  228                 new BlackboardAttribute(TSK_URL,
 
  229                 RecentActivityExtracterModuleFactory.getModuleName(),
 
  230                 StringUtils.defaultString(zoneInfo.getURL(), 
"")),
 
  232                 new BlackboardAttribute(TSK_DOMAIN,
 
  233                 RecentActivityExtracterModuleFactory.getModuleName(),
 
  234                 (zoneInfo.getURL() != null) ? NetworkUtils.extractDomain(zoneInfo.getURL()) : 
""),
 
  236                 new BlackboardAttribute(TSK_LOCATION,
 
  237                 RecentActivityExtracterModuleFactory.getModuleName(),
 
  238                 StringUtils.defaultString(zoneInfo.getZoneIdAsString(), 
"")))); 
 
  240         return addArtifact(TSK_DOWNLOAD_SOURCE, downloadFile, bbattributes);
 
  251     private BlackboardArtifact createDownloadArtifact(AbstractFile zoneFile, ZoneIdentifierInfo zoneInfo) {
 
  253         Collection<BlackboardAttribute> bbattributes = createDownloadAttributes(
 
  255                 zoneInfo.getURL(), null,
 
  256                 (zoneInfo.getURL() != null ? NetworkUtils.extractDomain(zoneInfo.getURL()) : 
""),
 
  258         return addArtifact(TSK_WEB_DOWNLOAD, zoneFile, bbattributes);
 
  270     private Set<Long> getPathIDsForType(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
 
  271         Set<Long> idList = 
new HashSet<>();
 
  272         for (BlackboardArtifact artifact : currentCase.getSleuthkitCase().getBlackboardArtifacts(type)) {
 
  273             BlackboardAttribute pathIDAttribute = artifact.getAttribute(
new BlackboardAttribute.Type(TSK_PATH_ID));
 
  275             if (pathIDAttribute != null) {
 
  276                 long contentID = pathIDAttribute.getValueLong();
 
  277                 if (contentID != -1) {
 
  278                     idList.add(contentID);
 
  286         "ExtractZone_Local_Machine=Local Machine Zone",
 
  287         "ExtractZone_Local_Intranet=Local Intranet Zone",
 
  288         "ExtractZone_Trusted=Trusted Sites Zone",
 
  289         "ExtractZone_Internet=Internet Zone",
 
  290         "ExtractZone_Restricted=Restricted Sites Zone" 
  303         private static final String ZONE_ID = 
"ZoneId"; 
 
  304         private static final String REFERRER_URL = 
"ReferrerUrl"; 
 
  305         private static final String HOST_URL = 
"HostUrl"; 
 
  306         private static final String FAMILY_NAME = 
"LastWriterPackageFamilyName"; 
 
  308         private final Properties properties = 
new Properties(null);
 
  320             properties.load(
new ReadContentInputStream(zoneFile));
 
  330             String value = properties.getProperty(ZONE_ID);
 
  332                 zoneValue = Integer.parseInt(value);
 
  344             switch (getZoneId()) {
 
  346                     return Bundle.ExtractZone_Local_Machine();
 
  348                     return Bundle.ExtractZone_Local_Intranet();
 
  350                     return Bundle.ExtractZone_Trusted();
 
  352                     return Bundle.ExtractZone_Internet();
 
  354                     return Bundle.ExtractZone_Restricted();
 
  366             return properties.getProperty(HOST_URL);
 
  375             return properties.getProperty(REFERRER_URL);
 
  384             return properties.getProperty(FAMILY_NAME);
 
synchronized List< AbstractFile > findFiles(String fileName)