Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Thanks to http://www.atrevido.net/blog/2005/01/28/Inline+X86+ASM+In+C.aspx
- $code = @"
- namespace Danger {
- using System;
- using System.Reflection;
- public class Danger {
- public delegate uint SillyDelegate();
- static uint PlaceHolder1() { return 0; }
- public unsafe static uint WillRobinson(Byte[] code) {
- fixed (byte* startAddress = &code[0]) {
- Type delType = typeof(Delegate);
- FieldInfo _methodPtr = delType.GetField("_methodPtr", BindingFlags.NonPublic | BindingFlags.Instance);
- SillyDelegate del = new SillyDelegate(PlaceHolder1);
- _methodPtr.SetValue(del, (IntPtr) startAddress);
- return del();
- }
- }
- }
- }
- "@
- #NOP Sled
- $shellcode = "909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090"
- $test = Convert-HexStringToByteArray $shellcode
- #the function Convert-HexStringToByteArray comes from someone else...don't have the reference at the moment.
- $options = New-Object System.CodeDom.Compiler.CompilerParameters
- $options.CompilerOptions = "/unsafe"
- Add-Type -TypeDefinition $code -CompilerParameters $options
- [Danger.Danger]::WillRobinson($test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement