Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
= evalhook - Alternate eval which hook all methods (and more) in the evaluated code
== Installation
=== Gem installation
Run in the terminal:
sudo gem install evalhook
OR
sudo gem install evalhook-X.X.X.gem.
== Documentation
Full API documentation can be found on: http://tario.github.com/evalhook/doc/
== Usage
This examples and more can be found in examples directory
=== Basic Example
Hook of method calls
require "rubygems"
require "evalhook"
class Hook < EvalHook::HookHandler
def handle_method(klass, recv, method_name)
print "called #{klass}##{method_name} over #{recv}\n"
nil
end
end
h = Hook.new
h.evalhook('print "hello world\n"')
=== Basic Example 2
Hook of global variables and constants
require "rubygems"
require "evalhook"
class Hook < EvalHook::HookHandler
# global variable assignment/creation
def handle_gasgn( global_name, new_value)
print "assignment of #{global_name} = #{new_value}\n"
nil
end
# constant assignment/creation
def handle_cdecl( container, const_name, new_value)
print "assignment of #{container}::#{const_name} = #{new_value}\n"
nil
end
end
h = Hook.new
h.evalhook('
$a = 4
A = 4', binding)
=== Basic Example 3
Redirect of method calls
require "rubygems"
require "evalhook"
class Hook < EvalHook::HookHandler
include RedirectHelper
def handle_method(klass, recv, method_name)
print "called #{klass}##{method_name} over #{recv}\n"
if method_name == :print
# change the method_name to alternative_print
Redirect.new(klass, recv, "alternative_print")
else
nil # do nothing
end
end
end
module Kernel
def alternative_print(*args)
print "alternative ", *args
end
end
h = Hook.new
h.evalhook('print "hello world\n"')
=== MultiHookHandler Example (new feature since 0.2.0)
require "rubygems"
require "evalhook"
include EvalHook
class Hook1 < HookHandler
def handle_method(klass,recv,method_name)
if method_name == :foo
redirect_method(klass,recv,:bar)
else
nil
end
end
end
class Hook2 < HookHandler
def handle_method(klass,recv,method_name)
if method_name == :bar
redirect_method(klass,recv,:test1)
else
nil
end
end
end
class X
def foo
print "foo\n"
end
def bar
print "bar\n"
end
def test1
print "test1\n"
end
end
x = X.new
x.foo # foo
mmh = MultiHookHandler.new
mmh.add( Hook1.new ) # :foo => :bar
mmh.add( Hook2.new ) # :bar => :test1
mmh.evalhook("x.foo") # test1
mmh.evalhook("x.bar") # test1
=== MultiHookHandler Example 2
require "rubygems"
require "evalhook"
include EvalHook
class DenyFooFilter < HookHandler
def handle_method(klass,recv,method_name)
if method_name == :foo
raise SecurityError
else
nil
end
end
end
class RedirectFooToBar < HookHandler
def handle_method(klass,recv,method_name)
if method_name == :foo
redirect_method(klass,recv,:bar)
else
nil
end
end
end
class X
def foo
print "foo\n"
end
def bar
print "bar\n"
end
end
x = X.new
x.foo # foo
mmh = MultiHookHandler.new
mmh.add( DenyFooFilter.new )
mmh.add( RedirectFooToBar.new )
begin
mmh.evalhook("x.foo")
rescue SecurityError
print "foo method filtered by a SecurityError exception\n"
end
mmh = MultiHookHandler.new
mmh.add( RedirectFooToBar.new )
mmh.add( DenyFooFilter.new )
mmh.evalhook("x.foo")
== Copying
Copyright (c) 2010-2011 Dario Seminara, released under the GPL License (see LICENSE)
FAQs
Unknown package
We found that evalhook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.