Wednesday, May 27, 2009

Syncing NirSoft Repository

Nirsoft has a great collection of tools streamlining some aspects of offensive penetration and system management. If you are stuck without your toolkit, it's possible to automaticaly sync Nirsoft repository to your local cache and go from there. The site posts directory of utils here
Each XML file describes individual utility including direct download link which we can use to cync the depots.

Here's my Powershell script.



PS C:\Users\dxs\Code\powershell> gc .\SyncNirsoft.ps1


function GetNirSoftUtils(
$padLink=[string]"http://www.nirsoft.net/pad/pad-links.txt"

){

BEGIN{
Write-host "Getting PAD link"
$webclient=(New-Object -Type System.Net.WebClient)
$webclient.DownloadFile($padlink,"$(pwd)\pad-links.txt")
$padidx=$( Get-ChildItem $(pwd) "*.txt" | %{ $_.Name } )
write-host "Gotten: $padidx"

}
PROCESS{
Write-host "Getting PAD XML Links"
foreach ( $padxmllnk in $(Get-Content $padidx )){

# strip http:// for filesystem operation
$padxmllnkfs=$padxmllnk -replace "http://", ""

# basename the file (i.e /path/to/file -> file )
$padxmlfs=(split-path $padxmllnkfs -leaf).split("/")[-1]

# Conform to full path
$padxmlfs="$(pwd)\$padxmlfs"

# Download XML index files
Write-Host "Getting Index $padxmllnk --> $padxmlfs "
#$webclient.DownloadFile($padxmllnk,"$padxmlfs")

# Parsing Index and Getting Depot Download links
$depotids=[XML](Get-Content $padxmlfs )
$depotURL=$($depotids.SelectNodes(
"descendant::Web_Info/Download_URLs/Primary_Download_URL") |
% { $_.Inner

Xml})


# strip http:// for filesystem operation
$depotfs=$depotURL -replace "http://", ""

# basename the file (i.e /path/to/file -> file )
$depotfs=(split-path $depotfs -leaf).split("/")[-1]

# Conform to full path
$depotfs="$(pwd)\$depotfs"
Write-Host "Getting Depot $depotURL --> $depotfs "

$webclient.DownloadFile($depotURL,"$depotfs")

}
}
END{
Write-host "end"
}

}








Runtime example:


PS C:\Users\dxs\Code\powershell> .\SyncNirsoft.ps1
Getting PAD link
Gotten: pad-links.txt
Getting PAD XML Links
Getting Index http://www.nirsoft.net/pad/acm.xml --> C:\Users\dxs\Downloads\Nirsoft-PAD\acm.xml
Getting Depot http://www.nirsoft.net/utils/acm.zip --> C:\Users\dxs\Downloads\Nirsoft-PAD\acm.zip

0 comments: