执行 HoneyC 时出错 - `require': 无法加载此类文件
Error when executing HoneyC - `require': cannot load such file
我正在尝试执行 HoneyC,代码在此 link:HoneyC Source Code。我已经按照 'readme' 文档说明进行操作,其中指出 UnitTest 必须首先是 运行。
上面写着:"Unpack the HoneyC distribution into a directory, cd into that directory, and execute ‘ruby UnitTester.rb’. This will start the unit tests executing some basic module tests. (Note that you need to have network connectivity and direct outgoing access on port 80 for the unit tests to succeed.)"
我正在使用 Ruby 版本 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
*我以前从未使用 Ruby 编程过。
端口 80 似乎没问题...如果我 运行 命令 netstat 我得到:
:~$ netstat -tulnap (Not all processes could be
identified, non-owned process info will not be shown, you would have
to be root to see it all.) Active Internet connections (servers and
established) Proto Recv-Q Send-Q Local Address Foreign
Address State PID/Program name tcp 0 0
127.0.0.1:3306 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:30800 0.0.0.0:*
LISTEN - tcp 0 0 0.0.0.0:80
0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:30900 0.0.0.0:* LISTEN -
tcp 0 0 127.0.1.1:53 0.0.0.0:*
LISTEN
但是,当我尝试 运行 单元测试时出现以下错误:
:~/honeypot/honeyc-master$ ruby UnitTester.rb
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- HoneyCConfiguration (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from UnitTester.rb:39:in `block in suite'
from /usr/lib/ruby/2.3.0/find.rb:49:in `block (2 levels) in find'
from /usr/lib/ruby/2.3.0/find.rb:48:in `catch'
from /usr/lib/ruby/2.3.0/find.rb:48:in `block in find'
from /usr/lib/ruby/2.3.0/find.rb:43:in `each'
from /usr/lib/ruby/2.3.0/find.rb:43:in `find'
from UnitTester.rb:29:in `suite'
from /usr/lib/ruby/vendor_ruby/test/unit/ui/testrunner.rb:12:in `initialize'
from /usr/lib/ruby/vendor_ruby/test/unit/ui/console/testrunner.rb:38:in `initialize'
from /usr/lib/ruby/vendor_ruby/test/unit/ui/testrunnerutilities.rb:24:in `new'
from /usr/lib/ruby/vendor_ruby/test/unit/ui/testrunnerutilities.rb:24:in `run'
from UnitTester.rb:54:in `<main>'
单元测试的ruby代码为:
require 'test/unit/testsuite'
require 'test/unit/ui/console/testrunner'
require 'find'
module Kernel
def get_class_for_name(name, objects = [Object])
#STDERR.puts name.to_s
return nil if objects.size == 0
object = objects.shift
object.constants.each do |constant_name|
real_object = object.const_get(constant_name)
case real_object
when Class
return real_object if constant_name == name
when Module
objects << real_object
end
end
return get_class_for_name(name, objects)
end
end
class UnitTester
def self.suite
exceptions = ["HoneyC","UnitTester"]
suite = Test::Unit::TestSuite.new("HoneyC Unit Tests")
#find all rb files
Find.find(".") do |full_file_name|
if /.rb/ =~ full_file_name and !(/.svn/ =~ full_file_name)
/.*\// =~ full_file_name
path = $&[2..$&.length]
classname = full_file_name[$&.length..-4]
if !exceptions.index(classname)
#assume test is under classname + "Test"
#run unit test on them except on the exceptions
require path + classname
classname.sub!(/\.tab/,"") #silly replacement for the snortruleparser, since this is an automatically generated class.
unit_test = get_class_for_name(classname + "Test")
if(unit_test==nil)
STDERR.puts "No unit test defined for class " + classname + "."
else
suite << unit_test.suite
end
end
end
end
return suite
end
end
Test::Unit::UI::Console::TestRunner.run(UnitTester)
如何获得这个蜜罐运行ning?
此代码库的最新提交是从 2007 年开始的(并将其转移到 git,我不确定最初的颠覆提交是否更早)。 Ruby 从那时起已经走了很长一段路,而你 运行 的 UnitTester 依赖于多年来发生变化的一些元编程行为。它试图查看源代码树中的所有 ruby 文件以加载它们以查找测试,但它的做法在现代红宝石中不起作用。至少有两处错误:
从 2009 年发布的 ruby 1.9 开始,当前目录不再(默认)在加载路径中,因此当您尝试 require
a module/class 在当前目录中定义它会失败。他们需要切换到 require_relative
(Why does Ruby 1.9.2 remove "." from LOAD_PATH, and what's the alternative?)
代码库正在做一些非常奇怪的事情(但也许曾经是必要的)它如何爬行对象树以试图弄清楚 classes/modules 已经定义了什么(https://github.com/honeynet/honeyc/blob/master/UnitTester.rb#L10 ).这在现代红宝石中无法正常工作。
您可以获得 UnitTests 运行 ruby 1.8.7,但请注意,自 2017 年 4 月 1 日起不再支持 ruby 版本。单元测试大部分都通过了,除了一些正在查询不再存在的 Web 服务。
我认为如果不进行大量升级工作就无法真正使用此代码库,这可能是 off-topic 此处。
我正在尝试执行 HoneyC,代码在此 link:HoneyC Source Code。我已经按照 'readme' 文档说明进行操作,其中指出 UnitTest 必须首先是 运行。
上面写着:"Unpack the HoneyC distribution into a directory, cd into that directory, and execute ‘ruby UnitTester.rb’. This will start the unit tests executing some basic module tests. (Note that you need to have network connectivity and direct outgoing access on port 80 for the unit tests to succeed.)"
我正在使用 Ruby 版本 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
*我以前从未使用 Ruby 编程过。
端口 80 似乎没问题...如果我 运行 命令 netstat 我得到:
:~$ netstat -tulnap (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:30800 0.0.0.0:*
LISTEN - tcp 0 0 0.0.0.0:80
0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:30900 0.0.0.0:* LISTEN -
tcp 0 0 127.0.1.1:53 0.0.0.0:*
LISTEN
但是,当我尝试 运行 单元测试时出现以下错误:
:~/honeypot/honeyc-master$ ruby UnitTester.rb
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- HoneyCConfiguration (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from UnitTester.rb:39:in `block in suite'
from /usr/lib/ruby/2.3.0/find.rb:49:in `block (2 levels) in find'
from /usr/lib/ruby/2.3.0/find.rb:48:in `catch'
from /usr/lib/ruby/2.3.0/find.rb:48:in `block in find'
from /usr/lib/ruby/2.3.0/find.rb:43:in `each'
from /usr/lib/ruby/2.3.0/find.rb:43:in `find'
from UnitTester.rb:29:in `suite'
from /usr/lib/ruby/vendor_ruby/test/unit/ui/testrunner.rb:12:in `initialize'
from /usr/lib/ruby/vendor_ruby/test/unit/ui/console/testrunner.rb:38:in `initialize'
from /usr/lib/ruby/vendor_ruby/test/unit/ui/testrunnerutilities.rb:24:in `new'
from /usr/lib/ruby/vendor_ruby/test/unit/ui/testrunnerutilities.rb:24:in `run'
from UnitTester.rb:54:in `<main>'
单元测试的ruby代码为:
require 'test/unit/testsuite'
require 'test/unit/ui/console/testrunner'
require 'find'
module Kernel
def get_class_for_name(name, objects = [Object])
#STDERR.puts name.to_s
return nil if objects.size == 0
object = objects.shift
object.constants.each do |constant_name|
real_object = object.const_get(constant_name)
case real_object
when Class
return real_object if constant_name == name
when Module
objects << real_object
end
end
return get_class_for_name(name, objects)
end
end
class UnitTester
def self.suite
exceptions = ["HoneyC","UnitTester"]
suite = Test::Unit::TestSuite.new("HoneyC Unit Tests")
#find all rb files
Find.find(".") do |full_file_name|
if /.rb/ =~ full_file_name and !(/.svn/ =~ full_file_name)
/.*\// =~ full_file_name
path = $&[2..$&.length]
classname = full_file_name[$&.length..-4]
if !exceptions.index(classname)
#assume test is under classname + "Test"
#run unit test on them except on the exceptions
require path + classname
classname.sub!(/\.tab/,"") #silly replacement for the snortruleparser, since this is an automatically generated class.
unit_test = get_class_for_name(classname + "Test")
if(unit_test==nil)
STDERR.puts "No unit test defined for class " + classname + "."
else
suite << unit_test.suite
end
end
end
end
return suite
end
end
Test::Unit::UI::Console::TestRunner.run(UnitTester)
如何获得这个蜜罐运行ning?
此代码库的最新提交是从 2007 年开始的(并将其转移到 git,我不确定最初的颠覆提交是否更早)。 Ruby 从那时起已经走了很长一段路,而你 运行 的 UnitTester 依赖于多年来发生变化的一些元编程行为。它试图查看源代码树中的所有 ruby 文件以加载它们以查找测试,但它的做法在现代红宝石中不起作用。至少有两处错误:
从 2009 年发布的 ruby 1.9 开始,当前目录不再(默认)在加载路径中,因此当您尝试
require
a module/class 在当前目录中定义它会失败。他们需要切换到require_relative
(Why does Ruby 1.9.2 remove "." from LOAD_PATH, and what's the alternative?)代码库正在做一些非常奇怪的事情(但也许曾经是必要的)它如何爬行对象树以试图弄清楚 classes/modules 已经定义了什么(https://github.com/honeynet/honeyc/blob/master/UnitTester.rb#L10 ).这在现代红宝石中无法正常工作。
您可以获得 UnitTests 运行 ruby 1.8.7,但请注意,自 2017 年 4 月 1 日起不再支持 ruby 版本。单元测试大部分都通过了,除了一些正在查询不再存在的 Web 服务。
我认为如果不进行大量升级工作就无法真正使用此代码库,这可能是 off-topic 此处。