Last active
June 12, 2018 19:24
-
-
Save stewartpark/db0f8d33eeedd259d0e4d385e577d9be to your computer and use it in GitHub Desktop.
Play with a running ruby process safely
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 bash | |
# | |
# ./reval "pid" "ruby code" | |
rm /tmp/ruby.out 2> /dev/null | |
expr=$(echo $2 | base64) | |
( | |
echo "set breakpoint pending on"; | |
echo "tb rb_funcallv" | |
echo "commands" | |
echo "call (void*)rb_eval_string_protect(\"require'base64';a=eval(Base64.decode64('$expr'));File.write('/tmp/ruby.out',a.to_s)\", (void*)0)" | |
echo "d" | |
echo "end" | |
echo "c" | |
) | gdb -p $1 &> /dev/null | |
if [ -f /tmp/ruby.out ]; then | |
cat /tmp/ruby.out | |
else | |
echo "Execution failed" | |
fi | |
root@staging-01:/tmp/test# vi reval | |
root@staging-01:/tmp/test# ./reval 349 "Octopus::Proxy.nil?" | |
false | |
root@staging-01:/tmp/test# cat reval | |
#!/usr/bin/env bash | |
# | |
# ./reval "pid" "ruby code" | |
rm /tmp/ruby.out 2> /dev/null | |
expr=$(echo $2 | base64) | |
( | |
echo "set breakpoint pending on"; | |
echo "tb rb_funcallv" | |
echo "commands" | |
echo "call (void*)rb_eval_string_protect(\"require'base64';a=eval(Base64.decode64('$expr'));File.write('/tmp/ruby.out',a.to_s)\", (void*)0)" | |
echo "d" | |
echo "end" | |
echo "c" | |
) | gdb -p $1 &> /dev/null | |
if [ -f /tmp/ruby.out ]; then | |
cat /tmp/ruby.out | |
echo "" | |
else | |
echo "Execution failed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment