{"id":12146,"date":"2025-02-11T16:31:03","date_gmt":"2025-02-12T00:31:03","guid":{"rendered":"https:\/\/www.xh86.me\/?p=12146"},"modified":"2025-02-11T16:31:03","modified_gmt":"2025-02-12T00:31:03","slug":"sngrep-%e5%ae%89%e8%a3%85%e4%b8%8e%e4%bd%bf%e7%94%a8%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xh86.me\/?p=12146","title":{"rendered":"sngrep \u5b89\u88c5\u4e0e\u4f7f\u7528\u6559\u7a0b"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><code>sngrep<\/code> \u662f\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u7684 SIP \u6293\u5305\u5de5\u5177\uff0c\u4e13\u95e8\u7528\u4e8e <strong>\u5b9e\u65f6\u5206\u6790 SIP \u547c\u53eb\u6d41<\/strong>\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d <strong>\u53ef\u89c6\u5316 SIP INVITE\u3001REGISTER\u3001BYE \u7b49\u6d88\u606f<\/strong>\uff0c\u5e76\u652f\u6301\u4fdd\u5b58\u548c\u8fc7\u6ee4\u6d41\u91cf\u3002<br \/>\n\u672c\u6559\u7a0b\u9002\u7528\u4e8e <strong>CentOS\uff08FreePBX\uff09\u3001Debian\u3001Ubuntu<\/strong> \u7b49 Linux \u670d\u52a1\u5668\u3002<\/p>\n<hr \/>\n<h2><strong>1. \u5b89\u88c5 sngrep<\/strong><\/h2>\n<h3><strong>1.1 CentOS \/ RHEL\uff08\u9002\u7528\u4e8e FreePBX\uff09<\/strong><\/h3>\n<ol>\n<li>\u542f\u7528 EPEL \u6e90\u5e76\u5b89\u88c5 sngrep\uff1a\n<pre><code class=\"language-bash\">yum install epel-release -y\r\nyum install sngrep -y\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3><strong>1.2 Debian \/ Ubuntu<\/strong><\/h3>\n<ol>\n<li>\u76f4\u63a5\u4f7f\u7528 apt \u5b89\u88c5\uff1a\n<pre><code class=\"language-bash\">apt update &amp;&amp; apt install sngrep -y\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3><strong>1.3 \u4ece\u6e90\u7801\u5b89\u88c5\uff08\u9002\u7528\u4e8e\u6240\u6709 Linux\uff09<\/strong><\/h3>\n<p>\u5982\u679c\u4f60\u60f3\u5b89\u88c5\u6700\u65b0\u7248\u672c\uff0c\u53ef\u4ee5\u4ece GitHub \u7f16\u8bd1\uff1a<\/p>\n<pre><code class=\"language-bash\">git clone https:\/\/github.com\/irontec\/sngrep.git\r\ncd sngrep\r\n.\/bootstrap.sh\r\n.\/configure\r\nmake &amp;&amp; make install\r\n<\/code><\/pre>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8fd0\u884c <code>sngrep<\/code> \u4ee5\u786e\u8ba4\u662f\u5426\u6210\u529f\u5b89\u88c5\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -v\r\n<\/code><\/pre>\n<p>\u5982\u679c\u8fd4\u56de\u7248\u672c\u53f7\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<hr \/>\n<h2><strong>2. \u4f7f\u7528 sngrep \u8fdb\u884c SIP \u6293\u5305<\/strong><\/h2>\n<h3><strong>2.1 \u8fd0\u884c sngrep<\/strong><\/h3>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef <strong>\u5b9e\u65f6\u67e5\u770b SIP \u6d41\u91cf<\/strong>\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep\r\n<\/code><\/pre>\n<p><strong>\u754c\u9762\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>\u663e\u793a\u6240\u6709 SIP \u4f1a\u8bdd\uff08REGISTER\u3001INVITE\u3001BYE \u7b49\uff09\u3002<\/li>\n<li>\u4f60\u53ef\u4ee5\u9009\u62e9\u67d0\u4e2a SIP \u901a\u8bdd\uff0c\u6309 <strong>Enter<\/strong> \u8fdb\u5165\u8be6\u7ec6\u5206\u6790\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3><strong>2.2 \u8fc7\u6ee4\u7279\u5b9a SIP \u7aef\u53e3<\/strong><\/h3>\n<p>SIP \u9ed8\u8ba4\u4f7f\u7528 <strong>UDP 5060 \u7aef\u53e3<\/strong>\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u7aef\u53e3\u6293\u5305\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -f \"port 5060\"\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u4f7f\u7528 PJSIP\uff0c\u53ef\u80fd\u4f1a\u4f7f\u7528 <strong>TCP\/TLS \u7aef\u53e3 5061<\/strong>\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -f \"port 5061\"\r\n<\/code><\/pre>\n<hr \/>\n<h3><strong>2.3 \u53ea\u6293\u53d6 INVITE\uff08\u547c\u53eb\u8bf7\u6c42\uff09<\/strong><\/h3>\n<pre><code class=\"language-bash\">sngrep -t INVITE\r\n<\/code><\/pre>\n<p>\u6216\u8005\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -f \"udp port 5060 and sip.Method == INVITE\"\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u53ea\u663e\u793a <strong>\u547c\u53eb<\/strong> \u800c\u4e0d\u663e\u793a REGISTER\u3001OPTIONS \u7b49 SIP \u6d88\u606f\u3002<\/p>\n<hr \/>\n<h3><strong>2.4 \u53ea\u6293\u53d6\u7279\u5b9a IP \u5730\u5740\u7684 SIP \u6d41\u91cf<\/strong><\/h3>\n<p>\u5982\u679c\u4f60\u60f3\u67e5\u770b\u67d0\u4e2a FreePBX \u670d\u52a1\u5668\u6216\u5916\u90e8 VoIP \u8bbe\u5907\u7684 SIP \u6d41\u91cf\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -IP 192.168.1.100\r\n<\/code><\/pre>\n<p>\u6216\u8005\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -f \"host 192.168.1.100\"\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u8fc7\u6ee4 <strong>\u7279\u5b9a IP \u7684 SIP \u6ce8\u518c\u548c\u901a\u8bdd<\/strong>\u3002<\/p>\n<hr \/>\n<h3><strong>2.5 \u4fdd\u5b58\u6293\u5305\u6570\u636e<\/strong><\/h3>\n<p>\u4f60\u53ef\u4ee5\u5c06 SIP \u6d41\u91cf\u4fdd\u5b58\u4e3a <strong>.pcap<\/strong> \u6587\u4ef6\uff0c\u7a0d\u540e\u7528 Wireshark \u5206\u6790\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -O \/tmp\/sip_capture.pcap\r\n<\/code><\/pre>\n<p>\u7136\u540e\u4f60\u53ef\u4ee5\u7528 <code>Wireshark<\/code> \u6253\u5f00 <code>\/tmp\/sip_capture.pcap<\/code> \u8fdb\u884c\u8be6\u7ec6\u5206\u6790\u3002<\/p>\n<hr \/>\n<h3><strong>2.6 \u4ec5\u6293\u53d6 RTP \u8bed\u97f3\u6d41<\/strong><\/h3>\n<p>\u5982\u679c\u4f60\u60f3\u8981\u6293\u53d6 <strong>RTP\uff08\u8bed\u97f3\u6d41\uff09<\/strong>\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -R\r\n<\/code><\/pre>\n<p>\u4f46\u662f <code>sngrep<\/code> \u4e3b\u8981\u7528\u4e8e SIP \u534f\u8bae\u5206\u6790\uff0c\u5982\u679c\u4f60\u9700\u8981\u8be6\u7ec6 RTP \u6570\u636e\uff0c\u5efa\u8bae\u4f7f\u7528 <code>tcpdump<\/code>\uff1a<\/p>\n<pre><code class=\"language-bash\">tcpdump -i eth0 udp -w \/tmp\/rtp_capture.pcap\r\n<\/code><\/pre>\n<hr \/>\n<h2><strong>3. \u8fdb\u9636\u529f\u80fd<\/strong><\/h2>\n<h3><strong>3.1 \u4ee5\u540e\u53f0\u6a21\u5f0f\u8fd0\u884c\uff08\u8bb0\u5f55 SIP \u6d41\u91cf\uff09<\/strong><\/h3>\n<p>\u4f60\u53ef\u4ee5\u8ba9 <code>sngrep<\/code> \u5728\u540e\u53f0\u8fd0\u884c\uff0c\u5e76\u4fdd\u5b58 SIP \u4f1a\u8bdd\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -O \/var\/log\/sngrep.pcap -d\r\n<\/code><\/pre>\n<p>\u5f53\u4f60\u9700\u8981\u5206\u6790\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -I \/var\/log\/sngrep.pcap\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u4f60\u53ef\u4ee5\u5728\u7a0d\u540e\u5206\u6790\u5b58\u50a8\u7684 SIP \u6293\u5305\u6570\u636e\u3002<\/p>\n<hr \/>\n<h3><strong>3.2 \u7ed3\u5408 grep \u8fc7\u6ee4\u7279\u5b9a\u53f7\u7801<\/strong><\/h3>\n<p>\u5982\u679c\u4f60\u60f3\u67e5\u627e\u7279\u5b9a\u53f7\u7801\u7684 SIP \u547c\u53eb\uff08\u4f8b\u5982 <code>1001<\/code>\uff09\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep | grep 1001\r\n<\/code><\/pre>\n<p>\u6216\u8005\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -f \"sip contains 1001\"\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u4f60\u5c31\u80fd\u5feb\u901f\u627e\u5230 <strong>\u8be5\u53f7\u7801\u7684\u6240\u6709 SIP \u547c\u53eb<\/strong>\u3002<\/p>\n<hr \/>\n<h3><strong>3.3 \u7ed3\u5408 Wireshark \u5206\u6790<\/strong><\/h3>\n<p>\u5982\u679c\u4f60\u9700\u8981\u8be6\u7ec6 RTP \u5206\u6790\uff0c\u53ef\u4ee5\u5148\u7528 <code>sngrep<\/code> \u6293\u53d6\u6570\u636e\uff1a<\/p>\n<pre><code class=\"language-bash\">sngrep -O \/tmp\/sip_capture.pcap\r\n<\/code><\/pre>\n<p>\u7136\u540e\u5c06\u6570\u636e\u4e0b\u8f7d\u5230\u672c\u5730\uff1a<\/p>\n<pre><code class=\"language-bash\">scp root@your_freepbx_ip:\/tmp\/sip_capture.pcap .\r\n<\/code><\/pre>\n<p>\u6700\u540e\u7528 <strong>Wireshark<\/strong> \u6253\u5f00\u5e76\u4f7f\u7528 <code>sip<\/code> \u6216 <code>rtp<\/code> \u8fc7\u6ee4\u6570\u636e\u3002<\/p>\n<hr \/>\n<h2><strong>4. \u603b\u7ed3<\/strong><\/h2>\n<table>\n<thead>\n<tr>\n<th>\u547d\u4ee4<\/th>\n<th>\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>sngrep<\/code><\/td>\n<td>\u76d1\u542c\u6240\u6709 SIP \u6d41\u91cf<\/td>\n<\/tr>\n<tr>\n<td><code>sngrep -f \"port 5060\"<\/code><\/td>\n<td>\u53ea\u6293\u53d6 SIP 5060 \u7aef\u53e3\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td><code>sngrep -t INVITE<\/code><\/td>\n<td>\u53ea\u663e\u793a INVITE \u547c\u53eb<\/td>\n<\/tr>\n<tr>\n<td><code>sngrep -IP 192.168.1.100<\/code><\/td>\n<td>\u53ea\u76d1\u542c\u6307\u5b9a IP<\/td>\n<\/tr>\n<tr>\n<td><code>sngrep -O \/tmp\/sip_capture.pcap<\/code><\/td>\n<td>\u4fdd\u5b58\u6293\u5305\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td><code>sngrep -R<\/code><\/td>\n<td>\u6293\u53d6 RTP \u8bed\u97f3\u6d41<\/td>\n<\/tr>\n<tr>\n<td><code>sngrep -d<\/code><\/td>\n<td>\u540e\u53f0\u8fd0\u884c\u5e76\u8bb0\u5f55\u6570\u636e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; sngrep \u662f\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u7684 SIP \u6293\u5305\u5de5\u5177\uff0c\u4e13\u95e8\u7528\u4e8e \u5b9e\u65f6\u5206\u6790 SIP \u547c\u53eb\u6d41\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,3],"tags":[],"class_list":["post-12146","post","type-post","status-publish","format-standard","hentry","category-linux","category-system"],"_links":{"self":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/12146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12146"}],"version-history":[{"count":1,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/12146\/revisions"}],"predecessor-version":[{"id":12147,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/12146\/revisions\/12147"}],"wp:attachment":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}