Skip to content

Instantly share code, notes, and snippets.

@stephen-fox
Last active April 13, 2024 15:18
Show Gist options
  • Save stephen-fox/d534fa0c480aafba2ba47c7e7eb9961e to your computer and use it in GitHub Desktop.
Save stephen-fox/d534fa0c480aafba2ba47c7e7eb9961e to your computer and use it in GitHub Desktop.
Encrypting data with openssl and transmitting it with nc
#!/bin/bash
# This snippet demonstrates how to send and receive data
# encrypted with openssl using netcat.
#
# You can switch around the netcat listener and sender
# depending on your preference. This example is setup
# for copying data from a host into a VirtualBox VM.
# You can also substitute 'nc' for another tool.
#
# This example keeps the encrypted data and the symetric
# password out of the terminal session history and the
# process table.
# Sender machine:
read -s PASS
export PASS
openssl enc -aes-256-cbc -pass env:PASS -base64 -pbkdf2 | nc -l 8080
# Target machine:
nc 10.0.2.2 8080 | openssl enc -aes-256-cbc -d -base64 -pbkdf2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment