أتمتة جمع المعلومات عبر برنامج مسح مجاني و قدرته على تحديد الخدمة المتصلة بالشبكة

Announcement, Article or Vulnerability

الابتكار والفعالية في الأمن السيبراني

موجز في العربية

برنامج ZMAP هو أحد البرامج المجانية المفتوحة المصدر التي يمكن استخدامها لمسح (Scan) الانظمة الموجودة على الشبكات. يُستخدم هذا البرنامج للكشف على المنافذ (ports) المستخدمة من قبل التطبيقات المتصلة بالشبكة و تحديد ما هو مفتوح (مستخدم عبر احد التطبيقات أو البرامج) أو مغلق (غير مستخدم أو محمي بجدار ناري - Firewall). يعمل zmap على بروتوكولي الشبكات TCP و UDP ولكن ما يميزه عن غيره هو امكانية تحديد الخدمة المستفيدة من ال UDP وكذلك ميزة ارسال نوع محدد من الداتا يحاكي عمل الخدمات أو التطبيقات لتحديد ماهيتها. و هذه ليست الميزة الوحيدة فوجود هذا البرنامج ضمن المكتبة الداعمة للغة البرمجة Python يتيح انتاج برامج جديدة تأتمت zmap و تعرض نتائجه بشكل أوضح كما يمكن أن ترسلها إلى قاعدة بيانات ليصار إلى الاستفادة منها في برامج أخرى كبرامج مسح الثغرات الأمنية، أو حتى تحليلها و استخراج رسوم بيانية منها.

Automated UDP Scanning via Zmap

One of the essential steps for hackers or penetration testers before taking over a system or an infrastructure is to get full knowledge about it. This is what so called a reconnaissance phase which can be performed either passively or actively to collect information about the target through various information gathering mechanisms. Port scanning using tools like zmap is an effective active reconnaissance method due to its speed and simplicity to clearly map the intended target. In this writing, we will demonstrate some of the zmap tool capabilities that helps gathering interesting information.
Putting the tool in action will basically reveal all open ports of a target system and hence it determines the potential services running behind each identified open port. This information is necessary to start discovering all vulnerabilities that would allow for an initial access. However, port scanning is very noisy and can be easily detected especially when a penetration tester does not know the security perimeter and all other in-place security measures. If scanning tool is not used correctly, especially from script kiddies who usually run it in an aggressive mode, the penetration testing attempt is discovered and scrutinized by defender team.

Port scanning: To get hands around scanning, let us explore more about the port scanner tool functionalities and how the relevant protocols react. The main two important protocols from TCP/IP family in subject are the transport protocols TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). Each of them has a 16 bits long port number field which enables a range of ports from 0 to 65535 that can be classified as reserved for a special purpose, dedicated to a certain application, or unknown. A port scanner determines a port status by sending a request, optionally with adjusted parameters, and wait for a response. The TCP protocol, as it is a connection-oriented protocol, will respond back with clear message. In contrast, UDP, which is a connection less protocol, might not react to queries as expected. Some well-known standard services as of DNS, SNMP, and DHCP run over UDP are excellent examples for such scan challenges. That is, unlike TCP it is hard to detect UDP ports as they might not respond back to requests sent. To make this happen, we adjust a specific payload in the transmitted packet to force a UDP server service to react. Zmap port scanner enables us to perform such operation also automatically and that is a good reason for choosing it over others.

Code snippet: We used Python (3.8) and the libzmap-python3 library. The latter allows to scan UDP and TCP ports using zmap, and it contains a parser to parse the results in a json format in order to save them. Zmap is a port scanner used for large-scale scanning and is considered one of the fastest scanning tools. Zmap uses many UDP probes (payload packets), which can help identifying open UDP ports. The importing of libzmap library in our code is illustrated below.

Libzmap Python Import

After sending the request, zmap waits for the response and pass the raw data to the parser, which parses and sends the data to an elasticsearch or any other database for further processing. The calling of the Zmap process in our code is illustrated below:

    Zmap Python Call

Probes are selected by the user in a config file depending on what UDP services need to be scanned, as mentioned before:

Zmap Probes

A snippet of example raw results, which are generated by zmap and sent to the parser, is illustrated below.

Raw Zmap Results

Your Content has been submitted