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.Collection;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Properties;
29 import java.util.logging.Level;
30 import org.openide.util.NbBundle.Messages;
37 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT;
38 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD;
40 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID;
50 final class ExtractZoneIdentifier
extends Extract {
52 private static final Logger LOG = Logger.getLogger(ExtractEdge.class.getName());
54 private static final String ZONE_IDENTIFIER_FILE =
"%:Zone.Identifier";
55 private static final String ZONE_IDENTIFIER =
":Zone.Identifier";
56 private Content dataSource;
59 "ExtractZone_process_errMsg_find=A failure occured while searching for :Zone.Indentifier files.",
60 "ExtractZone_process_errMsg=An error occured processing ':Zone.Indentifier' files.",
61 "ExtractZone_progress_Msg=Extracting :Zone.Identifer files"
65 void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) {
66 this.dataSource = dataSource;
67 progressBar.progress(Bundle.ExtractZone_progress_Msg());
69 List<AbstractFile> zoneFiles = null;
71 zoneFiles = currentCase.getServices().getFileManager().findFiles(dataSource, ZONE_IDENTIFIER_FILE);
72 }
catch (TskCoreException ex) {
73 addErrorMessage(Bundle.ExtractZone_process_errMsg_find());
74 LOG.log(Level.SEVERE,
"Unable to find zone identifier files, exception thrown. ", ex);
77 if (zoneFiles == null || zoneFiles.isEmpty()) {
81 Set<Long> knownPathIDs = null;
83 knownPathIDs = getPathIDsForType(TSK_WEB_DOWNLOAD);
84 }
catch (TskCoreException ex) {
85 addErrorMessage(Bundle.ExtractZone_process_errMsg());
86 LOG.log(Level.SEVERE,
"Failed to build PathIDs List for TSK_WEB_DOWNLOAD", ex);
89 if (knownPathIDs == null) {
93 Collection<BlackboardArtifact> associatedObjectArtifacts =
new ArrayList<>();
94 Collection<BlackboardArtifact> downloadArtifacts =
new ArrayList<>();
96 for (AbstractFile zoneFile : zoneFiles) {
98 if (context.dataSourceIngestIsCancelled()) {
103 processZoneFile(context, zoneFile, associatedObjectArtifacts, downloadArtifacts, knownPathIDs);
104 }
catch (TskCoreException ex) {
105 addErrorMessage(Bundle.ExtractZone_process_errMsg());
106 String message = String.format(
"Failed to process zone identifier file %s", zoneFile.getName());
107 LOG.log(Level.WARNING, message, ex);
111 if (!context.dataSourceIngestIsCancelled()) {
112 postArtifacts(associatedObjectArtifacts);
113 postArtifacts(downloadArtifacts);
127 private void processZoneFile(IngestJobContext context,
128 AbstractFile zoneFile, Collection<BlackboardArtifact> associatedObjectArtifacts,
129 Collection<BlackboardArtifact> downloadArtifacts,
130 Set<Long> knownPathIDs)
throws TskCoreException {
132 ZoneIdentifierInfo zoneInfo = null;
135 zoneInfo =
new ZoneIdentifierInfo(zoneFile);
136 }
catch (IOException ex) {
137 String message = String.format(
"Unable to parse temporary File for %s", zoneFile.getName());
138 LOG.log(Level.WARNING, message, ex);
141 if (zoneInfo == null) {
145 AbstractFile downloadFile = getDownloadFile(zoneFile);
147 if (downloadFile != null) {
149 if (!knownPathIDs.contains(downloadFile.getId())) {
152 BlackboardArtifact downloadBba = createDownloadArtifact(zoneFile, zoneInfo, downloadFile);
153 downloadArtifacts.add(downloadBba);
155 if (downloadFile.getArtifactsCount(TSK_ASSOCIATED_OBJECT) == 0) {
156 associatedObjectArtifacts.add(createAssociatedArtifact(downloadFile, downloadBba));
172 private AbstractFile getDownloadFile(AbstractFile zoneFile)
throws TskCoreException {
174 String downloadFileName = zoneFile.getName().replace(ZONE_IDENTIFIER,
"");
180 AbstractFile potentialDownloadFile = currentCase.getSleuthkitCase().getAbstractFileById(zoneFile.getId() - 1);
181 if (isZoneFileMatch(zoneFile, downloadFileName, potentialDownloadFile)) {
182 return potentialDownloadFile;
184 potentialDownloadFile = currentCase.getSleuthkitCase().getAbstractFileById(zoneFile.getId() - 2);
185 if (isZoneFileMatch(zoneFile, downloadFileName, potentialDownloadFile)) {
186 return potentialDownloadFile;
190 List<AbstractFile> fileList = fileManager.
findFilesExactName(zoneFile.getParent().getId(), downloadFileName);
192 for (AbstractFile file : fileList) {
193 if (isZoneFileMatch(zoneFile, downloadFileName, file)) {
213 private boolean isZoneFileMatch(AbstractFile zoneFile, String expectedDownloadFileName, AbstractFile possibleDownloadFile) {
215 if (zoneFile == null || possibleDownloadFile == null || expectedDownloadFileName == null) {
219 if (zoneFile.getMetaAddr() != possibleDownloadFile.getMetaAddr()) {
223 if (!expectedDownloadFileName.equals(possibleDownloadFile.getName())) {
227 if (!possibleDownloadFile.getParentPath().equals(zoneFile.getParentPath())) {
243 private BlackboardArtifact createDownloadArtifact(AbstractFile zoneFile, ZoneIdentifierInfo zoneInfo, AbstractFile downloadFile)
throws TskCoreException {
245 String downloadFilePath = downloadFile.getParentPath() + downloadFile.getName();
246 long pathID = Util.findID(dataSource, downloadFilePath);
247 Collection<BlackboardAttribute> bbattributes = createDownloadAttributes(
248 downloadFilePath, pathID,
249 zoneInfo.getURL(), null,
250 (zoneInfo.getURL() != null ? NetworkUtils.extractDomain(zoneInfo.getURL()) :
""),
252 if (zoneInfo.getZoneIdAsString() != null) {
253 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT,
254 RecentActivityExtracterModuleFactory.getModuleName(),
255 zoneInfo.getZoneIdAsString()));
257 return createArtifactWithAttributes(TSK_WEB_DOWNLOAD, zoneFile, bbattributes);
269 private Set<Long> getPathIDsForType(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
270 Set<Long> idList =
new HashSet<>();
271 for (BlackboardArtifact artifact : currentCase.getSleuthkitCase().getBlackboardArtifacts(type)) {
272 BlackboardAttribute pathIDAttribute = artifact.getAttribute(
new BlackboardAttribute.Type(TSK_PATH_ID));
274 if (pathIDAttribute != null) {
275 long contentID = pathIDAttribute.getValueLong();
276 if (contentID != -1) {
277 idList.add(contentID);
285 "ExtractZone_Local_Machine=Local Machine Zone",
286 "ExtractZone_Local_Intranet=Local Intranet Zone",
287 "ExtractZone_Trusted=Trusted Sites Zone",
288 "ExtractZone_Internet=Internet Zone",
289 "ExtractZone_Restricted=Restricted Sites Zone"
302 private static final String ZONE_ID =
"ZoneId";
303 private static final String REFERRER_URL =
"ReferrerUrl";
304 private static final String HOST_URL =
"HostUrl";
305 private static final String FAMILY_NAME =
"LastWriterPackageFamilyName";
308 private final Properties properties =
new Properties(null);
320 fileName = zoneFile.getName();
323 properties.load(
new ReadContentInputStream(zoneFile));
324 }
catch (IllegalArgumentException ex) {
325 String message = String.format(
"Unable to parse Zone Id for File %s", fileName);
326 LOG.log(Level.WARNING, message);
337 String value = properties.getProperty(ZONE_ID);
340 zoneValue = Integer.parseInt(value);
342 }
catch (NumberFormatException ex) {
343 String message = String.format(
"Unable to parse Zone Id for File %s", fileName);
344 LOG.log(Level.WARNING, message);
356 switch (getZoneId()) {
358 return Bundle.ExtractZone_Local_Machine();
360 return Bundle.ExtractZone_Local_Intranet();
362 return Bundle.ExtractZone_Trusted();
364 return Bundle.ExtractZone_Internet();
366 return Bundle.ExtractZone_Restricted();
378 return properties.getProperty(HOST_URL);
387 return properties.getProperty(REFERRER_URL);
396 return properties.getProperty(FAMILY_NAME);
List< AbstractFile > findFilesExactName(long parentId, String name)