Linux 使用 VLC 多媒体的 正确姿势,解决 VLC is not supposed to be run as root. 的问题

本文介绍了如何在Linux系统中,尤其是Debian和RedHat系Linux上,解决VLC播放器不允许以root权限运行的问题。通过修改VLC二进制文件中的特定指令,使得root用户可以顺利启动VLC。这一过程涉及到使用`objdump`、`sed`等工具,以及对程序执行流程的分析。文章还分享了一位国外专家利用`gdb`调试工具找出问题并解决的方法,为读者提供了一个学习技术问题解决思路的例子。
摘要由CSDN通过智能技术生成

  How to run vlc video player as root user in Linux

  首先是安装,不过在Debian系Linux中,使用 apt / apt-get 包管理会很轻松:

	$ sudo apt install vlc -y

在这里插入图片描述
在这里插入图片描述
   出现 vlc 多媒体图标

   若读者是Red Hat系Linux,则可参考博主另一篇:yum 安装 VLC多媒体

   可能细心的小伙伴们,在安装后就已经发现了,无论什么系Linux,但当我们在root账户下直接运行VLC时,就会出下如下报错:

	VLC is not supposed to be run as root. Sorry.
	If you need to use real-time priorities and/or privileged TCP ports
	you can use vlc-wrapper (make sure it is Set-UID root and
	cannot be run by non-trusted users first).

在这里插入图片描述
  别着急,博主这就为你解答,执行如下命令:

  ①:

	cp /usr/bin/vlc /usr/bin/vlc-backup

  ②:

	needle=$(objdump -d /usr/bin/vlc | grep euid | tail -1 | awk '{print "\\x"$2"\\x"$3"\\x"$4"\\x"$5"\\x"$6;}')

  ③:

	sed -ir "s/$needle/\xb8\x01\x00\x00\x00/" /usr/bin/vlc

  此时,会发现在 root 权限下可正常运行 vlc多媒体了。
在这里插入图片描述


  或许,会有小伙伴发问,是如何解决该问题的?博主,也为感兴趣的读者转载了国外大佬解决该问题的全过程:

  How I found this out

  When starting vlc as root you will probably get the following error message:
	VLC is not supposed to be run as root. Sorry.
	If you need to use real-time priorities and/or privileged TCP ports
	you can use vlc-wrapper (make sure it is Set-UID root and
	cannot be run by non-trusted users first).
  Here is how I change this behavior:
	gdb /usr/bin/vlc
	(gdb) info functions
	All defined functions:

	Non-debugging symbols:
	[...]
	0x0000000000400f40  geteuid
	[...]
  Let’s break in the function to get the effective user identity:
	(gdb) break geteuid
	Breakpoint 1 at 0x400f40
  Let’s start the program to run till the first breakpoint:
	(gdb) run
	Starting program: /usr/bin/vlc 

	Breakpoint 1, 0x00007ffff71cfc70 in geteuid () from /lib64/libc.so.6
  OK, let’s trace the program one command at a time:
	(gdb) stepi
	0x00007ffff71cfc75 in geteuid () from /lib64/libc.so.6
	(gdb) stepi
	0x00007ffff71cfc77 in geteuid () from /lib64/libc.so.6
	(gdb) 
	0x0000000000401103 in ?? ()
	(gdb) 
	0x0000000000401105 in ?? ()
	(gdb) 
  Ok, let’s look at this program part with a disassembler:
	objdump -d -M intel /usr/bin/vlc
	[...]
	 4010f9:       e8 32 0a 00 00          call   401b30 <unsetenv>
	 4010fe:       e8 3d fe ff ff          call   400f40 <geteuid@plt>
	 401103:       85 c0                   test   eax,eax
	 401105:       0f 84 04 06 00 00       je     40170f <fflush@plt+0x66f>
	 40110b:       be ca 1f 40 00          mov    esi,0x401fca
	 401110:       bf 06 00 00 00          mov    edi,0x6
	[...]
  If you do not have exactly the same vlc version as I have, yours will probably look different. In this case just follow the instructions below and assume your values instead of this example.
  It seems as if (address) 4010fe calls geteuid, 401103 prepares a conditional jump and 401105 jumps if equal somewhere. So we call a hexeditor:
	okteta /usr/bin/vlc
  and replace
	0f 84 04 06 00 00
  by some instructions to wait:
	90 90 90 90 90 90
  When calling vlc now as root, it does not abort 😃

  在阅读完之后,会发现大佬解决问题的方式,有着我们很多可学习借鉴的地方,是真的很强!!膜拜!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~晨曦静竹~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值