Secure Programming with Static Analysis - podcast episode cover

Secure Programming with Static Analysis

Feb 24, 202523 min
--:--
--:--
Download Metacast podcast app
Listen to this episode in Metacast mobile app
Don't just listen to podcasts. Learn from them with transcripts, summaries, and chapters for every episode. Skim, search, and bookmark insights. Learn more

Episode description

Secure Programming with Static Analysis is a Book detailing how to write secure software using static analysis tools. It focuses on common coding errors in C and Java that lead to security vulnerabilities, providing code examples and solutions. The book emphasizes preventing vulnerabilities, rather than merely addressing them after they occur, advocating for proactive techniques such as input validation and secure coding practices. Specific security issues like buffer overflows, SQL injection, and cross-site scripting are thoroughly examined. Finally, the text also includes practical guidance on integrating static analysis tools into the software development lifecycle.

You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cyber_security_summary

Get the Book now from Amazon:
https://www.amazon.com/Secure-Programming-Static-Analysis-Brian/dp/0321424778?&linkCode=ll1&tag=cvthunderx-20&linkId=679a352512d3f61a2c619ba74bf28a48&language=en_US&ref_=as_li_ss_tl



Discover our free courses in tech and cybersecurity, Start learning today:
https://linktr.ee/cybercode_academy

Transcript

Speaker 1

All right, let's dive right in. Today we're going to be getting into secure programming, specifically how to write code that can withstand even the most persistent attacker. We're looking at secure programming with static analysis. It's a book by Brian Chess and Jacob West.

Speaker 2

Yeah, it's a really interesting read. It really gets into how to build security and right from the beginning instead of just you know, trying to patch things up later.

Speaker 1

Yeah. They really make a good point about secure code not being something you just like tack on at the end. It's it's really a whole different way of thinking.

Speaker 2

Absolutely. Yeah. And one of the uh, I think one of the key takeaways from the book is is this idea of static analysis.

Speaker 1

So for folks listening, you can think of static analysis like having a super smart code reviewer, like always looking over your shoulder. You know. It's it's really good at catching those little errors that sometimes even you know, really experienced programmers miss. But what makes these tools so effective, Like especially when we're talking about languages like C and Java, well both SEE and Java.

Speaker 2

They give developers a lot of power and flexibility, which is great, but you know, it's kind of like the old spider man quote. With great power comes great responsibility, especially when it comes to how memory is managed. If you make mistakes in these areas, you can end up with some pretty bad vulnerabilities, like the dreaded buffer overflow.

Speaker 1

Ooh, buffer overflows that sounds that sounds scary.

Speaker 2

They can be. Yeah. Imagine you have a container and it's designed to only hold a certain amount of data. Well, a buffer overflow happens when you try to put more data in than it.

Speaker 1

Can handle, like trying to fit ten pounds of potatoes into a five pound sack.

Speaker 2

Exactly. Yeah, But instead of potatoes spilling out everywhere, you have data that's spilling over into other parts of the memory. And this is where it gets really interesting. Especially you know, if you're thinking like an attacker, they can actually use this overflow to overwrite important parts of a program's memory.

Speaker 1

Oh okay, I see how this could be bad.

Speaker 2

It can lead to all sorts of things, crashing a program, corrupting data. You can even potentially hijack the whole application to run some malicious code.

Speaker 1

Oh yikes, that sounds like a real problem.

Speaker 2

It can be, and Chessman Wes used this really good example in the book from open ssh. Open Ssh is used for you know, secure remote access to servers, so you can imagine what would happen if someone were to find and exploit a buffer overflow in that software.

Speaker 1

Yeah, definitely not good, not good at all.

Speaker 2

And this's just one example. They also talk about some cases with send mail, which is another really widely used piece of software, and these examples show how even you know, what might seem like a simple error can have some pretty serious consequences.

Speaker 1

So it's really not just about writing code that works, but about writing code that works securely.

Speaker 2

Right exactly, And that's where static analysis really comes in. Static analysis tools can actually analyze your code and find these potential buffer overflows and other vulnerabilities before they become a real problem in the wild.

Speaker 1

It's almost like having a security guard, you know, watching your code and making sure no one can sneak in through the back door. But Chess and West don't just focus on buffer overflows in the book, right.

Speaker 2

Right, Yeah, They actually spend a lot of time talking about web applications, which, you know, that's an environment where you're constantly having to deal with user input and user input well, let's be honest, it can often be you know, a bit of a security headache.

Speaker 1

Oh yeah, you're right. User input that's unpredictable exactly.

Speaker 2

You never know what you're going to get, and that's why it's super important to validate and sanitize that input before you do anything with it. If you don't, you could be opening yourself up to well a whole host of vulnerabilities like cross site scripting or EXSS.

Speaker 1

Okay EXSS. So I've heard of this before, but I've never really understood exactly how it works. Is this something that you know, the average person listening should be worried about?

Speaker 2

Oh yeah, definitely. So imagine this scenario. An attacker. Let's say they inject some you know, bad JavaScript code into a comment field on a website. Now, if that website isn't properly handling the user input, you know, making sure things are encoded properly, that malicious code could actually be executed in the browser of you know, anyone who visits that page.

Speaker 1

Oh so, it's like like planting a little bomb that goes off when someone comes across it.

Speaker 2

It's a good analogy. Yeah, and the consequences can be pretty bad. You can steal cookies, you can hijack accounts. You can even redirect users to other malicious websites.

Speaker 1

Oh, okay, EXSS is definitely something to watch out for.

Speaker 2

For sure, Jess and West. They actually use a really fascinating case study in the book about MySpace. So my Space tried to block these EXSS vulnerabilities, but you know what, clever attackers kept finding ways around their defenses.

Speaker 1

That's kind of scary, this cat and mouse game between developers and attackers.

Speaker 2

Yeah, it really shows why you need to have this proactive approach to security. You always have to be thinking like an attacker, asking yourself, you know, how could this be misused? And that's where static analysis tools, you know, they can be a real life saver. They can help you find those potential excess as vulnerabilities before they become a real problem.

Speaker 1

So it's really about catching these problems early on, before they can do any damage.

Speaker 2

Exactly. Yeah. But let's shift gears for a minute and talk about something that might seem a little less exciting. Let's talk about passwords and secrets.

Speaker 1

Ah, passwords, those little strings of characters that cause so many problems.

Speaker 2

They really can. Yeah. Yeah, And one of the biggest mistakes developers make is hard coding passwords right into their code.

Speaker 1

Okay, yeah, I can see how that wouldn't be good.

Speaker 2

Yeah, it's like leaving your house key under the doormat. If someone can access your code, well they've got your passwords. It's that easy. And actually, Chess and West highlight this real world example in the book, a system that was written in Java that got this wrong. Their passwords were exposed for anyone to see.

Speaker 1

Okay, yeah, that's definitely something to avoid. So what's the right way to handle passwords?

Speaker 2

Well, there's some best practices, but that the key is to never store passwords directly in your code. Instead, you should use secure hashing algorithms, so, you know, store passwords in a way that makes them almost impossible to reverse engineer.

Speaker 1

Hm hmm okay, so no ah, head and keys under the doormat, got it? What about what about systems that already have a lot of you know, power and access.

Speaker 2

That's a really good point. And Chess and West they dedicate a whole chapter to privileged programs. These are programs that you know, have special access, like the root user on Linux. If these programs get compromised, well, the damage can be pretty significant.

Speaker 1

It's like giving someone, you know, the master key to your whole house.

Speaker 2

Exactly. Yeah, that's why the principle of these privilege is so important. You only want to give programs the access that they absolutely need, nothing more. They have some great examples in the book about about how dropping privileges, like you know, running program as a less privileged user can help to limit the damage if an attack does happen.

Speaker 1

Oh, that's that's interesting. It's kind of like like having different keys for different rooms in your house. Like I wouldn't give you a guest the key to your safe, would you, right?

Speaker 2

Exactly. It's all about limiting, you know, the potential damage. And this applies to software too. When you limit the privileges of your programs, you make it a lot harder for an attacker to get access to your whole system.

Speaker 1

So we've talked about buffer overflows, We've talked about EXSS, we've talked about passwords, the importance of limiting privileges. Seems like there's a lot to think about when it comes to writing secure code.

Speaker 2

There is. Yeah, But the good news is static analysis tools can help with all of this. They can, you know, analyze your code for these vulnerabilities and even give you some advice on how to fix them.

Speaker 1

So these tools aren't just about finding the problems. They actually help you solve.

Speaker 2

Them too, exactly. They're like a security consultant built right into your development process.

Speaker 1

Okay, that makes sense.

Speaker 2

And then the next part of our deep dive, we're going to actually see some of these tools in action.

Speaker 1

That's good.

Speaker 2

Well, we'll walk through how these tools actually work. You know, how they build models of your code, trace data flow, and use rules to find those those tricky problems.

Speaker 1

Okay, yeah, I'm excited for that.

Speaker 2

And you know it's it's not magic, but it's it's pretty close.

Speaker 1

It's pretty cool, it really is.

Speaker 2

Okay. So we've talked a lot about, you know, why secure programming is so important, but now let's get into the how. How can we actually use these static analysis tools to find those vulnerabilities that might be hiding in our code.

Speaker 1

Yeah, let's let's get into it. I'm ready to put on my detective hat and start hunting for bugs.

Speaker 2

All right. Well, the first thing to remember is static analysis tools they're not magic. You know, they need a little bit of help to know what to look for, and that's where rules come in.

Speaker 1

Rules like a set of instructions that tell the tool you know, hey, this is a potential problem exactly.

Speaker 2

And the cool thing about these rules is you can customize them so you know, they fit your your specific needs how you code. You can define rules to make sure everyone's following coding standards. You can identify common security problems, and you can even model how how you know external libraries behave Oh.

Speaker 1

Okay, so it's not just like one size fits all. You can actually make the analysis specific to your project and environment exactly.

Speaker 2

And one of the one of the most powerful and common types of rules is what we call taint propagation rules.

Speaker 1

Taint propagation Okay, now that that sounds interesting. What's that all about?

Speaker 2

So imagine you're you're tracking a drop of ink as it spreads through water. Yeah, taint propagation rules. They work in a similar way. They let you track how potentially dangerous data or like tainted data moves through your program.

Speaker 1

Okay, So so if you have you know, user input coming into your program, which we know can be a bit unpredictable, you can like tag it as tainted and then see where it goes exactly.

Speaker 2

And if that if that tainted data ends up reaching you know, some sensitive operation like writing to a file or executing a system command. Then the tool can be like, hey, wait a minute, this this might be a problem.

Speaker 1

So, like, if you have tainted data that ends up in a SQL query without being checked properly, that would be a red flag for SQL injection.

Speaker 2

Right, you got it, And that's just one example. Tained propagation rules can be used to find a ton of different vulnerabilities cross sight scripting, command injection, path traversal attacks, you name it.

Speaker 1

Wow, So it's almost like you have a security camera that's following that data around making sure it doesn't end up somewhere it's not supposed to be.

Speaker 2

Yeah, that's a great way to put it. But tained propagation rules there's just one piece of the puzzle. You also have structural rules. These rules they look at the overall structure of your code, so they're looking.

Speaker 1

For patterns that could indicate a vulnerability even if there's no tainted data involved exactly.

Speaker 2

So, for example, a structural rule might flag the use of like a dangerous function like strecb in C that function is notorious for buffer overflows, or you know, it might check to see if you have empty catch blocks in Java, which can actually hide errors and lead to vulnerabilities.

Speaker 1

So it's like having a building inspector come in and make sure the foundation of your code is solid.

Speaker 2

Oh like that analogy, And then you have configuration rules. Those are used to model, you know, how your environment behaves and how external systems work.

Speaker 1

Okay, so if you're using a specific framework or library, you can actually create rules that define how it interacts with your code and what kind of security risks there might be precisely.

Speaker 2

And that helps to make sure that the results you get from your static analysis are tailored to your specific environment and how you code things.

Speaker 1

So we've got all these different kinds of rules working together to give us this comprehensive security analysis. What happens next, Like, once the tool has analyzed all the code, what do we see?

Speaker 2

Well, the tool will generate a report, and that report highlights any potential vulnerabilities. It's dound. But let's be honest, sometimes these reports can be a bit overwhelming, especially for you know, for larger projects.

Speaker 1

Yeah, I can imagine. It's like trying to drink from a fire hose. How do you even start to make sense of it all and figure out what to focus on first.

Speaker 2

That's where a really good static analysis tool, that's where it really shines. A good tool, it'll give you clear, concise reports, it'll highlight the most critical vulnerabilities, and it will help you understand you know, how bad each finding is and what kind of impact it could have.

Speaker 1

So it's not just about giving you a list of problems. It's about giving you some context and some actionable insights exactly.

Speaker 2

The tool should help you understand why a particular piece of code is being flagged. You know, how could it be exploited, what steps can you take to fix it. It might even suggest like specific code changes or best practices to follow.

Speaker 1

So it's almost like having a security expert sitting next to you, walking you through the results and helping you understand what to do next.

Speaker 2

Yeah, that's a great way to think about it. And the more you use these static analysis tools, the better you get at, you know, spotting and fixing potential problems early on in the development process, which can save you a lot of time and headaches later down the road.

Speaker 1

Okay, so let's say we've run our analysis, we've got our report, and we're ready to start, you know, digging in and looking at the findings. What what are some things we should be looking for? What are the key things?

Speaker 2

Okay, well, one of the most important things is to understand how serious each vulnerability is, because you know, not all vulnerabilities are created equal. Some are a lot riskier than others.

Speaker 1

Yeah, that makes sense. Like a buffer overflow that could you know, let someone execute code remotely. That's a much bigger dale than you know, some minor coding style issue. So how do how do we prioritize these findings?

Speaker 2

Most tools use a bunch of factors to assess the severity, you know, like what kind of vulnerability is it, what could the impact be, and how likely is it that someone could actually exploit it. They usually assign each finding a level like critical, high, medium, or low.

Speaker 1

Okay, so you should probably focus on those critical and high ones first, right.

Speaker 2

Absolutely, But you also need to understand the context of each vulnerability. Like a low severity vulnerability in a really critical system I might still need attention, while a high severity vulnerability to the system that's not that important might not be as much of a priority.

Speaker 1

Okay, so severity is important, but we also need to think about the bigger picture. What else should we be looking at.

Speaker 2

You should also pay attention to the confidence level that's assigned to each finding.

Speaker 1

Confidence level, what exactly does that mean?

Speaker 2

It's basically how certain the tool is that the finding is actually a real vulnerability. Static analysis tools are they're really smart, but they're they're not perfect. Okay. Yeah, Sometimes they can flag something as a vulnerability when it's actually not a problem. Those are called false positives.

Speaker 1

So a high confidence finding means it's more likely to be a real vulnerability than a low confidence finding.

Speaker 2

Exactly. And a good tool will give you information to help you decide how much you can trust each finding.

Speaker 1

Okay, so we're looking at severity, context, confidence level, anything else. To keep in mind, you should.

Speaker 2

Also take a look at the recommendations the tool gives you for fixing each vulnerability.

Speaker 1

Oh so, so the tool doesn't just tell you what's wrong, it actually gives you some guidance on how to fix it exactly.

Speaker 2

Yeah, and those recommendations could be anything from like simple code changes to more more complicated architectural modifications.

Speaker 1

Okay, so it's not just leaving you hanging, it's it's giving your roadmap for how to fix things.

Speaker 2

Right. But before you go and start changing your code, it's really important to validate each finding and make sure it's a real vulnerability.

Speaker 1

Ah, So we need to do some manual checking before we start hacking away at our code.

Speaker 2

You got it. Static analysis tools are they're powerful, but they're not perfect. You know. They can have those false positives and sometimes they might even miss real vulnerabilities.

Speaker 1

So even with these really sophisticated tools, we still need to use our own judgment and expertise.

Speaker 2

Absolutely, and that's exactly what we're going to do in the next part of our deep dives. We're going to take all of this knowledge. We're going to analyze some sample code with a real static analysis. Cool.

Speaker 1

Okay, I'm really looking forward to seeing these tools and action. So stay tuned, folks, we'll be right back to explore the world of real world code analysis. Okay, So we've we've talked about all the theory, we've looked at the tools, but now it's time to actually see static analysis in action. You know, roll our sleeves and get our hands a little dirty.

Speaker 2

Absolutely. Yeah, let's dive into some real coat and see what we can find.

Speaker 1

All right, So for this, for this little demonstration, We've got a simple Java web application. It's a it's basically a log in system. But you know, as we all know, even even simple systems can have can have hidden vulnerabilities.

Speaker 2

Oh yeah, definitely. You don't need complexity to have security flaws, that's for sure. So for this deep dive, we're going to be using a pretty popular commercial static analysis tool. It's called Fortify Source Code Analyzer or Fortify s c A.

Speaker 1

For sure SCA. All right, so how does this How does this all work? Do we just like point Fortify at our code and let it do its thing?

Speaker 2

Pretty much? Yeah, We feed the source code into Fortify s c A and then it goes to work. It analyzes the code based on a set of you know, predefined rules and configurations.

Speaker 1

So it's kind of like setting a bloodhound on the trail of a cent, except in this case, the scent is vulnerabilities.

Speaker 2

Huh Yeah, I like that analogy. Fortify SCA sniffs out those weaknesses in the code, and and once the analysis is completed, it gives us a report that highlights any potential issues that is found.

Speaker 1

Okay, all right, so let's see what this security bloodhound can dig up. What kind of vulnerabilities are we are we hoping to find here?

Speaker 2

Well, I mean, based on what we've talked about, SQL injection is always a big concern with with web applications, especially those dealing with you know, user logins.

Speaker 1

Right, sql injection the villain that always seems to come back.

Speaker 2

So let's let's see a fortify s c A can spot any any potential SQL injection vulnerabilities in our login system here? All right, okay, so it looks like fortifyica is found something. It's flagged dis section of code where the where the log in system is building a SQL query using string concatenation.

Speaker 1

Oh okay, that's a that's a classic red flag for SQL injection, right, Like, if you're you're directly putting user input into the query without shading it properly. It's it's basically like leaving the door wide open for an attacker.

Speaker 2

Exactly. Yeah, an attacker could could manipulate that user input, change the SQL query and and potentially gain access to the database.

Speaker 1

Oh that's not.

Speaker 2

Good, not good at all. And uh and that's exactly what fortify s c A is designed to catch. It's it's following that user input or that tainted data as we call it, and it flags any instances where that data reaches you know, sensitive operation, like like a database query.

Speaker 1

So it's like, uh, fortify s c A is playing a game of connect the dots, you know, between the user input put and the and the potential point of attack.

Speaker 2

Yeah, that's a that's a great way to put it. And in this case, it's it's definitely found a potential SQL injection vulnerability.

Speaker 1

Okay, sql injection check. What what else has fortify s c A found.

Speaker 2

It looks like it's also uh flagged a potential cross site scripting.

Speaker 1

Vulnerability right xss. That's where attackers inject malicious code into a website, right, hoping to compromise other users exactly.

Speaker 2

And it looks like in this case, Fortify s c A has found that the log in system is displaying user input without without properly encoding the output.

Speaker 1

So if an attacker were to inject say some some malicious JavaScript code into I don't know, like a username field it, it could potentially be executed in the browser of anyone who who've used that data.

Speaker 2

Exactly, And and fortify s c A is able to find this by by analyzing how that how that data is being handled before it's before it's shown to the user. It's looking for any instances where that that data might be into interpreted as code rather than just plain text.

Speaker 1

So it's not just looking for you know, bad code. It's it's looking for code that that could be misused or misinterpreted in a way that could cause harm exactly.

Speaker 2

It's it's about understanding, you know, what could happen based on how data is handled and displayed within an application.

Speaker 1

Okay, so sql injection, XSS, anything else.

Speaker 2

See, it looks like fortify Sea has has one more trick up its sleeve. It's it's flagged a potential hard coded password vulnerability.

Speaker 1

Oh ouch, Yeah, that's that's definitely a rooky mistake. But you'd be surprised how often it happens.

Speaker 2

You're absolutely right, it happens more often than you'd think. You know, sometimes developers take shortcuts, especially when they're you know, just developing and testing things. They hardcode credentials because it's it's convenient. But you know, as we've talked about, convenience can often come at the cost of security.

Speaker 1

Yeah, for sure, hard coding passwords right into your source code is like it's like taping a spare key to your front door. Anyone who can who can get to that code, Well, they've got your passwords.

Speaker 2

That's that's a great analogy. And fortify s c A can find this kind of vulnerability by by looking for specific patterns in the code, you know, like like strings that that look like passwords or or encryption keys.

Speaker 1

So it's like a it's like fortify c A is a code detective examining every line looking for clues that might might point to a security risk.

Speaker 2

I like that, And and the best part is this is all happening automatically. It's a it's saving us hours and hours of manual code review.

Speaker 1

That's amazing. Okay, so we've got our list of potential vulnerabilities thanks to fortify s c A. What happens next, Well, now it's.

Speaker 2

Time to roll up our sleeves and start fixing these vulnerabilities. Fortify s c A will usually give you some recommendations for for how to fix things. It might suggest some specific code changes or or some security best practices to follow.

Speaker 1

So it's not it's not just pointing fingers, it's actually offering solutions as well.

Speaker 2

Exactly, It's like that that helpful friend who you know, not only points out that you got a stain on your shirt, but also offers to help you clean it up.

Speaker 1

I like that. It's all about, uh, you know, being proactive and addressing these vulnerabilities before before someone else.

Speaker 2

Can exploit them exactly. And and that's that's the power of static analysis. It lets us shift security left. We can catch these problems early on in development when they're when they're easier and cheaper to fix.

Speaker 1

Okay, that makes sense. So as as we wrap up this, uh, this deep dive into secure programming with static analysis, what are some key takeaways for our listener?

Speaker 2

I think the biggest takeaway is that security it's it's not something you add on at the end. It's it's got to be part of the development process from from the very beginning. And static analysis tools like like fortify, s c A, they're they're invaluable in helping us, you know, build more secure and resilient software.

Speaker 1

Absolutely, we've we've seen how these tools can you find hidden vulnerabilities, give us some really actionable insights and even even help us come up with solutions.

Speaker 2

And uh, and remember, you know, the best defense is a good offense. By by being proactive about security and using these these powerful tools, we can stay ahead of, you know, the people who are trying to exploit our systems.

Speaker 1

That's that's great advice. Well, I think that brings our deep dive to a close. Thanks for joining us on this journey. And remember keep learning, keep coding and UH and keep those security flags flying high.

Transcript source: Provided by creator in RSS feed: download file
For the best experience, listen in Metacast app for iOS or Android