Exemplo n.º 1
0
def check():
    # return -1/2/1 -> normal / undetectable / phishing

    submit_url = request.args["url"]
    if not Checker.check_connection(submit_url):
        print("Connection unavailable")
        return "2"  # unable to detech

    if (Checker.Statistical_report(submit_url) == 1):
        return "1"
    try:
        print("Getting info for", submit_url)

        input_array = Helper.embed_url(submit_url)
        print(input_array)
        if "2" in input_array:
            # if cannot get some features
            print("Cannot get some features")
            return "2"

        result = Functions.check_vector(input_array)

        # this code is used to logged into the database file. Uncomment when needed
        # if (result == 1):
        #     f = open("model/data/urls.csv","a",encoding="UTF-8")
        #     f.write(submit_url+"\n")

        return str(result)
    except:
        print("Unable to detech")
        return "2"  # unable to detect
Exemplo n.º 2
0
def check():
    submit_url = request.args["url"]
    if not Checker.check_connection(submit_url):
        return "1"
    if (Checker.Statistical_report(submit_url) == 1):
        return "1"
    # return "-1"
    print("Getting info for", submit_url)
    input_array = embed_url(submit_url)
    print(input_array)
    print(len(input_array))
    result = Functions.check_vector(input_array)
    # if (result == 1):
    #     f = open("model/data/urls.csv","a",encoding="UTF-8")
    #     f.write(submit_url+"\n")
    return str(result)
Exemplo n.º 3
0
def check():
    # return -1/2/1 -> normal / undetectable / phishing

    submit_url = request.args["url"]
    submit_url = submit_url.replace(" ", "")
    if not Checker.check_connection(submit_url):
        print("Connection unavailable")
        return {
            "status": "unknown",  # unable to detect
            "message": "Unreachable"
        }

    if (Checker.Statistical_report(submit_url) == 1):
        return {"status": "phishing", "message": "Found in our database"}
    try:
        print("Getting info for", submit_url)

        embed_info = Helper.embed_url(submit_url)
        input_array = embed_info[0]
        info_obj = embed_info[1]

        print("Checking vector")
        result = Functions.check_vector(input_array)
        status = "unknown"
        if (result == 1):
            status = "phishing"
        elif (result == -1):
            status = "normal"

        return {
            "status": status,
            "message": "detect by model",
            "info": info_obj
        }
        # this code is used to logged into the database file. Uncomment when needed
        # if (result == 1):
        #     f = open("model/data/urls.csv","a",encoding="UTF-8")
        #     f.write(submit_url+"\n")

        return str(result)
    except:
        return {"status": "unknown", "message": "Internal error"}
Exemplo n.º 4
0
    def embed_url(url):
        features_size = 30
        threads = [None] * features_size
        arr_threads_result = []
        arr = []
        info = {}

        try:
            threads[0] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.having_IP_Address(arg1), 0)),
                args=(url, ))
            threads[1] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.URL_Length(arg1), 1)),
                args=(url, ))
            threads[2] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Shortining_Service(arg1), 2)),
                args=(url, ))
            threads[3] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.having_At_Symbol(arg1), 3)),
                args=(url, ))
            threads[4] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.double_slash_redirecting(arg1), 4)),
                args=(url, ))
            threads[5] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Prefix_Suffix(arg1), 5)),
                args=(url, ))
            threads[6] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.having_Sub_Domain(arg1), 6)),
                args=(url, ))
            threads[7] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.SSLfinal_State(arg1), 7)),
                args=(url, ))
            threads[8] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Domain_registeration_length(arg1), 8)),
                args=(url, ))
            threads[9] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Favicon(arg1), 9)),
                args=(url, ))
            threads[10] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.port(arg1), 10)),
                args=(url, ))
            threads[11] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.HTTPS_token(arg1), 11)),
                args=(url, ))
            threads[12] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Request_URL(arg1), 12)),
                args=(url, ))
            threads[13] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.URL_of_Anchor(arg1), 13)),
                args=(url, ))
            threads[14] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Links_in_tags(arg1), 14)),
                args=(url, ))
            threads[15] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.SFH(arg1), 15)),
                args=(url, ))
            threads[16] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Submitting_to_email(arg1), 16)),
                args=(url, ))
            threads[17] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Abnormal_URL(arg1), 17)),
                args=(url, ))
            threads[18] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Redirect(arg1), 18)),
                args=(url, ))
            threads[19] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.on_mouseover(arg1), 19)),
                args=(url, ))
            threads[20] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.RightClick(arg1), 20)),
                args=(url, ))
            threads[21] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.popUpWidnow(arg1), 21)),
                args=(url, ))
            threads[22] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Iframe(arg1), 22)),
                args=(url, ))
            threads[23] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.age_of_domain(arg1), 23)),
                args=(url, ))
            threads[24] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.DNSRecord(arg1), 24)),
                args=(url, ))
            threads[25] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.web_traffic(arg1), 25)),
                args=(url, ))
            threads[26] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Page_Rank(arg1), 26)),
                args=(url, ))
            threads[27] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Google_Index(arg1), 27)),
                args=(url, ))
            threads[28] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Links_pointing_to_page(arg1), 28)),
                args=(url, ))
            threads[29] = threading.Thread(
                target=lambda arg1: arr_threads_result.append(
                    (Checker.Statistical_report(arg1), 29)),
                args=(url, ))

            for i in range(features_size):
                threads[i].start()
            for i in range(features_size):
                threads[i].join()

            arr_threads_result.sort(key=lambda tup: tup[1])
            for elem in arr_threads_result:
                arr.append(elem[0]["status"])
                if "info" in elem[0].keys():
                    info = {**info, **elem[0]["info"]}

            return (arr, info)
        except Exception as e:
            print(e)
            return e
Exemplo n.º 5
0
def embed_url(url):
    url = "https://" + url
    threads = [None] * 30
    arr_threads_result = []
    arr = []
    try:
        threads[0] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.having_IP_Address(arg1), 0)),
            args=(arr_threads_result, url))
        threads[1] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.URL_Length(arg1), 1)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[2] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Shortining_Service(arg1), 2)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[3] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.having_At_Symbol(arg1), 3)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[4] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.double_slash_redirecting(arg1), 4)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[5] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Prefix_Suffix(arg1), 5)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[6] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.having_Sub_Domain(arg1), 6)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[7] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.SSLfinal_State(arg1), 7)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[8] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Domain_registeration_length(arg1), 8)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[9] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Favicon(arg1), 9)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[10] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.port(arg1), 10)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[11] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.HTTPS_token(arg1), 11)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[12] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Request_URL(arg1), 12)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[13] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.URL_of_Anchor(arg1), 13)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[14] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Links_in_tags(arg1), 14)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[15] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.SFH(arg1), 15)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[16] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Submitting_to_email(arg1), 16)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[17] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Abnormal_URL(arg1), 17)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[18] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Redirect(arg1), 18)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[19] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.on_mouseover(arg1), 19)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[20] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.RightClick(arg1), 20)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[21] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.popUpWidnow(arg1), 21)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[22] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Iframe(arg1), 22)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[23] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.age_of_domain(arg1), 23)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[24] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.DNSRecord(arg1), 24)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[25] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.web_traffic(arg1), 25)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[26] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Page_Rank(arg1), 26)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[27] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Google_Index(arg1), 27)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[28] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Links_pointing_to_page(arg1), 28)),
            args=(
                arr_threads_result,
                url,
            ))
        threads[29] = threading.Thread(
            target=lambda arr, arg1: arr_threads_result.append(
                (Checker.Statistical_report(arg1), 29)),
            args=(
                arr_threads_result,
                url,
            ))
        # threads[29] = -1
        for i in range(30):
            threads[i].start()
        for i in range(30):
            threads[i].join()
            print("THREAD ", i, "DONE", threads[i])
            print(len(arr))
        print("DONE THREAD")
        print(threads)
        arr_threads_result.sort(key=lambda tup: tup[1])
        for elem in arr_threads_result:
            arr.append(elem[0])
        print(arr)
        return arr
    except Exception as e:
        print(e)
        return -2
Exemplo n.º 6
0
#estado de partida onde não existe solução
initial_config2 = [1,2,3,4,13,68,12,5,9,0,7,14,11,10,15]

#estado teste
init_config_t1 = [1,2,3,4,5,6,7,8,9,10,11,0,13,14,15,12]
final_config_t1 = [9, 5, 12, 7, 14, 13, 0, 8, 1, 3, 2, 4, 6, 10, 15, 11]


#estado final
final_config =   [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0]

#objeto puzzle
puzzle = Puzzle(4, initial_config, final_config)

#objecto que checará se o puzzle possui solução ou não
checker = Checker(puzzle)

#método que inicial o jogo
def init_game():
    if checker.there_is_no_solution():
        print("Sem solução")
    else:
        print("-"*10+"Busca em Largura"+"-"*10)
        bl = BL(copy.deepcopy(puzzle))
        bl.search_solution()
        bl.show_solution()
        bl.solve()
        bl.show_time()
        bl.show_size()
        bl.show_depth()
Exemplo n.º 7
0
import json
from flask import Flask, render_template, request
from manages.DataBaseManager import DataBaseManager
from utils.Checker import Checker

app = Flask(__name__)
manager = DataBaseManager()
checker = Checker()


@app.route('/')
def index():
    data_list = manager.query_info()
    return render_template('index.html', data_list=data_list)


@app.route('/add', methods=['POST'])
def add_info():
    info = request.json
    if not checker.check_add_fields_exists(info):
        return json.dumps({
            'success': False,
            'reason': '字段不完整'
        },
                          ensure_ascii=False)
    fail_reason = checker.check_value_valid(info)
    if fail_reason:
        return json.dumps({
            'success': False,
            'reason': fail_reason
        },