Safely enter a network behind a Mikrotik device with SMS confirmation

Building on my last experiences documented here (read that one first, please) in this tutorial we will set up a safe backdoor access that can wake up the target machine, send an SMS to confirm the source IP address and expect an SMS back. The protocol can be anything, but in this case I will be using Remote desktop to log in.

Log in using winbox and go to Tools -> SMS.

01

The SMS Settings screen pops up. The minimal configuration is to check the Receive Enabled and set the proper Port. Everything else you can leave on the default settings for now:

02

Now let’s set up some firewall rules. Go to IP -> Firewall:

03

Go to the NAT tab (don’t mind the red rule, it’s normal) and click on the blue + button to add a new one:

04

The New Nat Rule screen will pop up:

05

Enter the following on the General tab:

Chain: dstnat

Protocol: 6 (tcp)

Dst. Port: 3389

In. Interface: ether1-gateway

06

On the Action tab:

Action: add src to address list

Address List: RDP250

Note: I mixed up the screenshots and it doesn’t show, but you REALLY need to enter RDP250 into the Address List field

Hit OK  to save it:

08

Click the blue + button once more to add another rule:

05

Fill the General tab as follows:

Chain: dstnat

Protocol: 6 (tcp)

Dst. Port: 3389

In. Interface: ether1-gateway

12

On the Advanced tab set it as below:

Src. Address List: RDPallow

Note: I know that it’s a different address list than the one we set earlier, it will all make sense soon

14

Finally on the Action tab do the following:

Action: dst-nat

To Addresses: 192.168.88.2 (use the private address you want to access from the internet)

To Ports: 3389

Hit OK:

15

This is how your 2 rules should look like:

16

Now to make it work, we need to create a schedule. Go to System -> Scheduler:

17

Add a new schedule by pressing the blue + button:

18

Give it a fancy Name, set the Interval to 30 seconds and input the folowing:


:foreach A in=[/ip firewall address-list find name=RDP250] do={
 if ([/ip firewall address-list get $A list]="RDP250") do={
 :global LastRDPAddress [/ip firewall address-list get $A address]
 /tool sms send usb1 "phone-number-comes-here" message="RDP session requested from: $LastRDPAddress. Allow it?"
 /ip firewall address-list remove $A
 }
}


19

The above script will query the address list and send you an SMS. To actually allow it in we need to create a script that we can call with our phone. Go to System -> Scripts:

20

The Script List panel shows up:

21

Add a new script by pressing (you guessed it) the blue + button:

22

Give it a Name (note: make it simple so you can type it out from your phone later) and enter the following into the Source textbox:


:global LastRDPAddress
/ip firewall address-list add list=RDP_allow address=$LastRDPAddress
/tool wol mac=mac-address-of-target-machine-comes-here interface=bridge-local
/tool sms send usb2 "phone-number-comes-here" message="WOL request sent. Please be patient. Note: $LastRDPAddress permanently added to access list."


23

After you hit OK it should saved:

24

If you trust your battery life you can limit the router to only accept messages from a single phone number. Go to Tools -> SMS and enter your phone number under Allowed Number. What I highly recommend is setting a Secret atleast that you must supply in each SMS you send to the router.

25

Now that it is set up, let’s run the script by sending an SMS to the routers number with the following message:

:cmd SECRET script allow

where SECRET is the secret we set at the above step, and allow is the script name we created earlier.

Leave a Reply

Your email address will not be published. Required fields are marked *