码迷,mamicode.com
首页 > 系统相关 > 详细

快速修复汉澳sinox命令解释程序bash shell

时间:2014-10-11 22:17:57      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:io   os   使用   ar   for   文件   sp   div   2014   

bash是linux默认命令行管理程序shell,汉澳 sinox也安装有,虽然sinox并没有默认使用bash,但是用户一旦使用就会可能被通过漏洞入侵,所以必须快速修复。虽然sinox使用freebsd 的ports,但是freebsd已经升级到最新的软件管理pkg,ports正在被淘汰,要通过portsnap直接更新到最新的ports然后用pkg安装,不过最新的ports只是在freebsd10以上使用,对于低版本pkg可能不支持。不管怎么说,如果你要用pkg,只能用freebsd10,否则问题会很多,pkg会直接升级到软件的最新版本。pkg产生是为了实现类似yum直接更新二进制程序。要想编译最新的ports,先编译安装最新的pkg。最新的ports在sinox运行有的程序会有问题的。

既然如此,我们只能修改 sinox当前版本bash,把漏洞堵上去。先看bash漏洞。

运行env x=‘() { :;}; echo vulnerable’ bash -c “echo this is a test”
产生结果
vulnerable
echo this is a test
问题是,环境变量x通过() { :;}; echo vulnerable获得,但其中echo是系统命令,会执行。
如果把 echo vulnerable改成ls,pwd会怎么样,如果是sudo就会获得超级管理员的权限。网页用户可以通过cgi程序等方式使用bash运行指令控制系统。

我查阅了网上资料,堵漏洞原理就是修改程序中对引入函数的处理,并参考了最新bash ports改动方式,制定了当前版本bash堵漏洞办法。

先用make extract,make patch把代码解压出来,然后备份shell.c和variables.c为后面加.orig,然后修改shell.c和variables.c,改好后进入源码目录生成补丁。

diff -uN shell.c.orig shell.c > shell.c.patch
diff -uN variables.c.orig variables.c >variables.c.patch

把生成的patch文件放到ports源码files目录.然后在 Makefile增加这两行

EXTRA_PATCHES+= ${PATCHDIR}/shell.c.patch
EXTRA_PATCHES+= ${PATCHDIR}/variables.c.patch

现在进入目录,make clean;make。检查一下代码是否已经改正好。如果好了就make install.

为了强制安装,我在/etc/make.conf增加

FORCE_PKG_REGISTER=yes

安装好了以后,运行bash。输入上面命令行,不再出现vulnerable,修复成功。

为了用gcc4.6编译,我在make.conf设置

DISABLE_VULNERABILITIES=YES
.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc46)

CC=gcc46
CXX=g++46
CPP=cpp46
.endif

下面粘贴patch文件
shell.c.patch

— shell.c.orig 2011-01-03 05:04:51.000000000 +0800
+++ shell.c 2014-10-11 17:37:30.000000000 +0800
@@ -225,7 +225,7 @@
#else
int posixly_correct = 0; /* Non-zero means posix.2 superset. */
#endif

+int import_functions = 0;//IMPORT_FUNCTIONS_DEF; //patch
/* Some long-winded argument names. These are obviously new. */
#define Int 1
#define Charp 2
@@ -244,6 +244,7 @@
{ “help”, Int, &want_initial_help, (char **)0x0 },
{ “init-file”, Charp, (int *)0x0, &bashrc_file },
{ “login”, Int, &make_login_shell, (char **)0x0 },
+ { “import-functions”, Int, &import_functions, (char **)0x0 }, //patch
{ “noediting”, Int, &no_line_editing, (char **)0x0 },
{ “noprofile”, Int, &no_profile, (char **)0x0 },
{ “norc”, Int, &no_rc, (char **)0x0 },

variables.c.patch

— variables.c.orig 2014-10-11 19:22:10.000000000 +0800
+++ variables.c 2014-10-11 19:21:34.000000000 +0800
@@ -100,6 +100,7 @@
extern int assigning_in_environment;
extern int executing_builtin;
extern int funcnest_max;
+extern int import_functions;//patch

#if defined (READLINE)
extern int no_line_editing;
@@ -312,7 +313,8 @@
char *name, *string, *temp_string;
int c, char_index, string_index, string_length;
SHELL_VAR *temp_var;

+ int skipped_import;//patch
+
create_variable_tables ();

for (string_index = 0; string = env[string_index++]; )
@@ -335,11 +337,18 @@
char_index == strlen (name) */

temp_var = (SHELL_VAR *)NULL;

+ skipped_import = 0;//patch
+reval: //patch
/* If exported function, define it now. Don’t import functions from
the environment in privileged mode. */
– if (privmode == 0 && read_but_dont_execute == 0 && STREQN (“() {“, string, 4))
+ if (skipped_import == 0 && privmode == 0 && read_but_dont_execute == 0 && STREQN (“() {“, string, 4)) //patch
{
+ if (!import_functions && !interactive_shell) { //patch————
+ skipped_import = 1;
+ //report_error (_(“Skipping importing function definition for `%s‘: –import-functions required.”), tname);
+ goto reval;
+ } //———–patch
+
string_length = strlen (string);
temp_string = (char *)xmalloc (3 + string_length + char_index);

我为sinox2014就是64位制作了bash修复安装包,安装命令如下|
pkg_add -f ftp://sinox.3322.org/bash-4.2.20.tbz

sinox2013没有制作修复安装包,大家可以自己按上面说明自己编译修复。

快速修复汉澳sinox命令解释程序bash shell

标签:io   os   使用   ar   for   文件   sp   div   2014   

原文地址:http://blog.csdn.net/sinox2010p1/article/details/39999793

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!