Skip to content

Instantly share code, notes, and snippets.

@AnisBoss
Created January 7, 2025 17:52
Show Gist options
  • Save AnisBoss/c8b75d1adbed76d3c011891baa169f38 to your computer and use it in GitHub Desktop.
Save AnisBoss/c8b75d1adbed76d3c011891baa169f38 to your computer and use it in GitHub Desktop.

Revisions

  1. AnisBoss created this gist Jan 7, 2025.
    80 changes: 80 additions & 0 deletions Obfuscate.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    #Author Anis_Boss
    #!/bin/bash
    zero='${#}'
    one='${##}'
    two='$((${##}<<${##}))'
    three='$(($((${##}<<${##}))#${##}${##}))'
    four='$((((${##}<<${##}))<<${##}))'
    five='$(($(($((${##}<<${##}))<<${##}))#${##}${##}))'
    six='$(($(($((${##}<<${##}))#${##}${##}))<<${##}))'
    seven='$(($(($(($((${##}<<${##}))#${##}${##}))<<${##}))#${##}${##}))'
    eight='$(($(($(($(($((${##}<<${##}))#${##}${##}))<<${##}))#${##}${##}))#${##}${##}))'
    nine='$(($(($(($(($(($((${##}<<${##}))#${##}${##}))<<${##}))#${##}${##}))#${##}${##}))#${##}${##}))'

    #convert char to octal
    function char_to_oct(){
    echo $(showkey -a <<<$(echo $1) 2>/dev/null|grep 0x|head -1|awk '{ print $2}'|tail -c +2|head -c -1)
    }
    #change number to its correspondance
    function iterate_numbers(){
    case $1 in
    0)
    echo $zero
    ;;
    1)
    echo $one
    ;;
    2)
    echo $two
    ;;
    3)
    echo $three
    ;;
    4)
    echo $four
    ;;
    5)
    echo $five
    ;;
    6)
    echo $six
    ;;
    7)
    echo $seven
    ;;
    8)
    echo $eight
    ;;
    9)
    echo $nine
    ;;
    esac
    }

    #construct the obfuscated command that solves the jail/restricted env
    obfuscated_cmd=""
    read -p "Enter command to run in jail " cmd
    for (( i=0; i<${#cmd}; i++ ));
    do
    if [ "${cmd:$i:1}" == " " ]
    then
    obfuscated_cmd+=','
    space_found=true
    continue
    fi
    octal_value=$(char_to_oct "${cmd:$i:1}")
    obfuscated_cmd+="\$'\\\\"
    for (( j=0; j<${#octal_value}; j++ ));
    do
    obfuscated_cmd+=$(iterate_numbers "${octal_value:$j:1}")
    done
    obfuscated_cmd+="'"
    done
    if [ "${space_found}" = true ]
    then
    obfuscated_cmd="bash -c \"{"${obfuscated_cmd}"}\""
    else
    obfuscated_cmd="bash -c \""${obfuscated_cmd}"\""
    fi
    echo "Copy this command into the jail/filtered area : "
    echo "$obfuscated_cmd"