fnode 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3534634c7d91c19df63d20f248ab30d73bd747a
4
+ data.tar.gz: bcb483783455d17a86cfc875aa95cec0a36eb6a1
5
+ SHA512:
6
+ metadata.gz: f48ec7638e9c011f11850c76540ed8fd081637e373e98c37a27b2b4d14ac37e1d3f4c45a5944946d25d78531eea2dfe7e1d5ef4c2e5d7a4ca99591a60fa1c818
7
+ data.tar.gz: 6079d19fb543b5ef03c72e2cf45a51e73652c13496330b628cd09cd8250119bbf8991668c1c08669a9584c30f1180d48edfe7ede94cc8216a9b76707f0ea0914
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ pkg/*
3
+ /log
4
+ /fuzzings
5
+ config.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fnode.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ FNode (0.0.1)
5
+ rest-client
6
+ sinatra
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ byebug (9.0.5)
12
+ diff-lcs (1.2.5)
13
+ domain_name (0.5.20160615)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ http-cookie (1.0.2)
16
+ domain_name (~> 0.5)
17
+ mime-types (3.1)
18
+ mime-types-data (~> 3.2015)
19
+ mime-types-data (3.2016.0521)
20
+ netrc (0.11.0)
21
+ rack (1.6.4)
22
+ rack-protection (1.5.3)
23
+ rack
24
+ rest-client (2.0.0)
25
+ http-cookie (>= 1.0.2, < 2.0)
26
+ mime-types (>= 1.16, < 4.0)
27
+ netrc (~> 0.8)
28
+ rspec (3.5.0)
29
+ rspec-core (~> 3.5.0)
30
+ rspec-expectations (~> 3.5.0)
31
+ rspec-mocks (~> 3.5.0)
32
+ rspec-core (3.5.2)
33
+ rspec-support (~> 3.5.0)
34
+ rspec-expectations (3.5.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.5.0)
37
+ rspec-mocks (3.5.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.5.0)
40
+ rspec-support (3.5.0)
41
+ sinatra (1.4.7)
42
+ rack (~> 1.5)
43
+ rack-protection (~> 1.4)
44
+ tilt (>= 1.3, < 3)
45
+ tilt (2.0.5)
46
+ unf (0.1.4)
47
+ unf_ext
48
+ unf_ext (0.0.7.2)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ FNode!
55
+ byebug
56
+ rspec
57
+
58
+ BUNDLED WITH
59
+ 1.12.5
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ fnode
2
+ --------
3
+
4
+ Fuzzing Node.
5
+
6
+ # Requirements
7
+
8
+ * Ruby 2.0 +
9
+ * Python 2.7 +
10
+
11
+
12
+ # Install
13
+
14
+ ```
15
+ pip install fusil
16
+ gem install fnode
17
+ ```
18
+
19
+ # Usage
20
+ not ready.
21
+
22
+ # TODO
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/fnode ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __dir__)
4
+
5
+ require "fnode"
6
+
7
+ FNode::Server.run!
data/fnode.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'fnode/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'fnode'
7
+ s.version = FNode::VERSION
8
+ s.licenses = ['MIT']
9
+ s.date = '2016-08-29'
10
+ s.summary = "F Node."
11
+ s.description = "F Node."
12
+ s.authors = ["Aston Fu"]
13
+ s.email = 'fudhao@gmail.com'
14
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_paths = ['lib']
17
+ s.executables = %w(fnode)
18
+ s.homepage = 'https://github.com/astonfu/fnode'
19
+
20
+ s.add_runtime_dependency 'rest-client'
21
+ s.add_runtime_dependency 'sinatra'
22
+ s.add_runtime_dependency 'logging'
23
+
24
+ s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'byebug'
26
+ end
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/python
2
+ """
3
+ fuzzing app templete
4
+ """
5
+
6
+ PROGRAM = 'fuzzing'
7
+ PLAY_DURATION = 3
8
+ MAX_FILESIZE = 1024*1024
9
+
10
+ from fusil.application import Application
11
+ from optparse import OptionGroup
12
+ from fusil.process.mangle import MangleProcess
13
+ from fusil.process.watch import WatchProcess
14
+ from fusil.process.stdout import WatchStdout
15
+ from fusil.auto_mangle import AutoMangle
16
+ from fusil.terminal_echo import TerminalEcho
17
+
18
+ class Fuzzer(Application):
19
+ NAME = "fuzzing"
20
+ USAGE = "%prog [options] filename"
21
+ NB_ARGUMENTS = 1
22
+
23
+ def createFuzzerOptions(self, parser):
24
+ options = OptionGroup(parser, "fuzzing")
25
+ options.add_option("--fuzzing", help="fuzzing program path (default: %s)" % PROGRAM,
26
+ type="str", default=PROGRAM)
27
+ options.add_option("--duration", help="Playing maximum duration in seconds (default: %s)" % PLAY_DURATION,
28
+ type="int", default=PLAY_DURATION)
29
+ options.add_option("--filesize", help="Maximum file size in bytes (default: %s)" % MAX_FILESIZE,
30
+ type="int", default=MAX_FILESIZE)
31
+ return options
32
+
33
+ def setupProject(self):
34
+ project = self.project
35
+ # Command line
36
+ arguments = [self.options.fuzzing]
37
+ timeout = self.options.duration + 1.0
38
+
39
+ # Create buggy input file
40
+ orig_filename = self.arguments[0]
41
+ mangle = AutoMangle(project, orig_filename)
42
+ mangle.max_size = self.options.filesize
43
+
44
+ process = MangleProcess(project,
45
+ arguments,
46
+ "<fuzzing>",
47
+ timeout=timeout)
48
+
49
+ process.setupX11()
50
+ process.env.copy('HOME')
51
+ watch = WatchProcess(process, timeout_score=0)
52
+ if watch.cpu:
53
+ watch.cpu.weight = 0.20
54
+ watch.cpu.max_load = 0.50
55
+ watch.cpu.max_duration = min(3, timeout-0.5)
56
+ watch.cpu.max_score = 0.50
57
+
58
+ stdout = WatchStdout(process)
59
+
60
+ # Restore terminal state
61
+ TerminalEcho(project)
62
+
63
+ if __name__ == "__main__":
64
+ Fuzzer().main()
data/lib/fnode.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative "fnode/server"
data/lib/fnode/node.rb ADDED
@@ -0,0 +1,132 @@
1
+ require 'logging'
2
+ require 'fileutils'
3
+ require 'singleton'
4
+ require 'yaml'
5
+
6
+
7
+ module FNode
8
+ class Node
9
+ include Singleton
10
+ CONFIG_FILE = "config.yml"
11
+ FUZZINGS_FOLDER = "fuzzings"
12
+ ATTRS = %w(name ip port os state pid test_app test_file_path admin_ip admin_port)
13
+
14
+ ATTRS.each do |attr|
15
+ attr_accessor(attr)
16
+ end
17
+
18
+ def load_attrs(yml_file=CONFIG_FILE)
19
+ attrs = YAML.load_file(yml_file)
20
+ ATTRS.each do |attr|
21
+ self.public_send("#{attr}=", attrs[attr])
22
+ end
23
+ end
24
+
25
+ def dump_attrs(yml_file=CONFIG_FILE)
26
+ attrs = {}
27
+ ATTRS.each do |attr|
28
+ attrs.store attr, self.public_send(attr)
29
+ end
30
+
31
+ open(yml_file, "w") do |f|
32
+ f << attrs.to_yaml
33
+ end
34
+ end
35
+
36
+ def set_state(new_state)
37
+ state = new_state
38
+ @log.info "Change state: #{state}"
39
+ end
40
+
41
+ def initialize
42
+ load_attrs CONFIG_FILE
43
+ setup_logger
44
+ end
45
+
46
+ def run_fuzz_test
47
+ stop_fuzz_test unless pid.nil?
48
+
49
+ self.pid = fork do
50
+ FileUtils.mkdir_p FUZZINGS_FOLDER
51
+ Dir.chdir FUZZINGS_FOLDER
52
+ cmd = "python #{File.expand_path('../../fuzzers/fusil_fuzzer.py', __dir__)} #{test_file_path} --force-unsafe --keep-sessions --fuzzing #{test_app}"
53
+ begin
54
+ set_state "running"
55
+ @log.info "pid: #{Process.pid}"
56
+ exec cmd
57
+ rescue Exception => e
58
+ @log_error.error "run test error: " + e.to_s
59
+ stop_fuzz_test
60
+ end
61
+ end
62
+ end
63
+
64
+ def stop_fuzz_test
65
+ unless pid.nil?
66
+ begin
67
+ Process.kill('QUIT', pid)
68
+ self.pid = nil
69
+ set_state "stop"
70
+ rescue => e
71
+ @log_error.error "stop fuzz test error" + e.to_s
72
+ end
73
+ end
74
+ end
75
+
76
+ def get_server_file
77
+ file = Tempfile.new("templete_file")
78
+ file.binmode
79
+ file << open("http://#{admin_ip}:#{admin_port}/tasks/#{task.id}/templete_file").read
80
+ file.close
81
+ file
82
+ end
83
+
84
+ def self.test
85
+ n = Node.instance
86
+ n.test_app = "pluma"
87
+ n.test_file_path = "/tmp/fuzz.txt"
88
+ n.run_fuzz_test
89
+ sleep 10
90
+ n.stop_fuzz_test
91
+ end
92
+
93
+ private
94
+ def setup_logger
95
+ require 'fileutils'
96
+ FileUtils.mkdir_p 'log'
97
+
98
+ @log = Logging.logger['fnode']
99
+ @log.level = :info
100
+
101
+ # here we setup a color scheme called 'bright'
102
+ Logging.color_scheme( 'bright',
103
+ :levels => {
104
+ :info => :green,
105
+ :warn => :yellow,
106
+ :error => :red,
107
+ :fatal => [:white, :on_red]
108
+ },
109
+ :date => :blue,
110
+ :logger => :cyan,
111
+ :message => :magenta
112
+ )
113
+
114
+ Logging.appenders.stdout(
115
+ 'stdout',
116
+ :layout => Logging.layouts.pattern(
117
+ :pattern => '[%d] %-5l %c: %m\n',
118
+ :color_scheme => 'bright'
119
+ )
120
+ )
121
+
122
+ @log.add_appenders 'stdout', \
123
+ Logging.appenders.file('log/fnode.log', \
124
+ :layout => Logging.layouts.pattern(:pattern => '[%d] %-5l %c: %m\n'))
125
+
126
+ @log_error = Logging.logger['error']
127
+ @log_error.level = :error
128
+ @log_error.add_appenders Logging.appenders.file('log/fnode.error.log', \
129
+ :layout => Logging.layouts.pattern(:pattern => '[%d] %-5l %c: %m\n'))
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,20 @@
1
+
2
+ require 'sinatra'
3
+
4
+ module FNode
5
+ class Server < Sinatra::Base
6
+ get '/' do
7
+ "OK"
8
+ end
9
+
10
+ get '/run' do
11
+ end
12
+
13
+ get '/stop' do
14
+
15
+ end
16
+
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: name
3
+ ip: 127.0.0.1
4
+ port: 4567
5
+ os: Linux
6
+ state: closed
7
+ pid:
8
+ test_app: app
9
+ test_file_path: "/path/to/file"
10
+ admin_ip: 127.0.0.1
11
+ admin_port: 3000
@@ -0,0 +1,3 @@
1
+ module FNode
2
+ VERSION = '0.0.2'
3
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fnode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Aston Fu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: logging
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: F Node.
84
+ email: fudhao@gmail.com
85
+ executables:
86
+ - fnode
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - README.md
95
+ - Rakefile
96
+ - bin/fnode
97
+ - fnode.gemspec
98
+ - fuzzers/fusil_fuzzer.py
99
+ - lib/fnode.rb
100
+ - lib/fnode/node.rb
101
+ - lib/fnode/server.rb
102
+ - lib/fnode/templates/config.example.yml
103
+ - lib/fnode/version.rb
104
+ homepage: https://github.com/astonfu/fnode
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: F Node.
128
+ test_files: []