예제 #1
0
        private void RealMain()
        {
            var serverProviderTcp = new BinaryServerFormatterSinkProvider();

            serverProviderTcp.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            var clientProviderTcp = new BinaryClientFormatterSinkProvider();
            var propertiesTcp     = new System.Collections.Hashtable();

            propertiesTcp["port"] = 9001;

            var tcpChannel = new TcpChannel(propertiesTcp, clientProviderTcp, serverProviderTcp);

            ChannelServices.RegisterChannel(tcpChannel, false);

            var serverProviderHttp = new SoapServerFormatterSinkProvider();

            serverProviderHttp.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            var clientProviderHttp = new SoapClientFormatterSinkProvider();
            var propertiesHttp     = new System.Collections.Hashtable();

            propertiesHttp["port"] = 9002;

            var httpChannel = new HttpChannel(propertiesHttp, clientProviderHttp, serverProviderHttp);

            ChannelServices.RegisterChannel(httpChannel, false);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyMarshalByRefClass), "GetObject", WellKnownObjectMode.SingleCall);

            var eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "app_server_wait_for_all_request_done_" + Port.ToString());

            CreatePidFile();
            eventWaitHandle.WaitOne(TimeSpan.FromMinutes(5));
        }
예제 #2
0
        // This display is the Server end.
        public void SetDestination(int ListeningPort)
        {
            // We chain xml-rpc -> soap so that we can support both XML-RPC and SOAP
            IServerChannelSinkProvider xml_rpc = new XmlRpcServerFormatterSinkProvider(null, null);
            IServerChannelSinkProvider soap    = new SoapServerFormatterSinkProvider();

            xml_rpc.Next = soap;

            IDictionary props = new Hashtable();

            props["ref"]  = "http";
            props["port"] = ListeningPort;
            HttpChannel channel = new HttpChannel(props, null, xml_rpc);

            ChannelServices.RegisterChannel(channel, false);

            // Not sure how this works if we re-configure and register when OperatingMode changes
            // There might be other ways to do the same thing and allow for de-registration
            RemotingConfiguration.Configure(null, false);

            // Counterintuitive, but when set to FALSE it reports errors across XML-RPC. Keep it this way to simplify debugging.
            RemotingConfiguration.CustomErrorsEnabled(false);

            // Can't figure out how to register at "http://serverip:port/". Must use "http://serverip:port/DreamBeam"
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(XmlRpcServer),
                                                               "DreamBeam", WellKnownObjectMode.Singleton);
        }
예제 #3
0
        /// <summary>
        /// TCP채널을 만들어 FTP서버를 작동시킴
        /// </summary>
        ///

        private void EstablishRemote()
        {
            SoapServerFormatterSinkProvider   soap   = new SoapServerFormatterSinkProvider();
            BinaryServerFormatterSinkProvider binary = new BinaryServerFormatterSinkProvider();

            soap.TypeFilterLevel   = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            binary.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            soap.Next = binary;

            Hashtable table = new Hashtable();

            table.Add("port", 8081);

            TcpChannel channel = new TcpChannel(table, null, soap);

            FTPServer.Logger = Logger;

            ChannelServices.RegisterChannel(channel, false);
            RemotingConfiguration.ApplicationName = "FTPServerAPP";
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(FTPServer), "ftpserver.svr", WellKnownObjectMode.Singleton);

            try
            {
                Logger.Text += Environment.NewLine + "***** FTP서버가 가동중입니다... *****" + Environment.NewLine;
            }
            catch (InvalidOperationException)
            {
            }
        }
예제 #4
0
    public static void Main()
    {
        try
        {
            IDictionary myDictionaryProperty = new Hashtable();
            myDictionaryProperty.Add("port", 8082);
// <Snippet4>
            IServerChannelSinkProvider myCustomProvider = new MyServerProvider();
            IServerChannelSinkProvider mySoapProvider   =
                new SoapServerFormatterSinkProvider();
            myCustomProvider.Next = mySoapProvider;
            // Set the Binary provider as the next 'IServerChannelSinkProvider' in the
            // sink chain.
            mySoapProvider.Next = new BinaryServerFormatterSinkProvider();
// </Snippet4>
            TcpChannel myTcpChannel =
                new TcpChannel(myDictionaryProperty, null, myCustomProvider);

            ChannelServices.RegisterChannel(myTcpChannel);

            RemotingConfiguration.ApplicationName = "HelloServiceApplication";

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(HelloService),
                                                               "MyUri", WellKnownObjectMode.Singleton);
            Console.WriteLine("Press enter to stop this process.");
            Console.ReadLine();
        }
        catch (Exception ex)
        {
            Console.WriteLine("The following exception is raised at server side: " + ex.Message);
        }
    }
예제 #5
0
파일: Form1.cs 프로젝트: O2SHEN/Silly
        private IJobServer GetIJobServer()
        {
            //
            // Register a channel.
            #region programmatically configured
            #region using tcp channel
            //BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            //BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            //serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            //Hashtable props = new Hashtable();
            //props["port"] = 0;      //First available port

            //TcpChannel tcpChan = new TcpChannel(props, clientProv, serverProv);
            //ChannelServices.RegisterChannel(tcpChan, false);
            #endregion

            #region using http channel
            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();
            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            Hashtable props = new Hashtable();
            props["port"] = 0;      //First available port

            HttpChannel tcpChan = new HttpChannel(props, clientProv, serverProv);
            ChannelServices.RegisterChannel(tcpChan, false);
            #endregion
            #endregion

            return((IJobServer)Activator.GetObject(typeof(IJobServer), "http://127.0.0.1:1234/JobURI"));
        }
        /// <summary>
        /// Register both types of channels - They throw a RemotingException
        /// if something doesn't work.
        /// We have to do a full registration of these channels because the client
        /// registers an ISponsor interface with the remote objects, meaning that the
        /// remote servers must be able to communicate back to the client.
        /// </summary>
        public void RegisterChannels()
        {
            IDictionary props = new Hashtable();

            props["timeout"] = DISTRIBUTED_TIMEOUT;
            props["port"]    = 0;               // Let .NET choose an available port
            try
            {
                BinaryServerFormatterSinkProvider prov = new BinaryServerFormatterSinkProvider();
                prov.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                TcpChannel Channel = new TcpChannel(props, null, prov);
                ChannelServices.RegisterChannel(Channel, false);
            }
            catch
            {
                m_TcpRegistered = false;
            }
            m_TcpRegistered = true;

            try
            {
                SoapServerFormatterSinkProvider prov = new SoapServerFormatterSinkProvider();
                prov.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                HttpChannel Channel = new HttpChannel(props, null, prov);
                ChannelServices.RegisterChannel(Channel, false);
            }
            catch
            {
                m_HttpRegistered = false;
            }
            m_HttpRegistered = true;
        }
예제 #7
0
    public static void Main()
    {
        IDictionary prop = new Hashtable();

        prop.Add("port", 8082);

        IServerChannelSinkProvider myServerFormatterProvider = new SoapServerFormatterSinkProvider();
        IServerChannelSinkProvider myServerLoggingProvider   =
            new MyServerProcessingLogServerChannelSinkProviderData();

        myServerLoggingProvider.Next = myServerFormatterProvider;

        IClientChannelSinkProvider myClientFormatterProvider = new SoapClientFormatterSinkProvider();
        IClientChannelSinkProvider myClientLoggingProvider   =
            new MyServerProcessingLogClientChannelSinkProviderData();

        myClientLoggingProvider.Next = myClientFormatterProvider;

        TcpChannel channel = new TcpChannel(prop, myClientLoggingProvider, myServerLoggingProvider);

        ChannelServices.RegisterChannel(channel);

        RemotingConfiguration.ApplicationName = "HelloServiceApplication";

        RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyHelloService),
                                                           "MyUri", WellKnownObjectMode.SingleCall);
        Console.WriteLine("Press enter to stop this process.");
        Console.ReadLine();
    }
예제 #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("id machine Ex: http://localhost:12345");
            String id = "http://localhost:12345";

            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();
            IDictionary props = new Hashtable();

            props["port"] = 12345;
            HttpChannel ch = new HttpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(ch, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ServerClass.Server), "RemoteServer.soap", WellKnownObjectMode.Singleton);


            IManager manager = (IManager)Activator.GetObject(typeof(IManager), "http://localhost:1234/RemoteManager.soap");

            manager.Register(id + "/RemoteServer.soap");

            Console.WriteLine("Server start");
            Console.ReadLine();

            manager.UnRegister(id + "/RemoteServer.soap");
        }
예제 #9
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Starting server...");

            // Configure the formatters for the channel
            BinaryServerFormatterSinkProvider formatterBin = new BinaryServerFormatterSinkProvider();

            formatterBin.TypeFilterLevel = TypeFilterLevel.Full;

            SoapServerFormatterSinkProvider formatterSoap = new SoapServerFormatterSinkProvider();

            formatterSoap.TypeFilterLevel = TypeFilterLevel.Low;

            formatterBin.Next = formatterSoap;

            // Register the channels
            IDictionary dict = new Hashtable();

            dict.Add("port", "1234");

            TcpChannel channel = new TcpChannel(dict, null, formatterBin);

            ChannelServices.RegisterChannel(channel);

            // Register the wellknown service
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(ServerImpl),
                "MyServer.rem",
                WellKnownObjectMode.Singleton);

            // Server configured properly
            System.Console.WriteLine("Server configured, waiting for requests!");
            System.Console.ReadLine();
        }
예제 #10
0
        static void Main(string[] args)
        {
            TMParser parser = new TMParser();

            if (!parser.Parse(args))
            {
                return;
            }

            var serverProv = new SoapServerFormatterSinkProvider {
                TypeFilterLevel = TypeFilterLevel.Full
            };

            var clientProv = new SoapClientFormatterSinkProvider();

            IDictionary props = new Hashtable();

            props["port"] = Int32.Parse(parser["p"]);

            var channel = new HttpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(channel, false);

            RemotingConfiguration.RegisterWellKnownServiceType
                (Type.GetType("MyTM.MyTM")                              // full type name
                , "TM.soap"                                             // URI
                , System.Runtime.Remoting.WellKnownObjectMode.Singleton // instancing mode
                );

            while (true)
            {
                Thread.Sleep(2000);
                TwoPhaseCommit.PrintMessage();
            }
        }
예제 #11
0
        /// <summary>
        /// —оздает провайдер дл¤ приемников, отвечающих за форматирование сообщений
        /// </summary>
        /// <returns>ѕровайдер дл¤ приемников, отвечающих за форматирование сообщений</returns>
        protected override IServerFormatterSinkProvider CreateFormatterSinkProvider()
        {
            SoapServerFormatterSinkProvider sinkProvider = new SoapServerFormatterSinkProvider();

            sinkProvider.TypeFilterLevel = TypeFilterLevel.Full;

            return(sinkProvider);
        }
예제 #12
0
파일: Server.cs 프로젝트: mono/gert
	static int Main ()
	{
		SoapServerFormatterSinkProvider serverFormatter = new SoapServerFormatterSinkProvider ();
		serverFormatter.TypeFilterLevel = TypeFilterLevel.Full;

		Hashtable ht = new Hashtable ();
		ht ["name"] = "hydraplus";
		ht ["port"] = 8081;
		ht ["authorizedGroup"] = "everyone";

		HttpChannel channel = new HttpChannel (ht, null, serverFormatter);
#if NET_2_0
		ChannelServices.RegisterChannel (channel, false);
#else
		ChannelServices.RegisterChannel (channel);
#endif

		WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry (
			typeof (ServerTalk), "hydraplus.soap",
			WellKnownObjectMode.Singleton);
		RemotingConfiguration.RegisterWellKnownServiceType (entry);

		ServerTalk.NewUser = new delUserInfo (NewClient);
		ServerTalk.DelUser = new delRemoveUser (RemoveClient);
		ServerTalk.ClientToHost = new delCommsInfo (ClientToHost);

		clientConnected = new AutoResetEvent (false);
		clientDisconnected = new AutoResetEvent (false);

		// wait for client to connect
		if (!clientConnected.WaitOne (20000, false)) {
			ReportFailure ("No client connected in time.");
			return 1;
		}

		// wait for message to arrive
		while (true) {
			Thread.Sleep (50);
			if (ServerTalk.ClientToServerQueue.Count > 0) {
				CommsInfo info = (CommsInfo) ServerTalk.ClientToServerQueue.Dequeue ();
				ClientToHost (info);
				break;
			}
		}

		// send message to client
		ServerTalk.RaiseHostToClient (client.Id, "txt", receivedMsg);

		// wait for client to disconnect
		if (clientConnected.WaitOne (2000, false)) {
			ReportFailure ("Client did not disconnect in time.");
			return 2;
		}

		return 0;
	}
예제 #13
0
        /// <summary>
        /// It gets the available connection
        /// </summary>
        private bool GetConnection()
        {
            bool connected = true;

            SoapServerFormatterSinkProvider   soap   = new SoapServerFormatterSinkProvider();
            BinaryServerFormatterSinkProvider binary = new BinaryServerFormatterSinkProvider();

            soap.TypeFilterLevel   = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            binary.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            soap.Next = binary;

            Hashtable table = new Hashtable();

            table.Add("port", "0");

            TcpChannel channel = new TcpChannel(table, null, soap);

            ChannelServices.RegisterChannel(channel, false);

            try
            {
                Server = (IFTPServer)Activator.GetObject(typeof(IFTPServer), string.Format("tcp://{0}:{1}/FTPServerAPP/ftpserver.svr", ServerIPValue.Text, ServerPortValue.Text));
            }
            catch (Exception ex)
            {
                connected = false;
                EventLogger.Logger(ex, "Client - GetConnection");
            }

            if (Server == null)
            {
                connected = false;
                ChannelServices.UnregisterChannel(channel);
                MessageBox.Show("Cannot Connect to the Server", "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(connected);
            }

            try
            {
                PostedData handler = new PostedData();
                handler.RefreshList += new EventHandler(handler_RefreshList);

                Server.PostedData += new PostedDataHandler(handler.Server_PostData);
                Server.Update     += new UpdateHandler(handler.Server_Update);

                Server.Connect(MachineInfo.GetJustIP());
            }
            catch (Exception ex)
            {
                connected = false;
                ChannelServices.UnregisterChannel(channel);
                MessageBox.Show(ex.Message, "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(connected);
        }
예제 #14
0
        static void Main(string[] args)
        {
            // Insert .NET Remoting code.
            // Register a listening channel.
            #region programmatically configured
            #region using tcp channel
            //Hashtable props = new Hashtable();
            //props["port"] = 1234;

            ////Set up for remoting events properly
            //BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            //serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            //TcpChannel oJobChannel = new TcpChannel(props, null, serverProv);


            ////HttpChannel oJobChannel = new HttpChannel(1234);
            //ChannelServices.RegisterChannel(oJobChannel, false);
            //// Register a well−known type.
            //RemotingConfiguration.RegisterWellKnownServiceType(
            //typeof(JobServerImpl),
            //"JobURI",
            //WellKnownObjectMode.Singleton);
            #endregion

            #region using http channel
            Hashtable props = new Hashtable();
            props["port"] = 1234;

            //Set up for remoting events properly
            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            HttpChannel oJobChannel = new HttpChannel(props, null, serverProv);


            //HttpChannel oJobChannel = new HttpChannel(1234);
            ChannelServices.RegisterChannel(oJobChannel, false);
            // Register a well−known type.
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(JobServerImpl),
                "JobURI",
                WellKnownObjectMode.Singleton);
            #endregion
            #endregion

            #region config file configured
            //RemotingConfiguration.Configure("Host.exe.config");
            #endregion

            // Keep running until told to quit.
            System.Console.WriteLine("Press Enter to exit");
            // Wait for user to press the Enter key.
            System.Console.ReadLine();
        }
예제 #15
0
        public static void SetupPort(int port)
        {
            var serverFormatter = new SoapServerFormatterSinkProvider {
                TypeFilterLevel = TypeFilterLevel.Full
            };

            var dictionary = new ListDictionary {
                { "port", port }
            };

            ChannelServices.RegisterChannel(new HttpChannel(dictionary, null, serverFormatter), false);
        }
예제 #16
0
파일: MyTM.cs 프로젝트: vlung/Citicenter
        static void Main(string[] args)
        {
            TMParser parser = new TMParser();

            if (!parser.Parse(args))
            {
                return;
            }

            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = TypeFilterLevel.Full;

            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();

            IDictionary props = new Hashtable();

            props["port"] = Int32.Parse(parser["p"]);

            HttpChannel channel = new HttpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(channel, false);

            RemotingConfiguration.RegisterWellKnownServiceType
                (Type.GetType("MyTM.MyTM")                                      // full type name
                , "TM.soap"                                                     // URI
                , System.Runtime.Remoting.WellKnownObjectMode.Singleton         // instancing mode
                );

            // activate the object
            string[] urls = channel.GetUrlsForUri("TM.soap");
            if (1 != urls.Length)
            {
                throw new InvalidOperationException();
            }

            MyTM transactionManager = (MyTM)System.Activator.GetObject(typeof(TP.TM), urls[0]);

            if (null == transactionManager)
            {
                throw new InvalidProgramException();
            }

            // Do recovery every 30 seconds to recommit/reabort unacknowledged transactions
            // as well as doing garbage collection on the outstanding transaction file
            while (true)
            {
                Console.WriteLine("Recovery will run in 30 seconds...");
                System.Threading.Thread.Sleep(30000);
                transactionManager.recovery();
            }
        }
예제 #17
0
        static void Main(string[] args)
        {
            /* Uncomment out the Setting Channel Properties region for page 15 of the chapter.
             * Then comment out the TcpChannels region
             * */



            #region Setting Channel Properties
            IDictionary properties = new Hashtable();
            properties["name"]     = "TCP Channel with a SOAP Formatter";
            properties["priority"] = "20";
            properties["port"]     = "8086";
            SoapServerFormatterSinkProvider sinkProvider =
                new SoapServerFormatterSinkProvider();
            TcpServerChannel tcpChannel =
                new TcpServerChannel(properties, sinkProvider);
            ShowChannelProperties(tcpChannel);
            #endregion

            #region TcpChannels

            //	TcpServerChannel tcpChannel = new TcpServerChannel(8086);
            //	ShowChannelProperties(tcpChannel);
            #endregion

            #region HttpChannel
            HttpServerChannel httpChannel = new HttpServerChannel(8085);
            ShowChannelProperties(httpChannel);
            #endregion

            #region RegisterChannels

            ChannelServices.RegisterChannel(tcpChannel);
            ChannelServices.RegisterChannel(httpChannel);

            #endregion


            /*
             * HttpServerChannel channel =
             *      (HttpServerChannel)ChannelServices.GetChannel("http");
             * channel.StopListening(null);
             */
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(Hello),
                "Hi",
                WellKnownObjectMode.SingleCall);

            System.Console.WriteLine("hit to exit");
            System.Console.ReadLine();
        }
예제 #18
0
        public void StartRPCServer()
        {
            var serv = new SoapServerFormatterSinkProvider {
                TypeFilterLevel = TypeFilterLevel.Full
            };
            var channel = new HttpServerChannel("server_remotezeus", 9254, serv);

            ChannelServices.RegisterChannel(channel, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteZeus), "RemoteZeus",
                                                               WellKnownObjectMode.SingleCall);

            RemoteZeus.ZeusWin = this;
        }
예제 #19
0
        protected override IChannel CreateChannel()
        {
            IDictionary prop = new Hashtable();

            prop["name"] = ServiceName;
            prop["port"] = Port;

            SoapClientFormatterSinkProvider clientProvider = new SoapClientFormatterSinkProvider();
            SoapServerFormatterSinkProvider serverProvider = new SoapServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            return(new TcpChannel(prop, clientProvider, serverProvider));
        }
예제 #20
0
        static void Main(string[] args)
        {
            // Run on localhost, port 1234
            String serverAddress = "http://localhost:1234/VulnerableEndpoint.rem";
            //String serverAddress = "http://localhost:8080/VulnerableEndpoint.rem"; // to proxy them in Burp - redirecting it to localhost:1234 with "Support invisible proxying"


            // * The following code could not be used to secure the client application by setting the typeFilterLevel to Low:

            IDictionary props = new Hashtable();
            SoapClientFormatterSinkProvider clientProvider = new SoapClientFormatterSinkProvider();
            SoapServerFormatterSinkProvider serverProvider = new SoapServerFormatterSinkProvider()
            {
                TypeFilterLevel = TypeFilterLevel.Low // This is where we can exploit it without knowing anything about the application or having an 0day!
            };

            props["name"]            = "ClientChannel";
            props["portName"]        = Guid.NewGuid().ToString();
            props["typeFilterLevel"] = "Low";
            props["port"]            = 0;

            HttpChannel clientChannel = new HttpChannel(props, clientProvider, serverProvider);

            // Register the channel.
            ChannelServices.RegisterChannel(clientChannel, false);

            RemotingConfiguration.RegisterWellKnownClientType(new WellKnownClientTypeEntry(typeof(RemoteObject1), serverAddress));

            //

            RemoteObject1 obj1 = (RemoteObject1)Activator.GetObject(typeof(RemoteObject1), serverAddress);

            try
            {
                Console.WriteLine("Calling GetCount - received: {0}", obj1.GetCount());

                Console.WriteLine("Calling EchoMe - Received: {0}", obj1.EchoMe("This is my text for echo!"));

                Console.WriteLine("Calling GetCount - received: {0}", obj1.GetCount());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            /* Wait for the user prompt: */

            Console.WriteLine("Press ENTER to exit the client.");
            Console.ReadLine();
            Console.WriteLine("The client is exiting.");
        }
예제 #21
0
        }     //GetOptions()

        private static IServerChannelSinkProvider GetProviderChain()
        {
            IServerChannelSinkProvider      chain        = new System.Runtime.Remoting.MetadataServices.SdlChannelSinkProvider();
            IServerChannelSinkProvider      sink         = chain;
            SoapServerFormatterSinkProvider soapProvider = new SoapServerFormatterSinkProvider();

            soapProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            sink.Next = soapProvider;
            sink      = sink.Next;
            BinaryServerFormatterSinkProvider binaryProvider = new BinaryServerFormatterSinkProvider();

            binaryProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            sink.Next = binaryProvider;
            return(chain);
        }
예제 #22
0
    public static void Main()
    {
        // <Snippet1>
        IDictionary prop = new Hashtable();

        prop["port"] = 9000;

        IClientChannelSinkProvider clientChain = new BinaryClientFormatterSinkProvider();

        IServerChannelSinkProvider serverChain = new SoapServerFormatterSinkProvider();

        serverChain.Next = new BinaryServerFormatterSinkProvider();

        ChannelServices.RegisterChannel(new HttpChannel(prop, clientChain, serverChain));
        // </Snippet1>
    }
예제 #23
0
파일: server.cs 프로젝트: mono/gert
	static void Main ()
	{
		SoapServerFormatterSinkProvider sfsp = new SoapServerFormatterSinkProvider ();
		sfsp.TypeFilterLevel = TypeFilterLevel.Full;
		HttpServerChannel channel = new HttpServerChannel ("Serv", 8080, sfsp);
#if NET_2_0
		ChannelServices.RegisterChannel (channel, false);
#else
		ChannelServices.RegisterChannel (channel);
#endif

		ServerImpl impl = new ServerImpl ();
		RemotingServices.Marshal (impl, "Server.rem");
		channel.StartListening (null);
		Console.ReadLine ();
		channel.StopListening (null);
	}
        public TestResultGrp RunTestSoap()
        {
            foreach (IChannel channel in ChannelServices.RegisteredChannels)
            {
                ChannelServices.UnregisterChannel(channel);
            }
            SoapServerFormatterSinkProvider svr  = new SoapServerFormatterSinkProvider();
            SoapClientFormatterSinkProvider clnt = new SoapClientFormatterSinkProvider();
            HttpChannel httpChannel = new HttpChannel();
            TcpChannel  tcpChannel  = new TcpChannel(null, clnt, svr);

            ChannelServices.RegisterChannel(httpChannel);
            ChannelServices.RegisterChannel(tcpChannel);

            TestResultGrp trg = RunTests();

            return(trg);
        }
예제 #25
0
    // This method should only peform the following operations:
    // - Setting up Remoting
    // - Obtaining the session
    // - Exporting the session
    //
    // If you make other calls especially NXOpen calls that may involve the UI
    // (such as ListingWindow).  This may put NX in state of an infinite loop.
    // Calls to the LogFile API are acceptable though.
    public static void Run()
    {
        DoLog("In NXOpenRemotingService.Main - getting session\n");
        theSession   = Session.GetSession();
        theUFSession = UFSession.GetUFSession();
        try
        {
            DoLog("Starting NX Service\n");

            LifetimeServices.LeaseTime = System.TimeSpan.FromDays(10000);

            SoapServerFormatterSinkProvider provider = new SoapServerFormatterSinkProvider();
            provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            // Create the IDictionary to set the port on the channel instance.

            IDictionary props = new Hashtable();
            props["port"] = port;

            // Create a new http channel with the given provider and properties
            ChannelServices.RegisterChannel(new HttpChannel(props, null, provider), false);

            DoLog("\n\n");
            DoLog("Exporting Session object");
            RemotingServices.Marshal(theSession, "NXOpenSession");

            DoLog("Exporting UFSession Object");
            RemotingServices.Marshal(theUFSession, "UFSession");


            DoLog("NX Service started on port " + port + "\n");
        }
        catch (Exception e)
        {
            DoLog(e.ToString());
        }
        while (!isUnloaded)
        {
            Thread.Sleep(1000);
        }

        DoLog("\n\nSERVICE ENDED!!!\n\n");
        serviceEnded = true;
    }
예제 #26
0
        /// <summary>
        /// http服务器
        /// </summary>
        /// <param name="port">端口</param>
        /// <param name="classname">类名</param>
        /// <param name="classtype">类类型</param>
        /// <param name="mode">single表示为每个对象使用同一个实例,否则为每个对象提供单独的实例</param>
        /// <returns>执行信息</returns>
        private string httpserverstart()
        {
            try
            {
                StringBuilder strinfo = new StringBuilder();

                System.Collections.IDictionary dict = new System.Collections.Hashtable();//一个 IDictionary 集合,为客户端和服务器信道要使用的配置属性指定值
                if (!string.IsNullOrEmpty(m_sChannelName))
                {
                    dict["name"] = m_sChannelName;
                }
                dict["port"] = m_iPort;
                //dict["authenticationMode"] = "IdentifyCallers";
                SoapServerFormatterSinkProvider bsf = new SoapServerFormatterSinkProvider();//为服务器SOAP格式化接受器提供实现
                //BinaryClientFormatterSinkProvider bcf = new BinaryClientFormatterSinkProvider();//为客服端二进制格式化接受器提供实现
                bsf.TypeFilterLevel = TypeFilterLevel.Full;
                m_ServerChannel     = new HttpServerChannel(dict, bsf);//提供使用 Http 协议传输消息的信道实现
                //Hcl.IsSecured = true;//设置当前信道为安全
                //m_ServerChannel.WantsToListen = true;//挂钩到外部针听端口
                LifetimeServices.LeaseTime = TimeSpan.Zero;
                ChannelServices.RegisterChannel(m_ServerChannel, false);//向信道服务注册信道。

                strinfo.AppendLine("当前信道的名称: " + m_ServerChannel.ChannelName.ToString());
                strinfo.AppendLine("当前信道的优先级: " + m_ServerChannel.ChannelPriority.ToString());

                RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;

                // Hcl.ChannelScheme = "http";//要挂钩到监听的类型
                //m_ServerChannel.StartListening(null);//监听
                ChannelDataStore data = (ChannelDataStore)((HttpServerChannel)m_ServerChannel).ChannelData;

                foreach (string strurl in data.ChannelUris)
                {
                    strinfo.AppendLine("当前信道所映射到的信道 URI: " + strurl);
                }

                // strinfo.AppendLine(string.Format("当前信道安全与否 {0}", Hcl.IsSecured));
                return(strinfo.ToString());
            }
            catch (Exception ex)
            {
                return(ex.Message.ToString());
            }
        }
        static void Main(string[] args)
        {
            /* Safe way of creating the channel without using SoapServerFormatterSinkProvider */
            //HttpServerChannel serverChannel = new HttpServerChannel(1234);
            /* Alternatively we could use this to create the server channel: */
            //HttpChannel serverChannel = new HttpChannel(1234);

            /* Instead if above, we want to create a vulnerable channel like this:  */
            /* start */

            SoapServerFormatterSinkProvider soapServerFormatterSinkProvider = new SoapServerFormatterSinkProvider()
            {
                TypeFilterLevel = TypeFilterLevel.Full // This is where we can exploit it without knowing anything about the application or having an 0day! Could be TypeFilterLevel.Low
            };

            IDictionary hashtables = new Hashtable();

            hashtables["port"]      = 1234;
            hashtables["proxyName"] = null;
            hashtables["name"]      = "Test Remoting Services";

            /* Creating the channel using SoapServerFormatterSinkProvider */
            HttpChannel serverChannel = new HttpChannel(hashtables, null, soapServerFormatterSinkProvider);

            /* Alternatively we could use this to create the server channel: */
            //HttpServerChannel serverChannel = new HttpServerChannel(hashtables, soapServerFormatterSinkProvider);

            /* end */

            /* the rest is shared between them all. */

            /* Register the server channel: */
            ChannelServices.RegisterChannel(serverChannel, false);

            /* Expose an object for remote calls: */
            /* This could also use WellKnownObjectMode.SingleCall instead of WellKnownObjectMode.Singleton */
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject1), "VulnerableEndpoint.rem", WellKnownObjectMode.Singleton);

            /* Wait for the user prompt: */
            Console.WriteLine("Press ENTER to exit the server.");
            Console.ReadLine();
            Console.WriteLine("The server is exiting.");
        }
예제 #28
0
        public static Peer NewPeer(string port, string uri)
        {
            #region CreateServer
            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            #endregion

            #region CreateClient
            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();
            #endregion

            #region CreateChannel
            IDictionary props = new Hashtable();
            props["port"] = port;

            /*
             *****Code for add multichannels******
             *
             *
             * IChannel ch = null;
             * switch (pc.ConnectionType)
             * {
             *  case "http":
             *      ch = new HttpChannel(props, clientProv, serverProv);
             *      break;
             *  case "tcp":
             *      ch = new TcpChannel(props, clientProv, serverProv);
             *      break;
             * }
             */

            IChannel ch = new HttpChannel(props, clientProv, serverProv);
            ChannelServices.RegisterChannel(ch);
            #endregion

            //Registers an object Type on the service end as a well-known type
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(Peer), "RemotePeer.soap", WellKnownObjectMode.Singleton);

            //Creates a proxy for a well-known object
            return((Peer)Activator.GetObject(typeof(Peer), uri));
        }
예제 #29
0
        /// <summary>
        /// Constructor for the HTTP on Soap Formatter server
        /// </summary>
        /// <param name="portNumber">TCP port number that this server is listening on</param>
        public HTTPSoapServer(int portNumber)
        {
            try
            {
                IDictionary formatterProps = new Hashtable();
                formatterProps["includeVersions"] = false;
                formatterProps["strictBinding"]   = false;

                SoapServerFormatterSinkProvider ftProvider = new SoapServerFormatterSinkProvider(formatterProps, null);
                //SoapServerFormatterSinkProvider ftProvider = new SoapServerFormatterSinkProvider();
                ftProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                ftProvider.Next = new System.Runtime.Remoting.MetadataServices.SdlChannelSinkProvider();
                m_Channel       = new HttpServerChannel(null, portNumber, ftProvider);
                EventLogMonitor.WriteToEventLogInfo("HTTPServerChannel, port:" + portNumber.ToString() + "..created", (int)Error.DataPorter_Servers);
            }
            catch (Exception ex)
            {
                EventLogMonitor.WriteToEventLogError("HTTPServerChannel not started, exception:" + ex.Message, (int)Error.DataPorter_Servers);
            }
        }
예제 #30
0
        public void Expose(Uri uri)
        {
            this.VerifyRemoteType();

            var properties = new Hashtable()
            {
                { "port", uri.Port }, { "name", "channel_" + uri.Port }
            };

            //TODO:设置windows权限
            if (uri.Scheme.Equals("tcp"))
            {
                var provider = new BinaryServerFormatterSinkProvider()
                {
                    TypeFilterLevel = TypeFilterLevel.Full
                };
                ChannelServices.RegisterChannel(new TcpChannel(properties, null, provider), false);
            }
            else if (uri.Scheme.Equals("http"))
            {
                var provider = new SoapServerFormatterSinkProvider()
                {
                    TypeFilterLevel = TypeFilterLevel.Full
                };
                ChannelServices.RegisterChannel(new HttpChannel(properties, null, provider), false);
            }
            else
            {
                throw new InvalidOperationException("不支持该通道:" + uri);
            }

            this.SetRemotingConfiguration();
            //facade无状态,使用singleton减少对象创建消耗
            //TODO:SAO+连接池对比singleton的高并发下连接创建性能?
            RemotingConfiguration.RegisterWellKnownServiceType(this.RemoteType
                                                               , uri.LocalPath.TrimStart('/')
                                                               , WellKnownObjectMode.Singleton);

            this._log.InfoFormat("将服务节点通过.Net Remoting暴露在地址{0},类型为{1}", uri, this.RemoteType);
        }
 public static void Main()
 {
     try
     {
         IDictionary myDictionaryProperty = new Hashtable();
         myDictionaryProperty.Add("port", 8082);
         IServerChannelSinkProvider mySoapProvider =
             new SoapServerFormatterSinkProvider();
         TcpChannel myTcpChannel =
             new TcpChannel(myDictionaryProperty, null, mySoapProvider);
         ChannelServices.RegisterChannel(myTcpChannel, false);
         RemotingConfiguration.ApplicationName = "HelloServiceApplication";
         RemotingConfiguration.RegisterWellKnownServiceType(typeof(HelloService),
                                                            "MyUri", WellKnownObjectMode.Singleton);
         Console.WriteLine("Press enter to stop this process.");
         Console.ReadLine();
     }
     catch (Exception ex)
     {
         Console.WriteLine("The following exception is raised at server side" + ex.Message);
     }
 }
예제 #32
0
        // Registers a new Remoting httpChannel utilizing SOAP formatter for serialization
        private void RegisterChannel()
        {
            Console.WriteLine("[Remoting Server]: Registering httpChannel");

            try
            {
                // Set the TypeFilterLevel to Full since callbacks require additional security requirements
                SoapServerFormatterSinkProvider serverFormatter = new SoapServerFormatterSinkProvider();
                serverFormatter.TypeFilterLevel = TypeFilterLevel.Full;

                // We have to change the name since we can't have two channels with the same name.
                Hashtable ht = new Hashtable();
                ht["name"] = "ServerChannel";
                ht["port"] = 9000;

                // Now create and register our custom HttpChannel
                HttpChannel channel = new HttpChannel(ht, null, serverFormatter);
                ChannelServices.RegisterChannel(channel, false);

                // Register a 'Well Known Object' type in Singleton mode
                string identifier        = "RUETalk";
                WellKnownObjectMode mode = WellKnownObjectMode.Singleton;

                // Register our Object model (RemotingComms)
                WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry(typeof(RemotingComms), identifier, mode);
                RemotingConfiguration.RegisterWellKnownServiceType(entry);
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("Prefix already in use."))
                {
                    Console.WriteLine("[Remoting Server ERROR]: Message - " + e.Message);
                }
                else
                {
                    Console.WriteLine("[Remoting Server]: httpChannel Registered");
                }
            }
        }