diff --git a/PowerHuntShares.psm1 b/PowerHuntShares.psm1 index 0950c06..219170f 100644 --- a/PowerHuntShares.psm1 +++ b/PowerHuntShares.psm1 @@ -4,7 +4,7 @@ #-------------------------------------- # Author: Scott Sutherland, 2022 NetSPI # License: 3-clause BSD -# Version: v1.18 +# Version: v1.20 # dont use ping filter for 445, add custom user group option, and potentially identify groups that have large 20% of domain user members (make this configrable) # References: This script includes code taken and modified from the open source projects PowerView, Invoke-Ping, and Invoke-Parrell. function Invoke-HuntSMBShares @@ -1089,7 +1089,66 @@ function Invoke-HuntSMBShares $Time = Get-Date -UFormat "%m/%d/%Y %R" 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" + $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 = ("ComputerCount","ShareCount","HighRiskAclCount","WriteAclCount","ReadAclCount","AclCount","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 + if($PrintRow -eq ""){ + $PrintRow = "" + }else{ + $PrintRow = "$PrintRow" + } + }catch{} + } + + # Return row + $HTMLTableHeadstart = "" + $HTMLTableHeadend = "" + "$HTMLTableHeadStart$PrintRow$HTMLTableHeadend" + } + + # Setup HTML end + Write-Verbose "[+] Creating html bottom." + $HTMLEND = @" + +
$_
$GetValue$GetValue
+"@ + + # Return it + $SubnetSummaryHTML = "$HTMLSTART $HTMLTableColumn $HTMLTableRow $HTMLEND" + # ---------------------------------------------------------------------- # Calculate percentages @@ -2572,6 +2631,7 @@ $NewHtmlReport = @" + @@ -3476,6 +3536,22 @@ This section contains a list of the most common SMB share names. In some cases, + + + + +
+
+

Data Insights: Affecetd Subnets

+This section contains a list of subnets hosting computers with shares that are configured with accessibe privileges. +
+ +
+$SubnetSummaryHTML +
+ @@ -5639,6 +5715,87 @@ function Convert-DataTableToHtmlTable } } +# ------------------------------------------- +# Function: Convert-DataTableToHtmlReport +# ------------------------------------------- +function Convert-DataTableToHtmlReport +{ + <# + .SYNOPSIS + This function can be used to convert a data table or ps object into a generic html table. + .PARAMETER $DataTable + The datatable to input. + .EXAMPLE + $object = New-Object psobject + $Object | Add-Member Noteproperty Name "my name 1" + $Object | Add-Member Noteproperty Description "my description 1" + Convert-DataTableToHtmlReport -Verbose -DataTable $object + .NOTES + Author: Scott Sutherland (@_nullbind) + #> + param ( + [Parameter(Mandatory = $true, + HelpMessage = 'The datatable to input.')] + $DataTable + ) + + # Setup HTML begin + Write-Verbose "[+] Creating html top." + $HTMLSTART = @" + +"@ + + # Get list of columns + $MyCsvColumns = $DataTable | Get-Member | Where-Object MemberType -like "NoteProperty" | Select-Object Name -ExpandProperty Name + + # Print columns creation + $HTMLTableHeadStart= "" + $MyCsvColumns | + ForEach-Object { + + # Add column + $HTMLTableColumn = "$HTMLTableColumn" + } + $HTMLTableColumn = "$HTMLTableHeadStart$HTMLTableColumn" + + # Create table rows + Write-Verbose "[+] Creating html table rows." + $HTMLTableRow = $DataTable | + ForEach-Object { + + # Create a value contain row data + $CurrentRow = $_ + $PrintRow = "" + $MyCsvColumns | + ForEach-Object{ + + try{ + $GetValue = $CurrentRow | Select-Object $_ -ExpandProperty $_ -ErrorAction SilentlyContinue + if($PrintRow -eq ""){ + $PrintRow = "" + }else{ + $PrintRow = "$PrintRow" + } + }catch{} + } + + # Return row + $HTMLTableHeadstart = "" + $HTMLTableHeadend = "" + "$HTMLTableHeadStart$PrintRow$HTMLTableHeadend" + } + + # Setup HTML end + Write-Verbose "[+] Creating html bottom." + $HTMLEND = @" + +
$_
$GetValue$GetValue
+"@ + + # Return it + "$HTMLSTART $HTMLTableColumn $HTMLTableRow $HTMLEND" +} + # ------------------------------------------- # Function: Get-FolderGroupMd5 # -------------------------------------------