Skip to content

Instantly share code, notes, and snippets.

@nvsofts
Last active August 29, 2015 14:10
Show Gist options
  • Save nvsofts/51753676982cb89dd02d to your computer and use it in GitHub Desktop.
Save nvsofts/51753676982cb89dd02d to your computer and use it in GitHub Desktop.
某小学4年生のサイトをハックするプロキシサーバ
#!/usr/bin/env ruby
require 'webrick'
require 'webrick/httpproxy'
BIND_ADDR = '127.0.0.1'
PORT = 8080
SCORE = 12345678
class HackProxy < WEBrick::HTTPProxyServer
def proxy_service(req, res)
unless req.host == 'why-kaisan.com' && req.path == '/score.json' then
super(req, res)
return
end
puts 'Hit why-kaisan.com/score.json'
res.status = 200
res.content_type = 'application/json'
res.body = '{"score":%d}' % SCORE
end
end
config = { :BindAddress => BIND_ADDR, :Port => PORT, :AccessLog => [] }
s = HackProxy.new( config )
Signal.trap('INT') do
s.shutdown
end
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment