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

import threading
import time
import socks
import socket
import smtplib
import json
import string
import random
import os
from core.alert import *
from core.targets import target_type
from core.targets import target_to_host
from lib.icmp.engine import do_one as do_one_ping
from lib.socks_resolver.engine import getaddrinfo


def extra_requirements_dict():
    return {
        "smtp_brute_users": ["admin", "root", "test", "ftp", "anonymous", "user", "support", "1"],
        "smtp_brute_passwds": ["admin", "root", "test", "ftp", "anonymous", "user", "1", "12345",
                               "123456", "124567", "12345678", "123456789", "1234567890", "admin1",
                               "password!@#", "support", "<PASSWORD>", "qweasd", "qwerty", "!<PASSWORD>",
                               "<PASSWORD>", "<PASSWORD>", "<PASSWORD>", "<PASSWORD>", "password", "<PASSWORD>",
                               "admin123", ""],
        "smtp_brute_ports": ["25", "465", "587"],
        "smtp_brute_split_user_set_pass": ["False"],
        "smtp_brute_split_user_set_pass_prefix": [""]
    }


def login(user, passwd, target, port, timeout_sec, log_in_file, language, retries, time_sleep, thread_tmp_filename,
          socks_proxy):
    _HOST = messages(language, 53)
    _USERNAME = messages(language, 54)
    _PASSWORD = messages(language, 55)
    _PORT = messages(language, 56)
    _TYPE = messages(language, 57)
    _DESCRIPTION = messages(language, 58)
    exit = 0
    if socks_proxy is not None:
        socks.set_default_proxy(socks.SOCKS5, str(socks_proxy.rsplit(':')[0]), int(socks_proxy.rsplit(':')[1]))
        socket.socket = socks.socksocket
        socket.getaddrinfo = getaddrinfo
    while 1:
        try:
            if timeout_sec is not None:
                server = smtplib.SMTP(target, int(port), timeout=timeout_sec)
            else:
                server = smtplib.SMTP(target, int(port))
            server.starttls()
            exit = 0
            break
        except:
            exit += 1
            if exit is retries:
                warn(messages(language, 73).format(target, port, user, passwd))
                return 1
        time.sleep(time_sleep)
    flag = 1
    try:
        server.login(user, passwd)
        flag = 0
    except smtplib.SMTPException as err:
        pass
    if flag is 0:
        info(messages(language, 70).format(user, passwd, target, port))
        save = open(log_in_file, 'a')
        save.write(json.dumps({_HOST: target, _USERNAME: user, _PASSWORD: <PASSWORD>, _PORT: port, _TYPE: 'smtp_brute',
                               _DESCRIPTION: messages(language, 66)}) + '\n')
        save.close()
        thread_write = open(thread_tmp_filename, 'w')
        thread_write.write('0')
        thread_write.close()
    else:
        pass
    try:
        server.quit()
    except:
        pass
    return flag


def __connect_to_port(port, timeout_sec, target, retries, language, num, total, time_sleep, ports_tmp_filename,
                      thread_number, total_req, socks_proxy):
    exit = 0
    port = int(port)
    if socks_proxy is not None:
        socks.set_default_proxy(socks.SOCKS5, str(socks_proxy.rsplit(':')[0]), int(socks_proxy.rsplit(':')[1]))
        socket.socket = socks.socksocket
        socket.getaddrinfo = getaddrinfo
    while 1:
        try:
            if timeout_sec is not None:
                server = smtplib.SMTP(target, int(port), timeout=timeout_sec)
            else:
                server = smtplib.SMTP(target, int(port))
            server.starttls()
            server.quit()
            exit = 0
            break
        except:
            exit += 1
            if exit is retries:<commit_msg>add feature to smtp_brute support socks4 and socks5<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import threading
import time
import socks
import socket
import smtplib
import json
import string
import random
import os
from core.alert import *
from core.targets import target_type
from core.targets import target_to_host
from lib.icmp.engine import do_one as do_one_ping
from lib.socks_resolver.engine import getaddrinfo


def extra_requirements_dict():
    return {
        "smtp_brute_users": ["admin", "root", "test", "ftp", "anonymous", "user", "support", "1"],
        "smtp_brute_passwds": ["admin", "root", "test", "ftp", "anonymous", "user", "1", "12345",
                               "123456", "124567", "12345678", "123456789", "1234567890", "admin1",
                               "password!@#", "support", "<PASSWORD>", "qweasd", "qwerty", "!Q<PASSWORD>",
                               "<PASSWORD>", "<PASSWORD>", "<PASSWORD>", "iloveyou", "password", "<PASSWORD>",
                               "admin123", ""],
        "smtp_brute_ports": ["25", "465", "587"],
        "smtp_brute_split_user_set_pass": ["False"],
        "smtp_brute_split_user_set_pass_prefix": [""]
    }


def login(user, passwd, target, port, timeout_sec, log_in_file, language, retries, time_sleep, thread_tmp_filename,
          socks_proxy):
    _HOST = messages(language, 53)
    _USERNAME = messages(language, 54)
    _PASSWORD = messages(language, 55)
    _PORT = messages(language, 56)
    _TYPE = messages(language, 57)
    _DESCRIPTION = messages(language, 58)
    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]
        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:
        try:
            if timeout_sec is not None:
                server = smtplib.SMTP(target, int(port), timeout=timeout_sec)
            else:
                server = smtplib.SMTP(target, int(port))
            server.starttls()
            exit = 0
            break
        except:
            exit += 1
            if exit is retries:
                warn(messages(language, 73).format(target, port, user, passwd))
                return 1
        time.sleep(time_sleep)
    flag = 1
    try:
        server.login(user, passwd)
        flag = 0
    except smtplib.SMTPException as err:
        pass
    if flag is 0:
        info(messages(language, 70).format(user, passwd, target, port))
        save = open(log_in_file, 'a')
        save.write(json.dumps({_HOST: target, _USERNAME: user, _PASSWORD: <PASSWORD>, _PORT: port, _TYPE: 'smtp_brute',
                               _DESCRIPTION: messages(language, 66)}) + '\n')
        save.close()
        thread_write = open(thread_tmp_filename, 'w')
        thread_write.write('0')
        thread_write.close()
    else:
        pass
    try:
        server.quit()
    except:
        pass
    return flag


def __connect_to_port(port, timeout_sec, target, retries, language, num, total, time_sleep, ports_tmp_filename,
                      thread_number, total_req, socks_proxy):
    exit = 0
    port = int(port)
    if socks_proxy is not None:
        socks_version = socks.SOCKS5 if socks_proxy.startswith('socks5://') else socks.SOCKS4
        socks_proxy = socks_proxy.rsplit('://')[1]
        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:
        try:
            if timeout_sec is not None:
                server = smtplib.SMTP(target, int(port), timeout=timeout_sec)
            else:
                server = smtplib.SMTP(target, int(port))
            server.starttls()
            server.quit()
            exit = 0
            break
        except:
            exit += 1
            if exit is retries:
{'fraction_non_alphanumeric': 0.12390503998984385, 'fraction_numerical': 0.02539037704709915, 'mean_word_length': 2.310084033613445, 'pattern_counts': {'":': 10, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7357329', 'n_tokens_mistral': 2604, 'n_tokens_neox': 2437, 'n_words': 578}