Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- #
- #
- # THIS IS THE VERY LEAST YOU NEED TO POST AN EDIT REQUEST TO PASTEBIN
- # IF YOU DON'T WANT COMMENTS GO CHECK THE MINIMAL UN-COMMENTED VERSION:
- # https://pastebin.com/zQjAMW8J
- # MINIMAL FORM OF: "Pastebin | edit your PASTE with POWERSHELL" https://pastebin.com/N4YsJQiC
- #
- #
- #
- $ptboundary = 'AAAAAAAAAAOPTIMUMPRAIHUHUHAHA' # random text to separate the request's fields
- $PASTE_ID = "N4YsJQiC" # your paste's url identifier (the final part of https://pastebin.com/N4YsJQiC)
- $MY_NEW_TEXT = "YOUR TEXT GOES HERE" # your paste's final text
- $COOKIE_VALUE = "YOUR COOKIE GOES HERE" # check your browser cookies and copy the 'pastebin-frontend' value
- $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
- $session.Cookies.Add((New-Object System.Net.Cookie(
- "pastebin-frontend",
- $COOKIE_VALUE,
- "/",
- "pastebin.com"
- )))
- # FIRST REQUEST TO GET THE csrf token (its neccesary to send the POST REQUEST of the /edit/ method)
- $WR = Invoke-WebRequest `
- -Uri "https://pastebin.com/edit/$PASTE_ID" `
- -WebSession $session ` # this variable will change after the request!!
- # SEARCHING AND SAVING THE csrf token
- $csrf = ($WR.RawContent -split '\r?\n' | Select-String '^.*input.*?name="_csrf' -Raw) -replace '^.*value *= *"(.*?)".*$', '$1'
- # HERE IS WHERE YOUR EDITED TEXT BELONGS
- # POST REQUEST's string (to edit the paste)
- $STRING = @(
- # SEPARATOR
- "--$ptboundary"
- # FIELD
- 'Content-Disposition: form-data; name="_csrf-frontend"'
- ''
- $csrf # the csrf we got right before
- # SEPARATOR
- "--$ptboundary"
- # FIELD
- 'Content-Disposition: form-data; name="PostForm[text]"'
- # THIS HAS TO BE BLANK (PROB LIKE A SEPARATOR FOR THE FIELD. IDK) (maybe like a : or =)
- ''
- # THIS IS THE FINAL TEXT OF THE PASTE
- # (IT CAN CONTAIN \n, \r, simbols or whatever)
- # 'MY TEXT' # COMMENTED SO YOU CAN CHANGE IT WITH A VARIABLE
- $MY_NEW_TEXT
- # SEPARATOR
- "--$ptboundary--"
- ) -join "`n" # join the fields and values with a newline
- <# It's hard to understand but your final string will form something like:
- --AAAAAAAAAAOPTIMUMPRAIHUHUHAHA
- Content-Disposition: form-data; name="_csrf-frontend"
- Ei3ecOPvbg9BegRBTz48Zy8N8vUzwy_aniZUoCERJmuq8kfTkQPGIk31PUW8I_FoiclrI2MHSpsn0hYszpLSK6==
- --AAAAAAAAAAOPTIMUMPRAIHUHUHAHA
- Content-Disposition: form-data; name="PostForm[text]"
- YOUR TEXT GOES HERE
- --AAAAAAAAAAOPTIMUMPRAIHUHUHAHA--
- #>
- #
- # that csrf token is a fake one.
- #
- # convert the string to bytes, for the request's body
- $BYTES = ([System.Text.Encoding]::UTF8.GetBytes($STRING))
- # send the post request to pastebin
- Invoke-WebRequest -Method Post -Uri "https://pastebin.com/edit/$PASTE_ID" `
- -WebSession $session `
- -ContentType "multipart/form-data; boundary=$ptboundary" `
- -Body $BYTES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement