33 File: PowerUpSQL.ps1
44 Author: Scott Sutherland (@_nullbind), NetSPI - 2023
55 Major Contributors: Antti Rantasaari and Eric Gruber
6- Version: 1.126
6+ Version: 1.128
77 Description: PowerUpSQL is a PowerShell toolkit for attacking SQL Server.
88 License: BSD 3-Clause
99 Required Dependencies: PowerShell v.2
@@ -12260,21 +12260,25 @@ Function Get-SQLTriggerDml
1226012260 $Query = " use [$DbName];
1226112261 SELECT '$ComputerName' as [ComputerName],
1226212262 '$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],
1226612267 [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"
1227812282
1227912283 # Execute Query
1228012284 $TblDmlTriggersTemp = Get-SQLQuery -Instance $Instance -Query $Query -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
@@ -27123,6 +27127,21 @@ Function Invoke-SQLDumpInfo
2712327127 $Results | Export-Csv -NoTypeInformation $OutPutPath
2712427128 }
2712527129
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+
2712627145 # Getting Custom XP Stored Procedures
2712727146 Write-Verbose -Message "$Instance - Getting custom extended stored procedures..."
2712827147 $Results = Get-SQLStoredProcedureXP -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
@@ -27207,6 +27226,20 @@ Function Invoke-SQLDumpInfo
2720727226 $Results | Export-Csv -NoTypeInformation $OutPutPath
2720827227 }
2720927228
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+
2721027243 # Getting Triggers DDL
2721127244 Write-Verbose -Message "$Instance - Getting DDL triggers..."
2721227245 $Results = Get-SQLTriggerDdl -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
@@ -27221,6 +27254,20 @@ Function Invoke-SQLDumpInfo
2722127254 $Results | Export-Csv -NoTypeInformation $OutPutPath
2722227255 }
2722327256
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+
2722427271 # Getting Version Information
2722527272 Write-Verbose -Message "$Instance - Getting server version information..."
2722627273 $Results = Get-SQLServerInfo -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
@@ -27263,8 +27310,8 @@ Function Invoke-SQLDumpInfo
2726327310 $Results | Export-Csv -NoTypeInformation $OutPutPath
2726427311 }
2726527312
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..."
2726827315 $Results = Get-SQLAgentJob -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
2726927316 if($xml)
2727027317 {
@@ -27277,6 +27324,20 @@ Function Invoke-SQLDumpInfo
2727727324 $Results | Export-Csv -NoTypeInformation $OutPutPath
2727827325 }
2727927326
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+
2728027341 # Getting OLE DB provder information
2728127342 Write-Verbose -Message "$Instance - Getting OLE DB provder information..."
2728227343 $Results = Get-SQLOleDbProvder -Instance $Instance -Username $Username -Password $Password -Credential $Credential -SuppressVerbose
0 commit comments