Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hammer cookies by adding/replacing in a tight loop
import Meddler;
import System;
import System.Text;
import System.Net.Sockets;
import System.Windows.Forms;
// You can set options for this script using the format:
// ScriptOptions("StartURL" (where {$PORT} is autoreplaced by the Meddler port number), "Optional HTTPS Certificate Thumbprint", "Random # Seed")
// public ScriptOptions("https://localhost:{$PORT}/Test2", "fc ba fd cd 07 02 14 db a6 b7 ad 37 92 a9 65 0a 75 33 4f 9a", "1234")
class Handlers
{
static function OnConnection(oSession: Session)
{
try{
if (oSession.ReadRequest()){
var oHeaders: ResponseHeaders = new ResponseHeaders();
oHeaders.Status = "200 OK";
oHeaders["Connection"] = "close";
oHeaders["Cache-Control"] = "no-cache";
if (oSession.requestHeaders.Path.indexOf(".jpg")>-1){
oHeaders["Content-Type"] = "image/jpeg";
oHeaders["Set-Cookie"] = "C"+(Fuzz.NewInteger(1,7).ToString())+"="+Fuzz.NewString('a', Fuzz.NewInteger(128,256));
oSession.WriteString(oHeaders);
oSession.WriteBytes(Fuzz.NewJPG(Fuzz.NewInteger(100,999).ToString(), 80, 60));
}
else
{
oHeaders["Content-Type"] = "text/html";
oSession.WriteString(oHeaders);
oSession.WriteString("<!doctype html>\r\n<head>\r\n<title>Cookie Hammer</title>\r\n"
+ "<script>\r\n\r\nsetInterval(function(){\r\n let a=document.cookie;\r\n if (a.length < 1) { alert('Cookie was empty\\n' + document.cookie); }\r\n"
+ "document.getElementById(\"divLen\").innerText = new Date() + ' ' + (\"Cookie Length: \" + a.length.toString());\r\n\r\n }, 1);\r\n</script>\r\n"
);
oSession.WriteString("</head>\r\n<body>\r\n\r\n");
for (var i=0; i<64; i++)
oSession.WriteString("<img onload='this.src = \"CookieRandom.jpg?"+i.toString()+"=\" + Math.random();' src=\"CookieRandom.jpg?\" />\r\n");
oSession.WriteString("\r\n<div id=\"divLen\"></div>\r\n\r\n</body>\r\n</html>");
}
}
oSession.CloseSocket();
}
catch(e)
{
// MessageBox.Show("Script threw exception\n"+e, "OnConnection Failed");
MeddlerObject.Log.LogString("Script threw exception\n"+e);
}
}
// Optional method called on compile
static function Main(){
var today: Date = new Date();
MeddlerObject.StatusText = " Rules.js was loaded at: " + today;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment