Skip to content

Instantly share code, notes, and snippets.

@jabb3rd
Created May 24, 2019 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jabb3rd/0821ca0cce527325f5b74c47f9003bd2 to your computer and use it in GitHub Desktop.
Save jabb3rd/0821ca0cce527325f5b74c47f9003bd2 to your computer and use it in GitHub Desktop.
RouterOS sermgr interaction via winbox Message protocol
#!/usr/bin/env python3
# https://github.com/jabberd/winbox
from winbox.common import *
from winbox.session import *
from winbox.service import *
import argparse
from getpass import getpass
def parse_args():
parser = argparse.ArgumentParser(description = 'description')
parser.add_argument('-H', '--host', help = 'host name', required = True)
parser.add_argument('-u', '--user', help = 'user name', required = False)
parser.add_argument('-p', '--password', action = 'store', nargs = '?', help = 'password')
args = vars(parser.parse_args())
return args
port = 8291
user = 'admin'
password = ''
if __name__ == "__main__":
args = parse_args()
#print(args)
if args['user']:
user = args['user']
if args['password']:
password = args['password']
host_port = args['host'].split(':')
host = host_port[0]
if len(host_port) == 2:
port = int(host_port[1])
print('[*] Establishing a winbox session with %s:%s' % (host, port))
winbox = mtWinboxSession(host, port)
if winbox.login_cleartext(user.encode(), password.encode()):
print('[+] Logged into %s:%s' % (host, port))
else:
print('[-] Login failed')
winbox.close()
exit(1)
print('[*] Getting services info...')
services = mtServices(winbox)
services.get_all()
api_id = services.get_id(b'api')
api_data = services.get_data(api_id)
api_port = services.get_value(api_data, 2, U32)
api_disabled = services.get_value(api_data, STD_DISABLED, BOOL) == True
api_disabled_desc = {True: 'disabled', False: 'enabled'}
print('api port = %s, the service is %s' % (api_port, api_disabled_desc[api_disabled]))
# services.set_disabled(api_id, False)
winbox.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment