业内同行盆友来稿:对libc.so下毒手引发的惨痛血案,围观大型翻车现场...

编程入门 行业动态 更新时间:2024-10-10 23:18:38

业内同行盆友来稿:对libc.so下毒手引发的惨痛血案,围观大型<a href=https://www.elefans.com/category/jswz/34/1734294.html style=翻车现场..."/>

业内同行盆友来稿:对libc.so下毒手引发的惨痛血案,围观大型翻车现场...

写在开篇

为了在线上安装环境依赖,给glibc库升级,由于线上环境libc.so版本低,不支持安装,所以手贱把动态库中的libc.so.6给移走了,直接导致Linux系统崩溃,系统瘫痪,所有用户均被强制退出。
意识到缺少对libc.so的认识,以为跟普通的lib包类似,直接把新版的so软连过去就可以满足安装和升级,现在哦豁… 软链不软链已经不重要了,反正腿是软趴趴的。

1、什么是libc.so

libc.so.6 是很基础的库(glibc),是软连接到在Linux系统中基本的命令,有很多可执行文件都会依赖这个共享库。当不小心把这个库改名字或者移走了,都会导致不同程度的异常,可以借助LD_PRELOAD变量和"ldconfig"命令来恢复这个共享库。前提是终端没有断开的情况下操作。
libc.so.6是一个类似于WINDOWS下的一个快捷指向型的文件,而 linux有两种库,分别为:glibc、libc

  • 说明
  1. libc 是Linux下的ANSI C 函数库;
  2. glibc 是Linux下的GUN C 函数库:

2、操作流程

  • 作系统版本是:Red Hat Enterprise Linux Server release 6.8
1、问题出现

因为笔者这里是直接在生产环境上操作,当时是做软连接没成功,报错:文件已存在,软连接失败。于是我们就想着把它给移走。还没来得及做新软链就直接导致报错。

  • 基本上非系统命令都有这一条 libc.so.6 => /lib64/libc.so.6 ,因此libc.so.6至关重要,绝对不能删,不能改名,不能移走,能不能覆盖就不知道了,想作死的可以试试
[root@IDC-Redhat 6.8]# ln -s /home/david/libc-2.17.so /lib64/libc.so.6
ln: creating symbolic link `/lib64/libc.so.6': File exists
[root@IDC-Redhat 6.8]# mv /lib64/libc.so.6 .
who: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
awk: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
date: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
[root@IDC-Redhat 6.8]# 

当时就吓尿了,生产环境被我玩坏了,怎么破。后来查原因才知道很多命令都依赖glibc,我把它的软链接移走了系统找不到此库,那肯定玩完。

  • 注意:出现这样的情况只要不关机重启,就不会影响业务运行,不够一定要注意磁盘的使用情况。
  • 终端输入用户名后回车ENTER,直接提示以下报错,无法登录。
2、尝试单点登入,会出现卡界面情况。如图:

单用户模式已经救不回来了,本来就是一个无知的少年,现在更是雪上加霜。

3、解决问题

当时执行命令误操作之后,只要不断开远程连接还有挽回的余地。但远程异常断开连接之后很多人就没有辙了。只能尝试急救模式Rescue mode

  1. 如果当时远程连接会话保持,可以尝试使用以下命令:
[root@IDC-Redhat 6.8 ~]# mv /lib64/libc.so.6 .
who: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
awk: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
date: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
[root@IDC-Redhat 6.8 ~]# LD_PRELOAD=/lib64/libc-2.12.so ln -s /lib64/libc-2.12.so /lib64/libc.so.6
[root@IDC-Redhat 6.8 ~]# ll
total 120492
-rw-r--r--. 1 root root 123361280 Apr 14 23:54 all.tar
-rw-------. 1 root root      1098 Apr 14 23:21 anaconda-ks.cfg
-rw-r--r--. 1 root root      8835 Apr 14 23:21 install.log
-rw-r--r--. 1 root root      3384 Apr 14 23:21 install.log.syslog
lrwxrwxrwx. 1 root root        12 Apr 14 23:20 libc.so.6 -> libc-2.12.so
[root@IDC-Redhat 6.8 ~]# mv
mv: missing file operand
Try `mv --help' for more information.
[root@IDC-Redhat 6.8 ~]# 
  • 说明:LD_PRELOAD允许你定义在程序运行前优先加载的动态链接库,因此在使用ln前就加载了lib库,而不是等到使用ln时加载,这样就能临时使用命令了
  1. 也可以使用ldconfid命令来恢复
[root@IDC-Redhat 6.8 ~]# mv /lib64/libc.so.6 .
who: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
awk: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
date: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
[root@IDC-Redhat 6.8 ~]#ldconfid
[root@IDC-Redhat 6.8 ~]# ll
total 120492
-rw-r--r--. 1 root root 123361280 Apr 14 23:54 all.tar
-rw-------. 1 root root      1098 Apr 14 23:21 anaconda-ks.cfg
-rw-r--r--. 1 root root      8835 Apr 14 23:21 install.log
-rw-r--r--. 1 root root      3384 Apr 14 23:21 install.log.syslog
lrwxrwxrwx. 1 root root        12 Apr 14 23:20 libc.so.6 -> libc-2.12.so
4、如果远程连接已经退出,只能使用急救模式尝试修复。首先准备好系统安装盘,使用安装盘启动系统。
  1. 选择第三个选项:Rescue installed system


2. 选择语言和键盘(默认配置):


3. 稍等一会儿会出现要不要设置网络,一般来说网络没问题就不用设置了,我这里选择No:

  1. rescue模式选项:
  • Continue, 救援模式程序会自动查找系统中已有的文件系统,并把他们挂载到/mnt/sysimage目录下。
  • Read-Only,则会以只读的方式挂载已有的文件系统。
  • Skip,则需要自己手动挂载。
  • Advanced ,高级选项。

  1. 原系统挂载路径/mnt/sysimage,如果想获得原系统root环境,执行行命令:chroot /mnt/sysimage 即可。


  1. 直接选择shell start shell 进入shell 命令行

  1. 因为执行过这个命令 “mv /lib64/libc.so.6 .” ,导致执行chroot /mnt/sysimge会报错:

  1. 退出shell& reboot 重启主机就OK啦!
    本文转载于:

更多推荐

业内同行盆友来稿:对libc.so下毒手引发的惨痛血案,围观大型翻车现场...

本文发布于:2024-02-05 10:54:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1745107.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:翻车   来稿   惨痛   血案   业内

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!