phantom_proxy 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -40,5 +40,9 @@ You can see the current proxy status by pointing your browser to
|
|
40
40
|
phantom_proxy_control_panel
|
41
41
|
if you have set the proxy or just to the address and port the proxy is running at
|
42
42
|
address:port/phantom_proxy_control_panel
|
43
|
+
|
44
|
+
Security(1.2.0)
|
45
|
+
Now the phantom_proxy can be secured with a key. The system is implemented with an hmac algorithm.
|
46
|
+
Simply supply "-hmac THE_KEY" when starting the proxy and the proxy is secured
|
43
47
|
|
44
48
|
== TODO
|
data/bin/phantom_proxy
CHANGED
@@ -24,14 +24,37 @@ options = {
|
|
24
24
|
:log_output => true
|
25
25
|
}
|
26
26
|
#Daemons.daemonize(options)
|
27
|
+
|
28
|
+
PARAMETERS = Array.new
|
29
|
+
|
30
|
+
hmac_key = nil
|
27
31
|
phantom = false
|
32
|
+
last_arg = nil
|
28
33
|
ARGV.each { |arg|
|
29
|
-
|
34
|
+
if !/-hmac/.match(arg) && !/-hmac/.match(last_arg) && !/-self/.match(arg)
|
35
|
+
PARAMETERS << arg
|
36
|
+
end
|
37
|
+
phantom = true if /-self/.match(arg)
|
38
|
+
hmac_key = arg if /-hmac/.match(last_arg)
|
39
|
+
last_arg = arg
|
30
40
|
}
|
31
41
|
|
42
|
+
if hmac_key
|
43
|
+
if !File.directory?("/tmp/phantom_proxy")
|
44
|
+
Dir.mkdir("/tmp/phantom_proxy")
|
45
|
+
end
|
46
|
+
|
47
|
+
File.open("/tmp/phantom_proxy/key", 'w+') {|f| f.write(hmac_key) }
|
48
|
+
else
|
49
|
+
begin
|
50
|
+
File.delete("/tmp/phantom_proxy/key")
|
51
|
+
rescue
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
32
55
|
if !phantom
|
33
|
-
startoptions = ["start", "-R", PhantomJSProxy::CONFIG, "-P", "/tmp/pids/phantom_proxy.pid", "--tag", "phantom_proxy"]+
|
34
|
-
Thin::Runner.new(startoptions).run!
|
56
|
+
startoptions = ["start", "-R", PhantomJSProxy::CONFIG, "-P", "/tmp/pids/phantom_proxy.pid", "--tag", "phantom_proxy"]+PARAMETERS
|
57
|
+
runner = Thin::Runner.new(startoptions).run!
|
35
58
|
else
|
36
59
|
Thin::Server.start(PhantomJSProxy::PhantomJSServer.new, ARGV[0], ARGV[1], ARGV[2])
|
37
60
|
end
|
@@ -24,10 +24,10 @@ module PhantomJSProxy
|
|
24
24
|
end
|
25
25
|
|
26
26
|
if pictureOnly
|
27
|
-
if !File.directory?("/tmp/
|
28
|
-
Dir.mkdir("/tmp/
|
27
|
+
if !File.directory?("/tmp/phantom_proxy")
|
28
|
+
Dir.mkdir("/tmp/phantom_proxy")
|
29
29
|
end
|
30
|
-
pictureFile = Tempfile.new(["
|
30
|
+
pictureFile = Tempfile.new(["phantom_proxy/page", ".png"])
|
31
31
|
picture = pictureFile.path
|
32
32
|
end
|
33
33
|
|
@@ -75,7 +75,7 @@ module PhantomJSProxy
|
|
75
75
|
def invokePhantomJS(script, args)
|
76
76
|
argString = " "+args.join(" ")
|
77
77
|
puts("Call phantomJS with: "+argString)
|
78
|
-
out = IO.popen(PHANTOMJS_BIN+" --cookies-file=/tmp/
|
78
|
+
out = IO.popen(PHANTOMJS_BIN+" --cookies-file=/tmp/phantom_proxy/cookies.txt "+script+argString)
|
79
79
|
o = out.readlines.join
|
80
80
|
puts("PHANTOMJS_OUT: "+o)
|
81
81
|
return o
|
@@ -1,12 +1,27 @@
|
|
1
1
|
require 'net/http'
|
2
|
+
require 'hmac-md5'
|
2
3
|
|
3
4
|
module PhantomJSProxy
|
4
5
|
class PhantomJSServer
|
5
|
-
def initialize
|
6
|
+
def initialize
|
6
7
|
@control_panel = PhantomJSProxy::PhantomJSControlPanel.new
|
8
|
+
|
9
|
+
#load key
|
10
|
+
@hmac_activated = false
|
11
|
+
@hmac = nil
|
12
|
+
if File.directory?("/tmp/phantom_proxy")
|
13
|
+
if File.exists?("/tmp/phantom_proxy/key")
|
14
|
+
key = File.open("/tmp/phantom_proxy/key", "r").read
|
15
|
+
#puts "HMAC_KEY: #{key}"
|
16
|
+
@hmac_activated = true
|
17
|
+
@hmac = HMAC::MD5.new key
|
18
|
+
end
|
19
|
+
end
|
7
20
|
end
|
8
21
|
|
9
22
|
attr_accessor :control_panel
|
23
|
+
attr_accessor :hmac
|
24
|
+
attr_accessor :hmac_activated
|
10
25
|
|
11
26
|
def check_for_route(url)
|
12
27
|
if /\.js/i.match(url)
|
@@ -42,6 +57,19 @@ module PhantomJSProxy
|
|
42
57
|
resp.finish
|
43
58
|
end
|
44
59
|
|
60
|
+
def check_request_security req, env
|
61
|
+
client_key = env['HTTP_HMAC_KEY']
|
62
|
+
client_time= Time.parse(env['HTTP_HMAC_TIME'])
|
63
|
+
remote_time= Time.now
|
64
|
+
remote_key = hmac.update(env['REQUEST_URI']+env['HTTP_HMAC_TIME']).hexdigest
|
65
|
+
|
66
|
+
if (client_key != remote_key || (remote_time-client_time).abs > 120)
|
67
|
+
control_panel.add_special_request "@did not pass security check"
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
return true
|
71
|
+
end
|
72
|
+
|
45
73
|
def call(env)
|
46
74
|
control_panel.add_request
|
47
75
|
|
@@ -50,7 +78,21 @@ module PhantomJSProxy
|
|
50
78
|
haha = env.collect { |k, v| "#{k} : #{v}\n" }.join
|
51
79
|
env['rack.errors'].write("The request: "+req.url()+"\nGET: "+haha+"\n")
|
52
80
|
|
53
|
-
|
81
|
+
if hmac_activated && !check_request_security(req, env)
|
82
|
+
resp = Rack::Response.new([], 503, {
|
83
|
+
'Content-Type' => 'text/html'
|
84
|
+
}) { |r|
|
85
|
+
r.write("Security ERROR")
|
86
|
+
}
|
87
|
+
return resp.finish
|
88
|
+
end
|
89
|
+
|
90
|
+
https_request = false
|
91
|
+
if /\:443/.match(req.url())
|
92
|
+
https_request = true
|
93
|
+
end
|
94
|
+
|
95
|
+
params = req.params.collect { |k, v| "#{k}=#{v}&" }.join
|
54
96
|
env['rack.errors'].write("Paramas: "+params+"\n")
|
55
97
|
|
56
98
|
#this routes the request to the outgoing server incase its not html that we want to load
|
@@ -79,6 +121,11 @@ module PhantomJSProxy
|
|
79
121
|
end
|
80
122
|
|
81
123
|
url = env['REQUEST_URI'];
|
124
|
+
if https_request
|
125
|
+
url['http'] = 'https'
|
126
|
+
url[':443'] = ''
|
127
|
+
end
|
128
|
+
|
82
129
|
if params.length > 0
|
83
130
|
url += '?'+params;
|
84
131
|
end
|
@@ -5,7 +5,7 @@ var frameCount = 1;
|
|
5
5
|
var frameContent = [];
|
6
6
|
var masterURL = "";
|
7
7
|
|
8
|
-
evaluateWithVars
|
8
|
+
function evaluateWithVars(page, func, vars)
|
9
9
|
{
|
10
10
|
var fstr = func.toString()
|
11
11
|
//console.log(fstr.replace("function () {", "function () {\n"+vstr))
|
@@ -20,7 +20,7 @@ evaluateWithVars = function(page, func, vars)
|
|
20
20
|
return page.evaluate(evalstr)
|
21
21
|
}
|
22
22
|
|
23
|
-
|
23
|
+
function insertFrames(url) {
|
24
24
|
var page = require('webpage').create();
|
25
25
|
page.onConsoleMessage = function (msg) { console.log(msg); };
|
26
26
|
page.onAlert = function(msg) { console.log(msg);};
|
File without changes
|
data/lib/phantom_proxy.rb
CHANGED
@@ -4,7 +4,7 @@ module PhantomJSProxy
|
|
4
4
|
ROOT = File.expand_path(File.dirname(__FILE__))
|
5
5
|
SCRIPT = ROOT+"/phantom_proxy/scripts/proxy.js"
|
6
6
|
CONTROL_PANEL = ROOT+"/phantom_proxy/web/control_panel.html"
|
7
|
-
PHANTOMJS_BIN = ROOT+'
|
7
|
+
PHANTOMJS_BIN = ROOT+'/phantom_proxy/vendor/bin/phantomjs'
|
8
8
|
end
|
9
9
|
|
10
10
|
require PhantomJSProxy::ROOT+'/phantom_proxy/phantomjs.rb'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantom_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 1.3.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ruby-hmac
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.4.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.4.0
|
30
46
|
description: This is a phyntonjs Proxy it allows you to fetch webpages and execute
|
31
47
|
javascript in them.
|
32
48
|
email: suddani@googlemail.com
|
@@ -42,8 +58,8 @@ files:
|
|
42
58
|
- lib/phantom_proxy/scripts/proxy.js
|
43
59
|
- lib/phantom_proxy/config.ru
|
44
60
|
- lib/phantom_proxy/web/control_panel.html
|
61
|
+
- lib/phantom_proxy/vendor/bin/phantomjs
|
45
62
|
- bin/phantom_proxy
|
46
|
-
- bin/phantomjs
|
47
63
|
- README.rdoc
|
48
64
|
- Gemfile
|
49
65
|
homepage: http://experteer.com
|