Advertisement
BaSs_HaXoR

SSP Tutorial: Secure Socket Protocol

Oct 24th, 2014
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.71 KB | None | 0 0
  1. /*SOURCE: http://www.ubers.org/Thread-Tutorial-Secure-Socket-Protocol
  2.  
  3.  
  4. Hello, in this thread I will explain and show you how to use SSP. Credits to DragonHunter for creating SSP.
  5. note: This example is written in C# but since SSP is a library you can also use it in VB.NET.
  6.  
  7. What is SSP?
  8. SSP is a lightweight network protocol, for scalabilty and for creating a massive server with less memory usage.
  9.  
  10. Why use this?
  11. Well for a few simple reasons
  12. 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
  13. 2. SSP is compressing the traffic to decrease network usage
  14. 3. SSP is using it's own cache system for decreasing the network usage at high ratio
  15. 4. All the bytes in the traffic are shuffled around in the data
  16. 5. It's fast and lightweight and scalable to handle a lot of traffic and connections and it's stable
  17. 6. All data is being hashed to be 100% sure it's being read correctly but also against man-in-the-middle attacks
  18.  
  19. Feature List
  20. Code:
  21. Create a secured server/client the easy way
  22. Less memory in use with +10000 connections, ~20mb ram
  23. Reliable Asynchronous TCP Connection
  24. Upload/Download speed ~120MBps
  25. TCP Traffic is 100% encrypted and compressed at all time
  26. The data you're sending is not only encrypted and compressed it's also being shuffled to make even harder to decrypt
  27. 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
  28. The client is able to connect through a Socks5 proxy
  29. 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
  30. 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
  31. Use a private key so only people with this key can connect
  32.  
  33. Tutorial
  34.  
  35. Requirements
  36.  
  37. - SSP library
  38. - Visual Basic or C# (I use C# in this tutorial)
  39.  
  40. Download Link Here! or visit https://ssp.svn.codeplex.com/svn/
  41.  
  42. Once you have got the library we are going to begin.
  43.  
  44. Step 1 - The Server
  45. We will create a console application, name it whatever you want.
  46. 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,
  47. http://i.imgur.com/mrQMCwx.png
  48.  
  49. Now we have done all that we need to add our Imports
  50. Code:*/
  51. using System;
  52. using System.Collections.Generic;
  53. using System.Text;
  54. using SecureSocketProtocol.Server;
  55. using System.Diagnostics;
  56. using SecureSocketProtocol.Network;
  57. using System.Threading;
  58. using System.IO;
  59. using System.Security.Cryptography;
  60. using SecureSocketProtocol.misc;
  61. using SecureSocketProtocol.Network.Compressions;
  62. using SecureSocketProtocol.Interfaces;
  63. using SecureSocketProtocol;
  64. After We have added our Imports we are going to build our server constructor.
  65. Code:
  66. static void Main(string[] args)
  67.         {
  68.            Console.Title = "Secure Socket Protocol - Server";
  69.             const int Port = 127; // We define 127 to Port
  70.             SSPServer server = new SSPServer(Port, "0.0.0.0", NetworkProtocol.TCP | NetworkProtocol.ReliableUDP, null);
  71.                                                                                  
  72.             server.onConnectionAccepted += onConnectionAccepted;
  73.             Console.WriteLine("Listening on " + Port);
  74.             Process.GetCurrentProcess().WaitForExit();
  75.         }
  76. /*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.
  77. http://i.imgur.com/R8psdzc.png
  78.  
  79. The next step is our onConnectionAccepted Event. What we do now is add this code(you will need to put this outside Main().
  80. Code:*/
  81. static void onConnectionAccepted(SSPClient client)
  82.         {
  83.             Console.WriteLine("Connection Accepted @" + client.RemoteIp);
  84.             client.MultiThreadProcessing = false;
  85.  
  86.             ulong ReceivedData = 0;
  87.             ulong TotalReceivedData = 0;
  88.  
  89.             NetworkProtocol proto = NetworkProtocol.TCP;
  90.             ThreadPool.QueueUserWorkItem((object o) =>
  91.                 {
  92.                     SSPClient c = (SSPClient)o;
  93.                     while (c.Connected)
  94.                     {
  95.                         Thread.Sleep(1000);
  96.                         Console.WriteLine("[" + c.RemoteIp + "] " + ", Id:" + c.connection.ClientId.ToString().Substring(0, 7) + ", " + (ReceivedData / 1024) / 1024 + "MBps" +
  97.                                       ", bytes: " + ReceivedData +
  98.                                       ", total MB received:" + (TotalReceivedData / 1024) / 1024 +
  99.                                       ", proto: " + proto +
  100.                                       ", lost packets:" + c.connection.UdpPacketLossCount);
  101.                         ReceivedData = 0;
  102.                     }
  103.                 }, client);
  104.             client.onReceiveData += (byte[] Data, PayloadReader pr, IClient c, NetworkProtocol Protocol) =>
  105.                 {
  106.                     ReceivedData += (ulong)Data.Length;
  107.                     TotalReceivedData += (ulong)Data.Length;
  108.                     proto = Protocol;
  109.                 };
  110.  
  111.             client.onVirtualConnectionAccepted += (VirtualConnection vConnection) =>
  112.             {
  113.                 Console.WriteLine("Virtual Connection Accepted");
  114.                 vConnection.onReceiveData += (byte[] Data, PayloadReader pr, VirtualConnection vc) =>
  115.                     {
  116.                         ReceivedData += (ulong)Data.Length;
  117.                         TotalReceivedData += (ulong)Data.Length;
  118.                         vc.SendPacket(Data);
  119.                     };
  120.             };
  121.              
  122.         }/*
  123. If you are confused and don't know where to put the code, look at the picture it should look like this.
  124. http://i.imgur.com/fD5UPnm.png
  125. 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.
  126. http://i.imgur.com/GNAm9DN.png
  127. Step 2 - Client
  128. This will also be a console application, name it whatever you want.
  129. 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.
  130. Now after we have done that we will continue to the next.
  131.  
  132. We need to add the imports for the client.
  133. Code:*/
  134. using System;
  135. using System.Collections.Generic;
  136. using System.Text;
  137. using SecureSocketProtocol.Client;
  138. using System.Diagnostics;
  139. using SecureSocketProtocol.Network;
  140. using System.Threading;
  141. using SecureSocketProtocol;
  142. using System.IO;
  143. using SecureSocketProtocol.misc;
  144. using SecureSocketProtocol.Interfaces;
  145. using SecureSocketProtocol.Network.Compressions;
  146. using SecureSocketProtocol.Network.Encryptions;
  147. /*After we have added the Imports, we need to add this code in the Main()
  148. Code:*/
  149. static void Main(string[] args)
  150.         {
  151.             Stopwatch RunTime = Stopwatch.StartNew();
  152.             Console.Title = "Secure Socket Protocol - Client";
  153.  
  154.             SSPClient client = new SSPClient("127.0.0.1", 127, NetworkProtocol.TCP | NetworkProtocol.ReliableUDP, null);
  155.  
  156.             Console.WriteLine("Connected");
  157.         }
  158. /*It should now look like this.
  159. http://i.imgur.com/LOQb8cy.png
  160.  
  161. Then we need to add the Events. This will need to go inside the Main() so that means between Console.WriteLine("Connected");
  162. *CODE*
  163. bracket
  164. Code:*/
  165. client.onReceiveData += (byte[] Data, PayloadReader pr, IClient c, NetworkProtocol Protocol) =>
  166.                 {
  167.                    We wont be using this but this is how the onReceivedData should look like.
  168.                 };
  169.  
  170.             client.onConnectionClosed += (IClient c) =>
  171.                 {
  172.                     Console.Title = "Secure Socket Protocol - Client - Disconnected";
  173.                 };
  174.  
  175.             VirtualConnection vConnection = client.CreateVirtualConnection((byte[] Data, PayloadReader pr, VirtualConnection vc) =>
  176.                 {
  177.  
  178.                 });
  179. /*Now we just need to finish the last step and that's a While (true).
  180. Code:*/
  181. while (true)
  182.             {
  183.                 for (int i = 0; i < 10000000; i++)
  184.                 {
  185.                     client.SendPacket(BitConverter.GetBytes(i), NetworkProtocol.UDP, false, false, true);
  186.                 }
  187.  
  188.                 Console.Title = "Secure Socket Protocol - Client - Runtime: " + RunTime.Elapsed.Hours.ToString("D2") + ":" + RunTime.Elapsed.Minutes.ToString("D2") + ":" + RunTime.Elapsed.Seconds.ToString("D2");
  189.             }
  190.             Process.GetCurrentProcess().WaitForExit();
  191. /*It should look like,
  192. http://i.imgur.com/Tfk3YJq.png
  193.  
  194. That was the final step and you can either build or debug it, the result should look like this
  195. http://i.imgur.com/2kifYpj.png
  196.  
  197. 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.
  198.  
  199. 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
  200.  
  201. EDIT; look at this DragonHunter sending 50MBps over WAN using a 1MBps network line.
  202. http://img853.imageshack.us/img853/2065/captureghc.png
  203.  
  204.  
  205. Read more: http://www.ubers.org/Thread-Tutorial-Secure-Socket-Protocol#ixzz3H2PX18M6*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement