国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 系統(tǒng)教程 Linux SFTP端口轉(zhuǎn)發(fā):啟用抑制功能

SFTP端口轉(zhuǎn)發(fā):啟用抑制功能

Mar 17, 2025 am 09:43 AM

SFTP Port Forwarding: Enabling Suppressed Functionality

引言

SSH協(xié)議支持三大類遠(yuǎn)程服務(wù)器活動:a) 命令執(zhí)行(包括登錄shell),b) 網(wǎng)絡(luò)轉(zhuǎn)發(fā)和操作,以及c) 文件傳輸。

OpenSSH維護(hù)者已確定sftp和scp對端口轉(zhuǎn)發(fā)(通過-L和-R選項(xiàng))沒有合法用途。在使用這些實(shí)用程序進(jìn)行文件傳輸期間,一個(gè)明確禁用這些功能的標(biāo)誌會被無條件地傳遞給子SSH可執(zhí)行文件。

某些用戶可能確實(shí)需要這些功能。一個(gè)明顯的子集是滲透測試人員,他們的任務(wù)是驗(yàn)證此功能是否在公共SFTP服務(wù)器上被明確禁用。

以下是兩種啟用這些被抑制功能的技術(shù),方法是修改sftp二進(jìn)製文件本身的字符串,或通過能夠輕鬆編輯命令行的shell進(jìn)行重定向。根據(jù)平臺的功能,可能需要任一技術(shù)才能實(shí)現(xiàn)此目標(biāo)。

抑制細(xì)節(jié)

首先,重要的是找到感興趣的運(yùn)行進(jìn)程。下面的shell函數(shù)將顯示與shell模式匹配的PID(請注意,這不是正則表達(dá)式)。這在Debian dash(和大多數(shù)其他常用shell)下運(yùn)行,並依賴於BSD的ps選項(xiàng):

 <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>

啟動一個(gè)傳統(tǒng)的SFTP會話,以檢查與其相關(guān)的進(jìn)程:

 <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>

我們假設(shè)上面的本地UNIX用戶在遠(yuǎn)程SFTP服務(wù)器上擁有相同用戶名帳戶。

會話運(yùn)行後,對用戶名進(jìn)行本地進(jìn)程搜索將顯示由SFTP生成的子SSH進(jìn)程:

 <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 yes參數(shù)將抑制任何轉(zhuǎn)發(fā)嘗試,而無需採取任何措施來破壞它。

-L和-R端口轉(zhuǎn)發(fā)標(biāo)誌並非作為SFTP命令行的有效選項(xiàng)存在,但我們可以使用-S選項(xiàng)明確觸發(fā)它們以指定自定義SSH處理程序,在本例中為郵件服務(wù)器:

 <code>$ cat portssh #!/bin/sh exec ssh -L2525:smtp.victimandum.com:25 "$@"</code>

如果轉(zhuǎn)發(fā)抑制沒有到位,則此SFTP調(diào)用足以建立轉(zhuǎn)發(fā)連接:

 <code>$ sftp -S ./portssh -oClearAllForwardings\ no aturing@sftp.victimandum.com aturing@sftp.victimandum.com's password: Connected to sftp.victimandum.com. sftp></code>

現(xiàn)在可以在子SSH進(jìn)程中看到轉(zhuǎn)發(fā)嘗試:

 <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>

但是,由於顯式覆蓋,嘗試通過本地轉(zhuǎn)發(fā)端口聯(lián)繫遠(yuǎn)程郵件服務(wù)器是不成功的:

 <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>

這些靜態(tài)字符串在編譯後的二進(jìn)製文件中也可見:

 <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>

更改編譯後的字符串

對於那些希望禁用默認(rèn)的ClearAllForwardings yes配置的人來說,一個(gè)選項(xiàng)是使用sed直接編輯SFTP二進(jìn)製文件中的字符串(假設(shè)平臺的sed是二進(jìn)制安全的):

 <code>$ sed 's/AllForwardings yes/AllForwardings no /' sftp.noclearforward</code>

這種直接修改比編譯新的二進(jìn)製文件要容易得多。

我們可以確認(rèn)字符串已成功修改:

 <code>$ strings ./sftp.noclearforward | grep [-]o[CFP] -oForwardX11 no -oPermitLocalCommand no -oClearAllForwardings no -oForwardAgent no -oPort %d</code>

雖然修改後的SFTP的內(nèi)容和校驗(yàn)和將不同,但任何存在的Linux BuildID sha1都將保持不變(但在使用編輯後的SFTP時(shí),請不要提交支持工單):

 <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>

可以調(diào)用修改後的SFTP二進(jìn)製文件來啟用端口轉(zhuǎn)發(fā):

 <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>

現(xiàn)在可以在子進(jìn)程中看到修改後的設(shè)置:

 <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>

該功能在遠(yuǎn)程服務(wù)器上已啟用並可運(yùn)行,並且可以在單獨(dú)的shell中驗(yàn)證連接:

 <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>

當(dāng)服務(wù)器上禁用轉(zhuǎn)發(fā)功能時(shí),客戶端將在連接嘗試時(shí)收到指示此狀態(tài)的通知:

 <code>channel 3: open failed: administratively prohibited: open failed</code>

分配不受信任帳戶的SFTP管理員應(yīng)該可能驗(yàn)證服務(wù)器配置是否明確禁用了轉(zhuǎn)發(fā)和命令執(zhí)行。

超越POSIX Shell

雖然dash和POSIX標(biāo)準(zhǔn)提供set --作為重置命令行參數(shù)的方法,但bash和ksh93中提供了更高級的功能:

 <code>$ cat ynargs #!/bin/bash echo "${@//yes/no}"</code>

快速測試確認(rèn)成功編輯:

 <code>$ ./ynargs -oForwardX11 no -oPermitLocalCommand yes -oClearAllForwardings yes -oForwardAgent no -oForwardX11 no -oPermitLocalCommand no -oClearAllForwardings no -oForwardAgent no</code>

請注意,上面的${@//.../...}不是有效的POSIX,並且在dash或任何從pdksh派生的shell(mksh,oksh)中都不能運(yùn)行。許多平臺沒有捆綁具有此功能的shell(例如Android和OpenBSD,儘管有添加它們的方法);對於受限平臺,二進(jìn)制編輯技術(shù)可能更直接,而不是安裝替代shell。

要利用具有功能強(qiáng)大的shell的此功能,我們創(chuàng)建一個(gè)目錄,然後在其中創(chuàng)建一個(gè)清除問題設(shè)置的SSH包裝器:

 <code>$ cat ~/switcharoo/ssh #!/bin/bash exec /usr/bin/ssh "${@//yes/no}"</code>

然後在$PATH中設(shè)置系統(tǒng)SSH之前的目錄:

 <code>$ export PATH=~/switcharoo:$PATH $ which ssh ~/switcharoo/ssh</code>

然後,我們在這種修改後的環(huán)境下調(diào)用系統(tǒng)SFTP:

 <code>$ /usr/bin/sftp -S ./portssh aturing@sftp.victimandum.com aturing@sftp.victimandum.com's password: Connected to sftp.victimandum.com. sftp></code>

我們觀察到shell重置了問題參數(shù):

 <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>

再次確認(rèn)了到轉(zhuǎn)發(fā)端口的本地連接:

 <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>

作為最終演示,可以使用以下腳本進(jìn)行完整的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>

我們可以使用該腳本將自身郵件發(fā)送到目標(biāo)SMTP服務(wù)器可以訪問的遠(yuǎn)程收件人:

 <code>$ ./awkmail jatanasoff@victimandum.com aturning@localhost awkmail Queued mail for delivery</code>

在高度受控的環(huán)境中,這些功能的存在並非最佳。

服務(wù)器限制

可以理解的是,SFTP管理員不希望允許其用戶在服務(wù)器的幫助下進(jìn)行任意TCP連接,這可能會使敏感網(wǎng)絡(luò)面臨風(fēng)險(xiǎn)。限制此活動是一種謹(jǐn)慎的安全設(shè)置。

常見的限制性配置是將不受信任的SFTP用戶添加到組中,然後在sshd_config中約束此組的活動:

 <code>Match Group sftponly ChrootDirectory %h ForceCommand internal-sftp AllowTcpForwarding no</code>

此推薦配置通常足以阻止所有轉(zhuǎn)發(fā)嘗試。

建議添加DisableForwarding yes:

 <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>

這留給管理員練習(xí)。

結(jié)論

過於嚴(yán)格的SFTP客戶端設(shè)置可能會導(dǎo)致某種程度的服務(wù)器管理盲目性。 SFTP客戶端限制很容易通過多種方法規(guī)避。

對於SFTP服務(wù)器管理員來說,了解哪些地方受到限制以及在哪裡限制非常重要,並且不要依賴客戶端來保護(hù)服務(wù)器免受任意TCP控制??蛻舳耸苡脩艨刂疲绻渲缅e(cuò)誤,則很難實(shí)現(xiàn)對服務(wù)器的TCP命令。任何測試都應(yīng)該在用戶ssh_config中沒有廣泛設(shè)置轉(zhuǎn)發(fā)的情況下進(jìn)行,注意文檔中的警告。

雖然這種功能可能有可以想像的合法用途,但濫用行為將很少見。

這些問題並非新鮮事物,因?yàn)檎军c(diǎn)exec的變體幾十年來一直存在於明文FTP中。 SFTP並不是明文文件傳輸?shù)暮唵翁娲?,它本身也具有許多易於利用的功能。

希望管理員能夠使用這些方法驗(yàn)證其服務(wù)器的安全性,以免措手不及。

以上是SFTP端口轉(zhuǎn)發(fā):啟用抑制功能的詳細(xì)內(nèi)容。更多資訊請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

5 Linux的最佳開源數(shù)學(xué)方程式編輯器 5 Linux的最佳開源數(shù)學(xué)方程式編輯器 Jun 18, 2025 am 09:28 AM

您是否正在尋找編寫數(shù)學(xué)方程式的好軟件?如果是這樣,本文提供了前5個(gè)方程式編輯器,您可以輕鬆地在自己喜歡的Linux發(fā)行版上安裝。

SCP Linux命令 - 在Linux中安全傳輸文件 SCP Linux命令 - 在Linux中安全傳輸文件 Jun 20, 2025 am 09:16 AM

Linux管理員應(yīng)熟悉命令行環(huán)境。由於通常不安裝Linux服務(wù)器中的GUI(圖形用戶界面)模式。 SSH可能是使Linux管理員能夠管理服務(wù)器的最受歡迎的協(xié)議

在RHEL,Rocky和Almalinux中安裝LXC(Linux容器) 在RHEL,Rocky和Almalinux中安裝LXC(Linux容器) Jul 05, 2025 am 09:25 AM

LXD被描述為下一代容器和虛擬機(jī)管理器,它為在容器內(nèi)部或虛擬機(jī)中運(yùn)行的Linux系統(tǒng)提供了沉浸式的。 它為有支持的Linux分佈數(shù)量提供圖像

gogo-在Linux中創(chuàng)建到目錄路徑的快捷方式 gogo-在Linux中創(chuàng)建到目錄路徑的快捷方式 Jun 19, 2025 am 10:41 AM

Gogo是在Linux Shell內(nèi)書籤目錄的非凡工具。它可以幫助您在Linux中為長而復(fù)雜的路徑創(chuàng)建快捷方式。這樣,您不再需要在Linux上鍵入或記住冗長的路徑。例如,如果有目錄

什麼是PPA,如何將其添加到Ubuntu? 什麼是PPA,如何將其添加到Ubuntu? Jun 18, 2025 am 12:21 AM

PPA是Ubuntu用戶擴(kuò)展軟件源的重要工具。 1.查找PPA時(shí)應(yīng)訪問Launchpad.net,確認(rèn)項(xiàng)目官網(wǎng)或文檔中的官方PPA,並閱讀描述與用戶評論確保其安全性和維護(hù)狀態(tài);2.添加PPA使用終端命令sudoadd-apt-repositoryppa:/,之後運(yùn)行sudoaptupdate更新包列表;3.管理PPA可通過grep命令查看已添加列表,使用--remove參數(shù)移除或手動刪除.list文件,避免因不兼容或停止更新引發(fā)問題;4.使用PPA應(yīng)權(quán)衡必要性,優(yōu)先選擇官方未提供或需新版軟件的情況

如何創(chuàng)建特定大小的文件以進(jìn)行測試? 如何創(chuàng)建特定大小的文件以進(jìn)行測試? Jun 17, 2025 am 09:23 AM

如何快速生成指定大小的測試文件?使用命令行工具或圖形化軟件均可實(shí)現(xiàn)。 Windows上可用fsutilfilecreatenew文件名大小生成指定字節(jié)的文件;macOS/Linux可用ddif=/dev/zeroof=文件bs=1Mcount=100生成真實(shí)數(shù)據(jù)文件,或用truncate-s100M文件快速創(chuàng)建稀疏文件。若不熟悉命令行,可選用FSUtilGUI、DummyFileGenerator等工具軟件。注意事項(xiàng)包括:注意文件系統(tǒng)限制(如FAT32文件大小上限)、避免覆蓋已有文件、部分程序可能

如何與Windows一起安裝Linux(雙啟動)? 如何與Windows一起安裝Linux(雙啟動)? Jun 18, 2025 am 12:19 AM

安裝Linux和Windows雙系統(tǒng)的關(guān)鍵是分區(qū)和啟動設(shè)置。 1.準(zhǔn)備工作包括備份數(shù)據(jù)並壓縮現(xiàn)有分區(qū)騰出空間;2.使用Ventoy或Rufus製作Linux啟動U盤,推薦Ubuntu;3.安裝時(shí)選擇“與其他系統(tǒng)並存”或手動分區(qū)(/至少20GB,/home剩餘空間,swap可選);4.勾選安裝第三方驅(qū)動以避免硬件問題;5.安裝後若未進(jìn)入Grub引導(dǎo)菜單,可用boot-repair修復(fù)引導(dǎo)或調(diào)整BIOS啟動順序。只要步驟清晰、操作得當(dāng),整個(gè)過程並不復(fù)雜。

NVM-在Linux中安裝和管理多個(gè)node.js版本 NVM-在Linux中安裝和管理多個(gè)node.js版本 Jun 19, 2025 am 09:09 AM

Node版本管理器(NVM)是一個(gè)簡單的BASH腳本,可幫助您在Linux系統(tǒng)上管理多個(gè)Node.js版本。它使您可以安裝各種node.js版本,查看可用的安裝版本,並檢查已經(jīng)安裝的版本。

See all articles