[ Avaa Bypassed ]




Upload:

Command:

www-data@18.118.136.90: ~ $
#!/usr/bin/env python
# Copyright Daniel Roesler, under MIT license, see LICENSE at github.com/diafygi/acme-tiny
import argparse, subprocess, json, os, sys, base64, binascii, time, hashlib, re, copy, textwrap, logging
try:
    from urllib.request import urlopen, Request # Python 3
except ImportError:
    from urllib2 import urlopen, Request # Python 2

DEFAULT_CA = "https://acme-v02.api.letsencrypt.org" # DEPRECATED! USE DEFAULT_DIRECTORY_URL INSTEAD
DEFAULT_DIRECTORY_URL = "https://acme-v02.api.letsencrypt.org/directory"

LOGGER = logging.getLogger(__name__)
LOGGER.addHandler(logging.StreamHandler())
LOGGER.setLevel(logging.INFO)

def get_crt(account_key, csr, acme_dir, log=LOGGER, CA=DEFAULT_CA, disable_check=False, directory_url=DEFAULT_DIRECTORY_URL, contact=None):
    directory, acct_headers, alg, jwk = None, None, None, None # global variables

    # helper functions - base64 encode for jose spec
    def _b64(b):
        return base64.urlsafe_b64encode(b).decode('utf8').replace("=", "")

    # helper function - run external commands
    def _cmd(cmd_list, stdin=None, cmd_input=None, err_msg="Command Line Error"):
        proc = subprocess.Popen(cmd_list, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = proc.communicate(cmd_input)
        if proc.returncode != 0:
            raise IOError("{0}\n{1}".format(err_msg, err))
        return out

    # helper function - make request and automatically parse json response
    def _do_request(url, data=None, err_msg="Error", depth=0):
        try:
            resp = urlopen(Request(url, data=data, headers={"Content-Type": "application/jose+json", "User-Agent": "acme-tiny"}))
            resp_data, code, headers = resp.read().decode("utf8"), resp.getcode(), resp.headers
        except IOError as e:
            resp_data = e.read().decode("utf8") if hasattr(e, "read") else str(e)
            code, headers = getattr(e, "code", None), {}
        try:
            resp_data = json.loads(resp_data) # try to parse json results
        except ValueError:
            pass # ignore json parsing errors
        if depth < 100 and code == 400 and resp_data['type'] == "urn:ietf:params:acme:error:badNonce":
            raise IndexError(resp_data) # allow 100 retrys for bad nonces
        if code not in [200, 201, 204]:
            raise ValueError("{0}:\nUrl: {1}\nData: {2}\nResponse Code: {3}\nResponse: {4}".format(err_msg, url, data, code, resp_data))
        return resp_data, code, headers

    # helper function - make signed requests
    def _send_signed_request(url, payload, err_msg, depth=0):
        payload64 = "" if payload is None else _b64(json.dumps(payload).encode('utf8'))
        new_nonce = _do_request(directory['newNonce'])[2]['Replay-Nonce']
        protected = {"url": url, "alg": alg, "nonce": new_nonce}
        protected.update({"jwk": jwk} if acct_headers is None else {"kid": acct_headers['Location']})
        protected64 = _b64(json.dumps(protected).encode('utf8'))
        protected_input = "{0}.{1}".format(protected64, payload64).encode('utf8')
        out = _cmd(["openssl", "dgst", "-sha256", "-sign", account_key], stdin=subprocess.PIPE, cmd_input=protected_input, err_msg="OpenSSL Error")
        data = json.dumps({"protected": protected64, "payload": payload64, "signature": _b64(out)})
        try:
            return _do_request(url, data=data.encode('utf8'), err_msg=err_msg, depth=depth)
        except IndexError: # retry bad nonces (they raise IndexError)
            return _send_signed_request(url, payload, err_msg, depth=(depth + 1))

    # helper function - poll until complete
    def _poll_until_not(url, pending_statuses, err_msg):
        result, t0 = None, time.time()
        while result is None or result['status'] in pending_statuses:
            assert (time.time() - t0 < 3600), "Polling timeout" # 1 hour timeout
            time.sleep(0 if result is None else 2)
            result, _, _ = _send_signed_request(url, None, err_msg)
        return result

    # parse account key to get public key
    log.info("Parsing account key...")
    out = _cmd(["openssl", "rsa", "-in", account_key, "-noout", "-text"], err_msg="OpenSSL Error")
    pub_pattern = r"modulus:[\s]+?00:([a-f0-9\:\s]+?)\npublicExponent: ([0-9]+)"
    pub_hex, pub_exp = re.search(pub_pattern, out.decode('utf8'), re.MULTILINE|re.DOTALL).groups()
    pub_exp = "{0:x}".format(int(pub_exp))
    pub_exp = "0{0}".format(pub_exp) if len(pub_exp) % 2 else pub_exp
    alg = "RS256"
    jwk = {
        "e": _b64(binascii.unhexlify(pub_exp.encode("utf-8"))),
        "kty": "RSA",
        "n": _b64(binascii.unhexlify(re.sub(r"(\s|:)", "", pub_hex).encode("utf-8"))),
    }
    accountkey_json = json.dumps(jwk, sort_keys=True, separators=(',', ':'))
    thumbprint = _b64(hashlib.sha256(accountkey_json.encode('utf8')).digest())

    # find domains
    log.info("Parsing CSR...")
    out = _cmd(["openssl", "req", "-in", csr, "-noout", "-text"], err_msg="Error loading {0}".format(csr))
    domains = set([])
    common_name = re.search(r"Subject:.*? CN\s?=\s?([^\s,;/]+)", out.decode('utf8'))
    if common_name is not None:
        domains.add(common_name.group(1))
    subject_alt_names = re.search(r"X509v3 Subject Alternative Name: (?:critical)?\n +([^\n]+)\n", out.decode('utf8'), re.MULTILINE|re.DOTALL)
    if subject_alt_names is not None:
        for san in subject_alt_names.group(1).split(", "):
            if san.startswith("DNS:"):
                domains.add(san[4:])
    log.info("Found domains: {0}".format(", ".join(domains)))

    # get the ACME directory of urls
    log.info("Getting directory...")
    directory_url = CA + "/directory" if CA != DEFAULT_CA else directory_url # backwards compatibility with deprecated CA kwarg
    directory, _, _ = _do_request(directory_url, err_msg="Error getting directory")
    log.info("Directory found!")

    # create account, update contact details (if any), and set the global key identifier
    log.info("Registering account...")
    reg_payload = {"termsOfServiceAgreed": True}
    account, code, acct_headers = _send_signed_request(directory['newAccount'], reg_payload, "Error registering")
    log.info("Registered!" if code == 201 else "Already registered!")
    if contact is not None:
        account, _, _ = _send_signed_request(acct_headers['Location'], {"contact": contact}, "Error updating contact details")
        log.info("Updated contact details:\n{0}".format("\n".join(account['contact'])))

    # create a new order
    log.info("Creating new order...")
    order_payload = {"identifiers": [{"type": "dns", "value": d} for d in domains]}
    order, _, order_headers = _send_signed_request(directory['newOrder'], order_payload, "Error creating new order")
    log.info("Order created!")

    # get the authorizations that need to be completed
    for auth_url in order['authorizations']:
        authorization, _, _ = _send_signed_request(auth_url, None, "Error getting challenges")
        domain = authorization['identifier']['value']
        log.info("Verifying {0}...".format(domain))

        # find the http-01 challenge and write the challenge file
        challenge = [c for c in authorization['challenges'] if c['type'] == "http-01"][0]
        token = re.sub(r"[^A-Za-z0-9_\-]", "_", challenge['token'])
        keyauthorization = "{0}.{1}".format(token, thumbprint)
        wellknown_path = os.path.join(acme_dir, token)
        with open(wellknown_path, "w") as wellknown_file:
            wellknown_file.write(keyauthorization)

        # check that the file is in place
        try:
            wellknown_url = "http://{0}/.well-known/acme-challenge/{1}".format(domain, token)
            assert (disable_check or _do_request(wellknown_url)[0] == keyauthorization)
        except (AssertionError, ValueError) as e:
            raise ValueError("Wrote file to {0}, but couldn't download {1}: {2}".format(wellknown_path, wellknown_url, e))

        # say the challenge is done
        _send_signed_request(challenge['url'], {}, "Error submitting challenges: {0}".format(domain))
        authorization = _poll_until_not(auth_url, ["pending"], "Error checking challenge status for {0}".format(domain))
        if authorization['status'] != "valid":
            raise ValueError("Challenge did not pass for {0}: {1}".format(domain, authorization))
        os.remove(wellknown_path)
        log.info("{0} verified!".format(domain))

    # finalize the order with the csr
    log.info("Signing certificate...")
    csr_der = _cmd(["openssl", "req", "-in", csr, "-outform", "DER"], err_msg="DER Export Error")
    _send_signed_request(order['finalize'], {"csr": _b64(csr_der)}, "Error finalizing order")

    # poll the order to monitor when it's done
    order = _poll_until_not(order_headers['Location'], ["pending", "processing"], "Error checking order status")
    if order['status'] != "valid":
        raise ValueError("Order failed: {0}".format(order))

    # download the certificate
    certificate_pem, _, _ = _send_signed_request(order['certificate'], None, "Certificate download failed")
    log.info("Certificate signed!")
    return certificate_pem

def main(argv=None):
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=textwrap.dedent("""\
            This script automates the process of getting a signed TLS certificate from Let's Encrypt using
            the ACME protocol. It will need to be run on your server and have access to your private
            account key, so PLEASE READ THROUGH IT! It's only ~200 lines, so it won't take long.

            Example Usage:
            python acme_tiny.py --account-key ./account.key --csr ./domain.csr --acme-dir /usr/share/nginx/html/.well-known/acme-challenge/ > signed_chain.crt

            Example Crontab Renewal (once per month):
            0 0 1 * * python /path/to/acme_tiny.py --account-key /path/to/account.key --csr /path/to/domain.csr --acme-dir /usr/share/nginx/html/.well-known/acme-challenge/ > /path/to/signed_chain.crt 2>> /var/log/acme_tiny.log
            """)
    )
    parser.add_argument("--account-key", required=True, help="path to your Let's Encrypt account private key")
    parser.add_argument("--csr", required=True, help="path to your certificate signing request")
    parser.add_argument("--acme-dir", required=True, help="path to the .well-known/acme-challenge/ directory")
    parser.add_argument("--quiet", action="store_const", const=logging.ERROR, help="suppress output except for errors")
    parser.add_argument("--disable-check", default=False, action="store_true", help="disable checking if the challenge file is hosted correctly before telling the CA")
    parser.add_argument("--directory-url", default=DEFAULT_DIRECTORY_URL, help="certificate authority directory url, default is Let's Encrypt")
    parser.add_argument("--ca", default=DEFAULT_CA, help="DEPRECATED! USE --directory-url INSTEAD!")
    parser.add_argument("--contact", metavar="CONTACT", default=None, nargs="*", help="Contact details (e.g. mailto:aaa@bbb.com) for your account-key")

    args = parser.parse_args(argv)
    LOGGER.setLevel(args.quiet or LOGGER.level)
    signed_crt = get_crt(args.account_key, args.csr, args.acme_dir, log=LOGGER, CA=args.ca, disable_check=args.disable_check, directory_url=args.directory_url, contact=args.contact)
    sys.stdout.write(signed_crt)

