0

If you open a port on a listening host and send bytes with nc to this port, the hash of the source and destination file might not be the same. Why is that and can it be prevented?

Here are the commands i use:

On the receiver:

bash@ubuntu $ nc -nlvp 4444 > target # at 192.168.155.51

On the sender:

powershell@windows $ Get-Content binaryFile.exe | nc 192.168.155.51 4444

SHA256 of the source (calculated with Get-FileHash): FFECB298B1381AFBF86247156F625EAECA327015C5BC0658F6FF6E063D59D759

SHA256 of the target (sha256sum): 1c1148ace41bc0d22c1523787c64fb34abba456551d62387a085d12c36d34452

TMOTTM
  • 219

1 Answers1

0

The issue doesn't deal with nc, but with Get-Content. If you Get-Content a.exe > b.exe you will have two different files (the file size doubles).

The issue is raised here https://stackoverflow.com/questions/10672092/read-parse-binary-files-with-powershell but I havn't found a Get-Content usage adequate with a binary file.

Using nc with the argument you are proposing (but a direct redirection from UNIX) works well.