Esempio n. 1
0
        private void whatsTheIPToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string message = OsirtHelper.GetIpFromUrl(uiTabbedBrowserControl.CurrentTab.Browser.URL);

            File.WriteAllText(Constants.TempTextFile, message);
            this.InvokeIfRequired(() => new TextPreviewer(Enums.Actions.Ipaddress, uiTabbedBrowserControl.CurrentTab.Browser.URL).Show());
        }
 private void UpdateFileDetailsUi()
 {
     tooltip.SetToolTip(uiFileDetailsLabel, "Hash: " + hash);
     uiFilePathTextBox.Text     = fileWithPath;
     uiFileDetailsLabel.Text    = $"{file}{Environment.NewLine}{OsirtHelper.GetHumanReadableFileSize(fileWithPath)}{Environment.NewLine}{TrimHash(hash)}";
     uiFileDetailsLabel.Visible = true;
 }
        public bool CleanUpDirectories()
        {
            string directory = Path.Combine(Constants.CasePath, Constants.CaseContainerName);

            OsirtHelper.DeleteDirectory(directory);
            return(Directory.Exists(directory));
        }
Esempio n. 4
0
        private void ExportAsCsv()
        {
            StringBuilder        sb          = new StringBuilder();
            DataTable            dt          = GetMergedDataTable();
            IEnumerable <string> columnNames = dt.Columns.Cast <DataColumn>().
                                               Select(column => column.ColumnName);

            sb.AppendLine(string.Join(",", columnNames));

            foreach (DataRow row in dt.Rows)
            {
                IEnumerable <string> fields = row.ItemArray.Select(field => field.ToString());
                sb.AppendLine(string.Join(",", fields));
            }

            string csvPath = Path.Combine(ExportPath, ReportContainerName + ".csv");

            File.WriteAllText(csvPath, sb.ToString());
            Logger.Log(new OsirtActionsLog(Enums.Actions.Report, OsirtHelper.GetFileHash(csvPath), ReportContainerName));
            PlaceReportInContainer(Path.Combine(ExportPath, ReportContainerName));
            if (openReport)
            {
                Process.Start(csvPath);
            }
        }
Esempio n. 5
0
        private void DisplayFileIconWithFileSize(string file, Actions caseDirectory)
        {
            BitmapSource icon = IconManager.GetLargeIcon(file, true, false);

            FilePreviewImage.Image = OsirtHelper.GetBitmap(icon);
            DisplayFileDetailsLabel(file, caseDirectory);
        }
        private void CurrentBrowser_DownloadCompleted(object sender, EventArgs e)
        {
            DownloadEventArgs dl = (DownloadEventArgs)e;

            Invoke((MethodInvoker) delegate
            {
                uiActionLoggedToolStripStatusLabel.Visible = false;
                uiDownloadProgressBar.Visible = false;
                MessageBox.Show("Download Completed", "Download Complete", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            });

            string dlPath   = dl.DownloadItems.FullPath;
            string savePath = Path.Combine(Constants.ContainerLocation, Constants.Directories.GetSpecifiedCaseDirectory(Actions.Download), Path.GetFileName(dl.DownloadItems.FullPath));

            if (File.Exists(savePath))
            {
                string extension = Path.GetExtension(savePath);
                string name      = Path.GetFileNameWithoutExtension(savePath) + "_" + (DateTime.Now.ToString("yyyy-MM-dd_hh_mm_ss") + extension);
                savePath = Path.Combine(Constants.ContainerLocation, Constants.Directories.GetSpecifiedCaseDirectory(Actions.Download), name);
            }


            File.Copy(dlPath, savePath);
            Logger.Log(new WebpageActionsLog(dl.DownloadItems.Url, Actions.Download, OsirtHelper.GetFileHash(dlPath), Path.GetFileName(savePath), ""));
        }
Esempio n. 7
0
        private async void uiBrowseIconButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png, *gif) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png; *.gif";
            dialog.Title  = "Constabulary Icon";
            DialogResult dr = dialog.ShowDialog();

            if (dr != DialogResult.OK)
            {
                return;
            }

            string path = dialog.FileName;

            try
            {
                string base64 = await Task.Run(() => OsirtHelper.ResizeConstabLogo(path));

                uiConstabularyIconPictureBox.Image = base64.Base64ToImage();
                settings.ConstabIcon = base64;
                settings.Save();
            }
            catch
            {
                MessageBox.Show("Unable to save icon", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 8
0
        private void ExportAsHtml()
        {
            string navBar = HtmlHelper.GetHtmlNavBar(GetSelectedTables());

            foreach (var value in GetHtml())
            {
                string savePath = Path.Combine(ExportPath, ReportContainerName, $"{value.Item1}.html");
                string page     = value.Item2.Replace("<%%NAV%%>", navBar);
                File.WriteAllText(savePath, page);
            }

            //combined
            string combined = DatatableToHtml.ConvertToHtml(GetMergedDataTable(), ExportPath, ReportContainerName);
            string save     = HtmlHelper.ReplaceReportDetails(combined, GSCP, true);

            save = save.Replace("<%%NAV%%>", navBar);
            File.WriteAllText(Path.Combine(ExportPath, ReportContainerName, "combined.html"), save);
            Thread.Sleep(750);
            string hash = OsirtHelper.CreateHashForFolder(Path.Combine(ExportPath, ReportContainerName));

            Logger.Log(new OsirtActionsLog(Enums.Actions.Report, hash, ReportContainerName));
            PlaceReportInContainer(Path.Combine(ExportPath, ReportContainerName));
            if (openReport)
            {
                Process.Start(Path.Combine(ExportPath, ReportContainerName, "combined.html"));
            }
        }
        private void DisplayFileDetailsLabel(string file, Actions caseDirectory)
        {
            string caseDir = Constants.Directories.GetSpecifiedCaseDirectory(caseDirectory);

            filePath = Path.Combine(Constants.ContainerLocation, caseDir, file);
            SetFileLabelText($"File size: {OsirtHelper.GetHumanReadableFileSize(filePath)}. File type: {Path.GetExtension(filePath.ToUpperInvariant())}");
        }
Esempio n. 10
0
 private void RezipCase(string path)
 {
     using (ZipFile zip = new ZipFile())
     {
         zip.AddDirectory(path, Path.GetFileName(path));
         zip.Save(Path.Combine(Directory.GetParent(path).FullName, Path.GetFileName(path) + Constants.ContainerExtension));
     }
     OsirtHelper.DeleteDirectory(path);
 }
Esempio n. 11
0
        private void uiSaveAsTextButton_Click(object sender, EventArgs e)
        {
            string savePath = Path.Combine(Constants.ContainerLocation, Constants.Directories.GetSpecifiedCaseDirectory(Enums.Actions.Exif), $"exif_data_{DateTime.Now.ToString("yyyy-MM-dd_hh_mm_ss")}.txt");
            string text     = string.Join("\r\n", properties);

            File.WriteAllText(savePath, text);
            Logger.Log(new WebpageActionsLog(url, Enums.Actions.Exif, OsirtHelper.GetFileHash(savePath), Path.GetFileName(savePath), "[Exif Saved]"));
            MessageBox.Show("Exif data saved.", "Exif saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 12
0
        public static string CreateHtml()
        {
            string caseDetails  = HtmlHelper.GetCaseDetails();
            string caseNotes    = GetCaseNotesToHtml();
            string htmlResource = OsirtHelper.GetResource("casenotes.html");

            htmlResource = htmlResource.Replace("<%%CASE_NOTES%%>", caseNotes)
                           .Replace("<%%CASE_DETAILS%%>", caseDetails)
                           .Replace("<%%CONSTAB_LOGO%%>", UserSettings.Load().ConstabIcon);
            return(htmlResource);
        }
Esempio n. 13
0
        private void CreatePDF(object sender, WaitWindowEventArgs e)
        {
            //TODO: When audit log is exported and case notes are then exported (or vice-verca) as PDF, the application hangs...
            string path = e.Arguments[0].ToString();
            string html = CaseNotesToHtml.CreateHtml();

            HtmLtoPdf.SaveHtmltoPdf(html, "", "Case Notes", path);
            string hash = OsirtHelper.GetFileHash(path);

            Logger.Log(new OsirtActionsLog(Enums.Actions.CaseNotes, hash, System.IO.Path.GetFileName(path)));
        }
Esempio n. 14
0
        private void HashCase()
        {
            string hash = OsirtHelper.GetFileHash(Path.Combine(Constants.CasePath, Constants.CaseContainerName + Constants.ContainerExtension));

            try
            {
                File.WriteAllText(Path.Combine(UserSettings.Load().HashExportLocation, Constants.ExportedHashFileName.Replace("%%dt%%", $"{DateTime.Now.ToString("yyyy-MM-dd_hh_mm_ss")}")), hash);
            }
            catch (Exception e)
            {
                File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Constants.ExportedHashFileName.Replace("%%dt%%", $"{DateTime.Now.ToString("yyyy-MM-dd_hh_mm_ss")}")), hash);
            }
        }
        private void SaveAsOther(object sender, WaitWindowEventArgs e)
        {
            //string fileName = e.Arguments[0].ToString();

            ImageSaveOptions options  = (ImageSaveOptions)e.Arguments[0];
            string           fileName = options.FileName;
            string           fileType = options.FileType;
            MagickFormat     format   = options.ImageFormat;

            pathToSave = "";
            bool thrown = false;

            try
            {
                using (MagickImage image = new MagickImage(filePath /*, settings*/))
                {
                    image.Format = format;

                    //uncomment this to get annotation
                    //image.Annotate(Url + "\n" + DateAndTime, Gravity.Southwest);

                    pathToSave = Path.Combine(Constants.ContainerLocation, Constants.Directories.GetSpecifiedCaseDirectory(action), fileName + fileType);
                    image.Write(pathToSave);
                    e.Window.Message = $"Rehashing {fileType}";
                    Hash             = OsirtHelper.GetFileHash(pathToSave);
                    successful       = true;
                }
            }
            catch (Exception ex) when(ex is MagickErrorException || ex is System.Runtime.InteropServices.SEHException || ex is ArgumentException || ex is System.Reflection.TargetInvocationException /*|| ex is System.AccessViolationException || ex is Exception*/)
            {
                thrown = true;
                var message = $"Unable to save as {fileType}. Reverting to saving as PNG.";

                Invoke((MethodInvoker)(() => uiFileExtensionComboBox.SelectedIndex = uiFileExtensionComboBox.Items.IndexOf(SaveableFileTypes.Png)));
                e.Window.Message = message;
                Task.Delay(2000).Wait(); //just so the user can see we're saving as PNG instead
                SaveAsPng(fileName);
            }
            finally
            {
                //delete temp pdf file
                if (thrown)
                {
                    if (File.Exists(pathToSave))
                    {
                        File.Delete(pathToSave);
                    }
                }
            }
        }
 private void DisplayFileIconWithFileSize(string file, Actions caseDirectory)
 {
     try
     {
         BitmapSource icon = IconManager.GetLargeIcon(file, true, false);
         FilePreviewImage.Image = OsirtHelper.GetBitmap(icon);
         DisplayFileDetailsLabel(file, caseDirectory);
     }
     catch
     {
         FilePreviewImage.Image = null;
         SetFileLabelText("Unable to read file");
     }
 }
Esempio n. 17
0
        private bool IsValidFileName()
        {
            bool valid = false;

            //must check this first, as trying to use Path.Combine with an illegal file char will throw an argument exception
            if (OsirtHelper.IsValidFilename(FileName))
            {
                string path = Path.Combine(Constants.ContainerLocation, Constants.Directories.GetSpecifiedCaseDirectory(action), FileName + FileExtension);
                if (!File.Exists(path))
                {
                    valid = true;
                }
            }
            return(valid);
        }
        private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            Logger.Log(new WebpageActionsLog(url, action, OsirtHelper.GetFileHash(savePath), filename, @"[N/A]"));

            files.Remove(files.First().Key);
            if (files.Count > 0)
            {
                Download();
            }
            else //completed
            {
                uiCompleteLabel.Text  = $"Download completed, you may now close this window.{Environment.NewLine} {count} image(s) were downloaded.{Environment.NewLine} {errorCount} image(s) could not be downloaded.";
                uiCloseButton.Enabled = true;
            }
        }
Esempio n. 19
0
        private void ExportAsXml()
        {
            ReportContainerName = Constants.ReportContainerName.Replace("%%dt%%", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"));

            DataTable dt = GetMergedDataTable();

            new ArtefactExporter(dt, ExportPath, ReportContainerName);

            string xmlPath = Path.Combine(ExportPath, ReportContainerName, "report.xml");

            dt.WriteXml(xmlPath);

            Logger.Log(new OsirtActionsLog(Enums.Actions.Report, OsirtHelper.GetFileHash(xmlPath), ReportContainerName));
            PlaceReportInContainer(Path.Combine(ExportPath, ReportContainerName));
        }
Esempio n. 20
0
        private void ExportAsPdf()
        {
            string page = DatatableToHtml.ConvertToHtml(GetMergedDataTable(), ExportPath, ReportContainerName);
            string save = HtmlHelper.ReplaceReportDetails(page, GSCP, false);

            HtmLtoPdf.SaveHtmltoPdf(save, GSCP, "audit log", Path.Combine(ExportPath, ReportContainerName, Constants.PdfReportName));
            string hash = OsirtHelper.CreateHashForFolder(Path.Combine(ExportPath, ReportContainerName));

            Logger.Log(new OsirtActionsLog(Enums.Actions.Report, hash, ReportContainerName));
            PlaceReportInContainer(Path.Combine(ExportPath, ReportContainerName));
            if (openReport)
            {
                Process.Start(Path.Combine(ExportPath, ReportContainerName, Constants.PdfReportName));
            }
        }
        private void SplashScreen_Load(object sender, EventArgs e)
        {
            uiVersionLabel.Text = $"v{Constants.OsirtVersion} {Constants.CefVersion}";


            var backgroundWorker = new BackgroundWorker();

            backgroundWorker.WorkerReportsProgress = true;
            backgroundWorker.DoWork += delegate
            {
                OsirtHelper.CheckCacheDirectoriesExist();
                Thread.Sleep(2000);
                string[] log  = OsirtLogWriter.ReadLog();
                string   path = log[0];


                if (!Convert.ToBoolean(log[1]))
                {
                    bool fileExists = File.Exists(path + ".osr");
                    if (!fileExists)
                    {
                        backgroundWorker.ReportProgress(10, $"Previous Case not closed successfully. Re-Archiving: {log[0] + Constants.ContainerExtension}");
                        Thread.Sleep(250);
                        using (ZipFile zip = new ZipFile())
                        {
                            //if (password.Length > 0)
                            //{
                            //    zip.Password = password;
                            //    zip.Encryption = EncryptionAlgorithm.WinZipAes256;
                            //}

                            zip.AddDirectory(path, Path.GetFileName(path));
                            zip.Save(Path.Combine(Directory.GetParent(path).FullName, Path.GetFileName(path) + Constants.ContainerExtension));
                        }

                        //Dear idiot, don't recursively delete your desktop again like a moron.
                        OsirtHelper.DeleteDirectory(path);
                    }
                }
            };
            backgroundWorker.ProgressChanged    += BackgroundWorker_ProgressChanged;
            backgroundWorker.RunWorkerCompleted += delegate
            {
                CaseChecked?.Invoke(this, e);
                Close();
            };
            backgroundWorker.RunWorkerAsync();
        }
        private void uiSaveSourceToolStripButton_Click(object sender, EventArgs e)
        {
            string filename = Constants.PageSourceFileName.Replace("%%dt%%", DateTime.Now.ToString("yyyy-MM-dd_hh_mm_ss")).Replace("%%name%%", domainUrlAndTitle.Item1).Replace("%%action%%", action.ToString().Replace(".", "_"));
            string path     = Path.Combine(Constants.ContainerLocation, Constants.Directories.GetSpecifiedCaseDirectory(action), filename);

            using (FileStream fileStream = new FileStream(path, FileMode.Create))
            {
                using (StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
                {
                    streamWriter.WriteLine(fctb.Text);
                }
            }

            Logger.Log(new WebpageActionsLog(domainUrlAndTitle.Item2, action, OsirtHelper.GetFileHash(path), filename, $"[{action.ToString()} downloaded]"));
            MessageBox.Show("Save successful", $"Saved - {action.ToString()}", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 23
0
        private void DownloadFile(string path)
        {
            try
            {
                WebClient webClient = new WebClient();
                webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
                webClient.DownloadFileCompleted   += webClient_DownloadFileCompleted;

                string file = Path.Combine(Constants.CacheLocation, Path.GetFileName(OsirtHelper.StripQueryFromPath(path)));
                webClient.DownloadFileAsync(new Uri(path), file, file);
            }
            catch
            {
                MessageBox.Show("Unable to download this file.", "Unable to download file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void uiDownloadButton_Click(object sender, EventArgs e)
        {
            if (!OsirtHelper.IsOnFacebook(DownloadUrl))
            {
                MessageBox.Show("The download URL does not appear to be a Facebook video URL.", "Invalid Facebook Video URL", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            uiDownloadProgressBar.Visible = true;
            uiCancelButton.Enabled        = false;
            string videoUrl = DownloadUrl;
            string url;

            try
            {
                using (WebClient wc = new WebClient())
                {
                    wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36");

                    //get page source from the url entered
                    string source = wc.DownloadString(videoUrl);
                    //simply parse the page source looking for simple tokens.
                    int hdLoc  = source.IndexOf("hd_src:");
                    int sdLoc  = source.IndexOf(",sd_src:");
                    int length = sdLoc - hdLoc;
                    url = source.Substring(hdLoc, length);
                    //find everything between quotes, in this case the Url
                    url = Regex.Match(url, "\"([^\"]*)\"").ToString().Replace("\"", "");
                }

                using (WebClient downloader = new WebClient())
                {
                    //need to rethink the video file in cache, could have multiple videos saving there
                    //need video recovery

                    string facebookVideoLocation = Path.Combine(Constants.VideoCacheLocation, "temp_facebook_vid.mp4");

                    downloader.DownloadFileAsync(new Uri(url), facebookVideoLocation);
                    downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged;
                    downloader.DownloadFileCompleted   += Downloader_DownloadFileCompleted;
                }
            }
            catch
            {
                MessageBox.Show("Unable to download this video. Make sure a valid video URL is entered.", "Error downloading video", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void uiBrowseButton_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFile = new OpenFileDialog())
            {
                DialogResult result = openFile.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                uiAttachFileProgressPanel.Visible = false;
                fileWithPath = openFile.FileName;
                file         = openFile.SafeFileName;
                hash         = OsirtHelper.GetFileHash(fileWithPath);

                UpdateFileDetailsUi();
                DisplayIcon();
            }
        }
Esempio n. 26
0
        void IContextMenuHandler.OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
        {
            //Removing existing menu item
            model.Clear();

            if (!string.IsNullOrEmpty(parameters.UnfilteredLinkUrl))
            {
                model.AddItem((CefMenuCommand)26501, "Open link in new tab");
                model.AddSeparator();
            }
            if (parameters.TypeFlags.HasFlag(ContextMenuType.Media) && parameters.HasImageContents)
            {
                if (!UI.BrowserPanel.IsUsingTor)
                {
                    if (OsirtHelper.HasJpegExtension(parameters.SourceUrl))
                    {
                        model.AddItem((CefMenuCommand)ViewImageExifData, "View image EXIF data");
                    }
                    model.AddItem((CefMenuCommand)MenuSaveImage, "Save image");
                }
                model.AddItem((CefMenuCommand)CopyImgLocation, "Copy image location to clipboard");
                model.AddItem((CefMenuCommand)ReverseImageSearch, "Reverse image search using TinEye");
                model.AddSeparator();
                //
            }
            if (OsirtHelper.IsOnYouTube(browserControl.Address))
            {
                model.AddItem((CefMenuCommand)SaveYouTubeVideo, "Extract YouTube video");
            }
            if (OsirtHelper.IsOnFacebook(browserControl.Address))
            {
                model.AddItem((CefMenuCommand)ViewFacebookId, "Show Facebook profile ID");
            }
            if (OsirtHelper.IsOnTwitter(browserControl.Address))
            {
                model.AddItem((CefMenuCommand)ViewTwitterId, "Show Twitter profile ID");
            }

            model.AddItem((CefMenuCommand)ViewSource, "View page source");
            model.AddItem((CefMenuCommand)ExtractAllLinks, "Extract all links on page");
            model.AddItem((CefMenuCommand)Bookmark, "Add page to bookmarks");
        }
Esempio n. 27
0
        private void uiBookmarksDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int col = e.ColumnIndex;

            if (col < 0)
            {
                return;
            }

            int             rowIndex = e.RowIndex;
            DataGridViewRow row      = uiBookmarksDataGridView.Rows[rowIndex];
            string          key      = "";

            switch (col)
            {
            case 0:
                DialogResult dr = MessageBox.Show("This will remove this bookmark. Are you sure?", "Remove Bookmark?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (dr != DialogResult.Yes)
                {
                    return;
                }
                key = row.Cells[1].Value.ToString();
                OsirtHelper.Favourites.Remove(key);
                uiBookmarksDataGridView.Rows.Remove(row);
                uiBookmarksDataGridView.Update();
                uiBookmarksDataGridView.Refresh();
                OsirtHelper.WriteFavourites();
                BookmarkRemoved?.Invoke(this, EventArgs.Empty);
                break;

            case 2:
                //click link
                key = row.Cells[2].Value.ToString();
                LinkClicked?.Invoke(this, new TextEventArgs(key));
                break;
            }
        }
Esempio n. 28
0
        private void PopulateExtenions()
        {
            uiFileExtensionComboBox.Items.Clear();
            string extensionsCsv = "";

            switch (action)
            {
            case Actions.Screenshot:
            case Actions.Scraped:     //Scraped won't use previewer?
            case Actions.Snippet:
                extensionsCsv = OsirtHelper.GetResource("ImageSaveableTypes.txt");
                break;

            case Actions.Video:
                extensionsCsv = OsirtHelper.GetResource("VideoSaveableFileTypes.txt");
                break;

            case Actions.Source:
            case Actions.Ipaddress:
            case Actions.Links:
            case Actions.Whois:
                extensionsCsv = OsirtHelper.GetResource("TextSaveableTypes.txt");
                break;
            }

            if (extensionsCsv.Contains(","))
            {
                string[] split = extensionsCsv.Split(',');
                uiFileExtensionComboBox.Items.AddRange(split);
            }
            else
            {
                uiFileExtensionComboBox.Items.Add(extensionsCsv);
            }
            uiFileExtensionComboBox.SelectedIndex = 0;
        }
Esempio n. 29
0
        private void CopyPageSaveToCase(string folder, WaitWindowEventArgs e)
        {
            using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory(folder);
                zip.Save(folder + ".zip");
                e.Window.Message = "Zipping...Please Wait";
            }

            string copyTo = Path.Combine(Constants.ContainerLocation, Constants.Directories.GetSpecifiedCaseDirectory(Enums.Actions.Download), Path.GetFileNameWithoutExtension(folder) + ".zip");

            File.Copy(folder + ".zip", copyTo);
            e.Window.Message = "Logging...Please Wait";
            Logger.Log(new WebpageActionsLog(uiTabbedBrowserControl.CurrentTab.Browser.URL, Enums.Actions.Download, OsirtHelper.GetFileHash(copyTo), Path.GetFileNameWithoutExtension(folder) + ".zip", "Webpage downloaded"));
            Thread.Sleep(2000);
            File.Delete(folder + ".zip");
            ImageDiskCache.RemoveItemsInCache();
        }
Esempio n. 30
0
        private void SavePage(object sender, WaitWindowEventArgs e)
        {
            string output = "";

            List <RequestWrapper> resources      = uiTabbedBrowserControl.CurrentTab.Browser.ResourcesSet().OrderBy(q => q.Identifier).ToList();
            List <HeaderWrapper>  headers        = uiTabbedBrowserControl.CurrentTab.Browser.ResponseHeaders().OrderBy(q => q.Identifer).ToList();
            List <HeaderWrapper>  requestHeaders = uiTabbedBrowserControl.CurrentTab.Browser.RequestHeaders().OrderBy(q => q.Identifer).ToList();

            string saveFolder  = new Uri(uiTabbedBrowserControl.CurrentTab.Browser.URL).Host.Replace(".", "_") + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff");
            string savePath    = Path.Combine(GSettings.Load().SaveDirectory, saveFolder);
            string logSavePath = Path.Combine(savePath, "_complete_log");

            Directory.CreateDirectory(savePath);
            Directory.CreateDirectory(logSavePath);

            output += "=================================================================================\r\n";
            output += "Capture started: " + DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss.fff") + "\r\n";
            output += "URL: " + uiTabbedBrowserControl.CurrentTab.Browser.URL + "\r\n";
            output += "IP(s): " + OsirtHelper.GetIpFromUrl(uiTabbedBrowserControl.CurrentTab.Browser.URL).Replace("\r\n", " ") + "\r\n";
            output += "Screenshot Hash: " + OsirtHelper.GetFileHash(Constants.TempImgFile) + "\r\n";
            output += "=================================================================================\r\n";

            ulong count = 0;

            foreach (var resource in resources)
            {
                Directory.CreateDirectory($@"{savePath}\{resource.ResourceType}");
                string filename = resource.ResourceType == ResourceType.MainFrame ? "mainframe.html" : OsirtHelper.GetSafeFilename(resource.RequestUrl, resource.MimeType);
                e.Window.Message = "Saving: " + filename + "...Please Wait";

                if (File.Exists($@"{savePath}\{resource.ResourceType}\{filename}"))
                {
                    filename = $"{++count}_{filename}";
                }

                File.WriteAllBytes($@"{savePath}\{resource.ResourceType}\{filename}", resource.Data);
                output  += "=================================================================================\r\n";
                output  += "Request ID: " + resource.Identifier + "\r\n";
                output  += "Request URL: " + resource.RequestUrl + "\r\n";
                output  += "Request URL IP(s): " + OsirtHelper.GetIpFromUrl(resource.RequestUrl).Replace("\r\n", " ") + "\r\n";
                output  += "Resource Type: " + resource.ResourceType + "\r\n";
                output  += "Mime Type: " + resource.MimeType + "\r\n";
                output  += "File Saved Location: " + $@"{savePath}\{resource.ResourceType}\{filename}" + "\r\n";
                output  += $"Hash [{UserSettings.Load().Hash.ToUpper()}]: " + OsirtHelper.GetFileHash(resource.Data) + "\r\n";
                output  += "Save completed at: " + DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss.fffffff") + "\r\n";
                output  += "=================================================================================\r\n";
                e.Result = savePath;
            }

            output += "=================================================================================\r\n";
            output += "Capture finished: " + DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss.fff") + "\r\n";
            output += "=================================================================================\r\n";
            File.AppendAllText($@"{logSavePath}\_capture.txt", output);
            File.Copy(Constants.TempImgFile, $@"{logSavePath}\_website.png");

            if (GSettings.Load().SaveHttpHeaders)
            {
                string headerOutput = "";
                foreach (var k in headers)
                {
                    headerOutput += "====================================================\r\n";
                    headerOutput += "Request ID: " + k.Identifer + "\r\n";
                    foreach (KeyValuePair <string, string> kv in k.Headers)
                    {
                        headerOutput += $"{kv.Key} : {kv.Value}" + "\r\n";
                    }
                    headerOutput += "====================================================\r\n";
                }
                File.AppendAllText($@"{logSavePath}\_headers.txt", headerOutput);

                //string reqheaderOutput = "";
                //foreach (var k in requestHeaders)
                //{
                //    reqheaderOutput += "====================================================\r\n";
                //    reqheaderOutput += "Request ID: " + k.Identifer + "\r\n";
                //    foreach (KeyValuePair<string, string> kv in k.Headers)
                //    {
                //        reqheaderOutput += $"{kv.Key} : {kv.Value}" + "\r\n";
                //    }
                //    reqheaderOutput += "====================================================\r\n";
                //}
                //File.AppendAllText($@"{logSavePath}\_request_headers.txt", reqheaderOutput);
            }

            CopyPageSaveToCase(savePath, e);
        }