Beispiel #1
0
def send_answermd5(masterData):
    sendip = masterData['ip']
    sendport = masterData['port']
    request_id = masterData['id']
    md5_hash = masterData['md5']
    ranges = masterData['ranges']

    my_ip = vra_http_request_helper.get_my_ip()
    my_port = vra_http_request_helper.get_my_port()

    print("/checkmd5: templates to try: " + str(ranges))
    result = 1
    result_string = ''
    for range in ranges:
        result_string = vra_md5.md5_crack(str(md5_hash), str(range))
        if result_string:
            result = 0
            print("cracking " + str(md5_hash) + " gave " + result_string)
            break
        else:
            print("failed to crack " + str(md5_hash))
    print("Giving back: " + str(result_string))
    jdata = json.dumps({"ip":my_ip,
                        "port":my_port,
                        "id":request_id,
                        "md5":md5_hash,
                        "result":result,
                        "resultstring":result_string
                        })
    vra_http_request_helper.send_post_request(sendip, sendport, jdata, "/answermd5")
    print("Sent /answermd5")
    return 0
Beispiel #2
0
def send_checkmd5(query, request_id, sendip, sendport, resource):
    if resource is not 0:
        ranges = vra_range_generator.get_range(query.last_range_index, query.wildcard)

        # If generated range is empty, then do not send out the request (out of ranges, this problem is not solved).
        if range is []:
            return query

        query.last_range_index += 1
        print("Range: " + str(ranges))
        pending_range = {}
        pending_range['id'] = request_id
        pending_range['ranges'] = str(ranges)
        pending_range['timestamp'] = time.time()
        query.pending_ranges[request_id] = pending_range

        my_ip = vra_http_request_helper.get_my_ip()
        my_port = vra_http_request_helper.get_my_port()

        jdata = json.dumps({"ip": my_ip,
                        "port": my_port,
                        "id": request_id,
                        "md5": query.md5,
                        "ranges": ranges,
                        "wildcard": query.wildcard
                        })
        vra_http_request_helper.send_post_request(sendip, sendport, jdata, "/checkmd5")
        print("Query: " + str(query))

    return query
Beispiel #3
0
def resource_handler(sendip, sendport, ttl, id, noask, is_busy):
    # Check if I am busy and respond accordingly
    my_ip = vra_http_request_helper.get_my_ip()
    my_port = vra_http_request_helper.get_my_port()

    resource = str(100)
    if is_busy:
        resource = str(0)

    jdata = json.dumps({"ip": my_ip, "port": my_port, "id": id, "resource": resource})
    vra_http_request_helper.send_post_request(sendip, sendport, jdata, "/resourcereply")

    # Forwarding request
    # Check if TTL is a digit
    if ttl.isdigit():
        ttl = int(ttl)
    else:
        return "TTL not a digit, will not forward this request."
    # If TTL > 1, send it to known hosts not in noask list
    if ttl > 1:
        ttl -= 1

        # If sender is not in noask list, add it to noask list
        noask = noask_string_to_list(noask)
        sender = [sendip, sendport]
        if sender not in noask:
            noask.append(sender)

        # Add myself to noask:
        noask.append([my_ip, my_port])

        # Check noask list vs known hosts list and generate list of new unique hosts to forward request to
        known_hosts_from_file = vra_io.load_hosts()
        known_hosts_from_web = hosts_from_web("http://maatriks.eu/web_machines.txt")

        will_ask = [x for x in known_hosts_from_file if x not in noask]  # Known hosts not in noask list
        will_ask += [
            x for x in known_hosts_from_web if x not in noask and x not in will_ask
        ]  # Web hosts not in noask list and will_ask list

        # Set up request url parameters
        my_params = (
            "/resource?sendip=" + str(sendip) + "&sendport=" + str(sendport) + "&ttl=" + str(ttl) + "&id=" + str(id)
        )
        for host in noask:
            my_params += "&noask=" + str(host[0]) + "_" + str(host[1])

        # Send requests to each unique host
        print("/resource: hosts in will_ask: " + str(will_ask))
        for host in will_ask:
            host_ip = str(host[0])
            host_port = str(host[1])
            vra_http_request_helper.send_get_request(host_ip, host_port, my_params)
    return str(0)
Beispiel #4
0
def md5_crack_request_handler(query):
    # Check known machines availability
    known_hosts = vra_io.load_hosts()

    for host in known_hosts:
        # generate random ID for client
        uid = str(uuid.uuid1())
        query.waiting_requestreply.append(uid)
        my_ip = vra_http_request_helper.get_my_ip()
        my_port = vra_http_request_helper.get_my_port()

        host_ip = str(host[0])
        host_port = str(host[1])
        my_params = '/resource?sendip=' + my_ip + '&sendport=' + my_port + '&ttl=10&id=' + uid
        vra_http_request_helper.send_get_request(host_ip, host_port, my_params)
    return query
Beispiel #5
0
def send_new_checkmd5(query, request_id, sendip, sendport, result, result_string):
    # If result already found, do nothing.
    if int(query.result_found) == 1:
        print("Well I ended up here somehow.")
        return query

    # If answer is found, prepare query.
    if int(result) == 0:
        query.result_found = 1
        # To avoid overwriting.
        if query.result is "":
            query.result = result_string
        query.pending_ranges = {}
        query.waiting_requestreply = []
        return query
    elif int(result) == 1:
        new_ranges = vra_range_generator.get_range(query.last_range_index, query.wildcard)
        query.last_range_index += 1
        pending_range = {
            'id':request_id,
            'ranges':str(new_ranges),
            'timestamp':time.time()
        }
        my_ip = vra_http_request_helper.get_my_ip()
        my_port = vra_http_request_helper.get_my_port()
        # Assign new value to old pending_range of the same node
        query.pending_ranges[request_id] = pending_range
        jdata = json.dumps({"ip": my_ip,
                        "port": my_port,
                        "id": request_id,
                        "md5": query.md5,
                        "ranges": new_ranges,
                        "wildcard": query.wildcard
                        })
        vra_http_request_helper.send_post_request(sendip, sendport, jdata, "/checkmd5")
    elif int(result) == 2:
        # TODO: reassign ranges
        pass
    return query