Created
February 15, 2017 14:37
-
-
Save endofline/cb8b4437c8db25bb3b0cd70399ee4940 to your computer and use it in GitHub Desktop.
subverting imported libraries
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
# test_a.py | |
# in the bot, this represents the new hangups library | |
this_is_a_constant = 'ABCD' | |
def print_constant(): | |
print(repr(this_is_a_constant)) | |
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
# test_b.py | |
# in the bot, this represents the plugin | |
import test_a |
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
# test_c.py | |
# in the bot, this file is the plugin loader | |
import test_b # plugin is loaded | |
import test_d # we replace the test_a module inside the plugin with this in EXAMPLE 2 | |
# EXAMPLE 1: replace constant | |
# setattr(test_b.test_a, 'this_is_a_constant', 'no longer constant'); | |
# EXAMPLE 2: replace module | |
# setattr(test_b, 'test_a', test_d) # replaces module with another one | |
test_b.test_a.print_constant() | |
# in example 1, this prints 'no longer constant' | |
# in example 2, this prints '3.142' |
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
# test_d.py | |
# in the bot, this replaces new hangups (test_a.py) with the compatibility layer | |
def print_constant(): | |
print('3.142'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment