B20の自己推薦で配属されたy_takaya(高谷)です。
本日より「春のAdventCalendar2020」と称して、B20生がバトンリレーで記事を投稿していきます!
初日は学年リーダ(らしい)の私からです。
本日私が紹介するのは、誰でも単語は聞いたことあるだろう「PHP」についてです。
PHPは「Personal Home Page tools」の略だかと言われています。
私はPHPをプログラミング初心者であるあなたにおすすめしたいです。
PHPのメリットはWebとの親和性の高さ、データベースとの接続の容易さだと思っています。
他にもPHPはコンパイルする必要がないため、アイデアをすぐに反映しやすいところもメリットだと思っています。
導入
懇切丁寧に書いてましたが、自分の環境に合わせてどこかのQiitaを見ながら導入した方が確実だと思ったので割愛しました。セキュリティ対策
ということで今回私が解説するのはセキュリティ対策についてです。
セッション固定化攻撃を防ぐ
URIによるセッション管理を禁止して、セッションIDを変更します。攻撃者がセッションIDを指定してしまう攻撃で、PHP5.3以前では簡単な形式チェックのみでしたので受け入れられてしまいました。
対策として、URIによるセッション管理を禁止します。
```php.ini
session.use_only_cookies = 1
```
そして、セッションIDは定期的にリジェネレートしましょう。
session_start()関数でセッションを開始した後に、リジェネレートを行うには次の関数を呼び出します。
```
session.regenerate_id(TRUE);
```
引数は、リジェネレート前のセッションIDを削除するかどうかです。削除しましょう。意味がなくなります。
SQLインジェクション対策
SQLインジェクションとは意図しないSQL文を実行させる攻撃です。
例えば、ログインフォームなどで、ログインIDとパスワードを入力してログインをします。
ここで対策を行なっていないと、ユーザ名に「username' --」のように入力した時に、パスワードの入力なしで通ってしまう可能性があります。
これはSQLのコメントアウト(--)を利用した抜け穴ですね。
この時実行されるSQL文はこうなります。
```SQL
SELECT * FROM user WHERE user='username' -- 'AND password=''
```
これをさせないために行うのが、プリペアドステートメントです。
プリペアドステートメントは、複数のデータを一括登録する場合に、用いるSQL文は同じで、データのみが異なる場合に用いるものです。
SQL文の実行に先立って、SQL文の構文解析、コンパイル、最適化が行われ、未対策の時からセキュリティ性が向上するだけではなく、処理速度も早くなることもあります。
ここでは、最初にSQL文を準備します。そしてデータ部分には「?」を入れましょう。
```SQL
SELECT * FROM user WHERE user=? AND password=?
```
次に、?への割り当てを行います。
```PHP
if ($stmt = mysqli_prepare($link, $sql)) {
// 変数のバインド。変数の型がどちらもs(string)であることを記述する
mysql_stmt_bind_param($stmt, 'ss', $_POST['id'], $_POST['password']);
// クエリの実行
mysqli_stmt_execute($stmt);
// リザルトの転送
mysqli_stmt_store_result($stmt);
}
```
私はPDOを使用しているので、次みたくしてます。
```PHP
$stmt = $pdo->prepare("INSERT INTO user(user, password ) VALUES (?, ?)");
$stmt->execute(array($_POST['id'], $_POST['password']));
```
または
```PHP
$stmt = $pdo->prepare("INSERT INTO user(user, password ) VALUES (:user, :password)");
$stmt->bindParam(':user', $_POST['id']);
$stmt->bindParam(':password', $_POST['password']);
$stmt->execute();
```
楽しくなって来ちゃいましたね。
NULLバイト攻撃
NULLバイトを使ってプログラムを誤作動させる攻撃です。NULLバイトは「¥x00や¥0」のことで、文字列の終端と判断してしまう関数が存在します。
例えば正規表現を行う場合にバイナリセーフでないereg()関数を使ってしまうと、URIのファイルの後に「?u=+x-///」と入力することによって、「」以降の正規表現をチェックしません。
あんまりない気がする(個人では対策したことない)実装ですが、調べると他にも色々な対策方法が出てきます。
とくにPHPはバージョンによって様々な脆弱性の対策が施されてきています。
もしかしたら、今紹介した中でも、わざわざ対策する必要がないものを出てくるのではないかと考えています。
ぜひ、参考にしてみてください。
Such a cool and creative game. Awesome work. slope unblocked game on here so great.
返信削除You present a very well-written article and with some awesome information which is very helpful, like me as reader. Thanks for sharing it and also please visit our great site below.
返信削除고스톱
PHP is just as safe as any other major programming language. You may develop insecure code in PHP, but that's a fundamental problem in every single programming language," he emphasises, but that's a fundamental problem in every single programming language.
返信削除Source: nicholasmathiou
このコメントは投稿者によって削除されました。
返信削除
返信削除Welcome to the McDonald's Customer Survey on McDVOICE.com. you have the enter a 26-digit McDVoice survey code and win Free Food Coupons. McDVoice survey
Very nice article and straight to the point. Keep it up, Thank you.
返信削除바카라사이트
카지노사이트
온라인카지노
I truly loved browsing this blog posts. Wonderful! Thanks
返信削除온라인카지노
바카라사이트
카지노사이트
온라인카지노
PHP code may be completely safe. mcdvoice
返信削除I stumbled onto your essay not too long ago and have been enjoying it ever since. I just wanted to say how much I respect your talent as a writer and how impressed I am by how committed your readers seem to be to seeing this story through to the end. I'm interested in commenting on recent postings and reading what you have to say. the backrooms
返信削除MyTranslationServices.com takes pride in offering top-notch medical records translation services in the UK. Our team of professional medical record translators in UK combines language proficiency with extensive knowledge of the healthcare field. Whether you need translations for patient histories, medical reports, or any other medical records, we have the expertise to handle it all. With our attention to detail and commitment to delivering accurate translations, you can trust us to provide reliable language solutions for your medical documentation requirements in the UK.
返信削除Thanks for sharing the information keep updating, looking forward to more post. Nice post ! I love its your site after reading! thanks for sharing. awesome information which is very helpful, like me as reader. Thanks for sharing it and also please visit our great site below.
返信削除can a protection order be dropped in virginia
domestic violence protective order virginia
Your article is exceptionally well-written, packed with awesome and helpful information for readers like me. Thank you for sharing it, and I kindly request you to explore our Natural Health Products as well.
返信削除Your article is very help full for us. I need Property for sale in JVC
返信削除can someone help me in professionally.
I just wanted to express how much I like your writing talent and how moved I am by how devoted your readers appear to following this narrative to its conclusion How to Create a Wikipedia Page for Someone.
返信削除I ordered this jacket from America Jackets and I must say I am amazed with the high quality and fit. You guys can also try it. Zombieland Tallahassee Snakeskin Jacket
返信削除Gemini Login is a simple, quick, and safe platform that allows you to build your cryptocurrency portfolio.
返信削除
返信削除"Keep up the good work! I can't wait to read more from your blog."New York State Legal Separation Vs Divorce
"3 Security Measures for PHP" emphasizes the importance of using prepared statements for database interactions, input validation and sanitization, and regular software updates. These measures help prevent SQL injection attacks, a common threat in web applications, and safeguard sensitive data. The article also highlights the importance of regular software updates, as outdated software can have vulnerabilities that attackers can exploit. Regular updates are a proactive way to enhance the security of PHP applications, as they help prevent vulnerabilities that attackers can exploit. Overall, the security measures outlined in the article are crucial for PHP developers to implement, addressing key areas of concern such as database security, input handling, and software maintenance, which are essential for ensuring the resilience of PHP-based web applications against various security threats.estate planning lawyer Fairfax VA
返信削除