Skip to content

Commit

Permalink
[*]优化目录结构
Browse files Browse the repository at this point in the history
  • Loading branch information
lcvvvv committed Mar 23, 2022
1 parent e717ee7 commit 1e5dd05
Show file tree
Hide file tree
Showing 48 changed files with 91 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "gonmap"]
path = lib/gonmap
path = core/gonmap
url = https://github.com/lcvvvv/gonmap
4 changes: 2 additions & 2 deletions app/type-config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package app

import (
"kscan/core/hydra"
"kscan/core/slog"
"kscan/lib/IP"
"kscan/lib/chinese"
"kscan/lib/hydra"
"kscan/lib/misc"
"kscan/lib/slog"
"kscan/lib/urlparse"
"os"
"regexp"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 4 additions & 7 deletions lib/fofa/fofa.go → core/fofa/fofa.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"io/ioutil"
"kscan/app"
"kscan/core/slog"
"kscan/lib/color"
"kscan/lib/misc"
"kscan/lib/slog"
"net/http"
"reflect"
"strconv"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (f *Fofa) SearchAll() {
}
}

func (f *Fofa) Search(keyword string) {
func (f *Fofa) Search(keyword string) *ResponseJson {
url := f.baseUrl + f.searchPath
req, _ := http.NewRequest(http.MethodGet, url, nil)
q := req.URL.Query()
Expand All @@ -72,7 +72,7 @@ func (f *Fofa) Search(keyword string) {
q.Add("key", f.key)
q.Add("page", "1")
q.Add("fields", strings.Join(f.fieldList, ","))
q.Add("size", misc.Int2Str(f.size))
q.Add("size", strconv.Itoa(f.size))
q.Add("full", "false")
req.URL.RawQuery = q.Encode()
resp, err := http.DefaultClient.Do(req)
Expand Down Expand Up @@ -115,10 +115,7 @@ func (f *Fofa) Search(keyword string) {
slog.Data(line)
}
slog.Infof("本次搜索,返回结果总条数为:%d,此次返回条数为:%d", responseJson.Size, len(responseJson.Results))

//table.SetPrintColumns(misc.First2UpperForSlice(f.field))
//t := table.Table(r)
//fmt.Println(t)
return &responseJson
}

func (f *Fofa) makeResult(responseJson ResponseJson) []Result {
Expand Down
25 changes: 25 additions & 0 deletions core/fofa/fofa_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fofa

import (
"fmt"
"kscan/lib/misc"
"os"
"strconv"
"strings"
"testing"
)

func TestGetPortMap(t *testing.T) {
email := os.Getenv("FOFA_EMAIL")
key := os.Getenv("FOFA_KEY")
f := New(email, key)
var fileSlice []string
for i := 1; i <= 65535; i++ {
keyword := "port=" + strconv.Itoa(i)
responseJson := f.Search(keyword)
row := fmt.Sprintf("%d\t%d", i, responseJson.Size)
fmt.Println(row)
fileSlice = append(fileSlice, row)
}
_ = misc.WriteLine("fofa_port.txt", []byte(strings.Join(fileSlice, "\n")))
}
File renamed without changes.
24 changes: 12 additions & 12 deletions lib/hydra/cracker.go → core/hydra/cracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package hydra

import (
"fmt"
"kscan/core/hydra/ftp"
"kscan/core/hydra/mongodb"
"kscan/core/hydra/mssql"
"kscan/core/hydra/mysql"
"kscan/core/hydra/oracle"
"kscan/core/hydra/postgresql"
"kscan/core/hydra/rdp"
"kscan/core/hydra/redis"
"kscan/core/hydra/smb"
"kscan/core/hydra/ssh"
"kscan/core/hydra/telnet"
"kscan/core/slog"
"kscan/lib/gotelnet"
"kscan/lib/grdp"
"kscan/lib/hydra/ftp"
"kscan/lib/hydra/mongodb"
"kscan/lib/hydra/mssql"
"kscan/lib/hydra/mysql"
"kscan/lib/hydra/oracle"
"kscan/lib/hydra/postgresql"
"kscan/lib/hydra/rdp"
"kscan/lib/hydra/redis"
"kscan/lib/hydra/smb"
"kscan/lib/hydra/ssh"
"kscan/lib/hydra/telnet"
"kscan/lib/slog"
)

func rdpCracker(IPAddr string, port int) func(interface{}) interface{} {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/hydra/hydra.go → core/hydra/hydra.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package hydra

import (
"kscan/core/hydra/oracle"
"kscan/lib/gotelnet"
"kscan/lib/hydra/oracle"
"kscan/lib/misc"
"kscan/lib/pool"
"time"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/hydra/oracle/oracle.go → core/hydra/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"
_ "github.com/sijms/go-ora/v2"
"kscan/lib/slog"
"kscan/core/slog"
"strings"
"time"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions lib/slog/slog.go → core/slog/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ func debugFilter(s string) bool {
//}
return false
}

func DebugLogger() *log.Logger {
return this.debug
}
4 changes: 2 additions & 2 deletions lib/spy/spy.go → core/spy/spy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package spy

import (
"fmt"
"kscan/core/gonmap"
"kscan/core/slog"
"kscan/lib/IP"
"kscan/lib/gonmap"
"kscan/lib/misc"
"kscan/lib/pool"
"kscan/lib/slog"
"net"
"strings"
)
Expand Down
2 changes: 1 addition & 1 deletion lib/touch/touch.go → core/touch/touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package touch

import (
"fmt"
"kscan/lib/gonmap/simplenet"
"kscan/core/gonmap/simplenet"
"strconv"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion lib/update/checkupdate.go → core/update/checkupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package update

import (
"bufio"
"kscan/core/slog"
"kscan/lib/misc"
"kscan/lib/slog"
"os"
"strings"
)
Expand Down
13 changes: 8 additions & 5 deletions kscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package main

import (
"kscan/app"
"kscan/core/fofa"
"kscan/core/gonmap"
"kscan/core/slog"
"kscan/core/spy"
"kscan/core/touch"
"kscan/lib/color"
"kscan/lib/fofa"
"kscan/lib/gonmap"
"kscan/lib/httpfinger"
"kscan/lib/slog"
"kscan/lib/spy"
"kscan/lib/touch"
"kscan/lib/pool"
"kscan/run"
"os"
"runtime"
Expand Down Expand Up @@ -173,6 +174,8 @@ func Init() {
slog.SetPrintDebug(app.Args.Debug)
//color包初始化
app.Setting.CloseColor = color.Init(app.Args.CloseColor)
//pool包初始化
pool.SetLogger(slog.DebugLogger())
//配置文件初始化
app.ConfigInit()
slog.Info("当前环境为:", runtime.GOOS, ", 输出编码为:", app.Setting.Encoding)
Expand Down
47 changes: 16 additions & 31 deletions lib/misc/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"fmt"
"io"
"io/ioutil"
"kscan/lib/chinese"
"kscan/lib/slog"
"math/rand"
"os"
"strconv"
Expand Down Expand Up @@ -36,17 +34,13 @@ func Str2Int(str string) int {
return intValue
}

//func IntArr2StrArr(intArr []int) []string {
// var strArr []string
// for _, value := range intArr {
// strValue := strconv.Itoa(value)
// strArr = append(strArr, strValue)
// }
// return strArr
//}

func Int2Str(Int int) string {
return strconv.Itoa(Int)
func IntArr2StrArr(intArr []int) []string {
var strArr []string
for _, value := range intArr {
strValue := strconv.Itoa(value)
strArr = append(strArr, strValue)
}
return strArr
}

func IsInStrArr(slice []string, val string) bool {
Expand Down Expand Up @@ -198,10 +192,6 @@ func StrMap2Str(stringMap map[string]string, keyPrint bool) string {
rArr = append(rArr, value)
}
}

for index, value := range rArr {
rArr[index] = chinese.ToUTF8(value)
}
return strings.Join(rArr, "、")
}

Expand Down Expand Up @@ -286,13 +276,9 @@ func Base64Encode(keyword string) string {
return encodeString
}

func Base64Decode(encodeString string) string {
func Base64Decode(encodeString string) (string, error) {
decodeBytes, err := base64.StdEncoding.DecodeString(encodeString)
if err != nil {
slog.Debug(err)
return ""
}
return string(decodeBytes)
return string(decodeBytes), err
}

func CloneStrMap(strMap map[string]string) map[string]string {
Expand Down Expand Up @@ -327,24 +313,23 @@ func RandomString(i ...int) string {
return str
}

func ReadAll(r io.Reader, duration time.Duration) []byte {
func ReadAll(r io.Reader, duration time.Duration) ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), duration)
defer cancel()
BufChan := make(chan []byte)

var err error

go func() {
var Buf []byte
defer func() {
if err := recover(); err != nil {
if len(Buf) != 0 {
slog.Debug(err, ",reader response is :", StrRandomCut(string(Buf), 20))
err = "reader response is :" + StrRandomCut(string(Buf), 20)
}
}
}()
Buf, err := ioutil.ReadAll(r)
if err != nil {
slog.Debug(err.Error())
}
Buf, err = ioutil.ReadAll(r)
BufChan <- Buf
}()

Expand All @@ -353,10 +338,10 @@ func ReadAll(r io.Reader, duration time.Duration) []byte {
select {
case <-ctx.Done():
close(BufChan)
return Buf
return Buf, err
case Buf = <-BufChan:
close(BufChan)
return Buf
return Buf, err
}
}

Expand Down
11 changes: 9 additions & 2 deletions lib/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package pool
import (
"errors"
"fmt"
"io"
"kscan/lib/misc"
"kscan/lib/slog"
"kscan/lib/smap"
"log"
"sync"
"time"
)

var logger = log.New(io.Discard, "", log.Ldate|log.Ltime)

//创建worker,每一个worker抽象成一个可以执行任务的函数
type Worker struct {
f func(interface{}) (interface{}, error)
Expand All @@ -22,7 +25,7 @@ func NewWorker(f func(interface{}) interface{}) *Worker {
defer func() {
if e := recover(); e != nil {
err = errors.New(fmt.Sprint("param: ", in, e))
slog.Debug(err, e)
logger.Println(err)
}
}()
out = f(in)
Expand Down Expand Up @@ -146,3 +149,7 @@ func (p *Pool) Stop() {
func (p *Pool) NewTick() string {
return misc.RandomString()
}

func SetLogger(log *log.Logger) {
logger = log
}
2 changes: 1 addition & 1 deletion run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package run

import (
"kscan/app"
"kscan/lib/slog"
"kscan/core/slog"
"time"
)

Expand Down
6 changes: 3 additions & 3 deletions run/type-kscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"encoding/json"
"fmt"
"kscan/app"
"kscan/core/gonmap"
"kscan/core/hydra"
"kscan/core/slog"
"kscan/lib/color"
"kscan/lib/gonmap"
"kscan/lib/httpfinger"
"kscan/lib/hydra"
"kscan/lib/misc"
"kscan/lib/pool"
"kscan/lib/queue"
"kscan/lib/slog"
"kscan/lib/smap"
"kscan/lib/urlparse"
"os"
Expand Down

0 comments on commit 1e5dd05

Please sign in to comment.