O'Reilly logo

Wicked Cool Ruby Scripts by Steve Pugh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Encrypted Server

Encrypted Server

RSA_server.rb

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required