<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import threading
import time
import socks
import socket
import json
import string
import random
import requests
import os
from core.alert import *
from core.targets import target_type
from core.targets import target_to_host
from core.load_modules import load_file_path
from lib.icmp.engine import do_one as do_one_ping
from lib.socks_resolver.engine import getaddrinfo
from core._time import now
from core.log import __log_into_file


def extra_requirements_dict():
    return {
        "http_basic_auth_brute_users": ["admin", "root", "test", "ftp", "anonymous", "user", "support", "1"],
        "http_basic_auth_brute_passwds": ["admin", "root", "test", "ftp", "anonymous", "user", "1", "12345",
                               "123456", "124567", "12345678", "123456789", "1234567890", "admin1",
                               "password!@#", "support", "<PASSWORD>", "q<PASSWORD>", "qwerty", <PASSWORD>",
                               "<PASSWORD>", "<PASSWORD>", "<PASSWORD>", "<PASSWORD>", "password", "<PASSWORD>",
                               "admin123", ""],
        "http_basic_auth_brute_ports": ["80"],
    }


def login(user, passwd, target, port, timeout_sec, log_in_file, language, retries, time_sleep, thread_tmp_filename,
          socks_proxy, scan_id, scan_cmd):
    exit = 0
    if socks_proxy is not None:
        socks_version = socks.SOCKS5 if socks_proxy.startswith('socks5://') else socks.SOCKS4
        socks_proxy = socks_proxy.rsplit('://')[1]
        if '@' in socks_proxy:
            socks_username = socks_proxy.rsplit(':')[0]
            socks_password = socks_proxy.rsplit(':')[1].rsplit('@')[0]
            socks.set_default_proxy(socks_version, str(socks_proxy.rsplit('@')[1].rsplit(':')[0]),
                                    int(socks_proxy.rsplit(':')[-1]), username=socks_username,
                                    password=<PASSWORD>)
            socket.socket = socks.socksocket
            socket.getaddrinfo = getaddrinfo
        else:
            socks.set_default_proxy(socks_version, str(socks_proxy.rsplit(':')[0]), int(socks_proxy.rsplit(':')[1]))
            socket.socket = socks.socksocket
            socket.getaddrinfo = getaddrinfo
    while 1:
        target = str(target)+":"+str(port)
        try:
            if timeout_sec is not None:
                req = requests.get(target, timeout=timeout_sec, auth=(user, passwd))
            else:
                req = requests.get(target, auth=(user, passwd))
            flag = 1
            if req.status_code != 200:
                exit += 1
                if exit is retries:
                    warn(messages(language,"http_auth_failed").format(target, user, passwd, port))
                    return 1
                else:
                    time.sleep(time_sleep)
                    continue
            elif req.status_code == 200:
                flag = 0
                if flag is 0:
                    info(messages(language,"http_auth_success").format(user, passwd, target, port))
                    data = json.dumps(
                        {'HOST': target, 'USERNAME': user, 'PASSWORD': <PASSWORD>, 'PORT': port,
                         'TYPE': 'http_basic_auth_brute', 'DESCRIPTION': messages(language,"login_successful"), 'TIME': now(),
                         'CATEGORY': "brute", 'SCAN_ID': scan_id, 'SCAN_CMD': scan_cmd}) + "\n"
                    __log_into_file(log_in_file, 'a', data, language)
                    __log_into_file(thread_tmp_filename, 'w', '0', language)
        except:
            exit += 1
            if exit is retries:
                warn(messages(language,"http_auth_failed").format(target, user, passwd, port))
                return 1<commit_msg>Fix error in http_basic_auth module<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import threading
import time
import socks
import socket
import json
import string
import random
import requests
import os
from core.alert import *
from core.targets import target_type
from core.targets import target_to_host
from core.load_modules import load_file_path
from lib.icmp.engine import do_one as do_one_ping
from lib.socks_resolver.engine import getaddrinfo
from core._time import now
from core.log import __log_into_file


def extra_requirements_dict():
    return {
        "http_basic_auth_brute_users": ["admin", "root", "test", "ftp", "anonymous", "user", "support", "1"],
        "http_basic_auth_brute_passwds": ["admin", "root", "test", "ftp", "anonymous", "user", "1", "12345",
                               "123456", "124567", "12345678", "123456789", "1234567890", "admin1",
                               "password!@#", "support", "1qaz2wsx", "qweasd", "qwerty", "!QAZ2wsx",
                               "<PASSWORD>", "<PASSWORD>", "<PASSWORD>", "<PASSWORD>", "password", "<PASSWORD>",
                               "admin123", ""],
        "http_basic_auth_brute_ports": ["80"],
    }


def login(user, passwd, target, port, timeout_sec, log_in_file, language, retries, time_sleep, thread_tmp_filename,
          socks_proxy, scan_id, scan_cmd):
    exit = 0
    if socks_proxy is not None:
        socks_version = socks.SOCKS5 if socks_proxy.startswith('socks5://') else socks.SOCKS4
        socks_proxy = socks_proxy.rsplit('://')[1]
        if '@' in socks_proxy:
            socks_username = socks_proxy.rsplit(':')[0]
            socks_password = socks_proxy.rsplit(':')[1].rsplit('@')[0]
            socks.set_default_proxy(socks_version, str(socks_proxy.rsplit('@')[1].rsplit(':')[0]),
                                    int(socks_proxy.rsplit(':')[-1]), username=socks_username,
                                    password=<PASSWORD>)
            socket.socket = socks.socksocket
            socket.getaddrinfo = getaddrinfo
        else:
            socks.set_default_proxy(socks_version, str(socks_proxy.rsplit(':')[0]), int(socks_proxy.rsplit(':')[1]))
            socket.socket = socks.socksocket
            socket.getaddrinfo = getaddrinfo
    while 1:
        target_host = str(target)+":"+str(port)
        try:
            if timeout_sec is not None:
                req = requests.get(target_host, timeout=timeout_sec, auth=(user, passwd))
            else:
                req = requests.get(target_host, auth=(user, passwd))
            flag = 1
            if req.status_code != 200:
                exit += 1
                if exit is retries:
                    warn(messages(language,"http_auth_failed").format(target, user, passwd, port))
                    return 1
                else:
                    time.sleep(time_sleep)
                    continue
            elif req.status_code == 200:
                flag = 0
                if flag is 0:
                    info(messages(language,"http_auth_success").format(user, passwd, target, port))
                    data = json.dumps(
                        {'HOST': target, 'USERNAME': user, 'PASSWORD': <PASSWORD>, 'PORT': port,
                         'TYPE': 'http_basic_auth_brute', 'DESCRIPTION': messages(language,"login_successful"), 'TIME': now(),
                         'CATEGORY': "brute", 'SCAN_ID': scan_id, 'SCAN_CMD': scan_cmd}) + "\n"
                    __log_into_file(log_in_file, 'a', data, language)
                    __log_into_file(thread_tmp_filename, 'w', '0', language)
        except:
            exit += 1
            if exit is retries:
                warn(messages(language,"http_auth_failed").format(target, user, passwd, port))
                return 1
{'fraction_non_alphanumeric': 0.1300276935249901, 'fraction_numerical': 0.021759198206514573, 'mean_word_length': 2.1639549436795993, 'pattern_counts': {'":': 8, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3728375', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2210, 'n_words': 497}