Created
May 28, 2026 23:54
-
-
Save ericlaw1979/aea1a9c7c9a737a443765087217a50ea to your computer and use it in GitHub Desktop.
Giant ranged download; script for [Meddler](https://bayden.com/meddler)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Meddler; | |
| import System; | |
| import System.Net.Sockets; | |
| import System.Windows.Forms; | |
| // Visit this script at http://127.0.0.1:8088/ | |
| class Handlers | |
| { | |
| static function OnConnection(oSession: Session) | |
| { | |
| if (oSession.ReadRequest()){ | |
| var oHeaders: ResponseHeaders = new ResponseHeaders(); | |
| MeddlerObject.Log.LogString(oSession.requestHeaders); | |
| if (oSession.urlContains("bigfile")) { | |
| var fileLen = Math.pow(2,32)+20000000000; | |
| // Base case | |
| if (!oSession.requestHeaders.Exists("Range")) { | |
| oHeaders.Status = "200 OK"; | |
| oHeaders["Connection"] = "Keep-Alive"; | |
| oHeaders["Content-Disposition"] = "attachment; filename=huge_"+ oSession.id.ToString()+".exe"; | |
| oHeaders["Content-Length"] = fileLen.ToString(); //2147483648+20gb | |
| oHeaders["ETag"] = '"Foo"'; | |
| oHeaders["Accept-Ranges"] = "bytes"; | |
| oSession.WriteString(oHeaders); | |
| MeddlerObject.Log.LogString(oHeaders); | |
| var randomJunk = Fuzz.NewByteArray(300000); | |
| for (var x=0; x<fileLen; x+=randomJunk.length){ | |
| System.Threading.Thread.Sleep(100); | |
| oSession.socket.Send(randomJunk); | |
| } | |
| } | |
| else // Chunk case | |
| { | |
| oHeaders.Status = "206 Partial"; | |
| oHeaders["Connection"] = "Keep-Alive"; | |
| oHeaders["Content-Disposition"] = "attachment; filename=huge_"+ oSession.id.ToString()+".exe"; | |
| oHeaders["ETag"] = '"Foo"'; | |
| oHeaders["Accept-Ranges"] = "bytes"; | |
| var strFrom = oSession.requestHeaders["Range"].Substring(6).TrimEnd("-"); | |
| var iFrom:Int64 = Int64.Parse(strFrom); | |
| var iChunkLen:Int64 = fileLen - iFrom; | |
| MeddlerObject.Log.LogString("!!! CHUNK DOWNLOAD FROM " + iFrom.ToString() + " of length: " + iChunkLen.ToString()); | |
| oHeaders["Content-Length"] = iChunkLen.ToString(); | |
| oHeaders["Content-Range"] = "bytes " + strFrom + "-" + (fileLen-1).ToString() + "/" + fileLen.ToString(); | |
| oSession.WriteString(oHeaders); | |
| MeddlerObject.Log.LogString(oHeaders); | |
| var randomJunk = Fuzz.NewByteArray(300000); | |
| for (var x=0; x<iChunkLen; x+=randomJunk.length){ | |
| oSession.socket.Send(randomJunk); | |
| } | |
| } | |
| } | |
| else | |
| { | |
| oHeaders.Status = "200 OK"; | |
| oHeaders["Connection"] = "close"; | |
| oHeaders["ETag"] = '"Foob"'; | |
| oHeaders["Accept-Ranges"] = "bytes"; | |
| oHeaders["content-type"] = "text/html"; | |
| oSession.WriteString(oHeaders); | |
| oSession.WriteString("<!doctype html><head><title>Download Test</title></head><body>"); | |
| oSession.WriteString("Start a giant download <a href='bigfile'>here</a>"); | |
| oSession.WriteString("</body></html>"); | |
| } | |
| } | |
| oSession.CloseSocket(); | |
| } | |
| 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