πŸ”’Protected File Transfer Methods

Introduction

As penetration testers, we often gain access to highly sensitive data such as user lists, credentials (i.e., downloading the NTDS.dit file for offline password cracking), and enumeration data that can contain critical information about the organization's network infrastructure, and Active Directory (AD) environment, etc. Therefore, it is essential to encrypt this data or use encrypted data connections such as SSH, SFTP, and HTTPS. However, sometimes these options are not available to us, and a different approach is required.

⚠️ Note: Unless specifically requested by a client, we do not recommend exfiltrating data such as Personally Identifiable Information (PII), financial data (i.e., credit card numbers), trade secrets, etc., from a client environment. Instead, if attempting to test Data Loss Prevention (DLP) controls/egress filtering protections, create a file with dummy data that mimics the data that the client is trying to protect.

Therefore, encrypting the data or files before a transfer is often necessary to prevent the data from being read if intercepted in transit.

Data leakage during a penetration test could have severe consequences for the penetration tester, their company, and the client. As information security professionals, we must act professionally and responsibly and take all measures to protect any data we encounter during an assessment.

File Encryption on Windows

Many different methods can be used to encrypt files and information on Windows systems. One of the simplest methods is the Invoke-AESEncryption.ps1 PowerShell script. This script is small and provides encryption of files and strings.

Invoke-AESEncryption.ps1 Script

Download or create the script:

# The script can be downloaded or created manually
# Save as Invoke-AESEncryption.ps1

Script functionality examples:

  • Encrypt string: Invoke-AESEncryption -Mode Encrypt -Key "test123" -Text "Secret Text"

  • Decrypt string: Invoke-AESEncryption -Mode Decrypt -Key "test123" -Text "LtxcRelxrDLrDB9rBD6JrfX/czKjZ2CUJkrg++kAMfs="

  • Encrypt file: Invoke-AESEncryption -Mode Encrypt -Key "test123" -Path file.bin

  • Decrypt file: Invoke-AESEncryption -Mode Decrypt -Key "test123" -Path file.bin.aes

PowerShell AES Encryption Script

Using the AES Encryption Script

Import the Module:

File Encryption Example:

String Encryption Examples:

File Decryption Example:

Alternative Windows Encryption Methods

Using 7-Zip with Password

Encrypt with 7-Zip:

Decrypt with 7-Zip:

Using Windows Built-in Cipher

Encrypt folder with EFS:

Check encryption status:

File Encryption on Linux

OpenSSL is frequently included in Linux distributions, with sysadmins using it to generate security certificates, among other tasks. OpenSSL can be used to send files "nc style" to encrypt files.

OpenSSL Encryption

Encrypting /etc/passwd with openssl:

Decrypt passwd.enc with openssl:

OpenSSL Advanced Options

Different cipher algorithms:

Base64 encoding with encryption:

Using password from file:

GPG Encryption

Symmetric encryption with GPG:

Generate GPG key pair:

Encrypt for specific recipient:

Decrypt file:

Archive Encryption

Create encrypted tar archive:

Extract encrypted tar archive:

Using 7-Zip on Linux:

Advanced Protection Methods

Steganography

Hide data in images using steghide:

Hide data using LSB (Least Significant Bit):

Split and Encrypt

Split large files before encryption:

Reassemble and decrypt:

Secure Transfer Protocols

HTTPS File Transfer

Upload via HTTPS with curl:

Download via HTTPS with wget:

SFTP (SSH File Transfer Protocol)

Upload encrypted file via SFTP:

Batch SFTP operations:

SCP over SSH

Upload encrypted file via SCP:

SCP with compression:

Best Practices for Protected File Transfers

Password Security

  1. Use strong, unique passwords for each engagement

  2. Minimum 16 characters with mixed case, numbers, and symbols

  3. Never reuse passwords across different clients

  4. Store passwords securely in a password manager

  5. Use different passwords for each encrypted file

Key Management

  1. Generate strong encryption keys using cryptographically secure methods

  2. Use key derivation functions (like PBKDF2) with high iteration counts

  3. Rotate encryption keys regularly

  4. Securely delete keys after use

  5. Never hardcode keys in scripts or documentation

File Handling

  1. Encrypt before transfer whenever possible

  2. Verify file integrity after transfer using checksums

  3. Securely delete original files after encryption

  4. Use secure deletion tools (like shred on Linux)

  5. Document encryption methods used for each file

Network Security

  1. Prefer encrypted transport protocols (HTTPS, SFTP, SSH)

  2. Avoid unencrypted protocols (HTTP, FTP, Telnet)

  3. Use VPN connections when possible

  4. Monitor network traffic for anomalies

  5. Implement proper firewall rules

Data Protection Regulations

  1. GDPR compliance - Encrypt personal data

  2. HIPAA requirements - Protect health information

  3. PCI DSS standards - Secure payment card data

  4. SOX compliance - Financial data protection

  5. Industry-specific regulations - Follow sector requirements

Documentation Requirements

  1. Document encryption methods used

  2. Maintain key management logs

  3. Record file transfer activities

  4. Track data handling procedures

  5. Report security incidents promptly

Troubleshooting Encrypted File Transfers

Common Issues

Incorrect password:

Corrupted encrypted files:

Encoding issues:

Verification Methods

File size comparison:

Checksum verification:

Key Takeaways

  1. Always encrypt sensitive data before transfer during penetration tests

  2. Use strong, unique passwords for each encryption operation

  3. Prefer secure transport protocols when available

  4. Document encryption methods and key management procedures

  5. Verify file integrity after encryption and transfer

  6. Follow legal and compliance requirements for data protection

  7. Implement proper key management practices

  8. Securely delete original files after encryption

  9. Test encryption/decryption before critical transfers

  10. Have backup encryption methods available

References

Last updated