Skip to content

Instantly share code, notes, and snippets.

@Flangvik
Last active February 4, 2022 03:24
Show Gist options
  • Save Flangvik/5fb58dffa373a50f4d560a14adaa415b to your computer and use it in GitHub Desktop.
Save Flangvik/5fb58dffa373a50f4d560a14adaa415b to your computer and use it in GitHub Desktop.
AlertOnNewIp.py
#!/usr/bin/env python
# Super dirty python3 scripts that alerts Cobalt Strike operator using pushover when a new IP is found amoung network interface on beacon
# Aggressor script for triggering this : https://gist.github.com/Flangvik/c31b26129743be699133dc9dab9c02c5
import argparse
from datetime import datetime
from base64 import b64encode,b64decode
from pushover import init, Client
from os import path
parser = argparse.ArgumentParser(description='beacon info')
parser.add_argument('--user')
parser.add_argument('--data')
parser.add_argument('--computer')
args = parser.parse_args()
#Replace the below keys, pushover.net
pushover_user_key = "<redacted>"
pushover_app_key = "<redacted>"
beaconuser = args.user
computer = args.computer
data = args.data
def pushovernotifications(user):
init(pushover_app_key)
Client(pushover_user_key).send_message("VPN!", title=user)
didCsvExists = path.exists("/<fullpath>/ip_logs_all_beacons.csv")
f = open("/<fullpath>/ip_logs_all_beacons.csv", "a+")
if not didCsvExists:
f.write("Type;Timestamp;User;Hostname;IP\n")
ipAdresser = b64decode(data).decode('UTF-16LE').split('\n')
for ip in ipAdresser:
if ip:
f.write("LOG;%s;%s;%s;%s\n" % (datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S"),beaconuser, computer, ip.split()[0]))
#Edit this based on the subnet of your beacons "home network"
if(ip.split('.')[0] != "192"):
pushovernotifications(beaconuser)
f.write("ALERT;%s;%s;%s;%s\n" % (datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S"),beaconuser, computer, ip.split()[0]))
f.close()
@Flangvik
Copy link
Author

Flangvik commented Feb 3, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment