Bandit Level 0 → Level 1

Level Goal

The password for the next level is stored in a file called readme located in the home directory. Use this password to log into bandit1 using SSH. Whenever you find a password for a level, use SSH (on port 2220) to log into that level and continue the game.

Commands you may need to solve this level

ls , cd , cat , file , du , find

 

find(1) - Linux manual page

find(1) — Linux manual page FIND(1) General Commands Manual FIND(1) NAME         top find - search for files in a directory hierarchy SYNOPSIS         top find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression] DESCRIPTION

man7.org

 

다음 레벨로 가는 비밀번호는 사용자 홈 디렉토리의 readme 파일에 기재 되어있다. 

다음 사용자는 bandit1이다.

 


readme 파일의 비밀번호와 다음 레벨로 접속하는 ssh

 

참고로 bandit0에서 바로 bandit1로 갈 수 없다 접속 해재 후 다시 badnit1로 접속해야함

비밀번호: NH2SXQwcBdpmTEzi3bvBHMM9H66vVXjL

Level 1->2 GOGO

'WarGame > Bandit WarGame' 카테고리의 다른 글

Bandit WarGame 4 -> 5  (0) 2023.11.10
Bandit WarGame 3 -> 4  (0) 2023.11.10
Bandit WarGame 2->3  (0) 2023.11.10
Bandit WarGame 1->2  (0) 2023.11.10
Bandit WarGame 접속  (0) 2023.11.10

Badnit WarGame 주소

https://overthewire.org/wargames/bandit/bandit0.html

 

OverTheWire: Level Goal

We're hackers, and we are good-looking. We are the 1%. Level Goal The goal of this level is for you to log into the game using SSH. The host to which you need to connect is bandit.labs.overthewire.org, on port 2220. The username is bandit0 and the password

overthewire.org

 

Bandit 사이트

Level 0로 들어가면 접속방법이 기재되어있다.


Level 0

The goal of this level is for you to log into the game using SSH. The host to which you need to connect is bandit.labs.overthewire.org, on port 2220. The username is bandit0 and the password is bandit0. Once logged in, go to the Level 1 page to find out how to beat Level 1.

 

SSH로  bandit.labs.overthewire.org 로 접속 포트는 2220, 사용자 bandit0, 비밀번호 bandit0로 접속

 


PS C:\Users\k> ssh bandit0@bandit.labs.overthewire.org -p 2220

ssh 접속 후 화면

Level0 ->1로 GOGO

'WarGame > Bandit WarGame' 카테고리의 다른 글

Bandit WarGame 4 -> 5  (0) 2023.11.10
Bandit WarGame 3 -> 4  (0) 2023.11.10
Bandit WarGame 2->3  (0) 2023.11.10
Bandit WarGame 1->2  (0) 2023.11.10
Bandit WarGame Level0 -> 1  (0) 2023.11.10

과제 4가지의 로그인 케이스 구현

1. 식별/인증 동시처리: 쿼리로 입력받은 ID, PW 함께 비교

2. 식별/인증 분리처리: 입력받은 ID로 데이터 조회 후 Back-End에서 IF문으로 비밀번호 비교

3. 식별/인증 동시처리 + Hash: 입력받은 PW를 Hash처리하여 쿼리로 ID, PW비교
4. 식별/인증 분리처리 + Hash: 입력받은 ID로 데이터 조회 후 Back-End에서 IF문으로 입력받은 PW를 Hash 처리하여 비교

 


식별/인증 동시처리

register.php( 모든 케이스 동일)

    <?php
      require_once 'db_connection.php';

      $is_id = isset($_POST['id']) && $_POST['id'];
      $is_name = isset($_POST['name']) && $_POST['name'];
      $is_pw = isset($_POST['pw']) && $_POST['pw'];
      $is_submit = isset($_POST['submit']);

      if ($is_name && $is_id && $is_pw && $is_submit) {
        // 모두 입력받았다면 아이디 중복확인.
        $idCount = idCount($_POST['id']);

        if($idCount < 1) {
          $result = register($_POST['id'], $_POST['name'], $_POST['pw']);
          if ($result) {
            echo "<script>alert('회원가입 완료.');
              location.href='/study/w3/case1/login.php'
            </script>";
            exit;
          }
        } 
      }
    ?>

 

 

login.php (모든 케이스 동일)

<?php
        require_once 'db_connection.php';
        ini_set('display_errors', 1);
        
        $is_id = isset($_POST['id']) && $_POST['id'];
        $is_pw = isset($_POST['pw']) && $_POST['pw'];
        $is_submit = isset($_POST['submit']);
           
        if($is_id && $is_pw && $is_submit) {
          // 로그인 로직 처리
          $login_result = login($_POST['id'], $_POST['pw']);
          
          if ($login_result > 0) {
            session_start();
            // echo "userID: {$id}";
            $_SESSION['id'] = $_POST['id'];
            header('Location: /study/w3/case1/index.php');
          }
        }
      ?>

 

db_connection.php

<?php
    ini_set('display_errors', 1);
    define('DB_SERVER', 'localhost');
    define('DB_USERNAME', 'admin');
    define('DB_PASSWORD', 'student1234');
    define('DB_NAME', 'test');
	
    $db_conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
    $db_conn -> set_charset('utf8');
   
   // 중략
   
    function login($id, $pw) {
        global $db_conn;
        
        // sql에서 id, pw 모두 사용
        $sql = "SELECT COUNT(USER_ID) as count 
        FROM user_case1 
        WHERE USER_ID = '{$id}' and PW = '{$pw}'";
	
        $result = mysqli_query($db_conn, $sql);
        $row = mysqli_fetch_array($result);

        return $row['count'];
    }
?>

 

쿼리에서 USER_ID, PW 모두 조건절로 처리하여 count만 반환하여 0보다 크다면 로그인 처리한다.


식별/인증 별도 처리

db_connection.php

<?php
    ini_set('display_errors', 1);
    define('DB_SERVER', 'localhost');
    define('DB_USERNAME', 'admin');
    define('DB_PASSWORD', 'student1234');
    define('DB_NAME', 'test');
	
    $db_conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
    $db_conn -> set_charset('utf8');
  
  	// 중략
  
    function login($id, $pw) {
        global $db_conn;
        $return_val = 0;
        $sql = "SELECT USER_ID AS userId, PW AS pw
        FROM user_case1 
        WHERE USER_ID = '{$id}'";

        $result = mysqli_query($db_conn, $sql);
        $row = mysqli_fetch_array($result);

        if($row && $row['pw'] == $pw) {
            $return_val = 1;
        } 

        return $return_val;
        

    }
?>

 

입력받은 USER_ID를 사용하여 DB에서 USER_ID, PW를 받아 PHP 로직에서 PW를 비교하여 로그인 처리 한다.

 


식별/인증 동시처리 + Hash

db_connection.php

<?php
    // 중략
    
    function register($id, $name, $pw) {
        global $db_conn;
        
        $pw = hash("sha256", $pw);
        $sql = "INSERT INTO user_case3 (USER_ID, USER_NM, PW) VALUE(
            '{$id}'
            , '{$name}'
            , '{$pw}'
        )";

        return mysqli_query($db_conn, $sql);
    }

    function login($id, $pw) {
        global $db_conn;
        $pw = hash("sha256", $pw);
        
        $sql = "SELECT COUNT(USER_ID) as count 
        FROM user_case1 
        WHERE USER_ID = '{$id}' and PW = '{$pw}'";

        $result = mysqli_query($db_conn, $sql);
        $row = mysqli_fetch_array($result);

        return $row['count'];
    }
?>

 

register에서 Insert 하기 전 pw를 Hash 처리한다.

이후 login 시 조건절에 들어갈 pw 또한 해시처리하여 비교한다.

해시처리 된 pw


식별/인증 별처리 + Hash

db_connection.php

<?php
    // 중략
    
    function login($id, $pw) {
        global $db_conn;
        $pw = hash("sha256", $pw);
        $return_val = 0;

        $sql = "SELECT USER_ID AS userId, PW AS pw
        FROM user_case3 
        WHERE USER_ID = '{$id}'";

        $result = mysqli_query($db_conn, $sql);
        $row = mysqli_fetch_array($result);

        if($row && $row['pw'] == $pw) {
            $return_val = 1;
        } 

        return $return_val;
    }
?>

 

Case2와 동일하지만 DB에서 가져온 PW는 Hash처리가 되어 있기 때문에 파라미터로 받는 $pw를 Hash처리하여 if문에서 비교한다.

식별/인증

식별: 수 많은 사용자 데이터 중 1개의 사용자를 특정(ID)
인증: 식별한 사용자가 실제 그 사용자가 맞는지 확인(PW)

식별정보: 로그인에서 ID가 식별정보이며 식별정보는 특정 1명의 사용자를 찾을 수 있어야하므로 유니크해야 한다.
인증정보: 로그인 시도한 사용자가 정말 그 사용자인지 확인하기 위해 사용자만 알 수 있는 값을 받아야한다 (PW)


Hash

Hash는 단방향 암호화 로직으로 (A ===HASH 처리 ===> B) 가능하지만 ( A <========= B)가 불가능하다
이러한 특징을 가지고 있기 때문에 BD가 탈취되어도 평문을 알 수 없다.

로그인 시 입력받은 비밀번호를 Hash처리하여 DB에 저장된 값과 비교만 하면되기 때문에 사용자의 비밀번호를 알 필요가 없다.


로그인 로직 방법들

  1. 식별/인증 동시처리: DB에서 동시에 식별정보 and 인증정보를 조회한다.
  2. 식별/인증 별도처리: DB에서 식별정보를 조회 후 Back-End의 if문으로 확인한다.
  3. 식별/인증 동시처리 + Hash : DB에 입력된 PW는 해쉬 처리가 되어 있으며 쿼리의 조건문에도 해쉬처리된 데이터로 조회한다.
  4. 식별/인증 별도처리 + Hash : DB에 입력된 PW는 해쉬 처리가 되어 있으며 비교는 Back-End의 로직에서 확인한다.

로그인의 유지

  • 쿠키: Client에 저장되며 데이터 요청시 전달하여 사용 Ex) setcookie(useId, 김만기)
    클라이언트에 저장되는 값으로 변조가 쉽다.
  • 세션: 쿠키와 다르게 데이터의 값은 Server의 파일로 저장되며 Client는 Cookie에 SessionId를 보내어 사용자를 특정하고 해당 사용자의 정보를 확인 할 있다.

HTTP의 특징

Stateless

Http는 무상태성(Stateless)로 Server와 Client가 항시 연결되어 있는 상태가 아니다. 요청한 데이터에 대한 응답을 전달하게 되면 연결이 끊어지는 방식으로 이전에 어떠한 요청을 했는지 알 수 없다.

 

이러한 Stateless의 특성을 가지고 있기 때문에 Cookie, Session_id 혹은 JWT와 같은 로그인 한 사용자라는 것을 증명 할 수 있는 데이터를 요청시마다 전달해야한다.

'웹 해킹 코스 > 내용 정리' 카테고리의 다른 글

5주차 SQL Ijection  (2) 2023.11.26
4주차 (burp suitte)  (0) 2023.11.15
2주차 (DB)  (0) 2023.11.01
0주차 (리눅스 기초 명령어)  (2) 2023.10.26
1주차(WEB, WAS, IP, NAT)  (0) 2023.10.26

+ Recent posts