Created
December 15, 2014 20:55
-
-
Save sionide21/00e20740aa2619a1c603 to your computer and use it in GitHub Desktop.
A proxy to the office365 IMAP server to figure out what a client tis up to.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
require 'socket' | |
Thread.abort_on_exception = true | |
server = TCPServer.new(1993) | |
n = 0 | |
loop do | |
client = server.accept | |
n += 1 | |
puts "[#{n}] New connection" | |
fork do | |
sock = TCPSocket.new('outlook.office365.com', 993) | |
ctx = OpenSSL::SSL::SSLContext.new | |
ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_NONE) | |
OpenSSL::SSL::SSLSocket.new(sock, ctx).tap do |server| | |
server.sync_close = true | |
server.connect | |
t = Thread.new do | |
while (line = server.gets) | |
puts "[#{n}]<- #{line.strip}" | |
client.write(line) | |
$stdout.flush | |
end | |
end | |
while (line = client.gets) | |
puts "[#{n}]-> #{line.strip}" | |
server.write(line) | |
$stdout.flush | |
end | |
t.join | |
end | |
client.close | |
puts "[#{n}] Connection closed" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment