Skip to content

Instantly share code, notes, and snippets.

@Erreinion
Created March 9, 2015 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erreinion/4966eb6165419e1b3dfc to your computer and use it in GitHub Desktop.
Save Erreinion/4966eb6165419e1b3dfc to your computer and use it in GitHub Desktop.
Generate a variety of traffic types to various targets. Intended for firewall testing.
#! /usr/bin/env python
import sys
from os import path
import logging
# needed to remove warnings from scapy, even on import
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
app_name = path.basename(sys.argv[0])
if (len(sys.argv) != 2):
print "Usage: " + app_name + " < number of loops | 0 >"
sys.exit(1)
try:
loops = int(sys.argv[1])
except:
raise TypeError('Must use an int for the number of loops')
sys.exit(1)
# Targets
pinglist = ["www.google.com", "www.facebook.com", "8.8.8.8"]
httplist = ["www.google.com", "www.facebook.com"]
httpslist = ["www.google.com", "www.facebook.com"]
ftplist = []
sshlist = ["alt.org", "thebes.openshells.net"]
icmp_tag = "XXXXXXXXXXX"
infinite = False
loops = 1
if loops == 0:
infinite = True
loops = 1
# logging parameters
logger = logging.getLogger(app_name)
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s: %(name)s - %(levelname)s - %(message)s')
grenade_handler = logging.StreamHandler()
grenade_handler.setLevel(logging.INFO)
grenade_handler.setFormatter(formatter)
logger.addHandler(grenade_handler)
# logging function
def my_logging (result, destination, protocol):
if result == True:
result_caps = "[SUCCESS]"
elif result == False:
result_caps = "[FAIL]"
logger.info(result_caps + " " + protocol + " " + destination)
return
def send_receive_ICMP (list):
for d in list:
# send crafted packet and store response
pkt = sr1(IP(dst = d)/ICMP()/icmp_tag, verbose=False)
if pkt.load == icmp_tag:
result = True
else:
result = False
my_logging(result, d, "icmp")
def send_receive (list, port, protocol):
for d in list:
# send crafted packet and store response
pkt = sr1(IP(dst = d)/TCP(dport = port), verbose=False)
if pkt.ack == 1 and pkt.sport == port:
result = True
else:
result = False
my_logging(result, d, protocol)
while loops:
send_receive_ICMP(pinglist)
send_receive(httplist, 80, "http")
send_receive(httpslist, 443, "https")
send_receive(sshlist, 22, "ssh")
if not infinite:
loops = loops - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment