Spaces:
Running
Running
Local checker v2 file name
Browse filesFiles changed (3)
- index.html+6-6
- local/keyguard-local.ps1+42-12
- local/keyguard-local.py+71-13
297 unmodified lines298299300301302303304305306307308309297 unmodified lines<div class="card checker addrguide" id="guide" style="margin-top:18px"><h2 data-i18n="lc_lh"></h2><p>1. <span data-i18n="lc_l1"></span></p><div class="row"><a class="secbtn dl" href="local/keyguard-local.ps1" download="keyguard-local.ps1" data-i18n="lc_lw"></a><a class="sl" href="https://huggingface.co/spaces/FINAL-Bench/KeyGuard/blob/main/local/keyguard-local.ps1" target="_blank" rel="noopener" data-i18n="lc_src"></a></div><div class="gl"><span data-i18n="lc_run"></span> Β· PowerShell</div><textarea id="runwin" class="cmd" readonly rows="2">powershell -ExecutionPolicy Bypass -File "$HOME\Downloads\keyguard-local.ps1"</textarea><button class="secbtn cp" data-for="runwin" data-i18n="gd_copy"></button><div class="gl hs">SHA-256 59a32327a9691de1c947f8c232cad003cb78d86d7e686b598639c575bbdaf9bc</div><div class="row"><a class="secbtn dl" href="local/keyguard-local.py" download="keyguard-local.py" data-i18n="lc_lp"></a><a class="sl" href="https://huggingface.co/spaces/FINAL-Bench/KeyGuard/blob/main/local/keyguard-local.py" target="_blank" rel="noopener" data-i18n="lc_src"></a></div><div class="gl"><span data-i18n="lc_run"></span> Β· Terminal</div><textarea id="runnix" class="cmd" readonly rows="2">python3 ~/Downloads/keyguard-local.py</textarea><button class="secbtn cp" data-for="runnix" data-i18n="gd_copy"></button><div class="gl hs">SHA-256 8d0d0f40702b230eb2cefda16bcde56419814869f3e3500751b9d92fccde1da0</div><p>2. <span data-i18n="lc_l2"></span></p><button class="secbtn" id="gogo" data-i18n="gd_go"></button><details style="margin-top:16px"><summary data-i18n="lc_one"></summary>297 unmodified lines298299300301302303304305306307308309297 unmodified lines<div class="card checker addrguide" id="guide" style="margin-top:18px"><h2 data-i18n="lc_lh"></h2><p>1. <span data-i18n="lc_l1"></span></p><div class="row"><a class="secbtn dl" href="local/keyguard-local.ps1" download="keyguard-local-v2.ps1" data-i18n="lc_lw"></a><a class="sl" href="https://huggingface.co/spaces/FINAL-Bench/KeyGuard/blob/main/local/keyguard-local.ps1" target="_blank" rel="noopener" data-i18n="lc_src"></a></div><div class="gl"><span data-i18n="lc_run"></span> Β· PowerShell</div><textarea id="runwin" class="cmd" readonly rows="2">powershell -ExecutionPolicy Bypass -File "$HOME\Downloads\keyguard-local-v2.ps1"</textarea><button class="secbtn cp" data-for="runwin" data-i18n="gd_copy"></button><div class="gl hs">SHA-256 5efac92df5f2ecfd887a495e4475e44060c5bad229d0d8bc8b8d08092be1e8a0</div><div class="row"><a class="secbtn dl" href="local/keyguard-local.py" download="keyguard-local-v2.py" data-i18n="lc_lp"></a><a class="sl" href="https://huggingface.co/spaces/FINAL-Bench/KeyGuard/blob/main/local/keyguard-local.py" target="_blank" rel="noopener" data-i18n="lc_src"></a></div><div class="gl"><span data-i18n="lc_run"></span> Β· Terminal</div><textarea id="runnix" class="cmd" readonly rows="2">python3 ~/Downloads/keyguard-local-v2.py</textarea><button class="secbtn cp" data-for="runnix" data-i18n="gd_copy"></button><div class="gl hs">SHA-256 1d79cea414535dea8c8ba7e020e020c9e3bb5407d842d885c1d6746c3b349152</div><p>2. <span data-i18n="lc_l2"></span></p><button class="secbtn" id="gogo" data-i18n="gd_go"></button><details style="margin-top:16px"><summary data-i18n="lc_one"></summary>
12345678991 unmodified lines1011021031041051061071081091101111121131141157 unmodified lines12312412512612712818 unmodified lines147148149150151152153ο»Ώ# KeyGuard Local for Windows (PowerShell 5.1 or 7): check the RSA PUBLIC keys of devices in your own private network and print the verdict.## powershell -ExecutionPolicy Bypass -File .\keyguard-local.ps1# powershell -ExecutionPolicy Bypass -File .\keyguard-local.ps1 -Hosts 192.168.0.1,192.168.0.20## What it does: TCP connect, one TLS handshake per open port (and ssh-keyscan on port 22 when available).# What it never does: no login attempts, no private keys, no internet traffic, no upload. The verdict is computed here and the key file stays on this computer.# The same file can also be opened in the Self-check tab of https://huggingface.co/spaces/FINAL-Bench/KeyGuard (checked inside your browser).# Use it only on networks and devices you own or are authorized to test. MIT License, VIDRAFT.91 unmodified linesreturn "-----BEGIN CERTIFICATE-----`n" + $b.TrimEnd() + "`n-----END CERTIFICATE-----"} catch { return $null } finally { $c.Close() }}function Get-SshRsa([string]$ip) {$x = Get-Command ssh-keyscan -ErrorAction SilentlyContinueif (-not $x) { return $null }try {$ErrorActionPreference = 'Continue'$o = & $x.Source -t rsa -T 4 $ip 2>$null$m = [regex]::Match(($o -join "`n"), 'ssh-rsa [A-Za-z0-9+/=]+')if ($m.Success) { return $m.Value }} catch { }return $null}7 unmodified lines}if ($Ports.Count -gt 5 -or $list.Count -gt 256 -or $list.Count -eq 0) { Write-Host 'At most 5 ports and 256 addresses.'; exit 1 }if (@($list | Where-Object { -not (Test-PrivateIp $_) }).Count) { Write-Host 'Only private addresses are allowed (10.x, 172.16-31.x, 192.168.x).'; exit 1 }Write-Host ("Target: {0} to {1} ({2} addresses), ports {3}" -f $list[0], $list[-1], $list.Count, ($Ports -join ','))if (-not $Yes) {Write-Host 'Use this only on a network you own or are authorized to test.'18 unmodified lines$lines = @('# KeyGuard Local: public keys only'); $keys = @(); $rows = @()foreach ($t in $open) {$lab = '{0}:{1}' -f $t.ip, $t.port$k = if ($t.port -eq 22) { Get-SshRsa $t.ip } else { Get-CertPem $t.ip $t.port }$v = $nullif ($k) { $lines += "# $lab"; $lines += $k; $v = Get-RsaKey $k }if ($v) { $keys += [pscustomobject]@{ lab = $lab; n = $v.n; e = $v.e; share = @() } }12345678991 unmodified lines1011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431447 unmodified lines15215315415515615715818 unmodified lines177178179180181182183ο»Ώ# KeyGuard Local for Windows (PowerShell 5.1 or 7): check the RSA PUBLIC keys of devices in your own private network and print the verdict.## powershell -ExecutionPolicy Bypass -File .\keyguard-local-v2.ps1# powershell -ExecutionPolicy Bypass -File .\keyguard-local-v2.ps1 -Hosts 192.168.0.1,192.168.0.20## What it does: TCP connect, a TLS handshake per open port (on port 22 the SSH key exchange, up to the host key).# What it never does: no login attempts, no private keys, no internet traffic, no upload. The verdict is computed here and the key file stays on this computer.# The same file can also be opened in the Self-check tab of https://huggingface.co/spaces/FINAL-Bench/KeyGuard (checked inside your browser).# Use it only on networks and devices you own or are authorized to test. MIT License, VIDRAFT.91 unmodified linesreturn "-----BEGIN CERTIFICATE-----`n" + $b.TrimEnd() + "`n-----END CERTIFICATE-----"} catch { return $null } finally { $c.Close() }}$Group14 = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF'$Group1 = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'$Kex = [ordered]@{ 'diffie-hellman-group14-sha256' = $Group14; 'diffie-hellman-group14-sha1' = $Group14; 'diffie-hellman-group1-sha1' = $Group1 }function Get-Rand([int]$n) { $b = New-Object byte[] $n; $r = [Security.Cryptography.RandomNumberGenerator]::Create(); $r.GetBytes($b); $r.Dispose(); return , $b }function ConvertTo-U32([int]$n) { return , [byte[]]@((($n -shr 24) -band 255), (($n -shr 16) -band 255), (($n -shr 8) -band 255), ($n -band 255)) }function ConvertFrom-U32([byte[]]$b, [int]$i) { return ([int]$b[$i] -shl 24) + ([int]$b[$i + 1] -shl 16) + ([int]$b[$i + 2] -shl 8) + $b[$i + 3] }function Read-Exact($st, [int]$n) { $b = New-Object byte[] $n; $k = 0; while ($k -lt $n) { $r = $st.Read($b, $k, $n - $k); if ($r -le 0) { throw 'closed' }; $k += $r }; return , $b }function Read-SshPacket($st) { $n = ConvertFrom-U32 (Read-Exact $st 4) 0; if ($n -lt 2 -or $n -gt 40000) { throw 'bad packet' }; $b = Read-Exact $st $n; return , (Get-Sub $b 1 ($n - 1 - $b[0])) }function Send-SshPacket($st, [byte[]]$body) {$pad = 8 - (($body.Length + 5) % 8); if ($pad -lt 4) { $pad += 8 }$m = [byte[]]((ConvertTo-U32 ($body.Length + $pad + 1)) + [byte]$pad + $body + (Get-Rand $pad)); $st.Write($m, 0, $m.Length); $st.Flush()}function Get-SshRsa([string]$ip, [int]$port) {# RSA host key of an SSH server. Runs the key exchange up to the host key and disconnects: no login step.$c = New-Object Net.Sockets.TcpClienttry {if (-not $c.ConnectAsync($ip, $port).Wait(3000)) { return $null }$c.ReceiveTimeout = 5000; $c.SendTimeout = 5000; $st = $c.GetStream(); $line = ''for ($q = 0; $q -lt 20; $q++) { $line = ''; while (-not $line.EndsWith("`n") -and $line.Length -lt 512) { $line += [char](Read-Exact $st 1)[0] }; if ($line.StartsWith('SSH-')) { break } }if (-not $line.StartsWith('SSH-')) { return $null }$v = [Text.Encoding]::ASCII.GetBytes("SSH-2.0-KeyGuardLocal`r`n"); $st.Write($v, 0, $v.Length)$enc = 'aes128-ctr,aes256-ctr,aes128-cbc,3des-cbc'; $mac = 'hmac-sha2-256,hmac-sha2-512,hmac-sha1'$body = [byte[]](@([byte]20) + (Get-Rand 16))foreach ($x in (($Kex.Keys) -join ','), 'rsa-sha2-512,rsa-sha2-256,ssh-rsa', $enc, $enc, $mac, $mac, 'none', 'none', '', '') { $a = [Text.Encoding]::ASCII.GetBytes($x); $body = [byte[]]($body + (ConvertTo-U32 $a.Length) + $a) }Send-SshPacket $st ([byte[]]($body + [byte[]](0, 0, 0, 0, 0)))$b = Read-SshPacket $st; while ($b[0] -ne 20) { $b = Read-SshPacket $st }$theirs = [Text.Encoding]::ASCII.GetString($b, 21, (ConvertFrom-U32 $b 17)).Split(',')$name = $Kex.Keys | Where-Object { $theirs -contains $_ } | Select-Object -First 1if (-not $name) { return $null }$p = $Big::Parse('0' + $Kex[$name], [Globalization.NumberStyles]::HexNumber)$e = $Big::ModPow((New-Object System.Numerics.BigInteger 2), (ConvertTo-Big (Get-Rand 32)), $p)$raw = $e.ToByteArray(); [Array]::Reverse($raw)Send-SshPacket $st ([byte[]](@([byte]30) + (ConvertTo-U32 $raw.Length) + $raw))for ($q = 0; $q -lt 6; $q++) {$b = Read-SshPacket $stif ($b[0] -eq 31) { $k = Get-Sub $b 5 (ConvertFrom-U32 $b 1); if ([Text.Encoding]::ASCII.GetString($k, 4, 7) -eq 'ssh-rsa') { return 'ssh-rsa ' + [Convert]::ToBase64String($k) }; return $null }}} catch { return $null } finally { $c.Close() }return $null}7 unmodified lines}if ($Ports.Count -gt 5 -or $list.Count -gt 256 -or $list.Count -eq 0) { Write-Host 'At most 5 ports and 256 addresses.'; exit 1 }if (@($list | Where-Object { -not (Test-PrivateIp $_) }).Count) { Write-Host 'Only private addresses are allowed (10.x, 172.16-31.x, 192.168.x).'; exit 1 }Write-Host 'KeyGuard Local v2'Write-Host ("Target: {0} to {1} ({2} addresses), ports {3}" -f $list[0], $list[-1], $list.Count, ($Ports -join ','))if (-not $Yes) {Write-Host 'Use this only on a network you own or are authorized to test.'18 unmodified lines$lines = @('# KeyGuard Local: public keys only'); $keys = @(); $rows = @()foreach ($t in $open) {$lab = '{0}:{1}' -f $t.ip, $t.port$k = if ($t.port -eq 22) { Get-SshRsa $t.ip $t.port } else { Get-CertPem $t.ip $t.port }$v = $nullif ($k) { $lines += "# $lab"; $lines += $k; $v = Get-RsaKey $k }if ($v) { $keys += [pscustomobject]@{ lab = $lab; n = $v.n; e = $v.e; share = @() } }
1 unmodified line23456789101112131415161746 unmodified lines64656667686970717273747576777879131 unmodified lines2112122132142152161 unmodified line# -*- coding: utf-8 -*-"""KeyGuard Local: check the RSA PUBLIC keys of devices in your own private network and print the verdict.python3 keyguard-local.py # scan the /24 of this computer (asks first)python3 keyguard-local.py --hosts 192.168.0.1,192.168.0.20python3 keyguard-local.py --ports 443,8443,22 --out keyguard_keys.txtWhat it does: TCP connect, one TLS handshake per open port (and ssh-keyscan on port 22 when available).What it never does: no login attempts, no private keys, no internet traffic, no upload. The verdict is computed here and the key file stays on this computer.The same file can also be opened in the Self-check tab of https://huggingface.co/spaces/FINAL-Bench/KeyGuard (checked inside your browser).Use it only on networks and devices you own or are authorized to test. Standard library only. MIT License, VIDRAFT."""import argparse, base64, ipaddress, locale, math, os, re, shutil, socket, ssl, subprocess, sysfrom concurrent.futures import ThreadPoolExecutorNETS = [ipaddress.ip_network(n) for n in ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "127.0.0.0/8")]46 unmodified linesreturn Nonedef ssh_rsa(ip, port):exe = shutil.which("ssh-keyscan")if not exe:return Nonetry:out = subprocess.run([exe, "-t", "rsa", "-T", "4", "-p", str(port), ip], capture_output=True, text=True, timeout=12).stdoutexcept (OSError, subprocess.SubprocessError):return Nonem = re.search(r"ssh-rsa ([A-Za-z0-9+/=]+)", out)return m.group(0) if m else NoneKO = (os.environ.get("LANG") or (locale.getlocale()[0] or "")).lower().startswith(("ko", "korean"))131 unmodified linessys.exit("At most 5 ports and 256 addresses.")if not all(h.version == 4 and private(h) for h in hosts):sys.exit("Only private addresses are allowed (10.x, 172.16-31.x, 192.168.x).")print("Target: %s%s (%d addresses), ports %s" % (hosts[0], " to %s" % hosts[-1] if len(hosts) > 1 else "", len(hosts), ports))if not a.yes:print("Use this only on a network you own or are authorized to test.\nλ³ΈμΈ μμ μ΄κ±°λ μ κ² κΆνμ΄ μλ λ€νΈμν¬μμλ§ μ¬μ©νμμμ€.")1 unmodified line23456789101112131415161746 unmodified lines646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136131 unmodified lines2682692702712722732741 unmodified line# -*- coding: utf-8 -*-"""KeyGuard Local: check the RSA PUBLIC keys of devices in your own private network and print the verdict.python3 keyguard-local-v2.py # scan the /24 of this computer (asks first)python3 keyguard-local-v2.py --hosts 192.168.0.1,192.168.0.20python3 keyguard-local-v2.py --ports 443,8443,22 --out keyguard_keys.txtWhat it does: TCP connect, a TLS handshake per open port (on port 22 the SSH key exchange, up to the host key).What it never does: no login attempts, no private keys, no internet traffic, no upload. The verdict is computed here and the key file stays on this computer.The same file can also be opened in the Self-check tab of https://huggingface.co/spaces/FINAL-Bench/KeyGuard (checked inside your browser).Use it only on networks and devices you own or are authorized to test. Standard library only. MIT License, VIDRAFT."""import argparse, base64, ipaddress, locale, math, os, socket, ssl, sysfrom concurrent.futures import ThreadPoolExecutorNETS = [ipaddress.ip_network(n) for n in ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "127.0.0.0/8")]46 unmodified linesreturn NoneGROUP14 = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF"GROUP1 = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF"KEX = {"diffie-hellman-group14-sha256": GROUP14, "diffie-hellman-group14-sha1": GROUP14, "diffie-hellman-group1-sha1": GROUP1}def ssh_rsa(ip, port):"""RSA host key of an SSH server. Runs the key exchange up to the host key and disconnects: no login step."""def st(b):return len(b).to_bytes(4, "big") + bdef send(body):pad = 8 - (len(body) + 5) % 8pad += 8 if pad < 4 else 0s.sendall((len(body) + pad + 1).to_bytes(4, "big") + bytes([pad]) + body + os.urandom(pad))def need(n):b = b""while len(b) < n:c = s.recv(n - len(b))if not c:raise OSError("closed")b += creturn bdef packet():n = int.from_bytes(need(4), "big")if not 2 <= n <= 40000:raise OSError("bad packet")b = need(n)return b[1:n - b[0]]try:with socket.create_connection((ip, port), 4) as s:s.settimeout(5)for _ in range(20):line = b""while not line.endswith(b"\n") and len(line) < 512:line += need(1)if line.startswith(b"SSH-"):breakelse:return Nones.sendall(b"SSH-2.0-KeyGuardLocal\r\n")hk = b"rsa-sha2-512,rsa-sha2-256,ssh-rsa"enc = b"aes128-ctr,aes256-ctr,aes128-cbc,3des-cbc"mac = b"hmac-sha2-256,hmac-sha2-512,hmac-sha1"send(b"\x14" + os.urandom(16) + b"".join(st(x) for x in (",".join(KEX).encode(), hk, enc, enc, mac, mac, b"none", b"none", b"", b"")) + b"\x00" * 5)b = packet()while b[:1] != b"\x14":b = packet()n = int.from_bytes(b[17:21], "big")theirs = b[21:21 + n].decode("ascii", "replace").split(",")kex = next((k for k in KEX if k in theirs), None)if not kex:return Nonee = pow(2, int.from_bytes(os.urandom(32), "big") | 1 << 255, int(KEX[kex], 16))raw = e.to_bytes(e.bit_length() // 8 + 1, "big")send(b"\x1e" + st(raw))for _ in range(6):b = packet()if b[:1] == b"\x1f":n = int.from_bytes(b[1:5], "big")key = b[5:5 + n]return "ssh-rsa " + base64.b64encode(key).decode() if key[4:11] == b"ssh-rsa" else Noneexcept (OSError, ValueError, IndexError):passreturn NoneKO = (os.environ.get("LANG") or (locale.getlocale()[0] or "")).lower().startswith(("ko", "korean"))131 unmodified linessys.exit("At most 5 ports and 256 addresses.")if not all(h.version == 4 and private(h) for h in hosts):sys.exit("Only private addresses are allowed (10.x, 172.16-31.x, 192.168.x).")print("KeyGuard Local v2")print("Target: %s%s (%d addresses), ports %s" % (hosts[0], " to %s" % hosts[-1] if len(hosts) > 1 else "", len(hosts), ports))if not a.yes:print("Use this only on a network you own or are authorized to test.\nλ³ΈμΈ μμ μ΄κ±°λ μ κ² κΆνμ΄ μλ λ€νΈμν¬μμλ§ μ¬μ©νμμμ€.")
index.html+6-6
local/keyguard-local.ps1+42-12
local/keyguard-local.py+71-13