mikrotik

package
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

`msg.go` contains the logic for building, reading, accessing, and serializing RouterOS M2 messages.

`webfig.go` implements encryption negotiation and authentication against the web interface (webfig) of RouterOS v6.45+.

`winbox.go` contains the logic for sending unencrypted M2 messages to the RouterOS Winbox port (8291)

Index

Constants

View Source
const (
	VarSysTo         uint32 = 0x00ff0001
	VarFrom          uint32 = 0x00ff0002
	VarReplyExpected uint32 = 0x00ff0005
	VarRequestID     uint32 = 0x00ff0006
	VarCommand       uint32 = 0x00ff0007
	VarErrorCode     uint32 = 0x00ff0008
	VarErrorString   uint32 = 0x00ff0009
	VarSessionID     uint32 = 0x00fe0001
)

Variables

This section is empty.

Functions

func FileUpload

func FileUpload(webfigURL string, filename string, contents string, session *WebfigSession) bool

Upload a file via webfig. The expected url is: http[s]://<address>:<port>/jsproxy The file will be written to /rw/disk and be viewable from the Webfig disk menu.

func Login

func Login(webfigURL string, username string, password string, session *WebfigSession) bool

Given a username and password, this function will authenticate with the remote router.

func NegotiateEncryption

func NegotiateEncryption(webfigURL string, session *WebfigSession) bool

Negotiates encryption with the remote Webfig described by `webfigURL`. Note that `webfigURL` is generally created like so:

webfigURL := protocol.GenerateURL(conf.Rhost, conf.Rport, conf.SSL, "/jsproxy")

But we didn't want to introduce a config dependency here.

func ParseM2Message

func ParseM2Message(data []byte, msg *M2Message) bool

this switch is cursed. it needs to be broke into manageable functions.

func ReceiveM2

func ReceiveM2(conn net.Conn, msg *M2Message) bool

func SendM2

func SendM2(conn net.Conn, msg *M2Message) bool

Types

type M2Message

type M2Message struct {
	Bools    map[uint32]bool
	U32s     map[uint32]uint32
	Strings  map[uint32][]byte
	Raw      map[uint32][]byte
	ArrayU32 map[uint32][]uint32
	ArrayM2  map[uint32][]*M2Message
}

func NewM2Message

func NewM2Message() *M2Message

func SendEncrypted

func SendEncrypted(webfigURL string, msg *M2Message, session *WebfigSession) (*M2Message, bool)

Provided an M2Message this function will apply the various paddings/headers, encrypt it, and send it to the remote target described by `webfigURL`. The function returns the router's M2Message response.

func (M2Message) AddBool

func (msg M2Message) AddBool(varname uint32, data bool)

func (M2Message) AddRaw

func (msg M2Message) AddRaw(varname uint32, data []byte)

func (M2Message) AddString

func (msg M2Message) AddString(varname uint32, data []byte)

func (M2Message) AddU32

func (msg M2Message) AddU32(varname uint32, data uint32)

func (M2Message) AddU32Array

func (msg M2Message) AddU32Array(varname uint32, data []uint32)

func (M2Message) GetSessionID

func (msg M2Message) GetSessionID() uint32

func (M2Message) Serialize

func (msg M2Message) Serialize() []byte

func (M2Message) SetCommand

func (msg M2Message) SetCommand(command uint32)

func (M2Message) SetReplyExpected

func (msg M2Message) SetReplyExpected(expected bool)

func (M2Message) SetRequestID

func (msg M2Message) SetRequestID(id uint32)

func (M2Message) SetSessionID

func (msg M2Message) SetSessionID(id uint32)

func (M2Message) SetTo

func (msg M2Message) SetTo(to uint32, handler uint32)

type WebfigSession

type WebfigSession struct {
	ID  uint32
	Seq int
	Rx  *rc4.Cipher
	Tx  *rc4.Cipher
}

WebfigSession tracks the crypto for a given "session" which is associated with an ID. A sequence number must also be tracked.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL