Commit 5ae4a673 authored by Clemens John's avatar Clemens John

Merge branch 'master' into 'master'

Fixed remote code execution

Prevent potential attacks

See merge request !3
parents 11a7a552 7f8d91cc
......@@ -11,6 +11,7 @@ require_once(ROOT_DIR.'/lib/extern/phpass/PasswordHash.php');
require_once(ROOT_DIR.'/lib/core/RouterStatus.class.php');
require_once(ROOT_DIR.'/lib/core/Networkinterface.class.php');
require_once(ROOT_DIR.'/lib/core/NetworkinterfaceStatus.class.php');
require_once(ROOT_DIR.'/lib/core/Validation.class.php');
if($_GET['section']=="get_standart_data") {
if ($_GET['authentificationmethod']=='hash') {
......@@ -130,6 +131,8 @@ if($_GET['section']=="get_hostnames_and_mac") {
/** Nodewatcher Version >18 */
if($_GET['section']=="insert_crawl_data") {
is_int($_POST['router_id']) or die('Invalid router id');
$router_data = Router_old::getRouterInfo($_POST['router_id']);
//If is owning user or if root
......@@ -155,6 +158,12 @@ if($_GET['section']=="insert_crawl_data") {
/**Insert Router Interfaces*/
foreach($_POST['int'] as $sendet_interface) {
if (!Validation::isValidInterfaceName($sendet_interface['name'])) {
echo 'Invalid interface name!';
continue;
}
/**
* Interface
*/
......
......@@ -7,31 +7,38 @@ require_once(ROOT_DIR.'/lib/core/RouterStatus.class.php');
require_once(ROOT_DIR.'/lib/core/Networkinterface.class.php');
require_once(ROOT_DIR.'/lib/core/NetworkinterfaceStatus.class.php');
require_once(ROOT_DIR.'/lib/core/Ip.class.php');
require_once(ROOT_DIR.'/lib/core/Validation.class.php');
class Crawl {
public function insertCrawlData($data) {
if (!is_int($data['router_id']))
return;
$router_data = Router_old::getRouterInfo($data['router_id']);
$actual_crawl_cycle = Crawling::getActualCrawlCycle();
$last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle();
/**Insert Router Interfaces*/
foreach($data['interface_data'] as $sendet_interface) {
if (!Validation::isValidInterfaceName($sendet_interface['name']))
continue;
//Update RRD Graph DB
$interface_last_endet_crawl = Interfaces::getInterfaceCrawlByCrawlCycleAndRouterIdAndInterfaceName($last_endet_crawl_cycle['id'], $data['router_id'], $sendet_interface['name']);
$traffic_rx_bps = round(($sendet_interface['traffic_rx']-$interface_last_endet_crawl['traffic_rx'])/$GLOBALS['crawl_cycle']/60);
$traffic_rx_bps = ($traffic_rx_bps<0) ? 0 : $traffic_rx_bps;
$traffic_tx_bps = round(($sendet_interface['traffic_tx']-$interface_last_endet_crawl['traffic_tx'])/$GLOBALS['crawl_cycle']/60);
$traffic_tx_bps = ($traffic_tx_bps<0) ? 0 : $traffic_tx_bps;
//Set default indizies to prevent from warnings
$sendet_interface['wlan_frequency'] = (isset($sendet_interface['wlan_frequency'])) ? preg_replace("/([A-Za-z])/","",$sendet_interface['wlan_frequency']) : "";
$sendet_interface['wlan_mode'] = (isset($sendet_interface['wlan_mode'])) ? $sendet_interface['wlan_mode'] : "";
$sendet_interface['wlan_essid'] = (isset($sendet_interface['wlan_essid'])) ? $sendet_interface['wlan_essid'] : "";
$sendet_interface['wlan_bssid'] = (isset($sendet_interface['wlan_bssid'])) ? $sendet_interface['wlan_bssid'] : "";
$sendet_interface['wlan_tx_power'] = (isset($sendet_interface['wlan_tx_power'])) ? $sendet_interface['wlan_tx_power'] : 0;
//check if interface already exists
$networkinterface_test = new Networkinterface(false, (int)$data['router_id'], $sendet_interface['name']);
//if interface not exist, create new
......@@ -41,7 +48,7 @@ class Crawl {
} else {
$networkinterface_id = $networkinterface_test->getNetworkinterfaceId();
}
//save crawl data for interface
$networkinterface_status = new NetworkinterfaceStatus(false, (int)$actual_crawl_cycle['id'], (int)$networkinterface_id, (int)$data['router_id'],
$sendet_interface['name'], $sendet_interface['mac_addr'], (int)$sendet_interface['mtu'],
......@@ -50,20 +57,20 @@ class Crawl {
$sendet_interface['wlan_mode'], $sendet_interface['wlan_frequency'], $sendet_interface['wlan_essid'], $sendet_interface['wlan_bssid'],
(int)$sendet_interface['wlan_tx_power'], false);
$networkinterface_status->store();
//Update RRDDatabase
$rrd_path_traffic_rx = ROOT_DIR."/rrdtool/databases/router_$data[router_id]_interface_$sendet_interface[name]_traffic_rx.rrd";
if(!file_exists($rrd_path_traffic_rx)) {
exec("rrdtool create $rrd_path_traffic_rx --step 600 --start ".time()." DS:traffic_rx:GAUGE:700:U:U DS:traffic_tx:GAUGE:900:U:U RRA:AVERAGE:0:1:144 RRA:AVERAGE:0:6:168 RRA:AVERAGE:0:18:240");
}
exec("rrdtool update $rrd_path_traffic_rx ".time().":".round($traffic_rx_bps/1000, 2).":".round($traffic_tx_bps/1000, 2));
//add unknown ipv6 link local addresses to netmon
//prepare data
$ipv6_link_local_addr = explode("/", $sendet_interface['ipv6_link_local_addr']);
$ipv6_link_local_netmask = (isset($ipv6_link_local_addr[1])) ? (int)$ipv6_link_local_addr[1] : 64;
$ipv6_link_local_addr = Ip::ipv6Expand($ipv6_link_local_addr[0]);
//first try to determine network of given address
$ipv6_link_local_network = Ip::ipv6NetworkFromAddr($ipv6_link_local_addr, (int)$ipv6_link_local_netmask);
$network = new Network(false, false, $ipv6_link_local_network, (int)$ipv6_link_local_netmask, 6);
......@@ -73,7 +80,7 @@ class Crawl {
$ip->store();
}
}
RrdTool::updateRouterClientCountHistory($data['router_id'], $data['client_count']);
}
}
......
......@@ -6,4 +6,9 @@ class Validation {
$regex = "/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/";
return (is_string($hostname) AND strlen($hostname)<=255 AND preg_match($regex, $hostname));
}
public static function isValidInterfaceName($interfacename) {
$regex = "/^[a-zA-Z0-9\-]*$/";
return is_string($interfacename) AND strlen($interfacename)<=20 AND preg_match($regex, $interfacename);
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment