소개
SSH 프로토콜은 원격 서버 활동의 세 가지 주요 범주를 지원합니다. a) 명령 실행 (로그인 쉘 포함), b) 네트워크 전달 및 작동 및 c) 파일 전송.
OpenSSH 관리자는 SFTP 및 SCP가 포트 전달에 대한 법적 목적이 없다고 결정했습니다 (-L 및 -R 옵션을 통해). 이러한 유틸리티를 사용하여 파일 전송 중에 이러한 기능을 명시 적으로 비활성화하는 플래그는 아동 SSH 실행 파일에게 무조건 전달됩니다.
일부 사용자는 실제로 이러한 기능이 필요할 수 있습니다. 명백한 하위 집합은 공개 SFTP 서버 에서이 기능이 명시 적으로 비활성화되어 있는지 확인하는 작업을하는 침투 테스터입니다.
다음은 SFTP 바이너리 자체의 문자열을 수정하거나 명령 줄을 쉽게 편집 할 수있는 쉘을 통해 리디렉션하여 이러한 억제 된 기능을 가능하게하는 두 가지 기술입니다. 플랫폼의 기능에 따라이 목표를 달성하기 위해서는 두 기술이 필요할 수 있습니다.
세부 사항을 억제합니다
먼저, 실행 관심있는 프로세스를 찾는 것이 중요합니다. 아래 쉘 함수는 쉘 패턴과 일치하는 PID를 표시합니다 (이것은 정규 표현이 아님). 이것은 Debian Dash (및 대부분의 다른 공통 쉘) 아래에서 실행되며 BSD의 PS 옵션에 의존합니다.
<code>pps () { local a= b= c= IFS=$'\r'; ps ax | while read -ra do [ "$b" ] || c=1; for b; do case "$a" in *"$b"*) c=1;; esac; done; [ "$c" ] && printf '%s\n' "$a" && c=; done; }</code>
전통적인 SFTP 세션을 시작하여 관련 프로세스를 확인하십시오.
<code>$ id uid=1001(aturing) gid=1001(aturing) groups=1001(aturing)... $ sftp aturing@sftp.victimandum.com aturing@sftp.victimandum.com's password: Connected to sftp.victimandum.com. sftp></code>
위의 로컬 UNIX 사용자는 원격 SFTP 서버에서 동일한 사용자 이름 계정을 가지고 있다고 가정합니다.
세션이 실행되면 사용자 이름에 대한 로컬 프로세스 검색에 SFTP가 생성 한 자식 SSH 프로세스가 표시됩니다.
<code>$ pps aturing PID TTY STAT TIME COMMAND 9666 pts/0 S 0:00 sftp aturing@sftp.victimandum.com 9667 pts/0 S 0:00 /usr/bin/ssh -oForwardX11 no -oPermitLocalCommand no -oClearAllForwardings yes -oForwardAgent no -l aturing -s -- sftp.victimandum.com sftp</code>
위의 ClearAllForwardings 예 매개 변수는이를 깨기 위해 조치를 취하지 않고 전달 시도를 억제합니다.
-l 및 -r 포트 전달 플래그는 SFTP 명령 줄에 대한 유효한 옵션으로 존재하지 않지만 -S 옵션을 사용하여 명시 적으로 트리거하여 사용자 정의 SSH 처리기 (이 경우 메일 서버)를 지정할 수 있습니다.
<code>$ cat portssh #!/bin/sh exec ssh -L2525:smtp.victimandum.com:25 "$@"</code>
전달 억제가 설치되지 않으면이 SFTP 호출은 전달 연결을 설정하기에 충분합니다.
<code>$ sftp -S ./portssh -oClearAllForwardings\ no aturing@sftp.victimandum.com aturing@sftp.victimandum.com's password: Connected to sftp.victimandum.com. sftp></code>
이제 아동 SSH 과정에서 전달 시도를 볼 수 있습니다.
<code>$ pps aturing PID TTY STAT TIME COMMAND 9897 pts/0 S 0:00 sftp -S ./portssh -oClearAllForwardings no aturing@sftp.victimandum.com 9898 pts/0 S 0:00 ssh -L2525:smtp.victimandum.com:25 -oForwardX11 no -oPermitLocalCommand no -oClearAllForwardings yes -o ClearAllForwardings no -oForwardAgent no -l aturing -s -- sftp.victimandum.com sftp</code>
그러나 명시 적 재정의 로컬 전달 포트를 통해 원격 메일 서버에 연락하는 것은 실패합니다.
<code>$ nc localhost 2525 $</code>
이 무조건 억제는 소스 코드에서 볼 수 있습니다.
<code>$ sed -n /X11/,/Forwardings/p openssh-8.7p1/sftp.c addargs(&args, "-oForwardX11 no"); addargs(&args, "-oPermitLocalCommand no"); addargs(&args, "-oClearAllForwardings yes");</code>
이러한 정적 문자열은 컴파일 된 이진 파일에서도 볼 수 있습니다.
<code>$ strings /usr/bin/sftp | grep [-]o[CFP] -oForwardX11 no -oPermitLocalCommand no -oClearAllForwardings yes -oForwardAgent no -oPort %d</code>
마지막으로, 문서는이 억제가 의도적이며 합리적인 이유를 제공한다는 것을 분명히 나타냅니다.
<code>$ man ssh_config | sed -n /ClearAllForwardings/,/default/p ClearAllForwardings Specifies that all local, remote, and dynamic port forwardings specified in the configuration files or on the command line be cleared. This option is primarily useful when used from the ssh(1) command line to clear port forwardings set in configura‐ tion files, and is automatically set by scp(1) and sftp(1). The argument must be yes or no (the default).</code>
컴파일 된 문자열을 변경합니다
Default ClearAllForwardings Yes 구성을 비활성화하려는 사람들의 경우 SED를 사용하여 SFTP 바이너리의 문자열을 직접 편집하는 것입니다 (플랫폼의 SED가 이진-안전이라고 가정).
<code>$ sed 's/AllForwardings yes/AllForwardings no /' sftp.noclearforward</code>
이 직접 수정은 새 이진 파일을 컴파일하는 것보다 훨씬 쉽습니다.
문자열이 성공적으로 수정되었음을 확인할 수 있습니다.
<code>$ strings ./sftp.noclearforward | grep [-]o[CFP] -oForwardX11 no -oPermitLocalCommand no -oClearAllForwardings no -oForwardAgent no -oPort %d</code>
수정 된 SFTP의 내용과 체크섬은 다르지만 기존 Linux BuildId SHA1은 동일하게 유지됩니다 (그러나 편집 된 SFTP를 사용할 때는 지원 티켓을 제출하지 마십시오).
<code>$ file /usr/bin/sftp ./sftp.noclearforward /usr/bin/sftp: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=d7e77e24d5fac0fdc89e62a4c9c656091f2c4a33, for GNU/Linux 3.2.0, stripped ./sftp.noclearforward: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=d7e77e24d5fac0fdc89e62a4c9c656091f2c4a33, for GNU/Linux 3.2.0, stripped $ sha1sum /usr/bin/sftp ./sftp.noclearforward d8bdaf0b4642b9c324f9c2e0aeee2d9578fbe383 /usr/bin/sftp b12dda8ecfd7bd2847919b5531aea7c03364c123 ./sftp.noclearforward $ sha256sum /usr/bin/sftp ./sftp.noclearforward 986eecdfc654c9b3ff3fd0dce59690d47cf56be96a4b98a04a3682aef95d3f52 /usr/bin/sftp c8f99ce33fc129250c11dc6dbb8a01112e01124e470a92d0acefb955fd17d670 ./sftp.noclearforward</code>
수정 된 SFTP 바이너리를 호출하여 포트 전달을 활성화 할 수 있습니다.
<code>$ chmod 755 sftp.noclearforward $ ./sftp.noclearforward -S ./portssh aturing@sftp.victimandum.com aturing@sftp.victimandum.com's password: Connected to sftp.victimandum.com. sftp></code>
이제 아동 프로세스에서 수정 된 설정을 볼 수 있습니다.
<code>$ pps aturing PID TTY STAT TIME COMMAND 9991 pts/0 S 0:00 ./sftp.noclearforward -S ./portssh aturing@sftp.victimandum.com 9992 pts/0 S 0:00 ssh -L2525:smtp.victimandum.com:25 -oForwardX11 no -oPermitLocalCommand no -oClearAllForwardings no -oForwardAgent no -l aturing -s -- sftp.victimandum.com sftp</code>
이 기능은 원격 서버에서 활성화되어 실행되며 별도의 쉘에서 연결을 확인할 수 있습니다.
<code>$ nc localhost 2525 220 smtp.victimandum.com Microsoft ESMTP MAIL Service, Version: 1.2.3456.78901 ready at Sun, 1 Jan 2023 01:23:45 -0100 ^C</code>
서버에서 전달이 비활성화되면 클라이언트는 연결이 시도 될 때이 상태를 나타내는 알림을받습니다.
<code>channel 3: open failed: administratively prohibited: open failed</code>
신뢰할 수없는 계정을 할당 한 SFTP 관리자는 서버 구성이 명시 적으로 전달 및 명령 실행을 비활성화했는지 확인해야합니다.
Posix Shell 너머
Dash 및 Posix 표준은 명령 행 매개 변수를 재설정하는 방법으로 설정을 제공하지만 Bash 및 KSH93에서 더 고급 기능이 제공됩니다.
<code>$ cat ynargs #!/bin/bash echo "${@//yes/no}"</code>
빠른 테스트는 성공적인 편집을 확인합니다.
<code>$ ./ynargs -oForwardX11 no -oPermitLocalCommand yes -oClearAllForwardings yes -oForwardAgent no -oForwardX11 no -oPermitLocalCommand no -oClearAllForwardings no -oForwardAgent no</code>
위의 $ {@// .../...}는 유효한 posix가 아니며 PDKSH에서 파생 된 대시 또는 쉘 (mksh, oksh)에서 실행할 수 없습니다. 많은 플랫폼은이 기능으로 쉘을 번들로 만들지 않습니다 (예 : 제한된 플랫폼의 경우 이진 편집 기술은 대체 쉘을 설치하는 것보다 더 직접적 일 수 있습니다.
강력한 쉘로이 기능을 활용하려면 디렉토리를 작성한 다음 문제 설정을 지우기 위해 SSH 래퍼를 만듭니다.
<code>$ cat ~/switcharoo/ssh #!/bin/bash exec /usr/bin/ssh "${@//yes/no}"</code>
그런 다음 $ 경로에서 System SSH 전에 디렉토리를 설정하십시오.
<code>$ export PATH=~/switcharoo:$PATH $ which ssh ~/switcharoo/ssh</code>
그런 다음이 수정 된 환경에서 시스템 SFTP를 호출합니다.
<code>$ /usr/bin/sftp -S ./portssh aturing@sftp.victimandum.com aturing@sftp.victimandum.com's password: Connected to sftp.victimandum.com. sftp></code>
우리는 쉘이 문제 매개 변수를 재설정하는 것을 관찰했습니다.
<code>$ pps aturing PID TTY STAT TIME COMMAND 10058 pts/0 S 0:00 /usr/bin/sftp -S ./portssh aturing@sftp.victimandum.com 10059 pts/0 S 0:00 /usr/bin/ssh -L2525:smtp.victimandum.com:25 -oForwardX11 no -oPermitLocalCommand no -oClearAllForwardings no -oForwardAgent no -l aturing -s -- sftp.victimandum.com sftp</code>
로컬 연결을 전달 포트로 재확인했습니다.
<code>$ nc localhost 2525 220 smtp.victimandum.com Microsoft ESMTP MAIL Service, Version: 1.2.3456.78901 ready at Sun, 1 Jan 2023 01:23:45 -0100 ^C</code>
최종 데모로서 다음 스크립트를 사용하여 완전한 SMTP 교환을 수행 할 수 있습니다.
<code>$ cat awkmail #!/bin/gawk -f BEGIN { smtp="/inet/tcp/0/localhost/2525"; ORS="\r\n"; r=ARGV[1]; s=ARGV[2]; sbj=ARGV[3]; # /bin/awkmail to from subj 0) print |& smtp print "." |& smtp; smtp |& getline j; print j print "quit" |& smtp; smtp |& getline j; print j close(smtp) } # /inet/protocol/local-port/remote-host/remote-port</code>
이 스크립트를 사용하여 Target SMTP 서버가 액세스 할 수있는 원격 수신자에게 자신의 메일을 보낼 수 있습니다.
<code>$ ./awkmail jatanasoff@victimandum.com aturning@localhost awkmail Queued mail for delivery</code>
고도로 통제 된 환경에서 이러한 기능의 존재는 최적이 아닙니다.
서버 제한
SFTP 관리자는 사용자가 서버의 도움으로 임의의 TCP 연결을 만들기를 원하지 않으므로 민감한 네트워크를 위험에 빠뜨릴 수 있습니다. 이 활동을 제한하는 것은 신중한 보안 설정입니다.
일반적인 제한 구성은 신뢰할 수없는 SFTP 사용자를 그룹에 추가 한 다음 SSHD_CONFIG 에서이 그룹의 활동을 제한하는 것입니다.
<code>Match Group sftponly ChrootDirectory %h ForceCommand internal-sftp AllowTcpForwarding no</code>
이 권장 구성은 일반적으로 모든 전달 시도를 방지하기에 충분합니다.
예를 들어 비활성화하는 것이 좋습니다. 예 :
<code>$ man sshd_config | sed -n /DisableForwarding/,/configurations/p DisableForwarding Disables all forwarding features, including X11, ssh-agent(1), TCP and StreamLocal. This option overrides all other forwarding- related options and may simplify restricted configurations.</code>
이것은 연습을 위해 관리자에게 맡겨집니다.
결론적으로
너무 엄격한 SFTP 클라이언트 설정은 어느 정도의 서버 관리 실명으로 이어질 수 있습니다. SFTP 클라이언트 제한은 다양한 방법을 통해 쉽게 우회 할 수 있습니다.
SFTP 서버 관리자의 경우 제한 위치와 제한 위치를 아는 것이 중요하며 임의의 TCP 제어로부터 서버를 보호하기 위해 클라이언트에 의존하지 않습니다. 클라이언트는 사용자에 의해 제어되며 구성이 잘못된 경우 서버에 TCP 명령을 구현하기가 어렵습니다. 사용자 SSH_CONFIG에서 광범위한 전달없이 모든 테스트를 수행해야하며 문서의 경고에주의를 기울여야합니다.
이 기능은 상상할 수있는 법적 목적을 가질 수 있지만 남용은 드물게됩니다.
Site Exec의 변형이 수십 년 동안 일반 텍스트 FTP에 존재했기 때문에 이러한 문제는 새로운 것이 아닙니다. SFTP는 일반 텍스트 파일 전송에 대한 간단한 대안이 아니며 사용하기 쉬운 기능도 많이 있습니다.
바라건대 관리자는 이러한 방법을 사용하여 서버의 보안을 검증하여 경비를 잡지 못하게 할 수 있습니다.
위 내용은 SFTP 포트 전달 : 억제 기능을 활성화합니다의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!