Advertisement
Joelg4dea

edit your pastebin pastes with POWERSHELL (minimal | with comments)

Oct 22nd, 2024 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. #
  3. #
  4. # THIS IS THE VERY LEAST YOU NEED TO POST AN EDIT REQUEST TO PASTEBIN
  5. # IF YOU DON'T WANT COMMENTS GO CHECK THE MINIMAL UN-COMMENTED VERSION:
  6. # https://pastebin.com/zQjAMW8J
  7. # MINIMAL FORM OF: "Pastebin | edit your PASTE with POWERSHELL" https://pastebin.com/N4YsJQiC
  8. #
  9. #
  10. #
  11. $ptboundary = 'AAAAAAAAAAOPTIMUMPRAIHUHUHAHA' # random text to separate the request's fields
  12. $PASTE_ID = "N4YsJQiC" # your paste's url identifier (the final part of https://pastebin.com/N4YsJQiC)
  13. $MY_NEW_TEXT = "YOUR TEXT GOES HERE" # your paste's final text
  14. $COOKIE_VALUE = "YOUR COOKIE GOES HERE" # check your browser cookies and copy the 'pastebin-frontend' value
  15.  
  16.  
  17.  
  18. $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
  19. $session.Cookies.Add((New-Object System.Net.Cookie(
  20.     "pastebin-frontend",
  21.     $COOKIE_VALUE,
  22.     "/",
  23.     "pastebin.com"
  24. )))
  25.  
  26.  
  27.  
  28. # FIRST REQUEST TO GET THE csrf token (its neccesary to send the POST REQUEST of the /edit/ method)
  29. $WR = Invoke-WebRequest `
  30. -Uri "https://pastebin.com/edit/$PASTE_ID" `
  31. -WebSession $session ` # this variable will change after the request!!
  32.  
  33.  
  34.  
  35. # SEARCHING AND SAVING THE csrf token
  36. $csrf = ($WR.RawContent -split '\r?\n' | Select-String '^.*input.*?name="_csrf' -Raw) -replace '^.*value *= *"(.*?)".*$', '$1'
  37.  
  38.  
  39.  
  40. # HERE IS WHERE YOUR EDITED TEXT BELONGS
  41. # POST REQUEST's string (to edit the paste)
  42. $STRING = @(
  43.     # SEPARATOR
  44.     "--$ptboundary"
  45.     # FIELD
  46.     'Content-Disposition: form-data; name="_csrf-frontend"'
  47.     ''
  48.     $csrf # the csrf we got right before
  49.     # SEPARATOR
  50.     "--$ptboundary"
  51.     # FIELD
  52.     'Content-Disposition: form-data; name="PostForm[text]"'
  53.     # THIS HAS TO BE BLANK (PROB LIKE A SEPARATOR FOR THE FIELD. IDK) (maybe like a : or =)
  54.     ''
  55.     # THIS IS THE FINAL TEXT OF THE PASTE
  56.     # (IT CAN CONTAIN \n, \r, simbols or whatever)
  57.     # 'MY TEXT' # COMMENTED SO YOU CAN CHANGE IT WITH A VARIABLE
  58.     $MY_NEW_TEXT
  59.     # SEPARATOR
  60.     "--$ptboundary--"
  61. ) -join "`n" # join the fields and values with a newline
  62.  
  63.  
  64. <#  It's hard to understand but your final string will form something like:
  65. --AAAAAAAAAAOPTIMUMPRAIHUHUHAHA
  66. Content-Disposition: form-data; name="_csrf-frontend"
  67.  
  68. Ei3ecOPvbg9BegRBTz48Zy8N8vUzwy_aniZUoCERJmuq8kfTkQPGIk31PUW8I_FoiclrI2MHSpsn0hYszpLSK6==
  69. --AAAAAAAAAAOPTIMUMPRAIHUHUHAHA
  70. Content-Disposition: form-data; name="PostForm[text]"
  71.  
  72. YOUR TEXT GOES HERE
  73. --AAAAAAAAAAOPTIMUMPRAIHUHUHAHA--
  74. #>
  75. #
  76. # that csrf token is a fake one.
  77. #
  78. # convert the string to bytes, for the request's body
  79. $BYTES = ([System.Text.Encoding]::UTF8.GetBytes($STRING))
  80.  
  81.  
  82.  
  83. # send the post request to pastebin
  84. Invoke-WebRequest -Method Post -Uri "https://pastebin.com/edit/$PASTE_ID" `
  85. -WebSession $session `
  86. -ContentType "multipart/form-data; boundary=$ptboundary" `
  87. -Body $BYTES
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement