我正在研究中间人攻击并尝试将原始HTTPS数据(即解密之前)与一对套接字进行管道传输。现在,我只想听取加密的流量,所以我希望任何数据都从我的网络浏览器,通过我的脚本,到预期的收件人,以及任何相反的数据。理想情况下,我只想将传入和传出的套接字连接在一起,并让它们自动在彼此之间传输数据,但我还没有看到在Ruby中这样做的方法所以我一直在使用以下内容,我从{ {3}}。
这是我的代码:
def socketLoop(incoming, outgoing)
loop do
puts "selecting"
ready = IO.select([outgoing, incoming])
if ready[0].include?(incoming)
data_to_send = incoming.read_nonblock(32768)
outgoing.write(data_to_send)
puts "sent out"
puts data_to_send
end
if ready[0].include?(outgoing)
data_received = outgoing.read_nonblock(32768)
incoming.write(data_received)
puts "read in"
puts data_received
break if outgoing.nil? || outgoing.closed? || outgoing.eof?
end
end
end
server = TCPServer.open(LISTENING_PORT)
loop {
Thread.start(server.accept){ |incoming|
outgoing = TCPSocket.new(TARGET_IP, TARGET_PORT)
socketLoop(incoming, outgoing)
outgoing.close # Disconnect from target
incoming.close # Disconnect from the client
}
}
它可以很好地用于HTTP,但是对于HTTPS,我的浏览器一直在旋转,输出似乎表明至少部分证书已被发送,但不是更多。我认为我天真地认为它适用于SSL,但据我所知,它使用TCP作为传输层,所以我不确定它为什么不起作用。是否有可能以这种方式获取原始数据?这是我的Ruby的问题还是我做了一些错误的假设?如果可能的话,我宁愿不使用系统范围的数据包嗅探器。如果在Ruby中不容易,我会非常感谢另一种语言中的任何指针。
非常感谢你的帮助!
编辑:我似乎可以使用netcat轻松完成这项工作 -sudo nc -l 443 0<backpipe | nc $TARGET_IP 443 >backpipe
所以我很尴尬,我一开始并没有想到这么简单的东西,但是我仍然有兴趣看看我在Ruby中做得不对。