Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathias R. Jessen IISResetMe

  • Booking.com
  • Netherlands
View GitHub Profile
View Get-ADCertificateAuthority.ps1
$ConfigurationDN = $([ADSI]"LDAP://RootDSE").ConfigurationNamingContext;
$SearchRoot = "LDAP://CN=Enrollment Services,CN=Public Key Services,CN=Services,$ConfigurationDN"
$SearchFilter = "(objectCategory=pkiEnrollmentService)"
foreach($CAEnrollService in (New-Object adsiSearcher([ADSI]$SearchRoot,$SearchFilter)).FindAll()){
$serviceProperties = [ordered]@{}
foreach($propName in 'Name CN DnsHostName'.Split()){
$serviceProperties[$propName] = $CAEnrollService.Properties[$propName] |Select -First 1
}
View Get-PSRStaticInvocationHistory.ps1
Get-PSReadLineOption |Get-Content -LiteralPath { $_.HistorySavePath } |ForEach-Object {
if($_.EndsWith('`')){
$last += "{0}`r`n" -f $_.Remove($_.Length - 1)
}else{
"${last}${_}"
$last = $null
}
} |Where-Object {$_ -like '*::*'} |ForEach-Object {
# parse history entry as powershell script
View half_a_record_typer.ps1
using namespace System.Reflection
using namespace System.Reflection.Emit
using namespace System.Runtime.CompilerServices
# We'll attempt to construct a subset of the functionality of:
# public record TestRecord(int M1, string M2);
#
# Namely, we'll generate:
# - property getters (`get_M1()`, `get_M2()`),
# - a public constructor (`TestRecord(int, int);`),
View MeasureCallstackPenalty.ps1
function target {
param($Caller = $((Get-PSCallStack)[0].Command))
"'$Caller' called!"
}
function volunteerID {
target -Caller $MyInvocation.MyCommand
}
@IISResetMe
IISResetMe / Find-VulnerableSchemas.ps1
Last active Jun 7, 2022
Find-VulnerableSchemas.ps1
View Find-VulnerableSchemas.ps1
# Dictionary to hold superclass names
$superClass = @{}
# List to hold class names that inherit from container and are allowed to live under computer object
$vulnerableSchemas = [System.Collections.Generic.List[string]]::new()
# Resolve schema naming context
$schemaNC = (Get-ADRootDSE).schemaNamingContext
# Enumerate all class schemas
View flatten.ps1
using namespace System.Collections
function flatten
{
param(
[IDictionary]$Dictionary,
[string]$KeyDelimiter = ':'
)
$newDict = @{}
View stackoverflow-font-hack.css
body *:not(code) { font-family: arial !important; }
code {font-family: monospace !important;}
@IISResetMe
IISResetMe / Get-InvocationQuote.ps1
Created Dec 31, 2020
Quote repeatable command invocation from [InvocationInfo] for simple parameter types
View Get-InvocationQuote.ps1
function Get-InvocationQuote
{
param([System.Management.Automation.InvocationInfo]$Invocation)
$cmdText = $Invocation.InvocationName
foreach($param in $Invocation.BoundParameters.GetEnumerator()){
$name = $param.Key
$value = switch($param.Value){
{$_ -is [string]} {
# Quote and escape all string values as sigle-quoted literals
@IISResetMe
IISResetMe / fib.ps1
Created Dec 31, 2020
Nega-fibonacci with (non-optimal) caching
View fib.ps1
# Z-fibonacci (or nega-fibonacci, see https://en.wikipedia.org/wiki/Fibonacci_number#Sequence_properties):
# F(n-2) = F(n) - F(n-1)
$function:fib = & {
$cache = [System.Collections.Generic.Dictionary[int,bigint]]::new()
-1..1 |Foreach-Object {
$cache.Add($_, $_)
}
return {
@IISResetMe
IISResetMe / MagicNumber.class.ps1
Created Dec 19, 2020
ECMA-335 SpecialName-based operator overloading in PowerShell classes
View MagicNumber.class.ps1
class MagicNumber
{
hidden [int] $_value
MagicNumber([int]$value)
{
$this._value = $value
}
# ECMA-335 I.10.3.2