此文章PDF文档下载地址:点击下载
0x00 前言
在移动互联网深入普及和物联网开始规模应用的今天,网络安全公司怎能不研究移动安全,要研究移动安全,怎能没有4G/LTE伪基站研究测试环境?
本文介绍如何利用开源项目和SDR,合法的搭建并使用便携式4G/LTE伪基站,用于实验室的安全研究,或者用于用户授权的物理渗透测试。
0x01 合法开展研究活动
根据国家无线电管理法规,我们需要先取得频率、设备和人员许可才能合法的在通信业务频段进行收发。而已经分配给运营商的频段,需要该运营商同意才能使用。因此,我们做通信实验时,通常的做法不是申请许可,而是构造一个封闭的电磁空间,即法拉第笼,在这个空间里进行无线信号的发射和接收不会影响到外部世界。
法拉第笼是由金属或金属网包围形成的一个空间,大可以到一个大房子,小可能就是一个小箱子。测试时,如果法拉第笼比较小,我们就只把发射和接收无线电信号的天线放在法拉第笼里面,其它部分仍可放在外面,内外通过馈线连接。
0x02 硬件准备
SBC:UP Board, Intel Atom x5-Z8350 四核CPU,4GB RAM,64GB eMMC
SDR:USRP B200mini + USB电缆
天线+馈线+双工器
充电宝:5V 3A(非常重要)
0x04 软件准备
1.Ubuntu 16.04 LTS
安装之后更新
sudo apt-get update sudo apt-get upgrade
2.必备软件:Git
sudo apt-get install git
国内专享:*、Privoxy
sudo apt-get install privoxy python-gevent python-pip sudo pip install *
*配置略。
0x05 安装步骤
1.eNodeB: OpenAirInterface
git clone https://gitlab.eurecom.fr/oai/openairinterface5g.git cd openairinterface5g git checkout develop source oaienv cd cmake_targets ./build_oai -I --eNB -x --install-system-files -w USRP
2.EPC: OpenAir-CN
git clone https://gitlab.eurecom.fr/oai/openair-cn.git cd openair-cn git checkout develop cd scripts ./build_hss -i ./build_mme -i ./build_spgw -i ./build_hss ./build_mme ./build_spgw
0x06 配置
1.eNodeB:
tracking_area_code = "13"; mobile_country_code = "460"; mobile_network_code = "01"; Nid_cell = 0; ////////// MME parameters: mme_ip_address = ( { ipv4 = "127.0.1.10"; ipv6 = "192:168:30::17"; active = "yes"; preference = "ipv4"; } ); NETWORK_INTERFACES : { ENB_INTERFACE_NAME_FOR_S1_MME = "lo"; ENB_IPV4_ADDRESS_FOR_S1_MME = "127.0.1.2/8"; ENB_INTERFACE_NAME_FOR_S1U = "lo"; ENB_IPV4_ADDRESS_FOR_S1U = "127.0.6.2/8"; ENB_PORT_FOR_S1U = 2152; # Spec 2152 };
2.EPC:
修改hosts文件和hostname,然后重新启动。
sudo gedit /etc/hosts 127.0.0.1 localhost 127.0.1.1 mini.openair4G.eur mini 127.0.33.1 hss.openair4G.eur hss
sudo gedit /etc/hostname
mini
复制EPC配置文件:
sudo mkdir -p /usr/local/etc/oai/freeDiameter sudo cp ~/openair-cn/etc/mme.conf /usr/local/etc/oai sudo cp ~/openair-cn/etc/hss.conf /usr/local/etc/oai sudo cp ~/openair-cn/etc/spgw.conf /usr/local/etc/oai sudo cp ~/openair-cn/etc/acl.conf /usr/local/etc/oai/freeDiameter sudo cp ~/openair-cn/etc/mme_fd.conf /usr/local/etc/oai/freeDiameter sudo cp ~/openair-cn/etc/hss_fd.conf /usr/local/etc/oai/freeDiameter
编辑hss.conf
## MySQL mandatory options MYSQL_server = "127.0.0.1"; MYSQL_user = "root"; MYSQL_pass = "linux"; MYSQL_db = "oai_db";
编辑mme.conf
REALM = "openair4G.eur"; S6A : { S6A_CONF = "/usr/local/etc/oai/freeDiameter/mme_fd.conf"; # YOUR MME freeDiameter config file path HSS_HOSTNAME = "hss"; # THE HSS HOSTNAME }; GUMMEI_LIST = ( {MCC="460" ; MNC="01"; MME_GID="4" ; MME_CODE="13"; } # YOUR GUMMEI CONFIG HERE ); TAI_LIST = ( {MCC="460" ; MNC="01"; TAC = "13"; } # YOUR PLMN CONFIG HERE ); NETWORK_INTERFACES : { # MME binded interface for S1-C or S1-MME communication (S1AP), can be ethernet interface, virtual ethernet interface, we don't advise wireless interfaces MME_INTERFACE_NAME_FOR_S1_MME = "lo"; # YOUR NETWORK CONFIG HERE MME_IPV4_ADDRESS_FOR_S1_MME = "127.0.1.10/8"; # YOUR NETWORK CONFIG HERE # MME binded interface for S11 communication (GTPV2-C) MME_INTERFACE_NAME_FOR_S11_MME = "lo"; # YOUR NETWORK CONFIG HERE MME_IPV4_ADDRESS_FOR_S11_MME = "127.0.8.11/8"; # YOUR NETWORK CONFIG HERE MME_PORT_FOR_S11_MME = 2123; # YOUR NETWORK CONFIG HERE }; S-GW : { # S-GW binded interface for S11 communication (GTPV2-C), if none selected the ITTI message interface is used SGW_IPV4_ADDRESS_FOR_S11 = "127.0.8.1/8"; # YOUR NETWORK CONFIG HERE };
编辑spgw.conf
S-GW : { NETWORK_INTERFACES : { # S-GW binded interface for S11 communication (GTPV2-C), if none selected the ITTI message interface is used SGW_INTERFACE_NAME_FOR_S11 = "lo"; # YOUR NETWORK CONFIG HERE SGW_IPV4_ADDRESS_FOR_S11 = "127.0.8.1/8"; # YOUR NETWORK CONFIG HERE # S-GW binded interface for S1-U communication (GTPV1-U) can be ethernet interface, virtual ethernet interface, we don't advise wireless interfaces SGW_INTERFACE_NAME_FOR_S1U_S12_S4_UP = "lo"; # YOUR NETWORK CONFIG HERE, USE "lo" if S-GW run on eNB host SGW_IPV4_ADDRESS_FOR_S1U_S12_S4_UP = "127.0.6.1/8"; # YOUR NETWORK CONFIG HERE SGW_IPV4_PORT_FOR_S1U_S12_S4_UP = 2152; # PREFER NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING # S-GW binded interface for S5 or S8 communication, not implemented, so leave it to none SGW_INTERFACE_NAME_FOR_S5_S8_UP = "none"; # DO NOT CHANGE (NOT IMPLEMENTED YET) SGW_IPV4_ADDRESS_FOR_S5_S8_UP = "0.0.0.0/24"; # DO NOT CHANGE (NOT IMPLEMENTED YET) }; ... } P-GW = { NETWORK_INTERFACES : { # P-GW binded interface for S5 or S8 communication, not implemented, so leave it to none PGW_INTERFACE_NAME_FOR_S5_S8 = "none"; # DO NOT CHANGE (NOT IMPLEMENTED YET) PGW_IPV4_ADDRESS_FOR_S5_S8 = "0.0.0.0/24"; # DO NOT CHANGE (NOT IMPLEMENTED YET) # P-GW binded interface for SGI (egress/ingress internet traffic) PGW_INTERFACE_NAME_FOR_SGI = "eth0"; # YOUR NETWORK CONFIG HERE PGW_IPV4_ADDRESS_FOR_SGI = "192.168.12.82/24"; # YOUR NETWORK CONFIG HERE PGW_MASQUERADE_SGI = "yes"; # YOUR NETWORK CONFIG HERE }; ... # DNS address communicated to UEs DEFAULT_DNS_IPV4_ADDRESS = "192.168.106.12"; # YOUR NETWORK CONFIG HERE DEFAULT_DNS_SEC_IPV4_ADDRESS = "192.168.12.100"; # YOUR NETWORK CONFIG HERE ... }
编辑HSS freediameter配置文件 (/usr/local/etc/oai/freeDiameter/hss_fd.conf):
Identity = "hss.openair4G.eur"; Realm = "openair4G.eur";
编辑MME freediameter配置文件 (/usr/local/etc/oai/freeDiameter/mme_fd.conf):
Identity = "mini.openair4G.eur"; Realm = "openair4G.eur"; ConnectPeer= "hss.openair4G.eur" { ConnectTo = "127.0.33.1"; No_SCTP ; No_IPv6; Prefer_TCP; No_TLS; port = 3868; realm = "openair4G.eur";};
0x07 运行
安装证书:
cd ~/openair-cn/scripts ./check_hss_s6a_certificate /usr/local/etc/oai/freeDiameter/ hss.openair4G.eur ./check_mme_s6a_certificate /usr/local/etc/oai/freeDiameter/ mini.openair4G.eur
首次运行HSS:
cd ~/openair-cn/scripts
./run_hss -i ~/openair-cn/src/oai_hss/db/oai_db.sql
之后每次运行HSS:
cd ~/openair-cn/scripts
./run_hss
运行MME:
cd ~/openair-cn/scripts
./run_mme
安全测试通常不需要运行SP-GW。
运行eNB:
cd ~/openairinterface5g source oaienv cd cmake_targets/lte_build_oai/build sudo -E ./lte-softmodem -O $OPENAIR_DIR/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band3.tm1.usrpb200.conf
0x08 高级玩法
1.对TD-LTE的支持
OAI本身支持TD-LTE。但是因为TD系统全网收发同步的要求,伪基站要正常工作,就必须与运营商现网同步。OAI已含有部分通过空中接口信号实现TD同步的代码,需要进一步修改才能完成与现网同步。
2.精简代码
如果我们只做网络安全研究,不做通信研究,就不需要完整的EPC。大部分公司只是研究空口的DoS攻击和RRC重定向攻击,每次只有少量固定格式的网络报文从MME返回,因此可以修改代码,直接返回我们想要的报文,或者执行我们想要的逻辑,就可以精简掉EPC,只运行lte-softmodem一个进程就好了。
3.连接运营商核心网
如果能从运营商核心网获得安全认证四元组:Kasme、AUTN、RAND、XRES,就能通过双向鉴权,让LTE手机相信我们的基站是真基站。这需要修改MME的代码和freeDiameter的配置来实现。
4.同一硬件集成LTE+GSM伪基站
5.架设自己的测试网
如果你对某一种高级玩法感兴趣,并且知道大体怎么实现,欢迎找我组队,可以一起做点有意思的(开源)通信安全项目,Seeker老师的微信:70772177。
0x09 结束语
在万物互联时代,了解LTE可用性和安全性的边界,事关我们每个人的人身安全和数据安全。
不管你是在开发无人驾驶汽车、医疗设备、智能电表,还是普通的移动应用,过于相信运营商网络的可用性和安全性都会带来安全威胁。不只是网络安全公司需要研究无线通信的安全,产品开发者同样需要。