Skip to content

Commit a6770fb

Browse files
committed
chore: update CommonLib to 2.0.15
feat: add flag to skip computer age check feat: add powershell auto-generated output
1 parent 1cc8bfe commit a6770fb

File tree

7 files changed

+699
-8
lines changed

7 files changed

+699
-8
lines changed

Sharphound.csproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,23 @@
2323
</PackageReference>
2424
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
2525
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
26-
<PackageReference Include="SharpHoundCommon" Version="2.0.13" />
26+
<PackageReference Include="SharpHoundCommon" Version="2.0.15" />
2727
<PackageReference Include="SharpZipLib" Version="1.3.3" />
2828
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
2929
<PackageReference Include="System.Threading.Channels" Version="6.0.0" />
3030
<PackageReference Include="Utf8Json" Version="1.3.7" />
3131
</ItemGroup>
3232

3333
<ItemGroup>
34-
<!-- <Reference Include="SharpHoundCommonLib, Version=2.0.12.0, Culture=neutral, PublicKeyToken=null">-->
34+
<!-- <Reference Include="SharpHoundCommonLib, Version=2.0.13.0, Culture=neutral, PublicKeyToken=null">-->
3535
<!-- <HintPath>..\SharpHoundCommon\src\CommonLib\bin\Debug\net462\SharpHoundCommonLib.dll</HintPath>-->
3636
<!-- </Reference>-->
3737
<Reference Include="System.DirectoryServices" />
3838
<Reference Include="System.DirectoryServices.Protocols" />
3939
<Reference Include="System.IO.Compression" />
4040
</ItemGroup>
41+
<Target Name="PS1" AfterTargets="Build">
42+
<Message Text="Test" />
43+
<Exec Command="powershell -ep bypass -c &quot;. '$(ProjectDir)src\Powershell\Out-CompressedDLL.ps1';Out-CompressedDll -FilePath '$(TargetPath)' -TemplatePath '$(ProjectDir)src\\Powershell\Template.ps1' | Out-File -Encoding ASCII '$(TargetDir)$(TargetName).ps1'&quot;" />
44+
</Target>
4145
</Project>

src/Client/Flags.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class Flags
1515
public bool SecureLDAP { get; set; }
1616
public bool DisableKerberosSigning { get; set; }
1717
public bool SkipPortScan { get; set; }
18+
public bool SkipPasswordAgeCheck { get; set; }
1819
public bool ExcludeDomainControllers { get; set; }
1920
public bool NoRegistryLoggedOn { get; set; }
2021
public bool DumpComputerStatus { get; set; }

src/Options.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Options
1414
// Options that affect what is collected
1515
[Option('c', "collectionmethods", Default = new[] { "Default" },
1616
HelpText =
17-
"Collection Methods: Container, Group, LocalGroup, GPOLocalGroup, Session, LoggedOn, ObjectProps, ACL, ComputerOnly, Trusts, Default, RDP, DCOM, DCOnly")]
17+
"Collection Methods: Group, LocalGroup, LocalAdmin, RDP, DCOM, PSRemote, Session, Trusts, ACL, Container, ComputerOnly, GPOLocalGroup, LoggedOn, ObjectProps, SPNTargets, Default, DCOnly, All")]
1818
public IEnumerable<string> CollectionMethods { get; set; }
1919

2020
[Option('d', "domain", Default = null, HelpText = "Specify domain to enumerate")]
@@ -59,13 +59,13 @@ public class Options
5959

6060
[Option(HelpText = "Don't zip files", Default = false)]
6161
public bool NoZip { get; set; }
62+
63+
[Option(HelpText = "Password protects the zip with the specified password", Default = null)]
64+
public string ZipPassword { get; set; }
6265

6366
[Option(HelpText = "Adds a CSV tracking requests to computers", Default = false)]
6467
public bool TrackComputerCalls { get; set; }
6568

66-
[Option(HelpText = "Password protects the zip with the specified password", Default = null)]
67-
public string ZipPassword { get; set; }
68-
6969
[Option(HelpText = "Pretty print JSON", Default = false)]
7070
public bool PrettyPrint { get; set; }
7171

@@ -92,9 +92,12 @@ public class Options
9292
//Options that affect how enumeration is performed
9393
[Option(HelpText = "Skip checking if 445 is open", Default = false)]
9494
public bool SkipPortCheck { get; set; }
95-
95+
9696
[Option(HelpText = "Timeout for port checks in milliseconds", Default = 500)]
9797
public int PortCheckTimeout { get; set; }
98+
99+
[Option(HelpText = "Skip check for PwdLastSet when enumerating computers", Default = false)]
100+
public bool SkipPasswordCheck { get; set; }
98101

99102
[Option(HelpText = "Exclude domain controllers from session/localgroup enumeration (mostly for ATA/ATP)",
100103
Default = false)]

src/PowerShell/Out-CompressedDLL.ps1

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
function Out-CompressedDll
2+
{
3+
<#
4+
.SYNOPSIS
5+
6+
Creates the powershell in-memory version of SharpHound.
7+
Based entirely off Out-CompressedDll by Matthew Graeber (@mattifestation)
8+
Original script at https://github.com/PowerShellMafia/PowerSploit/blob/master/ScriptModification/Out-CompressedDll.ps1
9+
#>
10+
11+
[CmdletBinding()] Param (
12+
[Parameter(Mandatory = $True)]
13+
[String]
14+
$FilePath,
15+
16+
[Parameter(Mandatory = $True)]
17+
[String]
18+
$TemplatePath
19+
)
20+
21+
$Path = Resolve-Path $FilePath
22+
23+
if (! [IO.File]::Exists($Path))
24+
{
25+
Throw "$Path does not exist."
26+
}
27+
28+
$FileBytes = [System.IO.File]::ReadAllBytes($Path)
29+
30+
if (($FileBytes[0..1] | % {[Char]$_}) -join '' -cne 'MZ')
31+
{
32+
Throw "$Path is not a valid executable."
33+
}
34+
35+
$Length = $FileBytes.Length
36+
$CompressedStream = New-Object IO.MemoryStream
37+
$DeflateStream = New-Object IO.Compression.DeflateStream ($CompressedStream, [IO.Compression.CompressionMode]::Compress)
38+
$DeflateStream.Write($FileBytes, 0, $FileBytes.Length)
39+
$DeflateStream.Dispose()
40+
$CompressedFileBytes = $CompressedStream.ToArray()
41+
$CompressedStream.Dispose()
42+
$EncodedCompressedFile = [Convert]::ToBase64String($CompressedFileBytes)
43+
44+
Write-Verbose "Compression ratio: $(($EncodedCompressedFile.Length/$FileBytes.Length).ToString('#%'))"
45+
46+
$Output = @"
47+
`$EncodedCompressedFile = '$EncodedCompressedFile`'
48+
`$DeflatedStream = New-Object IO.Compression.DeflateStream([IO.MemoryStream][Convert]::FromBase64String(`$EncodedCompressedFile),[IO.Compression.CompressionMode]::Decompress)
49+
`$UncompressedFileBytes = New-Object Byte[]($Length)
50+
`$DeflatedStream.Read(`$UncompressedFileBytes, 0, $Length) | Out-Null
51+
`$Assembly = [Reflection.Assembly]::Load(`$UncompressedFileBytes)
52+
`$BindingFlags = [Reflection.BindingFlags] "Public,Static"
53+
`$a = @()
54+
`$Assembly.GetType("Costura.AssemblyLoader", `$false).GetMethod("Attach", `$BindingFlags).Invoke(`$Null, @())
55+
`$Assembly.GetType("Sharphound.Program").GetMethod("InvokeSharpHound").Invoke(`$Null, @(,`$passed))
56+
"@
57+
58+
Get-Content $TemplatePath | %{$_ -replace "#ENCODEDCONTENTHERE", $Output}
59+
}

0 commit comments

Comments
 (0)