Class: FNode::Node
Constant Summary collapse
- CONFIG_FILE =
"config.yml"- FUZZINGS_FOLDER =
"fuzzings"- ATTRS =
%w(name ip port os state pid test_app test_file_path admin_ip admin_port)
Class Method Summary collapse
Instance Method Summary collapse
- #dump_attrs(yml_file = CONFIG_FILE) ⇒ Object
- #get_server_file ⇒ Object
-
#initialize ⇒ Node
constructor
A new instance of Node.
- #load_attrs(yml_file = CONFIG_FILE) ⇒ Object
- #run_fuzz_test ⇒ Object
- #set_state(new_state) ⇒ Object
- #stop_fuzz_test ⇒ Object
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
41 42 43 44 |
# File 'lib/fnode/node.rb', line 41 def initialize load_attrs CONFIG_FILE setup_logger end |
Class Method Details
.test ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/fnode/node.rb', line 84 def self.test n = Node.instance n.test_app = "pluma" n.test_file_path = "/tmp/fuzz.txt" n.run_fuzz_test sleep 10 n.stop_fuzz_test end |
Instance Method Details
#dump_attrs(yml_file = CONFIG_FILE) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fnode/node.rb', line 25 def dump_attrs(yml_file=CONFIG_FILE) attrs = {} ATTRS.each do |attr| attrs.store attr, self.public_send(attr) end open(yml_file, "w") do |f| f << attrs.to_yaml end end |
#get_server_file ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/fnode/node.rb', line 76 def get_server_file file = Tempfile.new("templete_file") file.binmode file << open("http://#{admin_ip}:#{admin_port}/tasks/#{task.id}/templete_file").read file.close file end |
#load_attrs(yml_file = CONFIG_FILE) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/fnode/node.rb', line 18 def load_attrs(yml_file=CONFIG_FILE) attrs = YAML.load_file(yml_file) ATTRS.each do |attr| self.public_send("#{attr}=", attrs[attr]) end end |
#run_fuzz_test ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fnode/node.rb', line 46 def run_fuzz_test stop_fuzz_test unless pid.nil? self.pid = fork do FileUtils.mkdir_p FUZZINGS_FOLDER Dir.chdir FUZZINGS_FOLDER cmd = "python #{File.expand_path('../../fuzzers/fusil_fuzzer.py', __dir__)} #{test_file_path} --force-unsafe --keep-sessions --fuzzing #{test_app}" begin set_state "running" @log.info "pid: #{Process.pid}" exec cmd rescue Exception => e @log_error.error "run test error: " + e.to_s stop_fuzz_test end end end |
#set_state(new_state) ⇒ Object
36 37 38 39 |
# File 'lib/fnode/node.rb', line 36 def set_state(new_state) state = new_state @log.info "Change state: #{state}" end |
#stop_fuzz_test ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fnode/node.rb', line 64 def stop_fuzz_test unless pid.nil? begin Process.kill('QUIT', pid) self.pid = nil set_state "stop" rescue => e @log_error.error "stop fuzz test error" + e.to_s end end end |