Results 1 to 20 of 29
Thread: Proxy Server Bypass Help
- 12-04-2011, 03:30 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Proxy Server Bypass Help
I'm creating a simple proxy server that is multi-threaded and will bypass all the host in the host array.
Please help me to my code.
I only want to use socket and streams for this:
Java Code:import java.io.*; import java.net.*; import java.util.*; public class ProxyServer extends Thread{ private ServerSocket ss; private String[] host = {"www.google.com", "www.facebook.com"}; private int remotePort = 80; public static long timeout = 30000; public ProxyServer(ServerSocket server) { this.ss = server; } public static void main(String[] args){ try{ System.out.println("Starting the Proxy Server.."); ServerSocket ss = new ServerSocket(50005); System.out.println("Proxy server started at port " + ss.getLocalPort() + ".\r\n"); for(int i = 0; i < 5; i++){ ProxyServer proxy = new ProxyServer(ss); proxy.start(); } }catch(Exception e){ System.out.println(e); } } public void run(){ try{ Socket clientSocket = ss.accept(); InputStream clientIn = clientSocket.getInputStream(); OutputStream clientOut = new BufferedOutputStream(clientSocket.getOutputStream()); for(int i = 0; i < host.length; i++){ try{ Socket serverSocket = new Socket(host[i], remotePort); System.out.println("Open connection to: " + serverSocket + "(timeout= " + timeout + " ms)\r\n"); InputStream serverIn = serverSocket.getInputStream(); OutputStream serverOut = new BufferedOutputStream(serverSocket.getOutputStream()); OpenConnection oc = new OpenConnection(clientIn, serverIn, clientOut, serverOut, clientSocket, serverSocket); oc.run(); }catch(Exception e){ System.out.println(e); } } }catch(Exception e){ System.out.println(e); } } }
Thanks in advance!Java Code:import java.io.*; import java.net.*; import java.util.*; public class OpenConnection extends Thread{ InputStream clientIn; InputStream serverIn; OutputStream clientOut; OutputStream serverOut; Socket clientSocket; Socket serverSocket; int timeout = 30000; public OpenConnection(InputStream clientIn, InputStream serverIn, OutputStream clientOut, OutputStream serverOut, Socket c, Socket s) { this.clientIn = clientIn; this.serverIn = serverIn; this.clientOut = clientOut; this.serverOut = serverOut; this.clientSocket = c; this.serverSocket = s; } public void run(){ int r0 = -1, r1 = -1, ch = -1, i = -1; long time0 = new Date().getTime(); long time1 = new Date().getTime(); try{ while(r0 != 0 || r1 != 0 || (time1 - time0) <= timeout) { while((r0 = clientIn.available()) > 0) { ch = clientIn.read(); if(ch != -1) { serverOut.write(ch); System.out.print((char)ch); } time0 = new Date().getTime(); serverOut.flush(); } while((r1 = serverIn.available()) > 0) { try{ ch = serverIn.read(); if(ch != -1) { clientOut.write(ch); } time0 = new Date().getTime(); clientOut.flush(); }catch(Exception e){ } } } }catch(Exception e){ System.out.println(e); }finally{ try{ clientIn.close(); clientOut.close(); serverIn.close(); serverOut.close(); clientSocket.close(); serverSocket.close(); }catch(Exception e){ System.out.println(e); } } } }
- 12-04-2011, 05:07 PM #2
Re: Proxy Server Bypass Help
Can you explain what the problem is with your code?
Last edited by Norm; 12-04-2011 at 05:10 PM.
- 12-04-2011, 05:25 PM #3
Re: Proxy Server Bypass Help
Cross posted at Simple Proxy Server, Bypassing. Help
- 12-05-2011, 12:27 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Re: Proxy Server Bypass Help
The problem is that the only site I can go is Google and not on Facebook. Maybe because of the for loop in the main method or the for loop in the ProxyServer.run :)
- 12-05-2011, 02:33 PM #5
Re: Proxy Server Bypass Help
Have you tried going only to the one site and does it work then?
Why do you start 5 threads?
- 12-05-2011, 03:02 PM #6
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Re: Proxy Server Bypass Help
Yes, but even if i type Welcome to Facebook - Log In, Sign Up or Learn More, the browser only goes to Google..
That for loop is for the multi thread, so that it can accept connections, the 5 is just for testing.. I can't make it while(true) {} :/
- 12-05-2011, 03:24 PM #7
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Re: Proxy Server Bypass Help
The proxy only accepts Google.com, even if I type Facebook.com . The for loop is for the threading so that it can accept multiple connection, the 5 is only for testing. I can't use while(true).
When I put the oc.run() outside the try catch, it only now allows Facebook.com . :/Last edited by jrdncchr; 12-05-2011 at 03:31 PM.
- 12-05-2011, 03:38 PM #8
Re: Proxy Server Bypass Help
You only need one ServerSocket for all your connections. When you get a connection, create a new thread and pass the socket from the connection to that thread.
- 12-05-2011, 03:51 PM #9
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Re: Proxy Server Bypass Help
Well, as you can see I only have 1 ServerSocket. :/
- 12-05-2011, 03:55 PM #10
Re: Proxy Server Bypass Help
Why do you have more than one accept call for that one server socket?
- 12-05-2011, 03:58 PM #11
Re: Proxy Server Bypass Help
Can you explain what your code is supposed to do?
The browsers are set to use your server as a proxy.
The server is started.
A browser tries to connect to a site: httP://somesite.com
The connect is sent to your server
What does your server do now???
- 12-05-2011, 04:00 PM #12
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Re: Proxy Server Bypass Help
I'm planning to thread or allow the 2 host "Google.com" and "Facebook.com" bypass the proxy. :/ but it turns out that it only allows 1?
- 12-05-2011, 04:02 PM #13
Re: Proxy Server Bypass Help
Can you explain what your code is supposed to do?
The browsers are set to use your server as a proxy.
The server is started.
A browser tries to connect to a site: httP://somesite.com
The connect is sent to your server
What does your server do now???
- 12-05-2011, 04:09 PM #14
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Re: Proxy Server Bypass Help
The browsers are set to use my server as a proxy.
I start the server at port 50005;
Wait for a browser to connect;
When the browser connect and typed any of the sites in the host[], it will allow it or bypass.
The OpenConnection will start and start streaming or reading bytes from that site.
But when the the typed site is not in the host[] it will not allow it.
That's all, all I want is to allow the server to bypass all the sites in the host[] in my proxy. :/
- 12-05-2011, 04:34 PM #15
Re: Proxy Server Bypass Help
What parts of your code works? Have you tested any of the parts by themselves to be sure that they work?
- 12-05-2011, 04:43 PM #16
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Re: Proxy Server Bypass Help
Yes they work, I think the error is that. When the socket of the server was created with the host name Google.com, the next socket of the server which is Facebook.com is not being recognized as a server that is allowed to connect to. I tried to put the oc.run() outside the try catch, and it turns out that it only allows Facebook.com :/
I can't make it that multiple servers are allowed to be bypass from the proxy.
- 12-05-2011, 04:56 PM #17
Re: Proxy Server Bypass Help
Where does your code test what the site is that the browser is trying to connect to?
It seems that it always tries to connect to the first site in the host array.
Why call oc.run() which blocks the loop instead of creating a thread and starting it?
- 12-05-2011, 05:11 PM #18
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Re: Proxy Server Bypass Help
Hmm, i'm just debugging and turns that when i put the "www.google.com" as host in the Socket serverSocket = new Socket("www.google.com", 80), it allows to bypass the site Google. That's why i tried to loop it so that all the sites in the host[] will make a socket for that site. But it turns out that it only allows that it blocks the loop.
Can you think of a code that will return the inputted site by the user in the browser into a string? Like:
String inputtedHost = clientSocket.getInetAddress().getHostName() ? I like to store the value that the user inputted in the browser, like "www.google.com"
- 12-05-2011, 05:12 PM #19
Re: Proxy Server Bypass Help
Print out everything about the socket connection and what you read from it to see what URL the user entered in the browser. The original URL must be there somewhere.
- 12-05-2011, 05:18 PM #20
Member
- Join Date
- Mar 2011
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
proxy server
By mahamudsust in forum NetworkingReplies: 3Last Post: 03-04-2013, 06:04 AM -
Proxy Server Development
By Comediant in forum Java ServletReplies: 0Last Post: 10-26-2011, 11:21 AM -
Trying to bypass proxy
By dipanshu.agrawal in forum NetworkingReplies: 2Last Post: 04-16-2010, 02:46 PM -
proxy server
By guneet singh in forum NetworkingReplies: 1Last Post: 01-18-2009, 01:06 PM -
Jakarta FTP via proxy server
By megalon in forum NetworkingReplies: 0Last Post: 07-24-2008, 10:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks