179 points · by c4e2bedf40955d8 · 8y ago · 139 comments
I run a pretty popular site that is constantly experiencing some form of abusive traffic- most notably attackers running password dumps against our login endpoint (sometimes from 10k+ ipv4 addresses among several subnets and ASNs). We've mostly mitigated this with rate limiting, captcha and other forms of "suspicious login" detection. But I've been recently pondering ways to waste their time or resources to make password dumping less appealing.
The most recent attack could be accurately and precisely detected, and I noticed the abusive traffic would follow 301 redirects, so I decided to redirect all requests back to their own IP addresses.
I don't think it really slowed them down, but got me thinking of otherwise to stop/slow them down:
* 301 redirect them to a "honeypot" server that holds onto sockets for as long as possible and/or causes the client to waste time/cpu cycles (perhaps, constantly asking the client to renegotiate TLS)
* 301 redirect to https://nsa.gov so they might get on someone's radar with the time and resources to stop them
* Redirect them to a non http protocol, like geo:, potentially blocking the abusive client with a dialog "Want to open this with <Maps Application>?" (Some attacks originate from Android devices- I'm not sure how deeply the custom protocol hooks are registered and if that would even work)
I know abusive web traffic is pretty widespread and was curious how others dealt with it other than standard captcha, rate limiting and iptables rules
To the first part: I would characterize certain scraping, usually behind an authentication wall, as malicious--though admittedly that's not the right word. An example would be scraping Facebook profiles to build a marketing list.
So, by 'non malicious,' i mostly mean 'publicly available data'
That way you can easily control the fake success rate, and you make sure that if the attacker realises they are being tricked, they can't just retry successful logins to double check, since they get the same result every time.
It will hopefully waste their time and discourage them from trying to find other ways.
ie) perl -e "print '0' for (1..1000000000)" | gzip > zipbomb.gz
This will create a ~ 1MB file that will expand into something 1000 times its size.
dd if=/dev/zero of=/dev/stdout bs=1M count=1024 | gzip > zipbomb.gz
However, you're restricted to NUL bytes there. However, you can vastly improve your original Perl script by writing more chars at a time: perl -e "my \$x = ('0' x 1000000); print \$x for (1..1000)" | gzip > zipbomb.gz
That runs about as fast as the dd variant on my system, and about 10 times faster than your original formulation.No, don’t do that. Don’t redirect them to anyone else but yourself.
IANAL but it seems pretty clear that you could end up being partly responsible for any damage caused by sending them elsewhere.
Furthermore, even attacking back in any way could be a very very dumb thing to do. Just because someone is attacking you you don’t know that the owner of the system is responsible for that. In fact most likely almost every single machine that is participating in attacks against you are just botnet victims.
The book Aggressive Network Self-defense talks a bit about this. https://www.amazon.com/Aggressive-Network-Self-Defense-Neil-...
I think the only reasonable thing to do is any combination of the following:
- Present captchas and use rate-limiting like you were
- Block / blackhole / null route
- Honeypot that holds onto sockets for as long as possible, but only if you are sure like someone else said ITT that doing so is not DOSing yourself.
https://en.wikipedia.org/wiki/Blue_Frog
It didn't work out so well.
Some attacks claim to originate from Android devices.
If you want to try to crash the client, you can try gzipping a large amount of null bytes and reply with that. It should compress about 1000 to 1.
Someone else suggested faking a successful login a small percentage of the time, which is a nice trick.
Note that by doing this stuff you could very well provoke a DDoS. Just block the traffic.
But if you can ID them easily then iptables rules might be the most effective use of your time, especially if you can use fail2ban, which makes the whole process very easy.
The TLS thing is interesting, but if some of this traffic is coming from compromised devices it would probably be less harmful for the owner of the device if you didn't make them burn a ton of CPU cycles.
It's fairly easy to create fake, but checksum compliant credit cards.
How about make the login process more resource intensive on the browser side, by running some intensive javascript code before sending it to the server?
The trick would be to make this much more intensive on the client side (say 1s of CPU time), while keeping this relatively easy for the server (say 1ms). We're trying to waste their resources, not ours.
One way I can think of:
1. server sends a random seed to the client
2. client calculates 1000 hashes based an random numbers generated from the seed, something like hash(rand() + password) and sends them to the server
3. server picks a one of those and validates it. In case the hash isn't valid, you'll respond with an invalid password, so the client won't be able to distinguish between a failed authentication because of hash validation or because of a wrong password.
Do exactly what bitcoin does: You send a random prefix and require the client to find a random suffix so that hash(prefix+suffix) ends with, say 4 zeros.
Stay away from trying to increase computational overhead. Everyone thinks computation is "free", but it isn't. There is a turbine somewhere cranking out annoyed pixies to drive your computation war with this botnet. The fact some actor has decided to distribute the energy cost to someone else doesn't mean you have to double down on the waste by multiplying the botnet operator's energy expenditure being dealt with by oblivious user's a thousandfold.
It's a bit like global thermonuclear warfare. The only winning mover is not to play.
The least resource intensive way of dealing with it is just detection and either preemptive drop (no more useful info) or if you want to get creative, start doing some whois digging with IP's and start blowing up some operator's inboxes with questions as to why you are getting malicious login traffic from their IP block so they can start running down the source from their end.
This is the Internet. We don't know everything going through it, but most operator's are generally open to trying to keep transits clean if they are made aware of a problem in a way that doesn't seem like a DDoS aimed at their time.
I guess you can fine tune how complex you want this to be by changing the number of zeros you require.
A friend suggested something else - make the client bruteforce a short RSA key (of say, 100 bits)
Thanks!
Can be used like a captcha or placed in between a process. You just specify how many hashes need to be completed before proceeding.
but are these scripts sophisticated enough to run JS etc?
Justin.tv used to redirect people who searched for "porn" keyword (apparently high overlap with people being toxic on the platform) to what they were looking and used an affiliate link. This became a negative newsstory for them.
TechCrunch calling them out: https://techcrunch.com/2009/02/16/justintv-is-redirecting-po...
Article with retrospection: https://www.inc.com/tess-townsend/justin-kan-stop-freaking-o...
Require your clients to perform some amount of computation to do a request.
Something like this: https://www.npmjs.com/package/work-token
* native code can almost certainly run faster than javascript code, even if you're using webassembly. in my experience js cryptominers operate at around half the speed compared to their native counterpart on the same machine
* the attacker can leverage GPUs to compute solutions hundreds of times faster than what your users can
* users have to wait 30 seconds before they can login. you can generate the key while the user's filling in the form to shave off a few perceived seconds, but that will result in a sluggish login form
* users with slow CPUs (ie. anything slower than what's in a c5.large) will take even longer to generate a solution. this is especially problematic for people on smartphones
* users might think that your site's high CPU usage is because you're running a cryptominer on your site!
If your attacker isn't even paying for the resources they use, such as from botnets or borrowed, then your attack value has gone out of the window. If the indivdual attack is free to the attacker, then you're left with time. PoW guarantees a time value. If a single PoW is too cheap, then ask for more values.
What if you write it in Electron though?
Someone who wishes just to abuse your API with no intention to actually log in will just flood you with reams of requests to obtain new work tokens without executing any of them.
So you're back to regular rate limiting, etc.
https://github.com/tinspin/rupy/blob/master/src/se/rupy/http...
It's secure and solves this problem too.
- not on company time, this is not crucial to the business
- try to collect as much information on the attackers (are they really "hackers"?) as possible, the info they send you, how they react to your challenges ... and share it with us!
Thanks and have fun!
I do share your desire though to try to direct the traffic towards some entity that could be better equipped at cutting it off at its source. It's automated traffic for the most part, so perhaps a clever automated solution could be effective at stirring a bigger or more well-equipped entity to cut if off. Past attempts at FBI reports and such have not amounted to anything for us.
I've since moved to a password manager, but before they were commonplace this was the only somewhat convenient way to give yourself some protection against password leaks.
I am not worried about bots trying to validate various account lists and build "existing users" list of my service, because those enumerating attempts are quickly prevented.
https://en.wikipedia.org/wiki/Billion_laughs_attack
Also, see if they crash with invalid responses. You can serve a malformed document or something like that.
Question is, would this approach get their attention? Seems unlikely, but maybe some users would wonder why their computer was sluggish, and run a virus scan, do a system update, or take other steps to check for malware.
Let's be clear, I'm not claiming it would work for sure. I said "maybe." Point is, the computer being a desktop should not lead to shutting the idea down.
Eating CPU though should do the trick.
Rate-limiting the IP's as well as giving them a 5-second delay before handling the http requests should be very effective.
2) Consider (if possible) assigning unique login urls for each user, company, group, etc so not all users access login from same URL.
3) Implement 2 factor authentication
4) To attempt chipping away at their install base, log the IP's of failed login attempts, identify top offenders and report to a few places:
- look up IP addresses on ARIN.net, and an automated email sent to the abuse contact email on file for each IP address with supporting proof. A similar approach is likely used for reaching torrent downloaders.
For botnet/hijacked devices this may cause some issues for the end user but maybe it's good for them to know their device may be compromised. If you're being hit with some VPN/TOR IP's..
https://whois.arin.net/ui/advanced.jsp
- Submit IP's to blacklists if not already there.
5) There should be a service that helps identify if you are being visited via VPN service/TOR IP, perhaps that could be a flag for you as well, or deny outright.
There is a "recidivist" option for fail2ban to further ban things that show up in the fail2ban log, repeatedly, every 12 hours, for a much longer period such as two weeks.
0) Return massive amounts of data.
1) Return empty on requests that go over a requests/second ratio (use memcache)
2) Return fake success pages. [This is super mean]
3) Return dictionary printouts. [Destroys pattern matching]
They use AI to block attacks to your site. You can do a bunch of customizations too. They are expensive though and start at USD 500/mo
Would you, or anyone reading this in a similar position, be interested in sharing further details privately (with or without NDA), and working together to build a solution?
This is the kind of thing I'd love to work on for free. Yes, for free; this is precisely the kind of thing that can't get filed under "awesome exposure!11", and I don't care anyway. I want to learn more about networking and this would be a great hands-on way to do so.
(1) Being able to identify the IPs from which attacks originate, in real time. You will need to blacklist those hosts (for a limited period of time).
(2) Minimizing and limiting the impact of traffic you previously flagged, on your infrastructure. Ideally, as hostile traffic is flagged, a response is never sent (at the TCP/UDP level). You absolutely do not want to serve any flagged requests. Block traffic as early as possible.
The new approach I would advise is along your very first point: don't let the attackers know you are on to them: silently sink their traffic into a dead service that doesnt even attempt a password login, but don't let them know. You continue to handle their password bruteforces, but you DONT ever return a success. This could be a straight up static page. This kind of approach only works if you are happy to pay the bandwidth price.. but the nice part is: you keep the attacker occupied, they have no idea they aren't making progress, and the users accounts are safe.
You'd still be able to detect new addresses and block as necessary. I don't see your point, of course the solution proposed isn't entirely hermetic, but how does your suggestion overcome this exact issue?
> "This kind of approach only works if you are happy to pay the bandwidth price"
Precisely the reason why most people would rather opt-out of serving malicious requests.
My email is in my profile if you fancy talking specifics, would love to hear about what you’re seeing.
I think this one is something to avoid. What happens if you have a false positive? You've just redirected one of your legitimate users to the attacker.
I interpreterd it as being redirect back to your own address. E.g if I'm an attacker and my IP is [FE80::2], then I'd be redirected to [FE80::2]. Same for an user. And if you've got attackers from 10k IPs, then I'd think it'd be unlikely that you'd single out a single attacker IP.
1. just redirect them to their OWN IP .
2. Just welcome them with a WebJelPool Note : WebJelpool will have infinite ( random ) list of Links with no factual result .. these links will only open a new Pool of random & infinite list of URL .. & so on . bot / person will be in a mess with no facts .
edit: why downvote?
CFAA is a tractor beam they can use against anyone they don't like.
I work cyber security (well, mostly application security these days and not so much networking/telecomms) and I've also been involved with a small spat as a contractor a few years back. Basically, I had broken a collection source for the FBI by fixing and securing a resource for a certain department for a certain state, and maybe hypothetically it had to do with a very sunshiney state and maybe hypothetically it was a department that involved wheeled objects.
The firm I worked for was contacted by an investigator, which, lemme tell you, when an FBI agent appears at your work and asks your boss what sort of assignment you're working on, have no illusion that he's not about to cover for you in any way. Not that I did anything wrong. So anyways, the investigator asked me why I made all these WAN changes and about what packet filtering I had added/removed/reconfigured, all this technical domain knowledge and be really had a good idea of what I was actually doing. So I was comfortable. Eventually he left, basically saying we may be contacted further or potentially if the "investigation" became more serious, be made to appear in court.
Well the following week, a different guy comes in, and basically sealed me in our little coffee room and interrogated me. I was cooperative as I could be because I thought he was well informed like the other guy and generally had an understanding with my work, but he was a complete asshole.
It ended up that (thank God) all my paperwork was in order and my contract was pretty intensively detailed about what work I was going to be doing, I hired an attorney and he took good care of me. Never made it to court, but I ended up owing the lawyer a couple grand (funny how THEY always get paid) and yeah. Luckily I didn't go to federal prison, and my gratitude pushed me to greener pastures and better states.
TL;DR, your judgment has gotten you this far, so trust yourself, but I've poked the government before and I almost went to federal prison. Ymmv
Because if not, you're not out of the woods.
I hired the attorney too. I thought (and he thought) it wasn't ever going to make it to court. I moved on to a different job in a different state. Years later, surprise surprise.
NEVER say anything but the word "lawyer" to a law enforcement official. FBI agents make a policy of not recording interrogations (euphemistically referred to as "interviews") with anything but their own notes. Every word you thought he was trying to put in your mouth, he did, successfully, and when and if it makes it into court, it's your word against his, and nobody will believe you.
I realized later how badly I fucked up that second interview because you're right, I shouldnt have said anything. It's embarrassing but I was more or less "good fed, bad fed"'d.
I've not had any major incidents of this nature since then, but rest assured, I know what to do now.
Were you a contractor too, or a state employee? How bad did it end up?
The bad part is that the agent's notes can be used to convict not only you, but other innocent parties as well. That happened with me- I've never talked to an FBI agent in my life, but after being woken up half-naked with 17+ FBI agents storming the house and pointing M4 assault rifles at her head, trapped in a fenced backyard, my wife did talk to them, no Miranda warning (2011).
Naturally, half the things in the notes were literally impossible for her to have said. The agent himself didn't even memorialize them in a 302 until 2 days after the whole-house search and seizure. That was good enough for the judge to call it consensual and admissible.
For more details, mattchannon dot org.
https://www.youtube.com/watch?v=d-7o9xYp7eE
What to do:
https://www.youtube.com/watch?v=b8S4isIxo2w
It's simple really:
What did he do?
"oh! I see, you want to stop the government from looking up drivers' social security numbers..."
"no, but that data doesn't need to be in the same table that the civilian website queries from, just in case."
"just in case what? Just in case I don't catch you stealing civilian's personal information? Just in case I don't catch your ass performing treason in my goddamn system?!"
"no no no, I'm just saying that information should be divided according to where it is expected to be used from, that way if there was ever to be an incident, the more sensitive information is farther away from where the attack surface is"
" so you've thought this through, tell me: how are you gonna do it? When I'm not looking, you empty out a government database and sell it to someone. Who? How? When?? Are you gonna make me sit here all day before you tell me?"
That type of shit.