static int Main(string[] args) { if (args.Length != 4) { Console.WriteLine("<Target PID>, <Assembly>, <Method>, <Source PID>"); return(-1); } else { //Console.WriteLine(args[0]); //Console.WriteLine(args[1]); //Console.WriteLine(args[2]); //Console.WriteLine(args[3]); int TargetPID = int.Parse(args[0]); string Assembly = args[1]; string Method = args[2]; int SourcePID = int.Parse(args[3]); Process p = Process.GetProcessById(TargetPID); RegistryKey key = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("APE", RegistryKeyPermissionCheck.Default, RegistryOptions.Volatile); key.SetValue(SourcePID + "_Attach_Status", "In_Process"); int result = (int)Needle.Inject(p, SourcePID, Assembly, Method); key.SetValue(SourcePID + "_Attach_Status", "Success"); return(result); } }
public string Inject(string SpawnTo, byte[] Shellcode) { this.SpawnTo = SpawnTo; var pi = Sacrifice(out IntPtr readPipe); var needle = new Needle(pi); needle.Inject(Shellcode); return(ReadFromPipe(pi, readPipe)); }
private void OnHandlersChanged(object sender, NotifyCollectionChangedEventArgs e) { Handlers.Aggregate(out _handleAsyncAggregated, out _loadFileAsyncAggregated, NoHandlerAsync); foreach (var newItem in e.NewItems) { if (newItem is null) { continue; } _logger.LogInformation(LogMessages.Registering, newItem.GetType()); Needle.Inject(newItem, Parent.Parent, Parent); } }
public string Inject(string SpawnTo, string FakeArgs, byte[] Shellcode) { this.Command = SpawnTo; this.FakeArgs = FakeArgs; var pi = Sacrifice(out IntPtr readPipe); var mole = new Mole(pi, this.RealArgs); mole.SpoofArgs(); var needle = new Needle(pi); needle.Inject(Shellcode); return(ReadFromPipe(pi, readPipe)); }
/// <inheritdoc /> public async Task LoadFileAsync(string oppyPath, string diskPath, Func <Task> next) { var notExist = !File.Exists(diskPath); if (notExist) { if (_scripts.TryGetValue(oppyPath, out var script)) { var toRemove = new List <string>(); if (Path.GetExtension(diskPath) == ".csx") { foreach (var kvp in _scripts) { if (kvp.Value == script) { toRemove.Add(kvp.Key); } } } else { toRemove.Add(oppyPath); } foreach (var s in toRemove) { _scripts.TryRemove(s, out _); } } await next(); return; } if (Path.GetExtension(diskPath) != ".csx") { var toAdd = new List <(string, HandlerScript)>(); foreach (var script in _scripts.Values) { if (script.DiskPathMatches(diskPath)) { toAdd.Add((oppyPath, script)); } } foreach (var val in toAdd) { _scripts.AddOrUpdate(val.Item1, val.Item2, (_, __) => val.Item2); } await next(); return; } try { var result = await CSharpScript.EvaluateAsync(await File.ReadAllTextAsync(diskPath), ScriptOptions .Default.WithAllowUnsafe(true).WithImports(_imports.Concat(AdditionalCsxImports)).WithReferences( AppDomain.CurrentDomain.GetAssemblies() .Where(x => !x.IsDynamic && !string.IsNullOrWhiteSpace(x.Location)))); if (result is HandlerScript handlerScript) { // do nothing more } else if (result is ValueTuple <IHandler, PathMatchingMode> handlerTuple1) { Needle.Inject(handlerTuple1.Item1, Listener, Host); handlerScript = new HandlerScript(handlerTuple1.Item1.HandleAsync, handlerTuple1.Item2); } else if (result is ValueTuple <PathMatchingMode, IHandler> handlerTuple2) { Needle.Inject(handlerTuple2.Item2, Listener, Host); handlerScript = new HandlerScript(handlerTuple2.Item2.HandleAsync, handlerTuple2.Item1); } else if (result is IHandler handler) { Needle.Inject(handler, Listener, Host); handlerScript = new HandlerScript(handler.HandleAsync, PathMatchingMode.Default); } else if (result is NoMixinEncapsulation noMixinHandler) { Host.Content.Handlers.Insert(0, noMixinHandler.Handler); return; } else { // not a valid script. don't await next for security reasons return; } handlerScript.ScriptDiskInfo = new FileInfo(diskPath); handlerScript.AddAllMatches(_scripts, Host); } catch (Exception e) { Logger?.LogError(LogMessages.ScriptEvalError, oppyPath, e); // not a valid script. don't await next for security reasons } }