Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
1012043a
Commit
1012043a
authored
Oct 30, 2015
by
rui.zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
detail log
parent
01040ca1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
21 deletions
+31
-21
http.go
http.go
+4
-1
socks.go
socks.go
+27
-20
No files found.
http.go
View file @
1012043a
...
...
@@ -18,6 +18,7 @@ func handleHttpRequest(req *http.Request, conn net.Conn, arg Args) {
glog
.
Infoln
(
string
(
dump
))
}
}
glog
.
V
(
LINFO
)
.
Infoln
(
"[http] CONNECT"
,
req
.
Host
)
var
username
,
password
string
if
arg
.
User
!=
nil
{
...
...
@@ -44,7 +45,7 @@ func handleHttpRequest(req *http.Request, conn net.Conn, arg Args) {
c
,
err
:=
Connect
(
req
.
Host
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
err
)
glog
.
V
(
LWARNING
)
.
Infoln
(
"[http] CONNECT"
,
req
.
Host
,
err
)
b
:=
[]
byte
(
"HTTP/1.1 503 Service unavailable
\r\n
"
+
"Proxy-Agent: gost/"
+
Version
+
"
\r\n\r\n
"
)
...
...
@@ -74,6 +75,8 @@ func handleHttpRequest(req *http.Request, conn net.Conn, arg Args) {
return
}
}
glog
.
V
(
LINFO
)
.
Infoln
(
"[http] CONNECT"
,
req
.
Host
,
"OK"
)
Transport
(
conn
,
c
)
}
...
...
socks.go
View file @
1012043a
...
...
@@ -159,11 +159,11 @@ func handleSocks5Request(req *gosocks5.Request, conn net.Conn) {
switch
req
.
Cmd
{
case
gosocks5
.
CmdConnect
:
glog
.
V
(
LINFO
)
.
Infoln
(
"
>>> socks5 connect:"
,
req
.
Addr
.
String
()
)
glog
.
V
(
LINFO
)
.
Infoln
(
"
[socks5] CONNECT"
,
req
.
Addr
)
tconn
,
err
:=
Connect
(
req
.
Addr
.
String
())
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"
socks5 connect:"
,
err
)
glog
.
V
(
LWARNING
)
.
Infoln
(
"
[socks5] CONNECT"
,
req
.
Addr
,
err
)
rep
:=
gosocks5
.
NewReply
(
gosocks5
.
HostUnreachable
,
nil
)
if
err
:=
rep
.
Write
(
conn
);
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 connect:"
,
err
)
...
...
@@ -181,9 +181,10 @@ func handleSocks5Request(req *gosocks5.Request, conn net.Conn) {
}
glog
.
V
(
LDEBUG
)
.
Infoln
(
rep
)
glog
.
V
(
LINFO
)
.
Infoln
(
"[socks5] CONNECT"
,
req
.
Addr
,
"OK"
)
Transport
(
conn
,
tconn
)
case
gosocks5
.
CmdBind
:
glog
.
V
(
LINFO
)
.
Infoln
(
"
>>> socks5 bind:
"
,
req
.
Addr
)
glog
.
V
(
LINFO
)
.
Infoln
(
"
[socks5] BIND
"
,
req
.
Addr
)
if
len
(
forwardArgs
)
>
0
{
forwardBind
(
req
,
conn
)
...
...
@@ -191,7 +192,7 @@ func handleSocks5Request(req *gosocks5.Request, conn net.Conn) {
serveBind
(
conn
)
}
case
gosocks5
.
CmdUdp
:
glog
.
V
(
LINFO
)
.
Infoln
(
"
>>> socks5 udp associate:
"
,
req
.
Addr
)
glog
.
V
(
LINFO
)
.
Infoln
(
"
[socks5] UDP ASSOCIATE
"
,
req
.
Addr
)
uconn
,
err
:=
net
.
ListenUDP
(
"udp"
,
nil
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 udp listen:"
,
err
)
...
...
@@ -208,7 +209,7 @@ func handleSocks5Request(req *gosocks5.Request, conn net.Conn) {
addr
:=
ToSocksAddr
(
uconn
.
LocalAddr
())
addr
.
Host
,
_
,
_
=
net
.
SplitHostPort
(
conn
.
LocalAddr
()
.
String
())
glog
.
V
(
LINFO
)
.
Infoln
(
"
socks5 udp listen:
"
,
addr
)
glog
.
V
(
LINFO
)
.
Infoln
(
"
[socks5] UDP listen on
"
,
addr
)
rep
:=
gosocks5
.
NewReply
(
gosocks5
.
Succeeded
,
addr
)
if
err
:=
rep
.
Write
(
conn
);
err
!=
nil
{
...
...
@@ -223,7 +224,7 @@ func handleSocks5Request(req *gosocks5.Request, conn net.Conn) {
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 udp:"
,
err
)
return
}
glog
.
V
(
L
DEBUG
)
.
Infof
(
"[udp] to %s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
glog
.
V
(
L
INFO
)
.
Infof
(
"[udp] to %s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
raddr
,
err
:=
net
.
ResolveUDPAddr
(
"udp"
,
dgram
.
Header
.
Addr
.
String
())
if
err
!=
nil
{
...
...
@@ -245,7 +246,7 @@ func handleSocks5Request(req *gosocks5.Request, conn net.Conn) {
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 udp:"
,
err
)
return
}
glog
.
V
(
L
DEBUG
)
.
Infof
(
"[udp] from %s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
glog
.
V
(
L
INFO
)
.
Infof
(
"[udp] from %s, length %d"
,
dgram
.
Header
.
Addr
,
len
(
dgram
.
Data
))
if
err
=
cc
.
WriteUDPTimeout
(
dgram
,
time
.
Second
*
30
);
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 udp:"
,
err
)
...
...
@@ -275,7 +276,6 @@ func serveBind(conn net.Conn) error {
addr
:=
ToSocksAddr
(
l
.
Addr
())
// Issue: may not reachable when host has two interfaces
addr
.
Host
,
_
,
_
=
net
.
SplitHostPort
(
conn
.
LocalAddr
()
.
String
())
glog
.
V
(
LINFO
)
.
Infoln
(
"socks5 bind:"
,
addr
)
rep
:=
gosocks5
.
NewReply
(
gosocks5
.
Succeeded
,
addr
)
if
err
:=
rep
.
Write
(
conn
);
err
!=
nil
{
...
...
@@ -284,6 +284,7 @@ func serveBind(conn net.Conn) error {
return
err
}
glog
.
V
(
LDEBUG
)
.
Infoln
(
rep
)
glog
.
V
(
LINFO
)
.
Infoln
(
"[socks5] BIND on"
,
addr
,
"OK"
)
tconn
,
err
:=
l
.
AcceptTCP
()
l
.
Close
()
// only accept one peer
...
...
@@ -301,7 +302,7 @@ func serveBind(conn net.Conn) error {
defer
tconn
.
Close
()
addr
=
ToSocksAddr
(
tconn
.
RemoteAddr
())
glog
.
V
(
LINFO
)
.
Infoln
(
"
socks5 bind accept:"
,
addr
.
String
()
)
glog
.
V
(
LINFO
)
.
Infoln
(
"
[socks5] BIND accept"
,
addr
)
rep
=
gosocks5
.
NewReply
(
gosocks5
.
Succeeded
,
addr
)
if
err
:=
rep
.
Write
(
conn
);
err
!=
nil
{
...
...
@@ -316,6 +317,7 @@ func serveBind(conn net.Conn) error {
func
forwardBind
(
req
*
gosocks5
.
Request
,
conn
net
.
Conn
)
error
{
fconn
,
_
,
err
:=
forwardChain
(
forwardArgs
...
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"[socks5] BIND(forward)"
,
req
.
Addr
,
err
)
if
fconn
!=
nil
{
fconn
.
Close
()
}
...
...
@@ -330,42 +332,47 @@ func forwardBind(req *gosocks5.Request, conn net.Conn) error {
defer
fconn
.
Close
()
if
err
:=
req
.
Write
(
fconn
);
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"
socks5 bind forward:
"
,
err
)
glog
.
V
(
LWARNING
)
.
Infoln
(
"
[socks5] BIND(forward)
"
,
err
)
gosocks5
.
NewReply
(
gosocks5
.
Failure
,
nil
)
.
Write
(
conn
)
return
err
}
glog
.
V
(
LDEBUG
)
.
Infoln
(
req
)
// first reply
if
err
:=
peekReply
(
conn
,
fconn
);
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 bind forward:"
,
err
)
rep
,
err
:=
peekReply
(
conn
,
fconn
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"[socks5] BIND(forward)"
,
err
)
return
err
}
glog
.
V
(
LINFO
)
.
Infoln
(
"[socks5] BIND(forward) on"
,
rep
.
Addr
,
"OK"
)
// second reply
if
err
:=
peekReply
(
conn
,
fconn
);
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"socks5 bind forward:"
,
err
)
rep
,
err
=
peekReply
(
conn
,
fconn
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
"[socks5] BIND(forward) accept"
,
err
)
return
err
}
glog
.
V
(
LINFO
)
.
Infoln
(
"[socks5] BIND(forward) accept"
,
rep
.
Addr
)
return
Transport
(
conn
,
fconn
)
}
func
peekReply
(
dst
io
.
Writer
,
src
io
.
Reader
)
error
{
rep
,
err
:
=
gosocks5
.
ReadReply
(
src
)
func
peekReply
(
dst
io
.
Writer
,
src
io
.
Reader
)
(
rep
*
gosocks5
.
Reply
,
err
error
)
{
rep
,
err
=
gosocks5
.
ReadReply
(
src
)
if
err
!=
nil
{
glog
.
V
(
LWARNING
)
.
Infoln
(
err
)
rep
=
gosocks5
.
NewReply
(
gosocks5
.
Failure
,
nil
)
}
if
err
:
=
rep
.
Write
(
dst
);
err
!=
nil
{
return
err
if
err
=
rep
.
Write
(
dst
);
err
!=
nil
{
return
}
glog
.
V
(
LDEBUG
)
.
Infoln
(
rep
)
if
rep
.
Rep
!=
gosocks5
.
Succeeded
{
return
errors
.
New
(
"Failure"
)
err
=
errors
.
New
(
"Failure"
)
}
return
nil
return
}
func
createClientConn
(
conn
net
.
Conn
,
uconn
*
net
.
UDPConn
)
(
c
*
UDPConn
,
dgram
*
gosocks5
.
UDPDatagram
,
err
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment