Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*SOURCE: http://www.ubers.org/Thread-Tutorial-Secure-Socket-Protocol
- Hello, in this thread I will explain and show you how to use SSP. Credits to DragonHunter for creating SSP.
- note: This example is written in C# but since SSP is a library you can also use it in VB.NET.
- What is SSP?
- SSP is a lightweight network protocol, for scalabilty and for creating a massive server with less memory usage.
- Why use this?
- Well for a few simple reasons
- 1. All It's traffic is encrypted with custom algorithm called UnsafeXor, and is using a dynamic key and not something like SSH which is having a static key once given
- 2. SSP is compressing the traffic to decrease network usage
- 3. SSP is using it's own cache system for decreasing the network usage at high ratio
- 4. All the bytes in the traffic are shuffled around in the data
- 5. It's fast and lightweight and scalable to handle a lot of traffic and connections and it's stable
- 6. All data is being hashed to be 100% sure it's being read correctly but also against man-in-the-middle attacks
- Feature List
- Code:
- Create a secured server/client the easy way
- Less memory in use with +10000 connections, ~20mb ram
- Reliable Asynchronous TCP Connection
- Upload/Download speed ~120MBps
- TCP Traffic is 100% encrypted and compressed at all time
- The data you're sending is not only encrypted and compressed it's also being shuffled to make even harder to decrypt
- To make SSP very lightweight for the network we created a Cache System it's so lightweight you're actually able to sent 50MB per second over WAN
- The client is able to connect through a Socks5 proxy
- VirtualConnection, Create a virtual connection inside the physical connection, you can create virtual connections, disconnect, send/receive data just like a normal connection but this kind of connection is more hidden and there is no need to make a second real SSP connection, it's also a very nice way to separate specific data
- All the data is getting hashed to be sure it's being received at the other side correctly and against man-in-the-middle attacks
- Use a private key so only people with this key can connect
- Tutorial
- Requirements
- - SSP library
- - Visual Basic or C# (I use C# in this tutorial)
- Download Link Here! or visit https://ssp.svn.codeplex.com/svn/
- Once you have got the library we are going to begin.
- Step 1 - The Server
- We will create a console application, name it whatever you want.
- After that you will need to add the library to your project. So right click on your project and select "Add Reference" Go to the "Browse" Tab and select the SSP library to the location you have it stored. Once you have done this it should look like this,
- http://i.imgur.com/mrQMCwx.png
- Now we have done all that we need to add our Imports
- Code:*/
- using System;
- using System.Collections.Generic;
- using System.Text;
- using SecureSocketProtocol.Server;
- using System.Diagnostics;
- using SecureSocketProtocol.Network;
- using System.Threading;
- using System.IO;
- using System.Security.Cryptography;
- using SecureSocketProtocol.misc;
- using SecureSocketProtocol.Network.Compressions;
- using SecureSocketProtocol.Interfaces;
- using SecureSocketProtocol;
- After We have added our Imports we are going to build our server constructor.
- Code:
- static void Main(string[] args)
- {
- Console.Title = "Secure Socket Protocol - Server";
- const int Port = 127; // We define 127 to Port
- SSPServer server = new SSPServer(Port, "0.0.0.0", NetworkProtocol.TCP | NetworkProtocol.ReliableUDP, null);
- server.onConnectionAccepted += onConnectionAccepted;
- Console.WriteLine("Listening on " + Port);
- Process.GetCurrentProcess().WaitForExit();
- }
- /*Yes you will get an error about onConnectionAccepted, don't worry about that. After you have added the code into Main() it should look like this.
- http://i.imgur.com/R8psdzc.png
- The next step is our onConnectionAccepted Event. What we do now is add this code(you will need to put this outside Main().
- Code:*/
- static void onConnectionAccepted(SSPClient client)
- {
- Console.WriteLine("Connection Accepted @" + client.RemoteIp);
- client.MultiThreadProcessing = false;
- ulong ReceivedData = 0;
- ulong TotalReceivedData = 0;
- NetworkProtocol proto = NetworkProtocol.TCP;
- ThreadPool.QueueUserWorkItem((object o) =>
- {
- SSPClient c = (SSPClient)o;
- while (c.Connected)
- {
- Thread.Sleep(1000);
- Console.WriteLine("[" + c.RemoteIp + "] " + ", Id:" + c.connection.ClientId.ToString().Substring(0, 7) + ", " + (ReceivedData / 1024) / 1024 + "MBps" +
- ", bytes: " + ReceivedData +
- ", total MB received:" + (TotalReceivedData / 1024) / 1024 +
- ", proto: " + proto +
- ", lost packets:" + c.connection.UdpPacketLossCount);
- ReceivedData = 0;
- }
- }, client);
- client.onReceiveData += (byte[] Data, PayloadReader pr, IClient c, NetworkProtocol Protocol) =>
- {
- ReceivedData += (ulong)Data.Length;
- TotalReceivedData += (ulong)Data.Length;
- proto = Protocol;
- };
- client.onVirtualConnectionAccepted += (VirtualConnection vConnection) =>
- {
- Console.WriteLine("Virtual Connection Accepted");
- vConnection.onReceiveData += (byte[] Data, PayloadReader pr, VirtualConnection vc) =>
- {
- ReceivedData += (ulong)Data.Length;
- TotalReceivedData += (ulong)Data.Length;
- vc.SendPacket(Data);
- };
- };
- }/*
- If you are confused and don't know where to put the code, look at the picture it should look like this.
- http://i.imgur.com/fD5UPnm.png
- We are done with the server now. It's almost time to switch to our client. But first! We need to right click on our solution select "Add" And then "New Project" Check the picture if you can't find it.
- http://i.imgur.com/GNAm9DN.png
- Step 2 - Client
- This will also be a console application, name it whatever you want.
- Remember when we had to add the library to the server? If not scroll back up, because we need to do the same for the client.
- Now after we have done that we will continue to the next.
- We need to add the imports for the client.
- Code:*/
- using System;
- using System.Collections.Generic;
- using System.Text;
- using SecureSocketProtocol.Client;
- using System.Diagnostics;
- using SecureSocketProtocol.Network;
- using System.Threading;
- using SecureSocketProtocol;
- using System.IO;
- using SecureSocketProtocol.misc;
- using SecureSocketProtocol.Interfaces;
- using SecureSocketProtocol.Network.Compressions;
- using SecureSocketProtocol.Network.Encryptions;
- /*After we have added the Imports, we need to add this code in the Main()
- Code:*/
- static void Main(string[] args)
- {
- Stopwatch RunTime = Stopwatch.StartNew();
- Console.Title = "Secure Socket Protocol - Client";
- SSPClient client = new SSPClient("127.0.0.1", 127, NetworkProtocol.TCP | NetworkProtocol.ReliableUDP, null);
- Console.WriteLine("Connected");
- }
- /*It should now look like this.
- http://i.imgur.com/LOQb8cy.png
- Then we need to add the Events. This will need to go inside the Main() so that means between Console.WriteLine("Connected");
- *CODE*
- bracket
- Code:*/
- client.onReceiveData += (byte[] Data, PayloadReader pr, IClient c, NetworkProtocol Protocol) =>
- {
- We wont be using this but this is how the onReceivedData should look like.
- };
- client.onConnectionClosed += (IClient c) =>
- {
- Console.Title = "Secure Socket Protocol - Client - Disconnected";
- };
- VirtualConnection vConnection = client.CreateVirtualConnection((byte[] Data, PayloadReader pr, VirtualConnection vc) =>
- {
- });
- /*Now we just need to finish the last step and that's a While (true).
- Code:*/
- while (true)
- {
- for (int i = 0; i < 10000000; i++)
- {
- client.SendPacket(BitConverter.GetBytes(i), NetworkProtocol.UDP, false, false, true);
- }
- Console.Title = "Secure Socket Protocol - Client - Runtime: " + RunTime.Elapsed.Hours.ToString("D2") + ":" + RunTime.Elapsed.Minutes.ToString("D2") + ":" + RunTime.Elapsed.Seconds.ToString("D2");
- }
- Process.GetCurrentProcess().WaitForExit();
- /*It should look like,
- http://i.imgur.com/Tfk3YJq.png
- That was the final step and you can either build or debug it, the result should look like this
- http://i.imgur.com/2kifYpj.png
- That should cover up the whole tutorial, it's really basic but I hope you understand now how SSP works and see it's also very secure.
- A quick note SSP2 is also released which is the MORE secure and better version of SSP so you might consider using that. It should not be hard to follow as you can read the library and see how it works. I hope you have enjoyed this tutorial and was informative, thanks. Glad
- EDIT; look at this DragonHunter sending 50MBps over WAN using a 1MBps network line.
- http://img853.imageshack.us/img853/2065/captureghc.png
- Read more: http://www.ubers.org/Thread-Tutorial-Secure-Socket-Protocol#ixzz3H2PX18M6*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement