【问题标题】:Browser history with powershell带有 powershell 的浏览器历史记录
【发布时间】:2019-06-21 17:10:17
【问题描述】:

我正在尝试创建一个脚本来检索我的所有浏览器历史记录,问题是我无法使用确切的链接和访问网站的日期时间使其工作。

有人可以帮我吗?

我已经尝试过这个页面,但仍然无法获取日期时间/完整的链接信息。

Export Chrome History with Powershell

function Get-ChromeHistory {
            $Path = "$Env:systemdrive\Users\$UserName\AppData\Local\Google\Chrome\User Data\Default\History"
            if (-not (Test-Path -Path $Path)) {
                Write-Verbose "[!] Could not find Chrome History for username: $UserName"
            }
            $Regex = '(htt(p|s))://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)*?'
            $Value = Get-Content -Path "$Env:systemdrive\Users\$UserName\AppData\Local\Google\Chrome\User Data\Default\History"|Select-String -AllMatches $regex |% {($_.Matches).Value} |Sort -Unique
            $Value | ForEach-Object {
                $Key = $_
                if ($Key -match $Search){
                    New-Object -TypeName PSObject -Property @{
                        User = $UserName
                        Browser = 'Chrome'
                        DataType = 'History'
                        Data = $_
                    }
                }
            }        
        }

实际结果: Chrome | myusername | https://www.stackoverflow.com/

预期结果: Chrome | username | 06/21/2019 11:05 | https://stackoverflow.com/questions/ask

【问题讨论】:

  • 您提供的代码仅从 Chrome 的历史记录 SQLLite DB 中提取 URL,而不是日期。除非您使用 SQLLite 应用程序或 System.Data.SQLite 等库之一,否则解析与 URL 关联的日期将非常困难
  • 对于 .NET,请参阅 this extension。您可以使用它与 sqllite db 进行交互。

标签: powershell google-chrome browser-history


【解决方案1】:

除了 SQLLite Parsing 问题之外,上面的代码还有两个 bug:$UserName 没有指定,正则表达式只能找到 HTTP URL。 以下是获取 HTTP 和 HTTPS 顶级 URL 的更正版本。不幸的是,它不包含您似乎想要但无法从 SQLLite 文件中可靠地获取的资源路径。文件中 URL 的结尾没有分隔符。

function Get-ChromeHistory {
    $Path = "$Env:SystemDrive\Users\$Env:USERNAME\AppData\Local\Google\Chrome\User Data\Default\History"
    if (-not (Test-Path -Path $Path)) {
        Write-Verbose "[!] Could not find Chrome History for username: $UserName"
    }
    $Regex = '(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)*?'
    $Value = Get-Content -Path $path | Select-String -AllMatches $regex |% {($_.Matches).Value} |Sort -Unique
    $Value | ForEach-Object {
        $Key = $_
        if ($Key -match $Search){
            New-Object -TypeName PSObject -Property @{
                User = $env:UserName
                Browser = 'Chrome'
                DataType = 'History'
                Data = $_
            }
        }
    } 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 2019-06-09
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 2011-11-14
    • 2013-05-21
    相关资源
    最近更新 更多