Jump to content
Sign in to follow this  
Particle

Socks4 Problem

Recommended Posts

Particle

I've been trying to write a simple chat program that connects to Battle.net through a Socks4 protocol. After doing the research i've seem to come so close, but I just dont understand what i'm doing wrong. Could anyone figure this out. All I want is for the socks4 proxy to respond back so I can send the data for connecting to Battle.net.

References:

http://www.autoitscript.com/forum/index.ph...;hl=socks+proxy

http://www.autoitscript.com/forum/index.ph...p;hl=battle.net

Source Code:

TCPStartup()
ConsoleWrite("Connecting..." & @CR)

$hc = TCPConnect("121.11.80.135",1080)                  ; Socks4a Proxy Server

If @error Then
    ConsoleWrite("Failed!" & @CR)
    Exit
Else
    ConsoleWrite("Connected!" & @CR)
EndIf

$sReq =   Chr(0x04) _                                   ; Protocol version  4
        & Chr(0x01) _                                   ; Command Code  1 - establish a tcp/ip stream connection
        & Chr(0x3d) & Chr(0x0c) _                       ; Port      6112
        & Chr(0x00) & Chr(0x00) & Chr(0x0) & Chr(0xFF) _ ; Ip Adress   Invalid - 0.0.0.255
        & "" & Chr(0x00) _                             ; User Id      Empty  
        & "63.240.202.139" & Chr(0x00)                 ; Host Name   useast.battle.net
        
;Chr(0x3f) & Chr(0xF0) & Chr(0xCA) & Chr(0x8B)         ;This set of chr is 63.240.202.139 in hex format

; Send Request to Proxy
ConsoleWrite("Sending Request..." & @CR)
ConsoleWrite("! Request: " & Hex(BinaryToString($sReq)) & @CR)
TCPSend($hc,$sReq)

; Wait for the Reply
While 1
    $sBuff = TCPRecv($hc,2048,1)
    If @error Then Exit @ScriptLineNumber
    If StringLen($sBuff) > 0 Then ExitLoop
    Sleep(100)
WEnd

$sBuff &= TCPRecv($hc,8,1)
ConsoleWrite("!   Reply: " & Hex(BinaryToString($sBuff)) & @CR)

; Check for errors
Switch StringMid(Hex(BinaryToString($sBuff)),3,2)
    Case "5A"
        ConsoleWrite("> request granted" & @CR)
    Case "5B"
        ConsoleWrite("> request rejected or failed" & @CR)
        Exit @ScriptLineNumber
    Case "5C"
        ConsoleWrite("> request failed because client is not running identd (or not reachable from the server)" & @CR)
        Exit @ScriptLineNumber
    Case "5D"
        ConsoleWrite("> request failed because client's identd could not confirm the user id string in the request" & @CR)
        Exit @ScriptLineNumber
EndSwitch

Exit

It seems when I run the program, it successfully connects to the socks4 proxy and attempts to send the protocol data and get's no response. My guess is my format is totally off somehow for $sReq, but i'm not totally sure...

Share this post


Link to post
Share on other sites
Particle

Bump :mellow:

Share this post


Link to post
Share on other sites
dbzfanatic

It's extremely rude to bump within 24 hours of your previous post. Someone will help you when they have time, no sooner. Please be patient.

Share this post


Link to post
Share on other sites
TehWhale

To Connect to battle.net and read/write text messages in the chat, you need to have a login/password. I do not see anywhere in your script where it sends this data.

Share this post


Link to post
Share on other sites
Particle

i thought u could bump every 4-5 hours... :mellow:

if u actually read my post u would understand that im first trying to make connection with the socks4, i have not gotten to the battle.net part. im first trying to make a successful connection where i send the first data upon connection and hope for a response. im not getting any response from the socks4 proxy server and yes i have made sure the proxy server is working and running.

Share this post


Link to post
Share on other sites
Glyph

TCPSend($hc,$sReq)

