<html>
<head>
<title>cookietester Source</title>
</head>
<body>
<plaintext>
cookietester.ctf

#!/bin/sh /ss/bin/ss.exe
<%
    response = Response()
    response.isBuffered(true)
%>
<html>
    <head>
        <title>Cookie Tester</title>
    </head>
    <body>

		<h1>Cookie Tester</h1>
		<hr>

		<%
			action = Request().Form("action")
			
			if action <> null then
				action = action.toLowerCase()

				if action = "set cookie" then
					key = Request().Form("key")
					if key <> null then
						key = key.trim()

						if key.length() > 0 then
							value = Request().Form("value")
							if value = null then
								value = ""
							else
								value = value.trim()
							end
							response.Cookies(key, value)
		%>
		Cookie to add or update:<br>
		<%
							Response().println(key + " = [" + value + "]<p>")
						end
					end
				elseif action = "remove cookie" then
					key = Request().Form("key")
					if key <> null then
						key = key.trim()

						if key.length() > 0 then
							cookie = Cookie(key, "")
							cookie.setExpires(0)
							response.Cookies(cookie)
		%>
		Cookie to remove:<br>
		<%
							Response().println(key + "<p>")
						end
					end
				end
			end

			println("Cookies received from browser:<br>")

			cookies = Request().Cookies()
			if cookies = null then
				print("None.<br>")
			else
				keys = cookies.keys()
				do while keys.hasMoreElements()
					id = keys.nextElement().toString()
					println(id + " = [" + cookies.get(id) + "]<br>")
				loop
			end

			response.isBuffered(false)
		%>

		<hr>

		<form action="./cookietester.ctf" method="get">
		Key:
		<input type="text" name="key" value="">
		<br>
		Value:
		<input type="text" name="value" value="">
		<p>
		<input type="submit" name="action" value="Set Cookie">
		<input type="submit" name="action" value="Remove Cookie">
		</form>

	</body>
</html>

