• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python all.sr1函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scapy.all.sr1函数的典型用法代码示例。如果您正苦于以下问题:Python sr1函数的具体用法?Python sr1怎么用?Python sr1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: main

def main():
    """
    :return: void()
    """
    seq = 0
    ack = 0
    # Hand Shake
    ip_layer = IP(src=SRC_IP, dst=DST_IP)
    tcp_layer = TCP(dport=PORT, seq=100, flags='S')
    syn_pkg = ip_layer / tcp_layer
    syn_ack_pkg = sr1(syn_pkg)
    if syn_ack_pkg != 0:
        ip_layer = IP(src=SRC_IP, dst=DST_IP)
        tcp_layer = TCP(dport=PORT, seq=syn_ack_pkg[TCP].ack,
                        ack=(syn_ack_pkg[TCP].seq + 1), flags='A')
        ack_pkg = ip_layer / tcp_layer
        seq = syn_ack_pkg[TCP].ack
        ack = syn_ack_pkg[TCP].seq + 1
        send(ack_pkg)
    print "Sould be connected to server by this point"
    # Finish hand-Shake
    ip_layer = IP(src=SRC_IP, dst=DST_IP)
    tcp_layer = TCP(dport=PORT, seq=seq,
                    ack=ack, flags='A')
    msg = raw_input('Enter text here: \n')
    http_msg = 'GET / HTTP/1.1\r\n' + msg + '\r\n'
    print 'http_msg: ' + str(http_msg)
    print 'src_ip: ' + str(SRC_IP)
    enc_msg = hmac.new(KEY,http_msg + SRC_IP, sha256)
    msg2 = http_msg + http_msg + enc_msg.hexdigest() + "\r\n\r\n"
    com_pkg = ip_layer / tcp_layer / msg2
    com_pkg.show()
    com_ans_pkg = sr1(com_pkg)
    com_ans_pkg.show()
开发者ID:alexstolr,项目名称:Cyber-security-defense-of-network-based-environments,代码行数:34,代码来源:q2httpclient.py


示例2: run

	def run(self):
		print "Starting %s %s %d" % (self.name, self.target, self.port)
		i = IP() 
		i.src="%i.%i.%i.%i" % (random.randint(1, 254), random.randint(1,254), random.randint(1, 254), random.randint(1,254))
		i.dst = self.target
		t = ICMP()
		print "Spoofing %s to send ICMP ..." % i.src
		sr1(i/ICMP,verbose=0)
开发者ID:sfluo,项目名称:Mr.Bot,代码行数:8,代码来源:icmpflood.py


示例3: run

	def run(self):
		print "Starting %s %s %d" % (self.name, self.target, self.port)
		i = IP() 
		i.src="%i.%i.%i.%i" % (random.randint(1, 254), random.randint(1,254), random.randint(1, 254), random.randint(1,254))
		i.dst = self.target
		t = TCP()
		t.dport = self.port
		t.flags='S'	
		print "Spoofing %s to send SYN ..." % i.src
		sr1(i/t,verbose=0)
开发者ID:sfluo,项目名称:Mr.Bot,代码行数:10,代码来源:synspoof.py


示例4: unpoison

def unpoison(routerip, target):
    """ get correct MAC for router and send to the target to reset ARP cache """
    hosts = {a.ip : a.mac for a in arp().hosts}

    # if not already in arp cache then ping and try again
    if routerip not in hosts:
        sr1(IP(dst=routerip)/ICMP())
        hosts = {a.ip : a.mac for a in arp().hosts}
    if routerip not in hosts:
        log.warning("Router MAC address not found. Could not remove ARP poison.")
        sys.exit()
    log.info("Unpoison sent to %s for gateway %s at mac address %s" % (target, routerip, hosts[routerip]))
    send(ARP(psrc=routerip, hwsrc=hosts[routerip], pdst=target))
开发者ID:simonm3,项目名称:mim,代码行数:13,代码来源:arp.py


示例5: flagfuzzer

	def flagfuzzer(self, dst, port):
		r = {
			'R':[],		# RST
			'RA':[],	# RST-ACK
			'SA':[],	# SYN-ACK
			'--':[],	# no response
			'??':[]		# ICMP error msgs (?)
		}
		scanflags = ['','F','S','FS','R','RF','RS','RSF','A','AF','AS','ASF','AR','ARF','ARS','ARSF']
		for flagval in scanflags:
			pkt = scapy.IP(dst=dst)
			pkt/= scapy.TCP(dport=port, sport=scapy.RandNum(1024,65535), flags=flagval)
			x = scapy.sr1( pkt, timeout=.5)
			sys.stderr.write(" %s \r" % flagval)
			sent = pkt.sprintf("%TCP.flags%")
			if sent == '':
				sent = '-'
			if x is not None:
				recvd = x.sprintf("%TCP.flags%")
				#self.r[recvd].append(sent+"."+str(x[scapy.IP].ttl))
				r[recvd].append(sent)
			else:
				r['--'].append(sent)
		log.msg("finished")
		del r['--']
		for k in r.keys():
			log.msg("%4s: %s" % (k, " ".join(r[k])))
开发者ID:v-p-b,项目名称:buherablog-packet-fu,代码行数:27,代码来源:pfu.py


示例6: trace

    def trace(self):
        hopCount = 1
        for request in self.echoRequests:
            request[sp.ICMP].id = random.randint(0, 65535)
            respuestas = []
            destinoAlcanzado = False
            for medicion in range(self.tamRafaga):
                for reintento in range(self.cantReintentos):
                    tiempoInicio = time.perf_counter()
                    respuesta = sp.sr1(request,timeout=self.timeout)
                    tiempoFin = time.perf_counter()
                    rtt = tiempoFin - tiempoInicio#TODO chequear que sean milisegundos
                    if respuesta is not None:
                        respuestas.append((respuesta.src, rtt))
                        destinoAlcanzado = self.destino == respuesta.src 
                        break

            hop, rttToHop = self.analizarRespuestas(respuestas)
            #TODO geolocalizar aqui
            self.traced.append({"rtt":rttToHop, "ip_address":hop, "salto_internacional":False, "hop_num":hopCount})
                
            hopCount = hopCount + 1 
            #if hop is not None:
            #    mediciones.append((request.ttl, hop, rttToHop))

            if destinoAlcanzado:
                break
开发者ID:nicoh22,项目名称:personal,代码行数:27,代码来源:rework.py


示例7: monlist_scan

 def monlist_scan(self,target):
     data = "\x17\x00\x03\x2a" + "\x00" * 4
     ip = IP(dst=target)
     udp=UDP(sport=random.randint(49152,65536),dport=123)
     a = Raw(load=data)
     pck = ip/udp/a
     n = 0
     results = None
     #try:
     while (n < 3):
         rep = sr1(pck,verbose=0,timeout=5)
         if hasattr(rep,'answers'):
             results = 1
             break
         elif not hasattr(rep,'answers') and (n < 3):
             #print "Pass ",n
             n = n + 1
         else:
             results = None
             break
             pass
     #except KeyboardInterrupt:
     #    sys.exit(0)
     #except Exception as e:
 #        results = None
         #print e
     return results
开发者ID:trylinux,项目名称:lift,代码行数:27,代码来源:ntp_function.py


示例8: run

    def run(self, state, pkt, wait,timeout=None):
        """Send pkt, receive the answer if wait is True, and return a tuple
        (validity of reply packet, reply packet). If no test function is
        given, assume it's valid."""
        self.dbgshow(pkt)
        if wait: # do we wait for a reply ?
            self.debug("Waiting for packet...", level=2)
            if pkt is None:
                timeout, buffermode = None, False
                if type(wait) is tuple:
                    wait, timeout, buffermode = wait
                    #print wait
                    #wait, buffermode = wait
                if hasattr(wait, '__call__'):
                    ans = self.waitForPacket(filterfct=wait, timeout=timeout)
#                     if buffermode: # ans is a buffer (list)
#                         self.debug("Entering buffer mode.", level=1)
#                         return [self.packetReceived(pkt,buffermode=True) for pkt in ans]
                else:
                    raise Exception("error, no packet generated.")
            else:
                #TODO: Make sure this waits continuously in a non blocking mode, convert this to dumping from a queue
                ans=sr1(pkt)
        else:
            send(pkt)
            #print pkt
            self.first = True # prev_pkt shouldnt be taken into account
            self.debug("Packet sent, no waiting, going on with next.",2)
            return (True, None) # no reply, no check
        return self.packetReceived(ans) # post-reply actions
开发者ID:Neohapsis,项目名称:mptcp-abuse,代码行数:30,代码来源:core.py


示例9: checkInterfaces

def checkInterfaces(ifaces=None, timeout=1):
    """
    @param ifaces:
        A dictionary in the form of ifaces['if_name'] = 'if_addr'.
    """
    try:
        from scapy.all import IP, ICMP
        from scapy.all import sr1  ## we want this check to be blocking
    except:
        log.msg(("Scapy required: www.secdev.org/projects/scapy"))

    ifup = {}
    if not ifaces:
        log.debug("checkInterfaces(): no interfaces specified!")
        return None

    for iface in ifaces:
        for ifname, ifaddr in iface:
            log.debug("checkInterfaces(): testing iface {} by pinging"
                      + " local address {}".format(ifname, ifaddr))
            try:
                pkt = IP(dst=ifaddr) / ICMP()
                ans, unans = sr1(pkt, iface=ifname, timeout=5, retry=3)
            except Exception, e:
                raise PermissionsError if e.find("Errno 1") else log.err(e)
            else:
                if ans.summary():
                    log.debug("checkInterfaces(): got answer on interface %s"
                              + ":\n%s".format(ifname, ans.summary()))
                    ifup.update(ifname, ifaddr)
                else:
                    log.debug("Interface test packet was unanswered:\n%s"
                              % unans.summary())
开发者ID:kudrom,项目名称:ooni-probe,代码行数:33,代码来源:net.py


示例10: scanTCPPort

def scanTCPPort(ip, port_dict, queue):
	while True:

		dst_port = queue.get()
		src_port = scapy.RandShort()
	
		packet = scapy.IP(dst=ip)/scapy.TCP(sport=src_port, dport=dst_port, flags="S")
		response = scapy.sr1(packet, verbose=False, timeout=5)

		if response is None:
			port_dict[dst_port]="Closed"
	
		elif(response.haslayer(scapy.TCP)):

			# If the packet returned had the SYN and ACK flags
			if(response.getlayer(scapy.TCP).flags == 0x12):
				# Send TCP packet back to host with ACK and RST flags
				packet = scapy.IP(dst=ip)/scapy.TCP(sport=src_port,dport=dst_port,flags=0x14)
				send_rst = scapy.sr(packet, verbose=False, timeout=5)
				port_dict[dst_port]="Open"

			# If the packet returned had the RST and ACK flags
			elif (response.getlayer(scapy.TCP).flags == 0x14):
				port_dict[dst_port]="Closed"
		else:
			port_dict[dst_port]="Closed"

		queue.task_done()
开发者ID:trhoy,项目名称:multithreaded_port_scanner,代码行数:28,代码来源:simple_port_scanner.py


示例11: add_a_record

def add_a_record(name_server, new_dns_record, ip_value):

    os.system('clear')
    title()

    # Verifying all required options have a populated value
    if name_server is None or new_dns_record is None or ip_value is None:
        print "[*] ERROR: You did not provide all the required command line options!"
        print "[*] ERROR: Please re-run with required options."
        sys.exit()

    print "[*] Crafting packet for record injection..."
    print "[*] Sending DNS packet adding " + new_dns_record
    print "[*] and pointing it to " + ip_value + "\n"

    dns_zone = new_dns_record[new_dns_record.find(".")+1:]

    # Craft the packet with scapy
    add_packet = sr1(IP(dst=name_server)/UDP()/DNS(
        opcode=5,
        qd=[DNSQR(qname=dns_zone, qtype="SOA")],
        ns=[DNSRR(rrname=new_dns_record,
            type="A", ttl=120, rdata=ip_value)]))

    print add_packet[DNS].summary()

    print "\n[*] Packet created and sent!"
开发者ID:B-Rich,项目名称:PenTestScripts,代码行数:27,代码来源:DNSInject.py


示例12: check_ip

    def check_ip(self, url=None, original_ip=None, neutral_dns_ip="8.8.8.8"):
        url = self.url if url is None else url
        original_ip = self.original_ip if original_ip is None else original_ip

        if self.ip == original_ip:
            self.log.info('IP is the same, DNS poisoning NOT detected (url: {})'.format(url))
            return True
        else:
            self.log.warning('Different IP detected: {}'.format(self.ip))
            dns_search = None
            try:
                dns_search = sr1(IP(dst=neutral_dns_ip) / UDP(dport=53) / DNS(rd=1, qd=DNSQR(qname=url)), verbose=0)
            except OSError as oserr:
                self.log.error('Error while trying to connect to DNS for URL {}: {}'. format(url, oserr))
                return False
            except Exception as exerr:
                self.log.error('Unexpected error in DNS check, URL {}: {}'.format(url, exerr))
                return False

            if dns_search is None or dns_search[DNSRR].rrname == '.':
                self.log.warning('URL ({}) not found in neutral DNS.'.format(url))
                return False

            obtained_ip = dns_search[DNSRR].rdata
            if original_ip == obtained_ip:
                self.log.warning('Neutral DNS returns original IP - DNS poisoning detected for URL {}'.format(url))
            elif self.ip == obtained_ip:
                self.log.warning('Neutral DNS returns given IP - maybe original IP not correct for URL {}'.format(url))
                return True
            else:
                self.log.warning('Unexpectedly, given IP is totally different: URL {} - IP {}'.format(url, obtained_ip))
            return False
开发者ID:alicenara,项目名称:CAT,代码行数:32,代码来源:TestWebsite.py


示例13: delete_dns_record

def delete_dns_record(del_ns, del_record):

    os.system('clear')
    title()

    # Verifying all required options have a populated value
    if del_ns is None or del_record is None:
        print "[*] ERROR: You did not provide all the required command line options!"
        print "[*] ERROR: Please re-run with required options."
        sys.exit()
    print "[*] Crafting packet for record deletion..."

    print "[*] Sending packet which deletes the following record: "
    print "[*] " + del_record + "\n"

    dns_zone = del_record[del_record.find(".")+1:]

    del_packet = sr1(IP(dst=del_ns)/UDP()/DNS(
        opcode=5,
        qd=[DNSQR(qname=dns_zone, qtype="SOA")],
        ns=[DNSRR(rrname=del_record, type="ALL",
                  rclass="ANY", ttl=0, rdata="")]))

    print del_packet[DNS].summary()

    print "\n[*] Packet created and sent!"
开发者ID:B-Rich,项目名称:PenTestScripts,代码行数:26,代码来源:DNSInject.py


示例14: run

	def run(self):
		while True:
			port = self.queue.get()
			answer = sr1(IP(dst=dstip)/TCP(dport=port,flags='S'),timeout=1,verbose=0)
			if answer['TCP'].flags == 18:
				print "Port %s open" % port
			self.queue.task_done()
开发者ID:jgrmnprz,项目名称:spse,代码行数:7,代码来源:scanr.py


示例15: main

def main(argv):
    print argv
    for i in xrange(1, 10):
        print "TTL:", i
        pkt = IP(dst=sys.argv[1], ttl=i) / ICMP()
        for j in xrange(1):
            res = sr1(pkt, timeout=5)
            print res
开发者ID:ltdicai,项目名称:tdc-tp2,代码行数:8,代码来源:enviar.py


示例16: pingIP

def pingIP(ip, active_ips):
	packet = scapy.IP(dst=ip, ttl=20)/scapy.ICMP()
	reply = scapy.sr1(packet, timeout=1, verbose=False)
	
	if not (reply is None):
		print ip, " is up."
		active_ips.append(ip)
	return
开发者ID:trhoy,项目名称:multithreaded_port_scanner,代码行数:8,代码来源:simple_port_scanner.py


示例17: handle_one

def handle_one(p, iface, timeout):
    print p.show()
    reply = sr1(p, iface=iface, retry=0, timeout=timeout)

    if reply:
        print reply.show()
        if reply.opcode != 128 and reply.ext_port > 0:
            print 'got', reply.ext_ip, reply.ext_port
开发者ID:fingon,项目名称:hnet-ttin,代码行数:8,代码来源:pcp_map.py


示例18: run

 def run(self):
   for ip in self.ips:
     if(self.STOP==False):
       p = IP(dst=ip)/ICMP()
       res = sr1(p, timeout=2)
       GObject.idle_add(self.update, (p, res))
     else:
       break
开发者ID:bennesp,项目名称:PyLanDiscovery,代码行数:8,代码来源:ICMP.py


示例19: rr_tcp

	def rr_tcp(self, dst, dport):
		pkt = scapy.IP(dst=dst, proto=6, options=scapy.IPOption('\x01\x07\x27\x04' + '\x00'*36))
		pkt/= scapy.TCP(sport=scapy.RandNum(1024,65535), dport=int(dport), flags="S",window=8192,
				options=[('MSS', 1460), ('NOP', None), ('WScale', 2), ('NOP', None),
					 ('NOP', None), ('SAckOK', '')])
		intr_tcp = scapy.sr1(pkt, timeout=2)
		if intr_tcp is not None:
			return intr_tcp.options[0].routers
开发者ID:v-p-b,项目名称:buherablog-packet-fu,代码行数:8,代码来源:pfu.py


示例20: _syn_scan

def _syn_scan(host, port, timeout):

    pkt = IP(dst=host) / TCP(dport=port,flags="S")
    pkt = sr1(pkt, timeout=timeout)

    if pkt is None:
        return None

    return pkt.getlayer(TCP).flags
开发者ID:rata,项目名称:redes-tps,代码行数:9,代码来源:scans.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python all.srp函数代码示例发布时间:2022-05-27
下一篇:
Python all.sniff函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap