-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from Mythologyli/dns-hijack-new
feat: add dns-hijack for tun mode
- Loading branch information
Showing
21 changed files
with
962 additions
and
162 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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package terminal_func | ||
|
||
import ( | ||
"context" | ||
"github.com/mythologyli/zju-connect/log" | ||
) | ||
|
||
type TerminalFunc func(ctx context.Context) error | ||
type TerminalItem struct { | ||
f TerminalFunc | ||
name string | ||
} | ||
|
||
var terminalFuncList []TerminalItem | ||
|
||
var terminalBegin = false | ||
|
||
func RegisterTerminalFunc(execName string, fun TerminalFunc) { | ||
terminalFuncList = append(terminalFuncList, TerminalItem{ | ||
f: fun, | ||
name: execName, | ||
}) | ||
log.Println("Register func on terminal:", execName) | ||
} | ||
|
||
func ExecTerminalFunc(ctx context.Context) []error { | ||
var errList []error | ||
terminalBegin = true | ||
for _, item := range terminalFuncList { | ||
log.Println("Exec func on terminal:", item.name) | ||
if err := item.f(ctx); err != nil { | ||
errList = append(errList, err) | ||
log.Println("Exec func on terminal ", item.name, "failed:", err) | ||
} else { | ||
log.Println("Exec func on terminal ", item.name, "success") | ||
} | ||
} | ||
return errList | ||
} | ||
|
||
func IsTerminal() bool { | ||
return terminalBegin | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package zcdns | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/miekg/dns" | ||
"net" | ||
) | ||
|
||
type LocalServer interface { | ||
HandleDnsMsg(ctx context.Context, msg *dns.Msg) (*dns.Msg, error) | ||
CheckDnsHijack(dstIP net.IP) bool | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package zctcpip | ||
|
||
import ( | ||
"encoding/binary" | ||
) | ||
|
||
type ICMPType = byte | ||
|
||
const ( | ||
ICMPTypePingRequest byte = 0x8 | ||
ICMPTypePingResponse byte = 0x0 | ||
) | ||
|
||
type ICMPPacket []byte | ||
|
||
func (p ICMPPacket) Type() ICMPType { | ||
return p[0] | ||
} | ||
|
||
func (p ICMPPacket) SetType(v ICMPType) { | ||
p[0] = v | ||
} | ||
|
||
func (p ICMPPacket) Code() byte { | ||
return p[1] | ||
} | ||
|
||
func (p ICMPPacket) Checksum() uint16 { | ||
return binary.BigEndian.Uint16(p[2:]) | ||
} | ||
|
||
func (p ICMPPacket) SetChecksum(sum [2]byte) { | ||
p[2] = sum[0] | ||
p[3] = sum[1] | ||
} | ||
|
||
func (p ICMPPacket) ResetChecksum() { | ||
p.SetChecksum(zeroChecksum) | ||
p.SetChecksum(Checksum(0, p)) | ||
} |
Oops, something went wrong.