if __name__ == "__main__": # pragma: no cover
    main(sys.argv[1:])

Filemanager

Name Type Size Permission Actions
help Folder 0755
images Folder 0755
lang Folder 0755
subdir Folder 0755
CHANGELOG File 12.02 KB 0644
acme_tiny.py File 11.24 KB 0755
adminupgrade File 299 B 0644
backup_config.pl File 1.97 KB 0755
bootup.cgi File 1.04 KB 0755
cache.cgi File 1.47 KB 0755
cgi_args.pl File 159 B 0755
change_access.cgi File 1.34 KB 0755
change_advanced.cgi File 3 KB 0755
change_anon.cgi File 712 B 0755
change_bind.cgi File 4.8 KB 0755
change_ca.cgi File 674 B 0755
change_debug.cgi File 1.38 KB 0755
change_lang.cgi File 558 B 0755
change_lock.cgi File 554 B 0755
change_log.cgi File 2.38 KB 0755
change_mobile.cgi File 940 B 0755
change_os.cgi File 1.85 KB 0755
change_osdn.cgi File 1.54 KB 0755
change_overlay.cgi File 1.16 KB 0755
change_proxy.cgi File 1.09 KB 0755
change_referers.cgi File 633 B 0755
change_session.cgi File 4.77 KB 0755
change_ssl.cgi File 3.03 KB 0755
change_startpage.cgi File 773 B 0755
change_status.cgi File 1.02 KB 0755
change_theme.cgi File 1.16 KB 0755
change_twofactor.cgi File 1.43 KB 0755
change_ui.cgi File 1.61 KB 0755
change_web.cgi File 2.47 KB 0755
clear_blocked.cgi File 154 B 0755
clear_cache.cgi File 205 B 0755
clone_mod.cgi File 2.06 KB 0755
config File 114 B 0644
config.info File 696 B 0644
config.info.ar File 414 B 0644
config.info.ca File 408 B 0644
config.info.cs File 233 B 0644
config.info.de File 368 B 0644
config.info.es File 229 B 0644
config.info.fa File 301 B 0644
config.info.fr File 577 B 0644
config.info.hr File 0 B 0644
config.info.hu File 0 B 0644
config.info.it File 245 B 0644
config.info.ja File 531 B 0644
config.info.ko File 206 B 0644
config.info.ms File 286 B 0644
config.info.nl File 299 B 0644
config.info.no File 283 B 0644
config.info.pl File 284 B 0644
config.info.pt_BR File 299 B 0644
config.info.ru File 491 B 0644
config.info.sk File 132 B 0644
config.info.sv File 202 B 0644
config.info.tr File 155 B 0644
cpan_modules.pl File 229 B 0755
defaultacl File 17 B 0644
delete_cache.cgi File 471 B 0755
delete_mod.cgi File 2.24 KB 0755
delete_webmincron.cgi File 1.51 KB 0755
download_cert.cgi File 532 B 0755
edit_access.cgi File 1.38 KB 0755
edit_advanced.cgi File 3.87 KB 0755
edit_anon.cgi File 812 B 0755
edit_assignment.cgi File 1.12 KB 0755
edit_bind.cgi File 2.95 KB 0755
edit_blocked.cgi File 944 B 0755
edit_ca.cgi File 2.82 KB 0755
edit_categories.cgi File 1.69 KB 0755
edit_debug.cgi File 2.04 KB 0755
edit_descs.cgi File 1.49 KB 0755
edit_ipkey.cgi File 1.7 KB 0755
edit_lang.cgi File 1.82 KB 0755
edit_lock.cgi File 763 B 0755
edit_log.cgi File 3.04 KB 0755
edit_mobile.cgi File 1.26 KB 0755
edit_mods.cgi File 4.45 KB 0755
edit_os.cgi File 2.72 KB 0755
edit_proxy.cgi File 3.7 KB 0755
edit_referers.cgi File 899 B 0755
edit_sendmail.cgi File 3.48 KB 0755
edit_session.cgi File 5.18 KB 0755
edit_ssl.cgi File 10.55 KB 0755
edit_startpage.cgi File 1.68 KB 0755
edit_status.cgi File 1.13 KB 0755
edit_themes.cgi File 3.72 KB 0755
edit_twofactor.cgi File 1.5 KB 0755
edit_ui.cgi File 2.51 KB 0755
edit_upgrade.cgi File 4.26 KB 0755
edit_web.cgi File 2.88 KB 0755
edit_webmincron.cgi File 1.35 KB 0755
export_mod.cgi File 1.23 KB 0755
feedback_files.pl File 126 B 0755
fix_os.cgi File 228 B 0755
gnupg-lib.pl File 13.38 KB 0755
hide.cgi File 326 B 0755
index.cgi File 4.16 KB 0755
install_mod.cgi File 3.11 KB 0755
install_theme.cgi File 2.29 KB 0755
jcameron-key.asc File 1.29 KB 0644
letsencrypt-cleanup.pl File 2.02 KB 0755
letsencrypt-dns.pl File 2.57 KB 0755
letsencrypt-lib.pl File 14.03 KB 0755
letsencrypt.cgi File 4.64 KB 0755
log_parser.pl File 1.23 KB 0755
module.info File 195 B 0644
module.info.af File 0 B 0644
module.info.af.auto File 142 B 0644
module.info.ar File 185 B 0644
module.info.ar.auto File 22 B 0644
module.info.be File 0 B 0644
module.info.be.auto File 208 B 0644
module.info.bg File 0 B 0644
module.info.bg.auto File 218 B 0644
module.info.ca File 134 B 0644
module.info.ca.auto File 15 B 0644
module.info.cs File 28 B 0644
module.info.cs.auto File 128 B 0644
module.info.da File 0 B 0644
module.info.da.auto File 142 B 0644
module.info.de File 126 B 0644
module.info.de.auto File 15 B 0644
module.info.el File 0 B 0644
module.info.el.auto File 262 B 0644
module.info.es File 33 B 0644
module.info.es.auto File 109 B 0644
module.info.eu File 0 B 0644
module.info.eu.auto File 158 B 0644
module.info.fa File 0 B 0644
module.info.fa.auto File 202 B 0644
module.info.fi File 0 B 0644
module.info.fi.auto File 141 B 0644
module.info.fr File 32 B 0644
module.info.fr.auto File 129 B 0644
module.info.he File 0 B 0644
module.info.he.auto File 195 B 0644
module.info.hr File 0 B 0644
module.info.hr.auto File 149 B 0644
module.info.hu File 30 B 0644
module.info.hu.auto File 148 B 0644
module.info.it File 33 B 0644
module.info.it.auto File 107 B 0644
module.info.ja File 180 B 0644
module.info.ko File 22 B 0644
module.info.ko.auto File 129 B 0644
module.info.lt File 0 B 0644
module.info.lt.auto File 180 B 0644
module.info.lv File 0 B 0644
module.info.lv.auto File 157 B 0644
module.info.ms File 119 B 0644
module.info.ms.auto File 15 B 0644
module.info.mt File 0 B 0644
module.info.mt.auto File 144 B 0644
module.info.nl File 28 B 0644
module.info.nl.auto File 117 B 0644
module.info.no File 29 B 0644
module.info.no.auto File 117 B 0644
module.info.pl File 155 B 0644
module.info.pl.auto File 15 B 0644
module.info.pt File 33 B 0644
module.info.pt.auto File 113 B 0644
module.info.pt_BR File 36 B 0644
module.info.pt_BR.auto File 119 B 0644
module.info.ro File 0 B 0644
module.info.ro.auto File 147 B 0644
module.info.ru File 34 B 0644
module.info.ru.auto File 172 B 0644
module.info.sk File 30 B 0644
module.info.sk.auto File 132 B 0644
module.info.sl File 0 B 0644
module.info.sl.auto File 147 B 0644
module.info.sv File 30 B 0644
module.info.sv.auto File 114 B 0644
module.info.th File 0 B 0644
module.info.th.auto File 258 B 0644
module.info.tr File 33 B 0644
module.info.tr.auto File 128 B 0644
module.info.uk File 0 B 0644
module.info.uk.auto File 215 B 0644
module.info.ur File 0 B 0644
module.info.ur.auto File 209 B 0644
module.info.vi File 0 B 0644
module.info.vi.auto File 177 B 0644
module.info.zh File 22 B 0644
module.info.zh_TW File 25 B 0644
module.info.zh_TW.auto File 115 B 0644
newcsr.cgi File 800 B 0755
newkey.cgi File 879 B 0755
postinstall.pl File 2.01 KB 0755
refresh_modules.cgi File 664 B 0755
restart.cgi File 87 B 0755
save_assignment.cgi File 485 B 0755
save_categories.cgi File 946 B 0755
save_descs.cgi File 1006 B 0755
save_ipkey.cgi File 1.31 KB 0755
save_newmod.cgi File 278 B 0755
save_sendmail.cgi File 2.08 KB 0755
save_webmincron.cgi File 1016 B 0755
savekey.cgi File 2.8 KB 0755
setup_ca.cgi File 1.52 KB 0755
standard_chooser.cgi File 1.68 KB 0755
stop_ca.cgi File 1.03 KB 0755
syslog_logs.pl File 633 B 0755
system_info.pl File 5.02 KB 0644
test_sendmail.cgi File 784 B 0755
third_chooser.cgi File 1.55 KB 0755
twofactor-funcs-lib.pl File 8.81 KB 0644
uninstall.pl File 236 B 0755
update.cgi File 2.86 KB 0755
upgrade.cgi File 16.6 KB 0755
view_webmincron.cgi File 1.66 KB 0755
webmin-lib.pl File 68.77 KB 0755