Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
6001CEM/defender.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
91 lines (59 sloc)
2.08 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scapy.all import * | |
import requests | |
import netifaces as ni | |
import getpass | |
import telnetlib | |
def check_pragma_attack(request): | |
pragma_count = 0 | |
value = request.headers | |
if ('PRAGMA' not in value): | |
print("PRAGMA header not detected") | |
return False | |
else: | |
print("PRAGMA header detected") | |
pragma_count += pragma_count | |
pragma_value = request.headers["PRAGMA"] | |
if (int(content_length) <= 2000000): | |
print("WARNING !") | |
return True | |
else: | |
return False | |
def check_availability(url): | |
response = requests.get(url) | |
if (response.status_code != 503): | |
print("{0}: Available".format(url)) | |
print("Resuming .../") | |
return True | |
def check_http_post_attack(request): | |
value = request.headers | |
if ('Content-Length' not in value): | |
return True | |
else: | |
content_length = request.headers["Content-Length"] | |
if (int(content_length) <= 2000000): | |
print("Content length is fine") | |
print("Resuming .../") | |
return True | |
else: | |
return False | |
if __name__ == "__main__": | |
network_interface = "br-abfe242530cd" # CHANGE THIS TO THE CONNECTED NETWORK INTERFACE | |
ip = ni.ifaddresses(network_interface)[ni.AF_INET][0]['addr'] | |
url = "http://{0}:5000".format(ip) | |
HOST = "localhost" | |
user = "USER" | |
#password = getpass.getpass() | |
#tn = telnetlib.Telnet(HOST) | |
#tn.read_until(b"login: ") | |
#tn.write(user.encode('ascii') + b"\n") | |
#if password: | |
# tn.read_until(b"Password: ") | |
# tn.write(password.encode('ascii') + b"\n") | |
#tn.write(b"ls\n") | |
#tn.write(b"exit\n") | |
#print(tn.read_all().decode('ascii')) | |
response = requests.get(url) | |
check_availability(url) | |
check_http_post_attack(response) | |
check_pragma_attack(response) | |
pkts = sniff(iface=network_interface,prn=lambda x:x.sprintf("{IP:%IP.src% -> %IP.dst%\n}{IP:%IP.ttl%\n}{Raw:%Raw.load%\n}")) | |