0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DVWA(weak-session-id)全レベルの脆弱性について

Posted at

前提

目標

  • 脆弱性の理解を深める。

手順概要

  • 挙動を把握する
  • コードを見て脆弱性を理解する

内容

###挙動の把握

low

  • generateした結果を以下に示す。
  • 容易に推測できる。。。
session:1
session:2
session:3
etc...

medium

session:1584112966
session:1584112969
session:1584112974
etc...

high

session:c4ca4238a0b923820dcc509a6f75849b
session:c81e728d9d4c2f636f067f89cc14862c
session:eccbc87e4b5ce2fe28308fd9f2a7baf3

etc...

コードを確認

low

<?php
    if (!isset ($_SESSION['last_session_id'])) {
        $_SESSION['last_session_id'] = 0;
    }
    $_SESSION['last_session_id']++;
    $cookie_value = $_SESSION['last_session_id']; 
?> 

medium

<?php
    $cookie_value = time();
    setcookie("dvwaSession", $cookie_value); 
?> 

high

<?php
    if (!isset ($_SESSION['last_session_id_high'])) {
        $_SESSION['last_session_id_high'] = 0;
    }
    $_SESSION['last_session_id_high']++;
    $cookie_value = md5($_SESSION['last_session_id_high']); 
?>

impossible

  • sha1はMd5の4倍の長さがある暗号キー。とはいえ逆変換ツールはあるので完全ではない
  • この場合、mt_rand()の全パターンを1秒間隔で送り込めば解読も不可能ではないが、一般人の悪ガキは諦めてくれるセキュリティはある
  • 後、setcookieのsecureを有効にしている
<?php
$cookie_value = sha1(mt_rand() . time() . "Impossible"); 
setcookie("dvwaSession", $cookie_value, time()+3600, "/vulnerabilities/weak_id/", $_SERVER['HTTP_HOST'], true, true); 
?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?