linux telnet 协议,利用MAC-Telnet协议进行纯二层网络通信(telnet/ssh)

Mac-Telnet协议通过二层mac进行通信,不依赖于IP地址。通过抓包,可以发现,服务端与客户端通信中,使用的是二层的广播(目标地址:ff:ff:ff:ff:ff:ff)进行通信,即只要在同一个二层广播域内,两台服务器可以在没有IP地址或者IP网段不相同,不能进行IP通信的情况下,仅通过从网卡发出二层mac报文,即可进行通信,如进行telnet或ssh登录另一台服务器。这在某些场合下,或许非常有用。

6469168a7c9c36d66ea59b42c0b9c54d.png

haakonnessjoen的源码是最基础的,aouyar对其进行了改进和增强,比如可以支持tcp遂道,可以转发ssh流,推荐使用aouyar的源码。

编译源码

# 准备编译环境

yum -y install wget automake gettext gettext-devel gcc make git

开始编译源码

# 下载源码

git clone https://github.com/cnznet/MAC-Telnet.git  #我将源码保存到自己的仓库了

#  编译

cd MAC-Telnet

make all

make install

install -d /usr/share/man/man1/

install docs/*.1 /usr/share/man/man1/

install -d /usr/bin

install mndp /usr/bin/

install macping /usr/bin/

install mactelnet /usr/bin/

install -d /usr/sbin

install -o root mactelnetd /usr/sbin/

install -d /etc

install -m 600 -o root config/mactelnetd.users /etc/

可以看到该程序包含nmdp、macping、mactelnet和mactelnetd四相可执行文件,另外还有一个配置文件/etc/mactelnetd.user

基本使用

mactelnetd 的使用

服务端,有两种工作模式,标准模式和TCP遂道模式

标准模式提供 telnet 服务,需要读取 /etc/mactelnetd.users 文件,该文件内以明文形式存储用户名和密码

TCP遂道模式支持以ssh协议提供服务,不需要 /etc/mactelnetd.users 文件

mactelnetd启动后,会以MNDP协议广播服务端信息,mndp工具就是接受该广播,从而获取到服务端信息的

# 标准模式

mactelnetd

## 启动守护进程,会读取/etc/mactelnetd.users中的帐号信息作为telnet的登录验证

## mactelnetd会开放5678和20561的UDP监听

# 遂道模式

mactelnetd -S

mactelnetd -S -P 22

## 启动守护进程,默认遂道至TCP 22端口,此时客户端需要以 -S 参数进行连接

## mactelnetd会开放5678和20561的UDP监听,当有ssh连接时,mactelnetd会通过127.0.0.1以tcp方式连接到ssh服务的监听端口

## mactelnet客户端会开放1962和60558的UDP监听,在建立shh连接时,会以tcp方式连接到127.0.0.1:2222端口

-n 不使用广播

mactelnet 的使用

mactelnet是客户端程序

# 服务发现,显示所有服务端

mactelnet -l

mactelnet -lB

# 以telnet方式连接到服务端

## 需要在 /etc/mactelnetd.users中添加帐号,帐号名需要系统中存在的用户,密码和系统同名帐号密码没有关系

mactelnet 0:c:29:aa:5d:73

mactelnet swarmkit1

## 会监听UDP 1928 端口

# 以ssh方式连接到服务器

## 不需要/etc/mactelnetd.users文件,使用ssh的帐号系统

mactelnet 0:c:29:aa:5d:73 -S

mactelnet 0:c:29:aa:5d:73 -S -u mcd    #指定以mcd用户登录,默认为root

## 使用ssh参数

mactelnet -S -u root 0:c:29:aa:5d:73 -- -L8080:127.0.0.1:80 -L443:127.0.0.1:8443

注意方向:与常见的是相反的

mactelnetd         ->    mactelnet

127.0.0.1:80        ->    127.0.0.1:8080

127.0.0.1:8443    ->    127.0.0.1:443

示例:

服务器(0:c:29:aa:5d:73)上安装有httpd服务,监听端口为80,并在该服务器上运行 mactelnetd -S

客户机使用mactelnet连接到服务器上,并将服务器上80商品业务映射到客户机 8080 端口:

mactelnet -S -u root 0:c:29:aa:5d:73 -- -L0.0.0.0:8080:127.0.0.1:80

mactelnet -S -u root 0:c:29:aa:5d:73 -- -L0.0.0.0:8080:127.0.0.1:80 -f -N

此时,访问客户机8080端口,即可访问到服务器上的httpd站点

可用ssh参数:

-C 允许数据压缩

-f 建立成功后在后台运行

-N 不执行远程指令

-g 允许远程主机连接主机的转发端口

macping 的使用

类似于ping命令

-f 没有发送间隔;-s 包大小byte,18-1490之间;-c 数量,0表示无限

macping 00:0c:29:aa:5d:73

0:c:29:aa:5d:73 56 byte, ping time 0.57 ms

0:c:29:aa:5d:73 56 byte, ping time 0.57 ms

0:c:29:aa:5d:73 56 byte, ping time 0.53 ms

0:c:29:aa:5d:73 56 byte, ping time 0.47 ms

0:c:29:aa:5d:73 56 byte, ping time 0.55 ms

5 packets transmitted, 5 packets received, 0% packet loss

round-trip min/avg/max = 0.47/0.54/0.57 ms

nmdp 工具的使用

nmdp工具用于服务发现,可发现当前二层网络中所有的基于mac-telnet协议的服务端

可显示mac地址和设备信息(如linux主机名、内核版本、在线时间等)

mndp

Searching for MikroTik routers... Abort with CTRL+C.

MAC-Address Identity (platform version hardware) uptime

0:c:29:aa:5d:73 swarmkit1 (Linux 3.10.0-514.el7.x86_64 x86_64) MAC-Telnet up 0 days 1 hours MAC-Telnet  # 这里的时间是开机时间

命令参数

mactelnetd:

Vim

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

mactelnetd-h

MAC-TelnetDaemon0.4.0

Usage:./mactelnetd[-v][-h][-n][-f][-S][-P][-U]

Parameters:

-fRunprocessinforeground.前台运行,默认后台运行,守护进程模式

-nDonotusebroadcastpackets.Justatadlessinsecure.不使用广播包,更安全

-S/-FForwardingofTCPconnectionsthroughMAC-Telnetprotocol,转发TCP连接

insteadofusingthestandardMAC-Telnetremoteterminal.

-PLocalTCPportusedforforwardingconnectionstoSSHServer.转发TCP的端口,通常是SSH的端口号,默认22

(Ifnotspecified,port22bydefault.)

-UDropprivilegesbyswitchingtouser,whenthecommandis以指定的用户运行,常用于限制命令以root权限运行

runasaprivilegeduserinconjunctionwiththe-noption.

StandardMAC-Telnetisnotcompatiblewiththisoption.

-vPrintversionandexit.

-hPrinthelpandexit.

mactelnet:

Vim

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

mactelnet-h

MAC-Telnet0.4.0

Usage:./mactelnet[-v][-h][-q][-n][-l][-B][-S][-P][-t][-u][-p][-c][-U]

Parameters:

MACMAC-AddressoftheRouterOS/mactelnetddevice.UseMNDPto

discoverit.

identityTheidentity/nameofyourdestinationdevice.UsesMNDP即主机名,通过mndp工具可获取到

protocoltofindit.

-lList/Searchforroutersnearby(MNDP).Youmayuse-ttosettimeout.该功能等价于执行mndp命令

-BBatchmode.Usecomputerreadableoutput(CSV),forusewith-l.配合-l使用,调整输出格式

-nDonotusebroadcastpackets.Lessinsecurebutrequires不使用广播包,更安全的方式但需要root权限

rootprivileges.

-tAmountofsecondstowaitforaresponseoneachinterface.超时时间

-uSpecifyusernameoncommandline.用户名

-pSpecifypasswordoncommandline.密码

-UDropprivilegestothisuser.Usedinconjunctionwith-n以指定用户权限执行程序

forsecurity.

-SUseMAC-SSHinsteadofMAC-Telnet.(Implies-F)启用MAC-SSH方式

ForwardSSHconnectionthroughMAC-TelnetandlaunchSSHclient.

-FForwardconnectionthroughofMAC-Telnetwithoutlaunchingthe使用MAC-Telnet方式

SSHClient.

-PLocalTCPportforforwardingSSHconnection.本地端口,默认2222

(Ifnotspecified,port2222bydefault.)

-cPathforsshclientexecutable.(Default:/usr/bin/ssh)指定ssh客户端程序

-qQuietmode.安静模式

-vPrintversionandexit.

-hThishelp.

Allargumentsafter'--'willbepassedtothesshclientcommand.--后接ssh参数

macping:

Vim

1

2

3

4

5

6

7

8

9

10

macping-h

MAC-Ping0.4.0

Usage:./macping[-h][-f][-c][-s]

Parameters:

MACMAC-AddressoftheRouterOS/mactelnetddevice.

-fFastmode,donotwaitbeforesendingnextpingrequest.快速模式

-sSpecifysizeofpingpacket.包大小,18-1490byte

-cNumberofpacketstosend.(0=unlimited)

-hThishelp.

mndp:

mndp没有参数,可使用 mactelnet -l 命令替代

喜欢 (5)or分享 (0)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值