Lampros - Weird Bricks

Sending files between hosts with netcrypt on Ubuntu 16

15 April, 2018 | Ubuntu

I love trying out new tools - for this post I picked netcrypt. A netcat-like tool with encryption built in. What I love about it is that you don't need an SSL certificate or SSH to set this up - you just set a password before the file transfer and netcrypt takes care of everything else for you. 

1. Overwrite the /etc/apt/sources.list with a more local repository - in my case I'm using the Pacific Northwest National Laboratory since it's geographically close to me. 

cat > /etc/apt/sources.list <<EOL
deb http://mirror.pnl.gov/ubuntu/ xenial main restricted
deb http://mirror.pnl.gov/ubuntu/ xenial-updates main restricted
deb http://mirror.pnl.gov/ubuntu/ xenial universe
deb http://mirror.pnl.gov/ubuntu/ xenial-updates universe
deb http://mirror.pnl.gov/ubuntu/ xenial multiverse
deb http://mirror.pnl.gov/ubuntu/ xenial-updates multiverse
deb http://mirror.pnl.gov/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirror.pnl.gov/ubuntu/ xenial-security main restricted
deb http://mirror.pnl.gov/ubuntu/ xenial-security universe
deb http://mirror.pnl.gov/ubuntu/ xenial-security multiverse
EOL

2. Get the latest package listings:

apt update

3. Install wget and unzip:

apt -y install wget unzip

4. Download and unzip the source code:

cd /tmp
wget https://github.com/tcShadowWalker/NetCrypt/archive/master.zip
unzip master.zip

5. Prepare to compile the source code:

cd NetCrypt-master/
mkdir build
cd build/

6. Install some more dependencies:

apt -y install libssl-dev libboost-all-dev cmake gcc g++

7. Run cmake and make:

cmake ..
make -j `nproc`
./netcrypt --version

You should get output like this:

Netcrypt version 0.4.9

8. Copy the executable to /usr/local/bin:

cp netcrypt /usr/local/bin/

9. On the server side, download a file to use as test for our transfer:

cd ~
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.15.8.tar.xz

10. Set a password for netcrypt as an environment variable:

export NETCRYPT_PASSPHRASE="manygoatsmany8984841"

11. Now "serve" the file using netcrypt on port 45173:

netcrypt -l 45173 -i linux-4.15.8.tar.xz

11. On the client side:

netcrypt -h $the_servers_public_ip -p 45173 -o myfile.xz

You'll be prompted to enter your password and then the transfer will begin :)

Sources: