Problem with script or something else after upgrade to 7.23 and status flagged

Hi.

In work I've Chateau LTE12. LTE is backup connection. I've script which check main ISP and if it failover LTE starts - it works until 7 Aug when upgrade firmware from 7.20 or 7.21 (I don't remember) to 7.23. At 7 Aug people from my work phoned to me, that they cannot work remotely (via plink). I restarted router and still don't work, change main ISP to LTE and script change to main (main works OK). Quick reading on internet - Ros has CVE and ... we had "security breach", ssh not work because someone change who can access via ssh (172.xxx, 10.xxx and 196.xxx). Removed this and now they can work remotely. I upgraded firmware to 7.23.x stable, this upgrade flagged router. Script no fully working because status is flagged or something else changed with upgrade?

Script:

:local adrHost "1.1.1.1";
:local WANPort "WANPort";
:local iloscProb 20;
:local warunek 15;
:local statusMainISP [/ip route get [find comment=GlownyISP] disabled];
:local statusBackupISP [/ip route get [find comment=Zapasowy] disabled];
:local iloscOdpowiedzi;
:set iloscOdpowiedzi [/ping $adrHost interface=$WANPort count=20];
#sprawdzamy warunek gdy 25% nie przeszło
:if ($iloscOdpowiedzi<$warunek) do={
:if (!$statusMainISP) do={
/ip route disable [find comment=GlownyISP];
};
:if ($statusBackupISP) do={
/ip route enable [find comment=Zapasowy];
};
/log info "Wyłączono główne połączenie, ilość odpowiedzi = $iloscOdpowiedzi (<$warunek) - test przez $WANPort";
};
#inaczej jest ok
:if ($iloscOdpowiedzi>=$warunek) do={
:if ($statusMainISP) do={
/ip route enable [find comment=GlownyISP];
};
:if (!$statusBackupISP) do={
/ip route disable [find comment=Zapasowy];
};
/log info "Przywrócono główne połączenie, ilość odpowiedzi = $iloscOdpowiedzi (>=$warunek) - test przez $WANPort";
};

WANPort is port where main ISP. I testing more ping then 4 because sometimes first 4 is OK and rest not.

BackupISP (comment=Zapasowy) is LTE.

Until upgrade script work OK, after if ISP is LTE this /ping $adrHost interface=$WANPort count=20] always return 0.

In short:
Compromised device;
export outside the device the file obtaied with /export show-sensitive file=mybackup;
REMOVE SIM;
perform a Netinstall;
clear the flagged status;
import back the mybackup.rsc "line by line" with notepad or similar, so you can check exactly what you restore;
do not use .backup;
disable all management services vs the WAN, and do not open services vs Internet for no reason;
Insert back the SIM.

Yesterday I do your list. Script still not work. It change from MainISP to BackupISP but not from Backup to Main. I think MT change something in newer ROs.

I still need working script (in September out LTE limit reach 0 because script not work)

Do not mix problems.

The main problem is that new version flagged your router a compromised so you HAVE to resrot the problem as the first step as @rextended wrote. Period.

The next step is to check why script does not work but it could be corellated to the upgrade but may be not.

Do not focus on a script that is not crucial comparing to some "enemies" inside your router.

As I wrote - "Yesterday I do your (rextended) list".

If it work before upgrade?

Your device still flagged?
Ping do not work as expected if is flagged...

What is the results of /sys device-mode pri command?

[rex@CCR-v7] > 
[rex@CCR-v7] > {
{... 
{... :local adrHost         "1.1.1.1"
{... 
{... :local WANPort         "ether1"
{... 
{... :local iloscOdpowiedzi [/ping $adrHost interface=$WANPort count=5]
{... 
{... 
{... 
{... :put $iloscOdpowiedzi
{... 
{... }
  SEQ HOST                                     SIZE TTL TIME       STATUS                                                                                                                                                                                  
    0 1.1.1.1                                    56  59 2ms814us  
    1 1.1.1.1                                    56  59 2ms648us  
    2 1.1.1.1                                    56  59 2ms805us  
    3 1.1.1.1                                    56  59 2ms739us  
    4 1.1.1.1                                    56  59 2ms696us  
    sent=5 received=5 packet-loss=0% min-rtt=2ms648us avg-rtt=2ms740us max-rtt=2ms814us 

5
[rex@CCR-v7] > :put [/sys resource get version]
7.23.7 (long-term)

The script, if it is exactly as you pasted it on the forum, is incorrect,
it is missing a } at the end...

Also, cleaning up the script wouldn't hurt,
there are too many semicolons and other parts that are unnecessary or unclear,
especially if it's written in a language other than English.

:local adrHost   "1.1.1.1"
:local WANPort   "WANPort"
:local iloscProb 20
:local warunek   15
:local MainISP   "GlownyISP"
:local BackupISP "Zapasowy"

:local iloscOdpowiedzi [:ping $adrHost interface=$WANPort count=$iloscProb]
/ip route
:if ($iloscOdpowiedzi < $warunek) do={
# sprawdzamy warunek gdy 25% nie przeszlo
    disable [find where comment=$MainISP   and disabled=no ]
    enable  [find where comment=$BackupISP and disabled=yes]
    :log info "Wylaczono glówne polaczenie, ilosc odpowiedzi = $iloscOdpowiedzi (<$warunek) - test przez $WANPort"
} else={
# inaczej jest ok
    enable  [find where comment=$MainISP   and disabled=yes]
    disable [find where comment=$BackupISP and disabled=no ]
}

Router is NO flagged. I do your list.

@D53G] > /sys/device-mode/ pri
                 mode: advanced     
     allowed-versions: 7.13+,6.49.8+
              flagged: no           
     flagging-enabled: yes          
            scheduler: yes          

Maybe I don't copy all code and missing }.

I usually write code in C# and SQL (my job) and certain habits remain.

Have you tried the modified script?

Yes. Still work on 50% - change from MainISP to Backup, not reverse. If MainISP is disabled

ping $adrHost interface=$WANPort count=$iloscProb always 0.

Try in terminal when MainISP is disabled ping 1.1.1.1 interface=WANPort count=20 and response is Timeout.

MainISP is static, WANPort is static IP A.B.C.252 mask 255.255.255.0 and gateway A.B.C.1

This is my MainISP route

and WanPort