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;
39 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_DOWNLOAD_SOURCE;
40 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD;
42 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN;
43 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION;
44 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID;
45 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL;
55 final class ExtractZoneIdentifier
extends Extract {
57 private static final Logger LOG = Logger.getLogger(ExtractEdge.class.getName());
59 private static final String ZONE_IDENTIFIER_FILE =
"%:Zone.Identifier";
60 private static final String ZONE_IDENTIFIER =
":Zone.Identifier";
63 "ExtractZone_process_errMsg_find=A failure occured while searching for :Zone.Indentifier files.",
64 "ExtractZone_process_errMsg=An error occured processing ':Zone.Indentifier' files.",
65 "ExtractZone_progress_Msg=Extracting :Zone.Identifer files"
69 void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) {
71 progressBar.progress(Bundle.ExtractZone_progress_Msg());
73 List<AbstractFile> zoneFiles = null;
75 zoneFiles = currentCase.getServices().getFileManager().findFiles(dataSource, ZONE_IDENTIFIER_FILE);
76 }
catch (TskCoreException ex) {
77 addErrorMessage(Bundle.ExtractZone_process_errMsg_find());
78 LOG.log(Level.SEVERE,
"Unable to find zone identifier files, exception thrown. ", ex);
81 if (zoneFiles == null || zoneFiles.isEmpty()) {
85 Set<Long> knownPathIDs = null;
87 knownPathIDs = getPathIDsForType(TSK_WEB_DOWNLOAD);
88 }
catch (TskCoreException ex) {
89 addErrorMessage(Bundle.ExtractZone_process_errMsg());
90 LOG.log(Level.SEVERE,
"Failed to build PathIDs List for TSK_WEB_DOWNLOAD", ex);
93 if (knownPathIDs == null) {
97 Collection<BlackboardArtifact> sourceArtifacts =
new ArrayList<>();
98 Collection<BlackboardArtifact> downloadArtifacts =
new ArrayList<>();
100 for (AbstractFile zoneFile : zoneFiles) {
102 if (context.dataSourceIngestIsCancelled()) {
107 processZoneFile(context, dataSource, zoneFile, sourceArtifacts, downloadArtifacts, knownPathIDs);
108 }
catch (TskCoreException ex) {
109 addErrorMessage(Bundle.ExtractZone_process_errMsg());
110 String message = String.format(
"Failed to process zone identifier file %s", zoneFile.getName());
111 LOG.log(Level.WARNING, message, ex);
115 postArtifacts(sourceArtifacts);
116 postArtifacts(downloadArtifacts);
130 private void processZoneFile(IngestJobContext context, Content dataSource,
131 AbstractFile zoneFile, Collection<BlackboardArtifact> sourceArtifacts,
132 Collection<BlackboardArtifact> downloadArtifacts,
133 Set<Long> knownPathIDs)
throws TskCoreException {
135 ZoneIdentifierInfo zoneInfo = null;
138 zoneInfo =
new ZoneIdentifierInfo(zoneFile);
139 }
catch (IOException ex) {
140 String message = String.format(
"Unable to parse temporary File for %s", zoneFile.getName());
141 LOG.log(Level.WARNING, message, ex);
144 if (zoneInfo == null) {
148 AbstractFile downloadFile = getDownloadFile(dataSource, zoneFile);
150 if (downloadFile != null) {
152 if (!knownPathIDs.contains(downloadFile.getDataSourceObjectId())) {
155 BlackboardArtifact downloadBba = createDownloadArtifact(zoneFile, zoneInfo);
156 if (downloadBba != null) {
157 downloadArtifacts.add(downloadBba);
162 if (downloadFile.getArtifactsCount(TSK_DOWNLOAD_SOURCE) == 0) {
163 BlackboardArtifact sourceBba = createDownloadSourceArtifact(downloadFile, zoneInfo);
164 if (sourceBba != null) {
165 sourceArtifacts.add(sourceBba);
181 private AbstractFile getDownloadFile(Content dataSource, AbstractFile zoneFile)
throws TskCoreException {
182 AbstractFile downloadFile = null;
185 = currentCase.getServices().getFileManager();
187 String downloadFileName = zoneFile.getName().replace(ZONE_IDENTIFIER,
"");
189 List<AbstractFile> fileList = fileManager.
findFiles(dataSource, downloadFileName, zoneFile.getParentPath());
191 if (fileList.size() == 1) {
192 downloadFile = fileList.get(0);
195 if (!downloadFile.getParentPath().equals(zoneFile.getParentPath())) {
197 }
else if (zoneFile.getMetaAddr() != downloadFile.getMetaAddr()) {
215 private BlackboardArtifact createDownloadSourceArtifact(AbstractFile downloadFile, ZoneIdentifierInfo zoneInfo) {
217 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
219 bbattributes.addAll(Arrays.asList(
220 new BlackboardAttribute(TSK_URL,
221 RecentActivityExtracterModuleFactory.getModuleName(),
222 StringUtils.defaultString(zoneInfo.getURL(),
"")),
224 new BlackboardAttribute(TSK_DOMAIN,
225 RecentActivityExtracterModuleFactory.getModuleName(),
226 (zoneInfo.getURL() != null) ? NetworkUtils.extractDomain(zoneInfo.getURL()) :
""),
228 new BlackboardAttribute(TSK_LOCATION,
229 RecentActivityExtracterModuleFactory.getModuleName(),
230 StringUtils.defaultString(zoneInfo.getZoneIdAsString(),
""))));
232 return createArtifactWithAttributes(TSK_DOWNLOAD_SOURCE, downloadFile, bbattributes);
243 private BlackboardArtifact createDownloadArtifact(AbstractFile zoneFile, ZoneIdentifierInfo zoneInfo) {
245 Collection<BlackboardAttribute> bbattributes = createDownloadAttributes(
247 zoneInfo.getURL(), null,
248 (zoneInfo.getURL() != null ? NetworkUtils.extractDomain(zoneInfo.getURL()) :
""),
250 return createArtifactWithAttributes(TSK_WEB_DOWNLOAD, zoneFile, bbattributes);
262 private Set<Long> getPathIDsForType(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
263 Set<Long> idList =
new HashSet<>();
264 for (BlackboardArtifact artifact : currentCase.getSleuthkitCase().getBlackboardArtifacts(type)) {
265 BlackboardAttribute pathIDAttribute = artifact.getAttribute(
new BlackboardAttribute.Type(TSK_PATH_ID));
267 if (pathIDAttribute != null) {
268 long contentID = pathIDAttribute.getValueLong();
269 if (contentID != -1) {
270 idList.add(contentID);
278 "ExtractZone_Local_Machine=Local Machine Zone",
279 "ExtractZone_Local_Intranet=Local Intranet Zone",
280 "ExtractZone_Trusted=Trusted Sites Zone",
281 "ExtractZone_Internet=Internet Zone",
282 "ExtractZone_Restricted=Restricted Sites Zone"
295 private static final String ZONE_ID =
"ZoneId";
296 private static final String REFERRER_URL =
"ReferrerUrl";
297 private static final String HOST_URL =
"HostUrl";
298 private static final String FAMILY_NAME =
"LastWriterPackageFamilyName";
300 private final Properties properties =
new Properties(null);
312 properties.load(
new ReadContentInputStream(zoneFile));
322 String value = properties.getProperty(ZONE_ID);
324 zoneValue = Integer.parseInt(value);
336 switch (getZoneId()) {
338 return Bundle.ExtractZone_Local_Machine();
340 return Bundle.ExtractZone_Local_Intranet();
342 return Bundle.ExtractZone_Trusted();
344 return Bundle.ExtractZone_Internet();
346 return Bundle.ExtractZone_Restricted();
358 return properties.getProperty(HOST_URL);
367 return properties.getProperty(REFERRER_URL);
376 return properties.getProperty(FAMILY_NAME);
synchronized List< AbstractFile > findFiles(String fileName)