; Wait for the Reply
While 1
    $sBuff = TCPRecv($hc,2048,1)
    If @error Then Exit @ScriptLineNumber
    If StringLen($sBuff) > 0 Then ExitLoop
    Sleep(100)
WEnd

You need to set these both in the loop, a GUI would do this.

You tcp send. Once its sent, you get a reply.

But, you have not gotten to the loop to receive the reply yet.

A gui would work because you're always in the loop, if you press a button to send the packet while receiving, you'll prolly get a better response.

If not, then I don't know.

Edited by Glyph

tolle indicium

Share this post


Link to post
Share on other sites
Particle

TCPSend($hc,$sReq)

; Wait for the Reply
While 1
    $sBuff = TCPRecv($hc,2048,1)
    If @error Then Exit @ScriptLineNumber
    If StringLen($sBuff) > 0 Then ExitLoop
    Sleep(100)
WEnd

You need to set these both in the loop, a GUI would do this.

You tcp send. Once its sent, you get a reply.

But, you have not gotten to the loop to receive the reply yet.

A gui would work because you're always in the loop, if you press a button to send the packet while receiving, you'll prolly get a better response.

If not, then I don't know.

Yeah you dont know. :mellow: Putting the script in a GUI will not make any difference. First off I dont want tcpsend in a loop cause I would rather not cause any spam to the proxy server. Second, where you say "But, you have not gotten to the loop to receive the reply yet.", yes actually I have. If you notice in my script on line 24, a consolewrite shows that you are about to send request and the next line the request is sent. What is right after that? line 28, the beginning of the loop which waits for a reply. If there is an error and no reply then of course it ends program and exits on line 30. So yes my reply is in a loop and thats where I'm running into problems. As far as I can tell, my syntax for $sReq must be completely wrong because it seems that my request is blank through the console. Even after following instructions on both socks4 and socks4a through Wiki.

Reference:

http://en.wikipedia.org/wiki/SOCKS

I've checked the proxy and it still works and now after just running the program again to check syntax errors it seems that its replied this time, but as I guessed it, something has to be wrong cause my reply is of course blank...

Console:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Code Backup\Au3 Files\Socks4.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams    
+>09:39:32 Starting AutoIt3Wrapper v.1.10.1.12  Environment(Language:0409  Keyboard:00000409  OS:WIN_VISTA/  CPU:X86  ANSI)
>Running AU3Check (1.54.13.0)  from:C:\Program Files\AutoIt3
+>09:39:33 AU3Check ended.rc:0
>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Code Backup\Au3 Files\Socks4.au3"  
Connecting...
Connected!
Sending Request...
! Request: 00000000
!   Reply: 00000000
+>09:39:55 AutoIT3.exe ended.rc:0
+>09:39:56 AutoIt3Wrapper Finished
>Exit code: 0   Time: 24.879

Share this post


Link to post
Share on other sites
SoulA

With this code here are you trying to craft your own special packet just for battlenet? Is this something battlenet can read? What is the return packet supposed to look like.

Edit: NM I see the link you posted now. Seems like you followed it pretty closely and if theres worked not sure why yours is not. I see that your info being sent is completely borked by your SCiTe output.

$sReq =   Chr(0x04) _                               ; Protocol version  4
        & Chr(0x01) _                               ; Command Code  1 - establish a tcp/ip stream connection
        & Chr(0x3d) & Chr(0x0c) _                   ; Port      6112
        & Chr(0x00) & Chr(0x00) & Chr(0x0) & Chr(0xFF) _; Ip Adress   Invalid - 0.0.0.255
        & "" & Chr(0x00) _                      ; User Id     Empty 
        & "63.240.202.139" & Chr(0x00)          ; Host Name   useast.battle.net
        
;Chr(0x3f) & Chr(0xF0) & Chr(0xCA) & Chr(0x8B)  ;This set of chr is 63.240.202.139 in hex format

When you send this it will just be a string I believe.

Edited by SoulA

Share this post


Link to post
Share on other sites
Particle

This topic isn't about battle.net guys, thats just the next step. I have not got there yet. Right now i'm focused on socks4 proxies in general. Being able to send a reply and get a response. I realize my sent reply has battle.net pretty much written all over it, perhaps that's what i'm doing wrong? All I want right now is to establish a connection with the proxy server to allow me to send over the so called 'bnet' data in hopes to connect to UsEast.Battle.Net server.

Share this post


Link to post
Share on other sites
SoulA

I ran this code and it connected to my socks proxy and returned the html of mamma. I changed the IP of battlenet as well.

TCPStartup()
 
$hc = TCPConnect("127.0.0.1",1080)          ; Socks4a Proxy Server
 
$sReq =   Chr(0x04) _                                    ; Protocol version  4
        & Chr(0x01) _                                    ; Command Code    1 - establish a tcp/ip stream connection
        & Chr(0x3d) & Chr(0x0c) _                        ; Port        6112
        & Chr(0x00) & Chr(0x00) & Chr(0x0) & Chr(0xFF) _ ; Ip Adress   Invalid - 0.0.0.255
        & "" & Chr(0x00) _                               ; User Id      Empty    
        & "63.240.202.131" & Chr(0x00)                   ; Host Name   useast.battle.net

; Send Request to Proxy
ConsoleWrite("! Request: " & Hex(BinaryToString($sReq)) & @CR)
TCPSend($hc,$sReq)

; Wait for the Reply
While 1
    $sBuff = TCPRecv($hc,1)
    If @error Then Exit @ScriptLineNumber
    If StringLen($sBuff) > 0 Then ExitLoop
    Sleep(100)
WEnd

$sBuff &= TCPRecv($hc,8)
ConsoleWrite("!   Reply: " & Hex(BinaryToString($sBuff)) & @CR)

; Check for errors
Switch StringMid(Hex(BinaryToString($sBuff)),3,2)
    Case "5A"
        ConsoleWrite("> request granted" & @CR)
    Case "5B"
        ConsoleWrite("> request rejected or failed" & @CR)
        Exit @ScriptLineNumber
    Case "5C"
        ConsoleWrite("> request failed because client is not running identd (or not reachable from the server)" & @CR)
        Exit @ScriptLineNumber
    Case "5D"
        ConsoleWrite("> request failed because client's identd could not confirm the user id string in the request" & @CR)
        Exit @ScriptLineNumber
EndSwitch

; Send Http Request to mamma and Search for "AutoIt"
$sReq  = "GET /Mamma?query=AutoIt HTTP/1.0" & @CRLF & @CRLF
ConsoleWrite("! Request:" & @CR & $sReq & "---------------------------------" & @CR)
TCPSend($hc,$sReq)

; Wait for the Reply
ConsoleWrite("Receiving Data ")
$sRepy = ""
While 1
    $sBuff = TCPRecv($hc,1024*5)
    If @error Then ExitLoop
    If StringLen($sBuff) > 0 Then
        $sRepy &= $sBuff
        ConsoleWrite(".")
    EndIf
    Sleep(100)
WEnd

; Parse Reply
$iHeadEnd = StringInStr($sRepy,@CRLF & @CRLF) + 2
$sRepyHead = StringMid($sRepy,1,$iHeadEnd)
$sRepyBody = StringMid($sRepy,$iHeadEnd)

ConsoleWrite(@CR & "! Reply:" & @CR & $sRepyHead & "---------------------------------" & @CR)

; Save Result to disk
$hFile = FileOpen("socks.htm",2)
FileWrite($hFile,$sRepyBody)
FileClose($hFile)

ConsoleWrite("Reply Body stored in .\socks.htm (" & Round(StringLen($sRepyBody)/1024,2) & "Kb)" & @CR)

Share this post


Link to post
Share on other sites
Glyph

First off I dont want tcpsend in a loop cause I would rather not cause any spam to the proxy server.

You obviously don't know how to handle loops.

When you click a button in a gui it executes the command, it doesn't execute uncontrollably. (you control the tcpsend with a button)

Hope that helps!


tolle indicium

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×