使用 PowerShell 进行网络抓取 问题:我的代码无法提取所需的信息。为什么?



使用PowerShell抓取网页问题:我的代码无法获取所需的信息。为什么?

到目前为止,我的代码将提取正确的信息。它显示的信息是:
Here is a list of the top 10 results:
href                                    
----                                    
/shadowsocks/shadowsocks-windows        
/Hack-with-Github/Windows               
/felixrieseberg/windows95               
/boxcutter/windows                      
/HostsTools/Windows                     
/chef-boneyard/windows                  
/Sycnex/Windows10Debloater              
/microsoft/terminal                     
/windows-toolkit/WindowsCommunityToolkit
/microsoft/Windows-universal-samples    

所需信息进入PowerShell终端后。我试着拉一个新的网页抓取,但它不工作。

下面是我的PowerShell代码:

$choice = Read-Host "Type number here"
Write-Host ""
if ([string]1 -eq $choice )
{
$add = Read-Host "Add an above repo here"
$url2 = 'https://raw.githubusercontent.com' + $add + '/master/README.md'
$contributors2 = Invoke-WebRequest -Uri $url2 -UseBasicParsing
$contributors2.Links| Where-Object "pre" | Select-Object innerText | Out-String
Write-Output $output2
}

我要获取的信息是:

<pre style="word-wrap: break-word; white-space: pre-wrap;">## Windows
Awesome tools to play with Windows!
List of tools used for exploiting Windows:
- **[Exploitation](https://github.com/hacksysteam/Exploitation)** : Windows Software Exploitation
- **[hacking-team-windows-kernel-lpe](https://github.com/vlad902/hacking-team-windows-kernel-lpe)** : Previously-0day exploit from the Hacking Team leak, written by Eugene Ching/Qavar.
- **[mimikatz](https://github.com/gentilkiwi/mimikatz)** : A little tool to play with Windows security - extract plaintexts passwords, hash, PIN code and kerberos tickets from memory.
- **[Pazuzu](https://github.com/BorjaMerino/Pazuzu)** : Reflective DLL to run binaries from memory
- **[Potato](https://github.com/foxglovesec/Potato)** : Privilege Escalation on Windows 7,8,10, Server 2008, Server 2012
- **[UACME](https://github.com/hfiref0x/UACME)** : Defeating Windows User Account Control
- **[Windows-Exploit-Suggester](https://github.com/GDSSecurity/Windows-Exploit-Suggester)** : This tool compares a targets patch levels against the Microsoft vulnerability database in order to detect potential missing patches on the target. It also notifies the user if there are public exploits and Metasploit modules available for the missing bulletins.
### Misc
- **[afot](https://github.com/harris21/afot)** : Automation Forensics Tool for Windows
- **[Invoke-LoginPrompt](https://github.com/enigma0x3/Invoke-LoginPrompt)** : Invokes a Windows Security Login Prompt and outputs the clear text password
- **[PowerShellArsenal](https://github.com/mattifestation/PowerShellArsenal)** : A PowerShell Module Dedicated to Reverse Engineering
- **[Winpayloads](https://github.com/nccgroup/Winpayloads)** : Undetectable Windows Payload Generation
### PowerShell
- **[BloodHound](https://github.com/adaptivethreat/BloodHound)** : Six Degrees of Domain Admin
- **[Empire](https://github.com/adaptivethreat/Empire)** : Empire is a PowerShell and Python post-exploitation agent
- **[Generate-Macro](https://github.com/enigma0x3/Generate-Macro)** : Powershell script will generate a malicious Microsoft Office document with a specified payload and persistence method
- **[Invoke-AltDSBackdoor](https://github.com/enigma0x3/Invoke-AltDSBackdoor)** : This script will obtain persistence on a Windows 7+ machine under both Standard and Administrative accounts by using two Alternate Data Streams
- **[Old-Powershell-payload-Excel-Delivery](https://github.com/enigma0x3/Old-Powershell-payload-Excel-Delivery)** : This version touches disk for registry persistence
- **[PSRecon](https://github.com/gfoss/PSRecon)** : PSRecon gathers data from a remote Windows host using PowerShell (v2 or later), organizes the data into folders, hashes all extracted data, hashes PowerShell and various system properties, and sends the data off to the security team
- **[PowerShell-Suite](https://github.com/FuzzySecurity/PowerShell-Suite)** : Some useful scripts in powershell
- **[PowerSploit](https://github.com/PowerShellMafia/PowerSploit)** : A PowerShell Post-Exploitation Framework
- **[PowerTools](https://github.com/PowerShellEmpire/PowerTools)** : A collection of PowerShell projects with a focus on offensive operations
- **[Powershell-C2](https://github.com/enigma0x3/Powershell-C2)** : A PowerShell script to maintain persistance on a Windows machine
- **[Powershell-Payload-Excel-Delivery](https://github.com/enigma0x3/Powershell-Payload-Excel-Delivery)** : Uses Invoke-Shellcode to execute a payload and persist on the system
- **[mimikittenz](https://github.com/putterpanda/mimikittenz)** : A post-exploitation powershell tool for extracting juicy info from memory.
</pre>

为什么我的代码不能拉进这个Github文档?

Replace:

$contributors2.Links| Where-Object "pre" | Select-Object innerText | Out-String

:

$contributors2.Content

它确实像你的代码缺少一些东西-根据@Theo的评论,它不清楚$output2来自哪里。

修复了我的问题。我需要将$contributors2限定符从Links更改为RawContent。

下面是代码更改:

$choice = Read-Host "Type number here"
Write-Host ""
if ([string]1 -eq $choice )
{
$add = Read-Host "Add an above repo here"
$url2 = 'https://raw.githubusercontent.com' + $add + '/master/README.md'
$contributors2 = Invoke-WebRequest -Uri $url2 -UseBasicParsing
$contributors2.RawContent | Out-String
Write-Output $output
}

它现在拉入所需的web- scraper。

最新更新