Python adventures 01

Hey amigo,

A common friend said you can help me out, you’ll be rewarded for your time - handsomely - don’t worry.

We phished some buffoon to get access, but this stands in our way to leak their entire database, it’s supposed to spit out some numbers we can use as an access code. Johnny said you’ll need Python 3.6 or 3.7 to run it (I’m not good with numbers, see if it runs FFS), and then give us the code.

import random

PASSWORD = random.weibullvariate(alpha=13, beta=37)

class InvalidUsernameException(BaseException):
    def __init__(self, invalid_username: str) -> None:
            f"'{invalid_username.format(error=self)}' "
            f"is not recognised as an authorised user, "
            f"but login is permitted with the secret key."

class InvalidPasswordException(BaseException):
    def __init__(self):
        print("Invalid password provided. Authorities have been informed.")

def grant_access():
        f"*** Access Granted! ***\n\n"
        f"  The Shirai Ryu are ninja, Liu Kang\n\n"
        f"The access code is: {PASSWORD / random.triangular()}"

def check_password(user_password: str) -> None:
    if user_password != str(PASSWORD):
        raise InvalidPasswordException()

if __name__ == "__main__":
    username = input("Username: ")
    password = PASSWORD

        if username != "the_mighty_snail":
            raise InvalidUsernameException(username)
    except InvalidUsernameException:
        password = input("Secret: ")

Hint 1

The idiot who wrote it messed up: the hard coded account doesn’t even work, because there’s a type mismatch between the passwords, so don’t bother

Hint 2

I wonder what the fuck was this guy thinking when he implemented InvalidUsernameException. I bet he showed that code around with pride and shit

Hint 3

Ah yeah, Nicky said there’s no sanitation on the username you enter, and you might be able to run some python bullshit there. Don’t care, just give me the code!


Hey @n00bi3s - is this something you’d be interested in?

1 Like

Thanks @hacker_snail! This looks very interesting! I’ll give it a shot :slight_smile:

This is what I got:

*** Access Granted! ***

The Shirai Ryu are ninja, Liu Kang

The access code is: 23.4824998086134


Well done (that was fast!) - the access code is random, just added it for fun. I hope you liked it <3

Awesome challenge. But still figured out the way how to throw that bullshit in python3 haha

This was a fantastic challenge. Took me many days to get this through. Thanks for constant support @hacker_snail ! I learnt a lot :slight_smile: Already in love with the community :slight_smile:

Maybe I’m missing the point here.

It’s supposed to spit out some numbers we can use as an access code. […] Give us the code.

This seems too simple. I saved the provided code as Then I created a second piece of code called

import challenge

That’s all it takes. I run

*** Access Granted! ***

  The Shirai Ryu are ninja, Liu Kang

The access code is: 19.388974297289792

Am I missing the point here?

Thanks @hacker_snail! That was a fantastic challenge.

Exploit in python
#!/usr/bin/env python
import subprocess
import re

if __name__ == '__main__':
   regex = re.compile("'(.+)'")

   proc = subprocess.Popen(['python3.7', './'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

   line = proc.stdout.readline().decode("utf-8")
   password = regex.findall(line)[0]

   proc.stdin.write((password + "\n").encode("utf-8"))

   lines = proc.stdout.readlines()
   print("".join([line.decode("utf-8") for line in lines]))