-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hard_WinDesk_mixIA_200924
206 lines (175 loc) · 7.46 KB
/
Hard_WinDesk_mixIA_200924
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# Ruta del archivo de salida
$output_file = "$env:USERPROFILE\Desktop\informe_seguridad_avanzado.html"
# Importar módulos necesarios
Import-Module BitsTransfer
# Función para agregar contenido HTML
function Add-HtmlContent {
param (
[string]$title,
[string]$content
)
@"
<h2>$title</h2>
$content
"@
}
# Función para convertir objetos a tabla HTML
function ConvertTo-HtmlTable {
param (
[Parameter(ValueFromPipeline=$true)]
[PSObject[]]$InputObject
)
if ($null -eq $InputObject -or $InputObject.Count -eq 0) {
return "<p>No hay datos disponibles.</p>"
}
$html = "<table border='1'><tr>"
$properties = $InputObject[0].PSObject.Properties
$properties | ForEach-Object { $html += "<th>$($_.Name)</th>" }
$html += "</tr>"
foreach ($obj in $InputObject) {
$html += "<tr>"
$properties | ForEach-Object {
$value = if ($null -eq $obj.$($_.Name)) { "N/A" } else { $obj.$($_.Name) }
$html += "<td>$value</td>"
}
$html += "</tr>"
}
$html += "</table>"
return $html
}
# Función para manejar errores y devolver un mensaje HTML
function Handle-Error {
param (
[string]$errorMessage
)
return "<p class='error'>Error: $errorMessage</p>"
}
# Iniciar el contenido HTML
$htmlContent = @"
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Informe de Seguridad Avanzado</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 800px; margin: 0 auto; padding: 20px; }
h1 { color: #2c3e50; }
h2 { color: #34495e; border-bottom: 1px solid #ecf0f1; padding-bottom: 10px; }
table { border-collapse: collapse; width: 100%; margin-bottom: 20px; }
th, td { text-align: left; padding: 8px; border: 1px solid #ddd; }
th { background-color: #f2f2f2; }
.warning { color: #e74c3c; }
.ok { color: #27ae60; }
.error { color: #c0392b; font-weight: bold; }
</style>
</head>
<body>
<h1>Informe de Seguridad Avanzado</h1>
<p>Generado el: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")</p>
"@
# 1. Información del Sistema Operativo
try {
$os_info = Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, BuildNumber, OSArchitecture
$htmlContent += Add-HtmlContent "Información del Sistema Operativo" (ConvertTo-HtmlTable $os_info)
} catch {
$htmlContent += Add-HtmlContent "Información del Sistema Operativo" (Handle-Error $_.Exception.Message)
}
# 2. Escaneo de Seguridad con Windows Defender
try {
$defenderStatus = Start-MpScan -ScanType QuickScan
$htmlContent += Add-HtmlContent "Resultado de Windows Defender" (ConvertTo-HtmlTable $defenderStatus)
} catch {
$htmlContent += Add-HtmlContent "Resultado de Windows Defender" (Handle-Error $_.Exception.Message)
}
# 3. Software Instalado y Vulnerabilidades
try {
$softwareList = Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" |
Where-Object { $_.DisplayName -and $_.DisplayVersion } |
Select-Object DisplayName, DisplayVersion |
Sort-Object DisplayName -Unique
# Comprobar vulnerabilidades conocidas (simulado, requeriría una base de datos real)
$vulnerableSoftware = $softwareList | Where-Object {
$_.DisplayName -match "Adobe Reader|Java|Flash Player"
}
$htmlContent += Add-HtmlContent "Software Potencialmente Vulnerable" (ConvertTo-HtmlTable $vulnerableSoftware)
} catch {
$htmlContent += Add-HtmlContent "Software Potencialmente Vulnerable" (Handle-Error $_.Exception.Message)
}
# 4. Configuración del Firewall
try {
$firewallProfiles = Get-NetFirewallProfile | Select-Object Name, Enabled
$htmlContent += Add-HtmlContent "Estado del Firewall" (ConvertTo-HtmlTable $firewallProfiles)
} catch {
$htmlContent += Add-HtmlContent "Estado del Firewall" (Handle-Error $_.Exception.Message)
}
# 5. Análisis de Puertos Abiertos
try {
$openPorts = Get-NetTCPConnection | Where-Object State -eq 'Listen' | Select-Object LocalPort, OwningProcess
$htmlContent += Add-HtmlContent "Puertos Abiertos" (ConvertTo-HtmlTable $openPorts)
} catch {
$htmlContent += Add-HtmlContent "Puertos Abiertos" (Handle-Error $_.Exception.Message)
}
# 6. Estado de las Actualizaciones
try {
$updateSession = New-Object -ComObject Microsoft.Update.Session
$updateSearcher = $updateSession.CreateUpdateSearcher()
$pendingUpdates = @($updateSearcher.Search("IsInstalled=0 and Type='Software'").Updates)
$htmlContent += Add-HtmlContent "Actualizaciones Pendientes" "<p>Número de actualizaciones pendientes: $($pendingUpdates.Count)</p>"
} catch {
$htmlContent += Add-HtmlContent "Actualizaciones Pendientes" (Handle-Error $_.Exception.Message)
}
# 7. Análisis de Cuentas de Usuario
try {
$users = Get-LocalUser | Select-Object Name, Enabled, LastLogon
$htmlContent += Add-HtmlContent "Cuentas de Usuario" (ConvertTo-HtmlTable $users)
} catch {
$htmlContent += Add-HtmlContent "Cuentas de Usuario" (Handle-Error $_.Exception.Message)
}
# 8. Comprobación de Políticas de Contraseñas
try {
$passwordPolicy = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" | Select-Object LmCompatibilityLevel, NoLMHash
$htmlContent += Add-HtmlContent "Política de Contraseñas" (ConvertTo-HtmlTable $passwordPolicy)
} catch {
$htmlContent += Add-HtmlContent "Política de Contraseñas" (Handle-Error $_.Exception.Message)
}
# 9. Análisis de Eventos de Seguridad Críticos
try {
$criticalEvents = Get-WinEvent -LogName Security -MaxEvents 1000 |
Where-Object { $_.Id -in 4625, 4648, 4719, 4765, 4766, 4794, 4897, 4964 } |
Select-Object TimeCreated, Id, Message
$htmlContent += Add-HtmlContent "Eventos de Seguridad Críticos" (ConvertTo-HtmlTable $criticalEvents)
} catch {
$htmlContent += Add-HtmlContent "Eventos de Seguridad Críticos" (Handle-Error $_.Exception.Message)
}
# 10. Comprobación de Cifrado de Disco
try {
$bitlockerVolumes = Get-BitLockerVolume | Select-Object MountPoint, VolumeStatus, EncryptionPercentage
$htmlContent += Add-HtmlContent "Estado de Cifrado BitLocker" (ConvertTo-HtmlTable $bitlockerVolumes)
} catch {
$htmlContent += Add-HtmlContent "Estado de Cifrado BitLocker" (Handle-Error $_.Exception.Message)
}
# 11. Análisis de Configuración de Red
try {
$networkConfig = Get-NetIPConfiguration | Select-Object InterfaceAlias, IPv4Address, IPv4DefaultGateway
$htmlContent += Add-HtmlContent "Configuración de Red" (ConvertTo-HtmlTable $networkConfig)
} catch {
$htmlContent += Add-HtmlContent "Configuración de Red" (Handle-Error $_.Exception.Message)
}
# 12. Comprobación de Servicios Críticos
try {
$criticalServices = @('Windefend', 'WinHttpAutoProxySvc', 'Dhcp', 'Dnscache', 'mpssvc')
$serviceStatus = Get-Service $criticalServices | Select-Object Name, Status
$htmlContent += Add-HtmlContent "Estado de Servicios Críticos" (ConvertTo-HtmlTable $serviceStatus)
} catch {
$htmlContent += Add-HtmlContent "Estado de Servicios Críticos" (Handle-Error $_.Exception.Message)
}
# Finalizar el contenido HTML
$htmlContent += @"
</body>
</html>
"@
# Guardar el informe HTML
$htmlContent | Out-File -FilePath $output_file -Encoding UTF8
# Abrir el informe en el navegador predeterminado
Start-Process $output_file