package generell; import java.net.*; import java.io.*; import org.bouncycastle.util.encoders.Hex; import org.bouncycastle.crypto.BufferedBlockCipher; import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; import org.bouncycastle.crypto.modes.CBCBlockCipher; import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.crypto.CryptoException; import java.util.Random; import java.util.zip.GZIPOutputStream; import java.sql.*; import java.util.GregorianCalendar; import java.util.logging.Logger; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; import generell.FindXmlHandler; public class ProxyServerThread extends Thread { private Socket socket = null; private byte[] cipherText = null; private String privateKey ="380971de720bf96f51d372441d4cacf3"; private int id = 0; private String[] searchTerm; private String token ="345Dgsdfg54534gdfghsgfhSDF8452wtHDFGHWG345tGD"; private String mediaFile; private String search; private String cd = "v=1009;77.247.178.21:9923:8;77.247.178.21:9923:8;"; private int cdv; private int cdu = 0; private int[] ports = {3383, 3384}; private int sourceLimit = 15; private int strikeLimit = 20; private Logger searchLog; private FindXmlHandler myXmlHandler; public ProxyServerThread(Socket socket, int sourceLimit, int strikeLimit, String privateKey, String token, String cd, int[] ports, Logger searchLog) { super("ProxyServerThread"); this.socket = socket; this.sourceLimit = sourceLimit; this.strikeLimit = strikeLimit; this.privateKey = privateKey; this.token = token; this.cd = cd; this.ports=ports; cdv = Integer.parseInt(cd.substring(2,cd.indexOf(";"))); //cdv = 1010; //System.out.println("cdv: "+cdv); this.searchLog = searchLog; } public void run() { try { GZIPOutputStream out = new GZIPOutputStream(socket.getOutputStream()); //PrintWriter out = new PrintWriter(socket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); String inputLine, outputLine; String outSt=""; inputLine = in.readLine(); String[] cryptText= inputLine.split("##"); outputLine = performDecrypt(Hex.decode(privateKey.getBytes()), cryptText[2]); //System.out.println(outputLine); if(outputLine.startsWith("")){ //if(outputLine.contains("FIND")){ outputLine = outputLine.substring(11); outputLine = outputLine.trim(); //System.out.println(outputLine); try{ myXmlHandler = ( FindXmlHandler ) fromString( outputLine ); }catch(Exception e){ System.out.println(e); } //myXmlHandler = prepareFindXml("outputLine"); System.out.println("servicetype: "+myXmlHandler.getServiceTyp()); System.out.println("clientversion: "+myXmlHandler.getClientVersion()); System.out.println("xmlversion: "+myXmlHandler.getXmlVersion()); System.out.println("searchtext: "+myXmlHandler.getSearchText()); System.out.println("media: "+myXmlHandler.getMedia()); System.out.println("key: "+myXmlHandler.getKey()); System.out.println("language: "+myXmlHandler.getLanguage()); System.out.println("android: "+myXmlHandler.getAndroid()); this.search = myXmlHandler.getSearchText(); this.mediaFile = myXmlHandler.getMedia(); if(makeFind()){ outSt = (id+"##1234567Have a lot of fun with BuzzerStar www.BuzzerStar.com"); //if(cdv > cdu){ // outSt = outSt+"##"+cd; // } }else{ outSt = (-1+"##1234567Sorry temporarily no server available please try later"); } //} }else{ this.searchTerm = outputLine.split("##"); if(searchTerm[0].equals("find")){ Random ran = new Random(); this.id = ran.nextInt(9999999); //System.out.println("find id :" +id +" balance ver: "+ searchTerm[6]); cdu = Integer.parseInt(searchTerm[6]); //System.out.println("cdu : "+ cdu +" cdv : "+ cdv); this.search = searchTerm[1]; this.mediaFile = searchTerm[2]; //System.out.println(searchTerm[6]); //if(licenceManagment(searchTerm[3])){ if(makeFind()){ outSt = (id+"##1234567Have a lot of fun with BuzzerStar www.BuzzerStar.com"); if(cdv > cdu){ outSt = outSt+"##"+cd; } }else{ outSt = (-1+"##1234567Sorry temporarily no server available please try later"); } //}else{ // outSt = (-1+"##1234567Your lisence has exspired. Please visit www.BitJoe.com for more information"); //} }else if(searchTerm[0].equals("result")){ this.id=Integer.parseInt(searchTerm[2]); if(searchTerm[6].equals("9865") ){ System.out.println("Android"); this.strikeLimit = this.strikeLimit * 2; } //System.out.println("result id :" +id); //System.out.println(); outSt = makeResult(); } } out.write(outSt.getBytes()); out.close(); in.close(); socket.close(); } catch (IOException e) { e.printStackTrace(); } } private static Object fromString( String s ) throws IOException ,ClassNotFoundException { byte [] data = Base64Coder.decode( s ); ObjectInputStream ois = new ObjectInputStream( new ByteArrayInputStream( data ) ); Object o = ois.readObject(); ois.close(); return o; } private FindXmlHandler prepareFindXml(String xml){ FindXmlHandler myXmlHandler = null; try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); StringReader sr = new StringReader(xml); myXmlHandler = new FindXmlHandler(); saxParser.parse(new InputSource(sr), myXmlHandler); //System.out.println("searchtext: "+myXmlHandler.getSearchText()); /*System.out.println(myXmlHandler.getServiceTyp()); System.out.println(myXmlHandler.getClientVersion()); System.out.println(myXmlHandler.getXmlVersion()); System.out.println(myXmlHandler.getSearchText()); System.out.println(myXmlHandler.getMedia()); System.out.println(myXmlHandler.getKey()); System.out.println(myXmlHandler.getLanguage()); System.out.println(myXmlHandler.getAndroid());*/ //return myXmlHandler; } catch (Exception e) { System.out.println("Error "+e.getMessage()); e.printStackTrace(); } return myXmlHandler; } private final String performDecrypt(byte[] key, String st){ cipherText = Hex.decode(st); BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine())); cipher.init(false, new KeyParameter(key)); byte[] rv = new byte[cipher.getOutputSize(cipherText.length)]; int oLen = cipher.processBytes(cipherText, 0, cipherText.length, rv, 0); try { cipher.doFinal(rv, oLen); } catch (CryptoException ce) { System.out.println(ce.toString()); } return new String(rv).trim(); } private boolean makeFind(){ boolean phexIsSearching = false; PrintWriter phexOut = null; //BufferedReader phexIn = null; for(int i = 0; i < ports.length; i++){ boolean ok = true; Socket phexSocket = null; try { phexSocket = new Socket("127.0.0.1", ports[i]); phexOut = new PrintWriter(phexSocket.getOutputStream(), true); //phexIn = new BufferedReader(new InputStreamReader(phexSocket.getInputStream())); } catch (UnknownHostException e) { //System.err.println("Don't know about host: Phex."); //return false; ok= false; } catch (IOException e) { //System.err.println("Couldn't get I/O for the connection to: Phex."); ok = false; } //String fromServer; /*try{ while ((fromServer = phexIn.readLine()) != null) { System.out.println("Phex: " + fromServer); } }catch(IOException e){ System.err.println("Couldn't get an answer from Phex"); return false; }*/ if(ok){ phexIsSearching = true; fileTypes(); String findPhex = "find "+ id+" 0 9999999999 Any "+token+" "+search+" "+mediaFile; phexOut.println(findPhex); phexOut.close(); System.out.println("Search initialized: "+ findPhex +" on port: "+ ports[i] ); searchLog.info(myXmlHandler.getSearchText()); }else{ System.out.println("Search not initialized: on port: "+ ports[i] ); } try{ if(phexSocket != null){ phexSocket.close(); } }catch(IOException e){ } } //fromServer = null; if(phexIsSearching){ return true; }else{ return false; } } private String makeResult(){ //for(int i =0; i < searchTerm.length; i++){ //System.out.println(searchTerm[i]); ResultBase resultBase = new ResultBase(sourceLimit, strikeLimit); StringBuffer sb = new StringBuffer(); for(int k = 0; k < ports.length; k++){ boolean ok = true; Socket phexSocket = null; PrintWriter phexOut = null; BufferedReader phexIn = null; try { phexSocket = new Socket("127.0.0.1", ports[k]); phexOut = new PrintWriter(phexSocket.getOutputStream(), true); phexIn = new BufferedReader(new InputStreamReader(phexSocket.getInputStream())); } catch (UnknownHostException e) { //System.err.println("Don't know about host: Phex."); //return "Server not availible"; ok = false; } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: Phex on: "+ ports[k]); ok = false; } if(ok){ String resultPhex = "result "+ id+" "+token; phexOut.println(resultPhex); System.out.println("Result initialized: "+ resultPhex); String fromServer; String[] results; //String tempo = ""; String[] tmp = null; String SHA1 =""; String SHA12=""; String size =""; String ipp=""; String index1=""; String index2=""; String name =""; //int count = 0; try{ while((fromServer = phexIn.readLine()) != null) { //System.out.println(fromServer); //fromServer ="280;!$#%&TTD24S5DTB5KSOVHHXDIUJ54VALC4P6Y;!$#%&5709824;!$#%&672;!$#%&24.70.153.172:20315;!$#%&Paris Hilton - Nothing In this World.mp3\\n280;!$#%&TTD24S5DTB5KSOVHHXDIUJ54VALC4P6Y;!$#%&5709824;!$#%&672;!$#%&24.70.153.172:20315;!$#%&Paris Hilton - Nothing In this World.mp3\\n350;!$#%&W4HJPIHNBWTGTVFOOCFV6II6CHPMMLVP;!$#%&4297783;!$#%&898;!$#%&67.180.142.243:49245;!$#%&guccimane - (ft._rick_ross_young_jeezy)-paris_hilton.mp3"; if(!fromServer.equals("")){ results = fromServer.split("\\\\n"); //System.out.println("Results insges: "+results.length); for(int i = 0 ; i < results.length; i++){ //System.out.println(results[i]); //System.out.println("Runde: " + i); //System.out.println("++++++++++++++++++++++++++++++++++"); tmp = results[i].split(";!\\$#%&"); for(int j = 0; j < tmp.length; j++){ if(j == 0){ index1 = tmp[j]; //System.out.println("Score: "+index1); }else if(j == 1){ SHA1 = tmp[j]; //System.out.println("SHA1: "+SHA1); }else if(j == 2){ size = tmp[j]; //System.out.println("size: "+ size); }else if(j == 3){ index2 = tmp[j]; //System.out.println("Fileindex: "+ index2); }else if(j == 4){ ipp = tmp[j]; //System.out.println("ipp: "+ ipp); }else if(j == 5){ name = tmp[j]; //System.out.println("name: "+ name); } } resultBase.setResult(SHA1, size ,name, index1, index2, ipp); } } } }catch(IOException e){ System.err.println("Couldn't get an answer from Phex on port: "+ports[k] ); //return "Server not availible"; } phexOut.close(); try{ phexIn.close(); phexSocket.close(); }catch(IOException e){ } fromServer = null; } } sb=resultBase.getAllResults(); return sb.toString(); } public void fileTypes(){ final String[] VIDEO_FILE_TYPES ={"3gp","mpg","avi","wmv","mp4","rm","mpeg","mov","wmm","wmf","ram","ogm","vivo","asx","flv","fla","swf","f4v"}; final String[] PICTURE_FILE_TYPES ={"jpg","jpeg","png","gif","bmp","tiff","svg","jpa","tif","thm"}; final String[] MUSIK_FILE_TYPES ={"mp3","wma","mp2","midi","mid","wav","aac","amr","wave","flac","smaf","mld","ogg","mmf","aiff","rma","ape","mpc", "3gp"}; final String[] JAVA_FILE_TYPES ={"jar","class","jad","sis","sisx", "apk", "cod"}; final String[] DOK_FILE_TYPES ={"txt","pdf","rtf","xls","xlsx","doc","docx","ppt","pptx","xml","html","htm","xhtml","odt","sxw","ods","sxc","odp","sxi"}; String tmp = mediaFile.substring(1); if(mediaFile.startsWith("v")){ mediaFile = "-filetype"; for(int i = 0; i < tmp.length() ; i++){ if(tmp.charAt(i)=='1'){ mediaFile = mediaFile +" "+VIDEO_FILE_TYPES[i]; } } }else if(mediaFile.startsWith("b")){ mediaFile = "-filetype"; for(int i = 0; i < tmp.length() ; i++){ if(tmp.charAt(i)=='1'){ mediaFile = mediaFile +" "+PICTURE_FILE_TYPES[i]; } } }else if(mediaFile.startsWith("m")){ mediaFile = "-filetype"; for(int i = 0; i < tmp.length() ; i++){ if(tmp.charAt(i)=='1'){ mediaFile = mediaFile +" "+MUSIK_FILE_TYPES[i]; } } }else if(mediaFile.startsWith("j")){ mediaFile = "-filetype"; for(int i = 0; i < tmp.length() ; i++){ if(tmp.charAt(i)=='1'){ mediaFile = mediaFile +" "+JAVA_FILE_TYPES[i]; } } }else if(mediaFile.startsWith("d")){ mediaFile = "-filetype"; for(int i = 0; i < tmp.length() ; i++){ if(tmp.charAt(i)=='1'){ mediaFile = mediaFile +" "+DOK_FILE_TYPES[i]; } } } } private boolean licenceManagment(String web_up_MD5){ Connection conn; String sql = ""; try{ conn = ConnectionManager.holeVerbindung("root", "###########99");//21 //conn = ConnectionManager.holeVerbindung("bitjoe", "bitjoe_java");//74 //System.out.println("Connection: "+ conn); }catch(Exception ex){ System.out.println("Fehler Datenbank Anbindung"); //ex.printStackTrace(); return true; } try{ Statement statement = conn.createStatement(); sql = "SELECT CURDATE(),`account_valid_until` FROM `bitjoe`.`bjparis_new` WHERE `web_up_MD5` ='"+web_up_MD5+"';"; ResultSet rs = statement.executeQuery(sql); if(rs.next()){ if(rollDateOneDay(rs.getDate(1)).before(rs.getDate(2))){ System.out.println("Date valid"); if(conn != null){ ConnectionManager.gibVerbindungFrei(conn); } return true; }else{ System.out.println("Date not valid!!"); if(conn != null){ ConnectionManager.gibVerbindungFrei(conn); } return false; } //System.out.println("now : "+rs.getDate(1)); //System.out.println("curdate: "+rs.getDate(2)); }else{ System.out.println("Not in Database!!"); if(conn != null){ ConnectionManager.gibVerbindungFrei(conn); } return false; } }catch(SQLException sqlex){ System.out.println("fehler beim lesen in Datenbank"); //sqlex.printStackTrace(); return true; } } public static Date rollDateOneDay( Date startDate){ GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate); gc.add(gc.DATE, 1); return new java.sql.Date(gc.getTime().getTime()); } }