﻿{"id":788,"date":"2011-12-29T13:01:10","date_gmt":"2011-12-29T05:01:10","guid":{"rendered":"http:\/\/notes.zerobox.org\/?p=788"},"modified":"2011-12-29T13:01:10","modified_gmt":"2011-12-29T05:01:10","slug":"%e8%bf%85%e9%9b%b7p2p%e9%80%9a%e4%bf%a1%e7%9a%84%e5%8a%a0%e5%af%86%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"http:\/\/zerobox.org\/notes\/788.html","title":{"rendered":"\u8fc5\u96f7P2P\u901a\u4fe1\u7684\u52a0\u5bc6\u7b97\u6cd5"},"content":{"rendered":"<p>\u6765\u6e90\uff1a<a href=\"http:\/\/hi.baidu.com\/vessial\/blog\/item\/93080325fed3097e35a80f93.html\">http:\/\/hi.baidu.com\/vessial\/blog\/item\/93080325fed3097e35a80f93.html<\/a><\/p>\n<p>\u5171\u4eab\u4e00\u4e0b\u8fc5\u96f7P2P\u901a\u4fe1\u7684\u52a0\u5bc6\u7b97\u6cd5\uff0c\u65b9\u4fbf\u90a3\u4e9b\u7814\u7a76\u8fc5\u96f7P2P\u901a\u4fe1\u534f\u8bae\u7684\u540c\u5b66\u4eec\uff1a\uff09<\/p>\n<p>\u7b97\u6cd5\u7ec6\u8282\u4e0d\u8be6\u7ec6\u63cf\u8ff0\u4e86\uff0c\u5171\u4eab\u7b97\u6cd5\u4ee3\u7801\uff0c\u53ea\u6709python\u7248\uff0c\u89e3\u5bc6\u51fa\u6765\u7684\u7ed3\u679c\u5c31\u662f<\/p>\n<p>\u660e\u6587\u534f\u8bae\u4e86\uff0c\u63a5\u4e0b\u6765\u7684\u4e8b\u60c5\u5c31\u662f\u505a\u534f\u8bae\u5206\u6790\u4e86\u3002\u53d1\u4e00\u4e2a\u534f\u8bae\u901a\u4fe1\u7684\u7247\u65ad\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>192.168.1.103 port 10047 &#8212;&gt; 111.195.202.215 port 10527<\/p>\n<p>0000 \u00a032 00 00 00 05 10 00 00 00 30 30 32 32 46 42 38 \u00a02&#8230;&#8230;..0022FB8<\/p>\n<p>0010 \u00a033 41 41 41 34 38 4e 51 51 00 00 3b b4 \u00a0 \u00a0 \u00a0 \u00a03AAA48NQQ..;.<\/p>\n<p>&nbsp;<\/p>\n<p>111.195.202.215 port 10527 &#8212;&gt; 192.168.1.103 port 10047<\/p>\n<p>0000 \u00a032 00 00 00 06 00 00 00 00 3b b4 00 00 61 6a 00 \u00a02&#8230;&#8230;..;&#8230;aj.<\/p>\n<p>0010 \u00a002 25 e2 60 24 00 00 00 00 00 00 01 00 00 00 \u00a0 \u00a0.%.`$&#8230;&#8230;&#8230;.<\/p>\n<p>&nbsp;<\/p>\n<p>192.168.1.103 port 10047 &#8212;&gt; 111.195.202.215 port 10527<\/p>\n<p>0000 \u00a032 00 00 00 06 01 00 00 00 00 00 3b b4 61 57 e1 \u00a02&#8230;&#8230;&#8230;.;.aW.<\/p>\n<p>0010 \u00a003 63 e1 7a 03 26 e2 60 24 00 00 05 00 00 00 \u00a0 \u00a0.c.z.&amp;.`$&#8230;&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p>111.195.202.215 port 10527 &#8212;&gt; 192.168.1.103 port 10047<\/p>\n<p>0000 \u00a032 00 00 00 11 3b b4 00 00 61 6a 00 02 00 00 01 \u00a02&#8230;.;&#8230;aj&#8230;..<\/p>\n<p>0010 \u00a000 26 e2 60 24 64 e1 7a 03 63 e1 7a 03 01 00 00 \u00a0.&amp;.`$d.z.c.z&#8230;.<\/p>\n<p>0020 \u00a000 00 00 00 00 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#8230;..<\/p>\n<div>\u7b97\u6cd5\u5982\u4e0b<\/div>\n<div>#Created by vessial<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>def p2p_udp_encrypt(pkt):<\/p>\n<p>header=random.randint(0,0xffff)<\/p>\n<p>t=((header&amp;0x1fff)+0x4000)&lt;&lt;0x10<\/p>\n<p>t+=random.randint(0,0xffff)<\/p>\n<p>body=struct.pack(&#8216;I&#8217;,t)<\/p>\n<p>sec2=random.randint(0,0xff)<\/p>\n<p>body+=struct.pack(&#8216;B&#8217;,sec2)<\/p>\n<p>length=(sec2&amp;0x03)+9<\/p>\n<p>pos=length<\/p>\n<p>for i in range(length-5):<\/p>\n<p>x=random.randint(0,0xff)<\/p>\n<p>body+=struct.pack(&#8216;B&#8217;,x)<\/p>\n<p>l=pos*7<\/p>\n<p>t=struct.unpack(&#8216;B&#8217;,body[pos-3])[0]<\/p>\n<p>t*=0x0d<\/p>\n<p>t&amp;=0xff<\/p>\n<p>k=l^t<\/p>\n<p>header=body[:pos-2]+struct.pack(&#8216;B&#8217;,k)<\/p>\n<p>t=struct.unpack(&#8216;B&#8217;,header[-1])[0]<\/p>\n<p>t*=0x0d<\/p>\n<p>t&amp;=0xff<\/p>\n<p>k=(l+7)^t<\/p>\n<p>header=header+struct.pack(&#8216;B&#8217;,k)<\/p>\n<p>out=&#8221;<\/p>\n<p>j=0<\/p>\n<p>t=array.array(&#8216;B&#8217;,header)<\/p>\n<p>buf=array.array(&#8216;B&#8217;,pkt)<\/p>\n<p>body_len=len(pkt)<\/p>\n<p>for i in range(body_len):<\/p>\n<p>j+=1<\/p>\n<p>if j==pos:<\/p>\n<p>j=0<\/p>\n<p>x=t[j]+0x5b<\/p>\n<p>x&amp;=0xff<\/p>\n<p>x^=t[j-1]<\/p>\n<p>t[j-1]=x<\/p>\n<p>buf[i]=(buf[i]+x)&amp;0xff<\/p>\n<p>out=header+buf.tostring()<\/p>\n<p>#print &#8220;out buf len is %d&#8221;%len(out)<\/p>\n<p>#print hexdump(out)<\/p>\n<p>#print hexdump(p2p_udp_decrypt(out))<\/p>\n<p>return out<\/p>\n<p>def p2p_udp_decrypt(pkt):<\/p>\n<p>if len(pkt)&lt;=8:<\/p>\n<p>return False<\/p>\n<p>header=struct.unpack(&#8216;&lt;I&#8217;,pkt[:4])[0]<\/p>\n<p>header&gt;&gt;=0x1d<\/p>\n<p>if header&gt;3:<\/p>\n<p>return False<\/p>\n<p>elif header ==1:<\/p>\n<p>pass<\/p>\n<p>elif header ==2:<\/p>\n<p>byte5=struct.unpack(&#8216;B&#8217;,pkt[4])[0]<\/p>\n<p>byte5&amp;=0x80000003<\/p>\n<p>byte5+=9<\/p>\n<p>if byte5&gt;len(pkt):<\/p>\n<p>return False<\/p>\n<p>pos=byte5<\/p>\n<p>head_check=array.array(&#8216;B&#8217;,pkt[:pos])<\/p>\n<p>t=struct.unpack(&#8216;B&#8217;,pkt[pos-2])[0]<\/p>\n<p>mid=pos*7<\/p>\n<p>p=7*pos+7<\/p>\n<p>t*=0x0d<\/p>\n<p>t&amp;=0xff<\/p>\n<p>p^=t<\/p>\n<p>s=struct.unpack(&#8216;B&#8217;,pkt[pos-1])[0]<\/p>\n<p>if p != s:<\/p>\n<p>return False<\/p>\n<p>t=struct.unpack(&#8216;B&#8217;,pkt[pos-3])[0]<\/p>\n<p>t*=0x0d<\/p>\n<p>t&amp;=0xff<\/p>\n<p>t^=mid<\/p>\n<p>if t !=struct.unpack(&#8216;B&#8217;,pkt[pos-2])[0]:<\/p>\n<p>return False<\/p>\n<p>j=0<\/p>\n<p>body=array.array(&#8216;B&#8217;,pkt[pos:])<\/p>\n<p>body_len=len(pkt)-pos<\/p>\n<p>for i in range(body_len):<\/p>\n<p>j+=1<\/p>\n<p>if j==pos:<\/p>\n<p>j=0<\/p>\n<p>x=head_check[j]+0x5b<\/p>\n<p>x&amp;=0xff<\/p>\n<p>x^=head_check[j-1]<\/p>\n<p>head_check[j-1]=x<\/p>\n<p>body[i]=(body[i]-x)&amp;0xff<\/p>\n<p>x=body.tostring()<\/p>\n<p>#print hexdump(x)<\/p>\n<p>return x<\/p>\n<p>elif header ==3:<\/p>\n<p>pass<\/p>\n<p>return False<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u6e90\uff1ahttp:\/\/hi.baidu.com\/vessial\/blog\/item &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/zerobox.org\/notes\/788.html\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[187],"class_list":["post-788","post","type-post","status-publish","format-standard","hentry","tag-187"],"views":1124,"_links":{"self":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/comments?post=788"}],"version-history":[{"count":0,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/788\/revisions"}],"wp:attachment":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/media?parent=788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/categories?post=788"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/tags?post=788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}