Class: Mitmdump
- Inherits:
-
Object
- Object
- Mitmdump
- Defined in:
- lib/mitmdump.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
Instance Method Summary collapse
- #blacklist(path) ⇒ Object
- #dumpfile ⇒ Object
-
#inherit(name) ⇒ Object
DSL.
-
#initialize(name, &block) ⇒ Mitmdump
constructor
A new instance of Mitmdump.
- #map_local(path, args = {}) ⇒ Object
- #output(filename) ⇒ Object
- #param(name) ⇒ Object
- #port(port) ⇒ Object
- #replace(path, args = {}) ⇒ Object
- #script(file, args = {}) ⇒ Object
-
#start(args = {}) ⇒ Object
END DSL.
- #stop ⇒ Object
- #strip_encoding ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Mitmdump
Returns a new instance of Mitmdump.
25 26 27 28 29 30 31 32 33 |
# File 'lib/mitmdump.rb', line 25 def initialize(name, &block) @name = name.to_sym @port = 8080 @output = 'dumps/mitm.dump' @scripts = [] @params = {} instance_eval &block end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
23 24 25 |
# File 'lib/mitmdump.rb', line 23 def params @params end |
#scripts ⇒ Object (readonly)
Returns the value of attribute scripts.
23 24 25 |
# File 'lib/mitmdump.rb', line 23 def scripts @scripts end |
Instance Method Details
#blacklist(path) ⇒ Object
51 52 53 |
# File 'lib/mitmdump.rb', line 51 def blacklist(path) script "#{script_path}blacklist.py", '-p' => path end |
#dumpfile ⇒ Object
108 109 110 |
# File 'lib/mitmdump.rb', line 108 def dumpfile @output end |
#inherit(name) ⇒ Object
DSL
35 36 37 38 39 40 41 |
# File 'lib/mitmdump.rb', line 35 def inherit(name) intersect = @params.keys & proxy(name.to_sym).params.keys intersect.empty? or raise "Duplicate parameters #{intersect} when inheriting proxy '#{name.to_sym}'" @scripts = @scripts | proxy(name.to_sym).scripts @params.merge! proxy(name.to_sym).params end |
#map_local(path, args = {}) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/mitmdump.rb', line 55 def map_local(path, args={}) unless args[:file].nil? script "#{script_path}map_local.py", '-p' => path, '-f' => args[:file] else raise ArgumentError, 'No file name provided for maplocal' end end |
#output(filename) ⇒ Object
47 48 49 |
# File 'lib/mitmdump.rb', line 47 def output(filename) @output = filename end |
#param(name) ⇒ Object
85 86 87 88 |
# File 'lib/mitmdump.rb', line 85 def param(name) !@params.has_key?("%#{name.to_s}") and @params["%#{name.to_s}"] = '' or raise "Parameter name '#{name}' already declared" end |
#port(port) ⇒ Object
43 44 45 |
# File 'lib/mitmdump.rb', line 43 def port(port) @port = port end |
#replace(path, args = {}) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/mitmdump.rb', line 63 def replace(path, args={}) unless args[:swap].nil? | args[:with].nil? script "#{script_path}replace.py", '-p' => path, '-x' => args[:swap], '-r' => args[:with] else raise ArgumentError, "Expecting arguments ':swap' and ':with' for replace" end end |
#script(file, args = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/mitmdump.rb', line 75 def script(file, args={}) args.each do |k,v| unless (key = v[/%[a-zA-Z_]+/]).nil? @params.has_key?(key) or raise "Parameter '#{key}' referenced in proxy '#{@name}' but not declared" end end @scripts << [file, args] end |
#start(args = {}) ⇒ Object
END DSL
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mitmdump.rb', line 90 def start(args={}) check_params(args) if port_available? manage_dumpfile @pid = Process.spawn command Process.detach @pid connection_successful? or raise "Failed to start mitmdump after 10 seconds\nCOMMAND LINE: <#{command}>" else raise "Cannot start mitmdump on port #{@port} - port unavailable" end end |
#stop ⇒ Object
103 104 105 106 |
# File 'lib/mitmdump.rb', line 103 def stop pid = `ps --ppid #{@pid} -o pid h` system("kill #{pid}") end |
#strip_encoding ⇒ Object
71 72 73 |
# File 'lib/mitmdump.rb', line 71 def strip_encoding script "#{script_path}strip_encoding.py" end |