-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvram2AcasScanPolicy.ps1
144 lines (111 loc) · 5.28 KB
/
vram2AcasScanPolicy.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<#
.SYNOPSIS
This script will create an ACAS Scan Policy for the audits that VRAM needs input from
.DESCRIPTION
This script will create an ACAS Scan Policy for the audits that VRAM needs input from
.PARAMETER auditPath
The path to the VRAM Audits (csv format)
.EXAMPLE
C:\PS>.\vram2AcasScanPolicy.ps1 -auditPath "c:\audits.csv"
This example will clean the designated path
.INPUTS
There are no inputs that can be directed to this script
.OUTPUTS
All outputs are sent to the console and logged in the log folder
.NOTES
Author: Robert Weber
Date: Nov 2, 2015
#>
[CmdletBinding()]
param( $auditPath )
clear
$error.clear()
. .\lib\PSClass.ps1
(gci .\lib) | % { . "$($_.FullName)" }
$vram2AcasScanPolicyClass = new-PSClass vram2AcasScanPolicy{
note -static PsScriptName "vram2AcasScanPolicy"
note -static Description ( ($(((get-help .\vram2AcasScanPolicy.ps1).Description)) | select Text).Text)
note -private mainProgressBar
note -private auditPath
note -private activeAudits
note -private scanPolicy
note -private ie
note -private gui
method Execute{
$private.mainProgressBar = $progressBarClass.New( @{ "parentId" = 0; "Activity" = "0 / 0 :"; "Status" = ("0% complete" ); "PercentComplete" = 0; "Completed" = $false; "id" = 1 }).Render()
$uiClass.writeColor( "$($uiClass.STAT_OK) Parsing Active Plugins")
$private.ie = new-object -com "InternetExplorer.Application"
$private.activeAudits = Import-Csv "$($private.auditPath)"
$private.scanPolicy = [xml](gc "$($pwd)/db/vramAcasSP.xml")
$c = 0
$d = 0
$activeCount = $( ( $private.activeAudits | ? { $_.'Nessus ID' -ne '' } ).count)
foreach($audit in ( $private.activeAudits | ? { $_.'Nessus ID' -ne '' } | sort 'Nessus ID')){
$c++
if($c % 100 -eq 0){
$i = 100*($c / $activeCount)
$private.mainProgressBar.Activity("$c / $activeCount : Analysing Plugin $($audit.'Nessus ID') ").Status(("{0:N2}% complete" -f $i)).Percent($i).Render()
}
$source = "http://www.tenable.com/plugins/index.php?view=single&id=$($audit.'Nessus ID')"
$present = $private.scanPolicy.selectNodes("/NessusClientData_v2/Policy/IndividualPluginSelection/PluginItem[./PluginId/text()='$($audit.'Nessus ID')']")
if($present.count -eq 0){
$private.ie.navigate( $source ) | out-null
while($private.ie.document.readyState -ne 'complete'){
sleep -milliseconds 100
}
$doc = $private.ie.Document
if($doc -ne $null -and $doc -ne ''){
$d++
# $pluginName = ($doc.documentElement.getElementsByClassName('plugin-single') | select -first 1 ).children | ? { $_.tagName -eq 'H1' } | select -first 1 | select -expand innerText
$pluginName = $($audit.'Title')
$pluginFamily = (($doc.documentElement.getElementsByTagName('p') | ? { $_.innerHtml -like '*strong*' } | ? { $_.innerHtml -like '*Family*' } | select -expand innerText ) -replace 'family:','')
$pluginId = $($audit.'Nessus ID')
$pluginItem = $private.scanPolicy.createElement('PluginItem')
$pluginIdNode = $private.scanPolicy.createElement('PluginId')
$pluginIdNode.innerText = $audit.'Nessus ID'
$pluginNameNode = $private.scanPolicy.createElement('PluginName')
$pluginNameNode.innerText = $pluginName
$pluginFamilyNode = $private.scanPolicy.createElement('Family')
$pluginFamilyNode.innerText = $pluginFamily
$pluginStatusNode = $private.scanPolicy.createElement('Status')
$pluginStatusNode.innerText = "enabled"
$pluginItem.appendChild($pluginIdNode) | out-null
$pluginItem.appendChild($pluginNameNode) | out-null
$pluginItem.appendChild($pluginFamilyNode) | out-null
$pluginItem.appendChild($pluginStatusNode) | out-null
$private.scanPolicy.NessusClientData_v2.Policy.IndividualPluginSelection.appendChild($pluginItem) | out-null
#enable plugin family
$p = $private.scanPolicy.selectSingleNode("/NessusClientData_v2/Policy/FamilySelection/FamilyItem[./FamilyName/text()='$($pluginFamily)']/Status")
if($p -ne $null){
$p.innerText = 'mixed'
}
$uiClass.writeColor( "$($uiClass.STAT_WAIT) Analysing Plugin #yellow#$($pluginId)# : $($pluginFamily) - #green#$($pluginName)#")
if ( ($d % 50) -eq 0){
$uiClass.writeColor("$($uiClass.STAT_WAIT) Saving Current Policy for in case of error...")
$private.scanPolicy.save("$($pwd)/db/vramAcasSP.xml") | out-null
}
}
}
}
$private.scanPolicy.PreserveWhitespace = $true
$private.scanPolicy.save("$($pwd)/db/vramAcasSP.xml") | out-null
copy-item "$($pwd)/db/vramAcasSP.xml" "$($pwd)/results/vramAcasSP.xml"
$private.ie.quit()
$private.mainProgressBar.Completed($true).Render()
$uiClass.errorLog()
}
constructor{
param()
$private.auditPath = $auditPath
while($utilities.isBlank($private.auditPath) -eq $true){
$private.gui = $null
$private.gui = $guiClass.New("vram2AcasScanPolicy.xml")
$private.gui.generateForm();
$private.gui.Controls.btnExecute.add_Click({ $private.gui.Form.close() })
$private.gui.Controls.btnOpenFileBrowser.add_Click({ $private.gui.Controls.txtAuditPath.Text = $private.gui.actInvokeFileBrowser(@{"CSV Files (*.csv)" = "*.csv";}) })
$private.gui.Form.ShowDialog()| Out-Null
$private.auditPath = $private.gui.Controls.txtAuditPath.Text
}
}
}
$vram2AcasScanPolicyClass.New().Execute() | out-null