Skip to content

Commit

Permalink
修复异常退出和完善配置说明
Browse files Browse the repository at this point in the history
  • Loading branch information
Kisesy committed Dec 13, 2017
1 parent e4f8cb2 commit 021d2d3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
10 changes: 7 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
// 注意:
// 扫描并发数 理论上设置越大扫的越快, 但是并不意味越大就可以扫到更多IP
// [扫描并发数] 理论上设置越大扫的越快, 但是并不意味越大就可以扫到更多IP
// 大量的并发数, 会造成网络堵塞, 甚至触到系统网络的限制或造成路由器宕机而出现更多的问题
// 所以如果在你那里基本扫不到IP, 可以试着减小扫描并发数并增大超时时间

// 新添了 Level 设置
// 可以按照说明进行修改来达到加速扫描的效果, 但是为了结果的准确性最好还是设置为最高

// 扫描并发数
"ScanWorker": 100,

Expand Down Expand Up @@ -32,6 +35,7 @@
// HTTPVerifyHosts 是 http 测试时使用的测试地址, 默认一个
// 如果设置多个, 将会依次进行测试
"HTTPVerifyHosts": ["dns.google.com"],
// 握手超时时间, 单位: 毫秒
"HandshakeTimeout": 2500,
"ScanMinRTT": 0,
"ScanMaxRTT": 3000,
Expand All @@ -48,6 +52,7 @@
// 1: 只是测试连接成功, 并且确定证书存在
// 2: 验证证书是否正确
// 3: 测试 HTTP 连接
// (2.x版默认等级为3, 所以如果lv2搜到的IP不能用, 可以改为 3)
"Level": 2,
},

Expand All @@ -73,7 +78,6 @@
// 暂时未使用
// "HTTPVerifyHosts": ["dns.google.com"],

// TLS 握手时间设置
"HandshakeTimeout": 2500,
"ScanMinRTT": 0,
"ScanMaxRTT": 3000,
Expand All @@ -83,6 +87,6 @@
"OutputFile": "./out_sni.txt",
// 1: 测试 tls 连接并握手
// 2: http 测试
"Level": 1,
"Level": 2,
},
}
3 changes: 1 addition & 2 deletions gscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ func initFiles(cfg *GScanConfig) {
func main() {
defer func() {
if r := recover(); r != nil {
panic(fmt.Sprintf("panic: %s\n", r))
fmt.Println("panic:", r)
}
fmt.Println()
if runtime.GOOS == "windows" {
cmd := exec.Command("cmd", "/C", "pause")
cmd.Stdout = os.Stdout
Expand Down
32 changes: 14 additions & 18 deletions quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func testQuic(ip string, config *GScanConfig, record *ScanRecord) bool {
addr := net.JoinHostPort(ip, "443")

start := time.Now()
success := make(chan bool, 5)
result := make(chan bool, 5)

go func() {
<-time.After(config.Quic.ScanMaxRTT * time.Millisecond)
success <- false
result <- false
}()

var quicSessn quic.Session
Expand Down Expand Up @@ -59,32 +59,32 @@ func testQuic(ip string, config *GScanConfig, record *ScanRecord) bool {
quicSessn, err = quic.Dial(udpConn, udpAddr, addr, quicTlsCfg, quicCfg)
if err != nil {
// log.Println(err)
success <- false
result <- false
return
}
// 只会验证证书存在
// lv1 只会验证证书是否存在
cs := quicSessn.ConnectionState()
if cs == nil {
success <- false
result <- false
return
}
pcs := cs.PeerCertificates
if len(pcs) < 2 {
success <- false
result <- false
return
}

// 验证证书
if config.Quic.Level > 1 { // 2
// lv2 验证证书是否正确
if config.Quic.Level > 1 {
pkp := pcs[1].RawSubjectPublicKeyInfo

if !bytes.Equal(g2pkp, pkp) && !bytes.Equal(g3pkp, pkp) { // && !bytes.Equal(g3ecc, pkp[:]) {
success <- false
result <- false
return
}
}

if config.Quic.Level > 2 { // 3
// lv3 使用 http 访问来验证
if config.Quic.Level > 2 {
tr := &h2quic.RoundTripper{DisableCompression: true}
defer tr.Close()

Expand All @@ -103,19 +103,15 @@ func testQuic(ip string, config *GScanConfig, record *ScanRecord) bool {
resp.Body.Close()
}
if err != nil || resp.StatusCode >= 400 {
success <- false
result <- false
return
}
}
}

success <- true
result <- true
}()

if <-success == false {
return false
}

record.RTT = record.RTT + time.Since(start)
return true
return <-result
}
10 changes: 5 additions & 5 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func testip_worker(ctx context.Context, ch chan string, options *ScanOptions, wg
}
}

func Scan(options *ScanOptions, cfg *ScanConfig, ipQueue chan string) (evalCount int) {
func Scan(options *ScanOptions, cfg *ScanConfig, ipqueue chan string) (evalCount int) {
var wg sync.WaitGroup
wg.Add(options.Config.ScanWorker)

wait := make(chan os.Signal, 1)
signal.Notify(wait, os.Interrupt, os.Kill)
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -112,10 +112,10 @@ func Scan(options *ScanOptions, cfg *ScanConfig, ipQueue chan string) (evalCount
go testip_worker(ctx, ch, options, &wg)
}

for ip := range ipQueue {
for ip := range ipqueue {
select {
case ch <- ip:
case <-wait:
case <-interrupt:
return
}
evalCount++
Expand Down

0 comments on commit 021d2d3

Please sign in to comment.