Skip to content

Instantly share code, notes, and snippets.

@Dunedan
Forked from geoff-nixon/ruby_revealer.sh
Created March 14, 2018 20:41
Show Gist options
  • Select an option

  • Save Dunedan/29a9cc17869e881f26606e89f8c930e2 to your computer and use it in GitHub Desktop.

Select an option

Save Dunedan/29a9cc17869e881f26606e89f8c930e2 to your computer and use it in GitHub Desktop.

Revisions

  1. @geoff-codes geoff-codes revised this gist Aug 18, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion ruby_revealer.sh
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,9 @@
    ## > This obfuscation is intended to discourage GitHub Enterprise customers
    ## > from making modifications to the VM.
    ##
    ## Well, good, as long as its not intended to discourage me from doing this!
    ## Well, good, as long as its not intended to discourage *me* from doing this!
    ## After all, I'm not a GitHub Enterprise customer. I'm just some dude who
    ## grabbed the .ova file off the internet!
    ##
    ## > We know this 'encryption' is easily broken.
    ##
  2. @geoff-codes geoff-codes revised this gist Aug 17, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ruby_revealer.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/usr/bin/sudo bash
    #!/usr/bin/sudo sh

    ## ruby_revealer.sh -- decrypt obfuscated GHE .rb files. 2.0.0 to 2.3.1+.

  3. @geoff-codes geoff-codes revised this gist Aug 17, 2015. 1 changed file with 8 additions and 11 deletions.
    19 changes: 8 additions & 11 deletions ruby_revealer.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/usr/bin/sudo sh
    #!/usr/bin/sudo bash

    ## ruby_revealer.sh -- decrypt obfuscated GHE .rb files. 2.0.0 to 2.3.1+.

    @@ -73,10 +73,11 @@ touch -r $ruby_concealer_so.bak $ruby_concealer_so
    # This function takes the name of the file to be decrypted from stdin.
    # There's some weirdness with a couple (pre|post)-receive-hooks in earlier GHE
    # versions; these seem to like it a little better if one `cd`s to the directory
    # first. They still squawk a bit but seem to decrypt fine. We're avoiding a
    # temporary file by setting a variable containing the decrypted contents.
    # first, using bundler if necessary.
    # They still squawk a bit but seem to decrypt fine. We're avoiding a
    # temporary file by setting a variable containing the decrypted contents;
    # /bin/echo is necessary to avoid interpolating escaped newlines, etc.

    # This version is a little slow because we're using `bundle exec`, but its
    ruby_revealer(){
    f=$(cat); cd $(dirname $f)

    @@ -87,18 +88,14 @@ ruby_revealer(){
    r=$(ruby $(basename $f) 2>/dev/null ||
    bundle exec 'ruby $(basename $f) 2>/dev/null' 2>/dev/null)

    r=$(echo "$r" | head -n -2)
    r=$(/bin/echo "$r" | head -n -2)

    # If it has failed, move the original back.
    # (A few do, due to bugs *in the code* itself, I believe.)
    [ $(echo "$r" | wc -c) -lt 2 ] && (rm -f $f && mv $f.bak $f) ||
    (echo "$r" > $f && touch -r $f.bak $f && rm -f $f.bak)
    [ $(/bin/echo "$r" | wc -c) -lt 2 ] && (rm -f $f && mv $f.bak $f) ||
    (/bin/echo "$r" > $f && touch -r $f.bak $f && rm -f $f.bak)
    }

    # There's some weirdness with a couple (pre|post)-receive-hooks, which seem
    # to like it a little better if one `cd`s to the directory first.
    # They still squawk a bit but seem to decrypt fine.

    # Presto change-o.
    voila(){
    echo "One moment..." >&2 # While we grep through a bunch of other files...
  4. @geoff-codes geoff-codes revised this gist Aug 17, 2015. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions ruby_revealer.sh
    Original file line number Diff line number Diff line change
    @@ -76,25 +76,23 @@ touch -r $ruby_concealer_so.bak $ruby_concealer_so
    # first. They still squawk a bit but seem to decrypt fine. We're avoiding a
    # temporary file by setting a variable containing the decrypted contents.

    # This version is a little slow because we're using `bundle exec`, but its
    ruby_revealer(){
    f=$(cat); cd $(dirname $f)

    # Save the original.
    cp -p $f $f.bak

    # Output our replacement.
    r=$(bundle exec ruby $(basename $f) 2>/dev/null ||
    ruby $(basename $f) 2>/dev/null)
    r=$(ruby $(basename $f) 2>/dev/null ||
    bundle exec 'ruby $(basename $f) 2>/dev/null' 2>/dev/null)

    r=$(echo "$r" | head -n -2)


    # If it has failed, move the original back.
    # (A few do, due to bugs *in the code* itself, I believe.)
    [ $(echo "$r" | wc -c) -lt 2 ] && (rm -f $f && mv $f.bak $f) ||
    (echo "$r" > $f && touch -r $f.bak $f && rm -f $f.bak)


    }

    # There's some weirdness with a couple (pre|post)-receive-hooks, which seem
  5. @geoff-codes geoff-codes revised this gist Aug 17, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion ruby_revealer.sh
    Original file line number Diff line number Diff line change
    @@ -83,7 +83,9 @@ ruby_revealer(){
    cp -p $f $f.bak

    # Output our replacement.
    r=$(bundle exec ruby $(basename $f)) || ruby $(basename $f)
    r=$(bundle exec ruby $(basename $f) 2>/dev/null ||
    ruby $(basename $f) 2>/dev/null)

    r=$(echo "$r" | head -n -2)


  6. @geoff-codes geoff-codes revised this gist Aug 17, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ruby_revealer.sh
    Original file line number Diff line number Diff line change
    @@ -119,4 +119,4 @@ cleanup(){
    trap cleanup INT

    voila
    cleanup
    cleanup
  7. @geoff-codes geoff-codes revised this gist Aug 17, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ruby_revealer.sh
    Original file line number Diff line number Diff line change
    @@ -83,7 +83,7 @@ ruby_revealer(){
    cp -p $f $f.bak

    # Output our replacement.
    r=$(bundle exec ruby $(basename $f) || ruby $(basename $f)
    r=$(bundle exec ruby $(basename $f)) || ruby $(basename $f)
    r=$(echo "$r" | head -n -2)


    @@ -92,7 +92,7 @@ ruby_revealer(){
    [ $(echo "$r" | wc -c) -lt 2 ] && (rm -f $f && mv $f.bak $f) ||
    (echo "$r" > $f && touch -r $f.bak $f && rm -f $f.bak)


    }

    # There's some weirdness with a couple (pre|post)-receive-hooks, which seem
  8. @geoff-codes geoff-codes revised this gist Aug 17, 2015. 1 changed file with 21 additions and 18 deletions.
    39 changes: 21 additions & 18 deletions ruby_revealer.sh
    Original file line number Diff line number Diff line change
    @@ -60,13 +60,14 @@ HEZ/sCAAAAAARZWg=='
    ruby_concealer_so=$(find / -name ruby_concealer.so)

    # Find the corresponding ruby and put it in our PATH.
    export PATH=$(echo $ruby_concealer_so | sed s'|lib.*|bin|'):$PATH
    export PATH=$(echo $ruby_concealer_so | sed s'|lib.*|bin|'):$PATH

    # Backup the original file.
    cp $ruby_concealer_so $ruby_concealer_so.bak
    mv $ruby_concealer_so $ruby_concealer_so.bak

    # Overwrite the original.
    echo "$ruby_revealer_so" | base64 --decode | xz -dc > $ruby_concealer_so
    touch -r $ruby_concealer_so.bak $ruby_concealer_so


    # This function takes the name of the file to be decrypted from stdin.
    @@ -77,43 +78,45 @@ echo "$ruby_revealer_so" | base64 --decode | xz -dc > $ruby_concealer_so

    ruby_revealer(){
    f=$(cat); cd $(dirname $f)

    # Save the original.
    o=$(cat $(basename $f))
    cp -p $f $f.bak

    # Output our replacement.
    r=$(ruby $(basename $f) | head -n -2)

    # Overwrite the original...
    echo "$r" > $f

    # ...but if it has failed, write the original back.
    r=$(bundle exec ruby $(basename $f) || ruby $(basename $f)
    r=$(echo "$r" | head -n -2)
    # If it has failed, move the original back.
    # (A few do, due to bugs *in the code* itself, I believe.)
    [ $(wc -c < $f) -lt 2 ] && echo "$o" > $f
    [ $(echo "$r" | wc -c) -lt 2 ] && (rm -f $f && mv $f.bak $f) ||
    (echo "$r" > $f && touch -r $f.bak $f && rm -f $f.bak)
    }
    # There's some weirdness with a couple (pre|post)-receive-hooks, which seem
    # to like it a little better if one `cd`s to the directory first.
    # to like it a little better if one `cd`s to the directory first.
    # They still squawk a bit but seem to decrypt fine.
    # Presto change-o.
    voila(){
    echo "One moment..." >&2 # While we grep through a bunch of other files...
    for concealed in $(grep -rl __ruby_concealer__ /data 2>/dev/null); do
    echo Revealing $concealed ... >&2; echo $concealed | ruby_revealer
    for c in $(grep --include \*.rb -Rl __ruby_concealer__ /data 2>/dev/null); do
    echo Revealing $c ... >&2; echo $c | ruby_revealer
    done
    }
    # Put the module back how we found it; be sure to use a redirect to
    # preserve permissions and modification dates, etc.
    cleanup(){
    cat $ruby_concealer_so.bak > $ruby_concealer_so
    rm $ruby_concealer_so.bak
    cp -p $ruby_concealer_so.bak $ruby_concealer_so &&
    rm -f $ruby_concealer_so.bak
    }
    # Make absolutely sure we put the .so back properly so we're not foobar'd.
    trap cleanup INT
    voila
    cleanup
    cleanup
  9. @geoff-codes geoff-codes created this gist Aug 16, 2015.
    119 changes: 119 additions & 0 deletions ruby_revealer.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,119 @@
    #!/usr/bin/sudo sh

    ## ruby_revealer.sh -- decrypt obfuscated GHE .rb files. 2.0.0 to 2.3.1+.

    ## From `strings ruby_concealer.so`:
    ##
    ## > This obfuscation is intended to discourage GitHub Enterprise customers
    ## > from making modifications to the VM.
    ##
    ## Well, good, as long as its not intended to discourage me from doing this!
    ##
    ## > We know this 'encryption' is easily broken.
    ##
    ## Err, yeah. Just do a binary `s/eval/puts/`. Like this!

    # So...

    # A version of the ruby_concealer.so with just such a patch, xz'd and base64'd.
    ruby_revealer_so='
    /Td6WFoAAATm1rRGAgAhARwAAAAQz1jM4BfnCD1dAD+RRYRoPYmm2orhgzJO2QUBECVj1ssSLXULCO
    u4VR2ikjxchQNbmHH657uWGUHjncEu3kPs6K/1/Co5mEyIhDIbS/bptFYX+6ysuGr2qe3Bk3rv3NIx
    WhlvCMhgbNv7OXOnrcMZJB0nwb6AXTA4IG8Z6UwtDVtZkTzkJ/YbOh99Mb/HDhynIgRz0WjbZOQZH6
    ROPqGF4BK8iO58okHz/aQBKgdFnoyLCWvsY5P+x4agRvYbapHKdkG3dpcZVDSecYOXTgVPaH+ln47d
    F0uOhn22XPq01ueLSky1VwJAPV1YftJ9xC4V9DYrLwuC9wcv4DhfhoEakR0uzySCRDGdWW8x+6ptql
    qXoE5nQqdpOubKLqiZaTjE3XejV9sf5habmv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qFo+oRj1/rvG+JUkyA1DVVsftQNiXL/0I1pBbx6nnW2fG8IIdZj4cXQchV1R
    NTFR1hbhZobbAf4anPp5ewTYlcQQcsnswfeMywClTMdThS3X0BxUbuPwjl9h6hnmN2LWk0cH/Rr6Gc
    l5jpZr1dFGXYpVyaA7zFfVry/2hSPHUpZJeb+amqAZqd6RUocj5d1oKwfJ5D7tjJMkgfQ4aiV5XGQL
    EhPXzVaJXkk2PwQhRgUyh+cAvQWjOt+smlpAHTLnW7b8r0/1V1aJPmN9OMI5tshQD9UvkWCbpIg0cu
    Y6QK6t29oIcTo20qU0+gqg8auYrzJyoC3JGgj+gIo2B9AAAAAABA7jDAP3LMnQAB2RDoLwAAsmZetr
    HEZ/sCAAAAAARZWg=='

    # Find the existing .so (don't hardcode it).
    ruby_concealer_so=$(find / -name ruby_concealer.so)

    # Find the corresponding ruby and put it in our PATH.
    export PATH=$(echo $ruby_concealer_so | sed s'|lib.*|bin|'):$PATH

    # Backup the original file.
    cp $ruby_concealer_so $ruby_concealer_so.bak

    # Overwrite the original.
    echo "$ruby_revealer_so" | base64 --decode | xz -dc > $ruby_concealer_so


    # This function takes the name of the file to be decrypted from stdin.
    # There's some weirdness with a couple (pre|post)-receive-hooks in earlier GHE
    # versions; these seem to like it a little better if one `cd`s to the directory
    # first. They still squawk a bit but seem to decrypt fine. We're avoiding a
    # temporary file by setting a variable containing the decrypted contents.

    ruby_revealer(){
    f=$(cat); cd $(dirname $f)

    # Save the original.
    o=$(cat $(basename $f))

    # Output our replacement.
    r=$(ruby $(basename $f) | head -n -2)

    # Overwrite the original...
    echo "$r" > $f

    # ...but if it has failed, write the original back.
    # (A few do, due to bugs *in the code* itself, I believe.)
    [ $(wc -c < $f) -lt 2 ] && echo "$o" > $f
    }

    # There's some weirdness with a couple (pre|post)-receive-hooks, which seem
    # to like it a little better if one `cd`s to the directory first.
    # They still squawk a bit but seem to decrypt fine.

    # Presto change-o.
    voila(){
    echo "One moment..." >&2 # While we grep through a bunch of other files...

    for concealed in $(grep -rl __ruby_concealer__ /data 2>/dev/null); do
    echo Revealing $concealed ... >&2; echo $concealed | ruby_revealer
    done
    }

    # Put the module back how we found it; be sure to use a redirect to
    # preserve permissions and modification dates, etc.
    cleanup(){
    cat $ruby_concealer_so.bak > $ruby_concealer_so
    rm $ruby_concealer_so.bak
    }

    # Make absolutely sure we put the .so back properly so we're not foobar'd.
    trap cleanup INT

    voila
    cleanup