测试 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

输出省略

还是要多动手

相关推荐
无名3871 天前
rtpengine-recording(8) 手册页
通信
无名3875 天前
FreeSWITCH limit 中文手册
通信
xixixi777776 天前
系统性地解析——边缘计算(从定义与驱动力、核心架构、关键技术特征、与云计算的范式对比、典型应用场景以及挑战与趋势等方面)
安全·架构·云计算·边缘计算·信息与通信·通信·反诈
xixixi777778 天前
从宏观架构、核心技术、战术对抗、治理挑战和未来趋势五个层面,系统性地剖析“短信反诈骗”
安全·架构·安全架构·通信·反诈·短信反诈
无名3879 天前
Kamailio usrloc 细节测试
通信
xixixi7777710 天前
App反诈骗:一场面向移动生态的深度安全战争(接上文短信反诈)
安全·信息与通信·通信·电话反诈
无名38713 天前
FusionPBX Debian 12 安装
运维·debian·通信
交换机路由器测试之路16 天前
什么是网络直径
网络·以太网·交换机·通信
无名38718 天前
RTPEngine 官方自带的 perl 测试程序
开发语言·perl·通信
xixixi7777719 天前
讲一下卫星移动通信网络(系统架构、核心技术与协议挑战及应用场景和战略价值)
网络·学习·安全·信息与通信·通信·卫星通信