rootđź’€senseicat:~#

Hack. Eat. Sleep. Repeat!!!


Project maintained by SENSEiXENUS Hosted on GitHub Pages — Theme by mattgraham

CTF-: PwnMe2025


image


Challenges



Profile Editor


image


@app.route('/profile', methods=['GET', 'POST'])
def profile():
    if not session.get('username'):
        return redirect('/login')
    
    profiles_file = 'profile/' + session.get('username')
    profiles_file = profiles_file if profiles_file.endswith('.html') else profiles_file + '.html'

    if commonpath((app.root_path, abspath(profiles_file))) != app.root_path:
        return render_template('error.html', msg='Error processing profile file!', return_to='/profile')

    if request.method == 'POST':
        with open(profiles_file, 'w') as f:
            f.write(request.form.get('profile'))
        return redirect('/profile')
    
    profile=''
    if exists(profiles_file):
        with open(profiles_file, 'r') as f:
            profile = f.read()

    return render_template('profile.html', username=session.get('username'), profile=profile)
@app.route('/show_profile', methods=['GET', 'POST'])
def show_profile():
    if not session.get('username'):
        return redirect('/login')
    
    profiles_file = 'profile/' + session.get('username')

    if commonpath((app.root_path, abspath(profiles_file))) != app.root_path:
        return render_template('error.html', msg='Error processing profile file!', return_to='/profile')

    profile = ''
    if exists(profiles_file):
        with open(profiles_file, 'r') as f:
            profile = f.read()

    return render_template('show_profile.html', username=session.get('username'), profile=profile)

Explanation-:


profiles_file = 'profile/' + session.get('username')
    profiles_file = profiles_file if profiles_file.endswith('.html') else profiles_file + '.html'

    if commonpath((app.root_path, abspath(profiles_file))) != app.root_path:
        return render_template('error.html', msg='Error processing profile file!', return_to='/profile')

    if request.method == 'POST':
        with open(profiles_file, 'w') as f:
            f.write(request.form.get('profile'))
        return redirect('/profile')
    
    profile=''
    if exists(profiles_file):
        with open(profiles_file, 'r') as f:
            profile = f.read()
app.config['TEMPLATES_AUTO_RELOAD'] = True

Exploiting it


image

image

@app.route('/register', methods=['GET', 'POST'])
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        if username in users:
            return render_template('error.html', msg='Username already taken!', return_to='/register')  ### Template gets triggered here

image


Thanks for Reading