essstat

2025-12-07 0 709

essstat – TP-Link Easy Smart Switch port statistics

TP-Link Easy Smart Switches are a family of managed switches capable of supporting QoS, VLANs and Link Aggregation Groups (LAGs).
They are managed through a web based interface, giving access a number of functions, including basic packets counters per-port.
Unfortunately, these switches do not implement SNMP for access to these counters, nor do they appear to implement a discrete URL for
direct access to this information. This project addresses this issue to produce per-port statistics from a single command line invocation
with output that can be trivially parsed for formatted output, or entered into a monitoring system like Zabbix.

This project has been tested against TP-Link switch models TL-SG1016DE and TL-SG108E. It should also be compatible with the other
members of this family, including the TL-SG105E and TL-SG1024DE.


*** WARNING ***

The Easy Smart Switch family has a number of unresolved vulnerabilities, including CVE-2017-17746. As described in https://se**clists.*org/fulldisclosure/2017/Dec/67, once a user from a given source IP address authenticates to the web-based management interface of the switch, any other user from that same source IP address is treated as authenticated.

The Python scripts in this project should be used only from a host that does not have general user access.


Major Components

essstat.py is a lightweight utility is used to pull port statistics from the switch and output in a readily parsable format. Additional
code will be added to parse and either output or store these statistics.

essstat.py

This lightweight Python application performs a quick login through the switch\’s web based administrative interface, and then queries the
unit for the current port statistics. Credentials for accessing the unit are passed on the command line. The utility was coded with
Python 3.6 and uses the Beautiful Soup library.

Usage

essstat.py [-h] [-1] [-d] -p TPpswd [-s] [-u TPuser] TPhost

Options

positional arguments:
TPhost                IP address or hostname of switch
optional arguments:
-h, --help            show this help message and exit
-1, --1line           output in a single line
-d, --debug           activate debugging output
-j, --json            output in JSON format
-p TPpswd, --password TPpswd
                      password for switch access
-s, --statsonly       output post statistics only
-u TPuser, --username TPuser
                      username for switch access

Example

$ essstat.py myswitch -p ChangeMe
2020-03-28 11:25:15
max_port_num=8
1;Enabled;Link Down;0,0,0,0
2;Enabled;10M Full;3568644976,0,3144940915,0
3;Enabled;1000M Full;237232286,0,66662515,0
4;Enabled;1000M Full;4019260430,0,3721138807,0
5;Enabled;1000M Full;1300360968,0,355032522,0
6;Enabled;Link Down;0,0,0,0
7;Enabled;1000M Full;2903398648,0,4293632425,5
8;Enabled;Link Down;0,0,0,0

Accumulate Data in CSV

The simplest way to accumulate data from the switches is to have essstat.py execute with the --1line option and
append the output to a CSV file. You can then pull down a copy of the CSV file and process the raw data through
this Excel workbook to produce a dynamic chart that will automatically rescale to the available data.

The first step is to setup a directory where the CSV files will accumulate the data. I chose to run all this under the
zabbix user that supports the monitoring application on this host. You may choose a different user, but just make sure
that the group of the directory matches the group of the user you will use.

$ ls -ald  /var/log/essstat
drwxrwxr-x. 2 root zabbix 68 Mar 30 10:56 /var/log/essstat

Next, create the cron job(s) for periodic data collection. To do this, create the file /etc/cron.d/essstat and add
one schedule for each switch you will monitor. To make this reasonably self-maintaining, include the current year as
part of the CSV file specification.

*/10 * * * *    zabbix  /usr/local/bin/essstat.py -1 -p ChangeMe1 orange >> /var/log/essstat/essstat-orange-`date +\\%G`.csv
*/10 * * * *    zabbix  /usr/local/bin/essstat.py -1 -p ChangeMe2 black >> /var/log/essstat/essstat-black-`date +\\%G`.csv

In the above example, there are two switches being monitored, named orange and black. For each switch, data collection
will run every 10 minutes starting on each hour. The data for orange will be accumulated in the file
/var/log/essstat/essstat-orange-2020.csv during the calendar year 2020.

essstat.xlsm

This macro-enabled Excel workbook is probably the best way to read and chart the port statistics. The workbook will automatically construct a query and execute a web GET operation against the monitoring server using the essstat2.cgi script. To configure the workbook for your local installation, the defined name essstatBaseURL must be modified to point to the webserver operating on your monitoring host and the name of the CGI script. To make this update in Excel 2019 on Windows, click the Excel Formulas tab, then click the Name Manager button on the ribbon. Click on the entry for essstatBaseURL and modify the entry to suit. Be sure to click the button with the green checkmark to save the modification, close the dialog and save the updated workbook. This needs to be done only once.

When using the workbook, the name of the switch and the reporting from and to date/times are specified in the parameter table at the top left of the WebData tab. Click the Update From Web button to fetch the data into the table and dynamically update the plot on the PPS Chart tab. If the switch under study has only eight ports, the extra ports will be hidden automatically.

The name of the switch and the metric plotted appears in the title of the chart. Once the metrics have been loaded into the table, the different metrics may be loaded into the chart by selecting from the choices in the dropdown cell next to the ‘Chart metriclabel. Moving between theses metrics for the same switch does *not* require doing anotherUpdate From Web` operation.

The table on the *LocalPortNames tab allows you to override the default port names shown in the chart. This table is entirely optional and defining entries for all ports on a given switch is not required (it is perfectly fine to define port name overrides for just a couple ports for a given switch). If you have multiple switches, you can add entries for all of them in a single table.

essstat-TPLhost.xlsx

This Excel workbook prototype can be used to process a copy of the raw --1line data output from essstat.py that has been
accumulated in a CSV file. Start by copying the file to a new name, incorporating the name of the switch being
monitored. This will be the switch monitoring notebook. For example:

C:\\user\\me\\Documents> copy essstat-TPLhost.xlsx essstat-orange.xlsx

Next, download a copy of the CSV data that has been accumulated on your monitoring host and open it
in Excel, as well as the switch monitoring workbook. At this stage, you will need to copy the data from the CSV to the RawData tab
of the switch monitoring notebook by value. To do this, go to the CSV file in Excel and select the top-left cell, A1. In Windows,
you can use the key sequence Ctrl-Shift-End to select all the data, then press Ctrl-Insert to copy all of it. Then go to the switch
monitoring workbook and select the first data cell in the RawData tab at A2 (top-left cell, below the headings). Right click
and choose the option to paste values. With the raw data in place, you should scroll down to make note of the last populated row. The
original CSV file can now be closed.

Click on the PPS Table tab to extend the analysis table and select the metric to be charted. The key is to extend the structured
table range to match the available RawData. Press Ctrl-End to locate the end of the table. Mouse over the tiny square at the
lower left corner of the cell until your mouse pointer changes to a crosshair. Click and drag down to the same row number as the last
populated row number in the RawData tab. All the formulae and ranges in PPS Table and PPS Chart will extend automatically.

There are four metrics that are being tracked for each port: Tx Good Packets, Tx Bad Packets, Rx Good Pkts, and Rx Bad Pkts. The
dropdown at cell B2 on the PPS Table tab is used to select which metric should be populated in the table and charted.

essstat.cgi

This CGI script is used to query the CSV data that has been accumulated on your monitoring host and return
matching entries. The CGI is self-contained, relying only upon access to awk for execution of a simple inline script. There are three
variables implmented in the CGI:

  • esTPLhost: (required) The name of the switch as used to store the accumulated CSV data.
  • esFrom: Return statistics starting with this date/time in format yyyy-mm-dd HH:MM:SS. Default value is for January 1st of the
    current year.
  • esTo: Return statistics ending with this date/time in format yyyy-mm-dd HH:MM:SS. Default value is for all data to the current
    date/time.

Note that partial date/time specifications are allowed, since the matching entries are determined by a simple string comparison. The
From and To dates are allowed to span across a year boundary (e.g. from 2019 to 2020).

To query the monitoring server for port statistics for the switch known as orange for the time range from 2/23/2020 00:00 to
3/7/2020 11:30, the URI would look like:

http://monitoring.my***domain.com/cgi-bin/essstat.cgi?esTPLhost=orange&esTo=2020-03-07%2011:30&esFrom=2020-02-23

essstat2.cgi

This CGI script is designed to support operation of the essstat.xlsm Excel workbook. The script supports the same query parameters as essstat.cgi and returns data for the same metrics. However, instead of returning raw packets counts in each record, essstat2.cgi will return the average packets per second rate since the previous record. The script will calculate the actual delta time between the current and previous record to ensure the rate is accurate. The script also has handling for individual counters resetting to zero as they wrap the maximum integer size for the counter. In such a case, the packet per second rate from the previous interval will be returned for the affected statistic.

Technical Background

The TP-Link Easy Smart Switch has more capabilities than a completely unmanaged switch. However, the management environment is relatively closed, with only a proprietary management client (Easy Smart Configuration Utility) or a web-based management page on the switch available. Furthermore, there is no support for monitoring the switch with SNMP. This means that our only entry into the switch will be via the protocol used by the proprietary client, or by scaping the web-based management interface on the switch.

First, a little background on the UDP-base Easy Smart Configuration Protocol (ESCP) that this project does not use. The Easy Smart Configuration Utility interacts with the switch over UDP with broadcasts. The client will send a UDP broadcast from port 29809 to 29808 of a specially encoded discovery packet. Compatible switches on the network will broadcast a response from port 29808 to 29809 than includes the name, model and IP address of the switch. From this point, it is up to the client to encode a login sequence and broadcast this on the network, with the expectation that the specific target switch will receive and process the instruction. This could be to send back information in another broadcast packet, modify the configuration of the switch, or take some other action.

This design and implementation has a number of issues that should cause some concern which have been highlighted by security researchers (@chrisdcmoore in Information disclosure vulnerability in TP-Link Easy Smart switches and @chmod7850 in Vulnerability disclosure TP-Link multiples CVEs). While hacking into the ESCP would be easy enough, I really did not like the idea of literally broadcasting credentials across the network on a regular basis to grab statistics.

The apprach that this project does use, the web-based client, is problematic as well. Using a TCP unicast connections is better, but SSL is not implemented by the switch. While it is possible to reconfigure the switch to use a different administrative username, there is only one username for accessing the switch. This precludes employing role-based access with a dedicated username for reading statistics only. The credential we use to grab the statistics could also be used to access the management interface allowing resetting of counters, reconfiguring the switch or even replacing the firmware.

Worse still are the vulnerabilities reported in CVE-2017-17746. As described in https://se**clists.*org/fulldisclosure/2017/Dec/67, once a user from a given source IP address authenticates to the web-based management interface of the switch, any other user from that same source IP address is treated as authenticated. This condition is created by the execution of the Python scripts in this project, where other users logged into or tunneling through the same host would then have unauthenticated access to the management interface of the switch. This problem can be mitigated by running the scripts from a dedicated management host. Use of a dedicated out-of-band management LAN could offer protection as well, but these switches are unlikely to be used in such an elaborately structured environment.


Peter Smode

psmode [at] kitsnet.us

下载源码

通过命令行克隆项目:

git clone https://github.com/psmode/essstat.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 essstat https://www.zuozi.net/31467.html

SPA asp.net api vuejs
上一篇: SPA asp.net api vuejs
netcat
下一篇: netcat
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务