-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change password reader and other cleanups
- Loading branch information
Showing
1 changed file
with
16 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,34 +8,16 @@ import ( | |
"io" | ||
"os" | ||
"strings" | ||
"syscall" | ||
|
||
"golang.org/x/crypto/ssh" | ||
|
||
"github.com/bgentry/speakeasy" | ||
"golang.org/x/crypto/ssh/terminal" | ||
|
||
"github.com/google/gopacket" | ||
"github.com/google/gopacket/layers" | ||
"github.com/google/gopacket/pcapgo" | ||
) | ||
|
||
/* | ||
Example output | ||
3.021795 10.10.0.100.42066 -> 10.10.0.1.22: ack 2725452283 | ||
0x0000 704c a55b 64e0 5404 a61b b3dd 0800 4510 pL.[d.T.......E. | ||
0x0010 0034 518e 4000 4006 d4ad 0a0a 0064 0a0a .4Q.@[email protected].. | ||
0x0020 0001 a452 0016 f69b 908d a273 19fb 8010 ...R.......s.... | ||
0x0030 1a8b 67b8 0000 0101 080a 3e36 f642 081d ..g.......>6.B.. | ||
0x0040 bb6a .j | ||
TODO: | ||
- graceful shutdown | ||
- get the stats sent from the fg on shutdown: | ||
^C | ||
66 packets received by filter | ||
0 packets dropped by kernel | ||
- code organization | ||
*/ | ||
|
||
// decodeSniff reads input produced by the fortigate sniffer | ||
func decodeSniff(r io.Reader, w io.Writer) error { | ||
snaplen := 3000 | ||
|
@@ -99,16 +81,18 @@ func main() { | |
os.Exit(1) | ||
} | ||
|
||
pass, err := speakeasy.Ask("password:") | ||
fmt.Print("Password: ") | ||
pass, err := terminal.ReadPassword(int(syscall.Stdin)) | ||
if err != nil { | ||
fmt.Println("error getting password:", err) | ||
os.Exit(1) | ||
} | ||
fmt.Println() | ||
|
||
sshConfig := &ssh.ClientConfig{ | ||
User: *userP, | ||
Auth: []ssh.AuthMethod{ | ||
ssh.Password(pass), | ||
ssh.Password(string(pass)), | ||
}, | ||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), | ||
} | ||
|
@@ -119,12 +103,20 @@ func main() { | |
os.Exit(1) | ||
} | ||
|
||
if *verbP { | ||
fmt.Println("Successfully connected") | ||
} | ||
|
||
session, err := client.NewSession() | ||
if err != nil { | ||
fmt.Printf("Failed to create session: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
if *verbP { | ||
fmt.Println("SSH session created") | ||
} | ||
|
||
modes := ssh.TerminalModes{ | ||
ssh.ECHO: 0, // disable echoing | ||
ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud | ||
|
@@ -152,7 +144,8 @@ func main() { | |
os.Exit(1) | ||
} | ||
|
||
// go io.Copy(f, stdout) | ||
fmt.Println("Capturing packets...") | ||
|
||
go decodeSniff(stdout, f) | ||
|
||
cnt := "" | ||
|