|
커피향이 나는 *NIX
커피닉스
시스템/네트웍/보안을 다루는 곳
|
|
|
|
| 이전 주제 보기 :: 다음 주제 보기 |
| 글쓴이 |
메시지 |
truefeel 카페 관리자
가입: 2003년 7월 24일 올린 글: 1277 위치: 대한민국
|
올려짐: 2005.10.09 일, 12:04 am 주제: ruby와 pcap으로 네트웍패킷 모니터링 |
|
|
Ruby와 Ruby/Pcap(libpcap 반드시 필요)을 사용하여 패킷 모니터링하는 방법에 대해 소개하고 있습니다.
* Monitoring network traffic with Ruby and Pcap (By Ryan Paul , Ian Smith-Heisters , 2005.10.5)
http://arstechnica.com/columns/linux/linux-20051002.ars
먼저 http://www.goto.info.waseda.ac.jp/%7efukusima/ruby/pcap-e.html 에서 Ruby/Pcap을 받아서 설치하고 테스트해보면 됩니다.
| 코드: |
# tar xvfz ruby-pcap-0.6.tar.gz
# cd pcap
#
# ruby extconf.rb
# make
# make install
|
몇 줄만으로 패킷 모니터링 프로그램을 만들 수 있겠네요.
다음은 위 Ruby/Pcap 라이브러리 제공사이트에 있는 httpdump.rb 예제입니다.
| 코드: |
#!/usr/local/bin/ruby
require 'pcaplet'
httpdump = Pcaplet.new('-s 1500')
HTTP_REQUEST = Pcap::Filter.new('tcp and dst port 80', httpdump.capture)
HTTP_RESPONSE = Pcap::Filter.new('tcp and src port 80', httpdump.capture)
httpdump.add_filter(HTTP_REQUEST | HTTP_RESPONSE)
httpdump.each_packet {|pkt|
data = pkt.tcp_data
case pkt
when HTTP_REQUEST
if data and data =~ /^GET\s+(\S+)/
path = $1
host = pkt.dst.to_s
host << ":#{pkt.dst_port}" if pkt.dport != 80
s = "#{pkt.src}:#{pkt.sport} > GET http://#{host}#{path}"
end
when HTTP_RESPONSE
if data and data =~ /^(HTTP\/.*)$/
status = $1
s = "#{pkt.dst}:#{pkt.dport} < #{status}"
end
end
puts s if s
}
|
|
|
| 위로 |
|
 |
|
|
새로운 주제를 올릴 수 있습니다 답글을 올릴 수 있습니다 주제를 수정할 수 없습니다 올린 글을 삭제할 수 없습니다 투표를 할 수 없습니다
|
Powered by phpBB © 2001, 2005 phpBB Group
|