
Language Sloth Discord ボットは、gif() および png() 関数においてディレクトリトラバーサルに対して脆弱です。これらの関数は、'name' パラメータにサニタイズされていないユーザー入力を使用してファイルパスを構築するため、攻撃者は意図されたリソースディレクトリの外部にあるファイルを参照できます。
files.py ファイル内の関数 "gif" と "png" は、"open" を使用してボットをホストしているサーバーからローカルファイルを取得するため、ディレクトリトラバーサルに対して脆弱です。以下のペイロードを使用すると、Discord 上の任意のユーザーが、ボットをホストしているサーバー上のどこかに置かれている ".gif" および ".png" ファイルを取得できます。
async def gif(self, ctx, name: str = None):
'''
(ADM) Sends a gif from the bot's gif folder.
:param name: The name of the gif file.
'''
await ctx.message.delete()
try:
with open(f'./gif/{name}.gif', 'rb') as pic:
await ctx.send(file=discord.File(pic))
except FileNotFoundError:
return await ctx.send("**File not found!**")
async def png(self, ctx, name: str = None):
'''
(ADM) Sends a png from the bot's png folder.
:param name: The name of the png file.
'''
await ctx.message.delete()
try:
await ctx.send(file=discord.File(f'./png/{name}.png'))
except FileNotFoundError:
return await ctx.send("**File not found!**")
name パラメータは、検証やサニタイズなしでファイルパスに直接挿入されます。
f'./gif/{name}.gif'
f'./png/{name}.png'
ペイロードの例:
z!gif ..\..\..\..\Windows\filename
z!png ..\..\..\..\Windows\filename
上の画像は、C:\Windows\cat.gif にある画像を抽出したものです。