Add files via upload

This commit is contained in:
apetro
2025-09-02 10:58:40 -05:00
committed by GitHub
parent bc71f59477
commit 4ecdffa513
11 changed files with 1944 additions and 0 deletions
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
+280
View File
@@ -0,0 +1,280 @@
param(
[string]$inputfile,
[string]$outputfile
)
#Path to DLL's for dumping
$wd = $(get-location).Path
$path = "$wd\Kerberos.NET.dll"
$path2 = "$wd\Microsoft.Extensions.Logging.Abstractions.dll"
$path3 = "$wd\System.Buffers.dll"
$null = [System.Reflection.Assembly]::LoadFrom($path2)
$tmp = [System.Reflection.Assembly]::LoadFrom($path)
$null = [System.Reflection.Assembly]::LoadFrom($path3)
Add-Type -AssemblyName "System.Collections"
#path to text file with ticket
#$p = "c:\users\Administrator\desktop\so.txt"
#$p = "C:\Users\Administrator\Desktop\klist-convertv2\pp05.txt"
$p = $inputfile
#path to the output cache file
$outpath = $outputfile
function convertDatestring($tmpstring){
$i = $tmpstring.indexof(':')
$tmptime = $($tmpstring.Substring($i + 2)).split('(')[0]
$da = get-date -Date $tmptime
$t = [int][double]($da.ToUniversalTime() - [datetime]'1970-01-01').TotalSeconds
return $t
}
function Convert-HexStringToBytes {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string] $HexString
)
$bytes = [byte[]]::new($HexString.Length / 2)
for ($i = 0; $i -lt $HexString.Length; $i += 2) {
$bytes[$i / 2] = [byte]::Parse($HexString.Substring($i, 2), [System.Globalization.NumberStyles]::HexNumber)
}
return $bytes
}
enum TicketFlags
{
# <summary>
# Reserved. Indicates the absense of flags.
# </summary>
None = -1
# <summary>
# Reserved for future extension.
# </summary>
Reserved = 1 -shl 31
# <summary>
# Tells the ticket-granting service that it can issue a new TGT—based on the
# presented TGT—with a different network address based on the presented TGT.
# </summary>
Forwardable = 1 -shl 30
# <summary>
# Indicates either that a TGT has been forwarded or that a ticket was issued from a forwarded TGT.
# </summary>
Forwarded = 1 -shl 29
# <summary>
# Tells the ticket-granting service that it can issue tickets with a network address that
# differs from the one in the TGT.
# </summary>
Proxiable = 1 -shl 28
# <summary>
# Indicates that the network address in the ticket is different from the one in the TGT
# used to obtain the ticket.
# </summary>
Proxy = 1 -shl 27
# <summary>
# Indicates the requested ticket may be post-dated for use in future.
# </summary>
#[Description("May Post-date")]
MayPostDate = 1 -shl 26
# <summary>
# Indicates the requested ticket is post-dated for use in the future.
# </summary>
#[Description("Post-dated")]
PostDated = 1 -shl 25
# <summary>
# This flag indicates that a ticket is invalid, and it must be validated by the KDC before use.
# Application servers must reject tickets which have this flag set.
# </summary>
Invalid = 1 -shl 24
# <summary>
# Used in combination with the End Time and Renew Till fields to cause tickets with long life
# spans to be renewed at the KDC periodically.
# </summary>
Renewable = 1 -shl 23
# <summary>
# Indicates that a ticket was issued using the authentication service (AS) exchange and
# not issued based on a TGT.
# </summary>
Initial = 1 -shl 22
# <summary>
# Indicates that the client was authenticated by the KDC before a ticket was issued.
# This flag usually indicates the presence of an authenticator in the ticket.
# It can also flag the presence of credentials taken from a smart card logon.
# </summary>
#[Description("Pre-Authenticated")]
PreAuthenticated = 1 -shl 21
# <summary>
# This flag was originally intended to indicate that hardware-supported authentication
# was used during pre-authentication. This flag is no longer recommended in the Kerberos
# V5 protocol. KDCs MUST NOT issue a ticket with this flag set. KDCs SHOULD NOT preserve
# this flag if it is set by another KDC.
# </summary>
#[Description("Hardware Authenticated")]
HardwareAuthentication = 1 -shl 20
# <summary>
# Application servers MUST ignore the TRANSITED-POLICY-CHECKED flag.
# </summary>
#[Description("Transit Policy-Checked")]
TransitPolicyChecked = 1 -shl 19
# <summary>
# The KDC MUST set the OK-AS-DELEGATE flag if the service account is trusted for delegation.
# </summary>
#[Description("Ok as Delegate")]
OkAsDelegate = 1 -shl 18
# <summary>
# Indicates the client supports FAST negotiation.
# </summary>
# [Description("Encrypted Pre-Authentication")]
EncryptedPreAuthentication = 1 -shl 16
# <summary>
# Indicates the ticket is anonymous.
# </summary>
Anonymous = 1 -shl 15
}
$fullfile = get-content $p
$totallines = $fullfile.Length
$ticketfilelines = $totallines - 14
$first = Get-Content -TotalCount 14 -path $p
$ticketfile = Get-Content -tail $ticketfilelines -path $p | ForEach-Object { $_.Substring(6) }
$servicename = $($first[0] -split ':')[1].Trim()
$username = $($first[2] -split ':')[1].Trim()
$realm = $($first[3] -split ':')[1].Trim()
$un = New-Object System.Collections.Generic.List[string]
$un.add($username)
$user = [Kerberos.NET.Entities.PrincipalName]::new([Kerberos.NET.Entities.PrincipalNameType]::NT_PRINCIPAL,$realm,$un)
$servname = New-Object System.Collections.Generic.List[string]
$servname.add($servicename)
$server = [Kerberos.NET.Entities.PrincipalName]::new([Kerberos.NET.Entities.PrincipalNameType]::NT_SRV_INST, $realm,$servname)
#$kerbkeytmp = [byte[]](0x7f,0x77,0x5c,0x86,0xf6,0x6e,0x6a,0x70,0xb2,0xc2,0xc6,0x29,0xe0,0x0d,0xa0,0xa7,0xf0,0xd6,0xb3,0x70,0x93,0xb5,0x44,0x6c,0xd8,0x80,0x77,0x08,0x35,0xbb,0xcc,0x68)
#$kerbkey = [System.ReadOnlyMemory[byte]]::new([byte[]](0x7f,0x77,0x5c,0x86,0xf6,0x6e,0x6a,0x70,0xb2,0xc2,0xc6,0x29,0xe0,0x0d,0xa0,0xa7,0xf0,0xd6,0xb3,0x70,0x93,0xb5,0x44,0x6c,0xd8,0x80,0x77,0x08,0x35,0xbb,0xcc,0x68))
$q = $first[8].IndexOf('-')
$kerbkeytmp = $($first[8].Substring($q +2)) -replace '[^0-9A-Fa-f]', ''
$kerbkeybytes = Convert-HexStringToBytes -HexString $kerbkeytmp
$kerbkey = [System.ReadOnlyMemory[byte]]::new([byte[]]($kerbkeybytes))
$encryptionType = [Kerberos.NET.Crypto.EncryptionType]::AES256_CTS_HMAC_SHA1_96
#$keyValuePair = new-object [System.Collections.Generic.KeyValuePair[EncryptionType, [System.ReadOnlyMemory[byte]]]
$keyValuePair = [System.Collections.Generic.KeyValuePair[Kerberos.NET.Crypto.EncryptionType, [System.ReadOnlyMemory[byte]]]]::new($encryptionType, $kerbkey)
$starttimetmp = convertDateString($first[9])
$authtimetmp = $starttime
$endtimetmp = convertDateString($first[10])
$renewtimetmp = ConvertDateString($first[11])
$epoch = [datetime]'1970-01-01T00:00:00Z'
$authtime = $epoch.AddSeconds($starttimetmp)
$starttime = $epoch.AddSeconds($starttimetmp)
$endtime = $epoch.AddSeconds($endtimetmp)
$renewtime = $epoch.AddSeconds($renewtimetmp)
$iskey = $false
#$tflags = [ticketflags]::Initial -bor [ticketflags]::Renewable -bor [ticketflags]::Forwardable -bor [ticketflags]::PreAuthenticated
#$tflagsline = $first[6]
#if ($tflagsline -match 'TicketFlags\s+:\s+\((0x[0-9a-fA-F]+)\)') {
# $tflags = [UInt32]::Parse($matches[1].Substring(2), 'HexNumber')
#}
#($test -split '[`(`)]')[1]
$tflagsline = $first[6]
$tflagshex = ($tflagsline -split '[()]')[1]
$tflags = [Convert]::ToUInt32($tflagshex, 16)
$tflags = [ticketflags]::Forwardable -bor [ticketflags]::Renewable -bor [ticketflags]::PreAuthenticated -bor [ticketflags]::OkAsDelegate
$krbinfo = [Kerberos.NET.Entities.KrbCredInfo]::new()
$krbenckey = [Kerberos.NET.Entities.KrbEncryptionKey]::new()
$krbenckey.EType = $encryptionType
$krbenckey.KeyValue = $kerbkey
$krbinfo.Key = $krbenckey
$krbinfo.SRealm = $realm
$krbinfo.AuthTime = $authtime
$krbinfo.EndTime = $endtime
$krbinfo.RenewTill = $renewtime
$krbinfo.Flags = $tflags
$krbinfo.PName = $user
$krbinfo.StartTime = $starttime
$tfile = $ticketfile -replace '[^0-9A-Fa-f]', ''
$hs = ''
$j = 0
$i = $ticketfilelines - 1
for($j; $j -lt $i; $j++) { $y = $tfile[$j]; $r = $y.substring(0,32); $hs += $r.Trim() }
#$hs += $tfile[$ticketfilelines - 1]
$tmp = $ticketfile[$ticketfilelines - 1]
$tmpl = $tmp.length
$hs += $($tmp.substring(0,$tmpl)) -replace '[^0-9A-Fa-f]', ''
$bbytes = Convert-HexStringToBytes -HexString $hs
$c = [System.ReadOnlyMemory[byte]]::new($bbytes)
$d = [Kerberos.NET.Entities.KrbTicket]::DecodeApplication($c)
$KRBCRED = [Kerberos.NET.Entities.KrbCred]::WrapTicket($d, $krbinfo)
$cpart = $krbcred.Validate()
$z = $KRBCRED.tickets[0]
$zinfo = $cpart.TicketInfo[0]
$zinfo.realm = $realm
$ticketcacheentry = [Kerberos.NET.TicketCacheEntry]::ConvertKrbCredToCacheEntry($cpart, $z, $zinfo)
$cache = [Kerberos.NET.Client.Krb5CredentialCache]::new()
$kdcClientOffset = [Kerberos.NET.Client.Krb5CredentialCacheTag]::KdcClientOffset
$cache.version = 4
$cache.DefaultPrincipalName = $user
$ttype = $cache.GetType()
$method = $ttype.GetMethod("Add", [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance)
$method.Invoke($cache,@($ticketcacheentry))
[System.IO.File]::WriteAllBytes($outpath, $cache.GetType().GetMethod("Serialize", [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Instance).Invoke($cache,@()))
+1456
View File
File diff suppressed because it is too large Load Diff
+31
View File
@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.34931.43
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "klist2", "klist2.vcxproj", "{3EFFA9E6-CB9A-442D-A124-C2D0A8A7FBF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3EFFA9E6-CB9A-442D-A124-C2D0A8A7FBF9}.Debug|x64.ActiveCfg = Debug|x64
{3EFFA9E6-CB9A-442D-A124-C2D0A8A7FBF9}.Debug|x64.Build.0 = Debug|x64
{3EFFA9E6-CB9A-442D-A124-C2D0A8A7FBF9}.Debug|x86.ActiveCfg = Debug|Win32
{3EFFA9E6-CB9A-442D-A124-C2D0A8A7FBF9}.Debug|x86.Build.0 = Debug|Win32
{3EFFA9E6-CB9A-442D-A124-C2D0A8A7FBF9}.Release|x64.ActiveCfg = Release|x64
{3EFFA9E6-CB9A-442D-A124-C2D0A8A7FBF9}.Release|x64.Build.0 = Release|x64
{3EFFA9E6-CB9A-442D-A124-C2D0A8A7FBF9}.Release|x86.ActiveCfg = Release|Win32
{3EFFA9E6-CB9A-442D-A124-C2D0A8A7FBF9}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {24DB0A17-A554-4F2D-B1DF-67D276782967}
EndGlobalSection
EndGlobal
+151
View File
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{3effa9e6-cb9a-442d-a124-c2d0a8a7fbf9}</ProjectGuid>
<RootNamespace>klist2</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Advapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Advapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Advapi32.lib;Secur32.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Advapi32.lib;Secur32.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="klist2.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="klist2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
Binary file not shown.