fengyouchao / sockslib Goto Github PK
View Code? Open in Web Editor NEWA Java library of SOCKS5 protocol including client and server
License: Apache License 2.0
A Java library of SOCKS5 protocol including client and server
License: Apache License 2.0
It would be amazing if you add some great java docs & just a proper wiki on how to use the library with java
Because right now I had to check the src of esocks but it is outdated because it is based on fucksocks(before it was renamed to sockslib) & I couldn't find a better socks library to implement a socks5 proxy server with java
How to use the Socks5 client with a http client lib?
Thanks
socks5 测试通过,完美,但是这边需要C++版本的库
In some rare cases, getBytes()
is null
triggering this. I haven't looked at the details of when this happens exactly.
java.lang.NullPointerException: null
at sockslib.server.msg.CommandMessage.getBytes(CommandMessage.java:142)
at sockslib.server.msg.CommandMessage.getLength(CommandMessage.java:104)
at sockslib.server.SocksSession.read(SocksSession.java:115)
at sockslib.server.Socks5Handler.handle(Socks5Handler.java:99)
at sockslib.server.Socks5Handler.run(Socks5Handler.java:270)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)```
What is the format of this file? How to trust cert?
Is there any convient way to use this lib for reverse proxy implementation?
It crashes due to a stack-over-flow problem everytime when I used the library as a socks5server running on Android device。Which is caused by the frequently allocated byte[] buffer using in StreamPipe.java。
I fixed this problem in two steps:
the BufferPool I used:
class BufferPool {
private static final int BUFFER_SIZE = 256960; //缓冲包2M
private static final int BUFFER_MAX_NUM = 40; //缓冲池保留最大数量
private static final ConcurrentLinkedQueue<byte[]> buffers = new ConcurrentLinkedQueue<byte[]>();
private static AtomicInteger countCreated = new AtomicInteger(0); //已创建的缓冲包个数
/**
* 分配
*/
public static byte[] allocate() {
byte[] result = buffers.poll();
//创建新缓冲包
if (result == null) {
result = new byte[BUFFER_SIZE];
//记录创建个数
int count = countCreated.incrementAndGet();
//日志
if (count <= BUFFER_MAX_NUM) {
logger.info("创建新的BufferPool缓冲池,已创建总数量:count={}", count);
} else {
logger.warn("创建新的BufferPool缓冲池,已创建总数量:count={}", count, new Throwable());
}
}
return result;
}
/**
* 回收
*
* @param buff
*/
public static void deallocate(byte[] buff) {
//缓冲池已达上限
if (buffers.size() >= BUFFER_MAX_NUM) return;
//回收的缓冲大小必须正确
if (buff.length != BUFFER_SIZE) return;
//加回到池中
buffers.add(buff);
}
}
Anyway, I didn't tested the performance influenced by the reduction of buffer size and nums。maybe there is another good way to make it runner better on Android.
Your code is Excellent !
Tests that make SSL connections fail due to errors when building with JDK 11. Specifically, these tests exhibit errors:
testConnectNoAuthSSLServer(sockslib.test.client.TestSSLSocks5): Connection reset
testConnectSSLAuthServer(sockslib.test.client.TestSSLSocks5): Connection reset
testSSLConnect(sockslib.test.quickstart.TestSocks5Server): Connection reset
testSSL2Connect(sockslib.test.quickstart.TestSocks5Server): Connection reset
tesSslUDP(sockslib.test.quickstart.TestSocks5Server): Received fatal alert: handshake_failure
This can be reproduced by building in containers. The tests pass when, in a local cloned repository directory, you execute
$ docker run -it --rm -v $PWD:/usr/src/sockslib -w /usr/src/sockslib maven:3.6-jdk-8 mvn clean install
...which builds with JDK 8, but they fail if you execute
$ docker run -it --rm -v $PWD:/usr/src/sockslib -w /usr/src/sockslib maven:3.6-jdk-11 mvn clean install
...which builds with JDK 11.
Partial build log showing the failures on JDK 11 is attached:
sockslib-build-jdk-11.log
Java version details are:
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment 18.9 (build 11.0.4+11)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.4+11, mixed mode)
A workaround is to set the system property jdk.tls.client.protocols=TLSv1.2
as mentioned here. (This was revealed to me in a comment on this question.) That is, change the Maven command to
$ mvn clean install -Djdk.tls.client.protocols=TLSv1.2
However, because it seems that JDK 11 is defaulting to TLSv1.3, some change to the SSLConfiguration.getSSLSocketFactory()
method is probably approprate. I do not know what that change is, though.
还是需要自己做加密?
When trying to use DatagramSocket.connect on a derived Socks5DatagramSocket, you will run into IllegalArgumentException "connected address and packet address differ". This is because the connect method is not overloaded to connect to the relayInetSocketAddress. This way, the socket is actually connected to the final destination address, leading to an address conflict with the encapsulated DatagramPacket.
To fix, overload connect() to transparently connect to relayInetSocketAddress instead. Additionally, you should store the InetSocketAddress given to connect by the caller and check equals in the overloaded send methods.
this shall be Strings.isNullOrEmpty(user.getUserName())
While trying the socks server using this project and opening in web browser websites seznam.cz and google.com with some search I received:
2018-06-17 14:54:36.526 INFO 3825 --- [ fs-thread] sockslib.server.BasicSocksProxyServer : Start proxy server at port:1080
[WARNING]
java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.fastRemove(ArrayList.java:550)
at java.util.ArrayList.remove(ArrayList.java:533)
at sockslib.server.io.StreamPipe.removePipeListener(StreamPipe.java:224)
at sockslib.server.io.SocketPipe.close(SocketPipe.java:124)
at sockslib.server.io.SocketPipe$PipeListenerImp.onStop(SocketPipe.java:208)
at sockslib.server.io.StreamPipe.stop(StreamPipe.java:141)
at sockslib.server.io.StreamPipe.run(StreamPipe.java:154)
at java.lang.Thread.run(Thread.java:748)
Should I enable trace logger level to get more info?
Thx for response
Hi,
I'm using latest beta release of fucksocks in JUnit test and starting/stopping the server for each test. I'm configuring the proxy using Java system properties, however this prevents the socks proxy from working, since it attempts to connect to itself when making connection to destination server (Socks5Handler.doConnect(..)).
I have been able to workaround this by providing my own implementation of Socks5Handler which turns off proxy usage in doConnect:
socket = new Socket(Proxy.NO_PROXY);
socket.connect(new InetSocketAddress(commandMessage.getInetAddress(), commandMessage.getPort()));
I saw that in latest code there is an option to specify a socks proxy when making connection to destination server, but it does not look like it is possible to turn off proxy usage, do you think that adding such support makes sense?
By the way, are there any plans to release a new sockslib version anytime soon.
Thanks,
Detelin
Hello,
could we start some regular versioning and releasing into maven repositories in public domain?
Ladislav
如果说错了请纠正。作者有没考虑后期上NIO的selector?
Hello,
i have a problem with SOCKS5 socket.
"[12.06 00:38:13] javaw.exe *64 - domain.com error : Could not connect through proxy 127.0.0.1:8082 - Proxy server cannot establish a connection with the target - general SOCKS server failure."
@fengyouchao
code
SocksProxyServer proxyServer = SocksServerBuilder.buildAnonymousSocks5Server(8082); proxyServer.start();
And how i can listen everythink/connection etc on that socks like in esocks ?
Thank you
this method works fine when the url contains http,
but it wouldn't works when the url contains https.
for example:
works fine: getResponse(new URL("http://www.worldjournal.com/"));
don't work: getResponse(new URL("https://google.com/"));
public static String getResponse(URL url){
String result = "";
StringBuilder builder = null;
InputStream inputStream = null;
OutputStream outputStream = null;
Socket socket = null;
int length = 0;
byte[] buffer = new byte[1024];
try {
SocksProxy proxy = new Socks5("x.x.x.x", 1080, new
UsernamePasswordCredentials("x", "x"));
socket = new SocksSocket(proxy, new InetSocketAddress(url.getHost(), url.getPort()));
inputStream = socket.getInputStream();
outputStream = socket.getOutputStream();
PrintWriter printWriter = new PrintWriter(outputStream);
printWriter.print("GET " + url + " HTTP/1.1\r\n");
printWriter.print("Host: " + url.getHost() + "\r\n");
printWriter.print("\r\n");
printWriter.flush();
builder = new StringBuilder("");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while ((length = inputStream.read(buffer)) > 0) {
System.out.print(new String(buffer, 0, length));
builder.append(new String(buffer, 0, length));
}
inputStream.close();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.