Skip to content

Instantly share code, notes, and snippets.

@stewartpark stewartpark/reval
Last active Jun 12, 2018

Embed
What would you like to do?
Play with a running ruby process safely
#!/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
You can’t perform that action at this time.