Exemplo n.º 1
0
        public bool ChangeModbusTcpRules(string dst_IP, string src_IP, string min_addr, string max_addr, string func, int Min_data, int Max_data, string dev_IP, bool log_record, bool add_delete)
        {
            ModbusTcpRulesForm mtrf = new ModbusTcpRulesForm();

            mtrf.setIP_Addr_Funcode(dst_IP, src_IP, min_addr, max_addr, func, Min_data, Max_data);

            DeviceForm devform = new DeviceForm(dev_IP, 22222);

            IConfigRules configDevice = new ConfigDPIRules(devform);

            return(configDevice.ConfigModbusTcpRules(mtrf, log_record, add_delete));
        }
Exemplo n.º 2
0
        public bool ConfigModbusTcpRules(ModbusTcpRulesForm mtrf, bool log_flag, bool add_delete)
        {
            // RulesDataProcess.ModbusTcpRulesDataProcess(mtrf);

            String dpi_pro = "modbusTcp";
            string flag = null; string dpi_rules_from_master_to_slave0 = null; string sql_rule = null;;

            if (mtrf.getSrc_IP() == "any" & mtrf.getDst_IP() == "any")
            {
                dpi_rules_from_master_to_slave0 = "iptables" + " -A" + " " + "FORWARD" + " " + "-p tcp" + " " + "--dport" + " " + "502" + " " + "-m" + " " + dpi_pro + " " + "--data-addr" + " " + mtrf.getMin_addr() + ":" + mtrf.getMax_addr() + " " + "--modbus-func " + mtrf.getfunc() + " " + "--modbus-data " + mtrf.getMin_data() + ":" + mtrf.getMax_data() + " -j" + " " + "DROP";
            }
            else if (mtrf.getSrc_IP() == "any" & mtrf.getDst_IP() != "any")
            {
                dpi_rules_from_master_to_slave0 = "iptables" + " -A" + " " + "FORWARD" + " " + "-p tcp" + " " + "--dport" + " " + "502" + " " + "-d" + " " + mtrf.getDst_IP() + " " + "-m" + " " + dpi_pro + " " + "--data-addr" + " " + mtrf.getMin_addr() + ":" + mtrf.getMax_addr() + " " + "--modbus-func " + mtrf.getfunc() + " " + "--modbus-data " + mtrf.getMin_data() + ":" + mtrf.getMax_data() + " -j" + " " + "DROP";
            }
            else if (mtrf.getSrc_IP() != "any" & mtrf.getDst_IP() == "any")
            {
                dpi_rules_from_master_to_slave0 = "iptables" + " -A" + " " + "FORWARD" + " " + "-p tcp" + " " + "--dport" + " " + "502" + " " + "-s " + mtrf.getSrc_IP() + " " + "-m" + " " + dpi_pro + " " + "--data-addr" + " " + mtrf.getMin_addr() + ":" + mtrf.getMax_addr() + " " + "--modbus-func " + mtrf.getfunc() + " " + "--modbus-data " + mtrf.getMin_data() + ":" + mtrf.getMax_data() + " -j" + " " + "DROP";
            }
            else
            {
                dpi_rules_from_master_to_slave0 = "iptables" + " -A" + " " + "FORWARD" + " " + "-p tcp" + " " + "--dport" + " " + "502" + " " + "-s " + mtrf.getSrc_IP() + " " + "-d" + " " + mtrf.getDst_IP() + " " + "-m" + " " + dpi_pro + " " + "--data-addr" + " " + mtrf.getMin_addr() + ":" + mtrf.getMax_addr() + " " + "--modbus-func " + mtrf.getfunc() + " " + "--modbus-data " + mtrf.getMin_data() + ":" + mtrf.getMax_data() + " -j" + " " + " DROP";
            }
            //string dpi_rules_from_master_to_slave1 = "iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT";
            string dpi_rules_from_master_to_slave_log = "iptables" + " -A" + " " + "FORWARD" + " " + "-p tcp" + " " + "--dport" + " " + "502" + " " + "-s " + mtrf.getSrc_IP() + " " + "-d" + " " + mtrf.getDst_IP() + " " + "-m" + " " + dpi_pro + " " + "--data-addr" + " " + mtrf.getMin_addr() + ":" + mtrf.getMax_addr() + " " + "--modbus-func " + mtrf.getfunc() + " " + "--modbus-data " + mtrf.getMin_data() + ":" + mtrf.getMax_data() + " -j" + " " + "LOG" + " " + "--log-prefix " + "\"" + "DROP&modbusTCP&data_illegal " + "\"";

            if (add_delete == true)
            {
                flag     = "DPI1";
                sql_rule = "insert into modbustcp values ('" + StaticGlobal.firewallmac + "','" + dpi_pro + "','" + mtrf.getSrc_IP() + "','" + mtrf.getDst_IP() + "','"
                           + mtrf.getMin_addr() + "','" + mtrf.getMax_addr() + "','" + mtrf.getMin_data() + "','" + mtrf.getMax_data() + "','" + mtrf.getfunc() + "','" + log_flag + "');";
            }

            else if (add_delete == false)
            {
                flag     = "DPI0";
                sql_rule = "delete from modbustcp where fw_mac= '" + StaticGlobal.firewallmac + "' and protocol = '" + dpi_pro + "' and source = '"
                           + mtrf.getSrc_IP() + "' and destination = '" + mtrf.getDst_IP() + "' and coiladdressstart = '" + mtrf.getMin_addr() + "' and coiladdressstart = '"
                           + mtrf.getMax_addr() + "'and minspeed ='" + mtrf.getMin_data() + "' and maxspeed ='" + mtrf.getMax_addr() + "' and functioncode = '" + mtrf.getfunc() + "' and log = '" + log_flag + "';";
            }
            string rule = flag + dpi_rules_from_master_to_slave_log + " && " + dpi_rules_from_master_to_slave0;

            DPIdb_operate.dboperate(sql_rule);
            SendInfo sendcmd = new SendInfo(devform);

            return(sendcmd.SendConfigInfo(rule));
        }