Receive and convert stream from remote server to string

Asked

Viewed 34 times

0

I am making a script that receives a stream, in hexadecimal format, from a remote server via TCP connection, in order to break its encryption and read an ASCII message that is in it. My goal is to read this stream, and convert it to string in order to run the script I made (which considers as input only strings).

I’m new to Ruby. I can’t even read the stream that comes into my program. I can, through a site provided for this challenge, view packets that leave the server. They are like this:

003B60558EB661BC55D2305E4A8AC07E6D518ABEE7A2BFE7B7B2A5E7B6B2AEBDE7A4B5A8B0A3E7A0A6B1A2E7ADA8BEA1B2ABE7B3AFA6A9ACB4E901

And I’ve been getting it on my terminal (in pitiful attempts to at least read the stream):

7�����焉(��hX@FB^T\[NSVQC]BZG^YPMRUEVDARO

How to read this stream, convert it to its normal format and , finally, convert it to string?

1 answer

0

To convert the stream to string you can use the following one-Liner:

"<seu stream hex>".split('').each_slice(2).map {|char| char.join.hex.chr }.join

is not an elegant solution, but is sufficient to meet your need.

As for the connection part to the TCP socket and reading of the packages coming from the server, take a look at the Tcpsocket class of the standard Ruby library (the latest version, 2.2.1, can be found here: http://ruby-doc.org/stdlib-2.2.1/libdoc/socket/rdoc/TCPSocket.html).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.