19 package org.sleuthkit.autopsy.modules.leappanalyzers;
21 import java.io.BufferedReader;
23 import java.io.FileNotFoundException;
24 import java.io.FileReader;
25 import java.io.IOException;
26 import java.io.UncheckedIOException;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import java.text.SimpleDateFormat;
31 import java.util.List;
32 import java.util.ArrayList;
33 import java.util.Locale;
34 import java.util.logging.Level;
35 import java.util.stream.Collectors;
36 import java.util.stream.Stream;
37 import org.apache.commons.io.FilenameUtils;
38 import org.openide.modules.InstalledFileLocator;
39 import org.openide.util.NbBundle;
69 private static final String
ILEAPP =
"iLeapp";
74 private static final String
XMLFILE =
"ileap-artifact-attribute-reference.xml";
88 "ILeappAnalyzerIngestModule.executable.not.found=iLeapp Executable Not Found.",
89 "ILeappAnalyzerIngestModule.requires.windows=iLeapp module requires windows.",
90 "ILeappAnalyzerIngestModule.error.ileapp.file.processor.init=Failure to initialize ILeappProcessFile"})
102 throw new IngestModuleException(Bundle.ILeappAnalyzerIngestModule_error_ileapp_file_processor_init(), ex);
107 }
catch (FileNotFoundException exception) {
108 logger.log(Level.WARNING,
"iLeapp executable not found.", exception);
109 throw new IngestModuleException(Bundle.ILeappAnalyzerIngestModule_executable_not_found(), exception);
115 "ILeappAnalyzerIngestModule.error.running.iLeapp=Error running iLeapp, see log file.",
116 "ILeappAnalyzerIngestModule.error.creating.output.dir=Error creating iLeapp module output directory.",
117 "ILeappAnalyzerIngestModule.starting.iLeapp=Starting iLeapp",
118 "ILeappAnalyzerIngestModule.running.iLeapp=Running iLeapp",
119 "ILeappAnalyzerIngestModule.has.run=iLeapp",
120 "ILeappAnalyzerIngestModule.iLeapp.cancelled=iLeapp run was canceled",
121 "ILeappAnalyzerIngestModule.completed=iLeapp Processing Completed",
122 "ILeappAnalyzerIngestModule.report.name=iLeapp Html Report"})
129 Files.createDirectories(tempOutputPath);
130 }
catch (IOException ex) {
131 logger.log(Level.SEVERE, String.format(
"Error creating iLeapp output directory %s", tempOutputPath.toString()), ex);
135 List<String> iLeappPathsToProcess =
new ArrayList<>();
140 logger.log(Level.SEVERE, String.format(
"Error when trying to execute iLeapp program getting file paths to search for result is %d", result));
144 }
catch (IOException ex) {
145 logger.log(Level.SEVERE, String.format(
"Error when trying to execute iLeapp program getting file paths to search"), ex);
149 statusHelper.
progress(Bundle.ILeappAnalyzerIngestModule_starting_iLeapp(), 0);
151 List<AbstractFile> iLeappFilesToProcess =
new ArrayList<>();
153 if (!(context.
getDataSource() instanceof LocalFilesDataSource)) {
156 processILeappFs(dataSource, currentCase, statusHelper, tempOutputPath.toString());
161 Integer filesProcessedCount = 0;
162 for (AbstractFile iLeappFile : iLeappFilesToProcess) {
163 processILeappFile(dataSource, currentCase, statusHelper, filesProcessedCount, iLeappFile);
164 filesProcessedCount++;
168 processILeappFs(dataSource, currentCase, statusHelper, tempOutputPath.toString());
172 Bundle.ILeappAnalyzerIngestModule_has_run(),
173 Bundle.ILeappAnalyzerIngestModule_completed());
187 AbstractFile iLeappFile) {
188 String currentTime =
new SimpleDateFormat(
"yyyy-MM-dd HH-mm-ss z", Locale.US).format(System.currentTimeMillis());
191 Files.createDirectories(moduleOutputPath);
192 }
catch (IOException ex) {
193 logger.log(Level.SEVERE, String.format(
"Error creating iLeapp output directory %s", moduleOutputPath.toString()), ex);
197 statusHelper.
progress(NbBundle.getMessage(
this.getClass(),
"ILeappAnalyzerIngestModule.processing.file", iLeappFile.getName()), filesProcessedCount);
198 ProcessBuilder iLeappCommand =
buildiLeappCommand(moduleOutputPath, iLeappFile.getLocalAbsPath(), iLeappFile.getNameExtension());
202 logger.log(Level.WARNING, String.format(
"Error when trying to execute iLeapp program getting file paths to search for result is %d", result));
208 }
catch (IOException ex) {
209 logger.log(Level.SEVERE, String.format(
"Error when trying to execute iLeapp program against file %s", iLeappFile.getLocalAbsPath()), ex);
214 logger.log(Level.INFO,
"ILeapp Analyser ingest module run was canceled");
233 String currentTime =
new SimpleDateFormat(
"yyyy-MM-dd HH-mm-ss z", Locale.US).format(System.currentTimeMillis());
236 Files.createDirectories(moduleOutputPath);
237 }
catch (IOException ex) {
238 logger.log(Level.SEVERE, String.format(
"Error creating iLeapp output directory %s", moduleOutputPath.toString()), ex);
242 statusHelper.
progress(NbBundle.getMessage(
this.getClass(),
"ILeappAnalyzerIngestModule.processing.filesystem"));
243 ProcessBuilder iLeappCommand =
buildiLeappCommand(moduleOutputPath, directoryToProcess,
"fs");
247 logger.log(Level.WARNING, String.format(
"Error when trying to execute iLeapp program getting file paths to search for result is %d", result));
253 }
catch (IOException ex) {
254 logger.log(Level.SEVERE, String.format(
"Error when trying to execute iLeapp program against file system"), ex);
259 logger.log(Level.INFO,
"ILeapp Analyser ingest module run was canceled");
280 List<AbstractFile> iLeappFiles =
new ArrayList<>();
282 FileManager fileManager = getCurrentCase().getServices().getFileManager();
286 iLeappFiles = fileManager.
findFiles(dataSource,
"%",
"/");
287 }
catch (TskCoreException ex) {
288 logger.log(Level.WARNING,
"No files found to process");
292 List<AbstractFile> iLeappFilesToProcess =
new ArrayList<>();
293 for (AbstractFile iLeappFile : iLeappFiles) {
294 if (((iLeappFile.getLocalAbsPath() != null)
295 && (!iLeappFile.getNameExtension().isEmpty() && (!iLeappFile.isVirtual())))
296 && ((iLeappFile.getName().toLowerCase().contains(
".zip") || (iLeappFile.getName().toLowerCase().contains(
".tar")))
297 || iLeappFile.getName().toLowerCase().contains(
".tgz"))) {
298 iLeappFilesToProcess.add(iLeappFile);
303 return iLeappFilesToProcess;
313 private ProcessBuilder
buildiLeappCommand(Path moduleOutputPath, String sourceFilePath, String iLeappFileSystemType) {
316 "\"" + iLeappExecutable +
"\"",
317 "-t", iLeappFileSystemType,
318 "-i", sourceFilePath,
319 "-o", moduleOutputPath.toString()
321 processBuilder.redirectError(moduleOutputPath.resolve(
"iLeapp_err.txt").toFile());
322 processBuilder.redirectOutput(moduleOutputPath.resolve(
"iLeapp_out.txt").toFile());
323 return processBuilder;
334 "\"" + iLeappExecutable +
"\"",
337 processBuilder.redirectError(moduleOutputPath.resolve(
"iLeapp_paths_error.txt").toFile());
338 processBuilder.redirectOutput(moduleOutputPath.resolve(
"iLeapp_paths.txt").toFile());
339 return processBuilder;
343 ProcessBuilder processBuilder =
new ProcessBuilder(commandLine);
348 processBuilder.environment().put(
"__COMPAT_LAYER",
"RunAsInvoker");
349 return processBuilder;
353 String executableToFindName = Paths.get(ILEAPP, executableName).toString();
355 File exeFile = InstalledFileLocator.getDefault().locate(executableToFindName,
ILeappAnalyzerIngestModule.class.getPackage().getName(),
false);
356 if (null == exeFile || exeFile.canExecute() ==
false) {
357 throw new FileNotFoundException(executableName +
" executable not found.");
367 List<String> allIndexFiles =
new ArrayList<>();
369 try (Stream<Path> walk = Files.walk(iLeappOutputDir)) {
371 allIndexFiles = walk.map(x -> x.toString())
372 .filter(f -> f.toLowerCase().endsWith(
"index.html")).collect(Collectors.toList());
374 if (!allIndexFiles.isEmpty()) {
376 String filePath = FilenameUtils.getFullPathNoEndSeparator(allIndexFiles.get(0));
377 File dataFilesDir =
new File(Paths.get(filePath,
"_TSV Exports").toString());
378 if (dataFilesDir.exists()) {
379 currentCase.
addReport(allIndexFiles.get(0),
MODULE_NAME, Bundle.ILeappAnalyzerIngestModule_report_name());
383 }
catch (IOException | UncheckedIOException | TskCoreException ex) {
385 logger.log(Level.WARNING, String.format(
"Error finding index file in path %s", iLeappOutputDir.toString()), ex);
395 private List<String>
loadIleappPathFile(Path moduleOutputPath)
throws FileNotFoundException, IOException {
396 List<String> iLeappPathsToProcess =
new ArrayList<>();
400 try (BufferedReader reader =
new BufferedReader(
new FileReader(filePath.toString()))) {
401 String line = reader.readLine();
402 while (line != null) {
403 if (line.contains(
"path list generation") || line.length() < 2) {
404 line = reader.readLine();
407 iLeappPathsToProcess.add(line.trim());
408 line = reader.readLine();
412 return iLeappPathsToProcess;
422 FileManager fileManager = getCurrentCase().getServices().getFileManager();
424 for (String fullFilePath : iLeappPathsToProcess) {
427 logger.log(Level.INFO,
"ILeapp Analyser ingest module run was canceled");
431 String ffp = fullFilePath.replaceAll(
"\\*",
"%");
432 ffp = FilenameUtils.normalize(ffp,
true);
433 String fileName = FilenameUtils.getName(ffp);
434 String filePath = FilenameUtils.getPath(ffp);
436 List<AbstractFile> iLeappFiles =
new ArrayList<>();
438 if (filePath.isEmpty()) {
439 iLeappFiles = fileManager.
findFiles(dataSource, fileName);
441 iLeappFiles = fileManager.
findFiles(dataSource, fileName, filePath);
443 }
catch (TskCoreException ex) {
444 logger.log(Level.WARNING,
"No files found to process");
448 for (AbstractFile iLeappFile : iLeappFiles) {
449 Path parentPath = Paths.get(moduleOutputPath.toString(), iLeappFile.getParentPath());
450 File fileParentPath =
new File(parentPath.toString());
464 private void extractFileToOutput(Content dataSource, AbstractFile iLeappFile, File fileParentPath, Path parentPath) {
465 if (fileParentPath.exists()) {
466 if (!iLeappFile.isDir()) {
470 Files.createDirectories(Paths.get(parentPath.toString(), iLeappFile.getName()));
471 }
catch (IOException ex) {
472 logger.log(Level.INFO, String.format(
"Error creating iLeapp output directory %s", parentPath.toString()), ex);
477 Files.createDirectories(parentPath);
478 }
catch (IOException ex) {
479 logger.log(Level.INFO, String.format(
"Error creating iLeapp output directory %s", parentPath.toString()), ex);
481 if (!iLeappFile.isDir()) {
485 Files.createDirectories(Paths.get(parentPath.toString(), iLeappFile.getName()));
486 }
catch (IOException ex) {
487 logger.log(Level.INFO, String.format(
"Error creating iLeapp output directory %s", parentPath.toString()), ex);
499 private void writeiLeappFile(Content dataSource, AbstractFile iLeappFile, String parentPath) {
500 String fileName = iLeappFile.getName().replace(
":",
"-");
501 if (!fileName.matches(
".") && !fileName.matches(
"..") && !fileName.toLowerCase().endsWith(
"-slack")) {
502 Path filePath = Paths.get(parentPath, fileName);
503 File localFile =
new File(filePath.toString());
506 }
catch (ReadContentInputStream.ReadContentInputStreamException ex) {
507 logger.log(Level.WARNING, String.format(
"Error reading file '%s' (id=%d).",
508 iLeappFile.getName(), iLeappFile.getId()), ex);
509 }
catch (IOException ex) {
510 logger.log(Level.WARNING, String.format(
"Error writing file local file '%s' (id=%d).",
511 filePath.toString(), iLeappFile.getId()), ex);
ProcessBuilder buildiLeappListCommand(Path moduleOutputPath)
void extractFilesFromImage(Content dataSource, List< String > iLeappPathsToProcess, Path moduleOutputPath)
void processILeappFs(Content dataSource, Case currentCase, DataSourceIngestModuleProgress statusHelper, String directoryToProcess)
List< AbstractFile > findiLeappFilesToProcess(Content dataSource)
static int execute(ProcessBuilder processBuilder)
String getTempDirectory()
static final String ILEAPP
void extractFileToOutput(Content dataSource, AbstractFile iLeappFile, File fileParentPath, Path parentPath)
static IngestMessage createMessage(MessageType messageType, String source, String subject, String detailsHtml)
static< T > long writeToFile(Content content, java.io.File outputFile, ProgressHandle progress, Future< T > worker, boolean source)
void addReport(String localPath, String srcModuleName, String reportName)
static final String MODULE_NAME
static final String ILEAPP_EXECUTABLE
static ProcessBuilder buildProcessWithRunAsInvoker(String...commandLine)
static final String ILEAPP_FS
ProcessBuilder buildiLeappCommand(Path moduleOutputPath, String sourceFilePath, String iLeappFileSystemType)
static final String XMLFILE
static final Logger logger
ProcessResult processFileSystem(Content dataSource, Path moduleOutputPath)
static File locateExecutable(String executableName)
ProcessResult processFiles(Content dataSource, Path moduleOutputPath, AbstractFile LeappFile)
void postMessage(final IngestMessage message)
String getModuleDirectory()
void addILeappReportToReports(Path iLeappOutputDir, Case currentCase)
boolean dataSourceIngestIsCancelled()
void startUp(IngestJobContext context)
void switchToDeterminate(int workUnits)
synchronized List< AbstractFile > findFiles(String fileName)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
ProcessResult process(Content dataSource, DataSourceIngestModuleProgress statusHelper)
static final String ILEAPP_PATHS_FILE
void processILeappFile(Content dataSource, Case currentCase, DataSourceIngestModuleProgress statusHelper, int filesProcessedCount, AbstractFile iLeappFile)
LeappFileProcessor iLeappFileProcessor
void writeiLeappFile(Content dataSource, AbstractFile iLeappFile, String parentPath)
List< String > loadIleappPathFile(Path moduleOutputPath)
void progress(int workUnits)
static synchronized IngestServices getInstance()