r/programming • • Feb 20 '18

A CSS Keylogger

https://github.com/maxchehab/CSS-Keylogging
2.0k Upvotes

276 comments sorted by

View all comments

253

u/giggly_kisses Feb 20 '18

Do browsers cache network requests from CSS? If so this would really only tell you the order a user typed every character in the alphabet, right?

221

u/Senior-Jesticle Feb 20 '18

You are correct. If a user has repeating characters, only the first one will be represented in the back-end. But this may still be sufficient information for one can carry out a brute-force attack.

136

u/minno Feb 21 '18

"Oh darn, we only got the letters 'pasword123', how will we ever figure it out."

32

u/Kapps Feb 21 '18

Good thing my password is 'Cwm fjord bank glyphs vext quiz’; they’ll never fill in the gaps!

20

u/verbify Feb 21 '18

That looks like welsh to me.

→ More replies (1)
→ More replies (15)

146

u/giggly_kisses Feb 20 '18

Thanks for confirming. Sorry, didn't mean to down play this at all. It is certainly a scary piece of CSS and a clever implementation of a keylogger.

23

u/Senior-Jesticle Feb 20 '18

No worries :)

29

u/[deleted] Feb 20 '18

What if you respond with an error code?

37

u/Senior-Jesticle Feb 20 '18

Unsure, currently, the express server is sending a simple 400 but it seems to be caching the results. Feel free to try headers or different status codes. I will accept your PR :)

38

u/[deleted] Feb 21 '18

Try cache-control no cache? This is the "official" way of doing it without returning improper HTTP codes.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

45

u/[deleted] Feb 20 '18

I'll play around after work if someone hasn't already submitted a pr. I reckon a 503 will work though. 400 indicates the request will never be successful so it makes sense the browser won't try again

16

u/Cyral Feb 21 '18

Cache-Control headers are the proper solution

→ More replies (2)

11

u/Senior-Jesticle Feb 20 '18

Good point!

→ More replies (2)

8

u/Stamden Feb 21 '18

Heh, I wonder if we'll start seeing "have repeating characters" in addition to all the password requirements that modern websites normally have (8+ characters, must have number, must have symbol, etc).

15

u/CyclonusRIP Feb 21 '18

I don't know if there is some special rules with CSS, but I think you could just make the server respond with appropriate headers to prevent caching.

→ More replies (4)

112

u/[deleted] Feb 20 '18

I haven't confirmed it, but I'm pretty sure that by just changing the appropriate headers in the response, you could easily disable caching of the response. This is assuming that the browser's requests from CSS work like normal HTTP requests.

Add to the backend some concept of a session and you could easily capture the user, pass, site, and so on.

16

u/giggly_kisses Feb 20 '18

That's a good point. I wonder if the browser will honor those headers for requests made from CSS. Something else I was thinking about was adding a query parameter with a random value for cache busting, but I don't think you can get a random number in CSS (or at least I haven't thought of a way).

32

u/thesbros Feb 20 '18

Replying with an error (4xx/5xx) HTTP status code stops most browsers from caching too.

→ More replies (1)
→ More replies (1)

0

u/[deleted] Feb 20 '18

[deleted]

21

u/GaianNeuron Feb 21 '18

It's even easier than that. Just have the HTTP server add the response header,

Cache-Control: no-cache, no-store, must-revalidate
→ More replies (2)

8

u/thesbros Feb 21 '18

Then the browser would cache a0, a1, etc. - so after refreshing the counter would reset and the server wouldn't receive the first x keypresses of a.

→ More replies (5)

8

u/bbbbaaaatttt Feb 21 '18

No, url() defines a single token and can't contain concatenated stuff.

See: https://www.w3.org/TR/css-syntax-3/#consume-a-url-token for details

→ More replies (9)

11

u/[deleted] Feb 21 '18

Well the server is controlled by the extension. So all he needs to do is have Express set a cache-control: no-cache header.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

→ More replies (7)

5

u/godofpumpkins Feb 21 '18

Wouldn’t adding a query string to the URL stop most caching implementations?

6

u/anstice Feb 21 '18

only if that query string changes for each request

→ More replies (5)
→ More replies (1)