Skip to content

Instantly share code, notes, and snippets.

View larrylv's full-sized avatar

Larry Lv larrylv

View GitHub Profile
@larrylv
larrylv / listen_packet.rb
Created April 27, 2016 09:10
tcp-stack-blog
class Listener
def initialize(conn, config, dst_ip)
@conn = conn
@cap = PacketFu::Capture.new(
iface: config[:iface],
start: true,
filter: "tcp and dst #{config[:ip_saddr]} and src #{dst_ip}"
)
end
@larrylv
larrylv / send_packet.rb
Created April 27, 2016 09:09
tcp-stack-blog
require 'packetfu'
config = PacketFu::Utils.whoami?
synpkt = PacketFu::TCPPacket.new(config: config, flavor: "Linux")
synpkt.ip_daddr = "216.58.221.142" # ip of google.com
synpkt.tcp_dst = 80 # port of google.com
synpkt.tcp_flags.syn = 1 # SYN
synpkt.recalc
@larrylv
larrylv / filter_packet.rb
Last active April 27, 2016 09:10
tcp-stack-blog
require 'packetfu'
cap = PacketFu::Capture.new(
iface: config[:iface],
start: true,
filter: "tcp and src 216.58.221.142"
)
cap.stream.each do |pkt|
# parse pkt and decide what to do next
@larrylv
larrylv / converter_simple.rb
Last active October 7, 2015 07:00
Convert Hash to XML
require "minitest/autorun"
require "builder"
class Converter
XML_DECLARATION = %q(<?xml version="1.0" encoding="UTF-8"?>)
def self.to_xml(h)
raise unless h.kind_of? Hash
h.inject("") { |s, (k, v)| s += node_with(k, v) }