Skip to content
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion ovisbot/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class Challenge(EmbeddedMongoModel):
attempted_by = fields.ListField(fields.CharField(), default=[])
solved_at = fields.DateTimeField(blank=True)
solved_by = fields.ListField(fields.CharField(), default=[], blank=True)
notebook_url = fields.CharField(default="", blank=True)
flag = fields.CharField()


Expand Down
35 changes: 0 additions & 35 deletions ovisbot/extensions/ctf/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
)
from ovisbot.helpers import (
chunkify,
create_corimd_notebook,
escape_md,
failed,
success,
Expand Down Expand Up @@ -197,7 +196,6 @@ async def addchallenge(self, ctx, challname, category):
self.bot.user: discord.PermissionOverwrite(read_messages=True),
ctx.message.author: discord.PermissionOverwrite(read_messages=True),
}
notebook_url = create_corimd_notebook()
challenge_channel = await ctx.channel.category.create_text_channel(
channel_name + "-" + challenge_name, overwrites=overwrites
)
Expand All @@ -206,16 +204,11 @@ async def addchallenge(self, ctx, challname, category):
tags=[category],
created_at=datetime.datetime.now(),
attempted_by=[ctx.message.author.name],
notebook_url=notebook_url,
)
ctf.challenges.append(new_challenge)
ctf.save()
await success(ctx.message)
await challenge_channel.send("@here Ατε να δούμε δώστου πίεση!")
notebook_msg = await challenge_channel.send(
f"Ετο τζαι το δευτερούι σου: {notebook_url}"
)
await notebook_msg.pin()

@addchallenge.error
async def addchallenge_error(self, ctx, error):
Expand Down Expand Up @@ -276,34 +269,6 @@ async def rmchallenge_error(self, ctx, error):
"Παρέα μου... εν κουτσιάς... Εν έσιει έτσι challenge!"
)

@ctf.command()
async def notes(self, ctx):
"""
Shows the notebook url for the particular challenge channel that you are currently in. If this command is run outside of a challenge channel, then ovis gets mad.
"""
chall_name = ctx.channel.name
ctf = CTF.objects.get({"name": ctx.channel.category.name})

# Find challenge in CTF by name
challenge = next((c for c in ctf.challenges if c.name == chall_name), None)

if not challenge:
raise NotInChallengeChannelException

if challenge.notebook_url != "":
await ctx.channel.send(f"Notes: {challenge.notebook_url}")
else:
await ctx.channel.send("Εν έσσιει έτσι πράμα δαμέ...Τζίλα το...")

@notes.error
async def notes_error(self, ctx, error):
if isinstance(
error.original, (NotInChallengeChannelException, CTF.DoesNotExist)
):
await ctx.channel.send(
"Ρε πελλοβρεμένε! For this command you have to be in a ctf challenge channel created by `!ctf addchallenge`."
)

@ctf.command()
@commands.has_permissions(manage_channels=True, manage_roles=True)
async def finish(self, ctx, ctf_name):
Expand Down
64 changes: 58 additions & 6 deletions ovisbot/extensions/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import logging
from ovisbot.helpers import chunkify
import struct
import string
import crypt

from Crypto.Util.number import long_to_bytes, bytes_to_long
from discord.ext import commands

logger = logging.getLogger(__name__)

def rotn_helper(offset, text):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change seems unrelated to the goal of this PR - can you please rebase so it goes away and only the notebook related changes are left? 🙏

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

should be OK now :)

shifted = string.ascii_lowercase[offset:] + string.ascii_lowercase[:offset] +\
string.ascii_uppercase[offset:] + string.ascii_uppercase[:offset]
shifted_tab = str.maketrans(string.ascii_letters, shifted)
return text.translate(shifted_tab)

class Utils(commands.Cog):
def __init__(self, bot):
Expand Down Expand Up @@ -53,14 +60,59 @@ async def hex2str(self, ctx, param):

@utils.command()
async def rotn(self, ctx, shift, *params):
shift = int(shift)
'''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here 🙏

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this should be OK now, too :)

Returns the ROT-n encoding of a message.
'''
msg = ' '.join(params)
shifted = string.ascii_lowercase[shift:] + string.ascii_lowercase[:shift] +\
string.ascii_uppercase[shift:] + string.ascii_uppercase[:shift]
shifted_tab = str.maketrans(string.ascii_letters, shifted)
shifted_str = msg.translate(shifted_tab)
await ctx.send(f"{msg} => {shifted_str}")
out = 'Original message:\n' + msg
if shift == "*":
for s in range(1, 14):
out += f'\n=[ ROT({s}) ]=\n'
out += rotn_helper(s, msg)
else:
shift = int(shift)
shifted_str = rotn_helper(shift, msg)

out += f'\n=[ ROT({shift}) ]=\n'
out += 'Encoded message:\n' + shifted_str

for chunk in chunkify(out, 1700):
await ctx.send("".join(["```", chunk, "```"]))

@utils.command()
async def genshadow(self, ctx, cleartext, method = None):
'''
genshadow, generates a UNIX password hash and a corresponding /etc/shadow entry
and is intended for usage in boot2root environments

Available hash types:
+ MD5
+ Blowfish
+ SHA-256
+ SHA-512
'''
__methods = {
"1": crypt.METHOD_MD5,
"MD5": crypt.METHOD_MD5,

"2": crypt.METHOD_BLOWFISH,
"BLOWFISH": crypt.METHOD_BLOWFISH,

"5": crypt.METHOD_SHA256,
"SHA256": crypt.METHOD_SHA256,

"6": crypt.METHOD_SHA512,
"SHA512": crypt.METHOD_SHA512
}
if method and not method.isnumeric():
method = method.upper()
method = __methods.get(method, None)

unix_passwd = crypt.crypt(cleartext, method)
shadow = f"root:{unix_passwd}:0:0:99999:7::"
await ctx.send(f"{cleartext}:\n" +\
f"=> {unix_passwd}\n" +\
f"=> {shadow}")

def setup(bot):
bot.add_cog(Utils(bot))
7 changes: 0 additions & 7 deletions ovisbot/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ def escape_md(text):
return text.replace("_", "\_").replace("*", "\*").replace(">>>", "\>>>")


def create_corimd_notebook():
base_url = "https://notes.status.im/"
create_new_note_url = base_url + "new"
res = requests.get(create_new_note_url)
return res.url


def wolfram_simple_query(query, app_id):
base_url = "https://api.wolframalpha.com/v2/result?i={0}&appid={1}"
query_url = base_url.format(urllib.parse.quote(query), app_id)
Expand Down