Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chisel
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
anun
chisel
Commits
ccd7441a
Commit
ccd7441a
authored
Jun 10, 2024
by
anun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flag code
parent
fe246359
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
55 additions
and
8 deletions
+55
-8
chisel
+0
-0
client/client.go
+11
-6
client/client_connect.go
+3
-2
main.go
+3
-0
server/server_handler.go
+5
-0
share/settings/config.go
+1
-0
share/settings/remote.go
+19
-0
share/tunnel/tunnel.go
+5
-0
share/tunnel/tunnel_in_proxy.go
+8
-0
No files found.
chisel
View file @
ccd7441a
No preview for this file type
client/client.go
View file @
ccd7441a
...
...
@@ -44,6 +44,7 @@ type Config struct {
TLS
TLSConfig
DialContext
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
Verbose
bool
Code
string
}
// TLSConfig for a Client
...
...
@@ -120,7 +121,7 @@ func NewClient(c *Config) (*Client, error) {
client
.
Logger
.
Info
=
true
p
,
e
:=
getPort
(
c
.
Server
+
"/register"
)
client
.
Debugf
(
"
p = %s"
,
p
)
client
.
Debugf
(
"--->
p = %s"
,
p
)
if
e
!=
nil
{
client
.
Errorf
(
"request %s/register : %s"
,
c
.
Server
,
e
)
}
...
...
@@ -158,13 +159,16 @@ client.Debugf("p = %s", p)
}
client
.
tlsConfig
=
tc
}
if
c
.
Code
==
""
{
c
.
Code
=
settings
.
RandString
(
16
)
}
//validate remotes
client
.
Debugf
(
"
c.Remotes = %s"
,
c
.
Remotes
)
// client.Debugf("--->
c.Remotes = %s", c.Remotes)
for
_
,
s
:=
range
c
.
Remotes
{
s
=
"R:"
+
string
(
p
)
+
":"
+
s
client
.
Debugf
(
"s = %s"
,
s
)
client
.
Debugf
(
"s = %s"
,
s
)
r
,
err
:=
settings
.
DecodeRemote
(
s
)
client
.
Debugf
(
"r = %s"
,
r
)
client
.
Debugf
(
"r = %s"
,
r
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Failed to decode remote '%s': %s"
,
s
,
err
)
}
...
...
@@ -186,14 +190,15 @@ client.Debugf("r = %s", r)
}
client
.
computed
.
Remotes
=
append
(
client
.
computed
.
Remotes
,
r
)
}
client
.
Infof
(
"Remotes# %s"
,
client
.
computed
.
Remotes
)
client
.
computed
.
Code
=
c
.
Code
client
.
Infof
(
"---> Remotes client.computed# %s"
,
client
.
computed
)
//outbound proxy
if
p
:=
c
.
Proxy
;
p
!=
""
{
client
.
proxyURL
,
err
=
url
.
Parse
(
p
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Invalid proxy URL (%s)"
,
err
)
}
client
.
Debugf
(
"
client.proxyURL = %s"
,
client
.
proxyURL
)
client
.
Debugf
(
"--->
client.proxyURL = %s"
,
client
.
proxyURL
)
}
//ssh auth and config
user
,
pass
:=
settings
.
ParseAuth
(
c
.
Auth
)
...
...
client/client_connect.go
View file @
ccd7441a
...
...
@@ -91,7 +91,6 @@ func (c *Client) connectionOnce(ctx context.Context) (connected bool, err error)
}
}
//c.Infof("c.server = %s", c.server)
//c.Infof("c = %s", c)
wsConn
,
_
,
err
:=
d
.
DialContext
(
ctx
,
c
.
server
,
c
.
config
.
Headers
)
if
err
!=
nil
{
return
false
,
err
...
...
@@ -115,6 +114,8 @@ func (c *Client) connectionOnce(ctx context.Context) (connected bool, err error)
// chisel client handshake (reverse of server handshake)
// send configuration
c
.
Debugf
(
"Sending config"
)
c
.
Debugf
(
"---> c.computed = %s"
,
c
.
computed
)
//c.Debugf("---> c = %s", c)
t0
:=
time
.
Now
()
_
,
configerr
,
err
:=
sshConn
.
SendRequest
(
"config"
,
...
...
@@ -128,7 +129,7 @@ func (c *Client) connectionOnce(ctx context.Context) (connected bool, err error)
if
len
(
configerr
)
>
0
{
return
false
,
errors
.
New
(
string
(
configerr
))
}
//c.Infof("
settings.EncodeConfig = %s", settings.EncodeConfig(c.computed))
//c.Debugf("--->
settings.EncodeConfig = %s", settings.EncodeConfig(c.computed))
c
.
Infof
(
"Connected (Latency %s)"
,
time
.
Since
(
t0
))
//connected, handover ssh connection for tunnel to use, and block
err
=
c
.
tunnel
.
BindSSH
(
ctx
,
sshConn
,
reqs
,
chans
)
...
...
main.go
View file @
ccd7441a
...
...
@@ -416,6 +416,8 @@ var clientHelp = `
--tls-cert, a path to a PEM encoded certificate matching the provided
private key. The certificate must have client authentication
enabled (mutual-TLS).
--code, serial number, token, text
`
+
commonHelp
func
client
(
args
[]
string
)
{
...
...
@@ -432,6 +434,7 @@ func client(args []string) {
flags
.
StringVar
(
&
config
.
TLS
.
Cert
,
"tls-cert"
,
""
,
""
)
flags
.
StringVar
(
&
config
.
TLS
.
Key
,
"tls-key"
,
""
,
""
)
flags
.
Var
(
&
headerFlags
{
config
.
Headers
},
"header"
,
""
)
flags
.
StringVar
(
&
config
.
Code
,
"code"
,
""
,
""
)
hostname
:=
flags
.
String
(
"hostname"
,
""
,
""
)
sni
:=
flags
.
String
(
"sni"
,
""
,
""
)
pid
:=
flags
.
Bool
(
"pid"
,
false
,
""
)
...
...
server/server_handler.go
View file @
ccd7441a
...
...
@@ -112,6 +112,7 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, req *http.Request) {
l
.
Debugf
(
"Verifying configuration"
)
// wait for request, with timeout
var
r
*
ssh
.
Request
// l.Debugf("---> r = %s", r)
select
{
case
r
=
<-
reqs
:
case
<-
time
.
After
(
settings
.
EnvDuration
(
"CONFIG_TIMEOUT"
,
10
*
time
.
Second
))
:
...
...
@@ -127,7 +128,9 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, req *http.Request) {
failed
(
s
.
Errorf
(
"expecting config request"
))
return
}
l
.
Debugf
(
"---> r.Payload = %s"
,
r
.
Payload
)
c
,
err
:=
settings
.
DecodeConfig
(
r
.
Payload
)
l
.
Debugf
(
"---> c = %s"
,
c
)
if
err
!=
nil
{
failed
(
s
.
Errorf
(
"invalid config"
))
return
...
...
@@ -192,7 +195,9 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, req *http.Request) {
err
=
eg
.
Wait
()
if
err
!=
nil
&&
!
strings
.
HasSuffix
(
err
.
Error
(),
"EOF"
)
{
l
.
Debugf
(
"Closed connection (%s)"
,
err
)
l
.
Debugf
(
"Code (%s)"
,
s
.
config
)
}
else
{
l
.
Debugf
(
"Closed connection"
)
l
.
Debugf
(
"Code (%s)"
,
s
.
config
)
}
}
share/settings/config.go
View file @
ccd7441a
...
...
@@ -8,6 +8,7 @@ import (
type
Config
struct
{
Version
string
Remotes
Code
string
}
func
DecodeConfig
(
b
[]
byte
)
(
*
Config
,
error
)
{
...
...
share/settings/remote.go
View file @
ccd7441a
...
...
@@ -7,6 +7,8 @@ import (
"regexp"
"strconv"
"strings"
// "log"
"math/rand"
)
// short-hand conversions (see remote_test)
...
...
@@ -36,6 +38,7 @@ type Remote struct {
LocalHost
,
LocalPort
,
LocalProto
string
RemoteHost
,
RemotePort
,
RemoteProto
string
Socks
,
Reverse
,
Stdio
bool
Code
string
}
const
revPrefix
=
"R:"
...
...
@@ -56,6 +59,7 @@ func DecodeRemote(s string) (*Remote, error) {
//to provide the defaults)
for
i
:=
len
(
parts
)
-
1
;
i
>=
0
;
i
--
{
p
:=
parts
[
i
][
1
]
//log.Println(r.Code)
//remote portion is socks?
if
i
==
len
(
parts
)
-
1
&&
p
==
"socks"
{
r
.
Socks
=
true
...
...
@@ -66,6 +70,12 @@ func DecodeRemote(s string) (*Remote, error) {
r
.
Stdio
=
true
continue
}
// if i == len(parts)-1 && len(p) >= 16 && p != "socks" && p != "stdio" {
// r.Code = p
// continue
// }
p
,
proto
:=
L4Proto
(
p
)
if
proto
!=
""
{
if
r
.
RemotePort
==
""
{
...
...
@@ -273,3 +283,12 @@ func (rs Remotes) Encode() []string {
}
return
s
}
func
RandString
(
n
int
)
string
{
const
letterBytes
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b
:=
make
([]
byte
,
n
)
for
i
:=
range
b
{
b
[
i
]
=
letterBytes
[
rand
.
Intn
(
len
(
letterBytes
))]
}
return
string
(
b
)
}
share/tunnel/tunnel.go
View file @
ccd7441a
...
...
@@ -70,6 +70,7 @@ func New(c Config) *Tunnel {
//BindSSH provides an active SSH for use for tunnelling
func
(
t
*
Tunnel
)
BindSSH
(
ctx
context
.
Context
,
c
ssh
.
Conn
,
reqs
<-
chan
*
ssh
.
Request
,
chans
<-
chan
ssh
.
NewChannel
)
error
{
//t.Debugf("reqs %s", reqs)
//link ctx to ssh-conn
go
func
()
{
<-
ctx
.
Done
()
...
...
@@ -151,11 +152,14 @@ func (t *Tunnel) BindRemotes(ctx context.Context, remotes []*settings.Remote) er
}
proxies
:=
make
([]
*
Proxy
,
len
(
remotes
))
for
i
,
remote
:=
range
remotes
{
//t.Debugf("remote = %s", remote)
//e.g. tun: remote = R:60569=>172.16.112.109:8001
p
,
err
:=
NewProxy
(
t
.
Logger
,
t
,
t
.
proxyCount
,
remote
)
if
err
!=
nil
{
return
err
}
proxies
[
i
]
=
p
//t.Debugf("p = %s", p)
t
.
proxyCount
++
}
//TODO: handle tunnel close
...
...
@@ -169,6 +173,7 @@ func (t *Tunnel) BindRemotes(ctx context.Context, remotes []*settings.Remote) er
t
.
Debugf
(
"Bound proxies"
)
err
:=
eg
.
Wait
()
t
.
Debugf
(
"Unbound proxies"
)
t
.
Debugf
(
"................"
)
return
err
}
...
...
share/tunnel/tunnel_in_proxy.go
View file @
ccd7441a
...
...
@@ -5,6 +5,7 @@ import (
"io"
"net"
"sync"
"log"
"dev.nexpie.com/anun/chisel/share/cio"
"dev.nexpie.com/anun/chisel/share/settings"
...
...
@@ -56,6 +57,7 @@ func (p *Proxy) listen() error {
}
p
.
Infof
(
"Listening"
)
p
.
tcp
=
l
// regisAddress(p.remote.Code)
}
else
if
p
.
remote
.
LocalProto
==
"udp"
{
l
,
err
:=
listenUDP
(
p
.
Logger
,
p
.
sshTun
,
p
.
remote
)
if
err
!=
nil
{
...
...
@@ -63,6 +65,7 @@ func (p *Proxy) listen() error {
}
p
.
Infof
(
"Listening"
)
p
.
udp
=
l
// regisAddress(p.remote.Code)
}
else
{
return
p
.
Errorf
(
"unknown local proto"
)
}
...
...
@@ -148,3 +151,8 @@ func (p *Proxy) pipeRemote(ctx context.Context, src io.ReadWriteCloser) {
s
,
r
:=
cio
.
Pipe
(
src
,
dst
)
l
.
Debugf
(
"Close (sent %s received %s)"
,
sizestr
.
ToString
(
s
),
sizestr
.
ToString
(
r
))
}
func
regisAddress
(
c
string
)
{
log
.
Printf
(
"NEXPIE route register..."
)
log
.
Printf
(
"p.remote.Code = %s"
,
c
)
}
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