How can i use RAW Sockets in Ruby?

只谈情不闲聊 提交于 2019-12-10 20:38:55

问题


I'm trying to create a raw socket using Ruby.

The problem is, there isn't anything called "raw socket" there and, on the other hand, the Socket class itself is not fully documented.

Does anybody have some code samples for that kind of socket in Ruby, or maybe some kind of a documentation for that?

By the way, I already know how to work with TCPSocket and TCPServer classes, and what I need is particularly a raw socket.


回答1:


Google brings up the following result: http://www.ruby-forum.com/topic/90408

Short version:

require 'socket'

rsock = Socket.open(Socket::PF_INET, Socket::SOCK_RAW, Socket::IPPROTO_RAW)

rsock.send(string, flags)

rsock.recv(1024)

More documentation on the various Socket classes: http://www.rubycentral.com/pickaxe/lib_network.html

(The whole raw sockets thing is rather nasty on unices since it usually requires root access. I did not test this code. You may need to construct the whole packet yourself if you're not using IPSocket)




回答2:


Have a look at PacketFu. It is very well maintained and used by the Metasploit Project.




回答3:


Have a look at the racket gem (https://rubygems.org/gems/racket). It seems to be a bit outdated since the last version was released in 2009 but its also used in the metasploit framework.



来源:https://stackoverflow.com/questions/1344534/how-can-i-use-raw-sockets-in-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!