Last active
June 20, 2017 20:25
-
-
Save bneg/c74dc7918b58c1f5aac34f3b12184439 to your computer and use it in GitHub Desktop.
Empire to Slack via REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import json | |
import ssl | |
import time | |
from urllib2 import Request, urlopen, URLError | |
url = "https://172.16.1.149:1337/api" | |
token = "fvcds7..." | |
live_agents = [] | |
def get_agents(): | |
url = url + '/agents?token='+token | |
request = Request(url) | |
try: | |
empire_agents = json.load(urlopen(request, context=ssl._create_unverified_context())) | |
for agent in empire_agents['agents']: | |
if agent['name'] not in live_agents: | |
live_agents.append(agent['name']) | |
message = "Agent "+ agent['name'] + " on "+ agent['hostname'] + " has just checked in" | |
post_message(message) | |
except URLError, e: | |
print "nope", e | |
def post_message(agent_info): | |
slack_url = 'https://hooks.slack.com/services/[your_own_token_here]' | |
data = '{"channel": "@bneg", "username": "Emperor Palpatine", "text": "'+ agent_info +'"}' | |
urlopen(slack_url, data) | |
def main(): | |
while True: | |
get_agents() | |
time.sleep(5) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment