Code Monkey home page Code Monkey logo

Comments (6)

mazen160 avatar mazen160 commented on July 16, 2024

Hi @Reboare ,

This is a very rare issue. I remember it was reported one time before, but the solution was indirect and could lead to further errors.

I'm not sure how to fix this issue in the best possible approach

from struts-pwn.

Reboare avatar Reboare commented on July 16, 2024

Thanks for the reply, I'm going to have a play around and see if I can find the fix it. What was the indirect solution?

from struts-pwn.

mazen160 avatar mazen160 commented on July 16, 2024

Here is the previous solution for the issue:

---
 struts-pwn.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/struts-pwn.py b/struts-pwn.py
index df93d83..b8db48f 100755
--- a/struts-pwn.py
+++ b/struts-pwn.py
@@ -91,13 +91,18 @@ def exploit(url, cmd):
     }
 
     timeout = 3
+    s = []
     try:
-        output = requests.get(url, headers=headers, verify=False, timeout=timeout, allow_redirects=False).text
-    except Exception as e:
-        print("EXCEPTION::::--> " + str(e))
-        output = 'ERROR'
-    return(output)
-
+        output = requests.get(url, headers=headers, verify=False, timeout=timeout, allow_redirects=False, stream=True)
+        if output.encoding is None:
+            output.encoding = 'utf-8'
+        for line in output.iter_content(chunk_size=None,decode_unicode=True):
+            s.append(line)
+            command_response = "".join(s)
+        output.close 
+    except:
+        pass
+    return(command_response)
 
 def check(url):
     url = url_prepare(url)
-- 

from struts-pwn.

mazen160 avatar mazen160 commented on July 16, 2024

Great!

Feel free to check it, and please let me know if you find another approach for solving the issue

from struts-pwn.

Reboare avatar Reboare commented on July 16, 2024

I've found a few approaches. It seems requests doesn't handle IncompleteRead's well at all and will happily throw away any data it finds.

One involves re-implementing in urllib2, which is far from ideal.

Alternatively re-raising a request in the event of a ChunkedEncodingError, which will then handle the IncompleteRead is possible, but then it means sending two connection requests each time, which is a bit messy. I could add a flag to allow handling this, but that's really just adding cruft.

The only other solution I can see is very similar to the above although I've tried to clean it up a bit and add correct error handling:

    try:
        with requests.get(url, headers=headers, timeout=timeout, allow_redirects=False, stream=True) as rq:
            output = ""
            for i in rq.iter_content():
                output += i
    except requests.exceptions.ChunkedEncodingError as e:
        print("EXCEPTION::::--> " + str(e))
        print("Server is prematurely closing connection!")
    except Exception as e:
        print type(e)
        print("EXCEPTION::::--> " + str(e))
        output = 'ERROR'
    return(output)

By delaying the request to later and then reading the content byte by byte, this should handle closing the request healthily by wrapping it within the with block, as I believe the above solution would still cause an error but leave the connection hanging. In the event of an IncompleteRead, the first Exception is always hit, but it means any recovered data can be returned without it being discarded.

Would you be happy with this solution if I were to clean it up and submit a pull? Effectively it's acting in a similar manner to under the hood, and I'm more than happy to add the stuff .text does to handle unicode/apparent encoding

from struts-pwn.

mazen160 avatar mazen160 commented on July 16, 2024

Hi @Reboare ,

This will be a great addition!. I would be totally happy implementing your solution to the repo. Once you make a pull request, I will test it on a local testing VM and then merge it to master.

Thanks again for your time and interest!

from struts-pwn.

Related Issues (6)

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.