rapid7 / ruby_smb

A native Ruby implementation of the SMB Protocol Family
Other
79 stars 82 forks source link

ruby_smb error when reading empty files #172

Open cgranleese-r7 opened 3 years ago

cgranleese-r7 commented 3 years ago

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)