Community discussions

MikroTik App
 
Kaldek
Member Candidate
Member Candidate
Topic Author
Posts: 111
Joined: Sat Jul 11, 2015 2:40 pm

SFTP upload via scripting only supports HMAC-MD5 and HMAC-SHA1

Wed Apr 26, 2023 7:17 am

I have a working SFTP upload script for my RouterOS devices which uploads backups to an SFTP server. However, I had to stuff about on my SFTP server because the /tool fetch command using SFTP only supports HMAC-MD5 and HMAC-SHA1.

I've raised a support ticket for this (in March) and just had my first reply (4 weeks later!), and the response was to "enable strong crypto" under /ip/ssh but that's for the SSH *server*, not the client.
Please can Mikrotik support place this in the long queue of things that need to be fixed. Many SFTP servers won't support these legacy HMAC algorithms without forcing them to downgrade their security.

For anyone who cares, here's the backup script. 90% of this was written by ChatGPT4.
# Variables
:local sftpServer "<Server IP>"
:local sftpUser "<SFTP user>"
:local sftpPass "<SFTP user password>"

# Set subdirectory on SFTP server
:local sftpDirectory "/network"

#Define what port the SFTP server is listening on
:local sftpPort 22

# Define binary backup and RSC export file names
:local backupFileName ("config_backup_" . [/system identity get name] . "_" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6])
:local exportFileName ("config_export_" . [/system identity get name] . "_" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6])

# Generate binary backup
/system backup save name=$backupFileName

# Generate export
/export file=$exportFileName

# Wait for backup files to be created
:delay 10s

# SFTP URL format
:local sftpUrl ("sftp://" . $sftpServer . ":" . $sftpPort . $sftpDirectory . "/")

# Upload binary backup to SFTP server
/tool fetch url=($sftpUrl . $backupFileName . ".backup") src-path=($backupFileName . ".backup") user=$sftpUser password=$sftpPass upload=yes

# Upload export to SFTP server
/tool fetch url=($sftpUrl . $exportFileName . ".rsc") src-path=($exportFileName . ".rsc") user=$sftpUser password=$sftpPass upload=yes

# Remove local binary backup file
/file remove ($backupFileName)

# Remove local backup file
/file remove ($exportFileName . ".rsc")
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: SFTP upload via scripting only supports HMAC-MD5 and HMAC-SHA1

Wed Apr 26, 2023 9:27 am

The setting is for both I think, client and server.

My server is running latest OpenSSH and I think I did not have to downgrade security. Will have to check for details...

Who is online

Users browsing this forum: Bing [Bot] and 24 guests