#!/usr/bin/python3
from flask import Flask, request, render_template, g
import sqlite3
import os
import binascii
app = Flask(__name__)
app.secret_key = os.urandom(32)
try:
FLAG = open('./flag.txt', 'r').read()
except:
FLAG = '[**FLAG**]'
DATABASE = "database.db"
if os.path.exists(DATABASE) == False:
db = sqlite3.connect(DATABASE)
db.execute('create table users(userid char(100), userpassword char(100));') //테이블에 데이터 추가
db.execute(f'insert into users(userid, userpassword) values ("guest", "guest"),
("admin", "{binascii.hexlify(os.urandom(16)).decode("utf8")}");') //"guest" "guest"와 "admin" "{~~}"로 두개의 데이터를 만듬
db.commit()
db.close()
def get_db():
db = getattr(g, '_database', None)
if db is None:
db = g._database = sqlite3.connect(DATABASE)
db.row_factory = sqlite3.Row
return db
def query_db(query, one=True):
cur = get_db().execute(query)
rv = cur.fetchall()
cur.close()
return (rv[0] if rv else None) if one else rv
@app.teardown_appcontext
def close_connection(exception):
db = getattr(g, '_database', None)
if db is not None:
db.close()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return render_template('login.html')
else:
userid = request.form.get('userid')
userpassword = request.form.get('userpassword')
res = query_db(f'select * from users where userid="{userid}" and userpassword="{userpassword}"')
if res:
userid = res[0] //데이터의 첫번째 값이 userid
if userid == 'admin': >>admin일때 flag가 나온다.
return f'hello {userid} flag is {FLAG}'
return f'<script>alert("hello {userid}");history.go(-1);</script>'
return '<script>alert("wrong");history.go(-1);</script>'
app.run(host='0.0.0.0', port=8000)
id admin "or " 1
pw 1 "or" 1 //""을 사용하므로
왜 guest로 로그인했다고 뜰까?????
if 에서 왜 'admin'을 갑자기 썼을까????
띄어쓰기를 하면 값에 다 들어간다
그래서 id admin"dlfjsadif
pw dlfijdaf
이렇게 하면 된다...허무하다...
'보안공부 > 워게임' 카테고리의 다른 글
XSS game 1,2,3,4 (0) | 2021.05.28 |
---|---|
LordofSQLInjection 1,2,3 (0) | 2021.05.27 |
wargame[2]csrf-1 (0) | 2021.05.22 |
wargame [1] file-download-1 (0) | 2021.05.20 |
워게임 (0) | 2021.05.07 |