Skip to content

Create admin_block_exe.py #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: Development
Choose a base branch
from
Open
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
62 changes: 62 additions & 0 deletions src/zorak/cogs/admin/admin_block_exe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
Listener to scan for exe or zip files.
"""
import logging

from discord.ext import commands

from zorak.utilities.cog_helpers._embeds import embed_cant_do_that

logger = logging.getLogger(__name__)


class FiletypeChecker(commands.Cog):
"""
Listener to check if a exe file or a zip file is attached in
a user's message to prevent malicious files from being sent.
"""

def __init__(self, bot):
self.bot = bot

@commands.Cog.listener()
async def on_message(self, message):
for attachment in message.attachments:
print(f"content type: {attachment.content_type}")
if attachment.content_type in [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Love the idea of blocking lots of different file types, As most of these are not really necessary.

"application/x-msdownload",
"application/x-dosexec",
"application/x-msdos-program",
"application/octet-stream",
"application/x-binary",
"application/x-mach-binary",
"application/x-apple-diskimage",
"application/java-archive",
"application/x-java-class",
"application/zip",
"application/x-zip-compressed",
"multipart/x-zip",
"application/x-compressed",
"application/x-compress",
"application/x-zip",
"application/zip-compressed",
"multipart/x-compressed",
]:
await message.delete()
await message.channel.send(
embed=embed_cant_do_that(
"You cannot send executable files or zip files."
),
delete_after=10,
)
logger.info(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it's good that we log this on the server, but perhaps we should have a more permanent log in the moderation logs to let us know what user, and what file was being uploaded. I'm not sure it would be necessary to actually log the file itself, but if it's a link, that would be useful to know about false positives / positive positives.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Add permanent logging here in Mod Logs

f"Blocked attachment from {message.author}:\n{message.clean_content}\nAttachment:{attachment.filename}"
)
return


def setup(bot):
"""
required.
"""
bot.add_cog(FiletypeChecker(bot))