【OpenSSH】CentOS7.x上編譯rpm升級(jí)OpenSSH至 9.8p1胞谭,解決 CVE-2024-6387安全漏洞問題

OpenSSH漏洞預(yù)警:無需用戶交互,可提權(quán)至 root
https://mp.weixin.qq.com/s/c_gATfwcjyXVGj0g6xXIBg

OpenSSH遠(yuǎn)程代碼執(zhí)行漏洞分析及POC(CVE-2024-6387)
https://mp.weixin.qq.com/s/79P1zpb36D0ku-gwwXfPtQ

OenSSH官方只提供源碼包,我們考慮自己將源碼編譯為rpm包來升級(jí)環(huán)境的OpenSSH仇哆。
當(dāng)然編譯過程也盡量簡(jiǎn)單化靶衍,這里我們直接使用開源的腳本進(jìn)行編譯灾炭。
https://github.com/boypt/openssh-rpms

# yum -y install epel-release 
 
# yum -y install  git   zip  unzip
 
# yum -y groupinstall  "Development Tools"
 
# yum -y install  imake rpm-build pam-devel krb5-devel zlib-devel libXt-devel libX11-devel gtk2-devel

# git clone https://github.com/boypt/openssh-rpms.git
 
# cd openssh-rpms-main
 
# ls -l
-rwxr-xr-x. 1 root root 1959 9月   3 21:44 compile.sh
drwxr-xr-x. 2 root root  114 9月   3 21:40 downloads
drwxr-xr-x. 7 root root   72 8月  10 15:22 el5
drwxr-xr-x. 7 root root   72 8月  10 15:22 el6
drwxr-xr-x. 8 root root   89 9月   3 21:44 el7
-rwxr-xr-x. 1 root root 1304 9月   3 21:39 pullsrc.sh
-rw-r--r--. 1 root root 1440 8月  10 15:22 README.md
-rw-r--r--. 1 root root  255 8月  10 15:22 version.env
 
 將出現(xiàn) source  version.env 行改為  source ./version.env 
# grep "version.env"   *.sh
compile.sh:source ./version.env
pullsrc.sh:source ./version.env
 
將出現(xiàn) wget 的行加上 --no-check-certificate 參數(shù),避免因?yàn)樽C書問題導(dǎo)致源碼下載失敗颅眶。
#  grep  "wget"  pullsrc.sh
wget --no-check-certificate $OPENSSLMIR/$OPENSSLSRC
wget --no-check-certificate $OPENSSHMIR/$OPENSSHSRC
wget --no-check-certificate $ASKPASSMIR/$ASKPASSSRC
#  sh  pullsrc.sh

#  sh  compile.sh
 
 
Obsoletes: ssh-server
處理文件:openssh-debuginfo-9.8p1-1.el7.x86_64
Provides: openssh-debuginfo = 9.8p1-1.el7 openssh-debuginfo(x86-64) = 9.8p1-1.el7
Requires(rpmlib): rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1
檢查未打包文件:/usr/lib/rpm/check-files /root/openssh-rpms-main/el7/BUILDROOT/openssh-9.8p1-1.el7.x86_64
寫道:/root/openssh-rpms-main/el7/SRPMS/openssh-9.8p1-1.el7.src.rpm
寫道:/root/openssh-rpms-main/el7/RPMS/x86_64/openssh-9.8p1-1.el7.x86_64.rpm
寫道:/root/openssh-rpms-main/el7/RPMS/x86_64/openssh-clients-9.8p1-1.el7.x86_64.rpm
寫道:/root/openssh-rpms-main/el7/RPMS/x86_64/openssh-server-9.8p1-1.el7.x86_64.rpm
寫道:/root/openssh-rpms-main/el7/RPMS/x86_64/openssh-debuginfo-9.8p1-1.el7.x86_64.rpm
執(zhí)行(%clean): /bin/sh -e /var/tmp/rpm-tmp.GHFx0p
+ umask 022
+ cd /root/openssh-rpms-main/el7/BUILD
+ cd openssh-9.8p1
+ rm -rf /root/openssh-rpms-main/el7/BUILDROOT/openssh-9.8p1-1.el7.x86_64
+ exit 0
~/openssh-rpms-main
# ll /root/openssh-rpms-main/el7/RPMS/x86_64/
 
總用量 15408
-rw-r--r--. 1 root root 5150056 9月   3 21:44 openssh-9.8p1-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 5179640 9月   3 21:45 openssh-clients-9.8p1-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 3911916 9月   3 21:45 openssh-debuginfo-9.8p1-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 1527088 9月   3 21:45 openssh-server-9.8p1-1.el7.x86_64.rpm
#  yum -y localinstall  /root/openssh-rpms-main/el7/RPMS/x86_64/*.rpm
 
