9 ms·
Police CyberAlarm Uses Alarming Cryptography
- api 4y agoWe need to stop saying don’t roll your own crypto and start teaching it with good examples and good explanations. The only people who will listen to “don’t roll your own crypto” are people who maybe should be learning crypto since they can approach it with the needed level of humility. The people who should not be writing crypto are precisely the ones who will ignore this advice. It’s also sort of elitist sounding and that puts people off and further reduces the odds that they will listen. Everyone knows that someone “rolls their own” crypto or none of it would exist. How does one get into this mysterious club? As near as I can tell you… roll your own crypto… and manage not to fuck it up. So the way you get to become someone who gives this sage advice is by disobeying it. (Of course there are degrees and Ph.Ds and publications but that’s the realm of real cryptographers of the sort that design ciphers. I’m talking about programmers using crypto.)
- CiPHPerCoder 4y ago> We need to stop saying don’t roll your own and start teaching it with good examples and good explanations. I 100% agree with this statement, in isolation. But in context, I have to wonder if something in the post sounded like I was telling people not to roll their own? Because that wasn't the take-away. Either way, https://gotchas.salusa.dev/GettingStarted.html https://gotchas.salusa.dev/GettingStarted.html > So the way you get to become someone who gives this sage advice is by disobeying it. Lawyers have a similar thing, from what I've been told. "Don't go to law school", "Don't become a lawyer", etc. are what many lawyer parents have told their children (some of whom went on to become lawyers themselves).
- melony 4y agoCrypto really isn't the sort of thing you should be doing by yourself, especially implementing crypto algorithms. To correctly implement a crypto algorithm from scratch without existing primitives, you need 1) A basic foundation in discrete mathematics, the type from a CS program and not a web dev bootcamp 2) Strong knowledge of computer architecture 3) Security knowledge of common exploits and vulnerabilities. It is like authoring compilers, most engineers have some knowledge of what's needed. But the few who are lucky enough to get paid to do it full time professionally are not very common. One thing I am thankful for with the hype about cryptocurrencies is that people with understanding of cryptography at the algorithmic are now much more common since the markets are aligned to reward technologies like symbolic execution and probably correct algorithms.
- yccs27 4y agoMan that typo in the last few words cracked me up. "Probably correct algorithm" sounds like "I didn't test the code but it'll probably work fine. Let's deploy it to production!"
- melony 4y ago*provably ;) *algorithmic level I should have proof read it
- mlyle 4y agoAs someone who has "rolled his own crypto" for various reasons, I was just wondering why you're saying this: > 2) Strong knowledge of computer architecture Is it so we can do performant things? Avoid side-channel attacks? Computer architecture isn't focal in my thinking when I'm working on cryptography. Very rarely it becomes important (I could leak information because of ... or boy, that is branch heavy and isn't going to be fast ...)
- GTP 4y agoIt's both, and your example in parentesys actually provides a good example, as brances can both slow you down and provide a side channel (but in crypto I think that in the particular case of branches only the second occurs). If you're looking for an example that is more rooted into computer architecture, you can look at how implementing AES with lookup tables can provide a cache timing side channel.
- mlyle 4y agoWell, then I'd say the knowledge fits more in "3". It's not general purpose architectural knowledge, but rather the wealth of things we've learned from people thinking about side channels.
- GTP 4y agoI think it's hard to pick one between 2 and 3, as after knowing about a possible side channel from 3, you need 2 to prevent it on the specific architecture you'll run your code on.
- pixl97 4y agoLawyers at least are going to a school to be professionally trained... If you're going to roll your own crypto maybe make sure you're professionally trained.
- Zenst 4y agoWould it not be better to have some accredited auditing sevice that can verify and certify crypto code? After all, the whole infosec feild moves fast and what was 100% professinal at the time of being trained with the then known aspects does not mean that they would hold true today. Heck I'm certified to recogise drugs and bombs, yet I'd not have any idea upon many modern drugs or explosives, so in some eye's I qualify as a professional and in my eye's I'm far from it and garantee many who have no such acreditation would be far better than I.
- api 4y agoOkay, then we need to tell people where to get this professional training. What should one do before one rolls their own crypto? But nobody does that. Nobody says "don't roll your own crypto until you learn these things and pass these tests." They just say don't, and the people saying don't are often the ones who are. So it's ignored, and with no good guidance people write crappy crypto.
- CiPHPerCoder 4y ago> Okay, then we need to tell people where to get this professional training. I posted a link to a Getting Started guide in my comment above. Once you've exhausted those resources, your best bet is to join a cryptography team at a tech company to round off your education with some real-world experience. For example, https://www.amazon.jobs/en/search?business_category[]=amazon-web-services&base_query=crypto%20tools https://www.amazon.jobs/en/search?business_category[]=amazon...
- dontbenebby 4y ago> We need to stop saying don’t roll your own crypto and start teaching it with good examples and good explanations. Or teaching it by silently noting and exploiting the flaw, rather than put out a public blog post. Once people know you are elite, all such things do is draw attention to yourself. We live in terrible times, it's not a good idea to engage in cyber dick waving that only serves to draw attention to oneself.
- haswell 4y agoI’m trying to understand this comment. Are you suggesting that writing explanatory blog posts about technical topics is dangerous because someone will eventually come after you for being elite?
- dontbenebby 4y ago>Are you suggesting that writing explanatory blog posts about technical topics is dangerous because someone will eventually come after you for being elite? Yes, based on my personal experience and that of others. But I wouldn't call myself elite... I just know a little bit ;-) I am saying giving them any sort of heads up is not good praxis, since the police have so thoroughly abused the access they already have. See: https://www.vice.com/en/article/k7bqew/us-marshal-securus-phone-location-tracked https://www.vice.com/en/article/k7bqew/us-marshal-securus-ph...
- samhw 4y agoWell, this is bad news for the existence of infosec professionals...
- flatiron 4y agoFrom the article their roll was aes cbc which in itself is perfectly fine…but they did hmac it
- carapace 4y agoPeople shouldn't "roll their own" cryptography any more than they should "roll their own" padlocks or door locks. > The people who should not be writing crypto are precisely the ones who will ignore this advice. Why would they pay attention to "good examples and good explanations" if they disregard the simplest and most basic advice? > It’s also sort of elitist sounding and that puts people off and further reduces the odds that they will listen. Modern cryptography is intrinsically elite. It requires math and computer knowledge far beyond the ken of mere mortals, eh? > Everyone knows that someone “rolls their own” crypto or none of it would exist. How does one get into this mysterious club? As near as I can tell you… roll your own crypto… and manage not to fuck it up. So the way you get to become someone who gives this sage advice is by disobeying it. That sounds like, "Medical students dissect corpses to learn anatomy, so non-doctors should be allowed to perform their own surgery."
- api 4y agoIf you ask a surgeon how to become one, they'll tell you to go to pre-med and then medical school and then become a resident and so on. There's a path to get there. They won't say "don't become a surgeon, go away." If you ask a crypto developer how to become one, they tell you to go away. "Don't roll your own crypto." Not "here's where you go to learn how to do crypto correctly, and here's a test you can take to determine if you're ready to do it." There's no generally accepted path to learn or to test your knowledge. There's just this informal guild of people we think know what they're doing. So no, it's nothing like medicine except in the most superficial sense of them both being hard things.
- carapace 4y agoKeeping with the metaphor, the solution to the situation is to start a medical school, not to encourage people to attempt surgery without any training, eh?
- api 4y agoI agree. My criticism is that the majority of the cryptography community just turns up their nose and does neither. They just say "go away," and people are obviously not listening to that and are instead attempting amateur surgery. The solution is to provide better learning materials. BTW some people often say "just use libraries." The problem is that even the best designed cryptographic libraries are easy to misuse if you don't at least understand the basics of what those building blocks are doing. Imagine using a networking library without knowing what a TCP connection is or how it behaves. You don't need to understand the deep internals of TCP but you need to at least know the semantics and what the protocol does.
- xwdv 4y agoIMO people shouldn’t roll their own anything. Use simple off the shelf solutions and services that are proven and ready to go, and leave the rolling to professionals doing true research and development.
- pavel_lishin 4y agoI'll go one step further; people shouldn't write software!
- SoftTalker 4y agoYou're really not wrong. There are so many ways a novice can screw up writing public-facing software. Even so-called experienced professional software "engineers" and billion-dollar tech companies do it regularly.
- jeroenhd 4y agoTo use crypto right requires knowledge of crypto systems. You're not going to know how to use crypto schemes correctly without knowing about common flaws and a range of side channel attacks. The crypto code itself is usually relatively easy to use (OpenSSL may have a clunky interface, but there are tons of examples out there). The problem here, and I'd argue actually in most cases, isn't that the libraries don't exist or are hard to use. The problem is that the people using said libraries don't know what they're doing. There are great books out there that will tell you everything you need to know to understand and write safe crypto code. It's not some kind of closely guarded secret kept by an exclusive elite, it just requires reading. Pirate the books if you want to stop information hoarding among the rich, it's trivially easy to do with libgen. You can roll your own crypto if you're capable of doing so, and have someone as competent as you check your work. In this case, this tweet has listed the flaws that the custom crypto implementation has: https://mobile.twitter.com/gsuberland/status/1538117635971371009 https://mobile.twitter.com/gsuberland/status/153811763597137... Some of these flaws aren't that bad (== vs === shouldn't matter too much in this case, though it's a sign of bad PHP code when the types are supposed to be well known). Others are either bad code practice (allowing a variable to be uninitialized) or well-known cryptographic mistakes that you'll learn to catch after reading a book or two (timing attack, shared keys). I won't pretend I would've spotted all of those at a glance, but I can admit that my crypto course has been too long ago for me to write or review such code. I've got a basic grasp of electrical cirtuits but that doesn't mean I should be allowed to design highly secure electronic security circuits. I will miss important problems and dangerous flaws because I lack in-depth knowledge and experience. It's not because there's not an easy 1-2-3 guide on how to design safe circuits or because a cabal of academic elites are keeping this knowledge to themselves and pretending to do so just shifts the blame for my lack of effort to others. Feel free to do your own crypto. Tons of companies do. You'd better put in the work to make sure you're doing it right, though! If you're working on some kind of new cryptographic structure and an academic writes up a theoretical attack in a paper somewhere, you're doing it right, assuming that you extend your scheme to solve the problems discovered. If you make textbook mistakes in important code, you're clearly doing it wrong. If you're interested in learning cryptography so you can try to roll your own, I recommend starting with books like these: - Cryptography Made Simple by Nigel Smart - Applied Cryptography by Bruce Schneier - Cryptography Engineering: design principles and practical applications by Neil Ferguson, Bruce Schneier, and Tadayoshi Kohno These books require some prerequisite mathematical knowledge (like all crypto does) which you can probably pick up on Khan Academy. They go in depth into how common cryptography works, why these schemes are secure and how they can be broken (in theory and in practice). Some of them are getting old, though, so you may need to find some newer material if you're doing stuff like modern elliptic curve or post-quantum cryptography.
- Nextgrid 4y agoHonestly, the cryptography part of it is the least concerning (if it was just that it would be an easy fix). Here's a summary with some screenshots of the code: https://paul.reviews/cyberalarm-an-independent-security-review-and-why-you-should-avoid-it/ https://paul.reviews/cyberalarm-an-independent-security-revi... The entire project is an unsalvageable mess and so is their response - clearly they've outsourced the entire thing to idiots and are trying to cover their ass now that it's been publicized.
- CiPHPerCoder 4y agoI agree. This was just a write-up I promised the Twitter thread. https://twitter.com/CiPHPerCoder/status/1538574970011500546 https://twitter.com/CiPHPerCoder/status/1538574970011500546
- CommieBobDole 4y agoWow. Worrying about the cryptography on this thing is like worrying about the quality of the padlock you're using to secure the flaps of a cardboard box.
- GordonS 4y agoI thought this might be an exaggeration, but... wow, just... wow. IMO the NPCC should sue Pervade and take them to the cleaners. Pervade are clearly incapable of developing a secure system, and have completely misrepresented their abilities. They also appear to have blatantly lied to the NPCC numerous times.
- Nextgrid 4y ago> NPCC should sue Pervade and take them to the cleaners You're assuming that the point was to actually deliver something of value that would help track cybercrime and that the contract was awarded fairly. I'm not sure this was the case. Most likely, the brokenness of the system is a feature to justify endless busywork for various people at all levels of the stack, where as a working implementation would not only require little/no maintenance but would actually deliver actionable evidence forcing them to do real police work.
- carbadtraingood 4y agoPolice have an inflated sense of their abilities? Leading to hubris and a poor implementation of something? Surely not. Surely the police only hire the best... (/s)
- Zenst 4y agoI can annicdote many instances that support your purported sarcasim. Only recently had disagreement with two officers who thought something was a civil law issue and not their domain when it was actually a common law issues and for context was fraud related. Of note I esculated to their managment who confirmed they were wrong and I was right.
- daniel-cussen 4y agoAnd the management was police as well, chain of command, perhaps a sheriff. There you go. A third police officer said you were right, without you... Going to ACLU or others to sue the Police Department, or going to Internal Affairs, or any of the new legislation they have to follow or other emasculations. Simple stuff, two said you were wrong, you escalated, and you were found to be right. Doesn't work that badly in real life.
- Zenst 4y agoYes but 99% of the populas would trust the police to know the law and as such would of accepted their mistake as a rule. Luckly I'm a bit more knowledgable in the law and why I pushed the point. So for most people, it wouldn't of worked out well.
- dontbenebby 4y ago>Of note I esculated to their managment And you made it out of that interaction without anyone threatening your life or beating you up? Salud on a peaceful response to your bravery.
- Zenst 4y ago
- 1970-01-01 4y agoCan anyone recommend a SAST tool to flag encryption bugs such as this example?
- amluto 4y agoI admit that, reading the code, I found it challenging to find a severe crypto bug simply because everything is wrong. Even their way of packing the data into a base64 is nonsense. The parser is nonsense. Almost every line of code is wrong. Without more context, I’m not quite convinced that the key is reliably anything other than a constant due to the use of PHP and the failure to validate that the variables in question are initialized. It’s like the most severe bugs are buried in code that is 100% bug! edit: the key is a constant. I’m speechless. See https://paul.reviews/cyberalarm-an-independent-security-review-and-why-you-should-avoid-it/ https://paul.reviews/cyberalarm-an-independent-security-revi...
- tyingq 4y ago>due to the use of PHP PHP allows using uninitialized variables, but it does spew notices: PHP Notice: Undefined variable: bar in testme.php on line2 And most implementations of this would probably be using objects, properties, property_exists(), etc.
- Nextgrid 4y ago"Proper" PHP with a modern framework such as Laravel is decent and as far as I know would forbid this (there's a global exception handler that returns a 500 page with a stack trace). Bare PHP with no framework or anything to patch PHP's shortcomings is IMO unacceptable in today's day and age.
- ev1 4y agoIf you're going to do the latter at the very least use the built in, included, free libsodium
- tgsovlerkhgsel 4y agoNo, no, the key is not a constant. See, they already changed it once! /s (Honestly, that was the biggest red flag for me. They had to change the key and that STILL didn't give them the hint that hardcoding it is not a sane option.) Any company that was involved in this disaster and either implemented or gave their seal of approval to hardcoded crypto keys needs to be permanently excluded from government contracts.
- tptacek 4y agoAs I understand it, the CSPRNG check thing isn't a security feature, it's there in case the CSPRNG spits out an IV with the separator bytes in it. (That's also very silly, I'm just saying).
- CiPHPerCoder 4y agoIt's both. The strpos() check is what you're describing, but openssl_random_pseudo_bytes() accepts an optional second by-reference argument and sets it to true or false depending on the behavior of RAND_pseudo_bytes(). https://www.php.net/openssl_random_pseudo_bytes https://www.php.net/openssl_random_pseudo_bytes This function also isn't fork-safe in PHP, and has caused RNG collisions before: https://github.com/ramsey/uuid/issues/80 https://github.com/ramsey/uuid/issues/80 Consequently, I advise against using this function entirely. random_bytes() is better in every way.
- 3np 4y agoIf I get that part right, it would generally have the same return value throughout the lifetime of a process. So in the off-chance that it does trigger, it gets stuck in an infinite loop.
- CiPHPerCoder 4y agoCorrect. The strpos() check just prevents the IV from containing ::
- sbf501 4y agoI totally missed hash_equals. D'oh! This was fun, I'd like to practice more "spot the flaw" scenarios. Is there a website/tutorial that shows bad code like this? I would find it helpful.
- pdpi 4y agoI've always found the Underhanded C Contest[0] to be a particularly interesting source of insight. Sadly it's been on hiatus for several years now. 0. http://www.underhanded-c.org/ http://www.underhanded-c.org/
- sbf501 4y agoCool, thanks!
- procinct 4y agoThat’s the gist of secure code warrior
- upofadown 4y ago>Now you’ve successfully downgraded the message to the legacy format, which didn’t provide any authentication over the ciphertext. ... and the system accepts the old format? Wouldn't that be the actual problem here? Is there something wrong with the old format that caused a security weakness? >Using either of the two methods, with the HMAC check completely bypassed, you’ve reduced the security of this construction to unauthenticated AES-CBC mode, which is vulnerable to a Padding Oracle Attack. Well was this particular system actually vulnerable to a padding oracle attack? I hate these security writeups that prime the reader but never actually get to the punch line. If something has a security weakness you should explicitly state exactly what it is. Don't leave it to the reader to figure it out. If it turns out that there was no actual issue then you are being misleading by the implication that there was.
- CiPHPerCoder 4y ago> > Using either of the two methods, with the HMAC check completely bypassed, you’ve reduced the security of this construction to unauthenticated AES-CBC mode, which is vulnerable to a Padding Oracle Attack. > Well was this particular system actually vulnerable to a padding oracle attack? Yes. That's what the thing you just quoted says. This isn't a theoretical leap, either. It's unauth CBC with PKCS#7 padding with OpenSSL's API. > I hate these security writeups that prime the reader but never actually get to the punch line. But it did. "X uses Y which is vulnerable to Z" does, emphatically, state that X is vulnerable to Z. Your rant is unnecessary.
- upofadown 4y agoI asked for an explicit statement that it was vulnerable, not if it could be vulnerable. To have a padding oracle attack against CBC, the attacker needs: * The ability to submit a lot of messages for decryption. * A error specific to a padding oracle issue. * Some sort of provided reverse channel to get that error information back to the attacker. Does the system in question have these attributes? I note that you have not explicitly stated that the system is susceptible to a padding oracle attack either. That's because you have read the same article and can not.
- brudgers 4y agoTo me, it's probably good enough. I mean any sophisticated adversary will use the traditional methods of bribery and coercion with violence to obtain intelligence and influence the course of events. They're cheaper, more widely available, and more reliable than monkeying around with code, e.g. https://xkcd.com/538/ https://xkcd.com/538/ Yes it doesn't handle an edge case in the same way body armor doesn't handle a 20mm depleted uranium chain gun, but it probably handles the likely threats well enough. And it is available at a price the city council is willing to pay when facing a we-must-do-something-this-is-something-therefore-we-must-do-it in an area where it lacks expertise and the money to buy expertise...good cybersecurity has a diminishing value for dollar curve.
- CiPHPerCoder 4y ago> To me, it's probably good enough. Your bar should be a little higher. > I mean any sophisticated adversary will use the traditional methods of bribery and coercion with violence to obtain intelligence and influence the course of events. Okay, but we're not talking about someone who failed to meet an ultra paranoid threat model. We're discussing an encryption technique that can be bypassed by anyone who bothered to do the first 2 sets of the cryptopals challenges. > Yes it doesn't handle an edge case in the same way body armor doesn't handle a 20mm depleted uranium chain gun, but it probably handles the likely threats well enough. The edge case is "someone with any knowledge about applied cryptography decided to kick the tires, even if only for the laughs". The code is that bad.
- brudgers 4y agoDo you think it is better than nothing? Because nothing is what the alternative was. It wasn’t Moxie Marlinspike on retainer. The city council chose from the alternatives to an RFP and probably made the choice in part based on who showed up and pitched at the Tuesday night meeting where the purchase was on the agenda. And those people probably met with staff beforehand on a sales call. Whatever better alternative you are imagining would have had to have done those things. Things which are expensive and more important than code quality. I could set my bar higher, but for living in the real world and that a higher bar would conflict with the high bar of assuming people are of good will and doing the best they can. YMMV.
- xd 4y agoIf, I assume the data is being sent back to their servers over HTTPS .. wouldn't that make this process of encrypting the "data" superfluous and have no impact on the overall security - or did I miss something? I'm not defending this mess just curious.
- CiPHPerCoder 4y agoThe vulnerability here is that their application-layer cryptography is vulnerable to adaptive chosen-ciphertext attacks, not that a passive observer could sniff packets and see plaintext.
- woodruffw 4y agoThis is par for the course for law enforcement software, and demonstrates tidily why every line of code used in a LE or legal context must either be open source or available for legal and public review.
- deepspace 4y ago> This is par for the course for law enforcement software That is also true for the software running on Breathalyzers. Long story short, the few times they were independently tested, the software quality was found to be about the same as that of the crap described here, and test results were wildly inaccurate. People are literally jailed every day based on bad law enforcement software.
- widjit 4y agogenuinely doing a bad job and sabotage look very similar
- shreyshnaccount 4y agothe product of the lowest bidder and excellent technical education
- hsbauauvhabzb 4y ago“ Not that it matters much, since you can just bypass the security control entirely, but == is not the correct way to compare hash function outputs.” I read an excellent whitepaper on brute forcing this over the internet in ~2012 but I cannot find it. Anyone happen to know the paper I’m referring to, or if it’s still relevant with modern cpu and compiler optimisations?
- CiPHPerCoder 4y agoThere's this 2009 paper http://www.cs.rice.edu/~dwallach/pub/crosby-timing2009.pdf http://www.cs.rice.edu/~dwallach/pub/crosby-timing2009.pdf
- hsbauauvhabzb 4y agoThanks that’s the one!
- lupire 4y ago
- Ava433 4y ago