Weaseling in with Weevely

Weevely creates a PHP backdoor on webservers running PHP. It is pretty straightforward to use, and pretty easy to get onto a webserver. You get to it through Applications | PostExploitation | Weevely:

Weaseling in with Weevely

When you first launch Weevely from the menu, it opens a terminal window and gently chides you about using the script improperly:

Weaseling in with Weevely

This is actually a more helpful doc string than the weevely --help command gives:

Weaseling in with Weevely

We know now that we can generate an agent, which can be dropped on a webserver. We can run a terminal to the target, and we can load an existing session file.

Weevely is a Python script, and there are a couple of improvements you will have to make to Python to use Weevely:

If you get in a hurry and skip this step, you might get the following error message:

Preparing to use Weevely

To create an agent, all we have to do is decide on an innocuous name, and a password:

Creating an agent

We save malware files in their own folder in the Kali /root/ directory, so we can find them again when needed. A better name for this directory might be as follows:

Creating an agent

Weevely is cross-platform, and should work wherever you are serving PHP pages. Here's an example of running Weevely against a webserver on the Kali Linux host:

Testing Weevely locally

It is just as simple to test Weevely on a Windows server if the Windows server is running PHP – for instance, if it is a web server running WordPress or some other PHP-based script. The server we are using for this test is Windows Server 2012 with PHP running. If you were just inside the Windows server using Metasploit, it is possible to drop our metrics01.php file, made by Weevely, into the webroot folder:

Testing Weevely on a Windows server

Once you have the file in place, you can do a lot of things with it. We have chosen just a few actions, though there are fifty commands you might be able to do. First, you contact your agent by using the following code:

The same kind of entry success output appears as when we tested it on the Kali webserver:

Testing Weevely on a Windows server

To find out what Weevely can do, we will run the help command to see what is available for you to run on the Windows server:

The help file reads out as in the following table. Note that there is a colon ":" at the beginning of each of the commands:

Command

Description

:audit_suidsgid

Find files with SUID or SGID flags.

:audit_phpconf

Audit PHP configuration.

:audit_etcpasswd

Get /etc/passwd with different techniques.

:audit_filesystem

Audit system files for wrong permissions.

:shell_php

Execute PHP commands.

:shell_sh

Execute Shell commands.

:shell_su

Elevate privileges with su command.

:system_extensions

Collect PHP and webserver extension list.

:system_info

Collect system information.

:backdoor_reversetcp

Execute a reverse TCP shell.

:backdoor_tcp

Spawn a shell on a TCP port.

:bruteforce_sql

Brute-force SQL database.

:file_cd

Change current working directory.

:file_grep

Print lines matching a pattern in multiple files.

:file_find

Find files with given names and attributes.

:file_rm

Remove remote file.

:file_cp

Copy single file.

:file_zip

Compress or expand zip files.

:file_enum

Check existence and permissions of a list of paths.

:file_check

Get remote file information.

:file_edit

Edit remote file on a local editor.

:file_upload2web

Upload file automatically to a web folder and get corresponding URL.

:file_gzip

Compress or expand gzip files.

:file_download

Download file to remote filesystem.

:file_touch

Change file timestamp.

:file_webdownload

Download URL to the filesystem.

:file_ls

List directory content.

:file_read

Read remote file from the remote filesystem.

:file_mount

Mount remote filesystem using HTTPfs.

:file_bzip2

Compress or expand bzip2 files.

:file_tar

Compress or expand tar archives.

:file_upload

Upload file to remote filesystem.

:sql_console

Execute SQL query or run console.

:sql_dump

Multi dbms mysqldump replacement.

:net_scan

TCP Port scan.

:net_curl

Perform a curl-like HTTP request.

:net_proxy

Proxify local HTTP traffic passing through the target.

:net_ifconfig

Get network interface addresses.

:net_phpproxy

Install PHP proxy on the target.

The next section of the help file shows you the commands you can use to simulate an unrestricted shell. For some inscrutable reason, the command and description are reversed in this section:

Description, or Internal Command

Weevely Command

zip, unzip

file_zip

touch

file_touch

gzip, gunzip

file_gzip

curl

net_curl

nmap

net_scan

cd

file_cd

whoami, hostname, pwd, uname

system_info

rm

file_rm

cat

file_read