Skip to content

Instantly share code, notes, and snippets.

@meatyite
Last active April 17, 2019 09:44
Show Gist options
  • Save meatyite/556d49aade9f270efbdee1b7debf82be to your computer and use it in GitHub Desktop.
Save meatyite/556d49aade9f270efbdee1b7debf82be to your computer and use it in GitHub Desktop.
Virustotal_Scanner_DiscordBot.py
#!/usr/bin/python3
######################################
# Made by sl4v #
# Licensed under the WTFPL, #
# see www.wtfpl.net/txt/copying/ #
######################################
import discord, requests, json, sys
file_ext_to_scan = ['exe', 'dll', 'zip', 'rar', 'tar.gz', 'msi', 'jar']
virustotal_apikey = ''
discord_apitoken = ''
class Client(discord.Client):
async def on_ready(self):
print('Logged in as')
print(self.user.name)
print(self.user.id)
print('------')
async def on_message(self, message):
# we do not want the bot to reply to itself
if message.author.id == self.user.id:
return
"""
# Save this for later reference
if message.content.startswith('!hello'):
await message.channel.send('Hello {0.author.mention}'.format(message))
"""
if len(message.attachments) >= 0:
for attachment in message.attachments:
for file_ext in file_ext_to_scan:
if attachment.filename.endswith('.' + file_ext):
params = {'apikey': virustotal_apikey, 'url': attachment.url}
headers = {
"User-Agent" : "a discordapp bot that scans attached files"
}
response = requests.post('https://www.virustotal.com/vtapi/v2/url/scan',
params=params, headers=headers)
await message.channel.send('WARNING! THIS TYPE A FILE MAY CONTAIN A VIRUS. HERE IS VIRUSTOTAL SCAN OF THIS FILE, MAKE SURE YOU CLICK ON "GOTO DOWNLOADED FILE ANALYSIS" ON VIRUSTOTAL')
permalink = json.loads(response.text)['permalink']
await message.channel.send(permalink)
if __name__ == '__main__':
for i in range(1, len(sys.argv)):
arg = sys.argv[i]
if arg == '-h':
print("""\
-h show this help menu and quit
-d [discord api token] set the discord api token
-v [virustotal api key] set the virustotal api key
""")
sys.exit(0)
elif arg == '-d':
discord_apitoken = sys.argv[i + 1]
elif arg == '-v':
virustotal_apikey = sys.argv[i + 1]
client = Client()
client.run(discord_apitoken)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment