Created
November 2, 2017 17:44
-
-
Save akwodkiewicz/4148b0206a908e2a5f522c553dd5f2a8 to your computer and use it in GitHub Desktop.
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
import os | |
import requests | |
import qrcode | |
from PIL import Image | |
from bs4 import BeautifulSoup | |
BASE_URL = 'https://easyweb.workshop.codisec.com' | |
TEMPLATE_IMG = 'template.png' | |
USER = 'andrzej' | |
PASSWORD = 'andrzej' | |
SESSION = requests.session() | |
def create_user(username, password): | |
r = SESSION.post(BASE_URL+'/register', | |
data={"username":username, | |
"password":password, | |
"repeat_password":password} | |
) | |
soup = BeautifulSoup(r.text, 'html.parser') | |
if soup.findAll("div", {"class":"alert-success"}): | |
print("User registered successfully ({}:{})".format(username, password)) | |
elif soup.findAll("div", {"class":"alert-danger"}): | |
raise Exception("User register error ({})".format(username)) | |
else: | |
raise Exception("Undefined register behaviour") | |
def login(username, password): | |
r = SESSION.post(BASE_URL+'/login', | |
data={"username":username, | |
"password":password} | |
) | |
soup = BeautifulSoup(r.text, 'html.parser') | |
if soup.findAll("div", {"class":"alert-danger"}): | |
raise Exception("Login error ({})".format(username)) | |
else: | |
print("Login successful") | |
def download_ticket_template(): | |
r = SESSION.get(BASE_URL+'/free_ticket', stream=True) | |
with open('TEMPLATE_IMG', 'wb') as f: | |
for chunk in r.iter_content(chunk_size=100): | |
f.write(chunk) | |
def check_ticket(ticket_path): | |
files = {'file': open(ticket_path, 'rb')} | |
r = SESSION.post(BASE_URL+'/validate', | |
files=files) | |
print(r.content) | |
def main(): | |
#create_user(USER, PASSWORD) | |
login(USER, PASSWORD) | |
download_ticket_template() | |
check_ticket(os.path.join(os.path.dirname(__file__), TEMPLATE_IMG)) | |
if __name__ == '__main__': | |
main() | |
''' | |
OUTPUT: | |
Login successful | |
b'<html>\n <head>\n <title>Internal Server Error</title>\n </head>\n <body>\n <h1><p>Internal Server Error</p></h1>\n \n </body>\n</html>\n' | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment