Cacti / plugin_mactrack

Mactrack Plugin for Cacti
GNU General Public License v2.0
12 stars 24 forks source link

mactrack_resolver.php variable vlan_id line 176 #143

Closed mikelott4u closed 3 years ago

mikelott4u commented 3 years ago

I am a PHP noob but learning very fast how to debug. I found a simple bug in mactrack_resolver.php where the vlan_id was passed to the DB function without single quotes to declare N/A as string. N/A is the default value in the table for vlan_id. I know you're expecting digits but N/A is valid and sent me on a bunny trail looking for column N.

Debug error from log where you find N/A vice 'N/A' for the vlan_id variable

2020/10/21 06:30:07 - CMDPHP ERROR: A DB Exec Failed!, Error: Unknown column 'N' in 'field list'

2020/10/21 06:30:07 - DBCALL ERROR: A DB Exec Failed!, Error: 1054, SQL: 'INSERT INTO mac_track_temp_ports (site_id, device_id, hostname, dns_hostname, device_name, vlan_id, vlan_name, mac_address, vendor_mac, ip_address, port_number, port_name, scan_date) VALUES (1,2,'192.168.3.1','192.168.1.1','pfSense.hometurf',N/A,'N/A','98:DE:D0:AF:FB:52','98:DE:D0','192.168.1.1','1','N/A','2020-10-21 06:30:02'), (1,2,'192.168.3.1','tv.hometurf','pfSense.hometurf',N/A,'N/A','00:1D:4F:48:CB:0C','00:1D:4F','192.168.3.137','2','N/A','2020-10-21 06:30:02'), (1,2,'192.168.3.1','192.168.3.4','pfSense.hometurf',N/A,'N/A','48:EE:0C:6B:B0:58','48:EE:0C','192.168.3.4','2','N/A','2020-10-21 06:30:02'), (1,2,'192.168.3.1','android-9034bd8936d456ba.hometurf','pfSense.hometurf',N/A,'N/A','5C:51:81:C1:7C:05','5C:51:81','192.168.3.118','2','N/A','2020-10-21 06:30:02'), (1,2,'192.168.3.1','mike-HP-Laptop-17-ak0xx.hometurf','pfSense.hometurf',N/A,'N/A','A4:B1:C1:AD:C0:6E','A4:B1:C1','192.168.3.104','2','N/A','2020-10-21 06:30:02'), (1,2,'192.168.3.1','SAMSUNG-SM-G891A.hometurf','pfSense.hometurf',N/A,'N/A','B0:72:BF:75:EE:F3','B0:72:BF','192.168.3.192','2','N/A','2020-10-21 06:30:02'), (1,2,'192.168.3.1','192.168.3.197','pfSense.hometurf',N/A,'N/A','D4:6A:6A:E1:FC:F7','D4:6A:6A','192.168.3.197','2','N/A','2020-10-21 06:30:02'), (1,1,'192.168.1.1','192.168.2.1','DD-WRT',N/A,'N/A','D8:B6:B7:FA:0E:57','D8:B6:B7','192.168.2.1','6','N/A','2020-10-21 06:30:02'), (1,1,'192.168.1.1','192.168.1.145','DD-WRT',N/A,'N/A','80:C1:6E:F4:9A:88','80:C1:6E','192.168.1.145','8','N/A','2020-10-21 06:30:02') ON DUPLICATE KEY UPDATE site_id = VALUES(site_id), hostname = VALUES(hostname), dns_hostname = VALUES(dns_hostname), device_name = VALUES(device_name), vlan_id = VALUES(vlan_id), vlan_name = VALUES(vlan_name), vendor_mac = VALUES(vendor_mac), port_name = VALUES(port_name)'

my fix for line 176 is db_qstr

           /* output updated details to database */
            foreach($unresolved_ips as $unresolved_ip) {
                    $sql[] = '(' .
                            $unresolved_ip['site_id']               . ',' .
                            $unresolved_ip['device_id']             . ',' .
                            db_qstr($unresolved_ip['hostname'])     . ',' .
                            db_qstr($unresolved_ip['dns_hostname']) . ',' .
                            db_qstr($unresolved_ip['device_name'])  . ',' .
                            db_qstr($unresolved_ip['vlan_id'])      . ',' .
                            db_qstr($unresolved_ip['vlan_name'])    . ',' .
                            db_qstr($unresolved_ip['mac_address'])  . ',' .
                            db_qstr($unresolved_ip['vendor_mac'])   . ',' .
                            db_qstr($unresolved_ip['ip_address'])   . ',' .
                            db_qstr($unresolved_ip['port_number'])  . ',' .
                            db_qstr($unresolved_ip['port_name'])    . ',' .
                            db_qstr($unresolved_ip['scan_date'])    . ')';
            }

I hope this helps because this will help new people using Mactrack to navigate picking the wrong device type and wondering why DNS does not resolve. Alternate fix might be vlan_id default value as number vice N/A

Thanks. Very powerful tool.

TheWitness commented 3 years ago

Thanks, fixed.