#  systemctl restart sshd
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.

 
# systemctl  status   sshd
 sshd.service - SYSV: OpenSSH server daemon
   Loaded: loaded (/etc/rc.d/init.d/sshd; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since 日 2023-09-03 21:47:05 CST; 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 85319 ExecStop=/etc/rc.d/init.d/sshd stop (code=exited, status=0/SUCCESS)
  Process: 85344 ExecStart=/etc/rc.d/init.d/sshd start (code=exited, status=1/FAILURE)
 Main PID: 1079 (code=exited, status=0/SUCCESS)
 
9月 03 21:47:05 localhost.localdomain sshd[85344]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
9月 03 21:47:05 localhost.localdomain sshd[85344]: Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open.
9月 03 21:47:05 localhost.localdomain sshd[85344]: It is required that your private key files are NOT accessible by others.
9月 03 21:47:05 localhost.localdomain sshd[85344]: This private key will be ignored.
9月 03 21:47:05 localhost.localdomain sshd[85344]: sshd: no hostkeys available -- exiting.
9月 03 21:47:05 localhost.localdomain sshd[85344]: [失敗]
9月 03 21:47:05 localhost.localdomain systemd[1]: sshd.service: control process exited, code=exited status=1
9月 03 21:47:05 localhost.localdomain systemd[1]: Failed to start SYSV: OpenSSH server daemon.
9月 03 21:47:05 localhost.localdomain systemd[1]: Unit sshd.service entered failed state.
9月 03 21:47:05 localhost.localdomain systemd[1]: sshd.service failed.
 
 
# chmod  400 /etc/ssh/*key
 
# systemctl  restart sshd
 
# systemctl  status   sshd
 
# systemctl  status   sshd
 sshd.service - SYSV: OpenSSH server daemon
   Loaded: loaded (/etc/rc.d/init.d/sshd; bad; vendor preset: enabled)
   Active: active (running) since 日 2023-09-03 21:47:46 CST; 6s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 85319 ExecStop=/etc/rc.d/init.d/sshd stop (code=exited, status=0/SUCCESS)
  Process: 85364 ExecStart=/etc/rc.d/init.d/sshd start (code=exited, status=0/SUCCESS)
 Main PID: 85372 (sshd)
    Tasks: 1
   Memory: 772.0K
   CGroup: /system.slice/sshd.service
           └─85372 sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups
 
9月 03 21:47:46 localhost.localdomain systemd[1]: Starting SYSV: OpenSSH server daemon...
9月 03 21:47:46 localhost.localdomain sshd[85364]: /sbin/restorecon:  lstat(/etc/ssh/ssh_host_dsa_key.pub) failed:  No such file or directory
9月 03 21:47:46 localhost.localdomain sshd[85364]: Starting sshd:[  確定  ]
9月 03 21:47:46 localhost.localdomain sshd[85372]: Server listening on 0.0.0.0 port 22.
9月 03 21:47:46 localhost.localdomain sshd[85372]: Server listening on :: port 22.
9月 03 21:47:46 localhost.localdomain systemd[1]: Can't open PID file /var/run/sshd.pid (yet?) after start: No such file or directory
9月 03 21:47:46 localhost.localdomain systemd[1]: Started SYSV: OpenSSH server daemon.

OpenSSH 從 7.0 后開始對(duì)于version 1.x 就不支持了蜈出,相應(yīng)的RSA1算法也不再支持了
編譯OpenSSH 源碼的時(shí)候也不會(huì)在/etc/ssh目錄下面生成ssh_host_key/ssh_host_key.pub
http://www.openssh.com/txt/release-6.9

將 /sbin/restorecon /etc/ssh/ssh_host_dsa_key.pub 行注釋掉

# sed -i '/ssh_host_dsa_key.pub/s/^/#/'  /etc/init.d/sshd
# systemctl daemon-reload
# systemctl  restart sshd

# systemctl  status   sshd
sshd.service - SYSV: OpenSSH server daemon
  Loaded: loaded (/etc/rc.d/init.d/sshd; bad; vendor preset: enabled)
  Active: active (running) since 日 2023-09-03 21:51:03 CST; 2s ago
    Docs: man:systemd-sysv-generator(8)
 Process: 85457 ExecStop=/etc/rc.d/init.d/sshd stop (code=exited, status=0/SUCCESS)
 Process: 85464 ExecStart=/etc/rc.d/init.d/sshd start (code=exited, status=0/SUCCESS)
Main PID: 85471 (sshd)
   Tasks: 1
  Memory: 788.0K
  CGroup: /system.slice/sshd.service
          └─85471 sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups

9月 03 21:51:03 localhost.localdomain systemd[1]: Starting SYSV: OpenSSH server daemon...
9月 03 21:51:03 localhost.localdomain sshd[85471]: Server listening on 0.0.0.0 port 22.
9月 03 21:51:03 localhost.localdomain sshd[85471]: Server listening on :: port 22.
9月 03 21:51:03 localhost.localdomain sshd[85464]: Starting sshd:[  確定  ]
9月 03 21:51:03 localhost.localdomain systemd[1]: Started SYSV: OpenSSH server daemon.
# ssh -V
OpenSSH_9.8p1, OpenSSL 1.1.1w  1 Aug 2023
 
# sshd  -V
OpenSSH_9.4, OpenSSL 1.1.1w  1 Aug 2023
 
# rpm -qa | grep openssh
openssh-9.8p1-1.el7.x86_64
openssh-clients-9.8p1-1.el7.x86_64
openssh-debuginfo-9.8p1-1.el7.x86_64
openssh-server-9.8p1-1.el7.x86_64
# mkdir  install_openssh-9.8p1
# cd  install_openssh-9.8p1
# cp  /root/openssh-rpms-main//el7/BUILD/openssh-9.8p1/contrib/ssh-copy-id   ./
# cp /root/openssh-rpms-main/el7/RPMS/x86_64/*   ./

cat install_openssh-9.8p1.sh


#!/bin/bash
 
if ! yum -y localinstall *.rpm ; then
  echo "OpenSSH rpm 安裝失敗涛酗!"
  exit 1
fi
 
chmod 400 /etc/ssh/ssh_host_*_key
 
cp ssh-copy-id  /usr/bin/
chmod  755  /usr/bin/ssh-copy-id

sed -i '/ssh_host_dsa_key.pub/s/^/#/' /etc/init.d/sshd
 
systemctl daemon-reload
 
systemctl restart sshd
systemctl enable  sshd
systemctl status sshd
 
rpm -qa | grep openssh
ssh  -V

參考

如何編譯打包OpenSSH 9.4并實(shí)現(xiàn)批量升級(jí)
https://mp.weixin.qq.com/s/XHyHJjwnO4P2XO5WUS4Ehw

CentOS7下快速升級(jí)至OpenSSH9.8p1安全版本
https://mp.weixin.qq.com/s/HokRwGqzK6uiSgCId3E0QA

OpenSSH重啟铡原,/sbin/restorecon:lstat(/etc/ssh/ssh_host_key.pub) failed報(bào)錯(cuò)
https://blog.51cto.com/kk876435928/1737597

sed 在行首或者行尾添加文本
https://blog.csdn.net/w2909526/article/details/102587577

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市商叹,隨后出現(xiàn)的幾起案子燕刻,更是在濱河造成了極大的恐慌,老刑警劉巖剖笙,帶你破解...
    沈念sama閱讀 221,635評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件卵洗,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡弥咪,警方通過查閱死者的電腦和手機(jī)过蹂,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,543評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來聚至,“玉大人酷勺,你說我怎么就攤上這事“夤” “怎么了脆诉?”我有些...
    開封第一講書人閱讀 168,083評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵甚亭,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我击胜,道長(zhǎng)亏狰,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,640評(píng)論 1 296
  • 正文 為了忘掉前任潜的,我火速辦了婚禮骚揍,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘啰挪。我一直安慰自己信不,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,640評(píng)論 6 397
  • 文/花漫 我一把揭開白布亡呵。 她就那樣靜靜地躺著抽活,像睡著了一般。 火紅的嫁衣襯著肌膚如雪锰什。 梳的紋絲不亂的頭發(fā)上下硕,一...
    開封第一講書人閱讀 52,262評(píng)論 1 308
  • 那天,我揣著相機(jī)與錄音汁胆,去河邊找鬼梭姓。 笑死,一個(gè)胖子當(dāng)著我的面吹牛嫩码,可吹牛的內(nèi)容都是我干的誉尖。 我是一名探鬼主播,決...
    沈念sama閱讀 40,833評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼铸题,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼铡恕!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起丢间,我...
    開封第一講書人閱讀 39,736評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤探熔,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后烘挫,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體诀艰,經(jīng)...
    沈念sama閱讀 46,280評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,369評(píng)論 3 340
  • 正文 我和宋清朗相戀三年饮六,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了其垄。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,503評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡喜滨,死狀恐怖捉捅,靈堂內(nèi)的尸體忽然破棺而出撤防,到底是詐尸還是另有隱情虽风,我是刑警寧澤棒口,帶...
    沈念sama閱讀 36,185評(píng)論 5 350
  • 正文 年R本政府宣布,位于F島的核電站辜膝,受9級(jí)特大地震影響无牵,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜厂抖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,870評(píng)論 3 333
  • 文/蒙蒙 一茎毁、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧忱辅,春花似錦七蜘、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,340評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至损搬,卻和暖如春碧库,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背巧勤。 一陣腳步聲響...
    開封第一講書人閱讀 33,460評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工嵌灰, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人颅悉。 一個(gè)月前我還...
    沈念sama閱讀 48,909評(píng)論 3 376
  • 正文 我出身青樓沽瞭,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親签舞。 傳聞我的和親對(duì)象是個(gè)殘疾皇子秕脓,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,512評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容