9 ms·
Russhian Roulette: 1/6 chance of posting your SSH private key on pastebin
- captn3m0 4y agoBug: Doesn't work with non-RSA or U2F/GPG keys. Some players will get an unfair advantage.
- pluc 4y agoHow is "(Math.floor(Math.random() * 6) === 0)" 1 in 6?
- nassimm 4y agoMath.random() generates a decimal that can be 0 but is less than 1, so when multiplied by 6 the range is 0-5.99999, which is then rounded down.
- jesprenj 4y agoProbably random() returns a value from 0 to one, multiplying by 6 yields a random point between 0 and 6. There is a 1 in 6 chance for this number to be in range [0, 1), which is checked by rounding it down and checking if it's zero. right?
- pluc 4y ago> The Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1 What a poor name for a method.
- kolinko 4y agowhy?
- pluc 4y agoIt just doesn't feel natural. If I ask you to give me a random number, are you going to assume it's random among all existing numbers or between the two smallest ones? I'd do Math.random(min,max) and then it could default to 0,1 though I guess you could go Math.random()*100 or whatever.. guess it just doesn't feel like good design or very convenient/readable - but then again this is JavaScript we're talking about.
- quesera 4y ago> I'd do Math.random(min,max) But then you'd need a different way to do random non-integers. Randomness does not naturally produce an integer result. The 0-1 range with precision determined by the architecture is actually the simplest and most logical and flexible way to do it. [EDIT: floats are never simple, see below!] Some languages offer convenience functions on top of the low level random number generator. I don't know what's available in JavaScript. E.g. in ruby: irb(main):001:0> rand => 0.5562701792527804 irb(main):002:0> rand(100) => 44 irb(main):003:0> rand(44..203) => 188 ...but of course, I could go on all day long about how pleasant Ruby is to work with. :)
- deathanatos 4y ago> Randomness does not naturally produce an integer result. The 0-1 range with precision determined by the architecture is actually the simplest and most logical and flexible way to do it. The most trivial way, I would think, would be to interpret a stream of bits would be as an unsigned integer. E.g., a u32 is just "take 32 bits of random data from your RNG, and cast." That's certainly far more natural than trying to build an IEEE double from [0, 1) with a uniform distribution. I'm actually not sure how you'd do that without doing something like starting with a random u32 and dividing by (U32_MAX + 1). Like maybe you can shove the RNG output into the mantissa, but it is not at all obvious to me about the correctness of that.
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- ordu 4y agoI'm not a javascript guru, but I see two ways how it may work. 1. The right part of equation converted into integer because the left part is integer. Conversion is done by rounding to nearest integer, and it will work this way. 2. The other way it may work is to convert 0 into floating point. Math.floor would make some canonical floating point representation of 0 from numbers in a range [0..1), and so do conversion of (int)0 into float. One needs to really know his language of choice to master such subtleties.
- cplusplusfellow 4y agoI didn’t realize the browser could exfiltrate files like this. Or is this intended to be run via Node?
- njsubedi 4y agoNode.
- TheBrokenRail 4y agoDefinitely Node (or Electron, which is basically Node with a browser bolted on).
- alpaca128 4y ago> Or is this intended to be run via Node? Yes, as can be seen in the single line in the linked readme.
- cplusplusfellow 4y agoI figured an honest question would be downvoted on such a site as this.
- Karellen 4y agoThe README.md, which is displayed on the linked page and should be above the fold on 95% of viewing devices, contains only two lines of text. One of which is the README's title and the name of the project. The other line is: `node main.js` for a 1/6 chance of posting your SSH private key on pastebin :) The question might be honest, but I don't think it adds much to the discussion.
- recuter 4y agoLandshark, cleverest species of them all..
- njsubedi 4y agoOne of my colleagues was asking me a question about this last week. Can all/any applications running on our device read the key? They work on a mac, and wrote a simple python script to confirm. Any program running in the userspace can read the private key file; have the private keys always been not so private all this time?
- EthicalSimilar 4y agoYou can store them in the Secure Enclave on OSX and require TouchID to use the key for signing. See: https://github.com/maxgoedjen/secretive https://github.com/maxgoedjen/secretive
- cassianoleal 4y agoI've been using Secretive for a long time now. It's a great piece of tech. Even if you don't require TouchID, no apps will be able to upload your private keys anywhere as they never leave the enclave. Sure, they can still _use_ the keys without your permission but to do that they need to be running on the workstation. That said, TouchID is really not very inconvenient and if you couple that with control persistence, muxing and keepalive on the SSH client, it's really a no-brainer.
- pluc 4y agoOnly if they run under your user as your private key permission should be only you can read it. Programs running as you are basically you.
- Bootvis 4y agoThat’s why ideally you use a pass phrase with you ssh key. Apps can still read it but not use it.
- progbits 4y agoEven better, if possible switch to something like PGP keys on Yubikey which prevents exfiltration of the private key, and will only sign things when you enter PIN / touch the device.
- traceroute66 4y agoBuy Yubikey, put SSH key on Yubikey, job done. You can use Nitrokey too, but IIRC be careful which one you buy as some are software-only implementations.
- trelane 4y ago> You can use Nitrokey too, but IIRC be careful which one you buy as some are software-only implementations. First I've heard of this. Do you have some links where I can read more about this?
- krmbzds 4y agoYou can check this guide: https://github.com/drduh/YubiKey-Guide https://github.com/drduh/YubiKey-Guide
- traceroute66 4y ago> First I've heard of this. Do you have some links where I can read more about this? Sure, the comparison table on the Nitrokey site[1] is probably sufficient. Anything without a green tick next to "tamper-resistant smart card" is a software implementation with the associated risks (e.g. firmware updates are available[2] - i.e. if you can update the firmware then you've also got a low-level attack vector for miscreants). Meanwhile all YubiKeys are hardware backed and it has never been possible to update firmware on them. [1] https://www.nitrokey.com/#comparison https://www.nitrokey.com/#comparison [2] https://www.nitrokey.com/releases https://www.nitrokey.com/releases
- hamasho 4y agoI'm already sure that this somehow slips into a dependency of a dependency of a dependency of React, and the world will end.
- cobbzilla 4y agoVery cute. It would have been cooler as a shell alias for ssh. Using node seems like cheating; plus you have to call it explicitly, you know you really want to use this to prank your colleague who left their laptop unlocked.
- jay-barronville 4y ago> Using node seems like cheating Well, you can easily turn it into an executable (e.g., using `pkg` [1]) so that the target computer doesn’t even need Node.js installed. [1]: https://www.npmjs.com/package/pkg https://www.npmjs.com/package/pkg
- cobbzilla 4y agoThat’s even more cheating. This can be done purely in shell, no extra tools!
- jay-barronville 4y agoFair enough.
- detrites 4y agoTIL: malware + gamification = how to get #1 FP on HN
- monsieurbanana 4y agoIt's not malware if you run it on purpose
- Karellen 4y agoSocial engineering is a legitimate attack vector. "try this edgy nerd game/challenge for the lulz" is just as valid an exploit as "to see the dancing pigs, just run this `curl | bash` command"
- xwdv 4y agoIf you really wanted to play a dangerous game, you could construct a terminal command that had a 1/6th chance of doing an rm -rf /* at the root directory with full admin privileges and automatic yes to all prompts, preferably on a non virtual machine in production with no backups.
- agilob 4y agoSuicide Linux, already exists
- throwawaaarrgh 4y agoPersonally I would want it to remove the most critical files first, or at least corrupt the filesystem. Most damage as quick as possible, in case they get cold feet and Ctrl+C. Maybe trap all signals so they can't do that either. Maybe run in the background!
- demindiro 4y agoProbably relevant: https://github.com/streaak/pastebin-scraper https://github.com/streaak/pastebin-scraper
- jay-barronville 4y agoSo how many of y’all have already ran this? Haha.
- rtuin 4y agoReally good! Sent this to my colleagues to raise awareness on third party package security risks.
- exabrial 4y agoEveryone likes to crap on PGP, but this is why my ssh keys are subkeys of my GPG key and locked up with the GPG SSH agent. This approach is far from perfect but certainly disallows outright exfiltration attacks.
- lostmsu 4y agoCan you elaborate more? What's the difference between PGP, and having a regular SSH key password protected + running a regular SSH agent?
- exabrial 4y agoThe advantages are very similar actually. The added ‘benefit’ or ‘disadvantage’ is dependent on your use case. If I regard my PGP key as the toehold to my online identity, having an ssh key tied to that identity is quite useful. Kind of neat to see the guy that signed the git commit is the same guy logging into the server, installing the software signed with the same pgp key. If your threat model needs to key your online identity somewhat anonymous, than a private key per server is likely the way to go. An encrypted ssh key is somewhere in the middle there.
- eropple 4y agoFor me, physical smartcard storage + overarching identification. I've been using a Yubikey as my GPG key for a long time (and another in my safe as my GPG root). You can use SSH with FIDO2 today as well, but outside of SSH GPG provides a web of trust which has other benefits, such as a root of revocation (a different Yubikey in my document safe contains my GPG root) and signature validation not being tied to SSH key presence/absence on GitHub.
- aaronmdjones 4y agoI too have a primary YubiKey with my 3 PGP subkeys on it (signing, authenticating, decrypting), and a backup YubiKey in my safe with my PGP master key on it. I find it works quite well. The primary YubiKey goes everywhere I go; I have a lanyard for it. The backup YubiKey stays in the safe until I need it for something (e.g. signing someone else's PGP key, rotating subkeys, renewing the expiration date on a subkey, ...). I also use both of them for FIDO, on websites that support real 2FA; more specifically, I enroll both of them, but I only routinely use the primary one.
- tryauuum 4y agoecho {a..z} | tr ' ' '\n' | sort -R | head -1 > /proc/sysrq-trigger this is my favourite linux russian roulette
- LinuxBender 4y agoHere's a variant that works in #!/bin/ash base64 /dev/urandom | tr -d '/+'| sed s/[^[:alpha:]]//g |tr 'A-Z' 'a-z' | dd bs=1 count=1 2>/dev/null
- mhio 4y agoI hate to be a golfer... buuuut this should still be pretty generic shell LC_ALL=C tr -dc 'a-z' </dev/urandom | head -c 1
- tryauuum 4y agoI think you don't even need head -c 1 because sysrq-trigger will read only one character anyway
- mhio 4y agoNice one! I wasn't taking testing that far =) edit - Actually I don't think it closes the input, so for an initial char that doesn't cause something fatal it looks to continue writing.
- tryauuum 4y agojust tested -- only reads first char, at least with echo (also any character which is not used is used as "h") echo apm > /proc/sysrq-trigger I'm too scared to test with your urandom stuff...
- mhio 4y agoI saw that too, but in this case `echo` exits. My note was just regarding the pipeline will continue to write forever if the first character was any of the non destructive commands. Without trashing vms... ( while true; do printf 'a'; done ) > /proc/sysrq-trigger With the `head`, the output is closed.
- jmclnx 4y agoAnd this is a good example of why people really should start looking seriously at OpenBSD. By default chrome and firefox uses plege(1) and unveil(1). With the defaults, ~/.ssh cannot be seen by these browsers.
- georgyo 4y agoI sorta understand your point, but this wouldn't help in the case of running that script. Namely, the JS sandbox of the browser already prevents filesystem access. But a user running `node` in a shell would not be protected by the browser or the hardening of browsers you mention. You would need to manually setup those protections for your command which most people will not do. Similarly, Linux has filesystem namespaces, and tools like bubblewrap can achieve similar protections. Lastly, the real risk of the above is that code is easily runnable automaticly with an `npm install` and if you have private repositories than node/npm would still need access to private key (or maybe token for http) information to fetch them.
- brnewd 4y agoI wrote a tiny node app wrapped as a single binary as a second factor for ssh public key login using pam_exec.so. It posts a Telegram poll, "allow login to server x as user y from ip z?" Yes/No with a 30second timeout to a private group. A simple way to add some additional protection.
- tete 4y agoTrivial to avoid by using any other path than the default for RSA keys, so a lot of keys made in the last few years. Also that's why you should have a strong password on things.
- anthk 4y agoSometimes I wish Linux and *BSD's followed the Plan9/9front security approach. Keys are handled by factotum, and not under your home directories.
- fmajid 4y agoJoke's on them. I only use ed25519 keys. Seriously, where's the downvote button when you need one? But yes, it would be nice for Linux to gain a version of OpenBSD's unveil system call.
- mrtweetyhack 4y ago[dead]
- johnchristopher 4y ago> ${process.env.HOME}/.ssh/id_rsa Oh well, good thing I always rename my keys with the remote host it connects to.