Created
October 6, 2017 20:55
-
-
Save picatz/f933d78735a494d351f1696e8ed07531 to your computer and use it in GitHub Desktop.
Watch network traffic for curlable HTTP requests that could can replayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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