还记得那个新闻吗?
“你家的摄像头安全吗?”--5元一个家用摄像头IP,对着卧室的10元,有羞羞画面的20元——原本用来监护家庭安全的家用摄像头可能让你的家变成直播间。据新华网报道,北京、浙江多地爆出家用摄像头隐私风险,除了公开出售IP,甚至还有破解软件在QQ群中传播叫卖。
作为物联网的典型应用,智能家居的经典场景,摄像头的安全隐患,也隐隐揭示了物联网的安全风险。我们先简单看看物联网常见的安全风险:
安全特性 | 设备/硬件侧 | 网络侧 | 云/服务器 |
---|---|---|---|
机密性 | 硬件攻击 | 低计算能力设备的加密 | 隐私 |
完整性 | 缺乏证明,非法升级 | 低计算能力设备的签名 | NA |
可用性 | 物理攻击,无线阻塞 | 网络不可靠 | NA |
认证 | 缺乏用户输入,硬件导出密钥 | 联合身份认证的挑战 | 缺乏设备识别实施标准 |
访问控制 | 物理访问,缺乏本地授权 | 访问控制的轻量协议 | 需要用户管理访问控制 |
不可抵赖性 | 没有安全的本地存储,低计算能力设备 | 低计算能力设备的签名 | NA |
黑客对物联网攻击的目标或是通过直接控制物联网设备达成,或是以物联网设备为跳板攻击其他设备或系统。前一种情况可以参考前面新闻里说的摄像头IP,后者比如利用Mirai病毒控制互联网上的物联网设备构成僵尸网络。有些人更是可以通过分析网络上物联网设备采集的信息发现机密。
再分享一个物联网安全威胁地图:
<p align=center>(来自《物联网安全关键技术白皮书》)</p>
物联网的安全如何防护不必赘言,我们直接来看如何防护。
保护物联网设备和网络的安全是确保整个物联网系统安全的关键。应该采取必要的措施来保护物联网设备的物理安全、网络安全和应用程序安全。可以参考的基础步骤:
设备安全示例:
a. 使用安全启动(Secure Boot)技术来确保设备启动时不会被恶意软件(Malware)攻击。示例代码:
1 2 3 4 5 6 7 8 9 | void secure_boot(void) { if (is_valid_boot_image(boot_image) && is_secure_boot(boot_image)) { boot_image(); } else { notify_security_team(); halt_system(); } } |
b. 配置访问控制列表(Access Control List,ACL)以限制对设备的访问。示例代码:
1 2 3 4 5 6 | void configure_acl(void) { acl.add( "admin" , READ_WRITE); acl.add( "user1" , READ_ONLY); acl.add( "user2" , DENIED); } |
网络安全代码示例:
a. 使用传输层安全(Transport Layer Security,TLS)协议来加密网络数据传输。示例代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | void setup_tls(void) { SSL_CTX * ctx = SSL_CTX_new(TLS_method()); SSL_CTX_set_cipher_list(ctx, "ECDHE-ECDSA-AES256-GCM-SHA384" ); SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, verify_callback); SSL_CTX_load_verify_locations(ctx, "ca.pem" , nullptr); SSL * ssl = SSL_new(ctx); SSL_set_fd(ssl, socket_fd); SSL_connect(ssl); SSL_write(ssl, data, data_size); SSL_read(ssl, buffer , buffer_size); SSL_shutdown(ssl); SSL_free(ssl); SSL_CTX_free(ctx); } |
b. 使用网络防火墙(Network Firewall)技术来限制网络流量和阻止未经授权的访问。示例代码:
1 2 3 4 5 | void setup_firewall(void) { firewall.add_rule( "allow" , "192.168.0.0/24" , "80" , "TCP" ); firewall.add_rule( "deny" , "any" , "any" , "any" ); } |
基础的示例代码就是这样。但是具体应用还是需要根据物联网系统和设备来选择合适的安全方案和技术。
1) 对称密钥加密(Symmetric Key Encryption)示例代码:
对称密钥加密使用相同的密钥加密和解密数据,适用于需要高效数据加密和解密的场景。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | / / 设置密钥和加密算法 const char * key = "my-secret-key" ; const char * iv = "1234567890123456" ; const EVP_CIPHER * cipher = EVP_aes_256_cbc(); / / 加密数据 int encrypt(unsigned char * plaintext, int plaintext_len, unsigned char * ciphertext, unsigned char * key, unsigned char * iv, const EVP_CIPHER * cipher) { EVP_CIPHER_CTX * ctx; int len ; int ciphertext_len; ctx = EVP_CIPHER_CTX_new(); EVP_EncryptInit_ex(ctx, cipher, nullptr, key, iv); EVP_EncryptUpdate(ctx, ciphertext, & len , plaintext, plaintext_len); ciphertext_len = len ; EVP_EncryptFinal_ex(ctx, ciphertext + len , & len ); ciphertext_len + = len ; EVP_CIPHER_CTX_free(ctx); return ciphertext_len; } / / 解密数据 int decrypt(unsigned char * ciphertext, int ciphertext_len, unsigned char * plaintext, unsigned char * key, unsigned char * iv, const EVP_CIPHER * cipher) { EVP_CIPHER_CTX * ctx; int len ; int plaintext_len; ctx = EVP_CIPHER_CTX_new(); EVP_DecryptInit_ex(ctx, cipher, nullptr, key, iv); EVP_DecryptUpdate(ctx, plaintext, & len , ciphertext, ciphertext_len); plaintext_len = len ; EVP_DecryptFinal_ex(ctx, plaintext + len , & len ); plaintext_len + = len ; EVP_CIPHER_CTX_free(ctx); return plaintext_len; } |
2) 公钥加密(Public Key Encryption)示例代码:
公钥加密使用一对公钥和私钥进行加密和解密数据,适用于需要安全加密和解密的场景。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | / / 生成公钥和私钥 RSA * generate_keypair( int bits) { RSA * keypair = RSA_new(); BIGNUM * exponent = BN_new(); BN_set_word(exponent, RSA_F4); RSA_generate_key_ex(keypair, bits, exponent, nullptr); BN_free(exponent); return keypair; } / / 加密数据 int encrypt(RSA * pubkey, unsigned char * plaintext, int plaintext_len, unsigned char * ciphertext) { int ciphertext_len = RSA_public_encrypt(plaintext_len, plaintext, ciphertext, pubkey, RSA_PKCS1_PADDING); return ciphertext_len; } / / 解密数据 int decrypt(RSA * privkey, unsigned char * ciphertext, int ciphertext_len, unsigned char * plaintext) { int plaintext_len = RSA_private_decrypt(ciphertext_len, ciphertext, plaintext, privkey, RSA_PKCS1_PADDING); return plaintext_len; } |
以上的代码同样要根据物联网系统和数据类型来选择合适的加密方式。
1) 用户名密码认证示例代码:
用户名密码认证是一种常见的认证方式,用于验证用户身份。
1 2 3 4 5 6 7 8 9 10 11 12 13 | / / 用户名和密码 const char * username = "admin" ; const char * password = "password" ; / / 认证函数 bool authenticate(const char * input_username, const char * input_password) { / / 检查用户名和密码是否匹配 if (strcmp(input_username, username) = = 0 && strcmp(input_password, password) = = 0 ) { return true; } return false; } |
2) OAuth 2.0 授权示例代码:
OAuth 2.0 是一种常见的授权框架,用于允许用户授权第三方应用程序访问他们的资源。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | / / OAuth 2.0 配置 const char * client_id = "my-client-id" ; const char * client_secret = "my-client-secret" ; const char * redirect_uri = "https://example.com/callback" ; const char * authorization_endpoint = "https://example.com/authorize" ; const char * token_endpoint = "https://example.com/token" ; / / 获取授权码 const char * authorize(const char * scope) { / / 构建授权请求 URL char url[ 256 ]; snprintf(url, sizeof(url), "%s?response_type=code&client_id=%s&redirect_uri=%s&scope=%s" , authorization_endpoint, client_id, redirect_uri, scope); / / 重定向用户到授权请求 URL redirect(url); / / 接收授权码 const char * code = receive_code(); return code; } / / 获取访问令牌 const char * get_access_token(const char * code) { / / 构建访问令牌请求 URL char url[ 256 ]; snprintf(url, sizeof(url), "%s?grant_type=authorization_code&code=%s&redirect_uri=%s&client_id=%s&client_secret=%s" , token_endpoint, code, redirect_uri, client_id, client_secret); / / 发送访问令牌请求并接收响应 const char * response = send_request(url); / / 解析访问令牌 const char * access_token = parse_access_token(response); return access_token; } |
1) OTA(Over-The-Air)更新示例代码:
OTA更新是一种常见的安全更新方式,允许通过无线网络远程更新设备的固件和软件。
1 2 3 4 5 6 7 8 9 10 11 12 13 | / / OTA 更新函数 bool update_ota(const char * url, const char * version) { / / 发送 OTA 更新请求 bool success = send_ota_request(url); if (success) { / / 更新成功后,保存最新的固件版本号 save_latest_version(version); } return success; } |
2) 漏洞修复示例代码:
漏洞修复是一种常见的安全更新方式,用于修复发现的漏洞和弱点。
1 2 3 4 5 6 7 8 9 10 11 12 13 | / / 漏洞修复函数 bool fix_vulnerability(const char * vulnerability) { / / 确认漏洞修复是否可行 bool feasible = check_vulnerability_feasibility(vulnerability); if (feasible) { / / 修复漏洞 fix_vulnerability(vulnerability); } return feasible; } |
物联网的设备与互联网连接并能够获取和传输敏感信息。这些设备包括智能家居设备、工业自动化系统、医疗设备、汽车和无人机等。如果这些设备遭到攻击或被未经授权的用户访问,可能会导致各种严重的问题,如数据泄露、身份盗窃、服务中断、身体伤害等。
毕竟,万物互联的基础还得是安全,不是吗?
业务安全产品:免费试用