Last active
September 16, 2017 01:13
-
-
Save Decstasy/e930d01d41a0b7793573f319165f9412 to your computer and use it in GitHub Desktop.
Unset a readonly variable in bash. ITS JUST A PROOF OF CONCEPT! DONT USE THIS FOR REAL, ITS NASTY!!!
This file contains 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
#!/bin/bash | |
# Dennis Ullrich | |
# [email protected] | |
# 2017-06-17 | |
# Unset readonly variable in bash | |
# ITS JUST A PROOF OF CONCEPT! DONT USE THIS FOR REAL, ITS NASTY!!! | |
readonly testvar="Bla bla" | |
unset testvar | |
#./test.sh: line 5: unset: testvar: cannot unset: readonly variable | |
echo "Content of testvar: \"$testvar\"" | |
# Call the bash internal function via GNU Debugger | |
# Source definition at line 3168 of file variables.c.: | |
# int unbind_variable ( char * name ) const | |
# { | |
# SHELL_VAR *v, *nv; | |
# int r; | |
# | |
# v = var_lookup (name, shell_variables); | |
# nv = (v && nameref_p (v)) ? find_variable_nameref (v) : (SHELL_VAR *)NULL; | |
# | |
# r = nv ? makunbound (nv->name, shell_variables) : makunbound (name, shell_variables); | |
# return r; | |
# } | |
# Let's use the knowledge (root user only or add sudo) | |
_unset(){ | |
type gdb >/dev/null || return false | |
cat << EOH| gdb >/dev/null | |
attach $$ | |
call unbind_variable("${1}") | |
detach | |
EOH | |
# End of Hack ;) | |
} | |
_unset testvar | |
echo "Content of testvar: \"$testvar\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment