0

Let's say I have an object, called myMD5, like this:

<md5 HASH object @ 0xb79b9860>

And here is dir(myMD5):

['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'block_size', 'copy', 'digest', 'digest_size', 'digestsize', 'hexdigest', 'name', 'update']

I want to get the hash string, and to do that I need to call myMD5.hexdigest(). The problem is that I'm actually making a challenge (called PyJail) and the use of the character dot (.) is forbidden.

So, I need to call this method by another way. Is there any way to call it like a function ? Something like this:

hexdigest(myMD5)

I tried to do this, but it does not work:

getattr(myMD5, dir(myMD5)[-3]) # returns <classmethod object at 0xb79b998c>

PS; Other elements are also forbidden by the challenge, like using quotes (', "), using import statements, using things like exec or eval, etc.

qux
  • 45
  • 1
  • 6

1 Answers1

0

The getattr(myMD5, dir(myMD5)[-3]) returns the method to call, on the object, then you just need to run the method using the parenthesis () :

myMD5 = md5('fooBar123'.encode("utf-8"))
hexDigestForMyMD5 = getattr(myMD5, dir(myMD5)[-3])

print(hexDigestForMyMD5())                           # dab589b4623e03507d4f094605813ff3
print(md5('fooBar123'.encode("utf-8")).hexdigest())  # dab589b4623e03507d4f094605813ff3

Or from Calling a function of a module by using its name (a string) you can shorten to

  • getattr(myMD5, dir(myMD5)[-3])()
  • getattr(myMD5, 'hexdigest')() as this doesn't return a dot
azro
  • 35,213
  • 7
  • 25
  • 55