Encrypted Server

Encrypted Server


Now that you have seen the client and all of its magic, it's time to analyze the server. The server receives the data, checks that the SHA1 hash is valid, decrypts the data, and, finally, executes the command string based on the payload transmitted.

The Code

 require 'socket'
 require 'digest/sha1'

 priv_key = OpenSSL::PKey::RSA.new(1024)
 pub_key = priv_key.public_key

 host = ARGV[0] || 'localhost'
 port = (ARGV[1] || 8887).to_i

 server = TCPServer.new(host, port)

 while session = server.accept begin puts "Connection ...

Get Wicked Cool Ruby Scripts now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.