Dangerous Errors
Podcast Posts Presentations Synthwave About
Podcast Posts Presentations Synthwave About
  • I'll ne'er look you i' the plaintext again May 3, 2016

    The alphabetically adjacent domains when this site was hosted at WordPress included air fresheners, web security, and cats. Thanks to Let's Encrypt, all of those now support HTTPS by default.

    deadliestwebattacks TLS

    Even better, WordPress serves the Strict-Transport-Security header to ensure browsers adhere to HTTPS when visiting it. So, whether you're being entertained by odors, HTML injection, or felines, your browser is encrypting traffic.

    Let's Encrypt makes this possible for two reasons. The project provides free certificates, which addresses the economic aspect of obtaining and managing them. Users who blog, create content, or set up their own web sites can do so with free tools. But the HTTPS certificates were never free and there was little incentive for them to spend money. To further compound the issue, users creating content and web sites rarely needed to know the technical underpinnings of how those sites were set up (which is perfectly fine!). Yet the secure handling and deployment of certificates requires more technical knowledge.

    Most importantly, Let's Encrypt addressed this latter challenge by establishing a simple, secure ACME protocol for the acquisition, maintenance, and renewal of certificates. Even when (or perhaps especially when) certificates have lifetimes of one or two years, site administrators would forget to renew them. It's this level of automation that makes the project successful.

    Hence, WordPress can now afford -- both in the economic and technical sense -- to deploy certificates for all the custom domain names it hosts. That's what brings us to the cert for this site, which is but one domain in a list of SAN entries from deadairfresheners to a Russian-language blog about, inevitably, cats.

    Yet not everyone has taken advantage of the new ease of encrypting everything. Five years ago I wrote about Why You Should Always Use HTTPS. Sadly, the article itself is served only via HTTP. You can request it via HTTPS, but the server returns a hostname mismatch error for the certificate, which breaks the intent of using a certificate to establish a server's identity.

    As with all things new, free, and automated, there will be abuse. For one, malware authors, phishers, and the like will continue to move towards HTTPS connections. The key point there being "continue to". Such bad actors already have access to certs and to compromised financial accounts with which to buy them. There's little in Let's Encrypt that aggravates this.

    Attackers may start looking for letsencrypt clients in order to obtain certs by fraudulently requesting new ones. For example, by provisioning a resource under a well-known URI for the domain (this, and provisioning DNS records, are two ways of establishing trust to the Let's Encrypt CA).

    Attackers may start accelerating domain enumeration via Let's Encrypt SANs. Again, it's trivial to walk through domains for any SAN certificate purchased today. This may only be a nuance for hosting sites or aggregators who are jumbling multiple domains into a single cert.

    Such attacks aren't proposed as creaky boards on the Let's Encrypt stage. They're merely reminders that we should always be reconsidering how old threats and techniques apply to new technologies and processes. For many "astounding" hacks of today, there are likely close parallels to old Phrack articles or basic security principles awaiting clever reinterpretation for our modern times.

    Julius Caesar

    Finally, I must leave you with some sort of pop culture reference, or else this post wouldn't befit the site. This is the 400th anniversary of Shakespeare's death. So I shall leave you with a quote from Julius Caesar:

    Nay, an I tell you that, Ill ne'er look you i' the

    face again: but those that understood him smiled at one

    another and shook their heads; but, for mine own part, it

    was Greek to me. I could tell you more news too: Marullus

    and Flavius, for pulling scarfs off Caesar's images, are

    put to silence. Fare you well. There was more foolery

    yet, if I could remember it.

    May it take us far less time to finally bury HTTP and praise the ubiquity of HTTPS. We've had enough foolery of unencrypted traffic.

  • You've Violated APE Law! Mar 18, 2016

    Developers who wish to defend their code should be aware of Advanced Persistent Exploitability (APE). It's a situation where broken code remains broken due to incomplete security improvements.

    La Planète des Singes

    Code has errors. Writing has errors. Consider the pervasiveness of spellcheckers and how often the red squiggle complains about a misspelling in as common an activity as composing email.

    Mistakes happen. They're a natural consequence of writing, whether code, blog, email, or book. The danger here is that mistakes in code lead to vulns that can be exploited.

    Sometimes coding errors arise from a stubborn refusal to acknowledge fundamental principles, as seen in the Advanced Persistent Ignorance that lets SQL injection persist more than a decade after programming languages first provided countermeasures. Anyone with sqlmap can trivially exploit that ancient vuln by now without bothering to know how they're doing so.

    Other coding errors stem from misdiagnosing a vuln's fundamental cause -- the fix addresses an exploit example as opposed to addressing the underlying issue. This failure becomes more stark when the attacker just tweaks an exploit payload in order to compromise the vuln again.

    We'll use the following PHP snippet as an example. It has an obvious flaw in the arg parameter:

    <?php
    $arg = $_GET['arg'];
    $r = exec('/bin/ls ' . $arg);
    ?>
    

    Confronted with an exploit that contains a semi-colon to execute an arbitrary command, a dev might choose to apply input validation. Doing so isn't necessarily wrong, but it's potentially incomplete.

    Unfortunately, it may also be a first step on the dangerous path of the "Clever Factor". In the following example, the dev intended to allow only values that contained alpha characters.

    <?php
    $arg = $_GET['arg'];
    # did one better than escapeshellarg
    if(preg_match('/[a-zA-Z]+/', $arg)) {
        $r = exec('/bin/ls ' . $arg);
    }
    ?>
    

    As a first offense, the regex should have been anchored to match the complete input string, such as /^[a-zA-Z]+$/ or /\A[a-z][A-Z]+\Z/.

    That mistake alone should worry us about the dev's understanding of the problem. But let's continue the exercise with three questions:

    • Is the intention clear?
    • Is it resilient?
    • Is it maintainable?

    This developer declared they "did one better" than the documented solution by restricting input to mixed-case letters. One possible interpretation is that they only expected directories with mixed-case alpha names. A subsequent dev may point out the need to review directories that include numbers or a dot (.) and, as a consequence, relax the regex. That change might still be in the spirit of the validation approach (after all, it's restricting input to expectations), but if the regex changes to where it allows a space or shell metacharacters, then it'll be exploited. Again.

    This leads to resilience against code churn. The initial code might be clear to someone who understands the regex to be an input filter (albeit an incorrect one in its first incarnation). But the regex's security requirements are ambiguous enough that someone else may mistakenly change it to allow metacharacters or introduce a typo that weakens it.

    Additionally, what kind of unit tests accompanied the original version? Merely some strings of known directories and a few negative tests with ./ and .. in the path? None of those tests would have demonstrated the vulnerability or conveyed the intended security aspect of the regex.

    Code must be maintained over time. In the PHP example, the point of validation is right next to the point of usage (the source and sink in SAST terms). Think of this as the spatial version of the time of check to time of use flaw.

    In more complex code, especially long-lived code and projects with multiple committers, the validation check could easily drift further and further from the location where its argument is used. This dilutes the original dev's intention since someone else may not realize the validation context and re-taint or otherwise misuse the parameter -- such as using string concatenation with other input values.

    In this scenario, a secure solution isn't even difficult. PHP's documentation gives clear, prominent warnings about how to secure calls to the entire family of exec-style commands.

    $r = exec('/bin/ls ' . escapeshellarg($arg));
    

    The recommended solution has favorable attributes:

    • Clear intent -- It escapes shell arguments passed to a command.

    • Resilient -- The PHP function will handle all shell metacharacters, not to mention the character encoding like UTF-8.

    • Easy to maintain -- Whatever manipulation the $arg parameter suffers throughout the code, it will be properly secured at its point of usage.

    It also requires less typing than the back-and-forth of multiple bug comments required to explain the pitfalls of regexes and the necessity of robust defenses. Securing code against one exploit is not the same as securing it against an entire vuln class.

    There are many examples of this "cleverness" phenomenon, from string-matching alert to dodge XSS payloads to renaming files to avoid exploitation.

    What does the future hold for programmers?

    Pierre Boule's vacationing astronauts perhaps summarized it best in the closing chapter of La Planète des Singes:

    Des hommes raisonnables ? ... Non, ce n'est pas possible

    May your interplanetary voyages lead to less strange worlds.

  • Laws of Magic, Technology, and Appsec Feb 12, 2016

    Just as there can be appsec truths, there can be appsec laws.

    Science fiction author Arthur C. Clarke succinctly described the wondrous nature of technology in what has come to be known as Clarke's Third Law (from a letter published in Science in January 1968):

    Any sufficiently advanced technology is indistinguishable from magic.

    The sentiment of that law can be found in an earlier short story by Leigh Brackett, "The Sorcerer of Rhiannon," published in Astounding Science-Fiction Magazine in February 1942:

    Witchcraft to the ignorant... Simple science to the learned.

    With those formulations as our departure point, we can now turn towards crypto, browser technologies, and privacy.

    The Latinate Lex Cryptobellum:

    Any sufficiently advanced cryptographic escrow system is indistinguishable from ROT13.

    Or in Leigh Brackett's formulation:

    Cryptographic escrow to the ignorant . . . Simple plaintext to the learned.

    A few Laws of Browser Plugins:

    Any sufficiently patched Flash is indistinguishable from a critical update.

    Any sufficiently patched Java is indistinguishable from Flash.

    A few Laws of Browsers:

    Any insufficiently patched browser is indistinguishable from malware.

    Any sufficiently patched browser remains distinguishable from a privacy-enhancing one.

    For what are browsers but thralls to Laws of Ads:

    Any sufficiently targeted ad is indistinguishable from chance.

    Any sufficiently distinguishable person's browser has tracking cookies.

    Any insufficiently distinguishable person has privacy.

    Writing against deadlines:

    Any sufficiently delivered manuscript is indistinguishable from overdue.

    Which leads us to the foundational Zeroth Law of Content:

    Any sufficiently popular post is indistinguishable from truth.

  • Battling the Geologic Timescale of SAST Oct 19, 2015

    65 million years ago, dinosaurs ruled the earth.

    In 45 million lines of code, Windows XP dominated the desktop. Yes it had far too many security holes and people held onto it for far too long — even after Microsoft tried to pull support for the first time. But its duration is still a testament to a certain measure of success.

    Much of today’s web still uses code that dates from the dawn of internet time, some new code is still written by dinosaurs, and even more code is written by the avian descendants of dinosaurs. These birds flock to new languages and new frameworks. Yet, looking at some of the trivial vulns that emerge (like hard-coded passwords and SQL built from string concatenation), it seems the bird brain hasn’t evolved as much security knowledge as we might wish.

    I’m a fan of dead languages. I’ve mentioned before my admiration of Latin. And hieroglyphs have an attractive mystery to them. This appreciation doesn’t carry over to Perl. (I wish I could find the original comment that noted an obfuscated Perl contest is a redundant effort.)

    But I do love regular expressions. I’ve crafted, tweaked, optimized, and obscured my fair share of regexes over the years. And I’ve discovered the performance benefits of pcre_study() and JIT compilation mode.

    Yet woe betide anyone using regexes as a comprehensive parser (especially for HTML). And if you’re trying to match quoted strings, be prepared to deal with complexities that turn a few character pattern into a monstrous composition.

    Seeing modern day humans still rely on poorly written regexes to conduct code scanning made me wonder how little mammals have advanced beyond the dinosaurs of prehistory. They might not be burning themselves with fire, but they’re burning their chances of accurate, effective scans.

    That was how I discovered pfff and its companion, sgrep.

    At the SOURCE Seattle conference this year I spoke a little about lessons learned from regexes and the advancements possible should you desire to venture into the realm of OCaml: SOURCE Seattle 2015 - Code Scanning. Who knows, if you can conquer fire you might be able to handle stone tools.

  • Bad Code Entitles Good Exploits Sep 9, 2014

    Here's an HTML injection (aka cross-site scripting) example that's due to a series of tragic assumptions that conspire to not only leave the site vulnerable, but waste lines of code doing so.

    The first clue to the flaw lies in the querystring's state parameter. The site renders the state value into a title element. Naturally, a first test payload for HTML injection would be attempting to terminate that element. If that works, then a more impactful followup would be to append arbitrary markup such as <script> tags. A simple probe looks like this:

    https://web.site/cg/aLink.do?state=abc%3C/title%3E

    The site responds by stripping the payload's </title> tag and all subsequent characters. Only the text leading up to the injected tag is rendered within the title.

    <HTML>
    <HEAD>
    <TITLE>abc</TITLE>
    

    This seems to have effectively countered the attack. Of course, if you've been reading this blog for a while, you'll suspect this initial countermeasure won't hold up -- that which seems secure shatters under scrutiny.

    The developers worried that an attacker might try to inject a closing </title> tag. Consequently, they created a filter to watch for such payloads and strip them. This could be implemented as a basic case-insensitive string comparison or a trivial regex.

    And it could be bypassed by just a few characters.

    Consider the following closing tags. Regardless of whether they seem surprising or silly, the extraneous characters are meaningless to HTML yet meaningful to our exploit because they belie the assumption that regexes make good parsers.

    <%00/title>
    <""/title>
    </title"">
    </title id="">
    

    After inspecting how the site responds to each of the above payloads, it's apparent that the filter only expected a so-called "good" </title> tag. Browsers don't care about an attribute on the closing tag. They'll ignore such characters as long as they don't violate parsing rules.

    Next, we combine the filter bypass with a payload. In this case, we'll use an image onerror event.

    https://web.site/cg/aLink.do?state=abc%3C/title%20id=%22a%22%3E%3Cimg%20src=x%20onerror=alert%289%29%3E

    The attack works! We should have been less sloppy and added an opening <TITLE> tag to match the newly orphaned closing one. A nice exploit won't leave the page messier than it was before.

    <HTML>
    <HEAD>
    <TITLE>abc</title id="a">
    <img src=x onerror=alert(9)>
    Vulnerable & Exploited Information Resource Center</TITLE>
    

    The tragedy of this flaw is that it shows how the site's developers were aware of the concept of HTML injection exploits, but failed to grasp the underlying principles of the vuln. The effort spent blocking an attack (i.e. countering an injected closing tag) not only wasted lines of code on an incorrect fix, but instilled a false sense of security. The code became more complex and less secure.

    The mistake also highlights the danger of assuming that well-formed markup is the only kind of markup. Browsers are capricious beasts. They must dance around typos, stomp upon (or skirt around) errors, and walk bravely amongst bizarrely nested tags. This syntactic havoc is why regexes are notoriously worse at dealing with HTML than proper parsers.

    There's an ancillary lesson here in terms of automated testing (or quality manual pen testing, for that matter). A scan of the site might easily miss the vuln if it uses a payload that the filter blocks, or doesn’t apply any attack variants. This is one way sites "become" vulnerable when code doesn't change, but attacks do.

    And it's one way developers must change their attitudes from trying to outsmart attackers to focusing on basic security principles.

1 ... 14 15 16 17 18 ... 30

Dangerous Errors

  • zombie
  • mutantzombie
  • mutantzombie.bsky.app
  • SecurityWeekly

Cybersecurity and more | © Mike Shema