您的位置:首页 > 运维架构 > 网站架构

C# winForm中直接使用网站JS函数的快捷方法,可执行多种JS函数

2013-03-27 00:31 661 查看
今日不知为何,总有点感慨人生。做了程序猿已经差不多快2年了,除了工作上的软件之外,貌似从来没为自己做过什么实用的软件,比如一些快捷的工具等等。感觉着编程技术在工作上确实很难学到。特别是国内的公司,尽管更新的技术,更优秀的技术诞生了,可我们还是依然用着以前的技术,某些简单的技术,反反复复。很难找到一些挑战性的元素。于是,就找点有意思的事情来做做吧。
腾讯QQ无疑已经是国内即时通讯软件的的巨头了.相当于国外的MSN。围绕着腾讯QQ的软件也非常多非常多,例如自动回复软件.群发消息软件等等。今天,我们就以腾讯QQ的注册为案列实现一个只需要输入验证码就能注册的C#版软件。
首先我们看看腾讯QQ的注册页面



根据这个页面,我们可以了解到,注册一个QQ的基本元素。昵称,密码,性别,生日,所在地,验证码(一般第一次打开这个页面时没有验证码),还有立即注册的提交按钮。
在这之前,我们需要这边一个抓包工具来抓取POST包IE
HttpAnalyzerV6



安装后在IE浏览器的工具里可以找到,如上图所示。具体用法请百度了。这里将不再讲述。
PS:刚刚抓包才发现,我的IEHttpAnalyzer已经过期了。将就用HttpWatch吧。其实用哪个都一样。。
抓包结果如图




我们主要关注POST提交这一段就可以了。如图



图片可能小了。看不清楚,附上文字
下面是提交POST的信息
POST/cgi-bin/chs/numreg/get_acc?r=0.6192339314225849HTTP/1.1

Accept:*/*

Accept-Language:zh-cn

Referer:http://zc.qq.com/chs/index.html

Accept-Encoding:gzip,deflate

User-Agent:Mozilla/5.0(compatible;MSIE9.0;WindowsNT6.1;WOW64;Trident/5.0)

Host:zc.qq.com

Content-Length:487

Connection:Keep-Alive

Cache-Control:no-cache

Cookie:pt2gguin=o2863947406;pgv_pvid=7187609245;RK=4/CD46/CsN;ptui_loginuin=617975284;uin=o2863947406;skey=@qeJO2b28Y;ptisp=ctc;pgv_info=ssid=s4156213344;o_cookie=2863947406;verifysession=h00168891a5a6d40916b6ff218c92710d21caffe26443b349cba00a65b3849c8105588840fd02f67123;
machineCookie=655f408c42841e99c57598d3968eebf866fa30383ff98073;zc_uid=1350381363_1822484793;sessionCookie=a20b4ac684c8f95844944206dec3534fa154a2929499851a;uoc=0-0-9-0-10-0-0-19;_new_uin=2863947406;wdl=57fe92992131b79c8df28eea424ac528a95c183264a47555;
clientkey=b3c7928a115950440deb11c9e59c7f7c1fd8459b8592f2c2;index_ec=0;nick=sdfsdf
&verifycode=ovur&qzone_flag=1&country=1&province=44&city=3&isnongli=0&year=1995&month=3&day=3&isrunyue=0&password=b0b81bd39cc122dc2389abd9a6753c474ffc5cd44b29c6fae65a82d0dc9926d0ae52cfad3e70d2801f81d9fbbdaed68880d1af187d246af698ecb25c7d38795579be20cf9d553c3a9e9c70b205a8152aebd22449e0d253296d94eecad82e9583380d76dce6d91bf3760acc44e4f71ba55026e32cd9ae3601f017b757ca4bb63d&phone_num=&nick=sdfsdf&email=false&other_email=false&elevel=1&sex=1&qzdate=&jumpfrom=58030&csloginstatus=0&r5d8=w5g8
下面是提交完成后返回的数据
HTTP/1.1200OK

Server:QZHTTP-2.12

Date:Thu,18Oct201202:43:42GMT

UUID:0

Content-Length:61

Set-Cookie:_new_uin=1791969847;Domain=zc.qq.com;Path=/

Set-Cookie:sessionCookie=;Domain=zc.qq.com;Path=/

Set-Cookie:wdl=0341a2fea2414c9b26097c75206bb7339a25631b7f6860c5;Domain=zc.qq.com;Expires=Thu,18Oct201203:43:42GMT;Path=/;HTTPOnly

Set-Cookie:clientkey=bf972ece0ce54040c485d69242c3d588d7fa22a82773ffc6;Domain=zc.qq.com;Path=/

Content-Type:text/html

Connection:keep-alive
{"ec":0,"safeverifyResult":"1","type":"0","uin":"1791969847"}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
分析提交的数据
&verifycode=ovur&qzone_flag=1&country=1&province=44&city=3&isnongli=0&year=1995&month=3&day=3&isrunyue=0&password=b0b81bd39cc122dc2389abd9a6753c474ffc5cd44b29c6fae65a82d0dc9926d0ae52cfad3e70d2801f81d9fbbdaed68880d1af187d246af698ecb25c7d38795579be20cf9d553c3a9e9c70b205a8152aebd22449e0d253296d94eecad82e9583380d76dce6d91bf3760acc44e4f71ba55026e32cd9ae3601f017b757ca4bb63d&phone_num=&nick=sdfsdf&email=false&other_email=false&elevel=1&sex=1&qzdate=&jumpfrom=58030&csloginstatus=0&r5d8=w5g8
verifycode:验证码
qzone_flag:是否开通空间,1代表开通0不开通
&country=1&province=44&city=3&isnongli=0&year=1995&month=3&day=3:这些你们懂的。。
isrunyue=0:不知道什么,估计是一个固定值
password::密码你懂得后面是加密过密码的字符串
&phone_num=&nick=sdfsdf&email=false&other_email=false&elevel=1&sex=1&qzdate=&jumpfrom=58030&csloginstatus=0&r5d8=w5g8:这些就不说了。估计你不知道的参数保持原样,我们只替换知道的参数就行
分析返回的结果
{"ec":0,"safeverifyResult":"1","type":"0","uin":"1791969847"}
ec:返回的标志代码,初步预测如下:
case0:注册成功;
case1:EMAIL注册成功;
case2:验证码错误;
case4:case5:case6:生日或省份错误;
case8:case9:EMAIL错误;
case13:case15:昵称错误;
case20:需要手机短信验证;

原因:可能是COOKIE错误
case21:恶意注册,暂时禁止;

原因:注册的账号过多,或RSA算法错误
case26:需要手机激活;

原因:相同IP注册过多或提交的COOKIE已经过期,或SESSION超时
case30:浏览器不兼容;

safeverifyResult:验证码通过
type:真心不知
uin:很明显,QQ号码
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
接下来我们就是要模拟数据了,在这之前,我们需要获得一些元素
第一:URL分析
地址:【+0.161!0.019944304GET200htmlhttp://zc.qq.com/cgi-bin/chs/numreg/init?r=0.5402871509444349&cookieCode=undefined】
分析:返回结果-》{"city":"娣卞湷","cityid":"3","country":"涓浗","countryid":"1","ec":0,"elevel":"1","localdate":"2012-10-18","province":"骞夸笢","provinceid":"44"}
utf-8编码之后,就是正常的了。看字面上的意思,我相信你们理解的。
参数r:随机数,准确的来说是0.(+16个随机数)[不写貌似也可能获得]
cookiecode:cookie代码,直接忽略吧。不管它
验证码:【0.244!0.0396302812GET200jpeghttp://captcha.qq.com/getimage?aid=1007901&r=0.7166559025129264】

分析:aid是当前的版本,r是随机数
Post地址:【+0.000!0.1661459564POST200htmlhttp://zc.qq.com/cgi-bin/chs/numreg/get_acc?r=0.6192339314225849】
分析:没什么好说的。
第二:密码分析
根据:password=b0b81bd39cc122dc2389abd9a6753c474ffc5cd44b29c6fae65a82d0dc9926d0ae52cfad3e70d2801f81d9fbbdaed68880d1af187d246af698ecb25c7d38795579be20cf9d553c3a9e9c70b205a8152aebd22449e0d253296d94eecad82e9583380d76dce6d91bf3760acc44e4f71ba55026e32cd9ae3601f017b757ca4bb63d
很明显,经过加密的,到底使用什么加密呢?????


通常,如果是我们写注册模块的话。会把加密文件写在哪里呢???


没错,不用怀疑,就是JS。。。JS。
根据我们的预测,我们来look,look我们抓包的页面的js下载的URL(带上你们的火眼look,look)



相信不用一分钟的实现,你们就发现了simple.js,rsa.js,index.js我了个去。够明显吧。rsa.js…..
预测90%是rsa加密了。
index.js做网站的人大部分都知道…这个文件的含义是什么…。很明显,也是90%通过这个文件提交表单数据,然后再这个文件里面条用rsa.js进行加密。
(PS:剩下10%大家去研究吧..仔细看看文件里面的内容)
本人也在研究中…………………….
大约看了10分钟的样子,肯定加一定:rsa.js加密
细心的你们肯定还会发现…他是这样调用的。。。
rsaEncrypt:function(a)
{
varb=newRSAKey;b.setPublic("C4D23C2DB0ECC904FE0CD0CBBCDC988C039D79E1BDA8ED4BFD4D43754EC9693460D15271AB43A59AD6D0F0EEE95424F70920F2C4A08DFDF03661300047CA3A6212E48204C1BE71A846E08DD2D9F1CBDDFF40CA00C10C62B1DD42486C70A09C454293BCA9ED4E7D6657E3F62076A14304943252A88EFA416770E0FBA270A141E7","10001");
returnb.encrypt(a)
}
ok,ok,到这里。我们及知道了rsa.js加密js文件,也知道了调用的方法…那就是说。。密码这一关,过了!!!!


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
万事俱备,只欠东风啊!!!!
分析就此完成,现在开始编码…………….
新建winform程序。。拖点控件啥的就不说了…直接切入主题

第一:准备js
拷贝rsa.js的内容,在后面加个方法,如下:

functionparseBigInt(a,b){returnnewBigInteger(a,b)}functionlinebrk(a,b){for(varc="",d=0;d+b<a.length;)c+=a.substring(d,d+b)+"\n",d+=b;returnc+a.substring(d,a.length)}functionbyte2Hex(a){returna<16?"0"+a.toString(16):a.toString(16)}functionpkcs1pad2(a,b){if(b<a.length+11)returnuv_alert("MessagetoolongforRSA"),null;for(varc=[],d=a.length-1;d>=0&&b>0;){vare=a.charCodeAt(d--);e<128?c[--b]=e:e>127&&e<2048?(c[--b]=e&63|128,c[--b]=e>>6|192):(c[--b]=e&63|128,c[--b]=e>>6&63|128,c[--b]=e>>12|224)}c[--b]=0;d=newSecureRandom;for(e=[];b>2;){for(e[0]=0;e[0]==0;)d.nextBytes(e);c[--b]=e[0]}c[--b]=2;c[--b]=0;returnnewBigInteger(c)}functionRSAKey(){this.n=null;this.e=0;this.coeff=this.dmq1=this.dmp1=this.q=this.p=this.d=null}functionRSASetPublic(a,b){a!=null&&b!=null&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16)):uv_alert("InvalidRSApublickey")}functionRSADoPublic(a){returna.modPowInt(this.e,this.n)}functionRSAEncrypt(a){a=pkcs1pad2(a,this.n.bitLength()+7>>3);if(a==null)returnnull;a=this.doPublic(a);if(a==null)returnnull;a=a.toString(16);return(a.length&1)==0?a:"0"+a}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;vardbits,canary=244837814094590,j_lm=(canary&16777215)==15715070;functionBigInteger(a,b,c){a!=null&&("number"==typeofa?this.fromNumber(a,b,c):b==null&&"string"!=typeofa?this.fromString(a,256):this.fromString(a,b))}functionnbi(){returnnewBigInteger(null)}functionam1(a,b,c,d,e,f){for(;--f>=0;){varg=b*this[a++]+c[d]+e,e=Math.floor(g/67108864);c[d++]=g&67108863}returne}functionam2(a,b,c,d,e,f){varg=b&32767;for(b>>=15;--f>=0;){varh=this[a]&32767,i=this[a++]>>15,k=b*h+i*g,h=g*h+((k&32767)<<15)+c[d]+(e&1073741823),e=(h>>>30)+(k>>>15)+b*i+(e>>>30);c[d++]=h&1073741823}returne}functionam3(a,b,c,d,e,f){varg=b&16383;for(b>>=14;--f>=0;){varh=this[a]&16383,i=this[a++]>>14,k=b*h+i*g,h=g*h+((k&16383)<<14)+c[d]+e,e=(h>>28)+(k>>14)+b*i;c[d++]=h&268435455}returne}j_lm=true;BigInteger.prototype.am=am2;dbits=30;BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=(1<<dbits)-1;BigInteger.prototype.DV=1<<dbits;varBI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP);BigInteger.prototype.F1=BI_FP-dbits;BigInteger.prototype.F2=2*dbits-BI_FP;varBI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=[],rr,vv;rr="0".charCodeAt(0);for(vv=0;vv<=9;++vv)BI_RC[rr++]=vv;rr="a".charCodeAt(0);for(vv=10;vv<36;++vv)BI_RC[rr++]=vv;rr="A".charCodeAt(0);for(vv=10;vv<36;++vv)BI_RC[rr++]=vv;functionint2char(a){returnBI_RM.charAt(a)}functionintAt(a,b){varc=BI_RC[a.charCodeAt(b)];returnc==null?-1:c}functionbnpCopyTo(a){for(varb=this.t-1;b>=0;--b)a[b]=this[b];a.t=this.t;a.s=this.s}functionbnpFromInt(a){this.t=1;this.s=a<0?-1:0;a>0?this[0]=a:a<-1?this[0]=a+DV:this.t=0}functionnbv(a){varb=nbi();b.fromInt(a);returnb}functionbnpFromString(a,b){varc;if(b==16)c=4;elseif(b==8)c=3;elseif(b==256)c=8;elseif(b==2)c=1;elseif(b==32)c=5;elseif(b==4)c=2;else{this.fromRadix(a,b);return}this.s=this.t=0;for(vard=a.length,e=false,f=0;--d>=0;){varg=c==8?a[d]&255:intAt(a,d);g<0?a.charAt(d)=="-"&&(e=true):(e=false,f==0?this[this.t++]=g:f+c>this.DB?(this[this.t-1]|=(g&(1<<this.DB-f)-1)<<f,this[this.t++]=g>>this.DB-f):this[this.t-1]|=g<<f,f+=c,f>=this.DB&&(f-=this.DB))}if(c==8&&(a[0]&128)!=0)this.s=-1,f>0&&(this[this.t-1]|=(1<<this.DB-f)-1<<f);this.clamp();e&&BigInteger.ZERO.subTo(this,this)}functionbnpClamp(){for(vara=this.s&this.DM;this.t>0&&this[this.t-1]==a;)--this.t}functionbnToString(a){if(this.s<0)return"-"+this.negate().toString(a);if(a==16)a=4;elseif(a==8)a=3;elseif(a==2)a=1;elseif(a==32)a=5;elseif(a==4)a=2;elsereturnthis.toRadix(a);varb=(1<<a)-1,c,d=false,e="",f=this.t,g=this.DB-f*this.DB%a;if(f-->0){if(g<this.DB&&(c=this[f]>>g)>0)d=true,e=int2char(c);for(;f>=0;)g<a?(c=(this[f]&(1<<g)-1)<<a-g,c|=this[--f]>>(g+=this.DB-a)):(c=this[f]>>(g-=a)&b,g<=0&&(g+=this.DB,--f)),c>0&&(d=true),d&&(e+=int2char(c))}returnd?e:"0"}functionbnNegate(){vara=nbi();BigInteger.ZERO.subTo(this,a);returna}functionbnAbs(){returnthis.s<0?this.negate():this}functionbnCompareTo(a){varb=this.s-a.s;if(b!=0)returnb;varc=this.t,b=c-a.t;if(b!=0)returnb;for(;--c>=0;)if((b=this[c]-a[c])!=0)returnb;return0}functionnbits(a){varb=1,c;if((c=a>>>16)!=0)a=c,b+=16;if((c=a>>8)!=0)a=c,b+=8;if((c=a>>4)!=0)a=c,b+=4;if((c=a>>2)!=0)a=c,b+=2;a>>1!=0&&(b+=1);returnb}functionbnBitLength(){returnthis.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}functionbnpDLShiftTo(a,b){varc;for(c=this.t-1;c>=0;--c)b[c+a]=this[c];for(c=a-1;c>=0;--c)b[c]=0;b.t=this.t+a;b.s=this.s}functionbnpDRShiftTo(a,b){for(varc=a;c<this.t;++c)b[c-a]=this[c];b.t=Math.max(this.t-a,0);b.s=this.s}functionbnpLShiftTo(a,b){varc=a%this.DB,d=this.DB-c,e=(1<<d)-1,f=Math.floor(a/this.DB),g=this.s<<c&this.DM,h;for(h=this.t-1;h>=0;--h)b[h+f+1]=this[h]>>d|g,g=(this[h]&e)<<c;for(h=f-1;h>=0;--h)b[h]=0;b[f]=g;b.t=this.t+f+1;b.s=this.s;b.clamp()}functionbnpRShiftTo(a,b){b.s=this.s;varc=Math.floor(a/this.DB);if(c>=this.t)b.t=0;else{vard=a%this.DB,e=this.DB-d,f=(1<<d)-1;b[0]=this[c]>>d;for(varg=c+1;g<this.t;++g)b[g-c-1]|=(this[g]&f)<<e,b[g-c]=this[g]>>d;d>0&&(b[this.t-c-1]|=(this.s&f)<<e);b.t=this.t-c;b.clamp()}}functionbnpSubTo(a,b){for(varc=0,d=0,e=Math.min(a.t,this.t);c<e;)d+=this[c]-a[c],b[c++]=d&this.DM,d>>=this.DB;if(a.t<this.t){for(d-=a.s;c<this.t;)d+=this[c],b[c++]=d&this.DM,d>>=this.DB;d+=this.s}else{for(d+=this.s;c<a.t;)d-=a[c],b[c++]=d&this.DM,d>>=this.DB;d-=a.s}b.s=d<0?-1:0;d<-1?b[c++]=this.DV+d:d>0&&(b[c++]=d);b.t=c;b.clamp()}functionbnpMultiplyTo(a,b){varc=this.abs(),d=a.abs(),e=c.t;for(b.t=e+d.t;--e>=0;)b[e]=0;for(e=0;e<d.t;++e)b[e+c.t]=c.am(0,d[e],b,e,0,c.t);b.s=0;b.clamp();this.s!=a.s&&BigInteger.ZERO.subTo(b,b)}functionbnpSquareTo(a){for(varb=this.abs(),c=a.t=2*b.t;--c>=0;)a[c]=0;for(c=0;c<b.t-1;++c){vard=b.am(c,b[c],a,2*c,0,1);if((a[c+b.t]+=b.am(c+1,2*b[c],a,2*c+1,d,b.t-c-1))>=b.DV)a[c+b.t]-=b.DV,a[c+b.t+1]=1}a.t>0&&(a[a.t-1]+=b.am(c,b[c],a,2*c,0,1));a.s=0;a.clamp()}functionbnpDivRemTo(a,b,c){vard=a.abs();if(!(d.t<=0)){vare=this.abs();if(e.t<d.t)b!=null&&b.fromInt(0),c!=null&&this.copyTo(c);else{c==null&&(c=nbi());varf=nbi(),g=this.s,a=a.s,h=this.DB-nbits(d[d.t-1]);h>0?(d.lShiftTo(h,f),e.lShiftTo(h,c)):(d.copyTo(f),e.copyTo(c));d=f.t;e=f[d-1];if(e!=0){vari=e*(1<<this.F1)+(d>1?f[d-2]>>this.F2:0),k=this.FV/i,i=(1<<this.F1)/i,o=1<<this.F2,l=c.t,m=l-d,j=b==null?nbi():b;f.dlShiftTo(m,j);c.compareTo(j)>=0&&(c[c.t++]=1,c.subTo(j,c));BigInteger.ONE.dlShiftTo(d,j);for(j.subTo(f,f);f.t<d;)f[f.t++]=0;for(;--m>=0;){varn=c[--l]==e?this.DM:Math.floor(c[l]*k+(c[l-1]+o)*i);if((c[l]+=f.am(0,n,c,m,0,d))<n){f.dlShiftTo(m,j);for(c.subTo(j,c);c[l]<--n;)c.subTo(j,c)}}b!=null&&(c.drShiftTo(d,b),g!=a&&BigInteger.ZERO.subTo(b,b));c.t=d;c.clamp();h>0&&c.rShiftTo(h,c);g<0&&BigInteger.ZERO.subTo(c,c)}}}}functionbnMod(a){varb=nbi();this.abs().divRemTo(a,null,b);this.s<0&&b.compareTo(BigInteger.ZERO)>0&&a.subTo(b,b);returnb}functionClassic(a){this.m=a}functioncConvert(a){returna.s<0||a.compareTo(this.m)>=0?a.mod(this.m):a}functioncRevert(a){returna}functioncReduce(a){a.divRemTo(this.m,null,a)}functioncMulTo(a,b,c){a.multiplyTo(b,c);this.reduce(c)}functioncSqrTo(a,b){a.squareTo(b);this.reduce(b)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;functionbnpInvDigit(){if(this.t<1)return0;vara=this[0];if((a&1)==0)return0;varb=a&3,b=b*(2-(a&15)*b)&15,b=b*(2-(a&255)*b)&255,b=b*(2-((a&65535)*b&65535))&65535,b=b*(2-a*b%this.DV)%this.DV;returnb>0?this.DV-b:-b}functionMontgomery(a){this.m=a;this.mp=a.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<a.DB-15)-1;this.mt2=2*a.t}functionmontConvert(a){varb=nbi();a.abs().dlShiftTo(this.m.t,b);b.divRemTo(this.m,null,b);a.s<0&&b.compareTo(BigInteger.ZERO)>0&&this.m.subTo(b,b);returnb}functionmontRevert(a){varb=nbi();a.copyTo(b);this.reduce(b);returnb}functionmontReduce(a){for(;a.t<=this.mt2;)a[a.t++]=0;for(varb=0;b<this.m.t;++b){varc=a[b]&32767,d=c*this.mpl+((c*this.mph+(a[b]>>15)*this.mpl&this.um)<<15)&a.DM,c=b+this.m.t;for(a[c]+=this.m.am(0,d,a,b,0,this.m.t);a[c]>=a.DV;)a[c]-=a.DV,a[++c]++}a.clamp();a.drShiftTo(this.m.t,a);a.compareTo(this.m)>=0&&a.subTo(this.m,a)}functionmontSqrTo(a,b){a.squareTo(b);this.reduce(b)}functionmontMulTo(a,b,c){a.multiplyTo(b,c);this.reduce(c)}Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;functionbnpIsEven(){return(this.t>0?this[0]&1:this.s)==0}functionbnpExp(a,b){if(a>4294967295||a<1)returnBigInteger.ONE;varc=nbi(),d=nbi(),e=b.convert(this),f=nbits(a)-1;for(e.copyTo(c);--f>=0;)if(b.sqrTo(c,d),(a&1<<f)>0)b.mulTo(d,e,c);elsevarg=c,c=d,d=g;returnb.revert(c)}functionbnModPowInt(a,b){varc;c=a<256||b.isEven()?newClassic(b):newMontgomery(b);returnthis.exp(a,c)}BigInteger.prototype.copyTo=bnpCopyTo;BigInteger.prototype.fromInt=bnpFromInt;BigInteger.prototype.fromString=bnpFromString;BigInteger.prototype.clamp=bnpClamp;BigInteger.prototype.dlShiftTo=bnpDLShiftTo;BigInteger.prototype.drShiftTo=bnpDRShiftTo;BigInteger.prototype.lShiftTo=bnpLShiftTo;BigInteger.prototype.rShiftTo=bnpRShiftTo;BigInteger.prototype.subTo=bnpSubTo;BigInteger.prototype.multiplyTo=bnpMultiplyTo;BigInteger.prototype.squareTo=bnpSquareTo;BigInteger.prototype.divRemTo=bnpDivRemTo;BigInteger.prototype.invDigit=bnpInvDigit;BigInteger.prototype.isEven=bnpIsEven;BigInteger.prototype.exp=bnpExp;BigInteger.prototype.toString=bnToString;BigInteger.prototype.negate=bnNegate;BigInteger.prototype.abs=bnAbs;BigInteger.prototype.compareTo=bnCompareTo;BigInteger.prototype.bitLength=bnBitLength;BigInteger.prototype.mod=bnMod;BigInteger.prototype.modPowInt=bnModPowInt;BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);varrng_state,rng_pool,rng_pptr;functionrng_seed_int(a){rng_pool[rng_pptr++]^=a&255;rng_pool[rng_pptr++]^=a>>8&255;rng_pool[rng_pptr++]^=a>>16&255;rng_pool[rng_pptr++]^=a>>24&255;rng_pptr>=rng_psize&&(rng_pptr-=rng_psize)}functionrng_seed_time(){rng_seed_int((newDate).getTime())}if(rng_pool==null){rng_pool=[];rng_pptr=0;vart;for(;rng_pptr<rng_psize;)t=Math.floor(65536*Math.random()),rng_pool[rng_pptr++]=t>>>8,rng_pool[rng_pptr++]=t&255;rng_pptr=0;rng_seed_time()}functionrng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr<rng_pool.length;++rng_pptr)rng_pool[rng_pptr]=0;rng_pptr=0}returnrng_state.next()}functionrng_get_bytes(a){varb;for(b=0;b<a.length;++b)a[b]=rng_get_byte()}functionSecureRandom(){}SecureRandom.prototype.nextBytes=rng_get_bytes;functionArcfour(){this.j=this.i=0;this.S=[]}functionARC4init(a){varb,c,d;for(b=0;b<256;++b)this.S[b]=b;for(b=c=0;b<256;++b)c=c+this.S[b]+a[b%a.length]&255,d=this.S[b],this.S[b]=this.S[c],this.S[c]=d;this.j=this.i=0}functionARC4next(){vara;this.i=this.i+1&255;this.j=this.j+this.S[this.i]&255;a=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=a;returnthis.S[a+this.S[this.i]&255]}Arcfour.prototype.init=ARC4init;Arcfour.prototype.next=ARC4next;functionprng_newstate(){returnnewArcfour}varrng_psize=256;functionrs(a){varb=newRSAKey;b.setPublic("C4D23C2DB0ECC904FE0CD0CBBCDC988C039D79E1BDA8ED4BFD4D43754EC9693460D15271AB43A59AD6D0F0EEE95424F70920F2C4A08DFDF03661300047CA3A6212E48204C1BE71A846E08DD2D9F1CBDDFF40CA00C10C62B1DD42486C70A09C454293BCA9ED4E7D6657E3F62076A14304943252A88EFA416770E0FBA270A141E7","10001");returnb.encrypt(a)}


要想在winform中调用js….需要安装控件
【MicrosoftScriptControl】/Winform调用js
没有的,猛击这里
不懂怎么操作的,猛击这里
提示一下:




引用的文件要把嵌入互操作类型设为false
第二:准备HttpHelper类
没有的,猛击这里
核心代码页贴出来吧,如下。。。(别人写的)

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

usingSystem.Net;

usingSystem.IO;

usingSystem.Drawing;

usingSystem.Text.RegularExpressions;


namespaceWindowsFormsRs

{

publicclassHttpHelper

{

privateCookieContainercc;


publicCookieContainerCC

{

get

{

returncc;

}

set

{

this.cc=value;

}

}


publicHttpHelper()

{

this.cc=newCookieContainer();

}


publicHttpHelper(CookieContainercc)

{

this.cc=cc;

}


///<summary>

///使用post方式访问目标网页,返回stream二进制流

///</summary>

publicStreamPostAndGetStream(stringtargetURL,stringformData,stringcontentType,stringreferer,boolallowAutoRedirect)

{

//数据编码

ASCIIEncodingencoding=newASCIIEncoding();

//UTF8Encodingencoding=newUTF8Encoding();

byte[]data=encoding.GetBytes(formData);


//请求目标网页

HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create(targetURL);

request.CookieContainer=cc;

request.Method="POST";//使用post方式发送数据

request.ContentType="application/x-www-form-urlencoded";

request.Referer=referer;

request.AllowAutoRedirect=allowAutoRedirect;

request.ContentLength=data.Length;

request.UserAgent="Mozilla/4.0(compatible;MSIE7.0;WindowsNT5.1;SV1;.NETCLR2.0.1124)";

//request.UnsafeAuthenticatedConnectionSharing=false;

//模拟一个UserAgent

StreamnewStream=request.GetRequestStream();

newStream.Write(data,0,data.Length);

newStream.Close();


//获取网页响应结果

HttpWebResponseresponse=(HttpWebResponse)request.GetResponse();

cc.Add(response.Cookies);

Streamstream=response.GetResponseStream();

returnstream;

}


///<summary>

///使用post方式访问目标网页,返回字节数组

///</summary>

publicbyte[]PostAndGetByte(stringtargetURL,stringformData,stringcontentType,stringreferer,boolallowAutoRedirect)

{

Streamstream=PostAndGetStream(targetURL,formData,contentType,referer,allowAutoRedirect);

byte[]bytes=newbyte[stream.Length];

stream.Read(bytes,0,bytes.Length);

stream.Seek(0,SeekOrigin.Begin);

returnbytes;

}


///<summary>

///使用post方式访问目标网页,返回图片

///</summary>

publicImagePostAndGetBitmap(stringtargetURL,stringformData,stringcontentType,stringreferer,boolallowAutoRedirect)

{

Streamstream=PostAndGetStream(targetURL,formData,contentType,referer,allowAutoRedirect);

Imageimage=Image.FromStream(stream);

returnimage;

}


///<summary>

///使用post方式访问目标网页,返回文件

///</summary>

publicvoidPostAndGetBitmap(stringtargetURL,stringformData,stringcontentType,stringreferer,boolallowAutoRedirect,stringfileName)

{

byte[]bytes=PostAndGetByte(targetURL,formData,contentType,referer,allowAutoRedirect);

FileStreamfs=newFileStream(fileName,FileMode.Create);

BinaryWriterbw=newBinaryWriter(fs);

bw.Write(bytes);

bw.Close();

fs.Close();

}


///<summary>

///使用post方式访问目标网页,返回html页面

///</summary>

publicstringPostAndGetHtml(stringtargetURL,stringformData,stringcontentType,stringreferer,boolallowAutoRedirect,Encodingencoding)

{

Streamstream=PostAndGetStream(targetURL,formData,contentType,referer,allowAutoRedirect);

stringhtml=newStreamReader(stream,encoding).ReadToEnd();

returnhtml;

}



///<summary>

///使用get方式访问目标网页,返回stream二进制流

///</summary>

publicStreamGetAndGetStream(stringtargetURL,stringcontentType,stringreferer,boolallowAutoRedirect)

{

//请求目标网页

HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create(targetURL);

request.CookieContainer=cc;

CC=cc;

request.Method="GET";//使用get方式发送数据

request.ContentType=contentType;

request.Referer=referer;

request.AllowAutoRedirect=allowAutoRedirect;

request.UserAgent="Mozilla/4.0(compatible;MSIE7.0;WindowsNT5.1;SV1;.NETCLR2.0.1124)";



//获取网页响应结果

HttpWebResponseresponse=(HttpWebResponse)request.GetResponse();

cc.Add(response.Cookies);

Streamstream=response.GetResponseStream();

returnstream;

}


///<summary>

///使用get方式访问目标网页,返回字节数组

///</summary>

publicbyte[]GetAndGetByte(stringtargetURL,stringcontentType,stringreferer,boolallowAutoRedirect)

{

Streamstream=GetAndGetStream(targetURL,contentType,referer,allowAutoRedirect);

byte[]bytes=newbyte[stream.Length];

stream.Read(bytes,0,bytes.Length);

stream.Seek(0,SeekOrigin.Begin);

returnbytes;

}


///<summary>

///使用get方式访问目标网页,返回图片

///</summary>

publicImageGetAndGetBitmap(stringtargetURL,stringcontentType,stringreferer,boolallowAutoRedirect)

{

Streamstream=GetAndGetStream(targetURL,contentType,referer,true);

Imageimage=Image.FromStream(stream);

returnimage;

}


///<summary>

///使用get方式访问目标网页,返回文件

///</summary>

publicvoidGetAndGetFile(stringtargetURL,stringcontentType,stringreferer,boolallowAutoRedirect,stringfileName)

{

byte[]bytes=GetAndGetByte(targetURL,contentType,referer,allowAutoRedirect);

FileStreamfs=newFileStream(fileName,FileMode.Create);

BinaryWriterbw=newBinaryWriter(fs);

bw.Write(bytes);

bw.Close();

fs.Close();

}


///<summary>

///使用get方式访问目标网页,返回html页面

///</summary>

publicstringGetAndGetHtml(stringtargetURL,stringcontentType,stringreferer,boolallowAutoRedirect,Encodingencoding)

{

Streamstream=GetAndGetStream(targetURL,contentType,referer,allowAutoRedirect);

stringhtml=newStreamReader(stream,encoding).ReadToEnd();

returnhtml;

}

}

}


第三:编写代码开始

privatestaticHttpHelperhttpHelper=newHttpHelper();

///<summary>

///得到第一次加密后的密码

///</summary>

///<paramname="jsFilePath">js文件</param>

///<paramname="funcName">加密的方法名</param>

///<paramname="paramers">加密方法需要传进的参数(一个是密码,另一个是页面上可获取的一个标志码)</param>

///<returns>加密过后的密码</returns>

publicstaticobjectGetRSAPassword(stringjsFilePath,stringfuncName,paramsobject[]paramers)

{

StreamReaderreader=newStreamReader(jsFilePath);

stringsScript=reader.ReadToEnd();

ScriptEnginese=newScriptEngine(ScriptLanguage.JavaScript);

objectobj=se.Run(funcName,paramers,sScript);

returnobj;

}


//"nick="+name+"&isnongli=0&isrunyue=0&appid=9&year="+year+"&month="+month+"&day="+day+"&sex="+sex+"&elevel=1&password="+GetRSAPassword(password)+"&verifycode="+code;

publicstaticstringRegisterQQNum(stringname,stringrsapassword,stringsex,stringyear,stringmonth,stringday,stringcode)

{

UTF8Encodingutf8=newUTF8Encoding();

Byte[]encodedBytes=utf8.GetBytes(name);//编码

name=System.Text.Encoding.UTF8.GetString(encodedBytes,0,(int)encodedBytes.Length);

stringregisterURL="http://zc.qq.com/cgi-bin/iframe/numreg/get_acc_9";

stringpostData=string.Format("nick={0}&isnongli=0&isrunyue=0&appid=9&year={1}&month={2}&day={3}&sex={4}&elevel=1&password={5}&verifycode={6}","aaaaabbbb",year,month,day,sex,rsapassword,code);





Debug.WriteLine(postData);

//httpHelper.CC=newSystem.Net.CookieContainer();

stringhtml=httpHelper.PostAndGetHtml(registerURL,postData,null,null,false,Encoding.UTF8);


//stringhtml=htlp.GetHtml(registerURL,postData,Encoding.UTF8);

returnhtml;


}



publicstaticstringGetRandrom()

{

Randomrand=newRandom();

stringstrNum="";

inti=0;

while(i<16)

{

i++;

intrandomNum=rand.Next(0,10);

strNum+=randomNum.ToString();

}

strNum="0."+strNum;

returnstrNum;

}



publicstaticImageGetCode()

{

stringpath="http://captcha.qq.com/getimage?aid=1007901&"+GetRandrom();

Imageimage=httpHelper.GetAndGetBitmap(path,null,null,false);

returnimage;


}



publicstaticstringGetAddress()

{

stringpath="http://zc.qq.com/cgi-bin/iframe/numreg/init_9?id="+GetRandrom();

stringhtml=httpHelper.GetAndGetHtml(path,null,null,true,Encoding.UTF8);

returnhtml;

}


以上是我编写的代码.调用而已…没啥啥技术含量滴。。
注册的参数删掉了很多,可以吧不必要的删掉。但是需要谨慎操作啊…!!!


Winform界面代码:(上图,总有动手写几行代码哦,亲…)



界面效果如下:








--------------------------------------------运行中,下图返回---------------------------------------




ok,注册成功
大功告成!!!

HttpHelper要小小修改一下,腾讯QQ在POST提交的时候要把获取验证码的cookie一并提交上去
但是这个HttpHelper没有把获取图片的Cookie赋值到POSTCookie.
所以要把CC=cc的代码写入.




-----------------------------------------------------------------------------------------------------
申明,本文只做教学指导只用,切勿干坏事!!!
如有疑问请回复本文章
源码:猛击下载
/article/6972324.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: