Skip to content

Commit 57870d3

Browse files
committed
Added interval and broken cli arguments into groups
1 parent d566325 commit 57870d3

File tree

2 files changed

+62
-31
lines changed

2 files changed

+62
-31
lines changed

inout/interval.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package inout
2+
3+
import (
4+
"io"
5+
"time"
6+
)
7+
8+
type Interval struct {
9+
io.ReadWriteCloser
10+
Interval int
11+
}
12+
13+
func (this *Interval) Read(p []byte) (n int, err error) {
14+
time.Sleep(time.Duration(this.Interval) * time.Second)
15+
n, err = this.ReadWriteCloser.Read(p)
16+
return n, err
17+
}

main.go

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,52 +37,65 @@ func NewReadWriteCloser(r io.Reader, w io.Writer, c io.Closer) io.ReadWriteClose
3737
var opts struct {
3838
// This is already the behaviour. Probably too difficult (and no reason) to implement
3939
// Close bool `short:"c" long:"close" description:"Close connection on EOF from stdin"`
40-
Detect bool `short:"D" long:"detect" description:"Detect remote shell automatically and try to raise a TTY on the remote (action)"`
41-
Exec string `short:"e" long:"exec" description:"Program to exec after connect"`
42-
// TODO
43-
Gateway []string `short:"g" long:"gateway" description:"Source-routing hop point[s], up to 8"`
44-
// TODO
45-
Pointer int `short:"G" long:"pointer" description:"Source-routing pointer:4, 8, 12, ..."`
46-
// TODO
47-
IdleTimeout int `short:"i" long:"interval" description:"Delay interval for lines sent, ports scanned"`
40+
// TODO: WTF is this?
41+
// Gateway []string `short:"g" long:"gateway" description:"Source-routing hop point[s], up to 8"`
42+
// TODO: WTF is this?
43+
// Pointer int `short:"G" long:"pointer" description:"Source-routing pointer:4, 8, 12, ..."`
4844
Listen bool `short:"l" long:"listen" description:"Listen mode, for inbound connects"`
49-
// TODO
50-
Tunnel string `short:"L" long:"tunnel" description:"Forward local port to remote address"`
51-
// TODO
52-
DontResolve bool `short:"n" long:"dont-resolve" description:"Numeric-only IP addresses, no DNS"`
53-
// TODO
54-
Output string `short:"o" long:"output" description:"Output hexdump traffic to FILE (implies -x)"`
45+
// TODO: Needs exposure of listen/dial conns
46+
// DontResolve bool `short:"n" long:"dont-resolve" description:"Numeric-only IP addresses, no DNS"`
5547
Port string `short:"p" long:"local-port" description:"Local port number"`
56-
Protocol string `short:"P" long:"protocol" description:"Provide protocol in the form of tcp{,4,6}|udp{,4,6}|unix{,gram,packet}|ip{,4,6}[:<protocol-number>|:<protocol-name>]\nFor <protocol-number> check https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml"`
5748
// Does not have any effect - even on netcat
5849
Randomize bool `short:"r" long:"randomize" description:"Randomize local and remote ports"`
59-
Raw bool `short:"R" long:"auto-raw" description:"Put local TTY in Raw mode on connect (action)"`
6050
Source string `short:"s" long:"source" description:"Local source address (ip or hostname)"`
61-
TCP bool `short:"t" long:"tcp" description:"TCP mode (default)"`
6251
// TODO
6352
Telnet bool `short:"T" long:"telnet" description:"answer using TELNET negotiation"`
64-
UDP bool `short:"u" long:"udp" description:"UDP mode"`
6553
// TODO
6654
Verbose bool `short:"v" long:"verbose" description:"-- Not effective, backwards compatibility"`
6755
// TODO
6856
Version bool `short:"V" long:"version" description:"Output version information and exit"`
69-
HexDump bool `short:"x" long:"hexdump" description:"Hexdump incoming and outgoing traffic"`
70-
// TODO
71-
Wait int `short:"w" long:"wait" description:"Timeout for connects and final net reads"`
72-
Zero bool `short:"z" long:"zero" description:"Zero-I/O mode (used for scanning)"`
57+
// TODO: Needs exposure of listen/dial conns
58+
// Wait int `short:"w" long:"wait" description:"Timeout for connects and final net reads"`
7359

7460
Positional struct {
7561
Hostname string `positional-arg-name:"hostname"`
7662
Port string `positional-arg-name:"port"`
7763
} `positional-args:"yes"`
7864
}
7965

66+
var optsService struct {
67+
Protocol string `short:"P" long:"protocol" description:"Provide protocol in the form of tcp{,4,6}|udp{,4,6}|unix{,gram,packet}|ip{,4,6}[:<protocol-number>|:<protocol-name>]\nFor <protocol-number> check https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml"`
68+
TCP bool `short:"t" long:"tcp" description:"TCP mode (default)"`
69+
UDP bool `short:"u" long:"udp" description:"UDP mode"`
70+
}
71+
72+
var optsInOut struct {
73+
// This is already the behaviour. Probably too difficult (and no reason) to implement
74+
// Close bool `short:"c" long:"close" description:"Close connection on EOF from stdin"`
75+
Exec string `short:"e" long:"exec" description:"Program to exec after connect"`
76+
Interval int `short:"i" long:"interval" description:"Delay interval for data sent, ports scanned"`
77+
// TODO: Needs exposure of listen/dial conns
78+
Tunnel string `short:"L" long:"tunnel" description:"Forward local port to remote address"`
79+
// TODO
80+
Output string `short:"o" long:"output" description:"Output hexdump traffic to FILE (implies -x)"`
81+
HexDump bool `short:"x" long:"hexdump" description:"Hexdump incoming and outgoing traffic"`
82+
Zero bool `short:"z" long:"zero" description:"Zero-I/O mode (used for scanning)"`
83+
}
84+
85+
var optsAction struct {
86+
Detect bool `short:"D" long:"detect" description:"Detect remote shell automatically and try to raise a TTY on the remote" group:"Actions"`
87+
Raw bool `short:"R" long:"auto-raw" description:"Put local TTY in Raw mode on connect (action)"`
88+
}
89+
8090
func main() {
8191
// Arguments
8292
// TODO: Break this into groups, in a different small function
8393
// TODO: Add option name to all arguments (tunnel=<something>)
8494
parser := flags.NewNamedParser("netcatty", flags.Default)
8595
parser.AddGroup("Application Options", "", &opts)
96+
parser.AddGroup("Service", "", &optsService)
97+
parser.AddGroup("InOut", "", &optsInOut)
98+
parser.AddGroup("Action", "", &optsAction)
8699
_, err := parser.Parse()
87100
if err != nil { return }
88101

@@ -99,11 +112,11 @@ func main() {
99112
address := strings.Join([]string{hostname, port}, ":")
100113

101114
protocol := "tcp"
102-
if opts.UDP {
115+
if optsService.UDP {
103116
protocol = "udp"
104117
}
105-
if len(opts.Protocol) > 0 {
106-
protocol = opts.Protocol
118+
if len(optsService.Protocol) > 0 {
119+
protocol = optsService.Protocol
107120
}
108121

109122
// Logo & Help
@@ -114,10 +127,10 @@ func main() {
114127
var ioc io.ReadWriteCloser
115128
var actions []func(service.Server) action.Actor
116129

117-
if len(opts.Exec) > 0 {
118-
ioc, err = inout.NewExec(opts.Exec)
130+
if len(optsInOut.Exec) > 0 {
131+
ioc, err = inout.NewExec(optsInOut.Exec)
119132
handleErr(err)
120-
} else if opts.Zero {
133+
} else if optsInOut.Zero {
121134
ioc, err = inout.NewZero()
122135
handleErr(err)
123136
} else {
@@ -135,20 +148,21 @@ func main() {
135148

136149
ioc = NewReadWriteCloser(in, t.Output(), t)
137150

138-
if opts.Raw {
151+
if optsAction.Raw {
139152
a := action.AutoRawActionGetter{t}
140153
actions = append(actions, a.GetAutoRawAction)
141154
}
142155
}
143156

144-
if opts.HexDump { ioc = &inout.HexDump{ioc} }
157+
if optsInOut.HexDump { ioc = &inout.HexDump{ioc} }
158+
if optsInOut.Interval > 0 { ioc = &inout.Interval{ioc, optsInOut.Interval} }
145159

146160
// Service
147161
var s service.Server
148162
s = service.NewNet(ioc, protocol, address)
149163

150164
// Actions
151-
if opts.Detect { action.NewRaiseTTY(s).Register() }
165+
if optsAction.Detect { action.NewRaiseTTY(s).Register() }
152166

153167
for _, a := range actions {
154168
a(s).Register()

0 commit comments

Comments
 (0)