Ninja Note

Description

We were told there was a web vulnerability in our website, so we made it into a CLI! That should fix it, right?

client.pyarrow-up-right

Solution

client.py:

from requests import get, post

BASE_URL = "http://localhost:8080"

def get_path(path):
    return get(BASE_URL + path, headers={"User-Agent": "NinjaNote 13.37"})

def post_path(path, data):
    return post(BASE_URL + path, headers={"User-Agent": "NinjaNote 13.37"}, json=data)

print("Welcome to NinjaNote!\n\nVersion: 13.37\n\n")

while True:
    primary_selection = ""
    while primary_selection not in ["1", "2", "3"]:
        print("What do you want to do?\n[1] Create note\n[2] Search note\n[3] Exit")
        primary_selection = input("Your selection: ")
        if primary_selection not in ["1", "2", "3"]:
            print("Invalid selection. Try again.")
        print("\n")
    if primary_selection == "1":
        print("Creating new note")
        title = input("Title: ")
        # Hopefully this should be enough?
        note_content = input("Note content: ").replace("{", "").replace("}", "")
        res = post_path("/api/submit", {"title": title, "content": note_content}).json()
        if 'note_id' in res:
            print("Success! Your note ID is: " + res['note_id'])
        else:
            print("Error in posting your note: ", res)
    elif primary_selection == "2":
        print("Retrieving note")
        note_id = input("Note ID to retrieve: ")
        print(get_path("/api/notes/" + note_id).text)
    else:
        break
    print("\n")

To interact with the endpoint we were provided with client.py, but it has a restriction of replace curly braces, remove the restriction and run the client.

SSTI identified.

https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Server%20Side%20Template%20Injection/Python.mdarrow-up-right

Make it simpler:

circle-check

Last updated