diff --git a/PowerHuntShares.psm1 b/PowerHuntShares.psm1 index 7678699..d902f30 100644 --- a/PowerHuntShares.psm1 +++ b/PowerHuntShares.psm1 @@ -4,7 +4,7 @@ #-------------------------------------- # Author: Scott Sutherland, 2024 NetSPI # License: 3-clause BSD -# Version: v1.176 +# Version: v1.178 # References: This script includes custom code and code taken and modified from the open source projects PowerView, Invoke-Ping, and Invoke-Parrell. function Invoke-HuntSMBShares { @@ -1152,78 +1152,7 @@ function Invoke-HuntSMBShares Write-Output " [*][$Time] - Identified $SubnetsCount subnets hosting shares configured with excessive privileges." $SubnetSummary | Export-Csv -NoTypeInformation "$OutputDirectory\$TargetDomain-Shares-Inventory-Common-Subnets.csv" $SubnetFile = "$TargetDomain-Shares-Inventory-Common-Subnets.csv" - - # Create HTML table for report - - # Setup HTML begin - Write-Verbose "[+] Creating html top." - $HTMLSTART = @" - -"@ - - # Get list of columns - $MyCsvColumns = ("Computers","Shares","ExploitableACEs","WriteACEs","ReadACEs","ACEs","Site","Created","Desc","Subnet") - - # Print columns creation - $HTMLTableHeadStart= "" - $MyCsvColumns | - ForEach-Object { - - # Add column - $HTMLTableColumn = "$HTMLTableColumn" - } - $HTMLTableColumn = "$HTMLTableHeadStart$HTMLTableColumn" - - # Create table rows - Write-Verbose "[+] Creating html table rows." - $HTMLTableRow = $SubnetSummary | - ForEach-Object { - - # Create a value contain row data - $CurrentRow = $_ - $PrintRow = "" - $MyCsvColumns | - ForEach-Object{ - - try{ - $GetValue = $CurrentRow | Select-Object $_ -ExpandProperty $_ -ErrorAction SilentlyContinue - $ColumnIndex = $MyCsvColumns.IndexOf($_) + 1 - - # Set background color based on shifted conditions - $BackgroundColor = "" - - if ($ColumnIndex -eq 5 -and [int]$GetValue -gt 0) { # Originally for column 4 = write - $BackgroundColor = ' style="background-color:#FDFFd9;"' - } elseif ($ColumnIndex -eq 4 -and [int]$GetValue -gt 0) { # Originally for column 5 = read - $BackgroundColor = ' style="background-color:#FFCC98;"' - } elseif ($ColumnIndex -eq 3 -and [int]$GetValue -gt 0) { - $BackgroundColor = ' style="background-color:#FC6C84;"' # Originally for column 2=shares,6=aces,1=computers - } - - # Append the value with the background color - if($PrintRow -eq ""){ - $PrintRow = "$GetValue" - }else{ - $PrintRow = "$GetValue$PrintRow" - } - }catch{} - } - - # Return row - $HTMLTableHeadstart = "" - $HTMLTableHeadend = "" - "$HTMLTableHeadStart$PrintRow$HTMLTableHeadend" - } - - # Setup HTML end - Write-Verbose "[+] Creating html bottom." - $HTMLEND = @" - -
$_
-"@ - - # Return it - $SubnetSummaryHTML = "$HTMLSTART $HTMLTableColumn $HTMLTableRow $HTMLEND" + # ---------------------------------------------------------------------- # Calculate percentages @@ -2500,6 +2429,129 @@ function Invoke-HuntSMBShares $UniqueFileSystemRightsSeries = "[" + ($UniqueFileSystemRightsCounts -replace(" ",",")) + "]" $UniqueFileSystemRightsSeries = $UniqueFileSystemRightsSeries -replace(" ",",") + # ---------------------------------------------------------------------- + # Create network table + # ---------------------------------------------------------------------- + + # Create HTML table for report + + # Setup HTML begin + Write-Verbose "[+] Creating html top." + $HTMLSTART = @" + +"@ + + # Get list of columns + $MyCsvColumns = ("Computers","Shares","ExploitableACEs","WriteACEs","ReadACEs","ACEs","Site","Created","Desc","Subnet") + + # Print columns creation + $HTMLTableHeadStart= "" + $MyCsvColumns | + ForEach-Object { + + # Add column + $HTMLTableColumn = "$HTMLTableColumn" + } + $HTMLTableColumn = "$HTMLTableHeadStart$HTMLTableColumn" + + # Create table rows + Write-Verbose "[+] Creating html table rows." + $HTMLTableRow = $SubnetSummary | + ForEach-Object { + + # Create a value contain row data + $CurrentRow = $_ + $PrintRow = "" + $MyCsvColumns | + ForEach-Object{ + + try{ + $GetValue = $CurrentRow | Select-Object $_ -ExpandProperty $_ -ErrorAction SilentlyContinue + $ColumnIndex = $MyCsvColumns.IndexOf($_) + 1 + + # Set background color based on shifted conditions + $BackgroundColor = "" + + if ($ColumnIndex -eq 5 -and [int]$GetValue -gt 0) { # Originally for column 4 = write + $BackgroundColor = ' style="background-color:#FDFFd9;"' + } elseif ($ColumnIndex -eq 4 -and [int]$GetValue -gt 0) { # Originally for column 5 = read + $BackgroundColor = ' style="background-color:#FFCC98;"' + } elseif ($ColumnIndex -eq 3 -and [int]$GetValue -gt 0) { + $BackgroundColor = ' style="background-color:#FC6C84;"' # Originally for column 2=shares,6=aces,1=computers + } + + # Append the value with the background color + if($PrintRow -eq ""){ + $PrintRow = "$GetValue" + }else{ + $PrintRow = "$GetValue$PrintRow" + } + }catch{} + } + + # Return row + $HTMLTableHeadstart = "" + $HTMLTableHeadend = "" + "$HTMLTableHeadStart$PrintRow$HTMLTableHeadend" + } + + # Setup HTML end + Write-Verbose "[+] Creating html bottom." + $HTMLEND = @" + +
$_
+"@ + + # Return it + $SubnetSummaryHTML = "$HTMLSTART $HTMLTableColumn $HTMLTableRow $HTMLEND" + + # Create network risk table data + $SubnetTotalLow = 0 + $SubnetTotalMedium = 0 + $SubnetTotalHigh = 0 + $SubnetTotalCritical = 0 + $SubnetSummary | + foreach{ + + # Get subnet without trailing .0 + $SubnetIp = $_.Subnet + $SubnetIpBase = ($SubnetIp -split '\.')[0..2] -join '.' + + # Get Low count for subnet + $SubnetCountLow = $ExcessiveSharePrivsFinal | where IpAddress -like "$SubnetIpBase*" | where RiskLevel -eq 'Low' | measure | select count -ExpandProperty count + if($SubnetCountLow -gt 0){ + $SubnetTotalLow = $SubnetTotalLow + 1 + } + + # Get Medium count for subnet + $SubnetCountMedium = $ExcessiveSharePrivsFinal | where IpAddress -like "$SubnetIpBase*" | where RiskLevel -eq 'Medium' | measure | select count -ExpandProperty count + if( $SubnetCountMedium -gt 0){ + $SubnetTotalMedium = $SubnetTotalMedium + 1 + } + + # Get High count for subnet + $SubnetCountHigh = $ExcessiveSharePrivsFinal | where IpAddress -like "$SubnetIpBase*" | where RiskLevel -eq 'High' | measure | select count -ExpandProperty count + if($SubnetCountHigh -gt 0){ + $SubnetTotalHigh = $SubnetTotalHigh + 1 + } + + # Get Critical count for subnet + $SubnetCountCritical = $ExcessiveSharePrivsFinal | where IpAddress -like "$SubnetIpBase*" | where RiskLevel -eq 'Critical' | measure | select count -ExpandProperty count + if($SubnetCountCritical -gt 0){ + $SubnetTotalCritical = $SubnetTotalCritical + 1 + } + } + + # Construct the array with the desired pattern + $subnetArray = @( + $SubnetTotalLow, + $SubnetTotalMedium, + $SubnetTotalHigh, + $SubnetTotalCritical + ) + + # Convert the array to a string in the desired format + $subnetChartString = "[" + ($subnetArray -join ",") + "]" # ---------------------------------------------------------------------- # Create Identity Insights Summary Information @@ -7222,20 +7274,21 @@ This section provide a summary and list of the affected shares grouped by name. Clear - @@ -7305,7 +7358,51 @@ This section provides an overview of the affected networks. $SubnetsCount networ

+ +
+ + +
+
+
+ Affected Networks +
+
+ + $SubnetsCount   + +
+
+
+ + +
+
+
+
+
+
+
+
+ +
+ + +
+
Loading...
+ Export   | + Clear +
+ + + + + $SubnetSummaryHTML +