打印本文 打印本文 关闭窗口 关闭窗口
VB6 中 使用Winsock穿越各种代理的实现(TCP协议)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4935  更新时间:2009/4/23 15:03:55  文章录入:mintao  责任编辑:mintao
t(DestPort / 256)

SendByte(3) = DestPort Mod 256

SendByte(4) = GetIPByte(1, DestIP)

SendByte(5) = GetIPByte(2, DestIP)

SendByte(6) = GetIPByte(3, DestIP)

SendByte(7) = GetIPByte(4, DestIP)

SendByte(8) = 0                  ''''最后要以 0 结束

Form1.Winsock1.SendData SendByte()

ConnStep = PStep + 1
Exit Function

End If


If PStep = 2 Then            ''''代理回复,第二字节为 90 为成功,其余值为失败
If Asc(Mid(RevBuffer, 2, 1)) <> 90 Then
Debug.Print Asc(Mid(RevBuffer, 2, 1))
MsgBox "连接sock4代理失败!", 48, "错误"
Form1.Winsock1.Close
ConnStep = 0
Exit Function
Else

Form1.Label8.Caption = "连接目标服务器成功!"
ConnStep = -1
Form2.Show
Exit Function
End If

End If
End If


''''*******************下面的例子有大量重复代码,是为了让大家更清楚地了解sock5穿透过程,大家可以拿回去自己优化 **********************************

If ProxyType = 1 Then ''''@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ sock5代理

Select Case PStep


Case 1
ReDim SendByte(0 To 2) As Byte   ''''第一步 无验证发送 05 01 00, 有验证发送 05 02 02
SendByte(0) = 5                     '''' 05
SendByte(1) = 1             ''''01 ''''在有用户密码验证时此字节是 1 还是 2 有诸多争论,现以腾讯QQ穿越代理模拟器时发送的数据为准,如有错误,请自己修改!
SendByte(2) = IIf(Form1.Check1.Value = 0, 0, 2) ''''00 或 02
Form1.Winsock1.SendData SendByte()
ConnStep = PStep + 1
Exit Function

Case 2               ''''代理回复
If Asc(Mid(RevBuffer, 2, 1)) = 255 Then ''''FF (255) 为失败
MsgBox "连接代理失败!", 64
Form1.Winsock1.Close
ConnStep = 0
Exit Function

End If

If Asc(Mid(RevBuffer, 2, 1)) = 0 And Asc(Mid(RevBuffer, 1, 1)) = 5 Then ''''若代理回复 05 00 为无验证连接成功
Form1.Label8.Caption = "连接成功!无验证"

ReDim SendByte(0 To 9) As Byte           ''''第二步 无验证 发送连接请求
SendByte(0) = 5
SendByte(1) = 1
SendByte(2) = 0
SendByte(3) = 1
SendByte(4) = GetIPByte(1, DestIP)
SendByte(5) = GetIPByte(2, DestIP)
SendByte(6) = GetIPByte(3, DestIP)
SendByte(7) = GetIPByte(4, DestIP)
SendByte(8) = Int(DestPort / 256)   ''''把10进制端口分成两个字节
SendByte(9) = DestPort Mod 256      ''''把10进制端口分成两个字节
Form1.Winsock1.SendData SendByte()

ConnStep = ConnStep + 1

Exit Function

End If


If Asc(Mid(RevBuffer, 2, 1)) = 2 And Asc(Mid(RevBuffer, 1, 1)) = 5 Then ''''第二步 有用户名密码验证 成功为 05 02
Form1.Label8.Caption = "连接成功!有验证"
ReDim SendByte(0 To 2 + Len(UserName) + Len(UserPassword)) As Byte

SendByte(0) = 1

SendByte(1) = Len(UserName)

MemCopy SendByte(2), ByVal UserName, Len(UserName)                     ''''将用户名转换

SendByte(2 + Len(UserName)) = Len(UserPassword)

MemCopy SendByte(3 + Len(UserName)), ByVal UserPassword, Len(UserPassword) ''''将密码转换


Form1.Winsock1.SendData SendByte()

ConnStep = ConnStep + 1

Exit Function
End If

Case
3
If Asc(Mid(RevBuffer, 2, 1)) <> 0 And Form1.Check1.Value = 1 Then ''''有验证,验证失败 代理回复第二字节为 00 验证成功,其余值为失败
MsgBox "sock5代理校验用户名、密码失败!", 48, "错误"
Form1.Winsock1.Close
ConnStep = 0
Exit Function
End If


If Asc(Mid(RevBuffer, 2, 1)) = 0 And Form1.Check1.Value = 1 Then ''''有验证,验证成功,回复值第二字节为 00 ,其余值为失败
Form1.Label8.Caption = "连接成功!有验证!"
ReDim SendByte(0 To 9) As Byte                                   ''''发送连接请求
SendByte(0) = 5
SendByte(1) = 1
SendByte(2) = 0
SendByte(3) = 1
SendByte(4) = GetIPByte(1, DestIP)
SendByte(5) = GetIPByte(2, DestIP)
SendByte(6) = GetIPByte(3, DestIP)
SendByte(7) = GetIPByte(4, DestIP)
SendByte(8) = Int(DestPort / 256) ''''把10进制端口分成两个字节
SendByte(9) = DestPort Mod 256    ''''把10进制端口分成两个字节
Form1.Winsock1.SendData SendByte()

ConnStep = ConnStep + 1

Exit Function
End If


If Asc(Mid(RevBuffer, 2, 1)) = 0 And Form1.Check1.Value = 0 Then

Form1.Label8.Caption = "连接目标服务器成功!" ''''无验证的最后一步,代理回复第二字节为 00 成功,其余值为失败
ConnStep = -1
Form2.Show
Exit Function
End If



If Asc(Mid(RevBuffer, 2, 1)) <> 0 And Form1.Check1.Value = 0 Then

MsgBox "连接目标服务器失败!", 48, "错误" ''''无验证的最后一步,代理回复第二字节为 00 成功,其余值为失败
ConnStep = 0
Form1.Winsock1.Close

Exit Function
End If


Case 4 ''''只有有验证才会用到这一步
If Asc(Mid(RevBuffer, 2, 1)) <> 0 Then
MsgBox "sock5代理连接目标服务器失败!", 48, "错误"
ConnStep = 0
Form1.Winsock1.Close
Exit Function
Else

Form1.Label8.Caption = "连接目标服务器成功!"
ConnStep = -1
Form2.Show
Exit Function
End If



End Select
End If


If ProxyType = 2 Then ''''@@@@@@@@@@@@@@@@@@@@@@@@HTTP1.1代理
If PStep = 1 Then ''''无用户名密码验证
If Form1.Check1.Value = 0 Then
HTTPHeader = "CONNECT " & Form1.Text5.Text & ":" & Form1.Text6.Text & _
" HTTP/1.1" & Chr(13) & Chr(10) & "Host: " & Form1.Text5.Text & ":" & Form1.Text6.Text & Chr(13) & Chr(10) & Chr(13) & Chr(10)

ConnStep = PStep + 1
Form1.Winsock1.SendData HTTPHeader
Exit Function

End If


If Form1.Check1.Value = 1 Then '''' 有用户名密码验证

HTTPHeader = "CONNECT " & Form1.Text5.Text & ":" & Form1.Text6.Text & _
" HTTP/1.1" & Chr(13) & Chr(10) & "Host: " & Form1.Text5.Text & ":" & _
Form1.Text6.Text & Chr(13) & Chr(10) & "Authorization: Basic " & StrtoBase64(Form1.Text3.Text & _
":" & Form1.Text4.Text) & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "Proxy-Authorization: Basic " & _
StrtoBase64(Form1.Text3.Text & ":" & Form1.Text4.Text) & Chr(13) & Chr(10) & Chr(13) & Chr(10)
'''' Chr(13) & Chr(10) 能否直接用vbCrLf ? 我不知道
Debug.Print HTTPHeader
ConnStep = PStep + 1
Form1.Winsock1.SendData HTTPHeader
Exit Function
End If



End If


If PStep = 2 Then ''''代理服务器回复,格式:HTTP/[代理版本] [状态代码] [状态说明]

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口