Windows 反向SSH隧道监视器
我已经使用PuTTY设置了一个反向ssh隧道,允许我在不启用NAT端口转发的情况下将VNC导入家庭计算机。很好,没问题 我想将隧道设置为一个“持久性服务”,它将在启动时连接,在丢弃时重新连接。这是在Windows上 谷歌搜索发现了一些产品,但许多产品似乎已经被放弃,而且没有一个产品具有重大的“街头信誉”Windows 反向SSH隧道监视器,windows,ssh,monitoring,tunnel,Windows,Ssh,Monitoring,Tunnel,我已经使用PuTTY设置了一个反向ssh隧道,允许我在不启用NAT端口转发的情况下将VNC导入家庭计算机。很好,没问题 我想将隧道设置为一个“持久性服务”,它将在启动时连接,在丢弃时重新连接。这是在Windows上 谷歌搜索发现了一些产品,但许多产品似乎已经被放弃,而且没有一个产品具有重大的“街头信誉” 有没有人对这类产品或这些产品有经验?我不需要所有的细节,只需要可靠性。你考虑过使用plink并将其作为一项服务吗?有隧道、袜子等栏目。可能会帮助你找到合适的东西。你可以设置任何应
有没有人对这类产品或这些产品有经验?我不需要所有的细节,只需要可靠性。你考虑过使用plink并将其作为一项服务吗?有隧道、袜子等栏目。可能会帮助你找到合适的东西。你可以设置任何应用程序以windows启动,并在启动时自动连接隧道。我个人使用Easytunnel。。。只是选中了启动时连接所有隧道的选项,并将windows设置为启动时启动Easytunnel。它工作得很好,但您需要设置服务器的非活动超时,否则每隔10分钟左右就会断开连接
希望你能成功 使用PuTTY中的plink并在批处理文件中运行。当连接真的断开时,plink将退出,这意味着您可以在循环中运行plink 像这样:
:: This is a batch file. Save with file name: plink_forever.bat
:restart
plink saved_session_name
goto restart
最后用srvany包装它,让它在登录时启动
或者更简单:将.bat放在windows调度程序中,并设置为每次启动时运行一次
文档:我经常使用ssh隧道,但所有的管理人员都不方便我(UI屏幕太多,不太稳定)。我想有一个脚本,可以很容易地配置和维护,所以我想出了一个PowerShell脚本。张贴。所以规则也要求我发布解决方案,我很乐意这样做: 要开始使用它,您需要如下配置:
# LocalPort TargetHost TargetPort SshHost SshUsername SshKeyPath
18080 google.com 80 bastion.example.com User D:\secure\path\to\private_key.ppk
将其另存为config.csv。并使用powershell脚本保持其正常运行:
<#
.SYNOPSIS
Powershell script for keeping ssh tunnel up and running
.DESCRIPTION
This script uses configuration of tunnels located in config.csv. For more information visit http://tsherlock.tech/2019/03/13/simple-ssh-tunnel-auto-reconnect-using-putty-and-powershell/
.NOTES
Version: 1.0
Author: Anton Shkuratov
Creation Date: 2019-03-13
Purpose/Change: Initial script development
#>
$currentDir = $PSScriptRoot
if (-not $env:PATH.Contains($currentDir)) {
$env:PATH="$env:PATH;$currentDir"
}
# Check plink is accessible
try {
Start-Process plink.exe -WindowStyle Hidden
} catch {
Write-Host Error running plink.exe Please make sure its path is in PATH environment variable
EXIT 1
}
# Parse config
$config = [System.IO.File]::ReadAllLines("$currentDir\config.csv");
$bindings = New-Object System.Collections.ArrayList
$regex = New-Object System.Text.RegularExpressions.Regex("(\d)+\s([^ ]+)\s(\d+)\s([^ ]+)\s([^ ]+)\s([^ ]+)", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase);
$keyPasswords = @{}
$procs = @{}
foreach($line in $config) {
$match = $regex.Match($line)
if ($match.Success) {
$sshKey = $match.Groups[6];
$bindings.Add(@{
LocalPort = $match.Groups[1];
TargetHost = $match.Groups[2];
TargetPort = $match.Groups.Groups[3];
SshHost = $match.Groups[4];
SshUser = $match.Groups[5];
SshKey = $match.Groups[6];
});
if (-not $keyPasswords.ContainsKey($sshKey)) {
$pass = Read-Host "Please enter password for key (if set): $sshKey" -AsSecureString
$keyPasswords.Add($sshKey, $pass);
}
}
}
# Starting Processes
function EnsureRunning($procs, $keyPasswords, $binding) {
if ($procs.ContainsKey($binding) -and $procs[$binding].HasExited) {
$proc = $procs[$binding]
$sshKey = $binding.sshKey
$out = $proc.StandardError.ReadToEnd()
if ($out.Contains("Wrong passphrase")) {
Write-Host "Wrong pass phrase for $sshKey, please re-enter"
$pass = Read-Host "Please enter password for key: $sshKey" -AsSecureString
$keyPasswords[$sshKey] = $pass;
} else {
$exitCode = $proc.ExitCode
$tHost = $binding.sshHost
Write-Host "Connection to $tHost is lost, exit code: $exitCode"
}
}
if (-not $procs.ContainsKey($binding) -or $procs[$binding].HasExited) {
$sshUser = $binding.SshUser
$sshHost = $binding.SshHost
$sshKey = $binding.SshKey
$lPort = $binding.LocalPort
$tPort = $binding.TargetPort
$tHost = $binding.TargetHost
$sshKeyPass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($keyPasswords[$sshKey]))
$psi = New-Object System.Diagnostics.ProcessStartInfo;
$psi.FileName = "plink.exe";
$psi.UseShellExecute = $false;
$psi.CreateNoWindow = $true;
$psi.RedirectStandardInput = $true;
$psi.RedirectStandardError = $true;
$psi.Arguments = "-ssh $sshUser@$sshHost -i `"$sshKey`" -batch -pw $sshKeyPass -L $lPort`:$tHost`:$tPort"
$proc = [System.Diagnostics.Process]::Start($psi);
Start-Sleep 1
if (-not $proc.HasExited) {
Write-Host Connected to $sshUser@$sshHost
}
$procs[$binding] = $proc;
}
}
function EnsureAllRunning($procs, $keyPasswords, $bindings) {
while($true) {
foreach($binding in $bindings) {
EnsureRunning $procs $keyPasswords $binding
}
Start-Sleep 1
}
}
try {
# Waiting for exit command
Write-Host Working... Press Ctrl+C to stop execution...
EnsureAllRunning $procs $keyPasswords $bindings
} finally {
# Clean up
Write-Host Clean up
foreach($proc in $procs.Values) {
if ($proc -ne $null -and -not $proc.HasExited) {
$proc.Kill();
}
}
}
要使用windows启动自动启动,请使用windows计划程序。永久隧道是安全漏洞。 我已经设置了一个开放式服务,只要你在网上,它就会被安全地打开。它也有内置的超时,没有活动2分钟,否则10分钟。是通过https的,上面有一些XTEA加密。请访问mylinuz.com
这个问题基本相似:我同意Igal。一个好的、简短的、切中要害的教程可以在
powershell -File autossh.ps1