Skip to content

Instantly share code, notes, and snippets.

@picatz
Created October 6, 2017 20:55
Show Gist options
  • Save picatz/f933d78735a494d351f1696e8ed07531 to your computer and use it in GitHub Desktop.
Save picatz/f933d78735a494d351f1696e8ed07531 to your computer and use it in GitHub Desktop.
Watch network traffic for curlable HTTP requests that could can replayed.
require "pcaprub"
capture = Pcap.open_live(Pcap.lookupdev, 65535, true, 1)
loop do
while packet = capture.next
if data = /\b(GET|POST|PUT|PATCH|DELETE|HEAD|CONNECT|OPTIONS|TRACE) ([^ ]+) (HTTP\/[0-9\/]+)/.match(packet)
method, path, version = data.captures
headers = packet.scan(/\S+\b:\s.+/).map(&:strip)
url = (headers.grep /\bHost:\s.+/).first.split(":").last.strip
command = "curl " + url + " -X " + method + " " + headers.map { |h| h = "-H " + "'" + h + "'" }.join(" ")
puts
puts command
puts
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment