hierynomus / smbj

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

SMBRuntimeException : .Buffer$BufferException: Underflow #565

Closed khilisharma closed 4 years ago

khilisharma commented 4 years ago

I'm trying to connect to Apple Time Capsule, and I'm facing Runtime Exception. For starter, I'm just using a simple scenario of listing down files from the Time Capsule. and below is my function. I have attached the stacktrace in here too. Smbj version is 0.10.0. Appreciate your help and time! Thank You. stacktrace.txt

public void listFiles() throws IOException { SmbConfig cfg = SmbConfig.builder().build(); SMBClient client = new SMBClient(cfg);

try {
  Connection connection = client.connect(IP);
  AuthenticationContext ac = new AuthenticationContext(Username, Password.toCharArray(), null);
  Session session = connection.authenticate(ac);

  // Connect to Share
  DiskShare share = (DiskShare) session.connectShare(ShareName);
    for (FileIdBothDirectoryInformation f : share.list(SharedPath, "*")) {
      System.out.println("File : " + f.getFileName());
    }
}
catch (SMBException ex) {
  throw new IOException(ex);
}

}

ecki commented 4 years ago

Looks like TC somehow violates the SMB protocol. You would need to provide an network dump for more details.

However a quick search made me think that TC might only support SMB1 anyway, for this you would need to use another library.

BTW I do think smbj should catch the buffer under flow and wrap it as a protocol violation exception.

khilisharma commented 4 years ago

@ecki Hmm! I read more about it and looks like Apple has officially discontinued the TC long back ,and they apparently never offered any additional updates for the product, so no SMB2 or SMB3.1 support from Apple on this product. Also, I guess Windows does not authorize SMB1 anymore , and to set PC to SMB1 is not recommended as it is a significant security risk!! I'm not sure if SMB 1.x on any local network should not be a security issue if the local network is already secure. I never saw this coming when I thought of working on this! Sad day!! I'm trying to see how to capture the network dump though!

Talwvs commented 4 years ago

@khilisharma, @ecki
I can confirm. In 2006 Apple has integrated a very old SMB1 only version and never upgraded to newer dialects. The product was discontinued officially a couple of years ago. This is true for the Time Capsule and Time machine.

ecki commented 4 years ago

If you use a java library for smb1 (jcifs(ng)) you don't need to enable smb1 on the Windows machine for it,

Dump would be good because this lib won't implement smb1, but it could produce better errors for your handshake case.

khilisharma commented 4 years ago

I added the dependency in my pom but it still gives me the same error. I'm sorry I'm a newbie here! @ecki

eu.agno3.jcifs jcifs-ng 2.1.4
ecki commented 4 years ago

You will need to change your code, jCIFS is used differently than smbj. It's an other project.

khilisharma commented 4 years ago

okay so, I completely changed my code and you were right about how it can produce better errors!! Got a few errors and after some workarounds I'm finally able to read the contents of the file! @ecki Appreciate your help and time! Thank you so much! Now that I'm able to establish connection, I will now start on writing the APIs that I actually wanted to!

Thanks once again!

listFiles.txt