Ejemplo n.º 1
0
def post_data(post_data, post_url, station, logger) -> bool:
    try:
        # init harware timer
        #timer = Timer(0)
        #TODO: Uncomment this for solution
        #timer.init(period=3000, mode=Timer.ONE_SHOT,callback=handlerTimer)
        [status, _] = post(post_url, headers=headers, data=post_data)
        #TODO: Uncomment this for solution
        #timer.deinit()
        if status == 200:
            #TODO: remove print
            print("Post Request [OK]")
            logger.info("Post Request [OK]")
            return True
        else:
            #TODO: remove print
            print("Post Request [Failed]")
            logger.info("Post Request [Failed]")
            return False
    except OSError as e:
        #TODO: remove print
        print("Warning: {0}".format(str(e)))
        logger.warning(str(e))
        if str(e) == "[Errno 113] EHOSTUNREACH":
            """
                station.active(False) seems to flush wifi module

                board output:
                    I (35596) wifi: flush txq
                    I (35596) wifi: stop sw txq
                    I (35596) wifi: lmac stop hw txq
            """
            station.active(False)
            station.active(True)
        return False
Ejemplo n.º 2
0
def post_data(post_data, post_url, logger: Logger) -> bool:
    try:
        response = post(post_url, headers=headers, data=post_data)
        if response.status_code == 200:
            #TODO: remove print
            print("Post Request Successful")
            logger.info("Post Request Successful")
            return True
        else:
            #TODO: remove print
            print("Post Request Unsuccessful")
            logger.info("Post Request Unsuccessful")
            return False
    except OSError as e:
        #TODO: remove print
        print("Warning: " + str(e))
        logger.warning(str(e))
Ejemplo n.º 3
0
def break_sp(gdt, host, location, recvd_headers, splashpage):
    gdt.feed()

    print("break_sp: Location:{}".format(location))

    # break with form resubmission
    forms = get_forms(splashpage)
    gdt.feed()
    collect()
    print(forms)

    if (len(forms) > 0):

        # generate response to form
        resp = form_response(forms[0])
        print("reponse: {}".format(resp))

        # Add from resubmit specific headers
        recvd_headers["Content-Type"] = "application/x-www-form-urlencoded"
        recvd_headers["Accept"] = "*/*"
        recvd_headers["Cache-Control"] = "no-cache"
        recvd_headers["Accept-Encoding"] = "gzip, deflate, br"
        recvd_headers["Connection"] = "keep-alive"

        # convert from dns address to usable URL
        if type(location) is tuple and len(location) == 2:

            #Another necessary header
            recvd_headers["Host"] = "{}".format(location[0])

            # URL conversion
            if location[1] == 80:
                location = "http://{}".format(location[0])
            elif location[1] == 443:
                location = "https://{}".format(location[0])

        # new location specified
        if "action" in forms[0]:

            if forms[0]["action"][0] == '/':  # relative path
                print("REALATIVE PATH /")

                # relative links append to <base ...> tag
                base_tag = tag_internals_to_dict(
                    breakup_tag(
                        get_tags(splashpage, "base")
                        [0]))  #relative paths must have a base specified
                base_url = base_tag["href"]
                [proto, dummy, base, _, _] = reqst.breakdown_url(base_url)

                location = "{0}//{1}{2}".format(
                    proto, base, forms[0]["action"])  #append to location

                #update header
                recvd_headers["Host"] = "{}".format(base)

            elif forms[0]["action"][0:2] == './':  # relative path
                print("REALATIVE PATH ./")

                # relative links append to <base ...> tag
                base_tag = tag_internals_to_dict(
                    breakup_tag(
                        get_tags(splashpage, "base")
                        [0]))  #relative paths must have a base specified
                base_url = base_tag["href"]
                [proto, dummy, base, _, _] = reqst.breakdown_url(base_url)

                location = "{0}//{1}{2}".format(
                    proto, base, forms[0]["action"][1:])  #append to location

                #update header
                recvd_headers["Host"] = "{}".format(base)

            else:  #absolute path
                print("ABSOLUTE PATH")
                location = forms[0]["action"]

        del splashpage
        del forms
        collect()

        #test
        resp = 'apname=%7B%7B%20apname%20%7D%7D&clmac=%7B%7B%20clmac%20%7D%7D'

        print("break_sp: Resubmitting form.\nLocation:{0}\n".format(location))
        gdt.feed()
        [dns_addr, status, recvd_page,
         recvd_headers] = reqst.post(location,
                                     data=resp,
                                     headers=recvd_headers,
                                     timeout=3000)
        gdt.feed()
        del resp
        collect()
        print("New page after resubmitting forms:")
        print("status:{}".format(status))
        print("headers:{}".format(recvd_headers))
        print("page:{}\n".format(recvd_page))

    # no forms, try following a-tags
    #else:
    #     #<a> TAG Splash Page Breaking
    #     a = splash_breaking_a(splashpage)
    #     for v in a:
    #         [status, _ ] = reqst.get(v)
    #         if status == 200:
    #             return True
    # -----------------------------

    # Possible Redirection on new page
    gdt.feed()
    print("Fed GDT before requesting splash page")
    if "Location" in recvd_headers and 300 <= status <= 309:
        [dns_addr, status, recvd_page,
         recvd_headers] = reqst.get_splash_page(recvd_headers["Location"])
        # new splashpage received
    elif "redirURL" in recvd_headers and 300 <= status <= 309:
        [dns_addr, status, recvd_page,
         recvd_headers] = reqst.get_splash_page(recvd_headers["redirURL"])
        # new splashpage received

    print("PAGE BREAKING COMPLETE!")
    host = "http://pmtlogger.000webhostapp.com/api/"
    print("Testing connection from {} ...".format(host))

    # test DNS -> GET Request
    # Test for open connection. DO NOT SEND THIS DATA BACK, you will only be backtracking to the inital page.
    [_, dns_status, _, dns_body, _] = reqst.test_dns_internet(host)
    gdt.feed()
    print("Status: {0}\nBody: {1}".format(dns_status, dns_body))

    if dns_status == 200 and dns_body == "OK":
        print("Internet Access [OK]")
        return True

    return [dns_addr, status, recvd_headers, recvd_page]