コード例 #1
0
 def __init__(self, header):
     self.hardware_type = header[:4]
     self.protocol_type = header[4:8]
     self.hardware_size = header[8:10]
     self.protocol_size = header[10:12]
     self.opcode = header[12:16]
     self.sender_mac_address = get_mac(header[16:28])
     self.sender_ip_address = get_ipv4(header[28:36])
     self.target_mac_address = get_mac(header[36:48])
     self.target_ip_address = get_ipv4(header[48:56])
コード例 #2
0
    def _packet_handler(self, pkt):
        """This method is called for each packet received through scapy's sniff function.
        Incoming ARP requests are used to spoof involved devices.

        Args:
            pkt (str): Received packet via scapy's sniff (through socket.recv).
        """
        # when ARP request
        if pkt[ARP].op == 1:

            # packets intended for this machine (upribox)
            if pkt[Ether].dst == self.mac:
                # incoming packets(that are sniffed): Windows correctly fills in the hwdst, linux (router) only 00:00:00:00:00:00
                # this answers packets asking if we are the gateway (directly not via broadcast)
                # Windows does this 3 times before sending a broadcast request
                sendp(Ether(dst=pkt[Ether].src) / ARP(op=2, psrc=pkt[ARP].pdst, pdst=pkt[ARP].psrc, hwdst=pkt[ARP].hwsrc, hwsrc=self.mac))

            # broadcast request to or from gateway
            elif pkt[Ether].dst.lower() == util.hex2str_mac(ETHER_BROADCAST) and (pkt[ARP].psrc == self.gateway or pkt[ARP].pdst == self.gateway):
                # spoof transmitter
                packets = [Ether(dst=pkt[Ether].src) / ARP(op=2, psrc=pkt[ARP].pdst, pdst=pkt[ARP].psrc, hwsrc=self.mac, hwdst=pkt[ARP].hwsrc)]

                # get mac address of original target
                dest = self.gate_mac
                if pkt[ARP].pdst != self.gateway:
                    # send arp request if destination was not the gateway
                    dest = util.get_mac(pkt[ARP].pdst, self.interface)

                if dest:
                    # spoof receiver
                    packets.append(Ether(dst=dest) / ARP(op=2, psrc=pkt[ARP].psrc, hwsrc=self.mac, pdst=pkt[ARP].pdst, hwdst=dest))

                # some os didn't accept an answer immediately (after sending the first ARP request after boot
                # so, send packets after some delay
                threading.Timer(self._DELAY, sendp, [packets]).start()
コード例 #3
0
ファイル: daemon_app.py プロジェクト: seurat-atreides/upribox
    def __init__(self, logger, interface, pidfile, stdout, stderr, dns_file):
        """Initialises several things needed to define the daemons behaviour.

        Args:
            logger (logging.Logger): Used for logging messages.
            interface (str): The network interface which should be used. (e.g. eth0)
            pidfile (str): Path of the pidfile, used by the daemon.
            stdout (str): Path of stdout, used by the daemon.
            stderr (str): Path of stderr, used by the daemon.
            dns_file (str): Path of file containing the nameservers.

        Raises:
            DaemonError: Signalises the failure of the daemon.
        """
        # disable scapys verbosity global
        conf.verb = 0

        self.stdin_path = os.devnull
        self.stdout_path = stdout
        self.stderr_path = stderr
        self.pidfile_path = pidfile
        self.pidfile_timeout = 5
        # self.pidfile_timeout = 0

        self.logger = logger
        self.interface = interface

        # namedtuple for providing information about the IP configuration
        IPInfo = collections.namedtuple(
            'IPInfo',
            'ip, netmask, network, gateway, mac, gate_mac, dns_servers, redis')

        if_info = None
        try:
            if_info = ni.ifaddresses(self.interface)
        except ValueError as e:
            self.logger.error(
                "An error concerning the interface {} has occurred: {}".format(
                    self.interface, str(e)))
            raise DaemonError()

        self.ipv4 = None
        self.ipv6 = None

        # get mac address of specified interface
        mac = if_info[ni.AF_LINK][0]['addr']
        rs = dns.resolver.Resolver(filename=dns_file)

        try:
            # get ip of specified interface
            ip = if_info[ni.AF_INET][-1]['addr']
            # get subnetmask of specified interface
            netmask = if_info[ni.AF_INET][-1]['netmask'].split("/")[0]
            # get the network address
            network = IPNetwork("{}/{}".format(ip, netmask))

            # get default gateway
            gateway = ni.gateways()["default"][ni.AF_INET][0]

            # get MAC address of gateway
            gate_mac = util.get_mac(gateway, self.interface)
            if not gate_mac:
                raise DaemonError("Unable to get MAC address of IPv4 Gateway")

            # get all ipv4 nameservers
            dns_servers = [
                x for x in rs.nameservers if IPAddress(x).version == 4
                and not IPAddress(x).is_reserved()
            ]
            # store ipv4 information
            self.ipv4 = IPInfo(ip, netmask, network, gateway, mac, gate_mac,
                               dns_servers, None)
        except AddrFormatError as afe:
            # this should never happen, because values are retrieved via netifaces library
            self.logger.error(
                "A error happened during determinig the IPv4 network: {}".
                format(str(afe)))
        except KeyError:
            self.logger.debug("No IPv4 default gateway is configured")
        except IndexError:
            self.logger.debug("No IPv4 address is configured")
        except DaemonError as de:
            self.logger.exception(de)

        try:
            # global IPv6 if self.ipv6 results in True
            # get ipv6 addresses of specified interface
            ip = [
                x for x in if_info[ni.AF_INET6]
                if not IPAddress(x['addr'].split("%")[0]).is_private()
            ]
            #self.linklocal = [x['addr'].split("%")[0] for x in if_info[ni.AF_INET6] if IPAddress(x['addr'].split("%")[0]).is_link_local()][0]

            # get network address
            network = IPNetwork("{}/{}".format(ip[0]['addr'],
                                               ip[0]['netmask'].split("/")[0]))
            # get subnetmask of specified interface
            netmask = [entry['netmask'] for entry in if_info[ni.AF_INET6]]
            # get default gateway
            gateway = ni.gateways()["default"][ni.AF_INET6][0]

            # get MAC address of gateway
            gate_mac = util.get_mac6(gateway, self.interface)
            if not gate_mac:
                raise DaemonError("Unable to get MAC address of IPv6 Gateway")

            # get all ipv6 nameservers
            dns_servers = [
                x for x in rs.nameservers if IPAddress(x).version == 6
                and not IPAddress(x).is_reserved()
            ]
            # store ipv6 information
            self.ipv6 = IPInfo(ip, netmask, network, gateway, mac, gate_mac,
                               dns_servers, None)
        except AddrFormatError as afe:
            # this should never happen, because values are retrieved via netifaces library
            self.logger.error(
                "A error happened during determinig the IPv6 network: {}".
                format(str(afe)))
        except KeyError:
            self.logger.debug("No IPv6 default gateway is configured")
        except IndexError:
            self.logger.debug("No IPv6 address is configured")
        except DaemonError as de:
            self.logger.exception(de)

        if not any((self.ipv4, self.ipv6)):
            # at least ipv4 or ipv6 has to be configured
            self.logger.error("Unable to retrieve IPv4 and IPv6 configuration")
            raise DaemonError()
コード例 #4
0
 def __init__(self, header):
     self.d_mac = get_mac(header[:12])
     self.s_mac = get_mac(header[12:24])
     self.type = header[24:28]
     self.next_proto = Ethernet.next_proto_map[self.type]
     self.time = time.time()
コード例 #5
0
    def __init__(self, logger, interface, pidfile, stdout, stderr):
        """Initialises several things needed to define the daemons behaviour.

        Args:
            logger (logging.Logger): Used for logging messages.
            interface (str): The network interface which should be used. (e.g. eth0)
            pidfile (str): Path of the pidfile, used by the daemon.
            stdout (str): Path of stdout, used by the daemon.
            stderr (str): Path of stderr, used by the daemon.

        Raises:
            DaemonError: Signalises the failure of the daemon.
        """
        # disable scapys verbosity global
        conf.verb = 0

        self.stdin_path = os.devnull
        self.stdout_path = stdout
        self.stderr_path = stderr
        self.pidfile_path = pidfile
        self.pidfile_timeout = 5
        # self.pidfile_timeout = 0

        self.logger = logger
        self.interface = interface

        if_info = None
        try:
            if_info = ni.ifaddresses(self.interface)
        except ValueError as e:
            self.logger.error("An error concerning the interface {} has occurred: {}".format(self.interface, str(e)))
            raise DaemonError()

        # get ip of specified interface
        self.ip = if_info[2][0]['addr']
        # get subnetmask of specified interface
        self.netmask = if_info[2][0]['netmask']
        # get mac address of specified interface
        self.mac = if_info[17][0]['addr']

        # get network address
        try:
            self.network = IPNetwork("{}/{}".format(self.ip, self.netmask))
        except AddrFormatError as afe:
            # this should never happen, because values are retrieved via netifaces library
            self.logger.error("A grave error happened during determinig the network: {}".format(str(afe)))
            raise DaemonError()

        # get default gateway
        try:
            self.gateway = ni.gateways()["default"][ni.AF_INET][0]
        except KeyError:
            self.logger.error("No default gateway is configured")
            raise DaemonError()

        # get all ip addresses that are in the specified network
        # and remove network address, broadcast, own ip, gateway ip
        self.ip_range = list(self.network)
        self.ip_range.remove(IPAddress(self.ip))
        self.ip_range.remove(IPAddress(self.gateway))
        self.ip_range.remove(IPAddress(self.network.broadcast))
        self.ip_range.remove(IPAddress(self.network.network))

        try:
            # get MAC address of gateway
            self.gate_mac = util.get_mac(self.gateway, self.interface)
            if not self.gate_mac:
                raise DaemonError()
        except Exception:
            self.logger.error("Unable to get MAC address of Gateway")
            raise DaemonError()
コード例 #6
0
def main():
    conn = pymysql.connect(host='localhost',
                           port=3306,
                           user='******',
                           password='******',
                           db='walmartmoneycard',
                           charset='utf8mb4',
                           cursorclass=pymysql.cursors.DictCursor)
    step_flag = 1
    get_info_success = 0
    register_pp_mac = get_mac()
    current_time = (datetime.datetime.utcnow() +
                    datetime.timedelta(hours=8)).strftime("%Y-%m-%d")
    sql = 'SELECT * from config'
    register_config = fetch_one_sql(conn, sql)
    if register_config:
        # 注册 paypal 账号类型
        paypal_type = register_config['paypal_type']
        # 是否添加卡信息
        add_card = register_config['add_card']
        # 是否添加银行信息
        confirm_bank = register_config['confirm_bank']
        # email 是否注册过卡信息
        is_register_card_email = register_config['is_register_card_email']
        # 账号注册程度: 1 仅注册激活 2 注册绑定银行卡
        created_paypal_account_process = register_config[
            'created_paypal_account_process']
    else:
        step_flag = 0
        print('Missing configuration information!')
    if step_flag == 1:
        if created_paypal_account_process == 0:
            sql = 'SELECT * from email_info where id>7174 and emailIsUsed=%s and created_paypal_account=%s and register_pp_mac=%s'
            register_info = fetch_one_sql(
                conn, sql, (is_register_card_email,
                            created_paypal_account_process, register_pp_mac))
            if register_info:
                get_info_success = 1
                email_id = register_info['id']
                email = register_info['email']
                print(email_id, email)
            else:
                if created_paypal_account_process == 0:
                    sql = 'SELECT * from email_info where id>7174 and emailIsUsed=%s and created_paypal_account=%s and confirm_identity=0 and register_pp_mac="-" order by id desc limit 1'
                    register_info = fetch_one_sql(
                        conn, sql, (is_register_card_email,
                                    created_paypal_account_process))
                    if register_info:
                        get_info_success = 1
                        email_id = register_info['id']
                        email = register_info['email']
                        print(email_id, email)
                        with open('D:\\hostname.ini', 'r',
                                  encoding='utf-8') as fp:
                            hostname = fp.read().strip()
                            print(hostname)
                        sql = 'UPDATE email_info set register_pp_mac=%s, register_machine=%s where email=%s'
                        commit_sql(conn, sql,
                                   (register_pp_mac, hostname, email))
                        change_computer_info.verify()
                    else:
                        print('Not data!')
        if get_info_success == 1:
            email_pwd = register_info['email_pwd']
            paypal_pwd = register_info['email_pwd'] + '@pp'
            recovery_email = register_info['recovery_email']
            card_num = register_info['temporaryCardNumber']
            expiration_date = register_info['expirationData']
            card_csc = register_info['securityCode']
            register_info_id = register_info['register_info_id']
            confirm_identity_state = register_info['confirm_identity']
            confirm_email = register_info['confirm_email']
            created_flag = register_info['created_paypal_account']
            if created_flag > 0:
                login_with_input_box = True
            else:
                login_with_input_box = False
            if is_register_card_email == 0:
                sql = 'SELECT * from register_info where id>34000 and userInfoIsUsed=0 and read_num<4 order by id limit 1'
                personal_info = fetch_one_sql(conn, sql)
            elif is_register_card_email == 1:
                sql = 'SELECT * from register_info where id=%s'
                personal_info = fetch_one_sql(conn, sql, register_info_id)
            if personal_info:
                register_info_id = personal_info['id']
                print(register_info_id)
                try:
                    firstname = personal_info['firstname'].capitalize()
                    lastname = personal_info['lastname'].capitalize()
                    name = firstname + ' ' + lastname
                except:
                    name = ' '
                birthdate = personal_info['birthdate']
                address = personal_info['address']
                city = personal_info['city']
                state = personal_info['state']
                sql = 'SELECT * from state_change where state_abb=%s'
                get_full_state = fetch_one_sql(conn, sql, state)
                if get_full_state:
                    full_state = get_full_state['state_full']
                zip_num = personal_info['zip']
                ssn = personal_info['socialnumber'][-4:]
                phone_num = personal_info['mobilenumber']
            if created_flag <= int(
                    created_paypal_account_process
            ) or confirm_identity_state == 0 or confirm_email == 0:
                config_text = get_path_config()
                proxy_exe = config_text['proxy_exe']
                client_exe = config_text['client_exe']
                proxifier_path = config_text['proxifier_path']
                proxifier_file = config_text['proxifier_file']
                open_proxy_process(client_exe)
                driver = re_driver_and_choice_ip(paypal_type, state, city,
                                                 proxy_exe, proxifier_path,
                                                 proxifier_file)
                if paypal_type == 1:
                    pass
                elif paypal_type == 2:
                    if created_flag == 0:
                        step_flag = paypal_here_page_one(
                            driver, step_flag, firstname, lastname, email,
                            paypal_pwd)
                        if step_flag == 1:
                            here_success = paypal_here_page_two(
                                driver, name, address, city, full_state,
                                zip_num, birthdate, phone_num, ssn)
                            if here_success > -1 and is_register_card_email == 0:
                                sql = sql = 'UPDATE register_info set userInfoIsUsed=1, email_id=%s, read_num=read_num+1 where id=%s'
                                commit_sql(conn, sql,
                                           (email_id, register_info_id))
                            if here_success == 1:
                                account_type = 2
                            elif here_success == 0:
                                account_type = 3
                            if here_success > -1:
                                sql = 'UPDATE email_info set account_type=3, paypal_pwd=%s, register_info_id=%s, created_paypal_time=%s, created_paypal_account=1'
                                commit_sql(conn, sql,
                                           (account_type, paypal_pwd,
                                            register_info_id, current_time))
                                step_flag = 1
                if confirm_email == 0 and step_flag == 1:
                    # 需要进入登录框登录
                    if login_with_input_box:
                        if paypal_type == 2:
                            step_flag = paypal_here_page_one(
                                driver, step_flag, firstname, lastname, email,
                                paypal_pwd, True)
                        login_paypal(driver, email, paypal_pwd)
                    email_type = email.split('@')[-1]
                    if email_type == 'gmail.com':
                        print('Gmail!')
                        login_gmail(driver, conn, email, email_pwd, paypal_pwd,
                                    recovery_email)
                    elif email_type == 'yahoo.com':
                        print('Yahoo!')
                        step_flag = login_yahoo(driver, conn, email, email_pwd,
                                                paypal_pwd, step_flag,
                                                paypal_type)
                        if step_flag == 1:
                            sql = 'UPDATE email_info set confirm_email=1 where email=%s'
                            commit_sql(conn, sql, email)
                time.sleep(3)
                # the_end()
                time.sleep(9999)

            else:
                print('Have already registered!')