Professional Documents
Culture Documents
dogma.
Hows the status quo working out for us? There are many alternatives to dogma that are even worse How do we find those that are better?
A Riddle
What is the fundamental difference between
Answer
When an attack doesnt work, you can tell.
disclosure
The Oracle Critical is just an unencrypted transport if its
a bug, then Wireshark is dropping hundreds of 0day Press Will Report Anything
impossible -> You dont have to show youve defended against anything
Critiques of defenses arent much better nobody is
finding effective defenses to the real and legitimate threats we cannot ignore
You shouldnt agree with everything Im going to present My goal is to show you some new ideas, and give you a
framework to consider them as worthwhile or not This is the only way were going to get defense to work
Lest you think theres nothing concrete here
had dead bodies to motivate them We dont have dead bodies, or hundreds of years. We still need to fix these problems. Some vendors out there care along these lines. Reward them!
1) The inability to authenticate 2) The inability to write secure code 3) The inability to bust the bad guys What were not talking about today
Authentication DNSSEC no time, ask me in private (or wait
important I tend to worry about the Aurora attack, which involved espionage against (lets face it) the entire Fortune 500, and against those raiding SMB payrolls, because that calls into question the very viability of SMB Others have different priorities
An immediate clarification
Its not that its impossible to write secure code
Its not impossible to deploy X.509 PKI Its not impossible to bust the bad guys
Timing Attacks
Many systems are modeled in terms of just what data
they send
Not in terms of when they send it Sometimes data leaks security sensitive data
latency over Internet, and 100 nanoseconds of latency over LAN (1000 samples)
Opportunities and limits of remote timing attacks (Scott A
critical context, compare them in constant time (so that theres no correlation between whats compared, and how long it takes)
public static boolean isEqual(byte[] a, byte[] b) {
if (a.length != b.length) { return false; } int result = 0; for (int i = 0; i < a.length; i++) { result |= a[i] ^ b[i] } return result == 0; }
Looks good, right?
The Problem
You have to remember to do this everywhere
performance impact is too high You thus must actually identify all the security critical comparisons
Its possible. But its not probable.
A Solution?
I seem to note that distinguishing against Internet
3ms 1ms
For all packets emitted from the first Ethernet interface, add a
Internet. Maybe Internet attackers also are impacted. This is a lot easier to deploy. That really matters.
But does it work?
Pretty much all password comparisons are done with non-constant time
compares, so I guess all passwords are vulnerable? Heres some SSH 0day sys_auth_passwd(Authctxt *authctxt, const char *password){ /* Encrypt the candidate password using the proper salt. */ encrypted_password = xcrypt(password, (pw_password[0] && pw_password[1]) ? pw_password : "xx"); return (strcmp(encrypted_password, pw_password) == 0); Strcmp is not constant time. So, you just offline brute force for passwords that have certain characters and see how far you get.
It is highly unlikely that the above attack actually works
Nanosecond differentials are too small to recover Maybe not locallyhmmm
permanently obscure how much timing signal beyond the point of infeasible return?
Somewhere between 1 nanosecond and 1 day there
There is a limit to how much lag we can ask for, from the
performance guys
It is higher for some requests than for others
We might require more lag than perf is willing to give (at least
to filter
Quantized into 1ms chunks? Gaussian when it should be uniform, or uniform when it
should be Gaussian Could be filterable thanks to TCP timestamps (which have ~10ms accuracy, but also have sharp edges)
All of the above can be fixed, the question is if they
need to be
The perfect (constant time comparisons) is the enemy of
depending on vendor) leak their private key No, not the thing with the SecureID seeds that were stolen The thing with certificates with easily breakable RSA keys
Something like 1 in 200 RSA keys on the Internet failed! Hughes and Lenstra had first announce, Nadia Heninger had parallel
research
derive
Euclids Greatest Common Denominator
RSA is bad!
Reality
Bad random number generators create trapdoor
password into a pseudorandom stream, which was then used to feed a key generator for RSA/DSA/ECC).
Bad RNG isnt a bug, its a feature!
They thought theyd shown RSA was bad They actually showed that RNGs are still broken
Debians bug wasnt just Debians Werent operating systems supposed to fix this?
Theory
Collecting and providing entropy is hard; let the
bits If /dev/random runs out of bits, block until more are found
Sources for entropy
Actual Environments
Desktops
Humans w/ keyboards and mice Often disks
Servers
Sometimes have disks
Hardware RNGs.
For some reason, people treat TPM hardware as
=3X3Cs6G7VbyRT1xEPcUX.4
Carbohydrates cause cancer
http://www.smh.com.au/lifestyle/diet-and-fitness/high-
carbohydrate-diet-tied-to-cancer-20110616-1g4o9.html
Fats cause cancer
http://www.telegraph.co.uk/health/healthnews/5650141/High-
fat-diet-can-increase-risk-of-deadly-cancer.html
Alcohol causes cancer
http://pubs.niaaa.nih.gov/publications/arh25-4/263-270.htm
booze.
You starve to death.
/dev/random 2) On initialization of their embedded device, the code tries to generate a key. 3) Theres no human at the keyboard, no hand at the mouse, no disk to spin, and no hardware RNG. /dev/random blocks. The device is a brick.
Quite literally, starving for entropy
A comparison
What perfectionists think will happen:
Its broken! Sure theyll demand hardware RNG!
works.
Perfectionism caused (at least) 1 out of 200
computers do
Human is slow clock, CPU is fast clock
per second per megahertz The error is generally much larger than a part per million, just from thermal noise
(Not just thermal noise)
1996) does
Run the CPU in a tight loop (count++); Every 16ms, fire an interrupt On interrupt, shuffle the count variable, and integrate it into a buffer The entropy comes in here timer is slow clock, CPU is fast clock After 11 shuffles, return the buffer as an integer Hash two buffers together using sha1, return only the
first byte
It aint bad. But its disowned.
Thats too bad, because it would have prevented (at
Why is it disowned?
(Literally Matt Blaze was vaguely horrified that
Multiple generators
Sleepers: Measure usleep with CLOCK_MONOTONIC CLOCK_REALTIME RDTSC (on X86 platforms) CPU counter there are equivalents for ARM, MIPS Incrementer: See how many times we can
creations has never written threaded code ;) Two Threads, One Int (one adds, one subtracts, main polls) Two Threads, Two ints (both add, main compares) One Thread, One Int (one adds, main polls) Possible addition: Noisier functions than add
DakaRand Flow
Short version
Push all bits into a SHA-256 Hash Dont undercount entropy Only count them as entropy when they pass Von
Count 1s to decide whether 0 or 1 Throw away 00 and 11, count only 01 and 10 Actually insert a 0 or a 1 when you count a bit Dont overcount entropy
256 value
Make it miserable to guess entropy
Attacking DakaRand
The game: Find a platform (Desktop/Server/VM/Embed) or
an OS under which DakaRand provides poor entropy in one of its modes Userspace/Hypervisor Scheduling
Were only called some number of times per second These times per second may be at predictable intervals If sufficiently predictable, theyll bias the output Will they simultaneously and identically bias both clocked entities?
Autoclocking If you time something against itself, youre going to have a bad
time
Clocks are highly correlated to themselves
timer in a VM VMs, more than anything else, should be exposing a random device (even if the random device itself uses clock differentials) Still, this code seems to still work on VMs
time
uncorrelated streams
Cant do anything after the read is fully completed During the read (which does last a second, due to scrypt)
is already after I actually dont think you can do better than this, though I was considering XORing the keystream with /dev/urandom anyway
that has obvious patterns If you have 100GB of 0s and 128 bits of actual randomness, output of hash has 128 bits of randomness We do explicitly include the 0 and 1
Stream Function vs. Raw Output Lots of raw output from a function tends to leak external state So lets not leak external state. Cryptographic Stream Function RNGs tend to have their own family of functions that are distinctly
was run across 21 ciphers, with inputs of either 16MB of zero or (the same) 16MB of /dev/urandom output
About 24,000 different tests per cipher/content class Thanks, Jamie Schwettman, who did all the work to
Neat tool want it? csql: run SQL against CSV files
$ cat pass2.csv | head -n 20000 | ./csql - "SELECT cipher,
content, test, subtest, count(pv), avg(pv) from c group by cipher, content, test, subtest;" | head -n 10 aes-128-cbc,urandom,dab_bytedistrib,0,10,0.0 aes-128-cbc,urandom,dab_dct,256,10,0.47393035 aes-128-cbc,urandom,diehard_2dsphere,2,10,0.627572674 aes-128-cbc,urandom,diehard_3dsphere,3,10,0.664239991 aes-128-cbc,urandom,diehard_birthdays,0,10,0.50850473 aes-128-cbc,urandom,diehard_bitstream,0,10,0.017056331 aes-128-cbc,urandom,diehard_count_1s_byt,0,10,0.441374983 aes-128-cbc,urandom,diehard_count_1s_str,0,10,0.538731369 aes-128-cbc,urandom,diehard_craps,0,20,0.0394997795 aes-128-cbc,urandom,diehard_dna,0,10,0.396250338
Kernel Recommendations
/dev/random MUST not block. Make an IOCTL if you must Return data slowly if you like CryptGenRandom on Windows does not appear to block
1 out of 200 RDP keys are not likely to be corrupt
Dont be so shy about interrupt sources Care less about interrupt counts than interrupt timings ftrace exposes microsecond timings, which might not be fine
grained enough Use nanosecond arrival times, as much as possible, from devices on foreign busses. The slower the foreign device is, the better.
You want to be measuring slow clocks against fast clocks By definition, the kernel is interrupted at finer grain than userspace.
around Random Number Generation They revolve around languages Language Theoretic Security: The hypothesis that security vulnerabilities are the consequence of the languages code is written in
Coined by Len Sassaman and Meredith Patterson Sapir-Whorf is true for code Corollary: If language got us into this mess, language
can get us out More important corollary: Languages are spoken or written by humans. Ignore their needs at your peril.
The Shift
One way to look at language theoretic security is
power, and communication should be limited to the least amount of power necessary Attacks expands power from Declarative to through Regular Expression through Turing Complete This is indeed a valid lens
Another lens
trees
Injection Vulnerabilities exist when a sending language and a
receiving language (which may or may not be the same) disagree on the nature of the tree sent An extreme case of this is when bytes flow out into surrounding memory But SQL Injection, LDAP Injection, XSS, etc are all just situations where (generally) the sender thought it sent the users data, but the receiver thought it received a peers code
A purely declarative language can still (easily) be injected into, and
complexity can remain declarative and still yield damage. The attack is not in the increase of complexity, but in the transition of content from one identity/context to another through parse tree differentials.
So what?
billions of dollars
[Yes, were going to revisit Interpoliqueits OK,
ZOMG) Not academics (they love Haskell) Not management (they love money)
Money is made by performance, reliability, maintainability,
the brainstorms of one guy Art is science before we know what were doing PHP beats your favorite language If we want to fix security, here is a good place to work
Instead, the database just looks like your favorite languages native objects. Great, right up until the moment you need to make a query.
]>>>+[<+<+>>-] <[>+<-]<[<++>>>+[<+<->>-]<[>+<]]>[<]<]>>[-]<<<[[- ]<[>>+>+<<<-]>> [<<+>>]>>++++++++[<-------->-]<->>++++[<++++ ++++>-]<<[>>>+<<[ >+>[-]<<-]>[<+>]>[<<<<<+>>>>++++[<++++++++>-]>-]< <-<-]>[<<<<[]>>>>[<<<<->>>>-]]<<++++[<<++++++++>>-]<<[>>+>+<<<-]>>[<<+ >>-]+>>+++++[<----->-]<-[<[]>>>+[<+<->>-]<[>+ <-]<[<++>>>+[<+<+ >>-]<[>+<]]>[<]<]>>[-]<<<[[-]<<[>>+>+<<<-]> >[<<+>>-]+>-----------[<[-]>>>+[<+<->>-]<[>+<-]<[<++>>>+[<+<+>>-]< [>+<]]>[<]<]>>[-]< <<<<------------->>[[-]+++++[<<+++++>>]<<+>> ]<[>++++[<<+++++++ +>>-]<-]>]<[]++++++++[<++++++++>-]<+>]<.[ -]+>>+<]>[[-]<]<]
BrainF*cks Rejoinder
There are more things in this world broken by
strlen($name) < 5') ->select('$name'); 32 characters of punctuation, deeply interspersed $result = query(SELECT $name FROM $names WHERE length($name)<5); 12 characters of punctuation (with large gaps) Which would you rather write?
The Classics
Escape? mysql_real_escape_string really? 25 characters? Bigger problems: Fails open code still works if its just missing
Greppability is huge you cant grep for a missing escape!
Escapes are a blacklist. Whens the last time you saw a blacklist
work properly?
Parameterization First you declare a template for a query Then you link individual variables to the template, on a positional
basis
This is the first argument This is the second argument MAYBE, if youre lucky, your language supports argument aliases.
The argument marked with :name should get the value of the variable name
Reality
Nobody has ever written a parameterized query without a gun to
quickly and we realized this was unsafe so we parameterized it That you have to threaten people with getting fired, is itself a data point.
For some strange reason, databases dont seem to provide
parameterize at all
Just try to parameterize SELECT.
SQL, for all its elegance, builds a remarkably complex parse tree
parameterized, etc. Its a decent RNG to know what you can get away with
Interpolique [0]
Released in 2010 at HOPE Concept for eliminating injection attacks while
Basic idea
SELECT * FROM foo where x=$x and y=$y Humans can pretty easily see the separation between
code and data. Data begins with $. Code does not. The language throws that data away and just smashes strings together. Does it have to?
Interpolique [1]
The original approach for Interpolique
First, use an alternate syntax to identify the desired
variables
SELECT * FROM foo where x=^^x and y=^^y
Finally, evaluate the generated code eval(b(SELECT * FROM foo where x=^^x and y=^^y); Eval is, surprisingly, the only way to retrieve the values of $x and $y from inside the function b().
y=$y); If $x and $y are attacker controlled, hes not far from an eval that will run code in PHPs context! The b() function is in a position to defend the code that ultimately enters eval, but now youre entirely dependent on b() knowing what PHP will do given arbitrary bytes.
GOOD LUCK WITH THAT
parent Could implement proxies so it can only read variables, and cant rewrite
$rows=$mysql_safequery(select * from foo where
x=^^x and y=^^y); Requires a patch to PHP -- Daniel Zulla is working on this!
Code Rewriting?
If we know what we would have liked developers to
$z = SELECT * from foo where x=$x and y=$y;; $rows = mysql_query($z); Static analysis can of course find such situations (thus knowing $x came in from a HTTP variable) but most devs dont have access to such static analysis tools
Should they?
Tainting
What if we actually marked every character that came in from an
Metadata, on a character by character basis Would survive passing from function to function Might even survive reasonable mangling by built in filters
would see that those particular characters were once tainted with the mark of the web, and could rewrite the unsafe query around it This still works with mysql_query_safe($x) when $x was assembled elsewhere, even concatenated;
Could have problems with silent failure with filtering functions Requires a patch to PHP Daniel Zulla also working on this
Etsy, based on an approach theyre already running in production What if all variables from the web, were encoded in a whitelisted format?
Simple hex encoding -- &%41 which, coincidentally, renders as
characters as data and parameterize accordingly mysql itself could have its lexer modified to handle HTML encoding, exposing such characters to less of the SQL parser (this is just a string) very LangSec
alone parsed in the frontend $sql = c(select * from foo where x=); $sql += $x; $sql += c(and y =); $sql += $y; Then either mysql_query_safe or mysql itself (cowardly) refuses to execute anything with unmarked code
Or, if this is baked into MySQL, it just doesnt see bytes as code if theyre
this? Can we limit how much code might contain a bug? CARE ABOUT YOUR DEVS OR THEY WILL NOT CARE ABOUT YOU
parties in the middle changing or blocking what you send Content alteration and blocking is becoming a real thing
Verizon is claiming the first amendment right to
rewrite Internet connections Entire countries are silently blocking web pages
Indonesias blocking a million porn sites in the run up to
Ramadan
to have a conversation with anyone on the Internet, using any protocol To any MITM, it would look like a real, unmodified conversation
So any alterations that might normally hit the real server, would hit this
too
Imaging
Browsers Same Origin Policy usually prevents web
account
But there is one exception
Any domain is allowed to load any other domains
images Beyond that, its allowed to know that the load was successful
Not merely that there was a file at that location, but that it was
actually an image You even get image dimensions (which youd have to, because it resizes the page)
Favicon.ico
(Its the picture to the left of Google in the tab)
So this is CensorSweeper
(Also by Joseph Van Geffen and Michael Tiffany) Written for Wall Street Journal Data Transparency Hackathon
Whats going on
img = new Image();
img.onload = function(event) { }// render favicon img.onerror = function(event) { validate(); } img.src = http://somesite.com/favicon.ico The above is done in parallel, reading from a list of sites that have confirmed presence of favicon.ico Six failures are required before a bomb is dropped on the map
Error Handling
Six failures isnt actually enough! Web browsers provide remarkably little feedback to a
down site
That being said, CensorSweeper works pretty well
Can we do better?
Sockets
Once upon a time, web browsers could act like
mapping censorship!
proxy Otherwise, the request will be hijacked by the proxy, serviced, and sent back to your Flash app You now see what that user would see, if they browsed to that site! You can then submit it back to yourself.
traffic on 443/tcp
MITM may have an alternate certificate for you
But (if youre careful) it cant tell the difference between the
browser starting SSL, and Flash/HaXe starting SSL It has to know which domain to pretend to have a certificate for
The proxy can parse the Server Hello, with its certificate
(Its your server saying hello) The proxy can parse the Client Hello, with its Server Name Indication (Its your Flash app saying hello) You can actually host the real Facebook certificate, or even proxy the real Facebook SSL endpoint Hard to keep track of all of Facebooks IPs It has to forge the certificate, before you have to prove you actually have Facebooks private key (assuming you arent proxying)
Slight Annoyance
No normal way, via Browser DOM, to determine the
attacker has already MITMd you and can alter your security validation layer
Full Proxying
One of the goals of N00ter was seeing if everyday content was
being altered or slowed down One of the headaches with these custom probes is writing these custom probes
How do you look just like a real web browser trying to access
browser (at the server) down to the Flash app (in the client), which will then make open connections back to the server who will proxy them to the rest of the Internet This will allow, at minimum, a protocol correct sequence of messages for HTTP and HTTPS that are only incorrect by destination IP
So basically, if the intercepting server doesnt care about IP correctness,
you get to interrogate its ruleset with no installed code on the client
today, that he couldnt do yesterday, for what class attacker, to what class victim?
Rather related to this: How many potential victims are
out there?
Ive run two major scans this year (that Ive talked
about)
Telnet Determining presence of Telnet Encryption support Answer: Very rare RDP Determining presence of open RDP access Answer: VERY common
My Process
Once upon a time, simply flooding TCP SYNs
was enough to find out what was out there Nowadays, many, many IP addresses will three way handshake, but there wont actually be anything there Solution: Split process
1) Identify candidate IP addresses, that are listening
More Detail
Candidate collection
For each IP, incrementing the first byte first,
(1.1.1.1, 2.1.1.1, 3.1.1.1), send a TCP SYN on the required port (23 for telnet, 3389 for RDP) In a separate window, log TCP SYN|ACKs with tcpdump
tcpdump w log 'tcp[tcpflags] = (tcp-syn|tcp-ack)' Scanrand was being buggy, this maximized logging
Candidate Inspection
Telnet Encryption nmap team whipped up a quick
def get(host, port=80): msg = "GET / HTTP/1.1\r\nHost: %s\r\n\r\n" % host yield connect(host, port) yield write(msg) response = yield read() yield close() print response def generate(host, count=100): for i in range(count): yield get('example.com')
and mysterious projects Especially when they give me CPU and Network Bandwidth So. Scanrand3! A new scanner that doesnt just flood SYNs,
and data_sent_time-now()>3 (to find sockets where a retransmit is needed) is just funny! SQLite, in memory-only mode, is really really fast
160K inserts/sec fast
Unfortunately, that speed disappears when you add indexes 20K inserts/sec with two indexes
Details! Details!
Scanrand didnt get its speed by keeping track of who it did
1) Send SYN
Maximum Segment Size==1460 Window Size==1460 (for all packets)
No Local State
If the first SYN is dropped OK, nobodys around to
retransmit it
May want to log RST|ACK to avoid future retransmits
retransmits SYN|ACK If the ACK w/ initial payload is dropped to the server, server retransmits SYN|ACK, causing new ACK w/ payload If any ACK w/ response payload is dropped to the client, server will retransmit ACK w/ response payload
Same with FIN|ACK Window size of 1460 means we always know which
Performance
Relatively unoptimized code on a well hosted but
underpowered server (cheap Dual Opteron) 50-80K servers/sec w/ full payloads 3.25M IPs takes 60-80 seconds, retrieves about 800MB of content Task is embarrassingly parallelizable across threads, databases, etc.
Should be able to use multiple bpf filters to route packets
to their appropriate thread with kernel filtering Writing to a SQLite DB, and then backing up to disk, is really fast (substantially faster than fwrite, though havent tested a large mmap yet) You basically reassemble payloads in SQLite as a postprocess
Security
Scanrand pioneered inverse SYN cookies you protect
against spoofed responses by validating fields in the response against hashes of data plus a secret only you know 16 bits in source port + 32 bits in sequence number are possible
May be able to get another 32 bits out of TCP Timestamps,
which are usually supported Havent implemented yet, so very easy to poison me Sequence space becomes less secure, the more data you actually send
You do know the exact size of each payload, so you can say I only
accept responses with no payload seq, payload 1 seq, payload 2 seq, etc Technically the other said can ACK at any byte offset, but that doesnt mean they actually will
Some Notes
Kernels have actually gotten kind of fast
More Notes
Can also try more efficient stores than sqlite
Giant allocation of RAM with fixed offsets per IP MemSQL Neat project by ex-facebookers compiles SQL to C++ They think even with the indexes they can do +100K
the server
Note that stateless client + stateless server = no
retransmits
C?
JavaScript? Lua?
Could implement support for nmap scripts
Whew!
Lots of stuff!
what I try to do
Thanks to everyone cited in the slides Thanks also to Nick, Johnny, Blackstock, Alex,
Allessandra, Allessandra, and Andrew of The Sub for putting up with me in DEFCON mode ;)