测试 Securing Kamailio’s JSON-RPC over HTTP

原文在这里:

https://kaufmania.wordpress.com/2023/09/13/securing-kamailios-json-rpc-over-http/

写的太好了,笔法老练,掌握精准


笔者改了下,kamailio.cfg 全部内容为:

复制代码
#!KAMAILIO

#!defenv RPC_USER
#!defenv RPC_PASS

loadmodule "pv"
loadmodule "ctl"
loadmodule "xlog"
loadmodule "sl"
loadmodule "json"
loadmodule "xhttp"
loadmodule "jsonrpcs"
loadmodule "tcpops"
loadmodule "htable"
loadmodule "auth"
loadmodule "kex"

tcp_accept_no_cl = yes
http_reply_parse = yes

socket_workers = 2
listen = tcp:enp0s3:8081  # 修改成实际网卡
listen = tcp:127.0.0.1:5060
debug = 3
log_stderror = yes
modparam("jsonrpcs", "transport", 0)
modparam("htable", "htable", "rpc_allow=>size=4");

request_route {
    exit;
}

event_route[xhttp:request] {
    route(XHTTP_PORT_CHECK);

    route(XHTTP_RPC_AUTH);

    route(VALIDATE_RPC_METHOD);

    jsonrpc_dispatch();
}

route[XHTTP_PORT_CHECK] {
    if ( $Rp != 8081 ) {
        xcrit("HTTP Request not received on port 8081. reject\n");
        tcp_close_connection();
    }
}

route[XHTTP_RPC_AUTH]{
    if ( $au != $null && $au != $def(RPC_USER) ) {
        xerr("Invalid RPC user : [$au].\n");
        xhttp_reply(
            "403", "Unauthorized", "text/plain", "403 Unauthorized\r\n"
        );
        exit;
    }

    if ( !pv_www_authenticate("$Ri", "$def(RPC_PASS)", "0") ) {
        switch ( $rc ) {
            case -2:
                xerr("Invalid RPC password for user $au\n");
                xhttp_reply(
                    "403", "Unauthorized", "text/plain", "403 Unauthorized\r\n"
                );
                exit;
            case -5:
                xinfo("HTTP request with no crednetials. Send challenge\n");
                www_challenge("$Ri", "0");
                exit;
            default:
                xinfo("Misc. WWW auth failure. $$rc [$rc]\n");
                xhttp_reply(
                    "503", "Server Error", "text/plain", "503 Server Error\r\n"
                );
                exit;
        }
    }

    consume_credentials();
}

route[VALIDATE_RPC_METHOD] {
	json_get_field("$rb", "method", "$avp(rpc_method)");
    $avp(rpc_method) = $(avp(rpc_method){s.unquote});

    if ( $sht(rpc_allow=>$avp(rpc_method)) == 1 ) {
        return;
    }

    xhttp_reply("403", "Not Allowed", "text/plain", "Not Allowed\n");
    exit;
}

event_route[htable:mod-init] {
    $sht(rpc_allow=>stats.fetch)  = 1;
    $sht(rpc_allow=>core.version) = 1;
    $sht(rpc_allow=>mod.stats)    = 1;
}

现在做测试

export RPC_USER=allen

export RPC_PASS=1234

kamailio # 启动 kamailio

curl -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"stats.fetch","id":"1","params":["all"]}' --digest -u allen:1234 http://127.0.0.1:8081 -vvv

输出省略

还是要多动手

相关推荐
xixixi777773 小时前
三重筑基:5G-A超级上行提速千兆,电联低频共享扫平盲点,800V HVDC算电协同破局
人工智能·5g·ai·大模型·算力·通信·信通院
ShineWinsu1 天前
对于Linux:进程间通信IPC(匿名管道)的解析
linux·c++·面试·进程·通信·管道·ipc
xixixi7777713 天前
跨境AI服务:多语种大模型+卫星通信+量子加密+数据脱敏+安全审计,合规·高效·安全三重保障
人工智能·安全·大模型·通信·卫星通信·审计·量子安全
搞科研的小刘选手13 天前
【高届数制造材料会议】第十二届先进制造技术与应用材料国际学术会议(ICAMMT 2026)
自动化·制造·通信·电子信息·材料·机械·先进半导体
xixixi7777714 天前
智算中心建设新范式:GPT-6/Rubin架构+1.6T光模块+量子安全网关+AI安全沙箱,算力·效率·安全·成本的最优平衡
人工智能·gpt·安全·机器学习·架构·大模型·通信
xixixi7777715 天前
AI自主挖洞 + 通信网络扩散:全域风险指数级放大,如何构建密码-沙箱-终端联动闭环?
开发语言·网络·人工智能·ai·大模型·php·通信
xixixi7777716 天前
从5G标准到6G前沿:Polar码的技术演进与未来之路
开发语言·人工智能·5g·大模型·php·通信·polar码
xixixi7777717 天前
Token 经济引爆 AI 产业加速:从百模大战到百虾大战,谁在定义 2026 的中国 AI?
大数据·人工智能·机器学习·ai·大模型·算力·通信
无名38722 天前
测试 kamailio 的 tcp_reuse_port 以及 FreeSWITCH 的 reuse-connections 等等
通信
liulilittle25 天前
WintunAdapter 设计解析:一个 VNP 数据面的无锁优雅实现
网络·c++·it·通信