Given that anyone can set up a relay server, what if a powerful adversary sets up a lot of relays around the world?
I'm no expert, but here's what I know:
If an adversary sets up multiple relay servers around the world, all they would get is a bunch of encrypted traffic. In fact, they'd actually be helping.
According to the Lifecycle of a Relay, it could take up to 68 days for a new Guard relay to see any meaningful traffic. Even so, the adversary would only see "who" and not "what."
If an adversary set up exit relays around the world, they'd be helping the Tor network even more! They would see "what" was being sent, but they still wouldn't be able to see "who" was sending it. As an added bonus, if the original traffic was encrypted (HTTPS websites for example), the adversary won't be able to see "what" either!
When multiple Tor relays are run by the same person, the MyFamily option is used to make sure no 2 relays in a circuit are owned by the same person. An adversary most likely won't set this, but I remember seeing something in the tor-relay mailing list saying that Tor was smart enough to not use 2 relays that are too close together in the IP addresses. (for example, 100.200.300.5 and 100.200.300.8 will probably not be in the same circuit) [I'd appreciate if someone could confirm this]
Wrapping it Up
In order to compromise the Tor network and its users, an adversary would need to control both the Guard relay and the Exit node in a given circuit. If a user was accessing an HTTPS website, the adversary would also need to break the original website encryption, which is pretty strong with the new SHA-256 certificates.
Even if an adversary tricked a client into using a guard and exit that they operated, Tor clients switch circuits every 10 minutes by default. On top of that, there are already 7000+ Tor relays that are already stable and "preferred" over new ones.
To put it bluntly, you would need a lot of time and money to effectively compromise the Tor network. It's much easier to compromise a user's data by infecting the Tor browser: http://www.theverge.com/2013/10/4/4802512/nsa-failed-to-compromise-tor-network-but-exploited-browser-vulnerabilities
Of course, once they start exploiting the browser, it's only a matter of time before someone finds out, and the exploit gets patched.
Doing the Math
There are 2000 guards and 1000 exits in the network. The initial cost to run 3000 servers for 2 months would be around $60,000. Since many VPS services charge extra for bandwidth, additional charges could be up to almost $1 million. Running 3000 servers at full capacity would cost just over $1 million per month, and they need to run for at least 2 months to get guard status.
Even after all that, an adversary would only capture half of the network, and this doesn't even include compromising bridges.
On top of this, an adversary would still need to break any encryption from the original traffic, like HTTPS or other encryption protocols.
At this point, I think it's safe to say the NSA and FBI have bigger targets. If they decide to compromise Tor, it would be easier to compromise the browsers or devices rather than the entire network.
Thank you. I wonder how much time and money one has to have in order to run a decent mass data surveillance program in Tor. I saw discussions about that in Bitcoin network (things like "if someone owns at least half of the network, he can do what he wants").– TailsApr 1, 2016 at 21:33
I added some more information to the answer. :) Apr 2, 2016 at 1:24