π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.ps1Script 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.binDecrypt 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
Use strong, unique passwords for each engagement
Minimum 16 characters with mixed case, numbers, and symbols
Never reuse passwords across different clients
Store passwords securely in a password manager
Use different passwords for each encrypted file
Key Management
Generate strong encryption keys using cryptographically secure methods
Use key derivation functions (like PBKDF2) with high iteration counts
Rotate encryption keys regularly
Securely delete keys after use
Never hardcode keys in scripts or documentation
File Handling
Encrypt before transfer whenever possible
Verify file integrity after transfer using checksums
Securely delete original files after encryption
Use secure deletion tools (like
shredon Linux)Document encryption methods used for each file
Network Security
Prefer encrypted transport protocols (HTTPS, SFTP, SSH)
Avoid unencrypted protocols (HTTP, FTP, Telnet)
Use VPN connections when possible
Monitor network traffic for anomalies
Implement proper firewall rules
Compliance and Legal Considerations
Data Protection Regulations
GDPR compliance - Encrypt personal data
HIPAA requirements - Protect health information
PCI DSS standards - Secure payment card data
SOX compliance - Financial data protection
Industry-specific regulations - Follow sector requirements
Documentation Requirements
Document encryption methods used
Maintain key management logs
Record file transfer activities
Track data handling procedures
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
Always encrypt sensitive data before transfer during penetration tests
Use strong, unique passwords for each encryption operation
Prefer secure transport protocols when available
Document encryption methods and key management procedures
Verify file integrity after encryption and transfer
Follow legal and compliance requirements for data protection
Implement proper key management practices
Securely delete original files after encryption
Test encryption/decryption before critical transfers
Have backup encryption methods available
References
Last updated