- Based on Scapy, sniffing HTTP traffic on the host, can be changed to sniff any network packets.
- Learn simple baseline at the beginning of the program to set average HTTP request rate
- Include various statistics : HTTP request rate, Top hits by Section, by Domain, by User-agent, by HTTP Method, by Status code, by Volume per Domain etc.
- Simple console-style outputs dashboard info with colored scheme
- Overflow protection: countermeasure of memory overrun by malformed payload
- By tagging each record with timestamp, enable to age out data that fall out a configurable retention window
- Highly configurable by static settings to change program behavior
- Plug-in design to extend custom statistic modules
- Implemented using OOA/OOD design patterns
- Python 3.5+
- Use
pip install -r requirements.txt
to install external libraries of followings:- scapy
- scapy-http
- termcolor
- requests
- Run unit test cases for the Alerting logic & State transition logic
python exercise_test.py
- Run the program
python exercise.py
to sniff on 'eth0', orpython exercise.py -i <interface_name> -p <port#>
to specify interface and/or port number - Display help message
python exercise.py --help
- Manually use browsers, curl, wget etc., or,
python gen_traffic.py -i <host_name> -f <seconds>
to automatically hit HTTP website(www.google.com by default) at the interval specified(5s by default) to test out the program - Press
Ctrl+c
to stop the main program - Optional: edit
exercise_config.py
and customize program behavior
class Config:
'''
Configurations determine the behavior of the exercise program
'''
timeout = 2 #Frequency in sec to check for new HTTP transaction, default 2s
dashboard_bucket_size = 10 #Frequency in sec to refresh dashboard info, default 10s
average_bucket_size = 60*2 #Bucket size in sec for average HTTP request rate, default 2mins
average_threshold = 10 #Threshold in percentage to trigger alerts when exceeding <average_baseline>, default 10%
average_learning_duration = average_bucket_size #Duration of learning for average HTTP request rate, default <average_bucket_size>
max_str_length = 1024 #Protection of overlong string, default set to 1kb
max_top_hits = 10 #Display top <N> hits and hide the rest, default top 10 hits
max_retention_length = 3600*24 #Retention length in sec, used to purge aging data, default 24hrs
- Add other useful statistics such as:
- Max alert duration
- Average alert duration
DevOps need a dashboard to monitor general health of HTTP traffic, and alerting on unusual signs indicating issues in the infrastructure, either under attack or hit by performance.
- Count HTTP request during entire learning duration, no Alerting is process or performed
- At the end of each learning duration, if average baseline value is zero, the learning automatically restarts, until baseline becomes non-zero value
Note: Learned average baseline does not change as it enters into enforce mode.
- Start with learning mode, collecting HTTP request per bucket size.
- At the end of learning, it calculates average HTTP count per bucket size, the rate baseline towards alert calculation
- Enter into enforce mode, passively count HTTP requests
- Alert message will be shown, or continue to show when previous average count exceeding baseline+threshold(in percentage)
- Alert dismissal message will be shown when when previous average count drop below baseline+threshold, it will be removed at next screen refreshing
- Step#2-4 repeats
Note: All previous alert history are preserved and printed at screen for the last 24hrs
- Always starts in learning state, until baseline value becomes non-zero by the end of learning duration
- Enforce mode transation(cycled): normal -> alert active -> alert dismiss
There are many things could be considered to better support the assumed use case in real-world production environment, they break down as followings:
- Top Hourly, Daily, Weekly, Monthly request rate
- Top In|Outbound Data volume by source IP
- Top Data volume by Geo location
- Top Protocol and Ports by source IP
- Top SaaS App action performed by source IP
- Top SaaS App users by request rate
- Average response time per server
- etc.
- SSL termination for backend servers to add visibility without security warnings in the browser
- Inline Reverse-proxy not only inspects traffic also protect backend servers in real-time, which enables a long list of Proxy relevant security capabilities.
- Protocol Coverage
- More HTTP based protocol support: E.g. Websockets, SOAP, HTTP2 etc.
- More protocol support at layer 3-7: E.g. DNS, DNSSec, QUIC etc.
- Scale-ability
- Use distributed Data store to store statistic information
- Use Application server cluster to deploy the solution at scale
- WAF, CASB, DDoS, Anti-malware, ATP, DLP, SIEM integration, DNS-based security, etc.
- Threat intelligence based to build solution based on known good or bad.
- Combine supervised and unsupervised Machine learning based approach, to detect anomalies and uncover unseen attack patterns for security.
- Similarly Machine learning approach could also help detect performance anomalies in the infrustructure.