Skip to content

Instantly share code, notes, and snippets.

@slayerlab
Last active February 26, 2025 19:08
Show Gist options
  • Save slayerlab/7eeaf913fa1c3266c9681a07177d7185 to your computer and use it in GitHub Desktop.
Save slayerlab/7eeaf913fa1c3266c9681a07177d7185 to your computer and use it in GitHub Desktop.
[PoC] Modify an instance method using the built-in class type.
#!/usr/bin/env python3
# The focus here is the L#34 and L#35.
class Birthday:
def __init__(self, day=1, month=2, year=3):
self._day = day
self._month = month
self._year = year
def show(self):
return f"Day: {self._day}, Month: {self._month}, Year: {self._year}"
class Person:
def __init__(self, first='tom', last='angelripper', birthday=None):
self._first = first
self._last = last
if birthday is None:
birthday = Birthday()
self._birthday = birthday
@property
def name(self):
return f"{self._first} {self._last}\n" + self._birthday.show()
def _(*args):
retval = s._birthday._show()
return retval.replace(',', '/')
s = Person()
print('Before:',s._birthday.show())
s._birthday._show = s._birthday.show
s._birthday.show = type(s._birthday.show)(_, ())
print('After:',s._birthday.show())
@slayerlab
Copy link
Author

Output:

$ python3 instancemethod.py 
Before: Day: 1, Month: 2, Year: 3
After: Day: 1/ Month: 2/ Year: 3

@slayerlab
Copy link
Author

This PoC is helpful to understand what sqlmap does.

@slayerlab
Copy link
Author

Public after 6 years

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment