zoukankan      html  css  js  c++  java
  • 2019-2020-1 20199325《Linux内核原理与分析》第十一周作业

    实验简介:

    Set-UID 是 Unix 系统中的一个重要的安全机制。当一个 Set-UID 程序运行的时候,它被假设为具有拥有者的权限。例如,如果程序的拥有者是root,那么任何人运行这个程序时都会获得程序拥有者的权限。Set-UID 允许我们做许多很有趣的事情,但不幸的是,它也是很多坏事情的罪魁祸首。
    因此本次实验的目标有两点:
    欣赏好的方面,理解为什么 Set-UID 是需要的,以及它是如何被执行的。
    注意坏的方面,理解它潜在的安全性问题。


    $ cp /usr/bin/passwd /tmp/passwd
    $ ls -la /usr/bin/passwd
    $ ls -la /tmp/passwd
    $ /tmp/passwd #shiyanlou密码可以通过点击右侧工具栏SSH直连看到
    $ /usr/bin/passwd
    

    将passwd拷贝过去,会发现权限发生了改变,复件没有修改密码的权限

    $ ls -l
    -rw-rw-r-- 1 shiyanlou shiyanlou 10 Apr 23 13:33 append_text 《--VULP输入文件
    -rw-rw-r-- 1 root root 0 Apr 23 13:32 root_file 《--目标文件
    -rw-rw-r-- 1 shiyanlou shiyanlou 0 Apr 23 13:45 tmp_file 《--助攻
    -rwsr-xr-x 1 root root 7403 Apr 23 13:27 vulp 《--漏洞文件
    -rw-r--r-- 1 root root 454 Apr 23 13:27 vulp.c

    sudo gcc vulp.c -o vulp
    sudo chmod u+s vulp
    sudo touch root_file 
    sudo chmod g+w root_file
    vi append_text
    touch tmp_file
    sudo chmod u+x check.sh
    gcc attacker.c -o attacker
    

    check.sh

    #!/bin/sh
    #注意`不是单引号
    old=`ls -l /home/shiyanlou/seed/root_file`
    new=`ls -l /home/shiyanlou/seed/root_file`
    while [ "$old" = "$new" ]
    do
        ./vulp < append_text
        new=`ls -l /home/shiyanlou/seed/root_file`
    done
    echo "STOP... The file has been changed"
    

    $ ls -l
    total 32
    -rw-rw-r-- 1 shiyanlou shiyanlou 10 Apr 23 13:33 append_text
    -rwxrwxr-x 1 shiyanlou shiyanlou 7164 Apr 23 14:01 attacker
    -rw-rw-r-- 1 shiyanlou shiyanlou 155 Apr 23 14:00 attacker.c
    -rwxrw-r-- 1 shiyanlou shiyanlou 246 Apr 23 13:58 check.sh
    -rw-rw-r-- 1 root root 0 Apr 23 13:32 root_file
    -rw-rw-r-- 1 shiyanlou shiyanlou 0 Apr 23 13:45 tmp_file
    -rwsr-xr-x 1 root root 7403 Apr 23 13:27 vulp
    -rw-r--r-- 1 root root 454 Apr 23 13:27 vulp.c

    先运行attacker再运行check.sh

    从上面步骤可以看出,/bin/bash有某种内在的保护机制可以阻止Set-UID机制的滥用。为了能够体验这种内在的保护机制出现之前的情形,我们打算使用另外一种shell程序——/bin/zsh。在一些linux的发行版中(比如Fedora和Ubuntu),/bin/sh实际上是/bin/bash的符号链接。为了使用zsh,我们需要把/bin/sh链接到/bin/zsh。

    总结:

    SET-UID程序的漏洞,主要集中在,通过利用root的权限,更改自身程序权限,能够获取相应的程序功能,SET-UID程序主要是在paswwd,chsh,su等这些重要命令当中当作一个检测的手段,能够避免一些问题。

  • 相关阅读:
    使用NoSQL可视化管理工具时报错The GuidRepresentation for the reader is CSharpLegacy
    git和github连接权限(这是一个简便方法,不是很安全,建议大家还是用ssh解决)
    python模块的使用
    利用python抓取页面数据
    利用递归解决“汉诺塔的移动”问题(使用python来做的,其它语言也行)
    mysql中利用show profile很直观的看到查询缓存的作用。
    MySQL中show profiles的开启
    浅谈依赖注入
    使用laraval框架和前端完成restful风格的请求对接(这里只是讨论restful的概念)
    利用composer安装laraval
  • 原文地址:https://www.cnblogs.com/buhery/p/11944967.html
Copyright © 2011-2022 走看看