def make_reply(self, req): ip = req.getlayer(IP) dns = req.getlayer(DNS) resp = IP(dst=ip.src, src=ip.dst)/UDP(dport=ip.sport,sport=ip.dport) rdata = self.match.get(dns.qd.qname, self.joker) resp /= DNS(id=dns.id, qr=1, qd=dns.qd, an=DNSRR(rrname=dns.qd.qname, ttl=10, rdata=rdata)) return resp
def dhcp_request(iface=None, **kargs): if conf.checkIPaddr != 0: warning( "conf.checkIPaddr is not 0, I may not be able to match the answer") if iface is None: iface = conf.iface hw = get_if_raw_hwaddr(iface) return srp1(Ether(dst="ff:ff:ff:ff:ff:ff") / IP(src="0.0.0.0", dst="255.255.255.255") / UDP(sport=68, dport=67) / BOOTP(chaddr=hw) / DHCP(options=[("message-type", "discover"), "end"]), iface=iface, **kargs)
def dyndns_del(nameserver, name, type="ALL", ttl=10): """Send a DNS delete message to a nameserver for "name" dyndns_del(nameserver, name, type="ANY", ttl=10) -> result code (0=ok) example: dyndns_del("ns1.toto.com", "dyn.toto.com") RFC2136 """ zone = name[name.find(".")+1:] r=sr1(IP(dst=nameserver)/UDP()/DNS(opcode=5, qd=[DNSQR(qname=zone, qtype="SOA")], ns=[DNSRR(rrname=name, type=type, rclass="ANY", ttl=0, rdata=b"")]), verbose=0, timeout=5) if r and r.haslayer(DNS): return r.getlayer(DNS).rcode else: return -1
def dyndns_add(nameserver, name, rdata, type="A", ttl=10): """Send a DNS add message to a nameserver for "name" to have a new "rdata" dyndns_add(nameserver, name, rdata, type="A", ttl=10) -> result code (0=ok) example: dyndns_add("ns1.toto.com", "dyn.toto.com", "127.0.0.1") RFC2136 """ zone = name[name.find(".")+1:] r=sr1(IP(dst=nameserver)/UDP()/DNS(opcode=5, qd=[DNSQR(qname=zone, qtype="SOA")], ns=[DNSRR(rrname=name, type="A", ttl=ttl, rdata=rdata)]), verbose=0, timeout=5) if r and r.haslayer(DNS): return r.getlayer(DNS).rcode else: return -1
def make_reply(self, req): mac = req.src if type(self.pool) is list: if not mac in self.leases: self.leases[mac] = self.pool.pop() ip = self.leases[mac] else: ip = self.pool repb = req.getlayer(BOOTP).copy() repb.op = "BOOTREPLY" repb.yiaddr = ip repb.siaddr = self.gw repb.ciaddr = self.gw repb.giaddr = self.gw del (repb.payload) rep = Ether(dst=mac) / IP(dst=ip) / UDP(sport=req.dport, dport=req.sport) / repb return rep
def execute_protocol(self): self.prtcol_result.clear() try: option = str(self.select_protocol.currentText()) url = str(self.packet_url.toPlainText()) if option == "ICMP": ar = [] request = IP(dst=url) / ICMP() ar = request.default_fields self.prtcol_result.insertPlainText('version :' + str(ar['version']) + "\n") self.prtcol_result.insertPlainText('ihl :' + str(ar['ihl']) + "\n") self.prtcol_result.insertPlainText('tos :' + str(ar['tos']) + "\n") self.prtcol_result.insertPlainText('len :' + str(ar['len']) + "\n") self.prtcol_result.insertPlainText('id :' + str(ar['id']) + "\n") self.prtcol_result.insertPlainText('frag :' + str(ar['frag']) + "\n") self.prtcol_result.insertPlainText('ttl :' + str(ar['ttl']) + "\n") self.prtcol_result.insertPlainText('chksum:' + str(ar['chksum']) + "\n") elif option == "ARP": ar = [] request = sniff(count=1, filter="arp") ar = request.res[0].fields self.prtcol_result.insertPlainText('src :' + str(ar['src']) + "\n") self.prtcol_result.insertPlainText('dst :' + str(ar['dst']) + "\n") self.prtcol_result.insertPlainText('type :' + str(ar['type']) + "\n") except Exception as e: errmsg(e)
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
def ikev2scan(ip): return sr( IP(dst=ip) / UDP() / IKEv2(init_SPI=RandString(8), exch_type=34) / IKEv2_payload_SA(prop=IKEv2_payload_Proposal()))
def ikescan(ip): return sr(IP(dst=ip)/UDP()/ISAKMP(init_cookie=RandString(8), exch_type=2)/ISAKMP_payload_SA(prop=ISAKMP_payload_Proposal()))