scapy scripts

Статья для понимания: http://linkmeup.ru/blog/121.html

Несколько примеров скриптов для scapy.
Функция, генерирующая ip пакетики с рандомным source mac:

def gen(count) :
 for n in xrange(count) :
  srcMAC = "00"+str(RandMAC())[2:]
  dstMAC = "00:1B:FC:00:00:00"
  print srcMAC + " " + str(n)
  pkt = Ether(src=srcMAC, dst=dstMAC)/IP(src="127.0.0.1",dst="10.111.111.190")/Padding(load="X"*18)
  sendp(pkt, verbose=0)
return

Вызов функции:
>>> gen(10)
00:66:71:97:09:04 0
00:6d:b4:34:16:a3 1
00:10:7b:43:b6:55 2
00:ee:3a:cb:6d:8a 3
00:43:95:b6:2d:f8 4
00:88:6e:92:96:01 5
00:94:aa:e3:c4:b0 6
00:78:bd:28:66:47 7
00:50:a8:26:c0:1c 8
00:cd:60:be:08:bd 9
>>>

Функция, генерирующая ip пакетики с рандомным source mac и тэгом 802.1q:

def gen(count) :
  for n in xrange(count) :
    srcMAC = "00"+str(RandMAC())[2:]
    dstMAC = "00:1B:FC:00:00:01"
    vtag = random.randint(1,4094)
    print srcMAC + "\t"+ str(vtag) + "\t" + str(n)
    pkt = Ether(src=srcMAC, dst=dstMAC)/Dot1Q(vlan=vtag)/IP(src="127.0.0.1",dst="10.111.111.190")/Padding(load="X"*18)
    sendp(pkt, verbose=0)

Генерация пакетов с маками различающимися на единицу:

for n in xrange(1000) :
 oct1 = 0
 oct2 = 0
 oct3 = 0
 if ((n//256 >= 1) and (n//256 < 256)) :
  oct1 = n//256
  srcMAC= "00:00:00:00:"+ str(hex(oct1)[2:]) +":"+ str(hex(n%256)[2:])
  dstMAC = "00:1B:FC:00:00:00"
  print srcMAC + " " + str(n)
  pkt = Ether(src=srcMAC, dst=dstMAC)/IP(src="127.0.0.1",dst="10.111.111.190")/Padding(load="X"*18)
  sendp(pkt, verbose=0)
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s