Git Product home page Git Product logo

webhacking-cookie.01's Introduction

Webhacking-cookie.01

image #!/usr/bin/python3 from flask import Flask, request, render_template, make_response, redirect, url_for

app = Flask(name)

try: FLAG = open('./flag.txt', 'r').read() except: FLAG = '[FLAG]'

users = { 'guest': 'guest', 'user': 'user1234', 'admin': FLAG }

this is our session storage

session_storage = { }

@app.route('/') def index(): session_id = request.cookies.get('sessionid', None) try: # get username from session_storage username = session_storage[session_id] except KeyError: return render_template('index.html')

return render_template('index.html', text=f'Hello {username}, {"flag is " + FLAG if username == "admin" else "you are not admin"}')

@app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'GET': return render_template('login.html') elif request.method == 'POST': username = request.form.get('username') password = request.form.get('password') try: # you cannot know admin's pw pw = users[username] except: return '<script>alert("not found user");history.go(-1);</script>' if pw == password: resp = make_response(redirect(url_for('index')) ) session_id = os.urandom(32).hex() session_storage[session_id] = username resp.set_cookie('sessionid', session_id) return resp return '<script>alert("wrong password");history.go(-1);</script>'

@app.route('/admin') def admin(): # what is it? Does this page tell you session? # It is weird... TODO: the developer should add a routine for checking privilege return session_storage

if name == 'main': import os # create admin sessionid and save it to our storage # and also you cannot reveal admin's sesseionid by brute forcing!!! haha session_storage[os.urandom(32).hex()] = 'admin' print(session_storage) app.run(host='0.0.0.0', port=8000)

// /login 를 /admin 으로 수정한다-> app.route가 admin이기 때문!

image

// /admin을 경로에 입력하면 해당 창이 나오게된다. 이때 쿠키의 세션 코드를 guest 또는 user 계정으로 로그인하여 이 계정들의 세션값에 저장하면 admin계정으로 로그인 성공! image

//flag를 획득하게 된다.

webhacking-cookie.01's People

Contributors

wjdgkdms avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.