Class: Dvash::Core
- Inherits:
-
Object
- Object
- Dvash::Core
- Defined in:
- lib/dvash/core.rb
Overview
Core class contains methods all other classes depend on to function properly.
Direct Known Subclasses
Instance Method Summary collapse
-
#client_ip(client) ⇒ String
Client source IP address in a [TCPServer].
-
#load_conf ⇒ Object
Loads the configuration file using [ParseConfig].
-
#load_honeyport ⇒ Object
Load all Honeyports set true in the configuration file.
-
#random_data ⇒ String
Generate a random string 64 bytes long.
-
#valid_ip?(address) ⇒ Boolean
Validates an IP address IP Address should be valid IPv4 or IPv6 addresses.
-
#valid_user? ⇒ Boolean
Validates user We must be root to create entries in the firewall.
-
#validate_os ⇒ Object
Validates the operating system OS must be Windows 7+, OS X, or Linux Creates a new instance of the operating system specific Dvash libraries required to block IP addresses properly, @@os is used as a class variable to call its methods from within a Honeyport.
Instance Method Details
#client_ip(client) ⇒ String
Client source IP address in a [TCPServer]
104 105 106 |
# File 'lib/dvash/core.rb', line 104 def client_ip(client) client.peeraddr[3] end |
#load_conf ⇒ Object
Loads the configuration file using [ParseConfig]
66 67 68 69 70 71 72 73 74 |
# File 'lib/dvash/core.rb', line 66 def load_conf begin @@cfgfile = ParseConfig.new(@paths[:config_path]) rescue # TODO: Use 'logger' gem to output debug information puts "invalid configuration file" exit end end |
#load_honeyport ⇒ Object
Load all Honeyports set true in the configuration file
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dvash/core.rb', line 77 def load_honeyport # Read honeyports group in configuration file, parse keys and values @@cfgfile['honeyports'].each do |key, value| if value == 'true' then ipver, proto = key.split("_") # Load methods for all honeyports set true begin require "dvash/honeyports/#{ipver}/#{proto}" rescue # TODO: Use [logger] gem to output debug information puts "couldn't load dvash/honeyports/#{ipver}/#{proto}" exit end # Push the loaded honeyport into a thread @honey_threads << Thread.new { Dvash::Honeyport.new.send(key) } end end end |
#random_data ⇒ String
Generate a random string 64 bytes long
98 99 100 |
# File 'lib/dvash/core.rb', line 98 def random_data SecureRandom.random_bytes(64) end |
#valid_ip?(address) ⇒ Boolean
Validates an IP address IP Address should be valid IPv4 or IPv6 addresses
20 21 22 23 24 25 26 27 |
# File 'lib/dvash/core.rb', line 20 def valid_ip?(address) begin IPAddr.new("#{address}") true rescue false end end |
#valid_user? ⇒ Boolean
Validates user We must be root to create entries in the firewall
13 14 15 |
# File 'lib/dvash/core.rb', line 13 def valid_user? Process.uid == 0 end |
#validate_os ⇒ Object
Validates the operating system OS must be Windows 7+, OS X, or Linux Creates a new instance of the operating system specific Dvash libraries required to block IP addresses properly, @@os is used as a class variable to call its methods from within a Honeyport
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dvash/core.rb', line 34 def validate_os # Rubygems platform data system = RUBY_PLATFORM # Use regular expressions to determine operating system case system # WINDOWS when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ # Create Dvash Windows object for use within 'honeyports' modules require 'dvash/os/windows' @@os = Dvash::Windows.new # MAC OS X when /darwin|mac os/ # Create Dvash Mac OS X object for use within 'honeyports' modules require 'dvash/os/mac' @@os = Dvash::Mac.new # LINUX when /linux/ # Create Dvash Linux object for use within 'honeyports' modules require 'dvash/os/linux' @@os = Dvash::Linux.new # BSD when /solaris|bsd/ # TODO: BSD support exit else # TODO: Use [logger] gem to output debug information puts "invalid operating system" exit end end |