hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
707 stars 180 forks source link

Unable to read the value of the ASN.1 object #749

Closed fengyingkong closed 1 year ago

fengyingkong commented 1 year ago

need help:

use version: 0.11.5 smb server use open source: https://github.com/gavriva/smb2

demo:

` SMBClient client = new SMBClient(); try (Connection connection = client.connect(smbConfig.getHost())) { AuthenticationContext ac = new AuthenticationContext(smbConfig.getUserName(), smbConfig.getPassword().toCharArray(), "SAMBA"); Session session = connection.authenticate(ac);

        try(DiskShare share = (DiskShare) session.connectShare(smbConfig.getWorkDir())) {
            Set<FileAttributes> fileAttributes = new HashSet<>();
            fileAttributes.add(FileAttributes.FILE_ATTRIBUTE_NORMAL);

            Set<SMB2CreateOptions> createOptions = new HashSet<>();
            createOptions.add(SMB2CreateOptions.FILE_RANDOM_ACCESS);

            Set<AccessMask> accessMasks = new HashSet<>(Collections.singletonList(AccessMask.GENERIC_ALL));

            share.open(smbConfig.getWorkDir().concat("test20230130003.txt"),
                    accessMasks,
                    fileAttributes,
                    SMB2ShareAccess.ALL,
                    SMB2CreateDisposition.FILE_OVERWRITE_IF,
                    createOptions);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }`

error:

2023-01-31 15:34:56.249 DEBUG 87756 --- [ main] c.h.s.t.t.direct.DirectTcpPacketReader : Starting PacketReader on thread: Packet Reader for 127.0.0.1 2023-01-31 15:34:56.253 DEBUG 87756 --- [ main] c.h.s.connection.SMBProtocolNegotiator : Negotiating dialects [SMB_2_0_2, SMB_2_1, SMB_3_0, SMB_3_0_2, SMB_3_1_1] 2023-01-31 15:34:56.256 DEBUG 87756 --- [ main] c.hierynomus.smbj.connection.Connection : Granted 1 (out of 1) credits to SMB2_NEGOTIATE with message id << 0 >> 2023-01-31 15:34:56.258 DEBUG 87756 --- [ main] c.h.s.t.tcp.direct.DirectTcpTransport : Writing packet SMB2_NEGOTIATE with message id << 0 >> 2023-01-31 15:34:56.262 DEBUG 87756 --- [r for 127.0.0.1] c.h.s.t.t.direct.DirectTcpPacketReader : Received packet SMB2_NEGOTIATE with message id << 0 >> 2023-01-31 15:34:56.263 DEBUG 87756 --- [r for 127.0.0.1] .h.s.c.p.SMB2CreditGrantingPacketHandler : Server granted us 1 credits for SMB2_NEGOTIATE with message id << 0 >>, now available: 1 credits 2023-01-31 15:34:56.265 DEBUG 87756 --- [ main] c.h.s.connection.SMBProtocolNegotiator : Negotiated the following connection settings: ConnectionContext{ serverGuid=ade83493-2424-5cc0-00b7-fce937791609, serverName='127.0.0.1', negotiatedProtocol=NegotiatedProtocol{dialect=SMB_3_0_2, maxTransactSize=8388608, maxReadSize=8388608, maxWriteSize=8388608}, clientGuid=e15f073d-9bd7-4314-8318-c1d3e2933464, clientCapabilities=[SMB2_GLOBAL_CAP_LARGE_MTU], serverCapabilities=[SMB2_GLOBAL_CAP_LARGE_MTU], clientSecurityMode=1, serverSecurityMode=1, server='com.hierynomus.smbj.server.Server@60b5e80d' } 2023-01-31 15:34:56.265 INFO 87756 --- [ main] c.h.smbj.connection.PacketEncryptor : Initialized PacketEncryptor with Cipher << AES_128_CCM >> 2023-01-31 15:34:56.271 INFO 87756 --- [ main] c.hierynomus.smbj.connection.Connection : Successfully connected to: 127.0.0.1 2023-01-31 15:34:56.284 DEBUG 87756 --- [ main] c.h.smbj.auth.NtlmAuthenticator : Initialized Authentication of root using NTLM 2023-01-31 15:34:56.289 DEBUG 87756 --- [ main] c.hierynomus.smbj.connection.Connection : Granted 1 (out of 1) credits to SMB2_SESSION_SETUP with message id << 1 >> 2023-01-31 15:34:56.289 DEBUG 87756 --- [ main] c.h.s.t.tcp.direct.DirectTcpTransport : Writing packet SMB2_SESSION_SETUP with message id << 1 >> 2023-01-31 15:34:59.547 DEBUG 87756 --- [r for 127.0.0.1] c.h.s.t.t.direct.DirectTcpPacketReader : Received packet SMB2_SESSION_SETUP with message id << 1 >> 2023-01-31 15:34:59.547 DEBUG 87756 --- [r for 127.0.0.1] .h.s.c.p.SMB2CreditGrantingPacketHandler : Server granted us 1 credits for SMB2_SESSION_SETUP with message id << 1 >>, now available: 1 credits 2023-01-31 15:34:59.548 DEBUG 87756 --- [ main] c.h.smbj.connection.SMBSessionBuilder : More processing required for authentication of root using com.hierynomus.smbj.auth.NtlmAuthenticator@51ac12ac 2023-01-31 15:34:59.548 DEBUG 87756 --- [ main] c.h.smbj.auth.NtlmAuthenticator : Received token: 4e 54 4c 4d 53 53 50 00 02 00 00 00 08 00 08 00 30 00 00 00 05 02 0a 20 48 9b 01 88 ed ed 99 54 00 00 00 00 00 00 00 00 00 00 00 00 30 00 00 00 74 00 65 00 73 00 74 00 2023-01-31 15:34:59.552 DEBUG 87756 --- [ main] c.h.s.t.t.direct.DirectTcpPacketReader : Stopping PacketReader... 2023-01-31 15:34:59.552 INFO 87756 --- [ main] c.hierynomus.smbj.connection.Connection : Closed connection to 127.0.0.1 2023-01-31 15:34:59.553 INFO 87756 --- [r for 127.0.0.1] c.h.s.t.t.direct.DirectTcpPacketReader : Thread[Packet Reader for 127.0.0.1,5,main] stopped. 2023-01-31 15:34:59.554 DEBUG 87756 --- [ main] com.hierynomus.smbj.SMBClient : Connection to << 127.0.0.1:445 >> closed com.hierynomus.asn1.ASN1ParseException: Unable to read the value of the ASN.1 object at com.hierynomus.asn1.encodingrules.ber.BERDecoder.readValue(BERDecoder.java:101) at com.hierynomus.asn1.ASN1InputStream.readObject(ASN1InputStream.java:51) at com.hierynomus.spnego.NegTokenTarg.read(NegTokenTarg.java:118) at com.hierynomus.spnego.NegTokenTarg.read(NegTokenTarg.java:113) at com.hierynomus.smbj.auth.NtlmAuthenticator.authenticate(NtlmAuthenticator.java:82) at com.hierynomus.smbj.connection.SMBSessionBuilder.processAuthenticationToken(SMBSessionBuilder.java:178) at com.hierynomus.smbj.connection.SMBSessionBuilder.setupSession(SMBSessionBuilder.java:141) at com.hierynomus.smbj.connection.SMBSessionBuilder.establish(SMBSessionBuilder.java:109) at com.hierynomus.smbj.connection.Connection.authenticate(Connection.java:202) at com.tencent.smb.client.SmbClientApplicationTests.contextLoads(SmbClientApplicationTests.java:36) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84) at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115) at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86) at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86) at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)

hierynomus commented 1 year ago

I would need more information. Either (ideally) a reproducible testcase with that server, or trace level logging and a packet dump

fengyingkong commented 1 year ago

WX20230131-173124 I found the negTokenInit Garbled codes. I suspect that it is the reason why the garbled code cannot be parsed. how to parsed?

hierynomus commented 1 year ago

NegTokens are bytes, I don't typically expect them to be human readable...

hierynomus commented 1 year ago

Given that the server you're using specifies "a very alpha version" I would expect a bug to be on that side. SMBJ is pretty hardened already, though I don't discount that there could be a bug in the client

fengyingkong commented 1 year ago

Can you recommend a reliable SMB-Server for java or go open source software ?support SMB2.x and SMB3.x version.

hierynomus commented 1 year ago

Why would it need to be Go or Java for the server? I don't know of any good compliant servers implemented in Java, or GoLang for that matter. For testing purposes, I would recommend a Docker container with samba, which is what SMBJ also uses to integration test against.

fengyingkong commented 1 year ago

samba implemented in C . I can't integrate into my project