Skip to content

Instantly share code, notes, and snippets.

function Split-Number {
param([string]$value)
$index = 0
while($index -lt $value.Length - 12) {
$value.Substring($index++, 13)
}
}
filter Evaluate-String {
$_.ToCharArray() | % { [int]::Parse($_) } | % {$total = 1} {$total *= $_} {$total}
@idavis
idavis / gist:293022f2ebe30f726673
Created June 9, 2015 18:28
Replacing the private functionality of loaded module
$module = New-Module -Name "monkey" -ScriptBlock {
function Get-Stuff {
return GetStuffPrivate
}
function GetStuffPrivate {
5
}
Export-ModuleMember Get-Stuff
}
Import-Module $module # you can also just use $module = Get-Module "someName"
@idavis
idavis / Monkey.psd1
Last active August 29, 2015 14:22
Stealing Private Data
@{
# Script module or binary module file associated with this manifest.
RootModule = 'Monkey.psm1'
# Version number of this module.
ModuleVersion = '1.0'
# ID used to uniquely identify this module
GUID = '4d4390dc-a8ad-4bce-8d69-f53ccf8e4163'
@idavis
idavis / gist:c16f117c0f99eb20c49f
Created June 12, 2015 16:46
PowerShell Module Security

I was playing around with dynamic module creation and figured out how to monkey patch modules.

I then thought about how PowerShell is a Last-In-Wins language, and tried replacing private methods.

This led to the "what if" moment of pulling [secure data out of a loaded module][]. In this case, the username and password of a credential set.

This seems like a security issue to me, or am I being over sensitive?

internal class Program
{
private const int size = 500;
private const int iterations = 5000;
private static void Main( string[] args )
{
TimeSpan elapsed = TimeOriginal();
Console.WriteLine( elapsed );
#region License
//
// Author: Nate Kohari <nate@enkari.com>
// Copyright (c) 2007-2010, Enkari, Ltd.
//
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
// See the file LICENSE.txt for details.
//
#endregion
#if !NO_ASSEMBLY_SCANNING
src/Ninject/Activation/Blocks/ActivationBlock.cs | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Ninject/Activation/Blocks/ActivationBlock.cs b/src/Ninject/Activation/Blocks/ActivationBlock.cs
index b16b503..4b64376 100644
--- a/src/Ninject/Activation/Blocks/ActivationBlock.cs
+++ b/src/Ninject/Activation/Blocks/ActivationBlock.cs
@@ -68,10 +68,10 @@ namespace Ninject.Activation.Blocks
/// </summary>
/// <param name="request">The request.</param>
#region Using Directives
using System;
using System.ServiceProcess;
using YourCorp.Services;
using Ninject;
using Topshelf;
using Topshelf.Configuration;
using Topshelf.Configuration.Dsl;
if (bindings == null)
{
return false;
}
lock(_handleMissingBindingLockObject)
{
if (!CanResolve(request))
{
bindings.Map(binding => binding.IsImplicit = true);
public enum TestEnum
{
None =0,
One = 1,
Two = 2
}
var zero = Enum<TestEnum>.GetValue<int>( TestEnum.None );
var one = Enum<TestEnum>.GetValue<int>( TestEnum.One );
var two = Enum<TestEnum>.GetValue<int>( TestEnum.Two );
var nine = Enum<TestEnum>.GetValue<int>( TestEnum.One | TestEnum.Eight );