本文整理汇总了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
示例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())
])
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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.
示例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())
])
示例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 ########
#################################################
示例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
示例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
示例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