Last active
November 5, 2017 09:24
-
-
Save onyxblade/a95d55b246a71c5019c324e21bd2244c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'readline' | |
proc { | |
my_exit = Kernel.method(:exit!) | |
my_puts = $stdout.method(:puts) | |
ObjectSpace.each_object(Module) { |m| m.freeze if m != Readline } | |
set_trace_func proc { |event, file, line, id, binding, klass| | |
bad_id = /`|exec|foreach|fork|load|method_added|open|read(?!line$)|require|set_trace_func|spawn|syscall|system/ | |
bad_class = /(?<!True|False|Nil)Class|Module|Dir|File|ObjectSpace|Process|Thread/ | |
if event =~ /class/ || (event =~ /call/ && (id =~ bad_id || klass.to_s =~ bad_class)) | |
my_puts.call "\e[1;31m== Hacker Detected (#{$&}) ==\e[0m" | |
my_exit.call | |
end | |
} | |
}.call | |
loop do | |
line = Readline.readline('baby> ', true) | |
puts '=> ' + eval(line, TOPLEVEL_BINDING).inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment