3
3
File: PowerUpSQL.ps1
4
4
Author: Scott Sutherland (@_nullbind), NetSPI - 2023
5
5
Major Contributors: Antti Rantasaari and Eric Gruber
6
- Version: 1.126
6
+ Version: 1.128
7
7
Description: PowerUpSQL is a PowerShell toolkit for attacking SQL Server.
8
8
License: BSD 3-Clause
9
9
Required Dependencies: PowerShell v.2
@@ -12260,21 +12260,25 @@ Function Get-SQLTriggerDml
12260
12260
$Query = " use [$DbName];
12261
12261
SELECT '$ComputerName' as [ComputerName],
12262
12262
'$Instance' as [Instance],
12263
- '$DbName' as [DatabaseName],
12264
- name as [TriggerName],
12265
- object_id as [TriggerId],
12263
+ '$DbName' AS [DatabaseName],
12264
+ SCHEMA_NAME(o.schema_id) AS [SchemaName],
12265
+ t.name AS [TriggerName],
12266
+ t.object_id AS [TriggerId],
12266
12267
[TriggerType] = 'DATABASE',
12267
- type_desc as [ObjectType],
12268
- parent_class_desc as [ObjectClass],
12269
- OBJECT_DEFINITION(OBJECT_ID) as [TriggerDefinition],
12270
- create_date,
12271
- modify_date,
12272
- is_ms_shipped,
12273
- is_disabled,
12274
- is_not_for_replication,
12275
- is_instead_of_trigger
12276
- FROM [$DbName].[sys].[triggers] WHERE 1=1
12277
- $TriggerNameFilter"
12268
+ t.type_desc AS [ObjectType],
12269
+ t.parent_class_desc AS [ObjectClass],
12270
+ OBJECT_DEFINITION(t.object_id) AS [TriggerDefinition],
12271
+ t.create_date,
12272
+ t.modify_date,
12273
+ t.is_ms_shipped,
12274
+ t.is_disabled,
12275
+ t.is_not_for_replication,
12276
+ t.is_instead_of_trigger
12277
+ FROM
12278
+ [sys].[triggers] t
12279
+ INNER JOIN
12280
+ [sys].[objects] o ON t.parent_id = o.object_id
12281
+ WHERE 1=1 $TriggerNameFilter"
12278
12282
12279
12283
# Execute Query
12280
12284
$TblDmlTriggersTemp = Get-SQLQuery -Instance $Instance -Query $Query -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
@@ -27123,6 +27127,21 @@ Function Invoke-SQLDumpInfo
27123
27127
$Results | Export-Csv -NoTypeInformation $OutPutPath
27124
27128
}
27125
27129
27130
+
27131
+ # Getting Stored Procedures that use Global Temp Tables
27132
+ Write-Verbose -Message "$Instance - Getting stored procedures that use global temp tables..."
27133
+ $Results = Get-SQLStoredProcedure -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose | where ProcedureDefinition -like "*##*"
27134
+ if($xml)
27135
+ {
27136
+ $OutPutPath = "$OutFolder\$OutPutInstance"+'_Database_stored_procedure_globaltmptbl.xml'
27137
+ $Results | Export-Clixml $OutPutPath
27138
+ }
27139
+ else
27140
+ {
27141
+ $OutPutPath = "$OutFolder\$OutPutInstance"+'_Database_stored_procedure_globaltmptbl.csv'
27142
+ $Results | Export-Csv -NoTypeInformation $OutPutPath
27143
+ }
27144
+
27126
27145
# Getting Custom XP Stored Procedures
27127
27146
Write-Verbose -Message "$Instance - Getting custom extended stored procedures..."
27128
27147
$Results = Get-SQLStoredProcedureXP -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
@@ -27207,6 +27226,20 @@ Function Invoke-SQLDumpInfo
27207
27226
$Results | Export-Csv -NoTypeInformation $OutPutPath
27208
27227
}
27209
27228
27229
+ # Getting Triggers DML that use Global Temp Tables
27230
+ Write-Verbose -Message "$Instance - Getting DML triggers that use global temp tables..."
27231
+ $Results = Get-SQLTriggerDml -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose | where TriggerDefinition -like "*##*"
27232
+ if($xml)
27233
+ {
27234
+ $OutPutPath = "$OutFolder\$OutPutInstance"+'_Server_triggers_dml_globaltmptbl.xml'
27235
+ $Results | Export-Clixml $OutPutPath
27236
+ }
27237
+ else
27238
+ {
27239
+ $OutPutPath = "$OutFolder\$OutPutInstance"+'_Server_triggers_dml_globaltmptbl.csv'
27240
+ $Results | Export-Csv -NoTypeInformation $OutPutPath
27241
+ }
27242
+
27210
27243
# Getting Triggers DDL
27211
27244
Write-Verbose -Message "$Instance - Getting DDL triggers..."
27212
27245
$Results = Get-SQLTriggerDdl -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
@@ -27221,6 +27254,20 @@ Function Invoke-SQLDumpInfo
27221
27254
$Results | Export-Csv -NoTypeInformation $OutPutPath
27222
27255
}
27223
27256
27257
+ # Getting Triggers DDL that use Global Temp Tables
27258
+ Write-Verbose -Message "$Instance - Getting DDL triggers that use global temp tables..."
27259
+ $Results = Get-SQLTriggerDdl -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose | where TriggerDefinition -like "*##*"
27260
+ if($xml)
27261
+ {
27262
+ $OutPutPath = "$OutFolder\$OutPutInstance"+'_Server_triggers_ddl_globaltmptbl.xml'
27263
+ $Results | Export-Clixml $OutPutPath
27264
+ }
27265
+ else
27266
+ {
27267
+ $OutPutPath = "$OutFolder\$OutPutInstance"+'_Server_triggers_ddl_globaltmptbl.csv'
27268
+ $Results | Export-Csv -NoTypeInformation $OutPutPath
27269
+ }
27270
+
27224
27271
# Getting Version Information
27225
27272
Write-Verbose -Message "$Instance - Getting server version information..."
27226
27273
$Results = Get-SQLServerInfo -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
@@ -27263,8 +27310,8 @@ Function Invoke-SQLDumpInfo
27263
27310
$Results | Export-Csv -NoTypeInformation $OutPutPath
27264
27311
}
27265
27312
27266
- # Getting Agent Jobs Information
27267
- Write-Verbose -Message "$Instance - Getting Agent Jobs information ..."
27313
+ # Getting Agent Jobs
27314
+ Write-Verbose -Message "$Instance - Getting Agent Jobs..."
27268
27315
$Results = Get-SQLAgentJob -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
27269
27316
if($xml)
27270
27317
{
@@ -27277,6 +27324,20 @@ Function Invoke-SQLDumpInfo
27277
27324
$Results | Export-Csv -NoTypeInformation $OutPutPath
27278
27325
}
27279
27326
27327
+ # Getting Agent Jobs that use Global Temp Tables
27328
+ Write-Verbose -Message "$Instance - Getting Agent Jobs that use global temp tables..."
27329
+ $Results = Get-SQLAgentJob -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose -Keyword "##"
27330
+ if($xml)
27331
+ {
27332
+ $OutPutPath = "$OutFolder\$OutPutInstance"+'_Server_agent_job_globaltmptbl.xml'
27333
+ $Results | Export-Clixml $OutPutPath
27334
+ }
27335
+ else
27336
+ {
27337
+ $OutPutPath = "$OutFolder\$OutPutInstance"+'_Server_agent_jobs_globaltmptbl.csv'
27338
+ $Results | Export-Csv -NoTypeInformation $OutPutPath
27339
+ }
27340
+
27280
27341
# Getting OLE DB provder information
27281
27342
Write-Verbose -Message "$Instance - Getting OLE DB provder information..."
27282
27343
$Results = Get-SQLOleDbProvder -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
0 commit comments