當前位置: 首頁>>代碼示例>>Python>>正文


Python inet.TCP屬性代碼示例

本文整理匯總了Python中scapy.layers.inet.TCP屬性的典型用法代碼示例。如果您正苦於以下問題:Python inet.TCP屬性的具體用法?Python inet.TCP怎麽用?Python inet.TCP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在scapy.layers.inet的用法示例。


在下文中一共展示了inet.TCP屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: queso_sig

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def queso_sig(target, dport=80, timeout=3):
    p = queso_kdb.get_base()
    ret = []
    for flags in ["S", "SA", "F", "FA", "SF", "P", "SEC"]:
        ans, unans = sr(IP(dst=target)/TCP(dport=dport,flags=flags,seq=RandInt()),
                        timeout=timeout, verbose=0)
        if len(ans) == 0:
            rs = "- - - -"
        else:
            s,r = ans[0]
            rs = "%i" % (r.seq != 0)
            if not r.ack:
                r += " 0"
            elif r.ack-s.seq > 666:
                rs += " R" % 0
            else:
                rs += " +%i" % (r.ack-s.seq)
            rs += " %X" % r.window
            rs += " %x" % r.payload.flags
        ret.append(rs)
    return ret 
開發者ID:medbenali,項目名稱:CyberScan,代碼行數:23,代碼來源:queso.py

示例2: __init__

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def __init__(self):
        """
        Creates a new instance of the PortscanAttack.
        This attack injects TCP Syn-requests and respective responses into the output pcap file.
        """
        # Initialize attack
        super(PortscanAttack, self).__init__("Portscan Attack", "Injects a nmap 'regular scan'",
                                             "Scanning/Probing")

        # Define allowed parameters and their type
        self.update_params([
            Parameter(self.IP_SOURCE, IPAddress()),
            Parameter(self.IP_DESTINATION, IPAddress()),
            Parameter(self.PORT_SOURCE, Port()),
            Parameter(self.PORT_DESTINATION, Port()),
            Parameter(self.PORT_OPEN, Port()),
            Parameter(self.MAC_SOURCE, MACAddress()),
            Parameter(self.MAC_DESTINATION, MACAddress()),
            Parameter(self.PORT_DEST_SHUFFLE, Boolean()),
            Parameter(self.PORT_DEST_ORDER_DESC, Boolean()),
            Parameter(self.IP_SOURCE_RANDOMIZE, Boolean()),
            Parameter(self.PACKETS_PER_SECOND, Float()),
            Parameter(self.PORT_SOURCE_RANDOMIZE, Boolean())
        ]) 
開發者ID:tklab-tud,項目名稱:ID2T,代碼行數:26,代碼來源:PortscanAttack.py

示例3: get_int_pkt

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def get_int_pkt(self, pkt, instructions, max_hop, transit_hops=0, hop_metadata=None):
        proto = UDP if UDP in pkt else TCP
        int_pkt = pkt.copy()
        int_pkt[IP].tos = 0x04
        shim_len = 4 + len(instructions) * transit_hops
        int_shim = INT_L45_HEAD(int_type=1, length=shim_len)
        int_header = INT_META_HDR(
            ins_cnt=len(instructions),
            max_hop_cnt=max_hop,
            total_hop_cnt=transit_hops,
            inst_mask=self.get_ins_mask(instructions))
        int_tail = INT_L45_TAIL(next_proto=pkt[IP].proto, proto_param=pkt[proto].dport)
        metadata = "".join([hop_metadata] * transit_hops)
        int_payload = int_shim / int_header / metadata / int_tail
        int_pkt[proto].payload = int_payload / int_pkt[proto].payload
        return int_pkt 
開發者ID:opennetworkinglab,項目名稱:fabric-p4test,代碼行數:18,代碼來源:fabric_test.py

示例4: makeMPCapableSyn

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def makeMPCapableSyn(sourceAddr,dport,dstAddr, sport=None, initTCPSeq=None, \
                     sendKey=None):

    if sport is None: sport = randintb(16)
    if initTCPSeq is None: initTCPSeq = randintb(32)
    if sendKey is None: sendKey = randintb(32)
    #TODO: make more elegant type handling for IPADDR
    dstAddr = str(dstAddr)


    pkt = (IP(version=4L,src=sourceAddr,dst=dstAddr)/        \
        TCP(sport=sport,dport=dport,flags="S",seq=initTCPSeq, \
        options=[TCPOption_MP(mptcp=MPTCP_CapableSYN(
                            checksum_req=1,
                            snd_key=sendKey))]))
    return pkt 
開發者ID:Neohapsis,項目名稱:mptcp-abuse,代碼行數:18,代碼來源:mptcp_scanner.py

示例5: makeJoinSyn

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def makeJoinSyn(sourceAddr,dport,dstAddr, sport=None, initTCPSeq=None, \
                mptcpAddrId=None,isBackupFlow=False, \
                rcvToken=None,sendNonce=None):

    if sport is None: sport = randintb(16)
    if sendNonce is None: sendNonce = randintb(32)
    if initTCPSeq is None: initTCPSeq = randintb(32)
    if rcvToken is None: rcvToken = randintb(32)
    if sendNonce is None: sendNonce = randintb(32)
    if mptcpAddrId is None: mptcpAddrId = randintb(8)
    #TODO: make more elegant type handling for IPADDR
    dstAddr = str(dstAddr)

    pkt = (IP(version=4L,src=sourceAddr,dst=dstAddr)/        \
        TCP(sport=sport,dport=dport,flags="S",seq=initTCPSeq, \
        options=[TCPOption_MP(mptcp=MPTCP_JoinSYN(
                            addr_id=mptcpAddrId,
                            backup_flow=isBackupFlow,
                            rcv_token=rcvToken,
                            snd_nonce=sendNonce,))]))

    return pkt 
開發者ID:Neohapsis,項目名稱:mptcp-abuse,代碼行數:24,代碼來源:mptcp_scanner.py

示例6: checkMPTCPSupportViaRST

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def checkMPTCPSupportViaRST(port,target,timeout,localIP,MpCapAlreadyPassed=False):
    MpCapPassed = MpCapAlreadyPassed
    #TODO: Abstract this out more elegantly so i dont repeat code from elsewhere
    if not MpCapPassed:
        pkt = makeMPCapableSyn(localIP, port, target)
        response=sr1(pkt,timeout=timeout)
        if response and getMpOption(pkt.getlayer("TCP")) is not None:
            MpCapPassed = True

    if MpCapPassed:
        pkt = makeJoinSyn(localIP, port, target)
        response=sr1(pkt,timeout=timeout)
        #TODO: Add checks for other types of response (such as ICMP)
        #TODO: Make this clearer

        #Check for the flag with a mask
        print response.getlayer("TCP").flags
        if (0x04 & response.getlayer("TCP").flags) == 0x04:
            print "RST Test indicates MPTCP support"
            return True
        else:
            print "RST Test indicates host doesn't understand MPTCP"
            return False 
開發者ID:Neohapsis,項目名稱:mptcp-abuse,代碼行數:25,代碼來源:mptcp_scanner.py

示例7: pre_dissect

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def pre_dissect(self, s):
        """
        Check that a valid DNS over TCP message can be decoded
        """
        if isinstance(self.underlayer, TCP):

            # Compute the length of the DNS packet
            if len(s) >= 2:
                dns_len = struct.unpack("!H", s[:2])[0]
            else:
                message = "Malformed DNS message: too small!"
                warning(message)
                raise Scapy_Exception(message)

            # Check if the length is valid
            if dns_len < 14 or len(s) < dns_len:
                message = "Malformed DNS message: invalid length!"
                warning(message)
                raise Scapy_Exception(message)

        return s


# https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4 
開發者ID:secdev,項目名稱:scapy,代碼行數:26,代碼來源:dns.py

示例8: guess_payload_class

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def guess_payload_class(self, pkt):
        d_port = s_port = True
        if self.underlayer and isinstance(self.underlayer, TCP):
            ports = conf.contribs['socks']['serverports']
            d_port = self.underlayer.dport in ports
            s_port = self.underlayer.sport in ports
        if self.vn == 0x5:
            if d_port:
                return SOCKS5Request
            elif s_port:
                return SOCKS5Reply
        elif self.vn == 0x4:
            if d_port:
                return SOCKS4Request
        elif self.vn == 0x0:
            if s_port:
                return SOCKS4Reply
        warning("No TCP underlayer, or dport/sport not in "
                "conf.contribs['socks']['serverports']. "
                "Assuming a SOCKS v5 request layer")
        return SOCKS5Request 
開發者ID:secdev,項目名稱:scapy,代碼行數:23,代碼來源:socks.py

示例9: tcp_syn

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def tcp_syn(src_ip, dst_ip, port):
    tcp_syn_p = TCP(dport=port, flags="S", window=29200, seq=random.randint(0, 100000), sport=random.randint(40000, 60000), options=[('MSS', 1460), ('SAckOK', ''), ('Timestamp', (147229543, 0)), ('NOP', None), ('WScale', 7)])

    syn = LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03) \
               / SNAP(OUI=0x000000, code=ETH_P_IP) \
               / IP(src=src_ip, dst=dst_ip, flags=0x02, tos=0x10, len=(20 + len(tcp_syn_p))) \
               / tcp_syn_p
    syn = LLC(str(syn))

    #syn.show()

    return syn


# 802.11 Beacon frame
# TODO: Fix me; duplicate code 
開發者ID:rpp0,項目名稱:aggr-inject,代碼行數:18,代碼來源:packets.py

示例10: __init__

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def __init__(self, src, dst, sport, dport):
        super(TCP64State, self).__init__(src, dst, sport, dport, PROTO_TCP)
        ip4dst = ipaddress.ip_address(ipaddress.ip_address(dst).packed[-4:])
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind(("0.0.0.0", TCP64State.tcp_port))
        sock.settimeout(1.0)
        sock.connect((str(ip4dst), dport))
        self.sock = sock
        self.state = TCP_INIT
        self.ack = 0
        self.seq = 4711
        self.window = 1200
        self.mss = 1200
        log.debug("TCP opening ", ip4dst, dport, sock)
        TCP64State.tcp_port = TCP64State.tcp_port + 1

    # Handle TCP state - forward data from socket to tun. 
開發者ID:joakimeriksson,項目名稱:ai-smarthome,代碼行數:20,代碼來源:nat64.py

示例11: __init__

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def __init__(self):
        """
        Creates a new instance of the SMBScanAttack.
        This Attack injects TCP Syn Requests to the port 445 of several ips and related response into the output
        pcap file.
        If port 445 is open, it will simulate and inject the SMB Protocol Negotiation too.
        """
        # Initialize attack
        super(SMBScanAttack, self).__init__("SMBScan Attack", "Injects an SMB scan",
                                            "Scanning/Probing")

        self.host_os = Util.get_rnd_os()

        # Define allowed parameters and their type
        self.update_params([
            Parameter(self.IP_SOURCE, IPAddress()),
            Parameter(self.IP_DESTINATION, IPAddress()),
            Parameter(self.MAC_DESTINATION, MACAddress()),
            Parameter(self.TARGET_COUNT, IntegerPositive()),
            Parameter(self.HOSTING_PERCENTAGE, Percentage()),
            Parameter(self.PORT_SOURCE, Port()),
            Parameter(self.MAC_SOURCE, MACAddress()),
            Parameter(self.IP_SOURCE_RANDOMIZE, Boolean()),
            Parameter(self.PACKETS_PER_SECOND, Float()),
            Parameter(self.PORT_SOURCE_RANDOMIZE, Boolean()),
            Parameter(self.HOSTING_IP, IPAddress()),
            Parameter(self.HOSTING_VERSION, String()),
            Parameter(self.SOURCE_PLATFORM, SpecificString(Util.platforms)),
            Parameter(self.PROTOCOL_VERSION, String())
        ]) 
開發者ID:tklab-tud,項目名稱:ID2T,代碼行數:32,代碼來源:SMBScanAttack.py

示例12: _random_mac

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def _random_mac(self) -> str:
        mac_bytes = bytearray(getrandbits(8) for i in range(6))
        if not self.broadcast:
            mac_bytes[0] &= ~1  # clear the first bytes' first bit
        if not self.virtual:
            mac_bytes[0] &= ~2  # clear the first bytes' second bit

        return ":".join("%02X" % b for b in mac_bytes)


#################################################
########    UDP/TCP Packet generation    ########
################################################# 
開發者ID:tklab-tud,項目名稱:ID2T,代碼行數:15,代碼來源:Generator.py

示例13: generate_packet

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def generate_packet(self, ip_src: str = "192.168.64.32", ip_dst: str = "192.168.64.48",
                        mac_src: str = "56:6D:D9:BC:70:1C",
                        mac_dst: str = "F4:2B:95:B3:0E:1A", port_src: int = 1337, port_dst: int = 6442, ttl: int = 64,
                        tcpflags: str = "S", payload: str = ""):
        """
        Creates a Packet with the specified Values for the current protocol

        :param ip_src: the source IP address of the IP header
        :param ip_dst the destination IP address of the IP header
        :param mac_src: the source MAC address of the MAC header
        :param mac_dst: the destination MAC address of the MAC header
        :param port_src: the source port of the header
        :param port_dst: the destination port of the header
        :param ttl: the ttl Value of the packet
        :param tcpflags: the TCP flags of the TCP header
        :param payload: the payload of the packet
        :return: the corresponding packet
        """

        if self.protocol == "udp":
            packet = generate_udp_packet(ip_src=ip_src, ip_dst=ip_dst, mac_src=mac_src, mac_dst=mac_dst, ttl=ttl,
                                         port_src=port_src, port_dst=port_dst, payload=payload)
        elif self.protocol == "tcp":
            packet = generate_tcp_packet(ip_src=ip_src, ip_dst=ip_dst, mac_src=mac_src, mac_dst=mac_dst, ttl=ttl,
                                         port_src=port_src, port_dst=port_dst, tcpflags=tcpflags, payload=payload)
        return packet 
開發者ID:tklab-tud,項目名稱:ID2T,代碼行數:28,代碼來源:Generator.py

示例14: pre_dissect

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def pre_dissect(self, raw_bytes):
        # figure out if we're UDP or TCP
        if self.underlayer is not None and self.underlayer.haslayer(UDP):
            self.guessed_next_layer = DTLSRecord
        elif ord(raw_bytes[0]) & 0x80:
            self.guessed_next_layer = SSLv2Record
        else:
            self.guessed_next_layer = TLSRecord
        return raw_bytes 
開發者ID:tintinweb,項目名稱:scapy-ssl_tls,代碼行數:11,代碼來源:ssl_tls.py

示例15: getMpOption

# 需要導入模塊: from scapy.layers import inet [as 別名]
# 或者: from scapy.layers.inet import TCP [as 別名]
def getMpOption(tcp):
    """Return a generator of mptcp options from a scapy TCP() object"""
    for opt in tcp.options:
        if opt.kind == 30:
            yield opt.mptcp

#From mptcptestlib 
開發者ID:Neohapsis,項目名稱:mptcp-abuse,代碼行數:9,代碼來源:mptcp_scanner.py


注:本文中的scapy.layers.inet.TCP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。