23 package org.sleuthkit.autopsy.recentactivity;
25 import java.io.BufferedReader;
26 import org.openide.util.NbBundle;
30 import java.io.FileInputStream;
31 import java.io.FileNotFoundException;
32 import java.io.IOException;
33 import java.io.InputStreamReader;
34 import java.text.ParseException;
35 import java.text.SimpleDateFormat;
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.logging.Level;
40 import java.util.Collection;
41 import java.util.Scanner;
42 import java.util.stream.Collectors;
43 import org.openide.modules.InstalledFileLocator;
44 import org.openide.util.NbBundle.Messages;
51 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
53 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
65 class ExtractIE
extends Extract {
67 private static final Logger logger = Logger.getLogger(ExtractIE.class.getName());
68 private final IngestServices services = IngestServices.getInstance();
69 private final String moduleTempResultsDir;
70 private String PASCO_LIB_PATH;
71 private final String JAVA_PATH;
72 private static final String RESOURCE_URL_PREFIX =
"res://";
73 private static final SimpleDateFormat dateFormatter =
new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
74 private Content dataSource;
75 private IngestJobContext context;
78 "Progress_Message_IE_History=IE History",
79 "Progress_Message_IE_Bookmarks=IE Bookmarks",
80 "Progress_Message_IE_Cookies=IE Cookies",
81 "Progress_Message_IE_Downloads=IE Downloads",
82 "Progress_Message_IE_FormHistory=IE Form History",
83 "Progress_Message_IE_AutoFill=IE Auto Fill",
84 "Progress_Message_IE_Logins=IE Logins",
87 ExtractIE() throws NoCurrentCaseException {
88 moduleName = NbBundle.getMessage(ExtractIE.class,
"ExtractIE.moduleName.text");
89 moduleTempResultsDir = RAImageIngestModule.getRATempPath(Case.getCurrentCaseThrows(),
"IE") + File.separator +
"results";
90 JAVA_PATH = PlatformUtil.getJavaPath();
94 public void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) {
95 this.dataSource = dataSource;
96 this.context = context;
99 progressBar.progress(Bundle.Progress_Message_IE_Bookmarks());
102 progressBar.progress(Bundle.Progress_Message_IE_Cookies());
105 progressBar.progress(Bundle.Progress_Message_IE_History());
112 private void getBookmark() {
114 List<AbstractFile> favoritesFiles;
116 favoritesFiles = fileManager.
findFiles(dataSource,
"%.url",
"Favorites");
117 }
catch (TskCoreException ex) {
118 logger.log(Level.WARNING,
"Error fetching 'url' files for Internet Explorer bookmarks.", ex);
119 this.addErrorMessage(
120 NbBundle.getMessage(
this.getClass(),
"ExtractIE.getBookmark.errMsg.errGettingBookmarks",
125 if (favoritesFiles.isEmpty()) {
126 logger.log(Level.INFO,
"Didn't find any IE bookmark files.");
131 Collection<BlackboardArtifact> bbartifacts =
new ArrayList<>();
132 for (AbstractFile fav : favoritesFiles) {
133 if (fav.getSize() == 0) {
137 if (context.dataSourceIngestIsCancelled()) {
141 String url = getURLFromIEBookmarkFile(fav);
143 String name = fav.getName();
144 Long datetime = fav.getCrtime();
145 String Tempdate = datetime.toString();
146 datetime = Long.valueOf(Tempdate);
147 String domain = extractDomain(url);
149 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
150 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_URL,
151 RecentActivityExtracterModuleFactory.getModuleName(), url));
152 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_TITLE,
153 RecentActivityExtracterModuleFactory.getModuleName(), name));
154 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME_CREATED,
155 RecentActivityExtracterModuleFactory.getModuleName(), datetime));
156 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PROG_NAME,
157 RecentActivityExtracterModuleFactory.getModuleName(),
158 NbBundle.getMessage(this.getClass(),
"ExtractIE.moduleName.text")));
159 if (domain != null && domain.isEmpty() ==
false) {
160 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DOMAIN,
161 RecentActivityExtracterModuleFactory.getModuleName(), domain));
164 BlackboardArtifact bbart = createArtifactWithAttributes(ARTIFACT_TYPE.TSK_WEB_BOOKMARK, fav, bbattributes);
166 bbartifacts.add(bbart);
170 postArtifacts(bbartifacts);
173 private String getURLFromIEBookmarkFile(AbstractFile fav) {
174 BufferedReader reader =
new BufferedReader(
new InputStreamReader(
new ReadContentInputStream(fav)));
175 String line, url =
"";
177 line = reader.readLine();
178 while (null != line) {
181 if (line.startsWith(
"URL")) {
182 url = line.substring(line.indexOf(
"=") + 1);
185 line = reader.readLine();
187 }
catch (IOException ex) {
188 logger.log(Level.WARNING,
"Failed to read from content: " + fav.getName(), ex);
189 this.addErrorMessage(
190 NbBundle.getMessage(
this.getClass(),
"ExtractIE.getURLFromIEBmkFile.errMsg", this.getName(),
192 }
catch (IndexOutOfBoundsException ex) {
193 logger.log(Level.WARNING,
"Failed while getting URL of IE bookmark. Unexpected format of the bookmark file: " + fav.getName(), ex);
194 this.addErrorMessage(
195 NbBundle.getMessage(
this.getClass(),
"ExtractIE.getURLFromIEBmkFile.errMsg2", this.getName(),
200 }
catch (IOException ex) {
201 logger.log(Level.WARNING,
"Failed to close reader.", ex);
211 private void getCookie() {
213 List<AbstractFile> cookiesFiles;
215 cookiesFiles = fileManager.
findFiles(dataSource,
"%.txt",
"Cookies");
216 }
catch (TskCoreException ex) {
217 logger.log(Level.WARNING,
"Error getting cookie files for IE");
218 this.addErrorMessage(
219 NbBundle.getMessage(
this.getClass(),
"ExtractIE.getCookie.errMsg.errGettingFile", this.getName()));
223 if (cookiesFiles.isEmpty()) {
224 logger.log(Level.INFO,
"Didn't find any IE cookies files.");
229 Collection<BlackboardArtifact> bbartifacts =
new ArrayList<>();
230 for (AbstractFile cookiesFile : cookiesFiles) {
231 if (context.dataSourceIngestIsCancelled()) {
234 if (cookiesFile.getSize() == 0) {
238 byte[] t =
new byte[(int) cookiesFile.getSize()];
240 final int bytesRead = cookiesFile.read(t, 0, cookiesFile.getSize());
241 }
catch (TskCoreException ex) {
242 logger.log(Level.WARNING,
"Error reading bytes of Internet Explorer cookie.", ex);
243 this.addErrorMessage(
244 NbBundle.getMessage(
this.getClass(),
"ExtractIE.getCookie.errMsg.errReadingIECookie",
245 this.getName(), cookiesFile.getName()));
248 String cookieString =
new String(t);
249 String[] values = cookieString.split(
"\n");
250 String url = values.length > 2 ? values[2] :
"";
251 String value = values.length > 1 ? values[1] :
"";
252 String name = values.length > 0 ? values[0] :
"";
253 Long datetime = cookiesFile.getCrtime();
254 String tempDate = datetime.toString();
255 datetime = Long.valueOf(tempDate);
256 String domain = extractDomain(url);
258 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
259 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_URL,
260 RecentActivityExtracterModuleFactory.getModuleName(), url));
261 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME,
262 RecentActivityExtracterModuleFactory.getModuleName(), datetime));
263 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_NAME,
264 RecentActivityExtracterModuleFactory.getModuleName(), (name != null) ? name :
""));
265 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_VALUE,
266 RecentActivityExtracterModuleFactory.getModuleName(), value));
267 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PROG_NAME,
268 RecentActivityExtracterModuleFactory.getModuleName(),
269 NbBundle.getMessage(this.getClass(),
"ExtractIE.moduleName.text")));
270 if (domain != null && domain.isEmpty() ==
false) {
271 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DOMAIN,
272 RecentActivityExtracterModuleFactory.getModuleName(), domain));
274 BlackboardArtifact bbart = createArtifactWithAttributes(ARTIFACT_TYPE.TSK_WEB_COOKIE, cookiesFile, bbattributes);
276 bbartifacts.add(bbart);
280 postArtifacts(bbartifacts);
286 private void getHistory() {
287 logger.log(Level.INFO,
"Pasco results path: {0}", moduleTempResultsDir);
288 boolean foundHistory =
false;
290 final File pascoRoot = InstalledFileLocator.getDefault().locate(
"pasco2", ExtractIE.class.getPackage().getName(),
false);
291 if (pascoRoot == null) {
292 this.addErrorMessage(
293 NbBundle.getMessage(
this.getClass(),
"ExtractIE.getHistory.errMsg.unableToGetHist", this.getName()));
294 logger.log(Level.SEVERE,
"Error finding pasco program ");
298 final String pascoHome = pascoRoot.getAbsolutePath();
299 logger.log(Level.INFO,
"Pasco2 home: {0}", pascoHome);
301 PASCO_LIB_PATH = pascoHome + File.separator +
"pasco2.jar" + File.pathSeparator
302 + pascoHome + File.separator +
"*";
304 File resultsDir =
new File(moduleTempResultsDir);
308 FileManager fileManager = currentCase.getServices().getFileManager();
309 List<AbstractFile> indexFiles;
311 indexFiles = fileManager.findFiles(dataSource,
"index.dat");
312 }
catch (TskCoreException ex) {
313 this.addErrorMessage(NbBundle.getMessage(
this.getClass(),
"ExtractIE.getHistory.errMsg.errGettingHistFiles",
315 logger.log(Level.WARNING,
"Error fetching 'index.data' files for Internet Explorer history.");
319 if (indexFiles.isEmpty()) {
320 String msg = NbBundle.getMessage(this.getClass(),
"ExtractIE.getHistory.errMsg.noHistFiles");
321 logger.log(Level.INFO, msg);
326 Collection<BlackboardArtifact> bbartifacts =
new ArrayList<>();
328 String indexFileName;
329 for (AbstractFile indexFile : indexFiles) {
336 indexFileName =
"index" + Integer.toString((
int) indexFile.getId()) +
".dat";
338 temps = RAImageIngestModule.getRATempPath(currentCase,
"IE") + File.separator + indexFileName;
339 File datFile =
new File(temps);
340 if (context.dataSourceIngestIsCancelled()) {
344 ContentUtils.writeToFile(indexFile, datFile, context::dataSourceIngestIsCancelled);
345 }
catch (IOException e) {
346 logger.log(Level.WARNING,
"Error while trying to write index.dat file " + datFile.getAbsolutePath(), e);
347 this.addErrorMessage(
348 NbBundle.getMessage(
this.getClass(),
"ExtractIE.getHistory.errMsg.errWriteFile", this.getName(),
349 datFile.getAbsolutePath()));
353 String filename =
"pasco2Result." + indexFile.getId() +
".txt";
354 boolean bPascProcSuccess = executePasco(temps, filename);
355 if (context.dataSourceIngestIsCancelled()) {
361 if (bPascProcSuccess) {
363 bbartifacts.addAll(parsePascoOutput(indexFile, filename).stream()
364 .filter(bbart -> bbart.getArtifactTypeID() == ARTIFACT_TYPE.TSK_WEB_HISTORY.getTypeID())
365 .collect(Collectors.toList()));
366 if (context.dataSourceIngestIsCancelled()) {
374 logger.log(Level.WARNING,
"pasco execution failed on: {0}", filename);
375 this.addErrorMessage(
376 NbBundle.getMessage(
this.getClass(),
"ExtractIE.getHistory.errMsg.errProcHist", this.getName()));
380 postArtifacts(bbartifacts);
391 private boolean executePasco(String indexFilePath, String outputFileName) {
392 boolean success =
true;
394 final String outputFileFullPath = moduleTempResultsDir + File.separator + outputFileName;
395 final String errFileFullPath = moduleTempResultsDir + File.separator + outputFileName +
".err";
396 logger.log(Level.INFO,
"Writing pasco results to: {0}", outputFileFullPath);
397 List<String> commandLine =
new ArrayList<>();
398 commandLine.add(JAVA_PATH);
399 commandLine.add(
"-cp");
400 commandLine.add(PASCO_LIB_PATH);
401 commandLine.add(
"isi.pasco2.Main");
402 commandLine.add(
"-T");
403 commandLine.add(
"history");
404 commandLine.add(indexFilePath);
405 ProcessBuilder processBuilder =
new ProcessBuilder(commandLine);
406 processBuilder.redirectOutput(
new File(outputFileFullPath));
407 processBuilder.redirectError(
new File(errFileFullPath));
417 ExecUtil.execute(processBuilder,
new DataSourceIngestModuleProcessTerminator(context));
419 }
catch (IOException ex) {
421 logger.log(Level.SEVERE,
"Unable to execute Pasco to process Internet Explorer web history.", ex);
435 private Collection<BlackboardArtifact> parsePascoOutput(AbstractFile origFile, String pascoOutputFileName) {
437 Collection<BlackboardArtifact> bbartifacts =
new ArrayList<>();
438 String fnAbs = moduleTempResultsDir + File.separator + pascoOutputFileName;
440 File file =
new File(fnAbs);
441 if (file.exists() ==
false) {
442 this.addErrorMessage(
443 NbBundle.getMessage(
this.getClass(),
"ExtractIE.parsePascoOutput.errMsg.notFound", this.getName(),
445 logger.log(Level.WARNING,
"Pasco Output not found: {0}", file.getPath());
451 if (file.length() == 0) {
457 fileScanner =
new Scanner(
new FileInputStream(file.toString()));
458 }
catch (FileNotFoundException ex) {
459 this.addErrorMessage(
460 NbBundle.getMessage(
this.getClass(),
"ExtractIE.parsePascoOutput.errMsg.errParsing", this.getName(),
462 logger.log(Level.WARNING,
"Unable to find the Pasco file at " + file.getPath(), ex);
465 while (fileScanner.hasNext()) {
467 if (context.dataSourceIngestIsCancelled()) {
471 String line = fileScanner.nextLine();
472 if (!line.startsWith(
"URL")) {
476 String[] lineBuff = line.split(
"\\t");
478 if (lineBuff.length < 4) {
479 logger.log(Level.INFO,
"Found unrecognized IE history format.");
483 String actime = lineBuff[3];
484 Long ftime = (long) 0;
486 String realurl = null;
493 if (lineBuff[1].contains(
"@")) {
494 String url[] = lineBuff[1].split(
"@", 2);
499 domain = extractDomain(url[0]);
501 if (domain != null && domain.isEmpty() ==
false) {
505 realurl = lineBuff[1].trim();
512 user = user.replace(
"Visited:",
"");
513 user = user.replace(
":Host:",
"");
514 user = user.replaceAll(
"(:)(.*?)(:)",
"");
517 realurl = realurl.replace(
"Visited:",
"");
518 realurl = realurl.replaceAll(
":(.*?):",
"");
519 realurl = realurl.replace(
":Host:",
"");
520 realurl = realurl.trim();
521 domain = extractDomain(realurl);
527 realurl = lineBuff[1].trim();
528 domain = extractDomain(realurl);
531 if (!actime.isEmpty()) {
533 Long epochtime = dateFormatter.parse(actime).getTime();
534 ftime = epochtime / 1000;
535 }
catch (ParseException e) {
536 this.addErrorMessage(
537 NbBundle.getMessage(
this.getClass(),
"ExtractIE.parsePascoOutput.errMsg.errParsingEntry",
539 logger.log(Level.WARNING, String.format(
"Error parsing Pasco results, may have partial processing of corrupt file (id=%d)", origFile.getId()), e);
544 BlackboardArtifact bbart = origFile.newArtifact(ARTIFACT_TYPE.TSK_WEB_HISTORY);
545 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
546 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_URL,
547 RecentActivityExtracterModuleFactory.getModuleName(), realurl));
550 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED,
551 RecentActivityExtracterModuleFactory.getModuleName(), ftime));
552 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_REFERRER,
553 RecentActivityExtracterModuleFactory.getModuleName(),
""));
555 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PROG_NAME,
556 RecentActivityExtracterModuleFactory.getModuleName(),
557 NbBundle.getMessage(this.getClass(),
558 "ExtractIE.moduleName.text")));
559 if (domain != null && domain.isEmpty() ==
false) {
560 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DOMAIN,
561 RecentActivityExtracterModuleFactory.getModuleName(), domain));
563 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_USER_NAME,
564 RecentActivityExtracterModuleFactory.getModuleName(), user));
565 bbart.addAttributes(bbattributes);
567 bbartifacts.add(bbart);
568 }
catch (TskCoreException ex) {
569 logger.log(Level.SEVERE,
"Error writing Internet Explorer web history artifact to the blackboard. Pasco results will be incomplete", ex);
584 private String extractDomain(String url) {
585 if (url == null || url.isEmpty()) {
589 if (url.toLowerCase().startsWith(RESOURCE_URL_PREFIX)) {
596 return NetworkUtils.extractDomain(url);
synchronized List< AbstractFile > findFiles(String fileName)