Last active
August 29, 2015 14:10
-
-
Save nvsofts/51753676982cb89dd02d to your computer and use it in GitHub Desktop.
某小学4年生のサイトをハックするプロキシサーバ
This file contains 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
#!/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