feat: complete basic functions

Support http,dns and mysql connection. Support custom http, dns response. Support dns rebinding.
Support mysql load local files and jdbc deserialize exploit.
This commit is contained in:
Li4n0
2021-04-21 18:55:16 +08:00
parent e9db8ddb24
commit 3559894acc
114 changed files with 41617 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
package qqwry
import (
"bytes"
"compress/zlib"
"crypto/tls"
"encoding/binary"
"errors"
"io/ioutil"
"net/http"
"sync"
"time"
log "unknwon.dev/clog/v2"
)
const (
COPY_WRITE_URL = "https://qqwry.mirror.noc.one/copywrite.rar"
QQWRY_URL = "https://qqwry.mirror.noc.one/qqwry.rar"
)
func get(url string) (b []byte, err error) {
client := http.Client{
Timeout: 90 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // disable verify
}}
request, _ := http.NewRequest("GET", url, nil)
request.Header.Add("User-Agent", "Nali/2.1.2 (Nali CLI, https://nali.skk.moe)")
resp, err := client.Do(request)
if err != nil {
return
}
defer resp.Body.Close()
b, err = ioutil.ReadAll(resp.Body)
return
}
func getKey(b []byte) (key uint32, err error) {
if len(b) != 280 {
return 0, errors.New("copywrite.rar is corrupt")
}
key = binary.LittleEndian.Uint32(b[20:])
return
}
func decrypt(b []byte, key uint32) (_ []byte, err error) {
for i := 0; i < 0x200; i++ {
key *= uint32(0x805)
key++
key &= uint32(0xff)
b[i] = b[i] ^ byte(key)
}
rc, err := zlib.NewReader(bytes.NewBuffer(b))
if err != nil {
return
}
defer rc.Close()
return ioutil.ReadAll(rc)
}
func download() (err error) {
var (
copyWriteData, qqwryData []byte
wg sync.WaitGroup
)
log.Info("Downloading qqwry.dat...")
wg.Add(2)
go func() {
defer wg.Done()
if copyWriteData, err = get(COPY_WRITE_URL); err != nil {
return
}
}()
go func() {
defer wg.Done()
if qqwryData, err = get(QQWRY_URL); err != nil {
return
}
}()
wg.Wait()
if err != nil {
return err
}
var key uint32
if key, err = getKey(copyWriteData); err != nil {
return
}
b, err := decrypt(qqwryData, key)
if err != nil {
return err
}
_ = ioutil.WriteFile("qqwry.dat", b, 0644)
return nil
}
+14
View File
@@ -0,0 +1,14 @@
package qqwry
// Area return IpArea according to ip
func Area(ip string) string {
ipData := GetQQWry().SearchByIPv4(ip)
if GetQQWry() == nil {
return ""
}
if ipData.Area == " CZ88.NET" {
return ipData.Country
} else {
return ipData.Country + " " + ipData.Area
}
}
+47
View File
@@ -0,0 +1,47 @@
package qqwry
import (
"os"
"sync"
"time"
"github.com/sinlov/qqwry-golang/qqwry"
log "unknwon.dev/clog/v2"
)
var wry *qqwry.QQwry
var once sync.Once
func init() {
info, err := os.Stat("qqwry.dat")
if err != nil {
if os.IsNotExist(err) {
err := download()
if err != nil {
log.Error("Download qqwry.dat failed, caused by:%v, recommend to download it by yourself otherwise the `IpArea` will be null", err.Error())
}
}
} else if info.ModTime().Sub(time.Now()) > 5*24*time.Hour {
log.Info("Updating qqwry.dat...")
err := download()
if err != nil {
log.Warn("Update qqwry.dat failed, please download qqwry.dat by yourself")
}
}
}
func GetQQWry() *qqwry.QQwry {
once.Do(func() {
qqwry.DatData.FilePath = "qqwry.dat"
init := qqwry.DatData.InitDatFile()
if v, ok := init.(error); ok {
if v != nil {
log.Error("qqwry init failed")
wry = nil
}
}
wry = qqwry.NewQQwry()
})
return wry
}