ssh root@localhost 错误;破解这个盒子

noo*_*ler 1 linux root ssh

我需要在 linux vm 上获得一个 root shell 以用于安全类。我在系统上有一个用户帐户,并且可以写入任何文件(即 /etc...),并希望通过以下方式提升我的权限:

ssh root@localhost
Run Code Online (Sandbox Code Playgroud)

我使用 ssh-keygen 制作 rsa 密钥并将它们添加到 /root/.ssh/authorized_keys,并修改 /etc/ssh/sshd_config 以允许 root 连接。但是,我无法以 root 身份连接到该框。这是输出:

Last login: Fri Jan 27 00:43:01 2012 from localhost
Connection to localhost closed.
Run Code Online (Sandbox Code Playgroud)

在我看来,身份验证成功,但是连接立即关闭。我不知道为什么这不起作用。

详细输出是:

OpenSSH_4.6p1 Debian-7, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/identity type -1
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.6p1 Debian-7
debug1: match: OpenSSH_4.6p1 Debian-7 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6p1 Debian-7
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /etc/ssh/ssh_known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,hostbased
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user/.ssh/identity
debug1: Offering public key: /home/user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending command: /bin/bash
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.0 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 255
Run Code Online (Sandbox Code Playgroud)

Gil*_*il' 7

SSH 登录分为三个主要步骤:

  1. SSH 对用户进行身份验证(通过检查所请求的用户是否拥有密码或私钥,或其他方法)。
  2. SSH 启动一个会话,该会话可以通过 PAM(因此可能会失败,具体取决于 PAM 配置)。
  3. SSH 启动一个shell。

ssh -v跟踪的这一部分:

debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending command: /bin/bash
Run Code Online (Sandbox Code Playgroud)

我们看到 SSH 级别的身份验证成功,并且 ssh 守护进程启动了一个 shell ( /bin/bash)。因此,它的某些内容/bin/bash或其配置会阻止登录。检查bash的初始化文件:~root/.bash_login~root/.bash_profile/etc/profile和其他文件它们可能包括。尝试使用非交互式登录:ssh root@localhost ls; 这仍然会通过 bash 但不会通过相同的初始化文件(bash 很奇怪,~/.bashrc当它的父级是rshd或时,它会读取非交互式登录sshd)。

如果初始化文件中有问题,您可以在正确的时间按Ctrl+来中断C(在建立 SSH 会话之后,这样 SSH 会将Ctrl+发送C到远程主机而不关闭连接,但在麻烦之前执行初始化文件中的指令)。在实践中,通常可以通过几次尝试手动实现正确的时间;它可能有助于装载机器。如果您不能手动制作,一个小expect程序应该可以帮助您实现。