基于 SQL-on-Hadoop 的...
Transcript of 基于 SQL-on-Hadoop 的...
网络流量日志采集
IP 流日志:DPI 引擎应用识别
开始时间, 持续时间, 协议, 应用, 源 IP, 源端口, 目标 IP, 目标端口,
发送字节数, 接收字节数, 域名
一个月
IP 流日志 3 TB 400 亿条
HTTP 日志 30 TB 1100 亿条
DNS日志 2 TB 200 亿条
网络流量日志采集
HTTP 请求:
时间, 源 IP, 源端口, 目标 IP, 目标端口,
方法, 域名, 路径, Cont.Type, Cont.Len., Referer, User-Agent
HTTP 应答:
时间, 源 IP, 源端口, 目标 IP, 目标端口,
状态码, Cont.Type, Cont.Len., ServerBanner
一个月
IP 流日志 3 TB 400 亿条
HTTP 日志 30 TB 1100 亿条
DNS日志 2 TB 200 亿条
网络流量日志采集
Passive DNS:授权回答资源记录
时间, 服务器 IP, 数据段, 域名, TTL, CLASS, TYPE, 数据
一个月
IP 流日志 3 TB 400 亿条
HTTP 日志 30 TB 1100 亿条
DNS 日志 2 TB 200 亿条
安全大数据分析平台
上海交通大学的 Hadoop 平台
• 使用 Cloudera CDH
• 4 个管理节点
• 24 个计算节点
• 2 x Intel Xeon E5-2670 @2.60GHz(共 32 线程)
• 128GB RAM
• 12 x 2TB HDD + 2 x 240GB SSD
• 10GE 互联
• HDFS 容量:500 TB
• 数据 3 个副本→ 166 TB 实际容量
SQL on Hadoop
在 Hadoop 上使用类 SQL 语言进行数据查询
• 灵活,低学习成本
• ODBC、JDBC 接口
Hive
• “HiveQL” 转化为MapReduce执行
• 较长的MapReduce初始化时间
• 执行效率偏低
数据存储格式
Hive Impala
查询 导入 查询 导入
Text √ √ √ √
Parquet √ √ √ √
RCFile √ √ √
ORC √ √
以下测试使用 Hive 0.12 on MR, Impala 1.4.1, 22 个计算节点
数据存储格式
row-oriented
column-oriented
A CB
A1 C1B1
A2 C2B2
A3 C3B3
A1 C1B1 A2 C2B2 A3 C3B3
A1 A3A2 B1 B3B2 C1 C3C2
Hive Impala
查询 导入 查询 导入
Text √ √ √ √
Parquet √ √ √ √
RCFile √ √ √
ORC √ √
列存储:查询只涉及部分列时,减少读取数据量
数据压缩
9.35 TB
6.78 TB
3.10 TB
1.73 TB
9.21 TB
3.58 TB
2.42 TB
1.15 TB
0.87 TB
Text
Parquet
Parquet / Snappy
Parquet / Gzip
RCFile
RCFile / Snappy
ORC
ORC / Snappy
ORC / Zlib
400 亿条 HTTP 日志
10 倍压缩比
5 倍压缩比
性能测试:全表扫描
1,146 1,106
714 726
1,045
461 506
358 359
663
490
231
135
672
302
0
200
400
600
800
1000
1200
1400
Text Parquet ParquetSnappy
ParquetGzip
RCFile RCFileSnappy
ORC ORCSnappy
ORCZlib
查询耗时(秒)
Hive Impala
性能测试:全表扫描
1,146 1,106
714 726
1,045
461 506
358 359
663
490
231
135
672
302
0
200
400
600
800
1000
1200
1400
Text Parquet ParquetSnappy
ParquetGzip
RCFile RCFileSnappy
ORC ORCSnappy
ORCZlib
查询耗时(秒)
Hive Impala
Impala 最佳:Parquet + Gzip
Hive 最佳:ORC + Zlib
性能测试:全表扫描
0%
20%
40%
60%
80%
100%
Hive Impala
Text Parquet Parquet / Snappy
Parquet / Gzip RCFile RCFile / Snappy
ORC ORC / Snappy ORC / Zlib
CPU 使用率
0 GB/s
3 GB/s
6 GB/s
9 GB/s
12 GB/s
15 GB/s
18 GB/s
Hive Impala
总磁盘 I/O
性能测试:列存储
0
20
40
60
80
100
120
140
0
200
400
600
800
1000
1200
1400
1600
1800
2000
1 2 3 4 5 6 7 8 9 10 11 12
查询耗
时(秒)
读取
数据
量(
GB)
列数
数据读取量 查询耗时
使用 Impala, Parquet + Gzip
SELECT column1, column2, ..., columnn FROM table WHERE column1 = condition
性能测试:聚合查询
169.4
226.7
353.9
28.3
99.6
488.3
0
100
200
300
400
500
查询 1 查询 2 查询 3
查询耗时
(秒)
Hive Impala
Impala 使用 Parquet + Gzip,Hive 使用 ORC + Zlib
1. select count(distinct ip) where domain = ...2. select method, count(*) ... group by method3. select useragent, count(*) ... group by useragent order by 2 desc
性能测试:聚合查询
169.4
226.7
353.9
28.3
99.6
488.3
0
100
200
300
400
500
查询 1 查询 2 查询 3
查询耗时
(秒)
Hive Impala
Impala 使用 Parquet + Gzip,Hive 使用 ORC + Zlib
1. select count(distinct ip) where domain = ...2. select method, count(*) ... group by method3. select useragent, count(*) ... group by useragent order by 2 desc
Impala:单线程 Group / Join
应用:漏洞评估
Discuz! 7.2 SQLi
• 特征字串:=%27&gids
0
25
50
75
100
125
150
175
200
6/3
0
7/1
7/2
7/3
7/4
7/5
7/6
7/7
7/8
7/9
7/1
0
7/1
1
7/1
2
7/1
3
7/1
4
7/1
5
7/1
6
7/1
7
7/1
8
7/1
9
7/2
0
攻击者数量
公开
应用:漏洞评估
Discuz! 7.2 SQLi
• 特征字串:=%27&gids
最流行利用代码
... concat(username,0x3a,password,0x3a,salt) from uc_members ...
... concat(0x5E5E5E,username,0x3a,password,0x3a,salt) from cdb_uc_members ...
... substr(authkey,1,62) from cdb_uc_applications ...
... concat(username,0x27,password) from cdb_members ...
... concat(version(),floor(rand(0)*2)) ...
应用:漏洞快速响应
定位校内受影响网站
• 网站备案登记 ?
• 搜索引擎 ?
• 扫描探测 ?
• … where path like “%/faq.php?action=grouppermission%”
应用:Web 攻击检测
HTTP 日志匹配攻击特征
类型 攻击者 请求数
SQL 注入 1,034 611,136
文件包含/下载 276 42,237
WebShell尝试 297 197,183
路径探测 14,933 1,023,730
扫描器 799 1,037,806
SJTU 数据中心,2014 上半年
应用:Web 攻击检测
HTTP 日志匹配攻击特征
类型 攻击者 请求数
SQL 注入 1,034 611,136
文件包含/下载 276 42,237
WebShell尝试 297 197,183
路径探测 14,933 1,023,730
扫描器 799 1,037,806
主动探测,验证漏洞是否存在
SJTU 数据中心,2014 上半年
应用:出站连接审计
服务器出站连接: 自动更新? 代理? 木马? 入侵?
时间 URL User Agent Content Type 尺寸
03-08 11:15:48 61.160.221.*:88/fuckWget/1.10.2(RedHatmodified)
application/
octet-stream6,772
03-08 11:16:03 61.160.221.*:88/xz32Wget/1.10.2(RedHatmodified)
application/
octet-stream1,351,181
03-09 02:54:24 61.160.221.*:88/fuck3.shWget/1.10.2(RedHatmodified)
application/
octet-stream404
03-09 02:54:42 61.160.221.*:88/fuckWget/1.10.2(RedHatmodified)
application/
octet-stream6,772
03-09 02:55:04 61.160.221.*:88/sshd8Wget/1.10.2(RedHatmodified)
application/
octet-stream1,513,570
03-09 02:57:20 61.160.221.*:88/ssh.pyWget/1.10.2(RedHatmodified)
application/
octet-stream1,324
03-09 02:57:35 61.160.221.*:88/mafix.tar.gzWget/1.10.2(RedHatmodified)
application/
octet-stream446,713
03-09 12:25:51 61.160.221.*:88/sshd8Wget/1.10.2(RedHatmodified)
application/
octet-stream1,513,570
应用:Google Hacking 分析
Referer来自 Google, Baidu:0.7%
0
50000
100000
150000
200000
250000
2014/1/1 2014/2/1 2014/3/1 2014/4/1 2014/5/1 2014/6/1 2014/7/1
Baidu Google
应用:Google Hacking 分析
inurl:".cgi/" 732
inurl:/register 110
inurl:/spip.php?page=forum 84
inurl:"/index.php?subaction=" 71
inurl:forum.php?mod 66
inurl:"/user/" 63
inurl:gastenboek 63
inurl:"index.php?do=rules" 54
inurl:?messagePage 42
inurl:wiley 42
inurl:"index.php?do=stats" 42
inurl:"index.php?do=register" 40
inurl:"index.php?do=feedback" 39
inurl:"showthread" 38
inurl:ewebeditor 37
filetype:pdf 42975
filetype:ppt 7643
filetype:pptx 4055
filetype:xls 503
filetype:doc 388
filetype:docx 127
filetype:ai 117
filetype:pps 80
filetype:xlsx 18
filetype:action 10
filetype:sql 3
filetype:php 2
filetype:do 2
filetype:asp 2