ruby_smb error when reading empty files

Open
#172 0 comments 0 reactions 1 assignee View on GitHub

@cdelafuente-r7 is already working on this.

Since May 17, 2021.

Assessment

This issue has not been assessed yet.

Description

bug

Ran into this error when testing some ascii/utf-8 issues.

If I ran examples/read_file.rb against an empty file, it would return the following errors:

➜  examples git:(master) ruby read_file.rb 192.168.215.190 <redacted> <redacted> Share 抽.txt 2
SMB2 : (0x00000000) STATUS_SUCCESS: The operation completed successfully.
Connected to \\192.168.215.190\Share successfully!

/Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/dispatcher/socket.rb:88:in `rescue in recv_packet': An error occurred reading from the Socket Connection reset by peer (RubySMB::Error::CommunicationError)
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/dispatcher/socket.rb:63:in `recv_packet'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/client.rb:540:in `recv_packet'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/client.rb:467:in `send_recv'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/smb2/file.rb:92:in `close'
	from read_file.rb:41:in `<main>'
/Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/dispatcher/socket.rb:70:in `read': Connection reset by peer (Errno::ECONNRESET)
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/dispatcher/socket.rb:70:in `recv_packet'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/client.rb:540:in `recv_packet'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/client.rb:467:in `send_recv'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/smb2/file.rb:92:in `close'
	from read_file.rb:41:in `<main>'
➜  examples git:(master)

This was tested against a Windows 8 & Windows 10 VM.

Found while attempting tor replicate this issue.

Steps to reproduce

How'd you do it?

  1. Run examples/read_file.rb against an SMB share. e.g.
ruby examples/read_file.rb 192.168.2.5 <redacted> <redacted> share_test "Мой файл.txt" 2) 

Were you following a specific guide/tutorial or reading documentation?

Found while attempting tor replicate this issue.

Expected behavior

Should return no errors and just a blank output, e.g.

➜  examples git:(master) ruby read_file.rb 192.168.215.190 <redacted> <redacted> Share 抽.txt 2
SMB2 : (0x00000000) STATUS_SUCCESS: The operation completed successfully.
Connected to \\192.168.215.190\Share successfully!

➜  examples git:(master)

Current behavior

Returns two errors:
RubySMB::Error::CommunicationError
Errno::ECONNRESET

➜  examples git:(master) ruby read_file.rb 192.168.215.190 <redacted> <redacted> Share 抽.txt 2
SMB2 : (0x00000000) STATUS_SUCCESS: The operation completed successfully.
Connected to \\192.168.215.190\Share successfully!

/Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/dispatcher/socket.rb:88:in `rescue in recv_packet': An error occurred reading from the Socket Connection reset by peer (RubySMB::Error::CommunicationError)
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/dispatcher/socket.rb:63:in `recv_packet'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/client.rb:540:in `recv_packet'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/client.rb:467:in `send_recv'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/smb2/file.rb:92:in `close'
	from read_file.rb:41:in `<main>'
/Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/dispatcher/socket.rb:70:in `read': Connection reset by peer (Errno::ECONNRESET)
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/dispatcher/socket.rb:70:in `recv_packet'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/client.rb:540:in `recv_packet'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/client.rb:467:in `send_recv'
	from /Users/cgranleese/rapid7/ruby_smb/lib/ruby_smb/smb2/file.rb:92:in `close'
	from read_file.rb:41:in `<main>'
➜  examples git:(master)
Dominant language
Ruby
Stars
86
Forks
90
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rapid7/ruby_smb

All issues in rapid7/ruby_smb

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.