要实现攻击流量的实时展示图,通常需要结合数据采集、实时处理和可视化技术。以下是一个分步实现的方案:
[攻击源] → [防火墙/IDS] → [日志采集] → [实时处理] → [数据库] → [可视化]
工具选择:
示例(Filebeat配置):yaml
filebeat.inputs:
- type: log
paths:
- /var/log/nginx/access.log
output.elasticsearch:
hosts: ["localhost:9200"]
def detect_attack(log):
if log['status'] == 403 and log['requests_per_second'] > 100:
return "Brute Force Attack"
elif log['payload'] contains 'SQL注入特征':
return "SQL Injection"
return None
时序数据库:InfluxDB(高效存储时间序列数据)
搜索数据库:Elasticsearch(快速检索日志)
-------------------------------------
技术栈:
代码片段:javascript
fetch('/api/attack-locations')
.then(res => res.json())
.then(data => {
data.forEach(ip => {
L.marker([ip.lat, ip.lon])
.bindPopup(`IP: ${ip.addr}<br>攻击类型: ${ip.type}`)
.addTo(map);
});
});
const chart = echarts.init(document.getElementById('chart'));
const ws = new WebSocket('ws://realtime/attack-data');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
chart.setOption({
series: [{
type: 'map',
data: data.geoPoints
}]
});
};
技术 | 延迟 | 延迟 |
---|---|---|
WebSocket | <100ms | 高频更新(如攻击轨迹) |
Server-Sent Events | ~1s | 日志流推送 |
Long Polling | 2-5s | 兼容旧浏览器 |
**-*** | *** | *** |
192.168.***.***
)