merlinthemagic / mtm-ssh
PHP 7 的 SSH 壳工具
dev-master
2023-04-07 17:32 UTC
Requires
- php: >=7.3.0
- merlinthemagic/mtm-encrypt: >=0.0.1
- merlinthemagic/mtm-network: >=0.0.1
- merlinthemagic/mtm-shells: >=0.0.1
- merlinthemagic/mtm-utilities: >=0.0.1
This package is auto-updated.
Last update: 2024-09-07 20:42:26 UTC
README
这是什么?
连接到其他主机并向 shell 发送命令。您还可以连接到一台设备,然后使用它来连接到另一台。例如,使用 ssh 连接到 Linux 服务器,使用该 shell 连接到 routerOS 设备。然后使用第二台设备连接到第三台设备(Linux 或 routeros),依此类推
您可以执行任何想要的命令。与底层 shell 完全兼容
安装
composer require merlinthemagic/mtm-ssh
使用密码在 Linux 服务器上获取远程 shell
$ctrlObj = \MTM\SSH\Factories::getShells()->passwordAuthentication("IpAddress", "username", "password");
使用密码在运行 mikrotik routeros 的设备上获取远程 shell
$username = \MTM\SSH\Factories::getShells()->getRouterOsTool()->getFormattedUsername("username");
$ctrlObj = \MTM\SSH\Factories::getShells()->passwordAuthentication("IpAddress", $username, "password");
使用公钥认证在 Linux 服务器上获取远程 shell
$key = "-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgk.....
....S8dBQ==
-----END PRIVATE KEY-----";
$ctrlObj = \MTM\SSH\Factories::getShells()->keyAuthentication("IpAddress", "username", $key);
使用公钥认证在运行 mikrotik routeros 的设备上获取远程 shell
$key = "-----BEGIN PRIVATE KEY-----
MIIEvAIBBDANBgk.....
....S8dBQ==
-----END PRIVATE KEY-----";
$username = \MTM\SSH\Factories::getShells()->getRouterOsTool()->getFormattedUsername("username");
$ctrlObj = \MTM\SSH\Factories::getShells()->keyAuthentication("IpAddress", $username, $key);
使用现有 shell 在 Linux 服务器上获取远程 shell
//no public key auth yet
$ctrlObj2 = \MTM\SSH\Factories::getShells()->passwordAuthentication("IpAddress", "username", "password", $ctrlObj);
//NOTE: Both existing shell ($ctrlObj) and built on shell ($ctrlObj2) will execute on the second host
使用现有 shell 在运行 mikrotik routeros 的设备上获取远程 shell
//no public key auth yet
$username = \MTM\SSH\Factories::getShells()->getRouterOsTool()->getFormattedUsername("username");
$ctrlObj2 = \MTM\SSH\Factories::getShells()->passwordAuthentication("IpAddress", $username, "password", $ctrlObj);
//NOTE: Both existing shell ($ctrlObj) and built on shell ($ctrlObj2) will execute on the second host
开始运行命令:linux
$data = $ctrlObj->getCmd("whoami")->exec()->get();
echo $data; //the name of the user you connected with
$ctrlObj->getCmd("cd /var")->exec()->get();
$data = $ctrlObj->getCmd("ls -sho --color=none")->exec()->get();
echo $data; //directory and file listing from /var
开始运行命令:routeros
注意:在设备上禁用所有 echo 记录,否则在运行命令时日志消息回显到 shell,可能会导致回退损坏
$data = $ctrlObj->getCmd("/system resource print")->exec()->get();
echo $data; //list of system resources
$data = $ctrlObj->getCmd("/interface print")->exec()->get();
echo $data; //list of interfaces