From 3d98bac4ffc7e3d9e96051adfab9255b3013c764 Mon Sep 17 00:00:00 2001 From: H4sh <38443613+TheHashZone@users.noreply.github.com> Date: Fri, 9 Nov 2018 22:32:42 +0100 Subject: [PATCH 1/7] Added symbols to passgen --- infoBot.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/infoBot.py b/infoBot.py index a57b004..b78fd3c 100644 --- a/infoBot.py +++ b/infoBot.py @@ -7,6 +7,7 @@ import pandas as pd import matplotlib.pyplot as plt from matplotlib import style +import random from Crypto import Random import hashlib import hmac @@ -70,15 +71,32 @@ async def user_metrics_background_task(): await asyncio.sleep(5) -class BotCrypto: # Massive shoutout to @Nanibongwa on Discord for this implementation. +class BotCrypto: # Massive shoutout to @Nanibongwa on Discord/nsk89 on GitHub for this implementation. def generate_password(self, length): # generate random bytes and hash returned data password = self.hash_data(Random.get_random_bytes(length)) secret = self.hash_data(Random.get_random_bytes(length)) # create secure hmac'd hash password hmac_pass = base64.b64encode(hmac.new(password, secret, hashlib.sha3_384).digest()) - - return hmac_pass[:length].decode() + + return self.symbol_insert(hmac_pass[:length].decode()) + + def symbol_insert(self, passphrase): + # list of symbols to choose from + symbol_list = ['!', '@', '#', '$', '%', '^', '&' '*', '(', ')', '+', '=', '_'] + # define the amount of symbols to use in a given string based on length >= 8 + symbol_count = round(len(passphrase) / 4) + count = 0 + while count < symbol_count: # pick random symbols based on int chosen and append it to passphrase + rand_int = random.randrange(0, len(symbol_list)) + passphrase += symbol_list[rand_int] + count += 1 + + passphrase = [char for char in passphrase] # no delimiter, no .split(). list comprehension to split characters + random.shuffle(passphrase) # Pycrypdome shuffle, shuffle the list elements around + passphrase = ''.join(passphrase) # rejoin the list into the passphrase string + + return passphrase def hash_data(self, data): # convert data to hash data = self.check_for_bytes(data) @@ -121,6 +139,10 @@ async def on_message(message, *args): !user_analysis - Show a graph of activity.```") + elif "!qa" == message.content.lower(): # Need to find a cleaner way to do this. + await message.channel.send("**How to hack [insert social media]?** \nDon't! That isn't why we made the server. But if you want to learn from a security point of view, google these things: Phishing, Keyloggers, MiTM, session hijacking, cookie stealing. \n\n**How do I start hacking?** \nThere are a lot of resources, here a few: https://www.hacker101.com, https://bit.ly/2PLuDv4 \n\n**What is the link for Kali Linux?** \nhttps://www.kali.org \n\n**Wi-Fi Hacking?** \nLook on Google for stuff like Aircrack-ng. \n\n**What is Tor?** \nTor (The Onion Router). It was originally developed with the U.S. Navy in mind, for the primary purpose of protecting government communications. Today, it is used every day for a wide variety of purposes by the military, journalists, law enforcement officers, activists, and many others. Here are some of the specific uses we've seen or recommend.\n\n**How do I use Tor?** \nGoogle it ;) \n\n**What is a CTF? How do I start?** \nhttps://www.ctf101.org") + + elif "!ports" == message.content.lower(): # Shows a list of common ports. Going to make it into a search. await message.channel.send(f"```py\nCommon Ports: \n{pd.DataFrame.from_dict(text_ports, orient = 'index')}```") From 71e5887fff521505a05ca319bed44ea393aa6dd5 Mon Sep 17 00:00:00 2001 From: H4sh <38443613+TheHashZone@users.noreply.github.com> Date: Sat, 10 Nov 2018 02:01:42 +0100 Subject: [PATCH 2/7] Updates Added port search, number of messages to delete, updated !help menu, and some changes to the !user_info function. --- infoBot.py | 101 ++++++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/infoBot.py b/infoBot.py index b78fd3c..e88754c 100644 --- a/infoBot.py +++ b/infoBot.py @@ -5,15 +5,12 @@ from discord.ext.commands import Bot import time import pandas as pd -import matplotlib.pyplot as plt -from matplotlib import style import random from Crypto import Random import hashlib import hmac import base64 -style.use("fivethirtyeight") client = discord.Client() token = open("token.txt", "r").read() @@ -31,44 +28,33 @@ def community_report(guild): online = 0 idle = 0 + dnd = 0 offline = 0 for member in guild.members: # Go through members in the server if str(member.status) == "online": online += 1 - if str(member.status) == "offline": - offline += 1 - elif str(member.status) == "idle" or str(member.status) == "dnd": + + elif str(member.status) == "idle": idle += 1 + + elif str(member.status) == "dnd": + dnd += 1 - return online, idle, offline + elif str(member.status) == "offline": + offline += 1 + else: + print(str(member.status)) -async def user_metrics_background_task(): - await client.wait_until_ready() - guild = client.get_guild(509992354543960064) - while not client.is_closed(): - try: - online, idle, offline = community_report(guild) # Get the data - with open("usermetrics.csv","a") as f: - f.write(f"{int(time.time())},{online},{idle},{offline}\n") # Put data in CSV file - - plt.clf() - df = pd.read_csv("usermetrics.csv", names = ['time', 'online', 'idle', 'offline']) # Read CSV file - df['date'] = pd.to_datetime(df['time'],unit = 's') - df['total'] = df['online'] + df['offline'] + df['idle'] - df.drop("time", 1, inplace = True) - df.set_index("date", inplace = True) - df['online'].plot(), df['offline'].plot(), df['idle'].plot() # Map data onto the grapgh - plt.legend() - plt.savefig("online.png") # Save graph as image - - await asyncio.sleep(30) - - except Exception as e: - print(str(e)) - await asyncio.sleep(5) + total = guild.member_count + online_p = (online / total) * 100 + idle_p = (idle / total) * 100 + dnd_p = (dnd / total) * 100 + offline_p = (offline / total) * 100 + + return total, online, online_p, idle, idle_p, dnd, dnd_p, offline, offline_p class BotCrypto: # Massive shoutout to @Nanibongwa on Discord/nsk89 on GitHub for this implementation. @@ -130,21 +116,29 @@ async def on_message(message, *args): elif "!help" == message.content.lower(): # Command to list commands - await message.channel.send("```\ - !help - Show this message\n\ - !clear - Delete channel messages up to 14 days old.\n\ - !passgen x - Password generator between 8 - 32 chars (x being the length you want the password)\n\ - !user_info - Get user count.\n\ - !ports - Show a list of common ports.\n\ - !user_analysis - Show a graph of activity.```") + await message.channel.send("```!help - Show this message \n!qa - Shows common questions with answers \n!clear x - Delete channel messages. (x being number of messages to delete) \n!passgen x - Password generator between 8 - 32 chars. (x being the length you want the password) \n!user_info - Get user count. \n!ports x - Show a list of common ports. (x being the port number. If no port is given it will send the whole list)\n```") elif "!qa" == message.content.lower(): # Need to find a cleaner way to do this. await message.channel.send("**How to hack [insert social media]?** \nDon't! That isn't why we made the server. But if you want to learn from a security point of view, google these things: Phishing, Keyloggers, MiTM, session hijacking, cookie stealing. \n\n**How do I start hacking?** \nThere are a lot of resources, here a few: https://www.hacker101.com, https://bit.ly/2PLuDv4 \n\n**What is the link for Kali Linux?** \nhttps://www.kali.org \n\n**Wi-Fi Hacking?** \nLook on Google for stuff like Aircrack-ng. \n\n**What is Tor?** \nTor (The Onion Router). It was originally developed with the U.S. Navy in mind, for the primary purpose of protecting government communications. Today, it is used every day for a wide variety of purposes by the military, journalists, law enforcement officers, activists, and many others. Here are some of the specific uses we've seen or recommend.\n\n**How do I use Tor?** \nGoogle it ;) \n\n**What is a CTF? How do I start?** \nhttps://www.ctf101.org") - elif "!ports" == message.content.lower(): # Shows a list of common ports. Going to make it into a search. - await message.channel.send(f"```py\nCommon Ports: \n{pd.DataFrame.from_dict(text_ports, orient = 'index')}```") + elif message.content.startswith("!ports"): # Ports list and search. + try: + args = message.content.split(" ")[1] + port = int(args) + + if port in num_ports: + await message.channel.send(f"```py\nPort {port}:\n{num_ports[port]}```") + + elif port not in num_ports: + await message.channel.send("Error, not a common port. Sorry!") + + except ValueError: + await message.channel.send("Error, port has to be an integer!") + + except IndexError: + await message.channel.send(f"```py\nCommon Ports:\n{pd.DataFrame.from_dict(text_ports, orient = 'index')}```") elif message.content.startswith("!passgen"): # Password generator @@ -168,7 +162,15 @@ async def on_message(message, *args): await message.author.send(f'Your password is: {password}') - elif "!clear" == message.content.lower(): # Delete all messages (Need to implement number of messages to delete) + elif message.content.startswith("!clear"): # Delete messages (Needs an int as input) + args = message.content.split(" ")[1] + + try: + limit = int(args) # Check if input is an int + + except ValueError: + await message.channel.send("Error, not a valid input!") + counter = 0 messages = [] channel = message.channel @@ -176,8 +178,11 @@ async def on_message(message, *args): # Need to add date check async for message in message.channel.history(): # Go through messages in channel - counter += 1 - messages.append(message) # Add message to list + if counter < limit: + counter += 1 + messages.append(message) # Add message to list + else: + pass await channel.delete_messages(messages) # Delete messages from list @@ -190,14 +195,8 @@ async def on_message(message, *args): elif "!user_info" == message.content.lower(): # Gives server info - online, idle, offline = community_report(guild) - await message.channel.send(f"```py\nTotal Users: {guild.member_count}\n Online: {online}\n Idle/busy/dnd: {idle}\n Offline: {offline}```") - - - elif "!user_analysis" == message.content.lower(): # Sends a graph of user activity - file = discord.File("online.png", filename = "online.png") - await message.channel.send("User Analysis", file = file) + total, online, online_p, idle, idle_p, dnd, dnd_p, offline, offline_p = community_report(guild) + await message.channel.send(f"```py\nTotal Users: {total} \nOnline: {int(online)} | {online_p}% \nIdle: {int(idle)} | {idle_p} \ndnd: {int(dnd)} | {dnd_p} \nOffline: {int(offline)} | {offline_p}%```") -client.loop.create_task(user_metrics_background_task()) client.run(token) \ No newline at end of file From dd67c6142dd89b4d6839a11d9133f6474c3dbee4 Mon Sep 17 00:00:00 2001 From: nsk89 <13374799+nsk89@users.noreply.github.com> Date: Sat, 10 Nov 2018 09:49:41 -0800 Subject: [PATCH 3/7] Accidental merge, reverted --- infoBot.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/infoBot.py b/infoBot.py index 0b70a99..e88754c 100644 --- a/infoBot.py +++ b/infoBot.py @@ -7,7 +7,6 @@ import pandas as pd import random from Crypto import Random -from Crypto.Random import random import hashlib import hmac import base64 @@ -57,7 +56,7 @@ def community_report(guild): return total, online, online_p, idle, idle_p, dnd, dnd_p, offline, offline_p - + class BotCrypto: # Massive shoutout to @Nanibongwa on Discord/nsk89 on GitHub for this implementation. def generate_password(self, length): # generate random bytes and hash returned data @@ -199,6 +198,5 @@ async def on_message(message, *args): total, online, online_p, idle, idle_p, dnd, dnd_p, offline, offline_p = community_report(guild) await message.channel.send(f"```py\nTotal Users: {total} \nOnline: {int(online)} | {online_p}% \nIdle: {int(idle)} | {idle_p} \ndnd: {int(dnd)} | {dnd_p} \nOffline: {int(offline)} | {offline_p}%```") - -client.loop.create_task(user_metrics_background_task()) -client.run(token) + +client.run(token) \ No newline at end of file From 4477bdbcfdae26baa27559f0e59ef78a6a27b731 Mon Sep 17 00:00:00 2001 From: H4sh <38443613+TheHashZone@users.noreply.github.com> Date: Sun, 11 Nov 2018 22:37:16 +0100 Subject: [PATCH 4/7] Error handling. Error handling for the !clear command + clearing up some comments that aren't needed anymore. --- infoBot.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/infoBot.py b/infoBot.py index e88754c..e4969c0 100644 --- a/infoBot.py +++ b/infoBot.py @@ -20,8 +20,7 @@ num_ports = {21: "FTP", 22: "SSH", 23: "Telnet", 25: "SMTP", # List of ports 53: "DNS", 67: "DHCP Server", 68: "DHCP Client", - 80: "HTTP", 110: "POP3", 143: "IMAP", 443: "HTTPS", # Need both for the port search later. - } + 80: "HTTP", 110: "POP3", 143: "IMAP", 443: "HTTPS"} text_ports = {v: k for k, v in num_ports.items()} # Reversed list of ports @@ -163,10 +162,13 @@ async def on_message(message, *args): elif message.content.startswith("!clear"): # Delete messages (Needs an int as input) - args = message.content.split(" ")[1] + try: + args = message.content.split(" ")[1] + except IndexError: + await message.channel.send("Error, You need to enter a number of messages!") try: - limit = int(args) # Check if input is an int + limit = int(args) + 1 # Check if input is an int and then add 1 to count the !clear message. except ValueError: await message.channel.send("Error, not a valid input!") From 97680a1538512206e128d44984c6061b89c46d34 Mon Sep 17 00:00:00 2001 From: H4sh <38443613+TheHashZone@users.noreply.github.com> Date: Sun, 11 Nov 2018 23:43:36 +0100 Subject: [PATCH 5/7] Removed standard random library --- infoBot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/infoBot.py b/infoBot.py index e4969c0..4905211 100644 --- a/infoBot.py +++ b/infoBot.py @@ -5,7 +5,6 @@ from discord.ext.commands import Bot import time import pandas as pd -import random from Crypto import Random import hashlib import hmac @@ -21,6 +20,7 @@ num_ports = {21: "FTP", 22: "SSH", 23: "Telnet", 25: "SMTP", # List of ports 53: "DNS", 67: "DHCP Server", 68: "DHCP Client", 80: "HTTP", 110: "POP3", 143: "IMAP", 443: "HTTPS"} + text_ports = {v: k for k, v in num_ports.items()} # Reversed list of ports @@ -73,12 +73,12 @@ def symbol_insert(self, passphrase): symbol_count = round(len(passphrase) / 4) count = 0 while count < symbol_count: # pick random symbols based on int chosen and append it to passphrase - rand_int = random.randrange(0, len(symbol_list)) + rand_int = Random.random.randrange(0, len(symbol_list)) passphrase += symbol_list[rand_int] count += 1 passphrase = [char for char in passphrase] # no delimiter, no .split(). list comprehension to split characters - random.shuffle(passphrase) # Pycrypdome shuffle, shuffle the list elements around + Random.random.shuffle(passphrase) # Pycrypdome shuffle, shuffle the list elements around passphrase = ''.join(passphrase) # rejoin the list into the passphrase string return passphrase From 88d3060eb299f328ba28b8be3744d423035e5ea2 Mon Sep 17 00:00:00 2001 From: H4sh <38443613+TheHashZone@users.noreply.github.com> Date: Sun, 11 Nov 2018 23:59:09 +0100 Subject: [PATCH 6/7] Added pycrypto --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 9a053ca..93da286 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +pycrypto discord asyncio pandas From fc210b070e9895624683ddf4090db3fa8957657f Mon Sep 17 00:00:00 2001 From: CADII Date: Mon, 12 Nov 2018 13:42:22 -0700 Subject: [PATCH 7/7] Update infoBot.py Added other common ports for SQL, RDP, etc. --- infoBot.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/infoBot.py b/infoBot.py index 4905211..64cc688 100644 --- a/infoBot.py +++ b/infoBot.py @@ -19,7 +19,11 @@ num_ports = {21: "FTP", 22: "SSH", 23: "Telnet", 25: "SMTP", # List of ports 53: "DNS", 67: "DHCP Server", 68: "DHCP Client", - 80: "HTTP", 110: "POP3", 143: "IMAP", 443: "HTTPS"} + 80: "HTTP", 110: "POP3", 143: "IMAP", 443: "HTTPS", + 3306: "MySQL/MariaDB (TCP)", 1433: "SQL Database Engine (TCP)", 1434: "SQL Browser Service (UDP)", + 3050: "Firebird/Interbase (TCP)", 5432: "PostgreSQL (TCP)", 3351: "Pervasive SQL (TCP)", 1583: "Pervasive SQL (TCP)", + 137: "Pervasive SQL Named Pipe Authentication (TCP/UDP)", 138: "Pervasive SQL Named Pipe Authentication (TCP/UDP)", + 139: "Pervasive SQL Named Pipe Authentication (TCP/UDP)", 3389: "RDP", 8080: "HTTP"} text_ports = {v: k for k, v in num_ports.items()} # Reversed list of ports