SCW Icons
hero bg no divider
Blog

コーダーがセキュリティを征服する:共有と学習シリーズ-コード・インジェクション

ヤープ・キャラン・シン
Published May 16, 2019
Last updated on Mar 10, 2026

Code injection attacks are among the most common, and also the most dangerous, that many websites and applications will encounter. They run the gamut both in terms of sophistication and in the danger that they pose, but nearly any site or app that accepts user input could be vulnerable. In fact, this kind of attack is one that almost every cybersecurity defender will need to deal with at some point in their career, and will probably grapple with it multiple times.

A code injection attack can occur whenever an application or website accepts input from users. This can be as simple as providing a search function or asking a user to enter their identification information. The attack happens when a malicious user enters code into the open field instead of normal text input. Their goal is to have the server mistake the input for valid code, and then execute whatever functions the attacker desires.

While code injection attacks are extremely common, so are the available defenses that can be used to stop them. In this episode, we will learn:

  • How they work
  • Why they are so dangerous
  • How you can put defenses in place to stop them.

How do Attackers Use Code Injection?

Although the specific details about code injection attacks change depending on the programming language used, any app or website can be vulnerable so long as it allows a user to input data. Code injection attacks have been triggered for SQL, HTML, XML, CSS and every other common programming language.

First, an attacker must locate vulnerable code within an application, normally at a point where users are allowed to enter their own input. For example, this code takes the PHP eval() function and passes it along to a user to modify, without any sort of validation of the return string.

$myvar = "varname";
$x = $_GET[arg];
eval("\$myvar = \$x;");

A clever attacker could easily add their own string to the eval function, even executing system commands if they choose.

/index.php?arg=1; system(id)

It's important to note that while code injection attacks can involve sending system commands, they are not restricted to just doing that. In fact, with code injection attacks, hackers are only limited by the functionality of the language itself. In our example, an attacker could program the targeted system to do almost anything allowed by the PHP framework.

Why are Code Injection Attacks so Dangerous?

Code injection attacks are potentially extremely dangerous depending on the skill of the attacker. They can do anything that the programming language allows, which puts them on the same footing as the app's programmers. An attacker could practically write their own app and have it executed within the target environment.

Even less skilled attackers can be dangerous. Instead of writing their own application or code strings, they can simply order the targeted system to accept and install pre-programmed malware. This could lead to site defacement, ransomware attacks or even become the basis for a phishing campaign leveled against the site's users.

Most of the time, code injection attacks are used to steal things like user lists and passwords, or to gain valuable reconnaissance into a system targeted for further compromise. But be warned, a skilled coder can do almost anything with a code injection attack, which is why it's critical that every potential instance of them are discovered and removed from your environment.

Trust No-One! (Or At Least, Not Users)

When eliminating code injection attack vulnerabilities, the first place to look is anywhere that asks for, or allows, user input. Anything inputted by a user is not to be trusted under any circumstances. If you allow user input without filtering or examination, you are basically inviting attackers to take a free shot at compromising your system or even your network.

Although it is not always possible, the best way to thwart code injection attacks is to prevent functions from executing or interpreting user input directly. Perhaps users can be given a choice of static options instead of free reign to enter their own queries, with the application programmed to only accept those limited choices as valid. It may not always be appropriate to do that, but using it where possible can eliminate code injections before they start.

For areas where users need to enter their own input, tight controls must be placed on that data. Assuming everything is a potential attack is a good place to start. Enforcing least privilege policies such as read-only user access, on both the client and server side, can prevent most code from executing.

The other good defense is to implement application-wide filters and sanitization on everything any user inputs. Developers have been aware of code injection attacks for years, and libraries of proven filters exist for every framework and language. When applying those filters, be sure to do so not just on the obvious user input areas or against common parameters like Get and Post commands, but also against cookies and HTTP headers.

Applying a Correction for Code Injection

Removing unnecessary user input areas from your environment, enforcing least privilege principles and using the latest filtering and sanitization tools to inspect and detect potential attacks can shut the door on this dangerous vulnerability. Having the mindset of never trusting user input will also serve you well moving forward. Do all that, and you can stay one step ahead of this dangerous type of attack.

For further reading, you can take a look at the OWASP write-up on code injection. You can also put your newfound defensive knowledge to the test with the free demo of the Secure Code Warrior platform, which trains cybersecurity teams to become the ultimate cyber warriors. To learn more about defeating this vulnerability, and a rogues'gallery of other threats, visit the Secure Code Warrior blog.

Face code injection head-on, right now. Take the challenge on our gamified training platform: [Start Here]

リソースを表示
リソースを表示

コードインジェクション攻撃は、多くの Web サイトやアプリケーションが遭遇する最も一般的で最も危険なものの 1 つです。攻撃は、巧妙さという点でも危険性という点でも多岐にわたりますが、ユーザー入力を受け入れるほとんどすべてのサイトやアプリが脆弱になる可能性があります。

もっと興味がありますか?

Jaap Karan Singhは、セキュア・コーディング・エバンジェリストであり、チーフ・シンであり、セキュア・コード・ウォリアーの共同創設者です。

learn more

Secure Code Warriorは、ソフトウェア開発ライフサイクル全体にわたってコードを保護し、サイバーセキュリティを最優先とする文化を築くお手伝いをします。アプリケーションセキュリティマネージャ、開発者、CISO、またはセキュリティ関係者のいずれであっても、安全でないコードに関連するリスクを軽減するお手伝いをします。

デモを予約
シェア:
linkedin brandsSocialx logo
著者
ヤープ・キャラン・シン
Published May 16, 2019

Jaap Karan Singhは、セキュア・コーディング・エバンジェリストであり、チーフ・シンであり、セキュア・コード・ウォリアーの共同創設者です。

シェア:
linkedin brandsSocialx logo

Code injection attacks are among the most common, and also the most dangerous, that many websites and applications will encounter. They run the gamut both in terms of sophistication and in the danger that they pose, but nearly any site or app that accepts user input could be vulnerable. In fact, this kind of attack is one that almost every cybersecurity defender will need to deal with at some point in their career, and will probably grapple with it multiple times.

A code injection attack can occur whenever an application or website accepts input from users. This can be as simple as providing a search function or asking a user to enter their identification information. The attack happens when a malicious user enters code into the open field instead of normal text input. Their goal is to have the server mistake the input for valid code, and then execute whatever functions the attacker desires.

While code injection attacks are extremely common, so are the available defenses that can be used to stop them. In this episode, we will learn:

  • How they work
  • Why they are so dangerous
  • How you can put defenses in place to stop them.

How do Attackers Use Code Injection?

Although the specific details about code injection attacks change depending on the programming language used, any app or website can be vulnerable so long as it allows a user to input data. Code injection attacks have been triggered for SQL, HTML, XML, CSS and every other common programming language.

First, an attacker must locate vulnerable code within an application, normally at a point where users are allowed to enter their own input. For example, this code takes the PHP eval() function and passes it along to a user to modify, without any sort of validation of the return string.

$myvar = "varname";
$x = $_GET[arg];
eval("\$myvar = \$x;");

A clever attacker could easily add their own string to the eval function, even executing system commands if they choose.

/index.php?arg=1; system(id)

It's important to note that while code injection attacks can involve sending system commands, they are not restricted to just doing that. In fact, with code injection attacks, hackers are only limited by the functionality of the language itself. In our example, an attacker could program the targeted system to do almost anything allowed by the PHP framework.

Why are Code Injection Attacks so Dangerous?

Code injection attacks are potentially extremely dangerous depending on the skill of the attacker. They can do anything that the programming language allows, which puts them on the same footing as the app's programmers. An attacker could practically write their own app and have it executed within the target environment.

Even less skilled attackers can be dangerous. Instead of writing their own application or code strings, they can simply order the targeted system to accept and install pre-programmed malware. This could lead to site defacement, ransomware attacks or even become the basis for a phishing campaign leveled against the site's users.

Most of the time, code injection attacks are used to steal things like user lists and passwords, or to gain valuable reconnaissance into a system targeted for further compromise. But be warned, a skilled coder can do almost anything with a code injection attack, which is why it's critical that every potential instance of them are discovered and removed from your environment.

Trust No-One! (Or At Least, Not Users)

When eliminating code injection attack vulnerabilities, the first place to look is anywhere that asks for, or allows, user input. Anything inputted by a user is not to be trusted under any circumstances. If you allow user input without filtering or examination, you are basically inviting attackers to take a free shot at compromising your system or even your network.

Although it is not always possible, the best way to thwart code injection attacks is to prevent functions from executing or interpreting user input directly. Perhaps users can be given a choice of static options instead of free reign to enter their own queries, with the application programmed to only accept those limited choices as valid. It may not always be appropriate to do that, but using it where possible can eliminate code injections before they start.

For areas where users need to enter their own input, tight controls must be placed on that data. Assuming everything is a potential attack is a good place to start. Enforcing least privilege policies such as read-only user access, on both the client and server side, can prevent most code from executing.

The other good defense is to implement application-wide filters and sanitization on everything any user inputs. Developers have been aware of code injection attacks for years, and libraries of proven filters exist for every framework and language. When applying those filters, be sure to do so not just on the obvious user input areas or against common parameters like Get and Post commands, but also against cookies and HTTP headers.

Applying a Correction for Code Injection

Removing unnecessary user input areas from your environment, enforcing least privilege principles and using the latest filtering and sanitization tools to inspect and detect potential attacks can shut the door on this dangerous vulnerability. Having the mindset of never trusting user input will also serve you well moving forward. Do all that, and you can stay one step ahead of this dangerous type of attack.

For further reading, you can take a look at the OWASP write-up on code injection. You can also put your newfound defensive knowledge to the test with the free demo of the Secure Code Warrior platform, which trains cybersecurity teams to become the ultimate cyber warriors. To learn more about defeating this vulnerability, and a rogues'gallery of other threats, visit the Secure Code Warrior blog.

Face code injection head-on, right now. Take the challenge on our gamified training platform: [Start Here]

リソースを表示
リソースを表示

レポートをダウンロードするには、以下のフォームに記入してください

当社の製品および/または関連するセキュアコーディングのトピックに関する情報を送信する許可をお願いします。当社は、お客様の個人情報を常に細心の注意を払って取り扱い、マーケティング目的で他社に販売することは決してありません。

送信
scw success icon
scw error icon
フォームを送信するには、「アナリティクス」クッキーを有効にしてください。設定が完了したら、再度無効にしても構いません。

Code injection attacks are among the most common, and also the most dangerous, that many websites and applications will encounter. They run the gamut both in terms of sophistication and in the danger that they pose, but nearly any site or app that accepts user input could be vulnerable. In fact, this kind of attack is one that almost every cybersecurity defender will need to deal with at some point in their career, and will probably grapple with it multiple times.

A code injection attack can occur whenever an application or website accepts input from users. This can be as simple as providing a search function or asking a user to enter their identification information. The attack happens when a malicious user enters code into the open field instead of normal text input. Their goal is to have the server mistake the input for valid code, and then execute whatever functions the attacker desires.

While code injection attacks are extremely common, so are the available defenses that can be used to stop them. In this episode, we will learn:

  • How they work
  • Why they are so dangerous
  • How you can put defenses in place to stop them.

How do Attackers Use Code Injection?

Although the specific details about code injection attacks change depending on the programming language used, any app or website can be vulnerable so long as it allows a user to input data. Code injection attacks have been triggered for SQL, HTML, XML, CSS and every other common programming language.

First, an attacker must locate vulnerable code within an application, normally at a point where users are allowed to enter their own input. For example, this code takes the PHP eval() function and passes it along to a user to modify, without any sort of validation of the return string.

$myvar = "varname";
$x = $_GET[arg];
eval("\$myvar = \$x;");

A clever attacker could easily add their own string to the eval function, even executing system commands if they choose.

/index.php?arg=1; system(id)

It's important to note that while code injection attacks can involve sending system commands, they are not restricted to just doing that. In fact, with code injection attacks, hackers are only limited by the functionality of the language itself. In our example, an attacker could program the targeted system to do almost anything allowed by the PHP framework.

Why are Code Injection Attacks so Dangerous?

Code injection attacks are potentially extremely dangerous depending on the skill of the attacker. They can do anything that the programming language allows, which puts them on the same footing as the app's programmers. An attacker could practically write their own app and have it executed within the target environment.

Even less skilled attackers can be dangerous. Instead of writing their own application or code strings, they can simply order the targeted system to accept and install pre-programmed malware. This could lead to site defacement, ransomware attacks or even become the basis for a phishing campaign leveled against the site's users.

Most of the time, code injection attacks are used to steal things like user lists and passwords, or to gain valuable reconnaissance into a system targeted for further compromise. But be warned, a skilled coder can do almost anything with a code injection attack, which is why it's critical that every potential instance of them are discovered and removed from your environment.

Trust No-One! (Or At Least, Not Users)

When eliminating code injection attack vulnerabilities, the first place to look is anywhere that asks for, or allows, user input. Anything inputted by a user is not to be trusted under any circumstances. If you allow user input without filtering or examination, you are basically inviting attackers to take a free shot at compromising your system or even your network.

Although it is not always possible, the best way to thwart code injection attacks is to prevent functions from executing or interpreting user input directly. Perhaps users can be given a choice of static options instead of free reign to enter their own queries, with the application programmed to only accept those limited choices as valid. It may not always be appropriate to do that, but using it where possible can eliminate code injections before they start.

For areas where users need to enter their own input, tight controls must be placed on that data. Assuming everything is a potential attack is a good place to start. Enforcing least privilege policies such as read-only user access, on both the client and server side, can prevent most code from executing.

The other good defense is to implement application-wide filters and sanitization on everything any user inputs. Developers have been aware of code injection attacks for years, and libraries of proven filters exist for every framework and language. When applying those filters, be sure to do so not just on the obvious user input areas or against common parameters like Get and Post commands, but also against cookies and HTTP headers.

Applying a Correction for Code Injection

Removing unnecessary user input areas from your environment, enforcing least privilege principles and using the latest filtering and sanitization tools to inspect and detect potential attacks can shut the door on this dangerous vulnerability. Having the mindset of never trusting user input will also serve you well moving forward. Do all that, and you can stay one step ahead of this dangerous type of attack.

For further reading, you can take a look at the OWASP write-up on code injection. You can also put your newfound defensive knowledge to the test with the free demo of the Secure Code Warrior platform, which trains cybersecurity teams to become the ultimate cyber warriors. To learn more about defeating this vulnerability, and a rogues'gallery of other threats, visit the Secure Code Warrior blog.

Face code injection head-on, right now. Take the challenge on our gamified training platform: [Start Here]

オンラインセミナーを見る
始めよう
learn more

以下のリンクをクリックして、このリソースのPDFをダウンロードしてください。

Secure Code Warriorは、ソフトウェア開発ライフサイクル全体にわたってコードを保護し、サイバーセキュリティを最優先とする文化を築くお手伝いをします。アプリケーションセキュリティマネージャ、開発者、CISO、またはセキュリティ関係者のいずれであっても、安全でないコードに関連するリスクを軽減するお手伝いをします。

レポートを表示デモを予約
PDF をダウンロード
リソースを表示
シェア:
linkedin brandsSocialx logo
もっと興味がありますか?

シェア:
linkedin brandsSocialx logo
著者
ヤープ・キャラン・シン
Published May 16, 2019

Jaap Karan Singhは、セキュア・コーディング・エバンジェリストであり、チーフ・シンであり、セキュア・コード・ウォリアーの共同創設者です。

シェア:
linkedin brandsSocialx logo

Code injection attacks are among the most common, and also the most dangerous, that many websites and applications will encounter. They run the gamut both in terms of sophistication and in the danger that they pose, but nearly any site or app that accepts user input could be vulnerable. In fact, this kind of attack is one that almost every cybersecurity defender will need to deal with at some point in their career, and will probably grapple with it multiple times.

A code injection attack can occur whenever an application or website accepts input from users. This can be as simple as providing a search function or asking a user to enter their identification information. The attack happens when a malicious user enters code into the open field instead of normal text input. Their goal is to have the server mistake the input for valid code, and then execute whatever functions the attacker desires.

While code injection attacks are extremely common, so are the available defenses that can be used to stop them. In this episode, we will learn:

  • How they work
  • Why they are so dangerous
  • How you can put defenses in place to stop them.

How do Attackers Use Code Injection?

Although the specific details about code injection attacks change depending on the programming language used, any app or website can be vulnerable so long as it allows a user to input data. Code injection attacks have been triggered for SQL, HTML, XML, CSS and every other common programming language.

First, an attacker must locate vulnerable code within an application, normally at a point where users are allowed to enter their own input. For example, this code takes the PHP eval() function and passes it along to a user to modify, without any sort of validation of the return string.

$myvar = "varname";
$x = $_GET[arg];
eval("\$myvar = \$x;");

A clever attacker could easily add their own string to the eval function, even executing system commands if they choose.

/index.php?arg=1; system(id)

It's important to note that while code injection attacks can involve sending system commands, they are not restricted to just doing that. In fact, with code injection attacks, hackers are only limited by the functionality of the language itself. In our example, an attacker could program the targeted system to do almost anything allowed by the PHP framework.

Why are Code Injection Attacks so Dangerous?

Code injection attacks are potentially extremely dangerous depending on the skill of the attacker. They can do anything that the programming language allows, which puts them on the same footing as the app's programmers. An attacker could practically write their own app and have it executed within the target environment.

Even less skilled attackers can be dangerous. Instead of writing their own application or code strings, they can simply order the targeted system to accept and install pre-programmed malware. This could lead to site defacement, ransomware attacks or even become the basis for a phishing campaign leveled against the site's users.

Most of the time, code injection attacks are used to steal things like user lists and passwords, or to gain valuable reconnaissance into a system targeted for further compromise. But be warned, a skilled coder can do almost anything with a code injection attack, which is why it's critical that every potential instance of them are discovered and removed from your environment.

Trust No-One! (Or At Least, Not Users)

When eliminating code injection attack vulnerabilities, the first place to look is anywhere that asks for, or allows, user input. Anything inputted by a user is not to be trusted under any circumstances. If you allow user input without filtering or examination, you are basically inviting attackers to take a free shot at compromising your system or even your network.

Although it is not always possible, the best way to thwart code injection attacks is to prevent functions from executing or interpreting user input directly. Perhaps users can be given a choice of static options instead of free reign to enter their own queries, with the application programmed to only accept those limited choices as valid. It may not always be appropriate to do that, but using it where possible can eliminate code injections before they start.

For areas where users need to enter their own input, tight controls must be placed on that data. Assuming everything is a potential attack is a good place to start. Enforcing least privilege policies such as read-only user access, on both the client and server side, can prevent most code from executing.

The other good defense is to implement application-wide filters and sanitization on everything any user inputs. Developers have been aware of code injection attacks for years, and libraries of proven filters exist for every framework and language. When applying those filters, be sure to do so not just on the obvious user input areas or against common parameters like Get and Post commands, but also against cookies and HTTP headers.

Applying a Correction for Code Injection

Removing unnecessary user input areas from your environment, enforcing least privilege principles and using the latest filtering and sanitization tools to inspect and detect potential attacks can shut the door on this dangerous vulnerability. Having the mindset of never trusting user input will also serve you well moving forward. Do all that, and you can stay one step ahead of this dangerous type of attack.

For further reading, you can take a look at the OWASP write-up on code injection. You can also put your newfound defensive knowledge to the test with the free demo of the Secure Code Warrior platform, which trains cybersecurity teams to become the ultimate cyber warriors. To learn more about defeating this vulnerability, and a rogues'gallery of other threats, visit the Secure Code Warrior blog.

Face code injection head-on, right now. Take the challenge on our gamified training platform: [Start Here]

目次

PDF をダウンロード
リソースを表示
もっと興味がありますか?

Jaap Karan Singhは、セキュア・コーディング・エバンジェリストであり、チーフ・シンであり、セキュア・コード・ウォリアーの共同創設者です。

learn more

Secure Code Warriorは、ソフトウェア開発ライフサイクル全体にわたってコードを保護し、サイバーセキュリティを最優先とする文化を築くお手伝いをします。アプリケーションセキュリティマネージャ、開発者、CISO、またはセキュリティ関係者のいずれであっても、安全でないコードに関連するリスクを軽減するお手伝いをします。

デモを予約[ダウンロード]
シェア:
linkedin brandsSocialx logo
リソースハブ

始めるためのリソース

その他の投稿
リソースハブ

始めるためのリソース

その他の投稿